> ## Documentation Index
> Fetch the complete documentation index at: https://docs.multiliquid.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Run a pair

> Open a pair as a capital provider, fund it, change its fees, pause it, and close it with the TypeScript SDK.

As a capital provider, you own your pairs on Solana. You set each pair's fees, hold its inventory in vaults that only the program can move, and pay the protocol fee on every swap from a separate fee account. This recipe takes a stablecoin and RWA pair from opening to closing.

## Before you start

* **Both tokens registered.** The Multiliquid admin registers a token, with its price sources, before anyone can pair it. [Contact the Multiliquid team](https://www.multiliquid.xyz/) to register one.
* **Issuer approval for permissioned tokens.** The issuer must admit two addresses: your wallet, which owns the token accounts you fund from, and your vault authority, the PDA that owns your vaults. Step 1 derives it. Admitting one does not admit the other, and the issuer must also thaw both token accounts if it freezes new ones.
* **The fee token.** Protocol fees are paid in the token that `client.fetchGlobalConfig()` returns as `feeTokenMint`.
* **SOL** for network fees and rent. Your wallet pays for the pair, its vaults, and the records the program keeps.
* **The SDK client and a wallet**, set up as in [Swap on-chain](https://docs.multiliquid.xyz/svm/guides/integration.md#2-create-a-client). Here the wallet is the capital provider's.

Every step below builds an unsigned transaction that your wallet signs and pays for. This helper signs, sends, and waits until each one is final:

```typescript send.ts expandable theme={null}
import {
  address,
  getBase64EncodedWireTransaction,
  getSignatureFromTransaction,
  signTransaction,
  type Transaction,
} from "@solana/kit";
import { buildUnsignedTransaction, swapProgramClient, toNativeAmount } from "@uniformlabs/multiliquid-svm-sdk";

const stablecoinMint = address(process.env.STABLECOIN_MINT!);
const rwaMint = address(process.env.RWA_MINT!);

async function send(transaction: Transaction) {
  const signedTransaction = await signTransaction([signer.keyPair], transaction);
  const signature = getSignatureFromTransaction(signedTransaction);
  await rpc
    .sendTransaction(getBase64EncodedWireTransaction(signedTransaction), {
      encoding: "base64",
      preflightCommitment: "confirmed",
    })
    .send();

  for (let attempt = 0; attempt < 60; attempt++) {
    const { value } = await rpc.getSignatureStatuses([signature]).send();
    const status = value[0];
    if (status?.err) throw new Error("Transaction failed", { cause: status.err });
    if (status?.confirmationStatus === "finalized") return signature;
    await new Promise((resolve) => setTimeout(resolve, 2_000));
  }
  throw new Error(`Not finalized yet: ${signature}`);
}
```

## 1. Get your vault authority admitted

Your vaults are token accounts owned by a PDA derived from your wallet. Derive it, and send both addresses to the issuer of each permissioned token:

```typescript theme={null}
const [vaultAuthority] = await client.deriveVaultAuthority(signer.address);
console.log("Ask each issuer to admit:", signer.address, vaultAuthority);
```

The program cannot grant issuer approval or thaw an account. Until the issuer acts, adding liquidity and swaps that touch the vault fail.

## 2. Open the pair

Pass the two mints in any order, and a fee for each direction in basis points:

```typescript theme={null}
const { transaction: initPair, accounts } = await client.buildInitPairTransaction({
  liquidityProvider: signer.address,
  mintA: stablecoinMint,
  mintB: rwaMint,
  redemptionFeeBps: 10,
  discountRateBps: 10,
});
console.log("Quote mint:", accounts.quoteTokenMintAddress);
await send(initPair);
```

The pair stores the mint with the lower address bytes as its quote mint, and the SDK sorts them for you. `redemptionFeeBps` applies to swaps from the quote mint to the base mint, and `discountRateBps` to swaps from base to quote. The quote mint is not always the stablecoin, so read `accounts.quoteTokenMintAddress` and set each fee for the direction you mean. Each fee is at most 9,900 basis points, and the two together must be less than 10,000.

Opening the pair also creates a vault for each mint, if you have none yet, and your fee account. A pair opens unpaused.

## 3. Fund your fee account

Every swap debits its protocol fee from your fee account, in the fee token. Swaps on all your pairs fail while it cannot pay, so keep it funded:

```typescript theme={null}
const { transaction: fundFees } = await client.buildFundLpFeeVaultTransaction({
  liquidityProvider: signer.address,
  funder: signer.address,
  amount: toNativeAmount("100", 6), // 100 units of a 6-decimal fee token
});
await send(fundFees);
```

Any wallet can fund it. Only you can take the balance back, by closing it.

## 4. Add inventory

Fund the vault each swap pays out of: the RWA vault for users who buy, and the stablecoin vault for users who sell.

```typescript theme={null}
const { transaction: addRwa } = await client.buildAddLiquidityTransaction({
  liquidityProvider: signer.address,
  mint: rwaMint,
  amount: toNativeAmount("1000", 9), // 1,000 units of a 9-decimal RWA
});
await send(addRwa);
```

One vault serves every pair you own with that mint.

## 5. Change fees or pause

`update_pair` sets both fees and the pause flag together, so pass all three:

```typescript theme={null}
const { transaction: updatePair } = await client.buildUpdatePairTransaction({
  liquidityProvider: signer.address,
  mintA: stablecoinMint,
  mintB: rwaMint,
  redemptionFeeBps: 15,
  discountRateBps: 10,
  paused: false,
});
await send(updatePair);
```

New fees apply to the next swap. To pause every pair you own with a given stablecoin in one call, set your stablecoin setting instead:

```typescript theme={null}
const pauseStablecoin = await swapProgramClient.getSetPausedForLpStableConfigInstructionAsync({
  mintAddress: stablecoinMint,
  liquidityProvider: signer.address,
  signer,
  paused: true,
});
await send(await buildUnsignedTransaction(rpc, signer.address, [pauseStablecoin]));
```

## 6. Withdraw inventory

Withdraw any amount the vault holds:

```typescript theme={null}
const { transaction: removeRwa } = await client.buildRemoveLiquidityTransaction({
  liquidityProvider: signer.address,
  mint: rwaMint,
  amount: toNativeAmount("500", 9),
});
await send(removeRwa);
```

Withdrawals work while a token or your stablecoin setting is paused, so you can always exit. Only a program-wide pause stops them.

## 7. Close the pair

Closing a pair reclaims its rent. When no other pair of yours uses a vault, the program also returns the vault's balance to you and closes it:

```typescript theme={null}
const { transaction: closePair } = await client.buildClosePairTransaction({
  liquidityProvider: signer.address,
  mintA: stablecoinMint,
  mintB: rwaMint,
});
await send(closePair);
```

After your last pair, close your fee account to recover its balance and rent, with `swapProgramClient.getCloseLpFeeAccountInstructionAsync`. Close it no earlier: swaps on any pair you still own fail without it.

## When something goes wrong

| Error | What happened | What to do |
| - | - | - |
| `OutOfRange` | A fee is above 9,900 basis points, or the two fees reach 10,000 | Lower the fees |
| `NonCanonicalTokenOrder` | The quote mint sorts after the base mint | Build with the SDK, which sorts the mints |
| `MissingLpStableConfig`, `InvalidAssetType` | A stablecoin side lacks its stablecoin setting, a non-stablecoin side has one, or both mints are the same | Build with the SDK, which places these accounts by each token's registered type |
| `ProgramPaused` | The program is paused | Wait until Multiliquid unpauses it |
| `RwaPaused`, `StablePaused` when adding | The token, or your stablecoin setting, is paused | Unpause your setting, or wait for the admin to unpause the token |
| `InsufficientLiquidity` | You asked to withdraw more than the vault holds | Withdraw at most the vault's balance |
| `InsufficientLpFeeBalance`, or `AccountNotInitialized` on `lp_fee_token_account` | Your fee account cannot pay a swap's protocol fee, or does not exist | Fund it, as in step 3 |
| `TreasuryBalanceNonZero` | Your Treasury position still holds value | Withdraw it with `remove_liquidity`, then close the pair |
| `Unauthorized` | A wallet other than yours or the admin's tried to pause your stablecoin setting | Sign with your wallet |
| Token program rejects a transfer | The issuer has not admitted or thawed your wallet's account or your vault | Ask the issuer to complete step 1 |

[Errors](https://docs.multiliquid.xyz/svm/instructions/errors.md) lists every program error.

## Next steps

> [card] [Pairs and liquidity](https://docs.multiliquid.xyz/svm/instructions/pair.md)
>
> Every pair and liquidity instruction, including Treasury routing.

> [card] [Ladder pricing](https://docs.multiliquid.xyz/svm/guides/ladder-pricing-model.md)
>
> Change fees with rolling volume, from an off-chain worker.

> [card] [Security](https://docs.multiliquid.xyz/svm/overview/security.md)
>
> What you control, and what the admin controls.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.