Create a pair
Overview
This guide outlines how to establish a new token pair on a Saros DLMM pool via your frontend. The workflow is encapsulated in a single user transaction and includes:
Deriving required PDAs (Program Derived Addresses)
Creating the quote asset badge
Initializing the pool pair
Setting up the bin arrays
Deriving PDAs
Before creating a pair, you need to derive several PDAs:
import { PublicKey } from "@solana/web3.js";
import { BN } from "@project-serum/anchor";
import { utils } from "@coral-xyz/anchor";
// Configuration PDA
const config = new PublicKey("address");
// Token mints
const tokenX = new PublicKey("address");
const tokenY = new PublicKey("address");
const BIN_STEP = 20;
const BIN_ARRAY_INDEX = 0; // Example value
const ACTIVE_ID = 8388608; // Example value (2^23)
// Derive bin step config PDA
const [binStepConfig] = PublicKey.findProgramAddressSync(
[
Buffer.from(utils.bytes.utf8.encode("bin_step_config")),
config.toBuffer(),
new Uint8Array([BIN_STEP]),
],
program.programId
);
// Derive quote asset badge PDA
const [quoteAssetBadge] = PublicKey.findProgramAddressSync(
[
Buffer.from(utils.bytes.utf8.encode("quote_asset_badge")),
config.toBuffer(),
tokenY.toBuffer(),
],
program.programId
);
// Derive pair PDA
const [pair] = PublicKey.findProgramAddressSync(
[
Buffer.from(utils.bytes.utf8.encode("pair")),
config.toBuffer(),
tokenX.toBuffer(),
tokenY.toBuffer(),
new Uint8Array([BIN_STEP]),
],
program.programId
);
// Derive bin array PDAs
const [binArrayLower] = PublicKey.findProgramAddressSync(
[
Buffer.from(utils.bytes.utf8.encode("bin_array")),
pair.toBuffer(),
new BN(BIN_ARRAY_INDEX).toArrayLike(Buffer, "le", 4),
],
program.programId
);
const [binArrayUpper] = PublicKey.findProgramAddressSync(
[
Buffer.from(utils.bytes.utf8.encode("bin_array")),
pair.toBuffer(),
new BN(BIN_ARRAY_INDEX + 1).toArrayLike(Buffer, "le", 4),
],
program.programId
);
Creating Token Vaults
For the pair to function, you need to create token vaults for both tokens:
Initializing the Quote Asset Badge
The quote asset badge identifies which token is the quote asset (token Y):
Initializing the Pair
Now you can initialize the pair with the specified active binitializeConfigD:
Initializing Bin Arrays
Finally, you need to initialize the bin arrays for the pair:
Complete End-to-End Example
Below is a consolidated script that ties together all the preceding steps:
Last updated