Skip to content

Commit

Permalink
Merge pull request #43 from MeteoraAg/fix-bn-assertion
Browse files Browse the repository at this point in the history
Fix/bn assertion
  • Loading branch information
00xSam authored Mar 26, 2024
2 parents 245c24f + 3128672 commit c74cd6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ts-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@meteora-ag/dlmm",
"version": "1.0.21-rc.1",
"version": "1.0.22",
"description": "",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down Expand Up @@ -41,4 +41,4 @@
"keywords": [],
"author": "McSam",
"license": "ISC"
}
}
22 changes: 11 additions & 11 deletions ts-client/src/dlmm/helpers/weightToAmounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ export function toAmountBothSide(
totalWeightX = totalWeightX.add(weighPerPrice);
}
});
const kx = new Decimal(amountX.toNumber()).div(totalWeightX);
const ky = new Decimal(amountY.toNumber()).div(totalWeightY);
const kx = new Decimal(amountX.toString()).div(totalWeightX);
const ky = new Decimal(amountY.toString()).div(totalWeightY);
let k = (kx.lessThan(ky) ? kx : ky);
return distributions.map((bin) => {
if (bin.binId < activeId) {
const amount = k.mul(new Decimal(bin.weight));
return {
binId: bin.binId,
amountX: new BN(0),
amountY: new BN(Math.floor(amount.toNumber())),
amountY: new BN(amount.floor().toString()),
};
}
if (bin.binId > activeId) {
Expand All @@ -148,7 +148,7 @@ export function toAmountBothSide(
const amount = k.mul(weighPerPrice);
return {
binId: bin.binId,
amountX: new BN(Math.floor(amount.toNumber())),
amountX: new BN(amount.floor().toString()),
amountY: new BN(0),
};
}
Expand All @@ -157,8 +157,8 @@ export function toAmountBothSide(
const amountYActiveBin = k.mul(wy0);
return {
binId: bin.binId,
amountX: new BN(Math.floor(amountXActiveBin.toNumber())),
amountY: new BN(Math.floor(amountYActiveBin.toNumber())),
amountX: new BN(amountXActiveBin.floor().toString()),
amountY: new BN(amountYActiveBin.floor().toString()),
};
});
} else {
Expand All @@ -174,8 +174,8 @@ export function toAmountBothSide(
}
});

let kx = new Decimal(amountX.toNumber()).div(totalWeightX);
let ky = new Decimal(amountY.toNumber()).div(totalWeightY);
let kx = new Decimal(amountX.toString()).div(totalWeightX);
let ky = new Decimal(amountY.toString()).div(totalWeightY);
let k = kx.lessThan(ky) ? kx : ky;

return distributions.map((bin) => {
Expand All @@ -184,15 +184,15 @@ export function toAmountBothSide(
return {
binId: bin.binId,
amountX: new BN(0),
amountY: new BN(Math.floor(amount.toNumber())),
amountY: new BN(amount.floor().toString()),
};
} else {
let price = getPriceOfBinByBinId(bin.binId, binStep);
let weighPerPrice = new Decimal(bin.weight).div(price);
const amount = k.mul(weighPerPrice);
return {
binId: bin.binId,
amountX: new BN(Math.floor(amount.toNumber())),
amountX: new BN(amount.floor().toString()),
amountY: new BN(0),
};
}
Expand Down Expand Up @@ -336,7 +336,7 @@ export function autoFillXByWeight(
totalWeightX = totalWeightX.add(weighPerPrice);
}
});
const ky = totalWeightY.isZero() ? new Decimal(1) : new Decimal(amountY.toNumber()).div(totalWeightY);
const ky = totalWeightY.isZero() ? new Decimal(1) : new Decimal(amountY.toString()).div(totalWeightY);
const amountX = ky.mul(totalWeightX);
return new BN(amountX.floor().toString())
}
Expand Down

0 comments on commit c74cd6c

Please sign in to comment.