Skip to content

Commit a7336af

Browse files
format
1 parent 63ef77b commit a7336af

29 files changed

Lines changed: 1763 additions & 1660 deletions

js/token-interface/.prettierrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"semi": true,
3+
"trailingComma": "all",
4+
"singleQuote": true,
5+
"printWidth": 80,
6+
"useTabs": false,
7+
"tabWidth": 4,
8+
"bracketSpacing": true,
9+
"arrowParens": "avoid"
10+
}

js/token-interface/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Payments-focused helpers for Light rent-free token flows.
44

55
Use this when you want SPL-style transfers with unified sender handling:
6+
67
- sender side auto wraps/loads into light ATA
78
- recipient ATA can be light (default), SPL, or Token-2022 via `tokenProgram`
89

@@ -100,4 +101,4 @@ console.log(account.amount, account.hotAmount, account.compressedAmount);
100101
- Canonical builders always use wrap-enabled sender setup (`createTransferInstructions`, `createLoadInstructions`, `createApproveInstructions`, `createRevokeInstructions`).
101102
- If sender SPL/T22 balances are wrapped by the flow, source SPL/T22 ATAs are not auto-closed.
102103
- Recipient ATA is derived from `(recipient, mint, tokenProgram)`; default is light token program.
103-
- Recipient-side load is still intentionally disabled.
104+
- Recipient-side load is still intentionally disabled.

js/token-interface/rollup.config.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ export default [
6666
jsConfig('cjs'),
6767
jsConfig('es'),
6868
dtsEntry('src/index.ts', 'dist/types/index.d.ts'),
69-
dtsEntry(
70-
'src/instructions/index.ts',
71-
'dist/types/instructions/index.d.ts',
72-
),
69+
dtsEntry('src/instructions/index.ts', 'dist/types/instructions/index.d.ts'),
7370
dtsEntry('src/kit/index.ts', 'dist/types/kit/index.d.ts'),
7471
];

