Skip to content

Commit eae43fc

Browse files
use allowOwnerOffCurve=true flag for hi level functions
1 parent 5087dae commit eae43fc

18 files changed

Lines changed: 130 additions & 128 deletions

js/token-interface/src/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export async function getAtaOrNull({
130130
mint,
131131
commitment,
132132
}: GetAtaInput): Promise<TokenInterfaceAccount | null> {
133-
const address = getAssociatedTokenAddress(mint, owner);
133+
const address = getAssociatedTokenAddress(mint, owner, true);
134134

135135
const [hotInfo, compressedResult] = await Promise.all([
136136
rpc.getAccountInfo(address, commitment),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
CreateRawApproveInstructionInput,
77
} from '../types';
88
import { toBigIntAmount } from '../helpers';
9-
import { getAtaAddress } from '../read';
9+
import { getAssociatedTokenAddress } from '../read';
1010
import { createLoadInstructions } from './load';
1111
import { toInstructionPlan } from './_plan';
1212

@@ -76,7 +76,7 @@ async function _createApproveInstructions(
7676
}: CreateApproveInstructionsInput,
7777
wrap: boolean,
7878
): Promise<TransactionInstruction[]> {
79-
const tokenAccount = getAtaAddress({ owner, mint });
79+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
8080

8181
return [
8282
...(await createLoadInstructions({

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { LIGHT_TOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';
1313
import { struct, u8, u32, option, vec, array } from '@coral-xyz/borsh';
1414
import { LIGHT_TOKEN_CONFIG, LIGHT_TOKEN_RENT_SPONSOR } from '../constants';
1515
import { getAtaProgramId } from '../read/ata-utils';
16-
import { getAtaAddress } from '../read';
16+
import { getAssociatedTokenAddress } from '../read';
1717
import type { CreateRawAtaInstructionInput } from '../types';
1818
import { toInstructionPlan } from './_plan';
1919

@@ -410,11 +410,12 @@ export function createAtaInstruction({
410410
programId,
411411
}: CreateRawAtaInstructionInput): TransactionInstruction {
412412
const targetProgramId = programId ?? LIGHT_TOKEN_PROGRAM_ID;
413-
const associatedToken = getAtaAddress({
414-
owner,
413+
const associatedToken = getAssociatedTokenAddress(
415414
mint,
416-
programId: targetProgramId,
417-
});
415+
owner,
416+
true,
417+
targetProgramId,
418+
);
418419

419420
return createAtaIdempotent({
420421
payer,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
CreateRawBurnInstructionInput,
88
} from '../types';
99
import { toBigIntAmount } from '../helpers';
10-
import { getAtaAddress } from '../read';
10+
import { getAssociatedTokenAddress } from '../read';
1111
import { createLoadInstructions } from './load';
1212
import { toInstructionPlan } from './_plan';
1313

@@ -122,7 +122,7 @@ async function _createBurnInstructions(
122122
}: CreateBurnInstructionsInput,
123123
wrap: boolean,
124124
): Promise<TransactionInstruction[]> {
125-
const tokenAccount = getAtaAddress({ owner, mint });
125+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
126126

127127
const amountBn = toBigIntAmount(amount);
128128
const burnIx =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
CreateFreezeInstructionsInput,
66
CreateRawFreezeInstructionInput,
77
} from '../types';
8-
import { getAtaAddress } from '../read';
8+
import { getAssociatedTokenAddress } from '../read';
99
import { createLoadInstructions } from './load';
1010
import { toInstructionPlan } from './_plan';
1111

@@ -50,7 +50,7 @@ async function _createFreezeInstructions(
5050
{ rpc, payer, owner, mint, freezeAuthority }: CreateFreezeInstructionsInput,
5151
wrap: boolean,
5252
): Promise<TransactionInstruction[]> {
53-
const tokenAccount = getAtaAddress({ owner, mint });
53+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
5454

5555
return [
5656
...(await createLoadInstructions({

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import { getAtaProgramId, checkAtaAddress, AtaType } from '../read/ata-utils';
3030
import type { LoadOptions } from '../load-options';
3131
import { getMint } from '../read/get-mint';
3232
import { toLoadOptions } from '../helpers';
33-
import { getAtaAddress } from '../read';
3433
import type { CreateLoadInstructionsInput } from '../types';
3534
import { toInstructionPlan } from './_plan';
3635
import { createDecompressInstruction } from './load/decompress';
@@ -66,24 +65,24 @@ async function _buildLoadInstructions(
6665
const primaryColdCompressedAccount =
6766
selectPrimaryColdCompressedAccountForLoad(sources);
6867

69-
const lightTokenAtaAddress = getAssociatedTokenAddress(mint, owner);
68+
const lightTokenAtaAddress = getAssociatedTokenAddress(mint, owner, true);
7069
const splAta = getAssociatedTokenAddressSync(
7170
mint,
7271
owner,
73-
false,
72+
true,
7473
TOKEN_PROGRAM_ID,
7574
getAtaProgramId(TOKEN_PROGRAM_ID),
7675
);
7776
const t22Ata = getAssociatedTokenAddressSync(
7877
mint,
7978
owner,
80-
false,
79+
true,
8180
TOKEN_2022_PROGRAM_ID,
8281
getAtaProgramId(TOKEN_2022_PROGRAM_ID),
8382
);
8483

8584
let ataType: AtaType = 'light-token';
86-
const validation = checkAtaAddress(targetAta, mint, owner);
85+
const validation = checkAtaAddress(targetAta, mint, owner, undefined, true);
8786
ataType = validation.type;
8887
if (wrap && ataType !== 'light-token') {
8988
throw new Error(
@@ -344,7 +343,7 @@ export async function createLoadInstructions({
344343
splInterfaces,
345344
decimals,
346345
}: CreateLoadInstructionOptions): Promise<TransactionInstruction[]> {
347-
const targetAta = getAtaAddress({ owner, mint });
346+
const targetAta = getAssociatedTokenAddress(mint, owner, true);
348347
const loadOptions = buildLoadOptions(owner, authority, wrap, splInterfaces);
349348

350349
assertV2Enabled();
@@ -361,6 +360,7 @@ export async function createLoadInstructions({
361360
undefined,
362361
undefined,
363362
wrap,
363+
true,
364364
);
365365
} catch (e) {
366366
if (e instanceof TokenAccountNotFoundError) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
CreateRawRevokeInstructionInput,
66
CreateRevokeInstructionsInput,
77
} from '../types';
8-
import { getAtaAddress } from '../read';
8+
import { getAssociatedTokenAddress } from '../read';
99
import { createLoadInstructions } from './load';
1010
import { toInstructionPlan } from './_plan';
1111

@@ -56,7 +56,7 @@ async function _createRevokeInstructions(
5656
{ rpc, payer, owner, mint }: CreateRevokeInstructionsInput,
5757
wrap: boolean,
5858
): Promise<TransactionInstruction[]> {
59-
const tokenAccount = getAtaAddress({ owner, mint });
59+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
6060

6161
return [
6262
...(await createLoadInstructions({

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
CreateRawThawInstructionInput,
66
CreateThawInstructionsInput,
77
} from '../types';
8-
import { getAtaAddress } from '../read';
8+
import { getAssociatedTokenAddress } from '../read';
99
import { createLoadInstructions } from './load';
1010
import { toInstructionPlan } from './_plan';
1111

@@ -50,7 +50,7 @@ async function _createThawInstructions(
5050
{ rpc, payer, owner, mint, freezeAuthority }: CreateThawInstructionsInput,
5151
wrap: boolean,
5252
): Promise<TransactionInstruction[]> {
53-
const tokenAccount = getAtaAddress({ owner, mint });
53+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
5454

5555
return [
5656
...(await createLoadInstructions({

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { LIGHT_TOKEN_PROGRAM_ID } from '@lightprotocol/stateless.js';
44
import { getSplInterfaces } from '../spl-interface';
55
import { createUnwrapInstruction } from './unwrap';
66
import { getMintDecimals, toBigIntAmount } from '../helpers';
7-
import { getAtaAddress } from '../read';
7+
import { getAssociatedTokenAddress } from '../read';
88
import type {
99
CreateRawTransferInstructionInput,
1010
CreateTransferInstructionsInput,
@@ -123,15 +123,13 @@ async function _createTransferInstructions(
123123
decimals,
124124
splInterfaces: transferSplInterfaces,
125125
});
126-
const recipientAta = getAtaAddress({
127-
owner: recipient,
126+
const recipientAta = getAssociatedTokenAddress(
128127
mint,
129-
programId: recipientTokenProgramId,
130-
});
131-
const senderAta = getAtaAddress({
132-
owner: sourceOwner,
133-
mint,
134-
});
128+
recipient,
129+
true,
130+
recipientTokenProgramId,
131+
);
132+
const senderAta = getAssociatedTokenAddress(mint, sourceOwner, true);
135133

136134
let transferInstruction: TransactionInstruction;
137135
if (recipientTokenProgramId.equals(LIGHT_TOKEN_PROGRAM_ID)) {

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from '../types';
1212
import { toInstructionPlan } from '../instructions/_plan';
1313
import { createLoadInstructions as createLoadInstructionsDefault } from '../instructions/load';
14-
import { getAtaAddress } from '../read';
14+
import { getAssociatedTokenAddress } from '../read';
1515
import { toBigIntAmount, getMintDecimals } from '../helpers';
1616
import { createTransferCheckedInstruction } from '../instructions/transfer';
1717
import { getSplInterfaces } from '../spl-interface';
@@ -76,15 +76,13 @@ export async function createTransferInstructions(
7676
splInterfaces: transferSplInterfaces,
7777
});
7878

79-
const recipientAta = getAtaAddress({
80-
owner: recipient,
79+
const recipientAta = getAssociatedTokenAddress(
8180
mint,
82-
programId: recipientTokenProgramId,
83-
});
84-
const senderAta = getAtaAddress({
85-
owner: sourceOwner,
86-
mint,
87-
});
81+
recipient,
82+
true,
83+
recipientTokenProgramId,
84+
);
85+
const senderAta = getAssociatedTokenAddress(mint, sourceOwner, true);
8886

8987
let transferInstruction: TransactionInstruction;
9088
if (recipientTokenProgramId.equals(LIGHT_TOKEN_PROGRAM_ID)) {
@@ -132,7 +130,7 @@ export async function createApproveInstructions(
132130
input: CreateApproveInstructionsInput,
133131
): Promise<TransactionInstruction[]> {
134132
const { rpc, payer, owner, mint, delegate, amount } = input;
135-
const tokenAccount = getAtaAddress({ owner, mint });
133+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
136134

137135
return [
138136
...(await createLoadInstructionsDefault({
@@ -156,7 +154,7 @@ export async function createRevokeInstructions(
156154
input: CreateRevokeInstructionsInput,
157155
): Promise<TransactionInstruction[]> {
158156
const { rpc, payer, owner, mint } = input;
159-
const tokenAccount = getAtaAddress({ owner, mint });
157+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
160158

161159
return [
162160
...(await createLoadInstructionsDefault({
@@ -178,7 +176,7 @@ export async function createBurnInstructions(
178176
input: CreateBurnInstructionsInput,
179177
): Promise<TransactionInstruction[]> {
180178
const { rpc, payer, owner, mint, authority, amount, decimals } = input;
181-
const tokenAccount = getAtaAddress({ owner, mint });
179+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
182180

183181
const amountBn = toBigIntAmount(amount);
184182
const burnIx =
@@ -216,7 +214,7 @@ export async function createFreezeInstructions(
216214
input: CreateFreezeInstructionsInput,
217215
): Promise<TransactionInstruction[]> {
218216
const { rpc, payer, owner, mint, freezeAuthority } = input;
219-
const tokenAccount = getAtaAddress({ owner, mint });
217+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
220218

221219
return [
222220
...(await createLoadInstructionsDefault({
@@ -238,7 +236,7 @@ export async function createThawInstructions(
238236
input: CreateThawInstructionsInput,
239237
): Promise<TransactionInstruction[]> {
240238
const { rpc, payer, owner, mint, freezeAuthority } = input;
241-
const tokenAccount = getAtaAddress({ owner, mint });
239+
const tokenAccount = getAssociatedTokenAddress(mint, owner, true);
242240

243241
return [
244242
...(await createLoadInstructionsDefault({

0 commit comments

Comments
 (0)