Skip to content

Commit

Permalink
fix: create ata idempotent before IF stake (#1293)
Browse files Browse the repository at this point in the history
* fix: create ata idempotent before IF stake

* fix: missed committing yarn.lock

* revert: tsc-watch changes for build watch
  • Loading branch information
LukasDeco authored Oct 29, 2024
1 parent 903a170 commit 6170c4f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions sdk/src/driftClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import bs58 from 'bs58';
import {
ASSOCIATED_TOKEN_PROGRAM_ID,
createAssociatedTokenAccountInstruction,
createAssociatedTokenAccountIdempotentInstruction,
createCloseAccountInstruction,
createInitializeAccountInstruction,
getAssociatedTokenAddress,
TOKEN_2022_PROGRAM_ID,
TOKEN_PROGRAM_ID,
getAssociatedTokenAddressSync,
} from '@solana/spl-token';
import {
DriftClientMetricsEvents,
Expand Down Expand Up @@ -7407,6 +7409,22 @@ export class DriftClient {
const createWSOLTokenAccount =
isSolMarket && collateralAccountPublicKey.equals(this.wallet.publicKey);

// create associated token account because it may not exist
const associatedTokenAccountPublicKey = getAssociatedTokenAddressSync(
spotMarketAccount.mint,
this.wallet.publicKey,
true
);

addIfStakeIxs.push(
await createAssociatedTokenAccountIdempotentInstruction(
this.wallet.publicKey,
associatedTokenAccountPublicKey,
this.wallet.publicKey,
spotMarketAccount.mint
)
);

let tokenAccount;

if (
Expand Down

0 comments on commit 6170c4f

Please sign in to comment.