Skip to content

Commit

Permalink
fix: Update seedLiquidityByOperator test
Browse files Browse the repository at this point in the history
  • Loading branch information
quangkeu95 committed Dec 19, 2024
1 parent 62bf4d6 commit 9e9fef6
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 280 deletions.
28 changes: 21 additions & 7 deletions ts-client/src/dlmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import {
PositionV2,
PositionVersion,
ProgramStrategyParameter,
SeedLiquidityByOperatorResponse,
SeedLiquidityResponse,
SwapExactOutParams,
SwapFee,
Expand Down Expand Up @@ -4475,7 +4476,7 @@ export class DLMM {
operator: PublicKey,
lockReleasePoint: BN,
shouldSeedPositionOwner: boolean = false
): Promise<SeedLiquidityResponse> {
): Promise<SeedLiquidityByOperatorResponse> {
const toLamportMultiplier = new Decimal(
10 ** (this.tokenY.decimal - this.tokenX.decimal)
);
Expand Down Expand Up @@ -4533,10 +4534,22 @@ export class DLMM {
// This amount will be deposited to the last bin without compression
const positionCount = getPositionCount(minBinId, maxBinId.sub(new BN(1)));

const initializeBinArraysAndPositionIxs = [];
const preflightIxs: Array<TransactionInstruction> = [];
const initializeBinArraysAndPositionIxs: Array<Array<TransactionInstruction>> = [];
const addLiquidityIxs = [];
const appendedInitBinArrayIx = new Set();

const { ataPubKey: userTokenX, ix: createPayerTokenXIx } =
await getOrCreateATAInstruction(
this.program.provider.connection,
this.lbPair.tokenXMint,
operator,
payer
);

// create userTokenX account
createPayerTokenXIx && preflightIxs.push(createPayerTokenXIx);

const operatorTokenX = getAssociatedTokenAddressSync(
this.lbPair.tokenXMint,
operator,
Expand All @@ -4555,15 +4568,15 @@ export class DLMM {
if (account.amount == BigInt(0)) {
// send 1 lamport to position owner token X to prove ownership
const transferIx = createTransferInstruction(operatorTokenX, positionOwnerTokenX, payer, 1);
initializeBinArraysAndPositionIxs.push(transferIx);
preflightIxs.push(transferIx);
}
} else {
const createPositionOwnerTokenXIx = createAssociatedTokenAccountInstruction(payer, positionOwnerTokenX, positionOwner, this.lbPair.tokenXMint);
initializeBinArraysAndPositionIxs.push(createPositionOwnerTokenXIx);
preflightIxs.push(createPositionOwnerTokenXIx);

// send 1 lamport to position owner token X to prove ownership
const transferIx = createTransferInstruction(operatorTokenX, positionOwnerTokenX, payer, 1);
initializeBinArraysAndPositionIxs.push(transferIx);
preflightIxs.push(transferIx);
}
}

Expand Down Expand Up @@ -4712,7 +4725,7 @@ export class DLMM {
binArrayBitmapExtension: this.binArrayBitmapExtension
? this.binArrayBitmapExtension.publicKey
: this.program.programId,
userToken: positionOwnerTokenX,
userToken: userTokenX,
reserve: this.lbPair.reserveX,
tokenMint: this.lbPair.tokenXMint,
binArrayLower: lowerBinArray,
Expand Down Expand Up @@ -4743,7 +4756,7 @@ export class DLMM {
binArrayBitmapExtension: this.binArrayBitmapExtension
? this.binArrayBitmapExtension.publicKey
: this.program.programId,
userToken: positionOwnerTokenX,
userToken: userTokenX,
reserve: this.lbPair.reserveX,
tokenMint: this.lbPair.tokenXMint,
binArrayLower: lowerBinArray,
Expand All @@ -4764,6 +4777,7 @@ export class DLMM {
}

return {
preflightIxs,
initializeBinArraysAndPositionIxs,
addLiquidityIxs,
};
Expand Down
6 changes: 6 additions & 0 deletions ts-client/src/dlmm/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,12 @@ export interface SeedLiquidityResponse {
addLiquidityIxs: TransactionInstruction[][];
}

export interface SeedLiquidityByOperatorResponse {
preflightIxs: TransactionInstruction[];
initializeBinArraysAndPositionIxs: TransactionInstruction[][];
addLiquidityIxs: TransactionInstruction[][];
}

export interface Clock {
slot: BN;
epochStartTimestamp: BN;
Expand Down
Loading

0 comments on commit 9e9fef6

Please sign in to comment.