토큰 예치하기

기밀 보류 잔액에 토큰을 입금하는 방법

토큰을 기밀로 전송하려면 먼저 공개 토큰 잔액을 기밀 잔액으로 변환해야 합니다. 이 변환은 두 단계로 이루어집니다:

  1. 기밀 보류 잔액: 처음에는 토큰이 공개 잔액에서 "보류" 기밀 잔액으로 "입금"됩니다.
  2. 기밀 가용 잔액: 보류 잔액이 가용 잔액에 "적용"되어 토큰을 기밀 전송에 사용할 수 있게 됩니다.

이 섹션에서는 첫 번째 단계인 공개 토큰 잔액을 기밀 보류 잔액으로 입금하는 과정을 설명합니다.

다음 다이어그램은 공개 잔액에서 기밀 보류 잔액으로 토큰을 입금하는 단계를 보여줍니다:

Deposit Tokens

필요한 명령어

공개 잔액을 기밀 보류 잔액으로 변환하려면 ConfidentialTransferInstruction::Deposit 명령어를 호출하세요. 입금 명령어당 최대 금액은 2^48로 제한됩니다.

spl_token_client 크레이트는 아래 예시에서 보여주듯이 Deposit 명령어가 포함된 트랜잭션을 빌드하고 전송하는 confidential_transfer_deposit 메서드를 제공합니다.

예제 코드

다음 예제는 공개 토큰 잔액을 기밀 보류 잔액으로 입금하는 방법을 보여줍니다.

기밀 전송은 ZK ElGamal Proof 프로그램에 의존하며, 이는 메인넷과 데브넷에서 활성화되어 있습니다. 기본 solana-test-validator 에서는 활성화되지 않지만, Surfpool과 같이 메인넷을 포킹하는 로컬 validator에서는 활성화됩니다. 자금이 충분한 페이어로 해당 환경 중 하나(코드는 데브넷 사용)에서 예제를 실행하고, 플레이스홀더 민트 및 계정 주소를 본인 것으로 교체하세요.

Rust

const ZK_PROOF_PROGRAM_ID: Pubkey =
solana_pubkey::pubkey!("ZkE1Gama1Proof11111111111111111111111111111");
fn main() -> Result<()> {
let rpc_client = RpcClient::new_with_commitment(
String::from("https://api.devnet.solana.com"),
CommitmentConfig::confirmed(),
);
// Owner = fee payer = token account owner. The setup below configures the
// account for confidential transfers (see "Create a Token Account").
let owner = load_keypair()?;
let amount: u64 = 100;
let decimals: u8 = 2;
// Setup: create a confidential token account with public tokens.
let (mint, token_account) = setup_deposit_account(&rpc_client, &owner, amount, decimals)?;
// Deposit moves tokens from the public balance into the pending confidential
// balance. No proof is required. The tokens land in the pending balance and
// must be applied (see "Apply Pending Balance") before they can be spent.
let deposit_ix = deposit(
&spl_token_2022::id(),
&token_account,
&mint,
amount,
decimals,
&owner.pubkey(),
&[&owner.pubkey()],
)?;
let blockhash = rpc_client.get_latest_blockhash()?;
let transaction =
Transaction::new_signed_with_payer(&[deposit_ix], Some(&owner.pubkey()), &[&owner], blockhash);
let signature = rpc_client.send_and_confirm_transaction(&transaction)?;
println!("Deposited {amount} tokens to the pending confidential balance: {signature}");
Ok(())
}

Typescript

const client = await createClient()
.use(signerFromFile(join(homedir(), ".config/solana/id.json")))
.use(
solanaRpc({
rpcUrl: "https://api.devnet.solana.com"
})
);
// The Solana CLI default keypair, used as fee payer, mint authority, and
// token account owner.
const owner = client.payer;
const amount = 100n;
const decimals = 2;
// Setup: create a confidential mint and token account with public tokens.
const mint = await createConfidentialMint(client, owner, decimals);
const token = await createConfidentialTokenAccount(client, owner, mint);
await mintPublicTokens(client, owner, mint, token, amount);
// Deposit moves public tokens into the pending confidential balance. No proof
// is required; the tokens must then be applied before they can be spent.
const depositInstruction = getConfidentialDepositInstruction({
token,
mint,
authority: owner,
amount,
decimals
});
const result = await client.sendTransaction([depositInstruction]);
console.log(
`Deposited ${amount} tokens to the pending confidential balance: ${result.context.signature}`
);

Is this page helpful?

목차

페이지 편집