Skip to content

Commit

Permalink
add short createAssociatedTokenAccountIdempotentInstruction
Browse files Browse the repository at this point in the history
  • Loading branch information
zzau13 committed Aug 22, 2024
1 parent e7c0781 commit f3e528c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions token/js/src/instructions/associatedTokenAccount.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { PublicKey } from '@solana/web3.js';
import { SystemProgram, TransactionInstruction } from '@solana/web3.js';
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '../constants.js';
import { getAssociatedTokenAddressSync } from '../state/mint.js';

/**
* Construct a CreateAssociatedTokenAccount instruction
Expand Down Expand Up @@ -64,6 +65,31 @@ export function createAssociatedTokenAccountIdempotentInstruction(
);
}

/**
* Construct a createAssociatedTokenAccountIdempotentInstructionShort instruction
*
* @param payer Payer of the initialization fees
* @param owner Owner of the new account
* @param mint Token mint account
* @param allowOwnerOffCurve Allow the owner account to be a PDA (Program Derived Address)
* @param programId SPL Token program account
* @param associatedTokenProgramId SPL Associated Token program account
*
* @return Instruction to add to a transaction
*/
export function createAssociatedTokenAccountIdempotentInstructionShort(
payer: PublicKey,
owner: PublicKey,
mint: PublicKey,
allowOwnerOffCurve = true,
programId = TOKEN_PROGRAM_ID,
associatedTokenProgramId = ASSOCIATED_TOKEN_PROGRAM_ID,
) {
const associatedToken = getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve);

return createAssociatedTokenAccountIdempotentInstruction(payer, owner, mint, programId, associatedTokenProgramId);
}

function buildAssociatedTokenAccountInstruction(
payer: PublicKey,
associatedToken: PublicKey,
Expand Down

0 comments on commit f3e528c

Please sign in to comment.