|
1 | | -import { Keypair } from "@solana/web3.js"; |
| 1 | +import { LAMPORTS_PER_SOL } from "@solana/web3.js"; |
2 | 2 | import { |
3 | 3 | getAssociatedTokenAddressInterface, |
4 | 4 | getAtaInterface, |
5 | | -} from "@lightprotocol/compressed-token"; |
6 | | -import { transferInterface } from "@lightprotocol/compressed-token/unified"; |
| 5 | +} from "@lightprotocol/compressed-token/unified"; |
7 | 6 | import { rpc, payer, setup } from "../setup.js"; |
8 | 7 |
|
9 | 8 | (async function () { |
10 | | - const { mint, senderAta } = await setup(); |
| 9 | + const { mint } = await setup(); |
11 | 10 |
|
12 | | - const recipient = Keypair.generate(); |
13 | | - await transferInterface( |
14 | | - rpc, |
15 | | - payer, |
16 | | - senderAta, |
17 | | - mint, |
18 | | - recipient.publicKey, |
19 | | - payer, |
20 | | - 100 |
21 | | - ); |
| 11 | + // SOL balance |
| 12 | + const solLamports = await rpc.getBalance(payer.publicKey); |
| 13 | + console.log(`SOL: ${solLamports / LAMPORTS_PER_SOL}`); |
22 | 14 |
|
23 | | - // Get recipient's balance |
24 | | - const recipientAta = getAssociatedTokenAddressInterface( |
25 | | - mint, |
26 | | - recipient.publicKey |
27 | | - ); |
28 | | - const { parsed: account } = await getAtaInterface( |
29 | | - rpc, |
30 | | - recipientAta, |
31 | | - recipient.publicKey, |
32 | | - mint |
33 | | - ); |
34 | | - console.log("Recipient's balance:", account.amount); |
| 15 | + // Unified token balance via SDK aggregation |
| 16 | + const ata = getAssociatedTokenAddressInterface(mint, payer.publicKey); |
| 17 | + const account = await getAtaInterface(rpc, ata, payer.publicKey, mint); |
| 18 | + |
| 19 | + const decimals = account.parsed.mint ? 9 : 9; |
| 20 | + const unified = |
| 21 | + Number(account.parsed.amount) / 10 ** decimals; |
| 22 | + console.log(`\nToken ${mint.toBase58().slice(0, 6)}... (unified): ${unified}`); |
| 23 | + |
| 24 | + // Per-source breakdown from _sources |
| 25 | + if (account._sources && account._sources.length > 0) { |
| 26 | + for (const source of account._sources) { |
| 27 | + const amount = Number(source.amount) / 10 ** decimals; |
| 28 | + console.log(` ${source.type}: ${amount}`); |
| 29 | + } |
| 30 | + } |
35 | 31 | })(); |
0 commit comments