// ATA address is ALWAYS the same for owner + mintlet ata = get_associated_token_address(&owner.pubkey(), &mint);// Address derived from: [owner_pubkey, token_program_id, mint]
ATA 주소가 도출되는 방식:
// The ATA address is a PDA of the Associated Token Program;// the account itself is owned by the Token Programlet (ata, bump) = Pubkey::find_program_address( &[ owner.as_ref(), spl_token::id().as_ref(), mint.as_ref(), ], &spl_associated_token_account::id(), // ATA program);
장점
소유자/mint 쌍당 하나의 표준 계정
결정적 - 누구나 주소를 계산할 수 있음
결제 간소화 - 지갑 주소 + mint만 있으면 됨
모든 Solana 앱에서 통용되는 표준 규칙
단점
소유자/mint당 ATA를 하나만 가질 수 있음(설계상)
대부분의 경우 권장: 지갑 애플리케이션, DeFi 프로토콜, NFT 보유,
결제 시스템 및 사용자 대상 토큰 전송 전반.
use litesvm::LiteSVM;use litesvm_token::{ get_spl_account, spl_token::{native_mint::DECIMALS, state::Account as TokenAccount}, CreateAccount, CreateMint, MintTo, Transfer,};use solana_sdk::{ native_token::LAMPORTS_PER_SOL, signature::{Keypair, Signer},};#[test]fn test_create_and_mint_tokens() { let mut svm = LiteSVM::new(); // Create payer account and fund it let payer = Keypair::new(); svm.airdrop(&payer.pubkey(), 10 * LAMPORTS_PER_SOL).unwrap(); // Create a new SPL token mint with the payer as the mint authority let mint = CreateMint::new(&mut svm, &payer) .authority(&payer.pubkey()) .decimals(DECIMALS) .send() .unwrap(); // Create a token account for the payer let token_account = CreateAccount::new(&mut svm, &payer, &mint) .owner(&payer.pubkey()) .send() .unwrap(); // Mint tokens into the payer's token account MintTo::new(&mut svm, &payer, &mint, &token_account, 1000) .owner(&payer) .send() .unwrap(); // Verify balance let token_account: TokenAccount = get_spl_account(&svm, &token_account).unwrap(); let account_balance = token_account.amount; assert_eq!(account_balance, 1000)}