Skip to content

Commit 8757c93

Browse files
committed
add new bulk instruction packaging
1 parent 010c210 commit 8757c93

File tree

2 files changed

+64
-41
lines changed

2 files changed

+64
-41
lines changed

sdk/src/driftClient.ts

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10478,15 +10478,7 @@ export class DriftClient {
1047810478
inAmount: BN,
1047910479
minOutAmount: BN,
1048010480
lpPool: PublicKey,
10481-
constituentTargetBase: PublicKey,
10482-
constituentInTokenAccount: PublicKey,
10483-
constituentOutTokenAccount: PublicKey,
10484-
userInTokenAccount: PublicKey,
10485-
userOutTokenAccount: PublicKey,
10486-
inConstituent: PublicKey,
10487-
outConstituent: PublicKey,
10488-
inMarketMint: PublicKey,
10489-
outMarketMint: PublicKey,
10481+
userAuthority: PublicKey,
1049010482
txParams?: TxParams
1049110483
): Promise<TransactionSignature> {
1049210484
const { txSig } = await this.sendTransaction(
@@ -10497,15 +10489,7 @@ export class DriftClient {
1049710489
inAmount,
1049810490
minOutAmount,
1049910491
lpPool,
10500-
constituentTargetBase,
10501-
constituentInTokenAccount,
10502-
constituentOutTokenAccount,
10503-
userInTokenAccount,
10504-
userOutTokenAccount,
10505-
inConstituent,
10506-
outConstituent,
10507-
inMarketMint,
10508-
outMarketMint
10492+
userAuthority
1050910493
),
1051010494
txParams
1051110495
),
@@ -10521,21 +10505,49 @@ export class DriftClient {
1052110505
inAmount: BN,
1052210506
minOutAmount: BN,
1052310507
lpPool: PublicKey,
10524-
constituentTargetBase: PublicKey,
10525-
constituentInTokenAccount: PublicKey,
10526-
constituentOutTokenAccount: PublicKey,
10527-
userInTokenAccount: PublicKey,
10528-
userOutTokenAccount: PublicKey,
10529-
inConstituent: PublicKey,
10530-
outConstituent: PublicKey,
10531-
inMarketMint: PublicKey,
10532-
outMarketMint: PublicKey
10508+
userAuthority: PublicKey
1053310509
): Promise<TransactionInstruction> {
1053410510
const remainingAccounts = this.getRemainingAccounts({
1053510511
userAccounts: [],
1053610512
readableSpotMarketIndexes: [inMarketIndex, outMarketIndex],
1053710513
});
1053810514

10515+
const constituentInTokenAccount = getConstituentVaultPublicKey(
10516+
this.program.programId,
10517+
lpPool,
10518+
inMarketIndex
10519+
);
10520+
const constituentOutTokenAccount = getConstituentVaultPublicKey(
10521+
this.program.programId,
10522+
lpPool,
10523+
outMarketIndex
10524+
);
10525+
const userInTokenAccount = await getAssociatedTokenAddress(
10526+
this.getSpotMarketAccount(inMarketIndex).mint,
10527+
userAuthority
10528+
);
10529+
const userOutTokenAccount = await getAssociatedTokenAddress(
10530+
this.getSpotMarketAccount(outMarketIndex).mint,
10531+
userAuthority
10532+
);
10533+
const inConstituent = getConstituentPublicKey(
10534+
this.program.programId,
10535+
lpPool,
10536+
inMarketIndex
10537+
);
10538+
const outConstituent = getConstituentPublicKey(
10539+
this.program.programId,
10540+
lpPool,
10541+
outMarketIndex
10542+
);
10543+
const inMarketMint = this.getSpotMarketAccount(inMarketIndex).mint;
10544+
const outMarketMint = this.getSpotMarketAccount(outMarketIndex).mint;
10545+
10546+
const constituentTargetBase = getConstituentTargetBasePublicKey(
10547+
this.program.programId,
10548+
lpPool
10549+
);
10550+
1053910551
return this.program.instruction.lpPoolSwap(
1054010552
inMarketIndex,
1054110553
outMarketIndex,
@@ -11245,6 +11257,30 @@ export class DriftClient {
1124511257
return ixs;
1124611258
}
1124711259

11260+
async getAllLpPoolSwapIxs(
11261+
lpPool: LPPoolAccount,
11262+
constituentMap: ConstituentMap,
11263+
inMarketIndex: number,
11264+
outMarketIndex: number,
11265+
inAmount: BN,
11266+
minOutAmount: BN,
11267+
userAuthority: PublicKey
11268+
): Promise<TransactionInstruction[]> {
11269+
const ixs: TransactionInstruction[] = [];
11270+
ixs.push(...(await this.getAllUpdateLpPoolAumIxs(lpPool, constituentMap)));
11271+
ixs.push(
11272+
await this.getLpPoolSwapIx(
11273+
inMarketIndex,
11274+
outMarketIndex,
11275+
inAmount,
11276+
minOutAmount,
11277+
lpPool.pubkey,
11278+
userAuthority
11279+
)
11280+
);
11281+
return ixs;
11282+
}
11283+
1124811284
async settlePerpToLpPool(
1124911285
lpPoolName: number[],
1125011286
perpMarketIndexes: number[]

tests/lpPoolSwap.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,6 @@ describe('LP Pool', () => {
425425
expect(lpPool2.lastAum.gt(lpPool1.lastAum)).to.be.true;
426426
console.log(`AUM: ${convertToNumber(lpPool2.lastAum, QUOTE_PRECISION)}`);
427427

428-
const constituentTargetWeightsPublicKey = getConstituentTargetBasePublicKey(
429-
program.programId,
430-
lpPoolKey
431-
);
432-
433428
// swap c0 for c1
434429

435430
const adminAuth = adminClient.wallet.publicKey;
@@ -467,15 +462,7 @@ describe('LP Pool', () => {
467462
new BN(224_300_000),
468463
new BN(0),
469464
lpPoolKey,
470-
constituentTargetWeightsPublicKey,
471-
const0TokenAccount,
472-
const1TokenAccount,
473-
c0UserTokenAccount,
474-
c1UserTokenAccount,
475-
const0Key,
476-
const1Key,
477-
usdcMint.publicKey,
478-
spotTokenMint.publicKey
465+
adminAuth
479466
)
480467
);
481468

0 commit comments

Comments
 (0)