Skip to content

Commit 4b751fd

Browse files
committed
better wsol handling
1 parent dfa0519 commit 4b751fd

File tree

1 file changed

+45
-30
lines changed

1 file changed

+45
-30
lines changed

sdk/src/driftClient.ts

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10818,7 +10818,8 @@ export class DriftClient {
1081810818
lpToBurn: BN;
1081910819
minAmountOut: BN;
1082010820
lpPool: LPPoolAccount;
10821-
}): Promise<TransactionInstruction> {
10821+
}): Promise<TransactionInstruction[]> {
10822+
const ixs: TransactionInstruction[] = [];
1082210823
const remainingAccounts = this.getRemainingAccounts({
1082310824
userAccounts: [],
1082410825
writableSpotMarketIndexes: [outMarketIndex],
@@ -10831,8 +10832,19 @@ export class DriftClient {
1083110832
lpPool.pubkey,
1083210833
outMarketIndex
1083310834
);
10835+
if (outMarketMint.equals(WRAPPED_SOL_MINT)) {
10836+
ixs.push(
10837+
createAssociatedTokenAccountIdempotentInstruction(
10838+
this.wallet.publicKey,
10839+
await this.getAssociatedTokenAccount(outMarketIndex, false),
10840+
this.wallet.publicKey,
10841+
WRAPPED_SOL_MINT
10842+
)
10843+
);
10844+
}
1083410845
const userOutTokenAccount = await this.getAssociatedTokenAccount(
10835-
outMarketIndex
10846+
outMarketIndex,
10847+
false
1083610848
);
1083710849
const constituentOutTokenAccount = getConstituentVaultPublicKey(
1083810850
this.program.programId,
@@ -10851,33 +10863,36 @@ export class DriftClient {
1085110863
lpPool.pubkey
1085210864
);
1085310865

10854-
return this.program.instruction.lpPoolRemoveLiquidity(
10855-
outMarketIndex,
10856-
lpToBurn,
10857-
minAmountOut,
10858-
{
10859-
remainingAccounts,
10860-
accounts: {
10861-
driftSigner: this.getSignerPublicKey(),
10862-
state: await this.getStatePublicKey(),
10863-
lpPool: lpPool.pubkey,
10864-
authority: this.wallet.publicKey,
10865-
outMarketMint,
10866-
outConstituent,
10867-
userOutTokenAccount,
10868-
constituentOutTokenAccount,
10869-
userLpTokenAccount,
10870-
lpMint,
10871-
lpPoolTokenVault: getLpPoolTokenVaultPublicKey(
10872-
this.program.programId,
10873-
lpPool.pubkey
10874-
),
10875-
constituentTargetBase,
10876-
tokenProgram: TOKEN_PROGRAM_ID,
10877-
ammCache: getAmmCachePublicKey(this.program.programId),
10878-
},
10879-
}
10866+
ixs.push(
10867+
this.program.instruction.lpPoolRemoveLiquidity(
10868+
outMarketIndex,
10869+
lpToBurn,
10870+
minAmountOut,
10871+
{
10872+
remainingAccounts,
10873+
accounts: {
10874+
driftSigner: this.getSignerPublicKey(),
10875+
state: await this.getStatePublicKey(),
10876+
lpPool: lpPool.pubkey,
10877+
authority: this.wallet.publicKey,
10878+
outMarketMint,
10879+
outConstituent,
10880+
userOutTokenAccount,
10881+
constituentOutTokenAccount,
10882+
userLpTokenAccount,
10883+
lpMint,
10884+
lpPoolTokenVault: getLpPoolTokenVaultPublicKey(
10885+
this.program.programId,
10886+
lpPool.pubkey
10887+
),
10888+
constituentTargetBase,
10889+
tokenProgram: TOKEN_PROGRAM_ID,
10890+
ammCache: getAmmCachePublicKey(this.program.programId),
10891+
},
10892+
}
10893+
)
1088010894
);
10895+
return ixs;
1088110896
}
1088210897

1088310898
public async viewLpPoolRemoveLiquidityFees({
@@ -11041,12 +11056,12 @@ export class DriftClient {
1104111056
);
1104211057
} else {
1104311058
ixs.push(
11044-
await this.getLpPoolRemoveLiquidityIx({
11059+
...(await this.getLpPoolRemoveLiquidityIx({
1104511060
outMarketIndex,
1104611061
lpToBurn,
1104711062
minAmountOut,
1104811063
lpPool,
11049-
})
11064+
}))
1105011065
);
1105111066
}
1105211067

0 commit comments

Comments
 (0)