Skip to content

Commit

Permalink
perf: optimze gMA
Browse files Browse the repository at this point in the history
  • Loading branch information
McSam94 committed Jan 17, 2024
1 parent 5463fde commit 7d45fff
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions ts-client/src/dlmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -898,17 +898,22 @@ export class DLMM {
this.pubkey,
this.program.programId
)[0];
const newLbPair = await this.program.account.lbPair.fetch(this.pubkey);
const [
lbPairAccountInfo,
binArrayBitmapExtensionAccountInfo,
reserveXAccountInfo,
reserveYAccountInfo,
] = await chunkedGetMultipleAccountInfos(this.program.provider.connection, [
this.pubkey,
binArrayBitmapExtensionPubkey,
newLbPair.reserveX,
newLbPair.reserveY,
this.lbPair.reserveX,
this.lbPair.reserveY,
]);

const lbPairState = this.program.coder.accounts.decode(
"lbPair",
lbPairAccountInfo.data
);
const binArrayBitmapExtensionState = this.program.coder.accounts.decode(
"binArrayBitmapExtension",
binArrayBitmapExtensionAccountInfo.data
Expand All @@ -923,24 +928,30 @@ export class DLMM {
const reserveXBalance = AccountLayout.decode(reserveXAccountInfo.data);
const reserveYBalance = AccountLayout.decode(reserveYAccountInfo.data);
const [tokenXDecimal, tokenYDecimal] = await Promise.all([
getTokenDecimals(this.program.provider.connection, newLbPair.tokenXMint),
getTokenDecimals(this.program.provider.connection, newLbPair.tokenYMint),
getTokenDecimals(
this.program.provider.connection,
lbPairState.tokenXMint
),
getTokenDecimals(
this.program.provider.connection,
lbPairState.tokenYMint
),
]);

this.tokenX = {
amount: reserveXBalance.amount,
decimal: tokenXDecimal,
publicKey: newLbPair.tokenXMint,
reserve: newLbPair.reserveX,
publicKey: lbPairState.tokenXMint,
reserve: lbPairState.reserveX,
};
this.tokenY = {
amount: reserveYBalance.amount,
decimal: tokenYDecimal,
publicKey: newLbPair.tokenYMint,
reserve: newLbPair.reserveY,
publicKey: lbPairState.tokenYMint,
reserve: lbPairState.reserveY,
};

this.lbPair = newLbPair;
this.lbPair = lbPairState;
}

/**
Expand Down

0 comments on commit 7d45fff

Please sign in to comment.