> For the complete documentation index, see [llms.txt](https://docs.saros.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.saros.xyz/kr/saros-dlmm/technical-guides/create-a-pair.md).

# 페어(거래쌍) 생성하기

### 개요(Overview)

이 가이드는 Saros DLMM 풀에서 새로운 토큰 페어를 프론트엔드를 통해 생성하는 방법을 설명합니다.\
모든 과정은 하나의 사용자 트랜잭션에 캡슐화되며 다음 단계를 포함합니다:

1. 필요한 PDA(Program Derived Address) 파생
2. Quote Asset Badge 생성
3. 풀 페어 초기화
4. Bin 배열 설정

### PDA 파생(Deriving PDAs)

페어를 생성하기 전에 다음과 같은 여러 PDA를 파생해야 합니다:

```
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)

거래쌍이 정상적으로 작동하려면 두 토큰 각각에 대한 토큰 볼트(Token Vault) 를 생성해야 합니다:

```
import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token";

// Create token vaults for the pair
const pairVaultX = await getOrCreateAssociatedTokenAccount(
  connection,
  wallet.payer,
  tokenX,
  pair,
  true
);

const pairVaultY = await getOrCreateAssociatedTokenAccount(
  connection,
  wallet.payer,
  tokenY,
  pair,
  true
);

```

### Quote Asset Badge 초기화(Initializing the Quote Asset Badge)

Quote Asset Badge는 어떤 토큰이 쿼트 자산(Token Y) 인지를 식별하는 역할을 합니다:

```
// Initialize quote asset badge
await program.methods
  .initializeQuoteAssetBadge()
  .accounts({
    quoteAssetBadge: quoteAssetBadge,
    liquidityBookConfig: config,
    tokenMint: tokenY,
    presetAuthority: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();
```

### 페어 초기화(Initializing the Pair)

지정한 액티브  binitializeConfigD를 사용하여 페어를 초기화할 수 있습니다:

```
// Initialize pair
await program.methods
  .initializePair(new BN(ACTIVE_ID))
  .accounts({
    liquidityBookConfig: config,
    binStepConfig: binStepConfig,
    quoteAssetBadge: quoteAssetBadge,
    pair: pair,
    tokenMintX: tokenX,
    tokenMintY: tokenY,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

```

### Bin 배열 초기화(Initializing Bin Arrays)​

마지막으로, 해당 페어에 대한 Bin 배열(Bin Arrays) 을 초기화해야 합니다:

```
// Initialize lower bin array
await program.methods
  .initializeBinArray(new BN(BIN_ARRAY_INDEX))
  .accounts({
    pair: pair,
    binArray: binArrayLower,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

// Initialize upper bin array
await program.methods
  .initializeBinArray(new BN(BIN_ARRAY_INDEX + 1))
  .accounts({
    pair: pair,
    binArray: binArrayUpper,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();
```

### 완전한 엔드 투 엔드 예시(Complete End-to-End Example)

아래는 앞서 설명한 모든 절차를 하나로 통합한 스크립트 예시입니다:

```
import { PublicKey } from "@solana/web3.js";
import { BN, Program, utils } from "@coral-xyz/anchor";
import { getOrCreateAssociatedTokenAccount } from "@solana/spl-token";

// Configuration
const config = new PublicKey("9aXo79uWCtxxxmssuTmAjCSGyP1sMxhQZdKZhrcMxGzz");
const tokenX = new PublicKey("FtJADTW8HSB4t6QQ4WsR8kcrrZ6oVaoVJk7KEWQZDJqt");
const tokenY = new PublicKey("Chc7CkBPvBsyNAmxAcupVox6pB5wcU2yuXD5PJAqQteb");
const BIN_STEP = 20;
const BIN_ARRAY_INDEX = 0;
const ACTIVE_ID = 8388608;

// Derive PDAs
const [binStepConfig] = PublicKey.findProgramAddressSync(
  [
    Buffer.from(utils.bytes.utf8.encode("bin_step_config")),
    config.toBuffer(),
    new Uint8Array([BIN_STEP]),
  ],
  program.programId
);

const [quoteAssetBadge] = PublicKey.findProgramAddressSync(
  [
    Buffer.from(utils.bytes.utf8.encode("quote_asset_badge")),
    config.toBuffer(),
    tokenY.toBuffer(),
  ],
  program.programId
);

const [pair] = PublicKey.findProgramAddressSync(
  [
    Buffer.from(utils.bytes.utf8.encode("pair")),
    config.toBuffer(),
    tokenX.toBuffer(),
    tokenY.toBuffer(),
    new Uint8Array([BIN_STEP]),
  ],
  program.programId
);

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
);

// Create token vaults
const pairVaultX = await getOrCreateAssociatedTokenAccount(
  connection,
  wallet.payer,
  tokenX,
  pair,
  true
);

const pairVaultY = await getOrCreateAssociatedTokenAccount(
  connection,
  wallet.payer,
  tokenY,
  pair,
  true
);

// Initialize quote asset badge
await program.methods
  .initializeQuoteAssetBadge()
  .accounts({
    quoteAssetBadge: quoteAssetBadge,
    liquidityBookConfig: config,
    tokenMint: tokenY,
    presetAuthority: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

// Initialize pair
await program.methods
  .initializePair(new BN(ACTIVE_ID))
  .accounts({
    liquidityBookConfig: config,
    binStepConfig: binStepConfig,
    quoteAssetBadge: quoteAssetBadge,
    pair: pair,
    tokenMintX: tokenX,
    tokenMintY: tokenY,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

// Initialize bin arrays
await program.methods
  .initializeBinArray(new BN(BIN_ARRAY_INDEX))
  .accounts({
    pair: pair,
    binArray: binArrayLower,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

await program.methods
  .initializeBinArray(new BN(BIN_ARRAY_INDEX + 1))
  .accounts({
    pair: pair,
    binArray: binArrayUpper,
    user: wallet.publicKey,
  })
  .signers([wallet.payer])
  .rpc();

console.log("Pair created successfully!");
console.log("Pair address:", pair.toBase58());
console.log("Bin array lower address:", binArrayLower.toBase58());
console.log("Bin array upper address:", binArrayUpper.toBase58());
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.saros.xyz/kr/saros-dlmm/technical-guides/create-a-pair.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
