Skip to content

Commit 2eabaca

Browse files
author
tilo-14
committed
fix getata
Entire-Checkpoint: 4afa49be1970
1 parent 6bd27b8 commit 2eabaca

12 files changed

Lines changed: 46 additions & 49 deletions

File tree

toolkits/payments/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"dependencies": {
2626
"@lightprotocol/compressed-token": "^0.23.0-beta.10",
2727
"@lightprotocol/stateless.js": "^0.23.0-beta.10",
28-
"@solana/spl-memo": "^0.2.5"
28+
"@solana/spl-memo": "^0.2.5",
29+
"@solana/spl-token": "^0.4.13"
2930
}
3031
}

toolkits/payments/setup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const payer = Keypair.fromSecretKey(
2828
);
2929

3030
/** Create SPL mint, fund payer, wrap into light-token ATA. */
31-
export async function setup(amount = 1_000_000) {
31+
export async function setup(amount = 1_000_000_000) {
3232
const { mint } = await createMintInterface(
3333
rpc,
3434
payer,

toolkits/payments/spend-permissions/delegate-approve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import { rpc, payer, setup } from "../setup.js";
55
(async function () {
66
const { mint, senderAta } = await setup();
77

8-
// Approve: grant delegate permission to spend up to 500,000 tokens
8+
// Approve: grant delegate permission to spend up to 500,000,000 tokens
99
const delegate = Keypair.generate();
1010
const tx = await approveInterface(
1111
rpc,
1212
payer,
1313
senderAta,
1414
mint,
1515
delegate.publicKey,
16-
500_000,
16+
500_000_000,
1717
payer
1818
);
1919

2020
console.log("Approved delegate:", delegate.publicKey.toBase58());
21-
console.log("Allowance: 500,000 tokens");
21+
console.log("Allowance: 500,000,000 tokens");
2222
console.log("Tx:", tx);
2323
})();

toolkits/payments/spend-permissions/delegate-check.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { rpc, payer, setup } from "../setup.js";
3131
senderAta,
3232
mint,
3333
delegate.publicKey,
34-
500_000,
34+
500_000_000,
3535
payer
3636
);
3737

toolkits/payments/spend-permissions/delegate-full-flow.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ import { rpc, payer, setup } from "../setup.js";
99
(async function () {
1010
const { mint, senderAta } = await setup();
1111

12-
// 1. Owner approves delegate to spend up to 500,000 tokens
12+
// 1. Owner approves delegate to spend up to 500,000,000 tokens
1313
const delegate = Keypair.generate();
1414
const approveTx = await approveInterface(
1515
rpc,
1616
payer,
1717
senderAta,
1818
mint,
1919
delegate.publicKey,
20-
500_000,
20+
500_000_000,
2121
payer
2222
);
2323
console.log("1. Approved delegate:", delegate.publicKey.toBase58());
24-
console.log(" Allowance: 500,000 tokens");
24+
console.log(" Allowance: 500,000,000 tokens");
2525
console.log(" Tx:", approveTx);
2626

2727
// 2. Check delegation status

toolkits/payments/spend-permissions/delegate-revoke.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { rpc, payer, setup } from "../setup.js";
1616
senderAta,
1717
mint,
1818
delegate.publicKey,
19-
500_000,
19+
500_000_000,
2020
payer
2121
);
2222
console.log("Approved delegate:", delegate.publicKey.toBase58());

toolkits/payments/spend-permissions/delegate-transfer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import { rpc, payer, setup } from "../setup.js";
88
(async function () {
99
const { mint, senderAta } = await setup();
1010

11-
// Approve: grant delegate permission to spend up to 500,000 tokens
11+
// Approve: grant delegate permission to spend up to 500,000,000 tokens
1212
const delegate = Keypair.generate();
1313
await approveInterface(
1414
rpc,
1515
payer,
1616
senderAta,
1717
mint,
1818
delegate.publicKey,
19-
500_000,
19+
500_000_000,
2020
payer
2121
);
2222
console.log("Approved delegate:", delegate.publicKey.toBase58());
@@ -30,13 +30,13 @@ import { rpc, payer, setup } from "../setup.js";
3030
mint,
3131
recipient.publicKey,
3232
delegate,
33-
200_000,
33+
200_000_000,
3434
undefined,
3535
undefined,
3636
{ owner: payer.publicKey }
3737
);
3838

3939
console.log("Delegated transfer to:", recipient.publicKey.toBase58());
40-
console.log("Amount: 200,000 tokens");
40+
console.log("Amount: 200,000,000 tokens");
4141
console.log("Tx:", tx);
4242
})();
Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,31 @@
1-
import { Keypair } from "@solana/web3.js";
1+
import { LAMPORTS_PER_SOL } from "@solana/web3.js";
22
import {
33
getAssociatedTokenAddressInterface,
44
getAtaInterface,
5-
} from "@lightprotocol/compressed-token";
6-
import { transferInterface } from "@lightprotocol/compressed-token/unified";
5+
} from "@lightprotocol/compressed-token/unified";
76
import { rpc, payer, setup } from "../setup.js";
87

98
(async function () {
10-
const { mint, senderAta } = await setup();
9+
const { mint } = await setup();
1110

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}`);
2214

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+
}
3531
})();

typescript-client/actions/delegate-approve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const payer = Keypair.fromSecretKey(
2525
(async function () {
2626
const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
2727
await mintToCompressed(rpc, payer, mint, payer, [
28-
{ recipient: payer.publicKey, amount: 1_000_000n },
28+
{ recipient: payer.publicKey, amount: 1_000_000_000n },
2929
]);
3030

3131
const senderAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
@@ -36,11 +36,11 @@ const payer = Keypair.fromSecretKey(
3636
senderAta,
3737
mint,
3838
delegate.publicKey,
39-
500_000,
39+
500_000_000,
4040
payer
4141
);
4242

4343
console.log("Approved delegate:", delegate.publicKey.toBase58());
44-
console.log("Allowance: 500,000 tokens");
44+
console.log("Allowance: 500,000,000 tokens");
4545
console.log("Tx:", tx);
4646
})();

typescript-client/actions/delegate-revoke.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const payer = Keypair.fromSecretKey(
2828
(async function () {
2929
const { mint } = await createMintInterface(rpc, payer, payer, null, 9);
3030
await mintToCompressed(rpc, payer, mint, payer, [
31-
{ recipient: payer.publicKey, amount: 1_000_000n },
31+
{ recipient: payer.publicKey, amount: 1_000_000_000n },
3232
]);
3333

3434
const senderAta = getAssociatedTokenAddressInterface(mint, payer.publicKey);
@@ -39,7 +39,7 @@ const payer = Keypair.fromSecretKey(
3939
senderAta,
4040
mint,
4141
delegate.publicKey,
42-
500_000,
42+
500_000_000,
4343
payer
4444
);
4545
console.log("Approved delegate:", delegate.publicKey.toBase58());

0 commit comments

Comments
 (0)