Skip to content

Commit

Permalink
fix: quote end price (#143)
Browse files Browse the repository at this point in the history
* fix: quote end price

* fix: remove unused account fetch in swap

* fix: remove unused account fetch in swapWithPriceImpact
  • Loading branch information
codewithgun authored Jan 3, 2025
1 parent 7254fd1 commit a590d77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## @meteora-ag/dlmm [1.3.7] - PR #143

### Fixed

- Fix `swapQuote` end price

## @meteora-ag/dlmm [1.3.6] - PR #116

### Changed

- Refactored; remove `position(V1)` interaction from SDK
- Throw error in `removeLiquidity` function if position doesn't have any liquidity

### Fixed

- Removed unused rpc call in `swap`

### Added

- Function `getPosition` to retrieve a single position data
Expand Down
2 changes: 1 addition & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteora-ag/dlmm",
"version": "1.3.6",
"version": "1.3.7",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
37 changes: 15 additions & 22 deletions ts-client/src/dlmm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3157,6 +3157,7 @@ export class DLMM {
let actualOutAmount: BN = new BN(0);
let feeAmount: BN = new BN(0);
let protocolFeeAmount: BN = new BN(0);
let lastFilledActiveBinId = activeId;

while (!inAmountLeft.isZero()) {
let binArrayAccountToSwap = findNextBinArrayWithLiquidity(
Expand Down Expand Up @@ -3211,6 +3212,8 @@ export class DLMM {
if (!startBin) {
startBin = bin;
}

lastFilledActiveBinId = activeId;
}
}

Expand Down Expand Up @@ -3249,8 +3252,9 @@ export class DLMM {
const minOutAmount = actualOutAmount
.mul(new BN(BASIS_POINT_MAX).sub(allowedSlippage))
.div(new BN(BASIS_POINT_MAX));

const endPrice = getPriceOfBinByBinId(
activeId.toNumber(),
lastFilledActiveBinId.toNumber(),
this.lbPair.binStep
);

Expand Down Expand Up @@ -3389,9 +3393,6 @@ export class DLMM {
priceImpact,
binArraysPubkey,
}: SwapWithPriceImpactParams): Promise<Transaction> {
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } =
await this.program.account.lbPair.fetch(lbPair);

const preInstructions: TransactionInstruction[] = [];
const postInstructions: Array<TransactionInstruction> = [];

Expand Down Expand Up @@ -3430,9 +3431,6 @@ export class DLMM {
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
}

let swapForY = true;
if (outToken.equals(tokenXMint)) swapForY = false;

// TODO: needs some refinement in case binArray not yet initialized
const binArrays: AccountMeta[] = binArraysPubkey.map((pubkey) => {
return {
Expand All @@ -3450,10 +3448,10 @@ export class DLMM {
)
.accounts({
lbPair,
reserveX,
reserveY,
tokenXMint,
tokenYMint,
reserveX: this.lbPair.reserveX,
reserveY: this.lbPair.reserveY,
tokenXMint: this.lbPair.tokenXMint,
tokenYMint: this.lbPair.tokenYMint,
tokenXProgram: TOKEN_PROGRAM_ID,
tokenYProgram: TOKEN_PROGRAM_ID,
user,
Expand All @@ -3462,7 +3460,7 @@ export class DLMM {
binArrayBitmapExtension: this.binArrayBitmapExtension
? this.binArrayBitmapExtension.publicKey
: null,
oracle,
oracle: this.lbPair.oracle,
hostFeeIn: null,
})
.remainingAccounts(binArrays)
Expand Down Expand Up @@ -3508,9 +3506,6 @@ export class DLMM {
user,
binArraysPubkey,
}: SwapParams): Promise<Transaction> {
const { tokenXMint, tokenYMint, reserveX, reserveY, activeId, oracle } =
await this.program.account.lbPair.fetch(lbPair);

const preInstructions: TransactionInstruction[] = [];
const postInstructions: Array<TransactionInstruction> = [];

Expand Down Expand Up @@ -3549,8 +3544,6 @@ export class DLMM {
closeWrappedSOLIx && postInstructions.push(closeWrappedSOLIx);
}

let swapForY = true;
if (outToken.equals(tokenXMint)) swapForY = false;

// TODO: needs some refinement in case binArray not yet initialized
const binArrays: AccountMeta[] = binArraysPubkey.map((pubkey) => {
Expand All @@ -3565,10 +3558,10 @@ export class DLMM {
.swap(inAmount, minOutAmount)
.accounts({
lbPair,
reserveX,
reserveY,
tokenXMint,
tokenYMint,
reserveX: this.lbPair.reserveX,
reserveY: this.lbPair.reserveY,
tokenXMint: this.lbPair.tokenXMint,
tokenYMint: this.lbPair.tokenYMint,
tokenXProgram: TOKEN_PROGRAM_ID, // dont use 2022 first; lack familiarity
tokenYProgram: TOKEN_PROGRAM_ID, // dont use 2022 first; lack familiarity
user,
Expand All @@ -3577,7 +3570,7 @@ export class DLMM {
binArrayBitmapExtension: this.binArrayBitmapExtension
? this.binArrayBitmapExtension.publicKey
: null,
oracle,
oracle: this.lbPair.oracle,
hostFeeIn: null,
})
.remainingAccounts(binArrays)
Expand Down

0 comments on commit a590d77

Please sign in to comment.