js/token-interface/src/account.ts

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { getAssociatedTokenAddress } from './read/associated-token-address';
2-
import {
3-
parseLightTokenCold,
4-
parseLightTokenHot,
5-
} from './read/get-account';
2+
import { parseLightTokenCold, parseLightTokenHot } from './read/get-account';
63
import { Buffer } from 'buffer';
74
import {
85
LIGHT_TOKEN_PROGRAM_ID,
@@ -64,12 +61,8 @@ function buildParsedAta(
6461
address: PublicKey,
6562
owner: PublicKey,
6663
mint: PublicKey,
67-
hotParsed:
68-
| ReturnType<typeof parseLightTokenHot>['parsed']
69-
| null,
70-
coldParsed:
71-
| ReturnType<typeof parseLightTokenCold>['parsed']
72-
| null,
64+
hotParsed: ReturnType<typeof parseLightTokenHot>['parsed'] | null,
65+
coldParsed: ReturnType<typeof parseLightTokenCold>['parsed'] | null,
7366
): TokenInterfaceParsedAta {
7467
const hotAmount = hotParsed?.amount ?? ZERO;
7568
const compressedAmount = coldParsed?.amount ?? ZERO;
@@ -103,23 +96,21 @@ function buildParsedAta(
10396
amount,
10497
delegate,
10598
delegatedAmount: clampDelegatedAmount(amount, delegatedAmount),
106-
isInitialized:
107-
hotParsed?.isInitialized === true || coldParsed !== null,
108-
isFrozen:
109-
hotParsed?.isFrozen === true || coldParsed?.isFrozen === true,
99+
isInitialized: hotParsed?.isInitialized === true || coldParsed !== null,
100+
isFrozen: hotParsed?.isFrozen === true || coldParsed?.isFrozen === true,
110101
};
111102
}
112103

113-
function selectPrimaryCompressedAccount(
114-
accounts: ParsedTokenAccount[],
115-
): {
104+
function selectPrimaryCompressedAccount(accounts: ParsedTokenAccount[]): {
116105
selected: ParsedTokenAccount | null;
117106
ignored: ParsedTokenAccount[];
118107
} {
119108
const candidates = sortCompressedAccounts(
120109
accounts.filter(account => {
121110
return (
122-
account.compressedAccount.owner.equals(LIGHT_TOKEN_PROGRAM_ID) &&
111+
account.compressedAccount.owner.equals(
112+
LIGHT_TOKEN_PROGRAM_ID,
113+
) &&
123114
account.compressedAccount.data !== null &&
124115
account.compressedAccount.data.data.length > 0 &&
125116
toBigIntAmount(account) > ZERO
@@ -184,7 +175,9 @@ export async function getAtaOrNull({
184175
};
185176
}
186177

187-
export async function getAta(input: GetAtaInput): Promise<TokenInterfaceAccount> {
178+
export async function getAta(
179+
input: GetAtaInput,
180+
): Promise<TokenInterfaceAccount> {
188181
const account = await getAtaOrNull(input);
189182

190183
if (!account) {
@@ -206,7 +199,10 @@ export function getSpendableAmount(
206199
account.parsed.delegate !== null &&
207200
authority.equals(account.parsed.delegate)
208201
) {
209-
return clampDelegatedAmount(account.amount, account.parsed.delegatedAmount);
202+
return clampDelegatedAmount(
203+
account.amount,
204+
account.parsed.delegatedAmount,
205+
);
210206
}
211207

212208
return ZERO;
@@ -217,9 +213,7 @@ export function assertAccountNotFrozen(
217213
operation: 'load' | 'transfer' | 'approve' | 'revoke' | 'burn' | 'freeze',
218214
): void {
219215
if (account.parsed.isFrozen) {
220-
throw new Error(
221-
`Account is frozen; ${operation} is not allowed.`,
222-
);
216+
throw new Error(`Account is frozen; ${operation} is not allowed.`);
223217
}
224218
}
225219

@@ -228,9 +222,6 @@ export function assertAccountFrozen(
228222
operation: 'thaw',
229223
): void {
230224
if (!account.parsed.isFrozen) {
231-
throw new Error(
232-
`Account is not frozen; ${operation} is not allowed.`,
233-
);
225+
throw new Error(`Account is not frozen; ${operation} is not allowed.`);
234226
}
235227
}
236-

js/token-interface/src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ export function deriveSplInterfacePdaWithIndex(
2727
mint: PublicKey,
2828
index: number,
2929
): [PublicKey, number] {
30-
const indexSeed = index === 0 ? Buffer.from([]) : Buffer.from([index & 0xff]);
30+
const indexSeed =
31+
index === 0 ? Buffer.from([]) : Buffer.from([index & 0xff]);
3132
return PublicKey.findProgramAddressSync(
3233
[POOL_SEED, mint.toBuffer(), indexSeed],
3334
COMPRESSED_TOKEN_PROGRAM_ID,

js/token-interface/src/instructions/_plan.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
} from '@solana/instruction-plans';
66
import type { TransactionInstruction } from '@solana/web3.js';
77

8-
export type KitInstruction = ReturnType<typeof fromLegacyTransactionInstruction>;
8+
export type KitInstruction = ReturnType<
9+
typeof fromLegacyTransactionInstruction
10+
>;
911

1012
export function toKitInstructions(
1113
instructions: TransactionInstruction[],

js/token-interface/src/instructions/ata.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ function encodeCreateAssociatedLightTokenAccountData(
125125
for (;;) {
126126
const buffer = Buffer.alloc(size);
127127
try {
128-
const len = CreateAssociatedTokenAccountInstructionDataLayout.encode(
129-
payload,
130-
buffer,
131-
);
128+
const len =
129+
CreateAssociatedTokenAccountInstructionDataLayout.encode(
130+
payload,
131+
buffer,
132+
);
132133
return Buffer.concat([discriminator, buffer.subarray(0, len)]);
133134
} catch (error) {
134135
if (!(error instanceof RangeError) || size >= 4096) {
@@ -160,16 +161,14 @@ export interface CreateAssociatedLightTokenAccountInstructionParams {
160161
* @param input.configAccount Config account (defaults to LIGHT_TOKEN_CONFIG).
161162
* @param input.rentPayerPda Rent payer PDA (defaults to LIGHT_TOKEN_RENT_SPONSOR).
162163
*/
163-
export function createAssociatedLightTokenAccountInstruction(
164-
{
165-
feePayer,
166-
owner,
167-
mint,
168-
compressibleConfig = DEFAULT_COMPRESSIBLE_CONFIG,
169-
configAccount = LIGHT_TOKEN_CONFIG,
170-
rentPayerPda = LIGHT_TOKEN_RENT_SPONSOR,
171-
}: CreateAssociatedLightTokenAccountInstructionParams,
172-
): TransactionInstruction {
164+
export function createAssociatedLightTokenAccountInstruction({
165+
feePayer,
166+
owner,
167+
mint,
168+
compressibleConfig = DEFAULT_COMPRESSIBLE_CONFIG,
169+
configAccount = LIGHT_TOKEN_CONFIG,
170+
rentPayerPda = LIGHT_TOKEN_RENT_SPONSOR,
171+
}: CreateAssociatedLightTokenAccountInstructionParams): TransactionInstruction {
173172
const effectiveFeePayer = feePayer ?? owner;
174173
const associatedTokenAccount = getAssociatedLightTokenAddress(owner, mint);
175174

@@ -235,16 +234,14 @@ export function createAssociatedLightTokenAccountInstruction(
235234
* @param input.configAccount Config account (defaults to LIGHT_TOKEN_CONFIG).
236235
* @param input.rentPayerPda Rent payer PDA (defaults to LIGHT_TOKEN_RENT_SPONSOR).
237236
*/
238-
export function createAssociatedLightTokenAccountIdempotentInstruction(
239-
{
240-
feePayer,
241-
owner,
242-
mint,
243-
compressibleConfig = DEFAULT_COMPRESSIBLE_CONFIG,
244-
configAccount = LIGHT_TOKEN_CONFIG,
245-
rentPayerPda = LIGHT_TOKEN_RENT_SPONSOR,
246-
}: CreateAssociatedLightTokenAccountInstructionParams,
247-
): TransactionInstruction {
237+
export function createAssociatedLightTokenAccountIdempotentInstruction({
238+
feePayer,
239+
owner,
240+
mint,
241+
compressibleConfig = DEFAULT_COMPRESSIBLE_CONFIG,
242+
configAccount = LIGHT_TOKEN_CONFIG,
243+
rentPayerPda = LIGHT_TOKEN_RENT_SPONSOR,
244+
}: CreateAssociatedLightTokenAccountInstructionParams): TransactionInstruction {
248245
const effectiveFeePayer = feePayer ?? owner;
249246
const associatedTokenAccount = getAssociatedLightTokenAddress(owner, mint);
250247

js/token-interface/src/instructions/burn.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ export function createBurnInstruction({
3737
isSigner: true,
3838
isWritable: effectivePayer.equals(authority),
3939
},
40-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
40+
{
41+
pubkey: SystemProgram.programId,
42+
isSigner: false,
43+
isWritable: false,
44+
},
4145
{
4246
pubkey: effectivePayer,
4347
isSigner: !effectivePayer.equals(authority),
@@ -73,7 +77,11 @@ export function createBurnCheckedInstruction({
7377
isSigner: true,
7478
isWritable: effectivePayer.equals(authority),
7579
},
76-
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
80+
{
81+
pubkey: SystemProgram.programId,
82+
isSigner: false,
83+
isWritable: false,
84+
},
7785
{
7886
pubkey: effectivePayer,
7987
isSigner: !effectivePayer.equals(authority),

0 commit comments

Comments
 (0)