@magmaprotocol/magma-clmm-sdk 0.5.83 → 0.5.85
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.d.ts +20 -4
- package/dist/index.js +355 -193
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +355 -193
- 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,133 @@ 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
|
+
if (maxBinId < activeId) {
|
|
2016
|
+
return [];
|
|
2017
|
+
}
|
|
2018
|
+
let weights = [];
|
|
2019
|
+
switch (strategyType) {
|
|
2020
|
+
case 1 /* Spot */: {
|
|
2021
|
+
weights = toWeightSpotBalanced(activeId, maxBinId);
|
|
2022
|
+
break;
|
|
2023
|
+
}
|
|
2024
|
+
case 2 /* Curve */: {
|
|
2025
|
+
weights = toWeightDecendingOrder(activeId, maxBinId);
|
|
2026
|
+
break;
|
|
2027
|
+
}
|
|
2028
|
+
case 3 /* BidAsk */: {
|
|
2029
|
+
weights = toWeightAscendingOrder(activeId, maxBinId);
|
|
2030
|
+
break;
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2034
|
+
return amounts.map((bin) => {
|
|
2035
|
+
return {
|
|
2036
|
+
binId: bin.binId,
|
|
2037
|
+
amountX: bin.amount,
|
|
2038
|
+
amountY: new BN10(0)
|
|
2039
|
+
};
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
function assignLeftAmountY(activeId, minBinId, amountY, strategyType) {
|
|
2043
|
+
if (minBinId > activeId) {
|
|
2044
|
+
return [];
|
|
2045
|
+
}
|
|
2046
|
+
let weights = [];
|
|
2047
|
+
switch (strategyType) {
|
|
2048
|
+
case 1 /* Spot */: {
|
|
2049
|
+
weights = toWeightSpotBalanced(minBinId, activeId);
|
|
2050
|
+
break;
|
|
2051
|
+
}
|
|
2052
|
+
case 2 /* Curve */: {
|
|
2053
|
+
weights = toWeightAscendingOrder(minBinId, activeId);
|
|
2054
|
+
break;
|
|
2055
|
+
}
|
|
2056
|
+
case 3 /* BidAsk */: {
|
|
2057
|
+
weights = toWeightDecendingOrder(minBinId, activeId);
|
|
2058
|
+
break;
|
|
2059
|
+
}
|
|
2060
|
+
}
|
|
2061
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2062
|
+
return amounts.map((bin) => {
|
|
2063
|
+
return {
|
|
2064
|
+
binId: bin.binId,
|
|
2065
|
+
amountX: new BN10(0),
|
|
2066
|
+
amountY: bin.amount
|
|
2067
|
+
};
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
function mergeBinDisplay(to, from) {
|
|
2071
|
+
const binMap = /* @__PURE__ */ new Map();
|
|
2072
|
+
for (const bin of to) {
|
|
2073
|
+
binMap.set(bin.binId, bin);
|
|
2074
|
+
}
|
|
2075
|
+
for (const bin of from) {
|
|
2076
|
+
const existingBin = binMap.get(bin.binId);
|
|
2077
|
+
if (existingBin) {
|
|
2078
|
+
existingBin.amountX = existingBin.amountX.add(bin.amountX);
|
|
2079
|
+
existingBin.amountY = existingBin.amountY.add(bin.amountY);
|
|
2080
|
+
} else {
|
|
2081
|
+
binMap.set(bin.binId, bin);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
return Array.from(binMap.values()).sort((a, b) => {
|
|
2085
|
+
return a.binId - b.binId;
|
|
2086
|
+
});
|
|
2087
|
+
}
|
|
2011
2088
|
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2012
2089
|
const isSingleSideX = amountY.isZero();
|
|
2090
|
+
let res = [];
|
|
2013
2091
|
switch (strategyType) {
|
|
2014
2092
|
case 1 /* Spot */: {
|
|
2015
2093
|
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2016
|
-
|
|
2094
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2095
|
+
break;
|
|
2017
2096
|
}
|
|
2018
2097
|
case 2 /* Curve */: {
|
|
2019
2098
|
if (activeId < minBinId) {
|
|
2020
2099
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2021
|
-
|
|
2100
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2022
2101
|
}
|
|
2023
2102
|
if (activeId > maxBinId) {
|
|
2024
2103
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2025
|
-
|
|
2104
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2026
2105
|
}
|
|
2027
2106
|
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2028
|
-
|
|
2107
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2108
|
+
break;
|
|
2029
2109
|
}
|
|
2030
2110
|
case 3 /* BidAsk */: {
|
|
2031
2111
|
if (activeId < minBinId) {
|
|
2032
2112
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2033
|
-
|
|
2113
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2034
2114
|
}
|
|
2035
2115
|
if (activeId > maxBinId) {
|
|
2036
2116
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2037
|
-
|
|
2117
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2038
2118
|
}
|
|
2039
2119
|
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2040
|
-
|
|
2120
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2121
|
+
break;
|
|
2041
2122
|
}
|
|
2042
2123
|
default:
|
|
2043
2124
|
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2044
2125
|
}
|
|
2126
|
+
let amountXLeft = amountX;
|
|
2127
|
+
let amountYLeft = amountY;
|
|
2128
|
+
res.forEach((bin) => {
|
|
2129
|
+
amountXLeft = amountXLeft.sub(bin.amountX);
|
|
2130
|
+
amountYLeft = amountYLeft.sub(bin.amountY);
|
|
2131
|
+
});
|
|
2132
|
+
if (amountXLeft.gt(new BN10(0))) {
|
|
2133
|
+
const xAssigned = assignLeftAmountX(activeId, binStep, maxBinId, amountXLeft, strategyType);
|
|
2134
|
+
res = mergeBinDisplay(res, xAssigned);
|
|
2135
|
+
}
|
|
2136
|
+
if (amountYLeft.gt(new BN10(0))) {
|
|
2137
|
+
const yAssigned = assignLeftAmountY(activeId, minBinId, amountYLeft, strategyType);
|
|
2138
|
+
res = mergeBinDisplay(res, yAssigned);
|
|
2139
|
+
}
|
|
2140
|
+
return res;
|
|
2045
2141
|
}
|
|
2046
2142
|
|
|
2047
2143
|
// src/math/LiquidityHelper.ts
|
|
@@ -2097,7 +2193,7 @@ function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply
|
|
|
2097
2193
|
}
|
|
2098
2194
|
|
|
2099
2195
|
// src/math/percentage.ts
|
|
2100
|
-
import
|
|
2196
|
+
import BN11 from "bn.js";
|
|
2101
2197
|
var Percentage = class {
|
|
2102
2198
|
numerator;
|
|
2103
2199
|
denominator;
|
|
@@ -2125,8 +2221,8 @@ var Percentage = class {
|
|
|
2125
2221
|
* @returns
|
|
2126
2222
|
*/
|
|
2127
2223
|
static fromFraction(numerator, denominator) {
|
|
2128
|
-
const num = typeof numerator === "number" ? new
|
|
2129
|
-
const denom = typeof denominator === "number" ? new
|
|
2224
|
+
const num = typeof numerator === "number" ? new BN11(numerator.toString()) : numerator;
|
|
2225
|
+
const denom = typeof denominator === "number" ? new BN11(denominator.toString()) : denominator;
|
|
2130
2226
|
return new Percentage(num, denom);
|
|
2131
2227
|
}
|
|
2132
2228
|
};
|
|
@@ -2226,7 +2322,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
2226
2322
|
}
|
|
2227
2323
|
|
|
2228
2324
|
// src/math/SplitSwap.ts
|
|
2229
|
-
import
|
|
2325
|
+
import BN12 from "bn.js";
|
|
2230
2326
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
2231
2327
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
2232
2328
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -2284,7 +2380,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
2284
2380
|
return splitSwapResult;
|
|
2285
2381
|
}
|
|
2286
2382
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
2287
|
-
let currentLiquidity = new
|
|
2383
|
+
let currentLiquidity = new BN12(poolData.liquidity);
|
|
2288
2384
|
let { currentSqrtPrice } = poolData;
|
|
2289
2385
|
let splitSwapResult = {
|
|
2290
2386
|
amountInArray: [],
|
|
@@ -2347,7 +2443,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2347
2443
|
targetSqrtPrice,
|
|
2348
2444
|
currentLiquidity,
|
|
2349
2445
|
remainerAmount,
|
|
2350
|
-
new
|
|
2446
|
+
new BN12(poolData.feeRate),
|
|
2351
2447
|
byAmountIn
|
|
2352
2448
|
);
|
|
2353
2449
|
tempStepResult = stepResult;
|
|
@@ -2359,7 +2455,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2359
2455
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2360
2456
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2361
2457
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2362
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2458
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
2363
2459
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2364
2460
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2365
2461
|
} else {
|
|
@@ -2384,7 +2480,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2384
2480
|
break;
|
|
2385
2481
|
}
|
|
2386
2482
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2387
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2483
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new BN12(-1)) : tick.liquidityNet;
|
|
2388
2484
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2389
2485
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2390
2486
|
} else {
|
|
@@ -2609,7 +2705,7 @@ function buildPool(objects) {
|
|
|
2609
2705
|
const rewarders = [];
|
|
2610
2706
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2611
2707
|
const { emissions_per_second } = item.fields;
|
|
2612
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2708
|
+
const emissionSeconds = MathUtil.fromX64(new BN13(emissions_per_second));
|
|
2613
2709
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2614
2710
|
rewarders.push({
|
|
2615
2711
|
emissions_per_second,
|
|
@@ -2801,11 +2897,11 @@ function buildTickData(objects) {
|
|
|
2801
2897
|
const possition = {
|
|
2802
2898
|
objectId: getObjectId(objects),
|
|
2803
2899
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
2804
|
-
sqrtPrice: new
|
|
2805
|
-
liquidityNet: new
|
|
2806
|
-
liquidityGross: new
|
|
2807
|
-
feeGrowthOutsideA: new
|
|
2808
|
-
feeGrowthOutsideB: new
|
|
2900
|
+
sqrtPrice: new BN13(valueItem.sqrt_price),
|
|
2901
|
+
liquidityNet: new BN13(valueItem.liquidity_net.fields.bits),
|
|
2902
|
+
liquidityGross: new BN13(valueItem.liquidity_gross),
|
|
2903
|
+
feeGrowthOutsideA: new BN13(valueItem.fee_growth_outside_a),
|
|
2904
|
+
feeGrowthOutsideB: new BN13(valueItem.fee_growth_outside_b),
|
|
2809
2905
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
2810
2906
|
};
|
|
2811
2907
|
return possition;
|
|
@@ -2815,11 +2911,11 @@ function buildTickDataByEvent(fields) {
|
|
|
2815
2911
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
2816
2912
|
}
|
|
2817
2913
|
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
|
|
2914
|
+
const sqrtPrice = new BN13(fields.sqrt_price);
|
|
2915
|
+
const liquidityNet = new BN13(fields.liquidity_net.bits);
|
|
2916
|
+
const liquidityGross = new BN13(fields.liquidity_gross);
|
|
2917
|
+
const feeGrowthOutsideA = new BN13(fields.fee_growth_outside_a);
|
|
2918
|
+
const feeGrowthOutsideB = new BN13(fields.fee_growth_outside_b);
|
|
2823
2919
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
2824
2920
|
const tick = {
|
|
2825
2921
|
objectId: "",
|
|
@@ -2838,7 +2934,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
2838
2934
|
}
|
|
2839
2935
|
|
|
2840
2936
|
// src/utils/tick.ts
|
|
2841
|
-
import
|
|
2937
|
+
import BN14 from "bn.js";
|
|
2842
2938
|
var TickUtil = class {
|
|
2843
2939
|
/**
|
|
2844
2940
|
* Get min tick index.
|
|
@@ -2878,22 +2974,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2878
2974
|
let rewarder_growth_below = growthGlobal[i];
|
|
2879
2975
|
if (tickLower !== null) {
|
|
2880
2976
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
2881
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
2977
|
+
rewarder_growth_below = growthGlobal[i].sub(new BN14(tickLower.rewardersGrowthOutside[i]));
|
|
2882
2978
|
} else {
|
|
2883
2979
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
2884
2980
|
}
|
|
2885
2981
|
}
|
|
2886
|
-
let rewarder_growth_above = new
|
|
2982
|
+
let rewarder_growth_above = new BN14(0);
|
|
2887
2983
|
if (tickUpper !== null) {
|
|
2888
2984
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
2889
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
2985
|
+
rewarder_growth_above = growthGlobal[i].sub(new BN14(tickUpper.rewardersGrowthOutside[i]));
|
|
2890
2986
|
} else {
|
|
2891
2987
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
2892
2988
|
}
|
|
2893
2989
|
}
|
|
2894
2990
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
2895
|
-
MathUtil.subUnderflowU128(new
|
|
2896
|
-
new
|
|
2991
|
+
MathUtil.subUnderflowU128(new BN14(growthGlobal[i]), new BN14(rewarder_growth_below)),
|
|
2992
|
+
new BN14(rewarder_growth_above)
|
|
2897
2993
|
);
|
|
2898
2994
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
2899
2995
|
}
|
|
@@ -2901,7 +2997,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
2901
2997
|
}
|
|
2902
2998
|
|
|
2903
2999
|
// src/utils/transaction-util.ts
|
|
2904
|
-
import
|
|
3000
|
+
import BN15 from "bn.js";
|
|
2905
3001
|
import Decimal7 from "decimal.js";
|
|
2906
3002
|
import { Transaction } from "@mysten/sui/transactions";
|
|
2907
3003
|
function findAdjustCoin(coinPair) {
|
|
@@ -3210,7 +3306,7 @@ var _TransactionUtil = class {
|
|
|
3210
3306
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
3211
3307
|
Number(params.tick_lower),
|
|
3212
3308
|
Number(params.tick_upper),
|
|
3213
|
-
new
|
|
3309
|
+
new BN15(coinAmount),
|
|
3214
3310
|
params.fix_amount_a,
|
|
3215
3311
|
true,
|
|
3216
3312
|
slippage,
|
|
@@ -4278,7 +4374,7 @@ var _TransactionUtil = class {
|
|
|
4278
4374
|
const basePath = splitPath.basePaths[i];
|
|
4279
4375
|
a2b.push(basePath.direction);
|
|
4280
4376
|
poolAddress.push(basePath.poolAddress);
|
|
4281
|
-
rawAmountLimit.push(new
|
|
4377
|
+
rawAmountLimit.push(new BN15(basePath.inputAmount.toString()));
|
|
4282
4378
|
if (i === 0) {
|
|
4283
4379
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
4284
4380
|
} else {
|
|
@@ -4286,8 +4382,8 @@ var _TransactionUtil = class {
|
|
|
4286
4382
|
}
|
|
4287
4383
|
}
|
|
4288
4384
|
const onePath = {
|
|
4289
|
-
amountIn: new
|
|
4290
|
-
amountOut: new
|
|
4385
|
+
amountIn: new BN15(splitPath.inputAmount.toString()),
|
|
4386
|
+
amountOut: new BN15(splitPath.outputAmount.toString()),
|
|
4291
4387
|
poolAddress,
|
|
4292
4388
|
a2b,
|
|
4293
4389
|
rawAmountLimit,
|
|
@@ -4644,9 +4740,9 @@ var TxBlock = class {
|
|
|
4644
4740
|
};
|
|
4645
4741
|
|
|
4646
4742
|
// src/utils/deepbook-utils.ts
|
|
4647
|
-
import
|
|
4743
|
+
import BN16 from "bn.js";
|
|
4648
4744
|
import { Transaction as Transaction3 } from "@mysten/sui/transactions";
|
|
4649
|
-
var FLOAT_SCALING = new
|
|
4745
|
+
var FLOAT_SCALING = new BN16(1e9);
|
|
4650
4746
|
var DeepbookUtils = class {
|
|
4651
4747
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4652
4748
|
if (senderAddress.length === 0) {
|
|
@@ -4792,9 +4888,9 @@ var DeepbookUtils = class {
|
|
|
4792
4888
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
4793
4889
|
let isExceed = false;
|
|
4794
4890
|
let amountOut = ZERO;
|
|
4795
|
-
let remainAmount = new
|
|
4891
|
+
let remainAmount = new BN16(amountIn);
|
|
4796
4892
|
let feeAmount = ZERO;
|
|
4797
|
-
const initAmountIn = new
|
|
4893
|
+
const initAmountIn = new BN16(amountIn);
|
|
4798
4894
|
if (a2b) {
|
|
4799
4895
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
4800
4896
|
if (bids === null) {
|
|
@@ -4804,16 +4900,16 @@ var DeepbookUtils = class {
|
|
|
4804
4900
|
return b.price - a.price;
|
|
4805
4901
|
});
|
|
4806
4902
|
for (let i = 0; i < bids.length; i += 1) {
|
|
4807
|
-
const curBidAmount = new
|
|
4808
|
-
const curBidPrice = new
|
|
4809
|
-
const fee = curBidAmount.mul(new
|
|
4903
|
+
const curBidAmount = new BN16(bids[i].quantity);
|
|
4904
|
+
const curBidPrice = new BN16(bids[i].price);
|
|
4905
|
+
const fee = curBidAmount.mul(new BN16(curBidPrice)).mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
4810
4906
|
if (remainAmount.gt(curBidAmount)) {
|
|
4811
4907
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
4812
4908
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
4813
4909
|
feeAmount = feeAmount.add(fee);
|
|
4814
4910
|
} else {
|
|
4815
|
-
const curOut = remainAmount.mul(new
|
|
4816
|
-
const curFee = curOut.mul(new
|
|
4911
|
+
const curOut = remainAmount.mul(new BN16(bids[i].price)).div(FLOAT_SCALING);
|
|
4912
|
+
const curFee = curOut.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4817
4913
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
4818
4914
|
remainAmount = remainAmount.sub(remainAmount);
|
|
4819
4915
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -4828,15 +4924,15 @@ var DeepbookUtils = class {
|
|
|
4828
4924
|
isExceed = true;
|
|
4829
4925
|
}
|
|
4830
4926
|
for (let i = 0; i < asks.length; i += 1) {
|
|
4831
|
-
const curAskAmount = new
|
|
4832
|
-
const fee = curAskAmount.mul(new
|
|
4927
|
+
const curAskAmount = new BN16(asks[i].price).mul(new BN16(asks[i].quantity)).div(new BN16(1e9));
|
|
4928
|
+
const fee = curAskAmount.mul(new BN16(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
4833
4929
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
4834
4930
|
if (remainAmount.gt(curAskAmount)) {
|
|
4835
|
-
amountOut = amountOut.add(new
|
|
4931
|
+
amountOut = amountOut.add(new BN16(asks[i].quantity));
|
|
4836
4932
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
4837
4933
|
feeAmount = feeAmount.add(fee);
|
|
4838
4934
|
} else {
|
|
4839
|
-
const splitNums = new
|
|
4935
|
+
const splitNums = new BN16(asks[i].quantity).div(new BN16(pool.lotSize));
|
|
4840
4936
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
4841
4937
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
4842
4938
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5156,7 +5252,7 @@ var PoolModule = class {
|
|
|
5156
5252
|
} catch (e) {
|
|
5157
5253
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "InvalidSwapCountUrl" /* InvalidSwapCountUrl */);
|
|
5158
5254
|
}
|
|
5159
|
-
const pools = json.data
|
|
5255
|
+
const { pools } = json.data;
|
|
5160
5256
|
if (!pools || pools.length === 0) {
|
|
5161
5257
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "PoolsNotFound" /* PoolsNotFound */);
|
|
5162
5258
|
}
|
|
@@ -5697,7 +5793,7 @@ var PoolModule = class {
|
|
|
5697
5793
|
};
|
|
5698
5794
|
|
|
5699
5795
|
// src/modules/positionModule.ts
|
|
5700
|
-
import
|
|
5796
|
+
import BN17 from "bn.js";
|
|
5701
5797
|
import { Transaction as Transaction5 } from "@mysten/sui/transactions";
|
|
5702
5798
|
import { isValidSuiObjectId } from "@mysten/sui/utils";
|
|
5703
5799
|
var PositionModule = class {
|
|
@@ -5919,8 +6015,8 @@ var PositionModule = class {
|
|
|
5919
6015
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
5920
6016
|
const { parsedJson } = valueData[i];
|
|
5921
6017
|
const posRrewarderResult = {
|
|
5922
|
-
feeOwedA: new
|
|
5923
|
-
feeOwedB: new
|
|
6018
|
+
feeOwedA: new BN17(parsedJson.fee_owned_a),
|
|
6019
|
+
feeOwedB: new BN17(parsedJson.fee_owned_b),
|
|
5924
6020
|
position_id: parsedJson.position_id
|
|
5925
6021
|
};
|
|
5926
6022
|
result.push(posRrewarderResult);
|
|
@@ -6296,7 +6392,7 @@ var PositionModule = class {
|
|
|
6296
6392
|
};
|
|
6297
6393
|
|
|
6298
6394
|
// src/modules/rewarderModule.ts
|
|
6299
|
-
import
|
|
6395
|
+
import BN18 from "bn.js";
|
|
6300
6396
|
import { Transaction as Transaction6 } from "@mysten/sui/transactions";
|
|
6301
6397
|
var RewarderModule = class {
|
|
6302
6398
|
_sdk;
|
|
@@ -6322,7 +6418,7 @@ var RewarderModule = class {
|
|
|
6322
6418
|
}
|
|
6323
6419
|
const emissionsEveryDay = [];
|
|
6324
6420
|
for (const rewarderInfo of rewarderInfos) {
|
|
6325
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6421
|
+
const emissionSeconds = MathUtil.fromX64(new BN18(rewarderInfo.emissions_per_second));
|
|
6326
6422
|
emissionsEveryDay.push({
|
|
6327
6423
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6328
6424
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6341,20 +6437,20 @@ var RewarderModule = class {
|
|
|
6341
6437
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6342
6438
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6343
6439
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6344
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6440
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new BN18(lastTime))) {
|
|
6345
6441
|
return currentPool;
|
|
6346
6442
|
}
|
|
6347
|
-
const timeDelta = currentTime.div(new
|
|
6443
|
+
const timeDelta = currentTime.div(new BN18(1e3)).sub(new BN18(lastTime)).add(new BN18(15));
|
|
6348
6444
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6349
6445
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6350
6446
|
const rewarderInfo = rewarderInfos[i];
|
|
6351
6447
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6352
6448
|
timeDelta,
|
|
6353
|
-
new
|
|
6354
|
-
new
|
|
6449
|
+
new BN18(rewarderInfo.emissions_per_second),
|
|
6450
|
+
new BN18(currentPool.liquidity),
|
|
6355
6451
|
128
|
|
6356
6452
|
);
|
|
6357
|
-
this.growthGlobal[i] = new
|
|
6453
|
+
this.growthGlobal[i] = new BN18(rewarderInfo.growth_global).add(new BN18(rewarderGrowthDelta));
|
|
6358
6454
|
}
|
|
6359
6455
|
return currentPool;
|
|
6360
6456
|
}
|
|
@@ -6369,7 +6465,7 @@ var RewarderModule = class {
|
|
|
6369
6465
|
*/
|
|
6370
6466
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6371
6467
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6372
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6468
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
6373
6469
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6374
6470
|
if (position === void 0) {
|
|
6375
6471
|
return [];
|
|
@@ -6390,7 +6486,7 @@ var RewarderModule = class {
|
|
|
6390
6486
|
*/
|
|
6391
6487
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6392
6488
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6393
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6489
|
+
const pool = await this.updatePoolRewarder(poolID, new BN18(currentTime));
|
|
6394
6490
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6395
6491
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6396
6492
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6417,38 +6513,38 @@ var RewarderModule = class {
|
|
|
6417
6513
|
const growthInside = [];
|
|
6418
6514
|
const AmountOwed = [];
|
|
6419
6515
|
if (rewardersInside.length > 0) {
|
|
6420
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6421
|
-
if (growthDelta0.gt(new
|
|
6516
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new BN18(position.reward_growth_inside_0));
|
|
6517
|
+
if (growthDelta0.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6422
6518
|
growthDelta0 = ONE;
|
|
6423
6519
|
}
|
|
6424
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6520
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta0, 64, 128);
|
|
6425
6521
|
growthInside.push(rewardersInside[0]);
|
|
6426
6522
|
AmountOwed.push({
|
|
6427
|
-
amount_owed: new
|
|
6523
|
+
amount_owed: new BN18(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6428
6524
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6429
6525
|
});
|
|
6430
6526
|
}
|
|
6431
6527
|
if (rewardersInside.length > 1) {
|
|
6432
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6433
|
-
if (growthDelta_1.gt(new
|
|
6528
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new BN18(position.reward_growth_inside_1));
|
|
6529
|
+
if (growthDelta_1.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6434
6530
|
growthDelta_1 = ONE;
|
|
6435
6531
|
}
|
|
6436
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6532
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_1, 64, 128);
|
|
6437
6533
|
growthInside.push(rewardersInside[1]);
|
|
6438
6534
|
AmountOwed.push({
|
|
6439
|
-
amount_owed: new
|
|
6535
|
+
amount_owed: new BN18(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6440
6536
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6441
6537
|
});
|
|
6442
6538
|
}
|
|
6443
6539
|
if (rewardersInside.length > 2) {
|
|
6444
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6445
|
-
if (growthDelta_2.gt(new
|
|
6540
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new BN18(position.reward_growth_inside_2));
|
|
6541
|
+
if (growthDelta_2.gt(new BN18("3402823669209384634633745948738404"))) {
|
|
6446
6542
|
growthDelta_2 = ONE;
|
|
6447
6543
|
}
|
|
6448
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6544
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new BN18(position.liquidity), growthDelta_2, 64, 128);
|
|
6449
6545
|
growthInside.push(rewardersInside[2]);
|
|
6450
6546
|
AmountOwed.push({
|
|
6451
|
-
amount_owed: new
|
|
6547
|
+
amount_owed: new BN18(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6452
6548
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6453
6549
|
});
|
|
6454
6550
|
}
|
|
@@ -6562,8 +6658,8 @@ var RewarderModule = class {
|
|
|
6562
6658
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6563
6659
|
const { parsedJson } = valueData[i];
|
|
6564
6660
|
const posRrewarderResult = {
|
|
6565
|
-
feeOwedA: new
|
|
6566
|
-
feeOwedB: new
|
|
6661
|
+
feeOwedA: new BN18(parsedJson.fee_owned_a),
|
|
6662
|
+
feeOwedB: new BN18(parsedJson.fee_owned_b),
|
|
6567
6663
|
position_id: parsedJson.position_id
|
|
6568
6664
|
};
|
|
6569
6665
|
result.push(posRrewarderResult);
|
|
@@ -6626,7 +6722,7 @@ var RewarderModule = class {
|
|
|
6626
6722
|
};
|
|
6627
6723
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6628
6724
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6629
|
-
amount_owed: new
|
|
6725
|
+
amount_owed: new BN18(valueData[i].parsedJson.data[j]),
|
|
6630
6726
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6631
6727
|
});
|
|
6632
6728
|
}
|
|
@@ -6785,7 +6881,7 @@ var RewarderModule = class {
|
|
|
6785
6881
|
};
|
|
6786
6882
|
|
|
6787
6883
|
// src/modules/routerModule.ts
|
|
6788
|
-
import
|
|
6884
|
+
import BN19 from "bn.js";
|
|
6789
6885
|
import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
|
|
6790
6886
|
import { Transaction as Transaction7 } from "@mysten/sui/transactions";
|
|
6791
6887
|
function _pairSymbol(base, quote) {
|
|
@@ -7067,8 +7163,8 @@ var RouterModule = class {
|
|
|
7067
7163
|
if (swapWithMultiPoolParams != null) {
|
|
7068
7164
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7069
7165
|
const onePath2 = {
|
|
7070
|
-
amountIn: new
|
|
7071
|
-
amountOut: new
|
|
7166
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7167
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7072
7168
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7073
7169
|
a2b: [preSwapResult2.aToB],
|
|
7074
7170
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7081,8 +7177,8 @@ var RouterModule = class {
|
|
|
7081
7177
|
priceSlippagePoint
|
|
7082
7178
|
};
|
|
7083
7179
|
const result2 = {
|
|
7084
|
-
amountIn: new
|
|
7085
|
-
amountOut: new
|
|
7180
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7181
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7086
7182
|
paths: [onePath2],
|
|
7087
7183
|
a2b: preSwapResult2.aToB,
|
|
7088
7184
|
b2c: void 0,
|
|
@@ -7104,8 +7200,8 @@ var RouterModule = class {
|
|
|
7104
7200
|
if (swapWithMultiPoolParams != null) {
|
|
7105
7201
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7106
7202
|
const onePath2 = {
|
|
7107
|
-
amountIn: new
|
|
7108
|
-
amountOut: new
|
|
7203
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7204
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7109
7205
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7110
7206
|
a2b: [preSwapResult2.aToB],
|
|
7111
7207
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7118,8 +7214,8 @@ var RouterModule = class {
|
|
|
7118
7214
|
priceSlippagePoint
|
|
7119
7215
|
};
|
|
7120
7216
|
const result3 = {
|
|
7121
|
-
amountIn: new
|
|
7122
|
-
amountOut: new
|
|
7217
|
+
amountIn: new BN19(preSwapResult2.estimatedAmountIn),
|
|
7218
|
+
amountOut: new BN19(preSwapResult2.estimatedAmountOut),
|
|
7123
7219
|
paths: [onePath2],
|
|
7124
7220
|
a2b: preSwapResult2.aToB,
|
|
7125
7221
|
b2c: void 0,
|
|
@@ -7200,8 +7296,8 @@ var RouterModule = class {
|
|
|
7200
7296
|
if (swapWithMultiPoolParams != null) {
|
|
7201
7297
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7202
7298
|
const onePath = {
|
|
7203
|
-
amountIn: new
|
|
7204
|
-
amountOut: new
|
|
7299
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7300
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
7205
7301
|
poolAddress: [preSwapResult.poolAddress],
|
|
7206
7302
|
a2b: [preSwapResult.aToB],
|
|
7207
7303
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -7214,8 +7310,8 @@ var RouterModule = class {
|
|
|
7214
7310
|
priceSlippagePoint
|
|
7215
7311
|
};
|
|
7216
7312
|
const result = {
|
|
7217
|
-
amountIn: new
|
|
7218
|
-
amountOut: new
|
|
7313
|
+
amountIn: new BN19(preSwapResult.estimatedAmountIn),
|
|
7314
|
+
amountOut: new BN19(preSwapResult.estimatedAmountOut),
|
|
7219
7315
|
paths: [onePath],
|
|
7220
7316
|
a2b: preSwapResult.aToB,
|
|
7221
7317
|
b2c: void 0,
|
|
@@ -7299,13 +7395,13 @@ var RouterModule = class {
|
|
|
7299
7395
|
continue;
|
|
7300
7396
|
}
|
|
7301
7397
|
if (params[0].byAmountIn) {
|
|
7302
|
-
const amount = new
|
|
7398
|
+
const amount = new BN19(valueData[i].parsedJson.data.amount_out);
|
|
7303
7399
|
if (amount.gt(tempMaxAmount)) {
|
|
7304
7400
|
tempIndex = i;
|
|
7305
7401
|
tempMaxAmount = amount;
|
|
7306
7402
|
}
|
|
7307
7403
|
} else {
|
|
7308
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7404
|
+
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
7405
|
if (amount.lt(tempMaxAmount)) {
|
|
7310
7406
|
tempIndex = i;
|
|
7311
7407
|
tempMaxAmount = amount;
|
|
@@ -7375,7 +7471,7 @@ var RouterModule = class {
|
|
|
7375
7471
|
};
|
|
7376
7472
|
|
|
7377
7473
|
// src/modules/swapModule.ts
|
|
7378
|
-
import
|
|
7474
|
+
import BN20 from "bn.js";
|
|
7379
7475
|
import Decimal8 from "decimal.js";
|
|
7380
7476
|
import { Transaction as Transaction8 } from "@mysten/sui/transactions";
|
|
7381
7477
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
@@ -7491,13 +7587,13 @@ var SwapModule = class {
|
|
|
7491
7587
|
continue;
|
|
7492
7588
|
}
|
|
7493
7589
|
if (params.byAmountIn) {
|
|
7494
|
-
const amount = new
|
|
7590
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7495
7591
|
if (amount.gt(tempMaxAmount)) {
|
|
7496
7592
|
tempIndex = i;
|
|
7497
7593
|
tempMaxAmount = amount;
|
|
7498
7594
|
}
|
|
7499
7595
|
} else {
|
|
7500
|
-
const amount = new
|
|
7596
|
+
const amount = new BN20(valueData[i].parsedJson.data.amount_out);
|
|
7501
7597
|
if (amount.lt(tempMaxAmount)) {
|
|
7502
7598
|
tempIndex = i;
|
|
7503
7599
|
tempMaxAmount = amount;
|
|
@@ -7561,7 +7657,7 @@ var SwapModule = class {
|
|
|
7561
7657
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7562
7658
|
}
|
|
7563
7659
|
transformSwapData(params, data) {
|
|
7564
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7660
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7565
7661
|
return {
|
|
7566
7662
|
poolAddress: params.pool.poolAddress,
|
|
7567
7663
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7578,7 +7674,7 @@ var SwapModule = class {
|
|
|
7578
7674
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7579
7675
|
const { data } = jsonData;
|
|
7580
7676
|
console.log("json data. ", data);
|
|
7581
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7677
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new BN20(data.amount_in).add(new BN20(data.fee_amount)).toString() : "";
|
|
7582
7678
|
return {
|
|
7583
7679
|
poolAddress: params.poolAddress,
|
|
7584
7680
|
estimatedAmountIn,
|
|
@@ -9091,7 +9187,7 @@ var TokenModule = class {
|
|
|
9091
9187
|
};
|
|
9092
9188
|
|
|
9093
9189
|
// src/modules/routerModuleV2.ts
|
|
9094
|
-
import
|
|
9190
|
+
import BN21 from "bn.js";
|
|
9095
9191
|
import Decimal9 from "decimal.js";
|
|
9096
9192
|
import { v4 as uuidv4 } from "uuid";
|
|
9097
9193
|
import axios from "axios";
|
|
@@ -9135,12 +9231,12 @@ var RouterModuleV2 = class {
|
|
|
9135
9231
|
outputAmount: basePath.output_amount,
|
|
9136
9232
|
inputAmount: basePath.input_amount,
|
|
9137
9233
|
feeRate: basePath.fee_rate,
|
|
9138
|
-
currentSqrtPrice: new
|
|
9139
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9234
|
+
currentSqrtPrice: new BN21(basePath.current_sqrt_price.toString()),
|
|
9235
|
+
afterSqrtPrice: basePath.label === "Magma" ? new BN21(basePath.after_sqrt_price.toString()) : ZERO,
|
|
9140
9236
|
fromDecimal: basePath.from_decimal,
|
|
9141
9237
|
toDecimal: basePath.to_decimal,
|
|
9142
9238
|
currentPrice: this.calculatePrice(
|
|
9143
|
-
new
|
|
9239
|
+
new BN21(basePath.current_sqrt_price.toString()),
|
|
9144
9240
|
basePath.from_decimal,
|
|
9145
9241
|
basePath.to_decimal,
|
|
9146
9242
|
basePath.direction,
|
|
@@ -9223,7 +9319,7 @@ var RouterModuleV2 = class {
|
|
|
9223
9319
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9224
9320
|
from,
|
|
9225
9321
|
to,
|
|
9226
|
-
new
|
|
9322
|
+
new BN21(amount),
|
|
9227
9323
|
byAmountIn,
|
|
9228
9324
|
priceSplitPoint,
|
|
9229
9325
|
partner,
|
|
@@ -9235,7 +9331,7 @@ var RouterModuleV2 = class {
|
|
|
9235
9331
|
if (path.poolAddress.length > 1) {
|
|
9236
9332
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9237
9333
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9238
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9334
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9239
9335
|
const path0 = {
|
|
9240
9336
|
direction: path.a2b[0],
|
|
9241
9337
|
label: "Magma",
|
|
@@ -9252,7 +9348,7 @@ var RouterModuleV2 = class {
|
|
|
9252
9348
|
};
|
|
9253
9349
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9254
9350
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9255
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9351
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9256
9352
|
const path1 = {
|
|
9257
9353
|
direction: path.a2b[1],
|
|
9258
9354
|
label: "Magma",
|
|
@@ -9271,7 +9367,7 @@ var RouterModuleV2 = class {
|
|
|
9271
9367
|
} else {
|
|
9272
9368
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9273
9369
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9274
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9370
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9275
9371
|
const path0 = {
|
|
9276
9372
|
direction: path.a2b[0],
|
|
9277
9373
|
label: "Magma",
|
|
@@ -9356,7 +9452,7 @@ var RouterModuleV2 = class {
|
|
|
9356
9452
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9357
9453
|
from,
|
|
9358
9454
|
to,
|
|
9359
|
-
new
|
|
9455
|
+
new BN21(amount),
|
|
9360
9456
|
byAmountIn,
|
|
9361
9457
|
priceSplitPoint,
|
|
9362
9458
|
partner,
|
|
@@ -9368,7 +9464,7 @@ var RouterModuleV2 = class {
|
|
|
9368
9464
|
if (path.poolAddress.length > 1) {
|
|
9369
9465
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9370
9466
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9371
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9467
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9372
9468
|
const path0 = {
|
|
9373
9469
|
direction: path.a2b[0],
|
|
9374
9470
|
label: "Magma",
|
|
@@ -9385,7 +9481,7 @@ var RouterModuleV2 = class {
|
|
|
9385
9481
|
};
|
|
9386
9482
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9387
9483
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9388
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9484
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9389
9485
|
const path1 = {
|
|
9390
9486
|
direction: path.a2b[1],
|
|
9391
9487
|
label: "Magma",
|
|
@@ -9404,7 +9500,7 @@ var RouterModuleV2 = class {
|
|
|
9404
9500
|
} else {
|
|
9405
9501
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9406
9502
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9407
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9503
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new BN21(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9408
9504
|
const path0 = {
|
|
9409
9505
|
direction: path.a2b[0],
|
|
9410
9506
|
label: "Magma",
|
|
@@ -10500,65 +10596,65 @@ var DlmmModule = class {
|
|
|
10500
10596
|
});
|
|
10501
10597
|
return tx;
|
|
10502
10598
|
}
|
|
10503
|
-
// Create a position by percent
|
|
10504
|
-
async mintPercent(params) {
|
|
10505
|
-
|
|
10506
|
-
|
|
10507
|
-
|
|
10508
|
-
|
|
10509
|
-
|
|
10510
|
-
|
|
10511
|
-
|
|
10512
|
-
|
|
10513
|
-
|
|
10514
|
-
|
|
10515
|
-
|
|
10516
|
-
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10530
|
-
|
|
10531
|
-
|
|
10532
|
-
}
|
|
10533
|
-
// Create a position by amount
|
|
10534
|
-
async createPositionByAmount(params) {
|
|
10535
|
-
|
|
10536
|
-
|
|
10537
|
-
|
|
10538
|
-
|
|
10539
|
-
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10557
|
-
|
|
10558
|
-
|
|
10559
|
-
|
|
10560
|
-
}
|
|
10561
|
-
async
|
|
10599
|
+
// // Create a position by percent
|
|
10600
|
+
// async mintPercent(params: MintPercentParams): Promise<Transaction> {
|
|
10601
|
+
// const tx = new Transaction()
|
|
10602
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10603
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10604
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10605
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10606
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10607
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10608
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10609
|
+
// const args = [
|
|
10610
|
+
// tx.object(params.pair),
|
|
10611
|
+
// tx.object(dlmmConfig.factory),
|
|
10612
|
+
// primaryCoinAInputs.targetCoin,
|
|
10613
|
+
// primaryCoinBInputs.targetCoin,
|
|
10614
|
+
// tx.pure.u64(params.amountATotal),
|
|
10615
|
+
// tx.pure.u64(params.amountBTotal),
|
|
10616
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10617
|
+
// tx.pure.vector('u64', params.binsAPercent),
|
|
10618
|
+
// tx.pure.vector('u64', params.binsBPercent),
|
|
10619
|
+
// tx.pure.address(params.to),
|
|
10620
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10621
|
+
// ]
|
|
10622
|
+
// tx.moveCall({
|
|
10623
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
|
|
10624
|
+
// typeArguments,
|
|
10625
|
+
// arguments: args,
|
|
10626
|
+
// })
|
|
10627
|
+
// return tx
|
|
10628
|
+
// }
|
|
10629
|
+
// // Create a position by amount
|
|
10630
|
+
// async createPositionByAmount(params: MintAmountParams): Promise<Transaction> {
|
|
10631
|
+
// const tx = new Transaction()
|
|
10632
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10633
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10634
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10635
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10636
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10637
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10638
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10639
|
+
// const args = [
|
|
10640
|
+
// tx.object(params.pair),
|
|
10641
|
+
// tx.object(dlmmConfig.factory),
|
|
10642
|
+
// primaryCoinAInputs.targetCoin,
|
|
10643
|
+
// primaryCoinBInputs.targetCoin,
|
|
10644
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10645
|
+
// tx.pure.vector('u64', params.amountsA),
|
|
10646
|
+
// tx.pure.vector('u64', params.amountsB),
|
|
10647
|
+
// tx.pure.address(params.to),
|
|
10648
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10649
|
+
// ]
|
|
10650
|
+
// tx.moveCall({
|
|
10651
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
|
|
10652
|
+
// typeArguments,
|
|
10653
|
+
// arguments: args,
|
|
10654
|
+
// })
|
|
10655
|
+
// return tx
|
|
10656
|
+
// }
|
|
10657
|
+
async addLiquidityByStrategy(params) {
|
|
10562
10658
|
if (params.rewards_token.length === 0) {
|
|
10563
10659
|
return this._raisePositionByAmounts(params);
|
|
10564
10660
|
}
|
|
@@ -10566,24 +10662,58 @@ var DlmmModule = class {
|
|
|
10566
10662
|
}
|
|
10567
10663
|
async _raisePositionByAmounts(params) {
|
|
10568
10664
|
const tx = new Transaction12();
|
|
10665
|
+
const slippage = new Decimal10(params.slippage);
|
|
10666
|
+
const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
|
|
10667
|
+
const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
|
|
10569
10668
|
tx.setSender(this.sdk.senderAddress);
|
|
10570
10669
|
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10571
10670
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10572
|
-
const
|
|
10671
|
+
const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
|
|
10672
|
+
const min_price = new Decimal10(price).mul(lower_slippage);
|
|
10673
|
+
const max_price = new Decimal10(price).mul(upper_slippage);
|
|
10674
|
+
const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10675
|
+
const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10676
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10573
10677
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
|
|
10577
|
-
|
|
10678
|
+
let amount_min = 0;
|
|
10679
|
+
let amount_max = 0;
|
|
10680
|
+
let primaryCoinAInputs;
|
|
10681
|
+
let primaryCoinBInputs;
|
|
10682
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10683
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10684
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10685
|
+
} else if (params.fixCoinA) {
|
|
10686
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10687
|
+
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10688
|
+
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10689
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10690
|
+
} else if (params.fixCoinB) {
|
|
10691
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10692
|
+
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10693
|
+
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10694
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10695
|
+
}
|
|
10696
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10697
|
+
} else if (params.fixCoinA) {
|
|
10698
|
+
params.amountBTotal = 0;
|
|
10699
|
+
} else if (params.fixCoinB) {
|
|
10700
|
+
params.amountATotal = 0;
|
|
10701
|
+
}
|
|
10578
10702
|
const args = [
|
|
10579
|
-
tx.object(params.
|
|
10703
|
+
tx.object(params.pair),
|
|
10580
10704
|
tx.object(dlmmConfig.factory),
|
|
10581
|
-
tx.object(params.
|
|
10705
|
+
tx.object(params.positionId),
|
|
10582
10706
|
primaryCoinAInputs.targetCoin,
|
|
10583
10707
|
primaryCoinBInputs.targetCoin,
|
|
10584
|
-
tx.pure.
|
|
10585
|
-
tx.pure.
|
|
10586
|
-
tx.pure.
|
|
10708
|
+
tx.pure.bool(params.fixCoinA),
|
|
10709
|
+
tx.pure.u64(params.amountATotal),
|
|
10710
|
+
tx.pure.bool(params.fixCoinB),
|
|
10711
|
+
tx.pure.u64(params.amountBTotal),
|
|
10712
|
+
tx.pure.u8(params.strategy),
|
|
10713
|
+
tx.pure.u32(active_min),
|
|
10714
|
+
tx.pure.u32(active_max),
|
|
10715
|
+
tx.pure.u64(amount_min),
|
|
10716
|
+
tx.pure.u64(amount_max),
|
|
10587
10717
|
tx.object(CLOCK_ADDRESS)
|
|
10588
10718
|
];
|
|
10589
10719
|
tx.moveCall({
|
|
@@ -10595,26 +10725,58 @@ var DlmmModule = class {
|
|
|
10595
10725
|
}
|
|
10596
10726
|
async _raisePositionByAmountsReward(params) {
|
|
10597
10727
|
const tx = new Transaction12();
|
|
10728
|
+
const slippage = new Decimal10(params.slippage);
|
|
10729
|
+
const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
|
|
10730
|
+
const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
|
|
10598
10731
|
tx.setSender(this.sdk.senderAddress);
|
|
10599
|
-
const { dlmm_pool, integrate
|
|
10732
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10600
10733
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10601
|
-
const
|
|
10602
|
-
const
|
|
10734
|
+
const price = get_price_x128_from_real_id3(params.active_bin, params.bin_step);
|
|
10735
|
+
const min_price = new Decimal10(price).mul(lower_slippage);
|
|
10736
|
+
const max_price = new Decimal10(price).mul(upper_slippage);
|
|
10737
|
+
const active_min = get_storage_id_from_real_id(get_real_id_from_price_x1282(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10738
|
+
const active_max = get_storage_id_from_real_id(get_real_id_from_price_x1282(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10739
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, ...params.rewards_token];
|
|
10603
10740
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10604
|
-
|
|
10605
|
-
|
|
10606
|
-
|
|
10607
|
-
|
|
10741
|
+
let amount_min = 0;
|
|
10742
|
+
let amount_max = 0;
|
|
10743
|
+
let primaryCoinAInputs;
|
|
10744
|
+
let primaryCoinBInputs;
|
|
10745
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10746
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10747
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10748
|
+
} else if (params.fixCoinA) {
|
|
10749
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10750
|
+
amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10751
|
+
amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10752
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10753
|
+
} else if (params.fixCoinB) {
|
|
10754
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10755
|
+
amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10756
|
+
amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10757
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10758
|
+
}
|
|
10759
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10760
|
+
} else if (params.fixCoinA) {
|
|
10761
|
+
params.amountBTotal = 0;
|
|
10762
|
+
} else if (params.fixCoinB) {
|
|
10763
|
+
params.amountATotal = 0;
|
|
10764
|
+
}
|
|
10608
10765
|
const args = [
|
|
10609
|
-
tx.object(params.
|
|
10766
|
+
tx.object(params.pair),
|
|
10610
10767
|
tx.object(dlmmConfig.factory),
|
|
10611
|
-
tx.object(
|
|
10612
|
-
tx.object(params.position_id),
|
|
10768
|
+
tx.object(params.positionId),
|
|
10613
10769
|
primaryCoinAInputs.targetCoin,
|
|
10614
10770
|
primaryCoinBInputs.targetCoin,
|
|
10615
|
-
tx.pure.
|
|
10616
|
-
tx.pure.
|
|
10617
|
-
tx.pure.
|
|
10771
|
+
tx.pure.bool(params.fixCoinA),
|
|
10772
|
+
tx.pure.u64(params.amountATotal),
|
|
10773
|
+
tx.pure.bool(params.fixCoinB),
|
|
10774
|
+
tx.pure.u64(params.amountBTotal),
|
|
10775
|
+
tx.pure.u8(params.strategy),
|
|
10776
|
+
tx.pure.u32(active_min),
|
|
10777
|
+
tx.pure.u32(active_max),
|
|
10778
|
+
tx.pure.u64(amount_min),
|
|
10779
|
+
tx.pure.u64(amount_max),
|
|
10618
10780
|
tx.object(CLOCK_ADDRESS)
|
|
10619
10781
|
];
|
|
10620
10782
|
tx.moveCall({
|