@magmaprotocol/magma-clmm-sdk 0.5.83 → 0.5.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +201 -111
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -37,7 +37,7 @@ var CachedContent = class {
|
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
// src/utils/common.ts
|
|
40
|
-
import
|
|
40
|
+
import BN13 from "bn.js";
|
|
41
41
|
import { fromB64, fromHEX } from "@mysten/bcs";
|
|
42
42
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519";
|
|
43
43
|
import { Secp256k1Keypair } from "@mysten/sui/keypairs/secp256k1";
|
|
@@ -1592,6 +1592,9 @@ function collectFeesQuote(param) {
|
|
|
1592
1592
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1593
1593
|
}
|
|
1594
1594
|
|
|
1595
|
+
// src/math/dlmmStrategy.ts
|
|
1596
|
+
import BN10 from "bn.js";
|
|
1597
|
+
|
|
1595
1598
|
// src/math/dlmmWeightToAmounts.ts
|
|
1596
1599
|
import BN9 from "bn.js";
|
|
1597
1600
|
import Decimal3 from "decimal.js";
|
|
@@ -2008,40 +2011,127 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
2008
2011
|
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2009
2012
|
}
|
|
2010
2013
|
}
|
|
2014
|
+
function assignLeftAmountX(activeId, binStep, maxBinId, amountX, strategyType) {
|
|
2015
|
+
let weights = [];
|
|
2016
|
+
switch (strategyType) {
|
|
2017
|
+
case 1 /* Spot */: {
|
|
2018
|
+
weights = toWeightSpotBalanced(activeId, maxBinId);
|
|
2019
|
+
break;
|
|
2020
|
+
}
|
|
2021
|
+
case 2 /* Curve */: {
|
|
2022
|
+
weights = toWeightDecendingOrder(activeId, maxBinId);
|
|
2023
|
+
break;
|
|
2024
|
+
}
|
|
2025
|
+
case 3 /* BidAsk */: {
|
|
2026
|
+
weights = toWeightAscendingOrder(activeId, maxBinId);
|
|
2027
|
+
break;
|
|
2028
|
+
}
|
|
2029
|
+
}
|
|
2030
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2031
|
+
return amounts.map((bin) => {
|
|
2032
|
+
return {
|
|
2033
|
+
binId: bin.binId,
|
|
2034
|
+
amountX: bin.amount,
|
|
2035
|
+
amountY: new BN10(0)
|
|
2036
|
+
};
|
|
2037
|
+
});
|
|
2038
|
+
}
|
|
2039
|
+
function assignLeftAmountY(activeId, minBinId, amountY, strategyType) {
|
|
2040
|
+
let weights = [];
|
|
2041
|
+
switch (strategyType) {
|
|
2042
|
+
case 1 /* Spot */: {
|
|
2043
|
+
weights = toWeightSpotBalanced(minBinId, activeId);
|
|
2044
|
+
break;
|
|
2045
|
+
}
|
|
2046
|
+
case 2 /* Curve */: {
|
|
2047
|
+
weights = toWeightAscendingOrder(minBinId, activeId);
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
case 3 /* BidAsk */: {
|
|
2051
|
+
weights = toWeightDecendingOrder(minBinId, activeId);
|
|
2052
|
+
break;
|
|
2053
|
+
}
|
|
2054
|
+
}
|
|
2055
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2056
|
+
return amounts.map((bin) => {
|
|
2057
|
+
return {
|
|
2058
|
+
binId: bin.binId,
|
|
2059
|
+
amountX: new BN10(0),
|
|
2060
|
+
amountY: bin.amount
|
|
2061
|
+
};
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
function mergeBinDisplay(to, from) {
|
|
2065
|
+
const binMap = /* @__PURE__ */ new Map();
|
|
2066
|
+
for (const bin of to) {
|
|
2067
|
+
binMap.set(bin.binId, bin);
|
|
2068
|
+
}
|
|
2069
|
+
for (const bin of from) {
|
|
2070
|
+
const existingBin = binMap.get(bin.binId);
|
|
2071
|
+
if (existingBin) {
|
|
2072
|
+
existingBin.amountX = existingBin.amountX.add(bin.amountX);
|
|
2073
|
+
existingBin.amountY = existingBin.amountY.add(bin.amountY);
|
|
2074
|
+
} else {
|
|
2075
|
+
binMap.set(bin.binId, bin);
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
return Array.from(binMap.values()).sort((a, b) => {
|
|
2079
|
+
return a.binId - b.binId;
|
|
2080
|
+
});
|
|
2081
|
+
}
|
|
2011
2082
|
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2012
2083
|
const isSingleSideX = amountY.isZero();
|
|
2084
|
+
let res = [];
|
|
2013
2085
|
switch (strategyType) {
|
|
2014
2086
|
case 1 /* Spot */: {
|
|
2015
2087
|
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2016
|
-
|
|
2088
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2089
|
+
break;
|
|
2017
2090
|
}
|
|
2018
2091
|
case 2 /* Curve */: {
|
|
2019
2092
|
if (activeId < minBinId) {
|
|
2020
2093
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2021
|
-
|
|
2094
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2022
2095
|
}
|
|
2023
2096
|
if (activeId > maxBinId) {
|
|
2024
2097
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2025
|
-
|
|
2098
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2026
2099
|
}
|
|
2027
2100
|
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2028
|
-
|
|
2101
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2102
|
+
break;
|
|
2029
2103
|
}
|
|
2030
2104
|
case 3 /* BidAsk */: {
|
|
2031
2105
|
if (activeId < minBinId) {
|
|
2032
2106
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2033
|
-
|
|
2107
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2034
2108
|
}
|
|
2035
2109
|
if (activeId > maxBinId) {
|
|
2036
2110
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2037
|
-
|
|
2111
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2038
2112
|
}
|
|
2039
2113
|
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2040
|
-
|
|
2114
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2115
|
+
break;
|
|
2041
2116
|
}
|
|
2042
2117
|
default:
|
|
2043
2118
|
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2044
2119
|
}
|
|
2120
|
+
let amountXLeft = amountX;
|
|
2121
|
+
let amountYLeft = amountY;
|
|
2122
|
+
res.forEach((bin) => {
|
|
2123
|
+
amountXLeft = amountXLeft.sub(bin.amountX);
|
|
2124
|
+
amountYLeft = amountYLeft.sub(bin.amountY);
|
|
2125
|
+
});
|
|
2126
|
+
if (amountXLeft.gt(new BN10(0))) {
|
|
2127
|
+
const xAssigned = assignLeftAmountX(activeId, binStep, maxBinId, amountXLeft, strategyType);
|
|
2128
|
+
res = mergeBinDisplay(res, xAssigned);
|
|
2129
|
+
}
|
|
2130
|
+
if (amountYLeft.gt(new BN10(0))) {
|
|
2131
|
+
const yAssigned = assignLeftAmountY(activeId, minBinId, amountYLeft, strategyType);
|
|
2132
|
+
res = mergeBinDisplay(res, yAssigned);
|
|
2133
|
+
}
|
|
2134
|
+
return res;
|
|
2045
2135
|
}
|
|
2046
2136
|
|
|
2047
2137
|
// src/math/LiquidityHelper.ts
|
|
@@ -2097,7 +2187,7 @@ function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply
|
|
|
2097
2187
|
}
|
|
2098
2188
|
|
|
2099
2189
|
// src/math/percentage.ts
|
|
2100
|
-
import
|
|
2190
|
+
import BN11 from "bn.js";
|
|
2101
2191
|
var Percentage = class {
|
|
2102
2192
|
numerator;
|
|
2103
2193
|
denominator;
|
|
@@ -2125,8 +2215,8 @@ var Percentage = class {
|
|
|
2125
2215
|
* @returns
|
|
2126
2216
|
*/
|
|
2127
2217
|
static fromFraction(numerator, denominator) {
|
|
2128
|
-
const num = typeof numerator === "number" ? new
|
|
2129
|
-
const denom = typeof denominator === "number" ? new
|
|
2218
|
+
const num = typeof numerator === "number" ? new BN11(numerator.toString()) : numerator;
|
|
2219
|
+
const denom = typeof denominator === "number" ? new BN11(denominator.toString()) : denominator;
|
|
2130
2220
|
return new Percentage(num, denom);
|
|
2131
2221
|
}
|
|
2132
2222
|
};
|
|
@@ -2226,7 +2316,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
2226
2316
|
}
|
|
2227
2317
|
|
|
2228
2318
|
// src/math/SplitSwap.ts
|
|
2229
|
-
import
|
|
2319
|
+
import BN12 from "bn.js";
|
|
2230
2320
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
2231
2321
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
2232
2322
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -2284,7 +2374,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
2284
2374
|
return splitSwapResult;
|
|
2285
2375
|
}
|
|
2286
2376
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
2287
|
-
let currentLiquidity = new
|
|
2377
|
+
let currentLiquidity = new BN12(poolData.liquidity);
|
|
2288
2378
|
let { currentSqrtPrice } = poolData;
|
|
2289
2379
|
let splitSwapResult = {
|
|
2290
2380
|
amountInArray: [],
|
|
@@ -2347,7 +2437,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2347
2437
|
targetSqrtPrice,
|
|
2348
2438
|
currentLiquidity,
|
|
2349
2439
|
remainerAmount,
|
|
2350
|
-
new
|
|
2440
|
+
new BN12(poolData.feeRate),
|
|
2351
2441
|
byAmountIn
|
|
2352
2442
|
);
|
|
2353
2443
|
tempStepResult = stepResult;
|
|
@@ -2359,7 +2449,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2359
2449
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2360
2450
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2361
2451
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2362
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2452
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
2363
2453
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2364
2454
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2365
2455
|
} else {
|
|
@@ -2384,7 +2474,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2384
2474
|
break;
|
|
2385
2475
|
}
|
|
2386
2476
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2387
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2477
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
2388
2478
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2389
2479
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2390
2480
|
} else {
|
|
@@ -2609,7 +2699,7 @@ function buildPool(objects) {
|
|
|
2609
2699
|
const rewarders = [];
|
|
2610
2700
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2611
2701
|
const { emissions_per_second } = item.fields;
|
|
2612
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2702
|
+
const emissionSeconds = MathUtil.fromX64(new BN13(emissions_per_second));
|
|
2613
2703
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2614
2704
|
rewarders.push({
|
|
2615
2705
|
emissions_per_second,
|
|
@@ -2801,11 +2891,11 @@ function buildTickData(objects) {
|
|
|
2801
2891
|
const possition = {
|
|
2802
2892
|
objectId: getObjectId(objects),
|
|
2803
2893
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2804
|
-
sqrtPrice: new
|
|
2805
|
-
liquidityNet: new
|
|
2806
|
-
liquidityGross: new
|
|
2807
|
-
feeGrowthOutsideA: new
|
|
2808
|
-
feeGrowthOutsideB: new
|
|
2894
|
+
sqrtPrice: new BN13(valueItem.sqrt_price),
|
|
2895
|
+
liquidityNet: new BN13(valueItem.liquidity_net.fields.bits),
|
|
2896
|
+
liquidityGross: new BN13(valueItem.liquidity_gross),
|
|
2897
|
+
feeGrowthOutsideA: new BN13(valueItem.fee_growth_outside_a),
|
|
2898
|
+
feeGrowthOutsideB: new BN13(valueItem.fee_growth_outside_b),
|
|
2809
2899
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2810
2900
|
};
|
|
2811
2901
|
return possition;
|
|
@@ -2815,11 +2905,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2815
2905
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2816
2906
|
}
|
|
2817
2907
|
const index = asIntN(BigInt(fields.index.bits));
|
|
2818
|
-
const sqrtPrice = new
|
|
2819
|
-
const liquidityNet = new
|
|
2820
|
-
const liquidityGross = new
|
|
2821
|
-
const feeGrowthOutsideA = new
|
|
2822
|
-
const feeGrowthOutsideB = new
|
|
2908
|
+
const sqrtPrice = new BN13(fields.sqrt_price);
|
|
2909
|
+
const liquidityNet = new BN13(fields.liquidity_net.bits);
|
|
2910
|
+
const liquidityGross = new BN13(fields.liquidity_gross);
|
|
2911
|
+
const feeGrowthOutsideA = new BN13(fields.fee_growth_outside_a);
|
|
2912
|
+
const feeGrowthOutsideB = new BN13(fields.fee_growth_outside_b);
|
|
2823
2913
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2824
2914
|
const tick = {
|
|
2825
2915
|
objectId: "",
|
|
@@ -2838,7 +2928,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2838
2928
|
}
|
|
2839
2929
|
|
|
2840
2930
|
// src/utils/tick.ts
|
|
2841
|
-
import
|
|
2931
|
+
import BN14 from "bn.js";
|
|
2842
2932
|
var TickUtil = class {
|
|
2843
2933
|
/**
|
|
2844
2934
|
* Get min tick index.
|
|
@@ -2878,22 +2968,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2878
2968
|
let rewarder_growth_below = growthGlobal[i];
|
|
2879
2969
|
if (tickLower !== null) {
|
|
2880
2970
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2881
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
2971
|
+
rewarder_growth_below = growthGlobal[i].sub(new BN14(tickLower.rewardersGrowthOutside[i]));
|
|
2882
2972
|
} else {
|
|
2883
2973
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2884
2974
|
}
|
|
2885
2975
|
}
|
|
2886
|
-
let rewarder_growth_above = new
|
|
2976
|
+
let rewarder_growth_above = new BN14(0);
|
|
2887
2977
|
if (tickUpper !== null) {
|
|
2888
2978
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2889
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
2979
|
+
rewarder_growth_above = growthGlobal[i].sub(new BN14(tickUpper.rewardersGrowthOutside[i]));
|
|
2890
2980
|
} else {
|
|
2891
2981
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2892
2982
|
}
|
|
2893
2983
|
}
|
|
2894
2984
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2895
|
-
MathUtil.subUnderflowU128(new
|
|
2896
|
-
new
|
|
2985
|
+
MathUtil.subUnderflowU128(new BN14(growthGlobal[i]), new BN14(rewarder_growth_below)),
|
|
2986
|
+
new BN14(rewarder_growth_above)
|
|
2897
2987
|
);
|
|
2898
2988
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2899
2989
|
}
|
|
@@ -2901,7 +2991,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2901
2991
|
}
|
|
2902
2992
|
|
|
2903
2993
|
// src/utils/transaction-util.ts
|
|
2904
|
-
import
|
|
2994
|
+
import BN15 from "bn.js";
|
|
2905
2995
|
import Decimal7 from "decimal.js";
|
|
2906
2996
|
import { Transaction } from "@mysten/sui/transactions";
|
|
2907
2997
|
function findAdjustCoin(coinPair) {
|
|
@@ -3210,7 +3300,7 @@ var _TransactionUtil = class {
|
|
|
3210
3300
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
3211
3301
|
Number(params.tick_lower),
|
|
3212
3302
|
Number(params.tick_upper),
|
|
3213
|
-
new
|
|
3303
|
+
new BN15(coinAmount),
|
|
3214
3304
|
params.fix_amount_a,
|
|
3215
3305
|
true,
|
|
3216
3306
|
slippage,
|
|
@@ -4278,7 +4368,7 @@ var _TransactionUtil = class {
|
|
|
4278
4368
|
const basePath = splitPath.basePaths[i];
|
|
4279
4369
|
a2b.push(basePath.direction);
|
|
4280
4370
|
poolAddress.push(basePath.poolAddress);
|
|
4281
|
-
rawAmountLimit.push(new
|
|
4371
|
+
rawAmountLimit.push(new BN15(basePath.inputAmount.toString()));
|
|
4282
4372
|
if (i === 0) {
|
|
4283
4373
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
4284
4374
|
} else {
|
|
@@ -4286,8 +4376,8 @@ var _TransactionUtil = class {
|
|
|
4286
4376
|
}
|
|
4287
4377
|
}
|
|
4288
4378
|
const onePath = {
|
|
4289
|
-
amountIn: new
|
|
4290
|
-
amountOut: new
|
|
4379
|
+
amountIn: new BN15(splitPath.inputAmount.toString()),
|
|
4380
|
+
amountOut: new BN15(splitPath.outputAmount.toString()),
|
|
4291
4381
|
poolAddress,
|
|
4292
4382
|
a2b,
|
|
4293
4383
|
rawAmountLimit,
|
|
@@ -4644,9 +4734,9 @@ var TxBlock = class {
|
|
|
4644
4734
|
};
|
|
4645
4735
|
|
|
4646
4736
|
// src/utils/deepbook-utils.ts
|
|
4647
|
-
import
|
|
4737
|
+
import BN16 from "bn.js";
|
|
4648
4738
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4649
|
-
var FLOAT_SCALING = new
|
|
4739
|
+
var FLOAT_SCALING = new BN16(1e9);
|
|
4650
4740
|
var DeepbookUtils = class {
|
|
4651
4741
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4652
4742
|
if (senderAddress.length === 0) {
|
|
@@ -4792,9 +4882,9 @@ var DeepbookUtils = class {
|
|
|
4792
4882
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4793
4883
|
let isExceed = false;
|
|
4794
4884
|
let amountOut = ZERO;
|
|
4795
|
-
let remainAmount = new
|
|
4885
|
+
let remainAmount = new BN16(amountIn);
|
|
4796
4886
|
let feeAmount = ZERO;
|
|
4797
|
-
const initAmountIn = new
|
|
4887
|
+
const initAmountIn = new BN16(amountIn);
|
|
4798
4888
|
if (a2b) {
|
|
4799
4889
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4800
4890
|
if (bids === null) {
|
|
@@ -4804,16 +4894,16 @@ var DeepbookUtils = class {
|
|
|
4804
4894
|
return b.price - a.price;
|
|
4805
4895
|
});
|
|
4806
4896
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4807
|
-
const curBidAmount = new
|
|
4808
|
-
const curBidPrice = new
|
|
4809
|
-
const fee = curBidAmount.mul(new
|
|
4897
|
+
const curBidAmount = new BN16(bids[i].quantity);
|
|
4898
|
+
const curBidPrice = new BN16(bids[i].price);
|
|
4899
|
+
const fee = curBidAmount.mul(new BN16(curBidPrice)).mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4810
4900
|
if (remainAmount.gt(curBidAmount)) {
|
|
4811
4901
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4812
4902
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4813
4903
|
feeAmount = feeAmount.add(fee);
|
|
4814
4904
|
} else {
|
|
4815
|
-
const curOut = remainAmount.mul(new
|
|
4816
|
-
const curFee = curOut.mul(new
|
|
4905
|
+
const curOut = remainAmount.mul(new BN16(bids[i].price)).div(FLOAT_SCALING);
|
|
4906
|
+
const curFee = curOut.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4817
4907
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4818
4908
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4819
4909
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4828,15 +4918,15 @@ var DeepbookUtils = class {
|
|
|
4828
4918
|
isExceed = true;
|
|
4829
4919
|
}
|
|
4830
4920
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4831
|
-
const curAskAmount = new
|
|
4832
|
-
const fee = curAskAmount.mul(new
|
|
4921
|
+
const curAskAmount = new BN16(asks[i].price).mul(new BN16(asks[i].quantity)).div(new BN16(1e9));
|
|
4922
|
+
const fee = curAskAmount.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4833
4923
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4834
4924
|
if (remainAmount.gt(curAskAmount)) {
|
|
4835
|
-
amountOut = amountOut.add(new
|
|
4925
|
+
amountOut = amountOut.add(new BN16(asks[i].quantity));
|
|
4836
4926
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4837
4927
|
feeAmount = feeAmount.add(fee);
|
|
4838
4928
|
} else {
|
|
4839
|
-
const splitNums = new
|
|
4929
|
+
const splitNums = new BN16(asks[i].quantity).div(new BN16(pool.lotSize));
|
|
4840
4930
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4841
4931
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4842
4932
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5156,7 +5246,7 @@ var PoolModule = class {
|
|
|
5156
5246
|
} catch (e) {
|
|
5157
5247
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "InvalidSwapCountUrl" /* InvalidSwapCountUrl */);
|
|
5158
5248
|
}
|
|
5159
|
-
const pools = json.data
|
|
5249
|
+
const { pools } = json.data;
|
|
5160
5250
|
if (!pools || pools.length === 0) {
|
|
5161
5251
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "PoolsNotFound" /* PoolsNotFound */);
|
|
5162
5252
|
}
|
|
@@ -5697,7 +5787,7 @@ var PoolModule = class {
|
|
|
5697
5787
|
};
|
|
5698
5788
|
|
|
5699
5789
|
// src/modules/positionModule.ts
|
|
5700
|
-
import
|
|
5790
|
+
import BN17 from "bn.js";
|
|
5701
5791
|
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
5702
5792
|
import { isValidSuiObjectId } from "@mysten/sui/utils";
|
|
5703
5793
|
var PositionModule = class {
|
|
@@ -5919,8 +6009,8 @@ var PositionModule = class {
|
|
|
5919
6009
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5920
6010
|
const { parsedJson } = valueData[i];
|
|
5921
6011
|
const posRrewarderResult = {
|
|
5922
|
-
feeOwedA: new
|
|
5923
|
-
feeOwedB: new
|
|
6012
|
+
feeOwedA: new BN17(parsedJson.fee_owned_a),
|
|
6013
|
+
feeOwedB: new BN17(parsedJson.fee_owned_b),
|
|
5924
6014
|
position_id: parsedJson.position_id
|
|
5925
6015
|
};
|
|
5926
6016
|
result.push(posRrewarderResult);
|
|
@@ -6296,7 +6386,7 @@ var PositionModule = class {
|
|
|
6296
6386
|
};
|
|
6297
6387
|
|
|
6298
6388
|
// src/modules/rewarderModule.ts
|
|
6299
|
-
import
|
|
6389
|
+
import BN18 from "bn.js";
|
|
6300
6390
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
6301
6391
|
var RewarderModule = class {
|
|
6302
6392
|
_sdk;
|
|
@@ -6322,7 +6412,7 @@ var RewarderModule = class {
|
|
|
6322
6412
|
}
|
|
6323
6413
|
const emissionsEveryDay = [];
|
|
6324
6414
|
for (const rewarderInfo of rewarderInfos) {
|
|
6325
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6415
|
+
const emissionSeconds = MathUtil.fromX64(new BN18(rewarderInfo.emissions_per_second));
|
|
6326
6416
|
emissionsEveryDay.push({
|
|
6327
6417
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6328
6418
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6341,20 +6431,20 @@ var RewarderModule = class {
|
|
|
6341
6431
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6342
6432
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6343
6433
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6344
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6434
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new BN18(lastTime))) {
|
|
6345
6435
|
return currentPool;
|
|
6346
6436
|
}
|
|
6347
|
-
const timeDelta = currentTime.div(new
|
|
6437
|
+
const timeDelta = currentTime.div(new BN18(1e3)).sub(new BN18(lastTime)).add(new BN18(15));
|
|
6348
6438
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6349
6439
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6350
6440
|
const rewarderInfo = rewarderInfos[i];
|
|
6351
6441
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6352
6442
|
timeDelta,
|
|
6353
|
-
new
|
|
6354
|
-
new
|
|
6443
|
+
new BN18(rewarderInfo.emissions_per_second),
|
|
6444
|
+
new BN18(currentPool.liquidity),
|
|
6355
6445
|
128
|
|
6356
6446
|
);
|
|
6357
|
-
this.growthGlobal[i] = new
|
|
6447
|
+
this.growthGlobal[i] = new BN18(rewarderInfo.growth_global).add(new BN18(rewarderGrowthDelta));
|
|
6358
6448
|
}
|
|
6359
6449
|
return currentPool;
|
|
6360
6450
|
}
|
|
@@ -6369,7 +6459,7 @@ var RewarderModule = class {
|
|
|
6369
6459
|
*/
|
|
6370
6460
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6371
6461
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6372
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6462
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
6373
6463
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6374
6464
|
if (position === void 0) {
|
|
6375
6465
|
return [];
|
|
@@ -6390,7 +6480,7 @@ var RewarderModule = class {
|
|
|
6390
6480
|
*/
|
|
6391
6481
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6392
6482
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6393
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6483
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
6394
6484
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6395
6485
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6396
6486
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6417,38 +6507,38 @@ var RewarderModule = class {
|
|
|
6417
6507
|
const growthInside = [];
|
|
6418
6508
|
const AmountOwed = [];
|
|
6419
6509
|
if (rewardersInside.length > 0) {
|
|
6420
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6421
|
-
if (growthDelta0.gt(new
|
|
6510
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new BN18(position.reward_growth_inside_0));
|
|
6511
|
+
if (growthDelta0.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6422
6512
|
growthDelta0 = ONE;
|
|
6423
6513
|
}
|
|
6424
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6514
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta0, 64, 128);
|
|
6425
6515
|
growthInside.push(rewardersInside[0]);
|
|
6426
6516
|
AmountOwed.push({
|
|
6427
|
-
amount_owed: new
|
|
6517
|
+
amount_owed: new BN18(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6428
6518
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6429
6519
|
});
|
|
6430
6520
|
}
|
|
6431
6521
|
if (rewardersInside.length > 1) {
|
|
6432
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6433
|
-
if (growthDelta_1.gt(new
|
|
6522
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new BN18(position.reward_growth_inside_1));
|
|
6523
|
+
if (growthDelta_1.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6434
6524
|
growthDelta_1 = ONE;
|
|
6435
6525
|
}
|
|
6436
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6526
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_1, 64, 128);
|
|
6437
6527
|
growthInside.push(rewardersInside[1]);
|
|
6438
6528
|
AmountOwed.push({
|
|
6439
|
-
amount_owed: new
|
|
6529
|
+
amount_owed: new BN18(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6440
6530
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6441
6531
|
});
|
|
6442
6532
|
}
|
|
6443
6533
|
if (rewardersInside.length > 2) {
|
|
6444
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6445
|
-
if (growthDelta_2.gt(new
|
|
6534
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new BN18(position.reward_growth_inside_2));
|
|
6535
|
+
if (growthDelta_2.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6446
6536
|
growthDelta_2 = ONE;
|
|
6447
6537
|
}
|
|
6448
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6538
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_2, 64, 128);
|
|
6449
6539
|
growthInside.push(rewardersInside[2]);
|
|
6450
6540
|
AmountOwed.push({
|
|
6451
|
-
amount_owed: new
|
|
6541
|
+
amount_owed: new BN18(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6452
6542
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6453
6543
|
});
|
|
6454
6544
|
}
|
|
@@ -6562,8 +6652,8 @@ var RewarderModule = class {
|
|
|
6562
6652
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6563
6653
|
const { parsedJson } = valueData[i];
|
|
6564
6654
|
const posRrewarderResult = {
|
|
6565
|
-
feeOwedA: new
|
|
6566
|
-
feeOwedB: new
|
|
6655
|
+
feeOwedA: new BN18(parsedJson.fee_owned_a),
|
|
6656
|
+
feeOwedB: new BN18(parsedJson.fee_owned_b),
|
|
6567
6657
|
position_id: parsedJson.position_id
|
|
6568
6658
|
};
|
|
6569
6659
|
result.push(posRrewarderResult);
|
|
@@ -6626,7 +6716,7 @@ var RewarderModule = class {
|
|
|
6626
6716
|
};
|
|
6627
6717
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6628
6718
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6629
|
-
amount_owed: new
|
|
6719
|
+
amount_owed: new BN18(valueData[i].parsedJson.data[j]),
|
|
6630
6720
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6631
6721
|
});
|
|
6632
6722
|
}
|
|
@@ -6785,7 +6875,7 @@ var RewarderModule = class {
|
|
|
6785
6875
|
};
|
|
6786
6876
|
|
|
6787
6877
|
// src/modules/routerModule.ts
|
|
6788
|
-
import
|
|
6878
|
+
import BN19 from "bn.js";
|
|
6789
6879
|
import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
|
|
6790
6880
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
6791
6881
|
function _pairSymbol(base, quote) {
|
|
@@ -7067,8 +7157,8 @@ var RouterModule = class {
|
|
|
7067
7157
|
if (swapWithMultiPoolParams != null) {
|
|
7068
7158
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7069
7159
|
const onePath2 = {
|
|
7070
|
-
amountIn: new
|
|
7071
|
-
amountOut: new
|
|
7160
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7161
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7072
7162
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7073
7163
|
a2b: [preSwapResult2.aToB],
|
|
7074
7164
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7081,8 +7171,8 @@ var RouterModule = class {
|
|
|
7081
7171
|
priceSlippagePoint
|
|
7082
7172
|
};
|
|
7083
7173
|
const result2 = {
|
|
7084
|
-
amountIn: new
|
|
7085
|
-
amountOut: new
|
|
7174
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7175
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7086
7176
|
paths: [onePath2],
|
|
7087
7177
|
a2b: preSwapResult2.aToB,
|
|
7088
7178
|
b2c: void 0,
|
|
@@ -7104,8 +7194,8 @@ var RouterModule = class {
|
|
|
7104
7194
|
if (swapWithMultiPoolParams != null) {
|
|
7105
7195
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7106
7196
|
const onePath2 = {
|
|
7107
|
-
amountIn: new
|
|
7108
|
-
amountOut: new
|
|
7197
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7198
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7109
7199
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7110
7200
|
a2b: [preSwapResult2.aToB],
|
|
7111
7201
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7118,8 +7208,8 @@ var RouterModule = class {
|
|
|
7118
7208
|
priceSlippagePoint
|
|
7119
7209
|
};
|
|
7120
7210
|
const result3 = {
|
|
7121
|
-
amountIn: new
|
|
7122
|
-
amountOut: new
|
|
7211
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7212
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7123
7213
|
paths: [onePath2],
|
|
7124
7214
|
a2b: preSwapResult2.aToB,
|
|
7125
7215
|
b2c: void 0,
|
|
@@ -7200,8 +7290,8 @@ var RouterModule = class {
|
|
|
7200
7290
|
if (swapWithMultiPoolParams != null) {
|
|
7201
7291
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7202
7292
|
const onePath = {
|
|
7203
|
-
amountIn: new
|
|
7204
|
-
amountOut: new
|
|
7293
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7294
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
7205
7295
|
poolAddress: [preSwapResult.poolAddress],
|
|
7206
7296
|
a2b: [preSwapResult.aToB],
|
|
7207
7297
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -7214,8 +7304,8 @@ var RouterModule = class {
|
|
|
7214
7304
|
priceSlippagePoint
|
|
7215
7305
|
};
|
|
7216
7306
|
const result = {
|
|
7217
|
-
amountIn: new
|
|
7218
|
-
amountOut: new
|
|
7307
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7308
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
7219
7309
|
paths: [onePath],
|
|
7220
7310
|
a2b: preSwapResult.aToB,
|
|
7221
7311
|
b2c: void 0,
|
|
@@ -7299,13 +7389,13 @@ var RouterModule = class {
|
|
|
7299
7389
|
continue;
|
|
7300
7390
|
}
|
|
7301
7391
|
if (params[0].byAmountIn) {
|
|
7302
|
-
const amount = new
|
|
7392
|
+
const amount = new BN19(valueData[i].parsedJson.data.amount_out);
|
|
7303
7393
|
if (amount.gt(tempMaxAmount)) {
|
|
7304
7394
|
tempIndex = i;
|
|
7305
7395
|
tempMaxAmount = amount;
|
|
7306
7396
|
}
|
|
7307
7397
|
} else {
|
|
7308
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7398
|
+
const amount = params[i].stepNums > 1 ? new BN19(valueData[i].parsedJson.data.amount_in) : new BN19(valueData[i].parsedJson.data.amount_in).add(new BN19(valueData[i].parsedJson.data.fee_amount));
|
|
7309
7399
|
if (amount.lt(tempMaxAmount)) {
|
|
7310
7400
|
tempIndex = i;
|
|
7311
7401
|
tempMaxAmount = amount;
|
|
@@ -7375,7 +7465,7 @@ var RouterModule = class {
|
|
|
7375
7465
|
};
|
|
7376
7466
|
|
|
7377
7467
|
// src/modules/swapModule.ts
|
|
7378
|
-
import
|
|
7468
|
+
import BN20 from "bn.js";
|
|
7379
7469
|
import Decimal8 from "decimal.js";
|
|
7380
7470
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
7381
7471
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
@@ -7491,13 +7581,13 @@ var SwapModule = class {
|
|
|
7491
7581
|
continue;
|
|
7492
7582
|
}
|
|
7493
7583
|
if (params.byAmountIn) {
|
|
7494
|
-
const amount = new
|
|
7584
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7495
7585
|
if (amount.gt(tempMaxAmount)) {
|
|
7496
7586
|
tempIndex = i;
|
|
7497
7587
|
tempMaxAmount = amount;
|
|
7498
7588
|
}
|
|
7499
7589
|
} else {
|
|
7500
|
-
const amount = new
|
|
7590
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7501
7591
|
if (amount.lt(tempMaxAmount)) {
|
|
7502
7592
|
tempIndex = i;
|
|
7503
7593
|
tempMaxAmount = amount;
|
|
@@ -7561,7 +7651,7 @@ var SwapModule = class {
|
|
|
7561
7651
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7562
7652
|
}
|
|
7563
7653
|
transformSwapData(params, data) {
|
|
7564
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7654
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7565
7655
|
return {
|
|
7566
7656
|
poolAddress: params.pool.poolAddress,
|
|
7567
7657
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7578,7 +7668,7 @@ var SwapModule = class {
|
|
|
7578
7668
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7579
7669
|
const { data } = jsonData;
|
|
7580
7670
|
console.log("json data. ", data);
|
|
7581
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7671
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7582
7672
|
return {
|
|
7583
7673
|
poolAddress: params.poolAddress,
|
|
7584
7674
|
estimatedAmountIn,
|
|
@@ -9091,7 +9181,7 @@ var TokenModule = class {
|
|
|
9091
9181
|
};
|
|
9092
9182
|
|
|
9093
9183
|
// src/modules/routerModuleV2.ts
|
|
9094
|
-
import
|
|
9184
|
+
import BN21 from "bn.js";
|
|
9095
9185
|
import Decimal9 from "decimal.js";
|
|
9096
9186
|
import { v4 as uuidv4 } from "uuid";
|
|
9097
9187
|
import axios from "axios";
|
|
@@ -9135,12 +9225,12 @@ var RouterModuleV2 = class {
|
|
|
9135
9225
|
outputAmount: basePath.output_amount,
|
|
9136
9226
|
inputAmount: basePath.input_amount,
|
|
9137
9227
|
feeRate: basePath.fee_rate,
|
|
9138
|
-
currentSqrtPrice: new
|
|
9139
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9228
|
+
currentSqrtPrice: new BN21(basePath.current_sqrt_price.toString()),
|
|
9229
|
+
afterSqrtPrice: basePath.label === "Magma" ? new BN21(basePath.after_sqrt_price.toString()) : ZERO,
|
|
9140
9230
|
fromDecimal: basePath.from_decimal,
|
|
9141
9231
|
toDecimal: basePath.to_decimal,
|
|
9142
9232
|
currentPrice: this.calculatePrice(
|
|
9143
|
-
new
|
|
9233
|
+
new BN21(basePath.current_sqrt_price.toString()),
|
|
9144
9234
|
basePath.from_decimal,
|
|
9145
9235
|
basePath.to_decimal,
|
|
9146
9236
|
basePath.direction,
|
|
@@ -9223,7 +9313,7 @@ var RouterModuleV2 = class {
|
|
|
9223
9313
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9224
9314
|
from,
|
|
9225
9315
|
to,
|
|
9226
|
-
new
|
|
9316
|
+
new BN21(amount),
|
|
9227
9317
|
byAmountIn,
|
|
9228
9318
|
priceSplitPoint,
|
|
9229
9319
|
partner,
|
|
@@ -9235,7 +9325,7 @@ var RouterModuleV2 = class {
|
|
|
9235
9325
|
if (path.poolAddress.length > 1) {
|
|
9236
9326
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9237
9327
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9238
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9328
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9239
9329
|
const path0 = {
|
|
9240
9330
|
direction: path.a2b[0],
|
|
9241
9331
|
label: "Magma",
|
|
@@ -9252,7 +9342,7 @@ var RouterModuleV2 = class {
|
|
|
9252
9342
|
};
|
|
9253
9343
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9254
9344
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9255
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9345
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9256
9346
|
const path1 = {
|
|
9257
9347
|
direction: path.a2b[1],
|
|
9258
9348
|
label: "Magma",
|
|
@@ -9271,7 +9361,7 @@ var RouterModuleV2 = class {
|
|
|
9271
9361
|
} else {
|
|
9272
9362
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9273
9363
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9274
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9364
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9275
9365
|
const path0 = {
|
|
9276
9366
|
direction: path.a2b[0],
|
|
9277
9367
|
label: "Magma",
|
|
@@ -9356,7 +9446,7 @@ var RouterModuleV2 = class {
|
|
|
9356
9446
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9357
9447
|
from,
|
|
9358
9448
|
to,
|
|
9359
|
-
new
|
|
9449
|
+
new BN21(amount),
|
|
9360
9450
|
byAmountIn,
|
|
9361
9451
|
priceSplitPoint,
|
|
9362
9452
|
partner,
|
|
@@ -9368,7 +9458,7 @@ var RouterModuleV2 = class {
|
|
|
9368
9458
|
if (path.poolAddress.length > 1) {
|
|
9369
9459
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9370
9460
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9371
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9461
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9372
9462
|
const path0 = {
|
|
9373
9463
|
direction: path.a2b[0],
|
|
9374
9464
|
label: "Magma",
|
|
@@ -9385,7 +9475,7 @@ var RouterModuleV2 = class {
|
|
|
9385
9475
|
};
|
|
9386
9476
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9387
9477
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9388
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9478
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9389
9479
|
const path1 = {
|
|
9390
9480
|
direction: path.a2b[1],
|
|
9391
9481
|
label: "Magma",
|
|
@@ -9404,7 +9494,7 @@ var RouterModuleV2 = class {
|
|
|
9404
9494
|
} else {
|
|
9405
9495
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9406
9496
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9407
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9497
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9408
9498
|
const path0 = {
|
|
9409
9499
|
direction: path.a2b[0],
|
|
9410
9500
|
label: "Magma",
|