Skip to content

Commit

Permalink
[token-js] Switch to associated token address sync. (solana-labs#4114)
Browse files Browse the repository at this point in the history
  • Loading branch information
fedorerd authored and HaoranYi committed Jul 19, 2023
1 parent 662e365 commit 277e5cf
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions token/js/src/actions/createAssociatedTokenAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ConfirmOptions, Connection, PublicKey, Signer } from '@solana/web3
import { sendAndConfirmTransaction, Transaction } from '@solana/web3.js';
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '../constants.js';
import { createAssociatedTokenAccountInstruction } from '../instructions/associatedTokenAccount.js';
import { getAssociatedTokenAddress } from '../state/mint.js';
import { getAssociatedTokenAddressSync } from '../state/mint.js';

/**
* Create and initialize a new associated token account
Expand All @@ -26,7 +26,7 @@ export async function createAssociatedTokenAccount(
programId = TOKEN_PROGRAM_ID,
associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
): Promise<PublicKey> {
const associatedToken = await getAssociatedTokenAddress(mint, owner, false, programId, associatedTokenProgramId);
const associatedToken = getAssociatedTokenAddressSync(mint, owner, false, programId, associatedTokenProgramId);

const transaction = new Transaction().add(
createAssociatedTokenAccountInstruction(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ConfirmOptions, Connection, PublicKey, Signer } from '@solana/web3
import { sendAndConfirmTransaction, Transaction } from '@solana/web3.js';
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '../constants.js';
import { createAssociatedTokenAccountIdempotentInstruction } from '../instructions/associatedTokenAccount.js';
import { getAssociatedTokenAddress } from '../state/mint.js';
import { getAssociatedTokenAddressSync } from '../state/mint.js';

/**
* Create and initialize a new associated token account
Expand All @@ -27,7 +27,7 @@ export async function createAssociatedTokenAccountIdempotent(
programId = TOKEN_PROGRAM_ID,
associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
): Promise<PublicKey> {
const associatedToken = await getAssociatedTokenAddress(mint, owner, false, programId, associatedTokenProgramId);
const associatedToken = getAssociatedTokenAddressSync(mint, owner, false, programId, associatedTokenProgramId);

const transaction = new Transaction().add(
createAssociatedTokenAccountIdempotentInstruction(
Expand Down
4 changes: 2 additions & 2 deletions token/js/src/actions/createWrappedNativeAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createAssociatedTokenAccountInstruction } from '../instructions/associa
import { createInitializeAccountInstruction } from '../instructions/initializeAccount.js';
import { createSyncNativeInstruction } from '../instructions/syncNative.js';
import { ACCOUNT_SIZE, getMinimumBalanceForRentExemptAccount } from '../state/account.js';
import { getAssociatedTokenAddress } from '../state/mint.js';
import { getAssociatedTokenAddressSync } from '../state/mint.js';
import { createAccount } from './createAccount.js';

/**
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function createWrappedNativeAccount(

// If a keypair isn't provided, create the account at the owner's ATA for the native mint and return its address
if (!keypair) {
const associatedToken = await getAssociatedTokenAddress(
const associatedToken = getAssociatedTokenAddressSync(
nativeMint,
owner,
false,
Expand Down
4 changes: 2 additions & 2 deletions token/js/src/actions/getOrCreateAssociatedTokenAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { createAssociatedTokenAccountInstruction } from '../instructions/associatedTokenAccount.js';
import type { Account } from '../state/account.js';
import { getAccount } from '../state/account.js';
import { getAssociatedTokenAddress } from '../state/mint.js';
import { getAssociatedTokenAddressSync } from '../state/mint.js';

/**
* Retrieve the associated token account, or create it if it doesn't exist
Expand Down Expand Up @@ -38,7 +38,7 @@ export async function getOrCreateAssociatedTokenAccount(
programId = TOKEN_PROGRAM_ID,
associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID
): Promise<Account> {
const associatedToken = await getAssociatedTokenAddress(
const associatedToken = getAssociatedTokenAddressSync(
mint,
owner,
allowOwnerOffCurve,
Expand Down

0 comments on commit 277e5cf

Please sign in to comment.