@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.js
CHANGED
|
@@ -257,7 +257,7 @@ var CachedContent = class {
|
|
|
257
257
|
};
|
|
258
258
|
|
|
259
259
|
// src/utils/common.ts
|
|
260
|
-
var
|
|
260
|
+
var import_bn13 = __toESM(require("bn.js"));
|
|
261
261
|
var import_bcs = require("@mysten/bcs");
|
|
262
262
|
var import_ed25519 = require("@mysten/sui/keypairs/ed25519");
|
|
263
263
|
var import_secp256k1 = require("@mysten/sui/keypairs/secp256k1");
|
|
@@ -1812,6 +1812,9 @@ function collectFeesQuote(param) {
|
|
|
1812
1812
|
return updateFees(param.position, fee_growth_inside_a, fee_growth_inside_b);
|
|
1813
1813
|
}
|
|
1814
1814
|
|
|
1815
|
+
// src/math/dlmmStrategy.ts
|
|
1816
|
+
var import_bn10 = __toESM(require("bn.js"));
|
|
1817
|
+
|
|
1815
1818
|
// src/math/dlmmWeightToAmounts.ts
|
|
1816
1819
|
var import_bn9 = __toESM(require("bn.js"));
|
|
1817
1820
|
var import_decimal6 = __toESM(require("decimal.js"));
|
|
@@ -2228,40 +2231,133 @@ function autoFillXByStrategy(activeId, binStep, amountY, amountXInActiveBin, amo
|
|
|
2228
2231
|
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2229
2232
|
}
|
|
2230
2233
|
}
|
|
2234
|
+
function assignLeftAmountX(activeId, binStep, maxBinId, amountX, strategyType) {
|
|
2235
|
+
if (maxBinId < activeId) {
|
|
2236
|
+
return [];
|
|
2237
|
+
}
|
|
2238
|
+
let weights = [];
|
|
2239
|
+
switch (strategyType) {
|
|
2240
|
+
case 1 /* Spot */: {
|
|
2241
|
+
weights = toWeightSpotBalanced(activeId, maxBinId);
|
|
2242
|
+
break;
|
|
2243
|
+
}
|
|
2244
|
+
case 2 /* Curve */: {
|
|
2245
|
+
weights = toWeightDecendingOrder(activeId, maxBinId);
|
|
2246
|
+
break;
|
|
2247
|
+
}
|
|
2248
|
+
case 3 /* BidAsk */: {
|
|
2249
|
+
weights = toWeightAscendingOrder(activeId, maxBinId);
|
|
2250
|
+
break;
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
const amounts = toAmountAskSide(activeId, binStep, amountX, weights);
|
|
2254
|
+
return amounts.map((bin) => {
|
|
2255
|
+
return {
|
|
2256
|
+
binId: bin.binId,
|
|
2257
|
+
amountX: bin.amount,
|
|
2258
|
+
amountY: new import_bn10.default(0)
|
|
2259
|
+
};
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
function assignLeftAmountY(activeId, minBinId, amountY, strategyType) {
|
|
2263
|
+
if (minBinId > activeId) {
|
|
2264
|
+
return [];
|
|
2265
|
+
}
|
|
2266
|
+
let weights = [];
|
|
2267
|
+
switch (strategyType) {
|
|
2268
|
+
case 1 /* Spot */: {
|
|
2269
|
+
weights = toWeightSpotBalanced(minBinId, activeId);
|
|
2270
|
+
break;
|
|
2271
|
+
}
|
|
2272
|
+
case 2 /* Curve */: {
|
|
2273
|
+
weights = toWeightAscendingOrder(minBinId, activeId);
|
|
2274
|
+
break;
|
|
2275
|
+
}
|
|
2276
|
+
case 3 /* BidAsk */: {
|
|
2277
|
+
weights = toWeightDecendingOrder(minBinId, activeId);
|
|
2278
|
+
break;
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
const amounts = toAmountBidSide(activeId, amountY, weights);
|
|
2282
|
+
return amounts.map((bin) => {
|
|
2283
|
+
return {
|
|
2284
|
+
binId: bin.binId,
|
|
2285
|
+
amountX: new import_bn10.default(0),
|
|
2286
|
+
amountY: bin.amount
|
|
2287
|
+
};
|
|
2288
|
+
});
|
|
2289
|
+
}
|
|
2290
|
+
function mergeBinDisplay(to, from) {
|
|
2291
|
+
const binMap = /* @__PURE__ */ new Map();
|
|
2292
|
+
for (const bin of to) {
|
|
2293
|
+
binMap.set(bin.binId, bin);
|
|
2294
|
+
}
|
|
2295
|
+
for (const bin of from) {
|
|
2296
|
+
const existingBin = binMap.get(bin.binId);
|
|
2297
|
+
if (existingBin) {
|
|
2298
|
+
existingBin.amountX = existingBin.amountX.add(bin.amountX);
|
|
2299
|
+
existingBin.amountY = existingBin.amountY.add(bin.amountY);
|
|
2300
|
+
} else {
|
|
2301
|
+
binMap.set(bin.binId, bin);
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
return Array.from(binMap.values()).sort((a, b) => {
|
|
2305
|
+
return a.binId - b.binId;
|
|
2306
|
+
});
|
|
2307
|
+
}
|
|
2231
2308
|
function toAmountsBothSideByStrategy(activeId, binStep, minBinId, maxBinId, amountX, amountY, amountXInActiveBin, amountYInActiveBin, strategyType) {
|
|
2232
2309
|
const isSingleSideX = amountY.isZero();
|
|
2310
|
+
let res = [];
|
|
2233
2311
|
switch (strategyType) {
|
|
2234
2312
|
case 1 /* Spot */: {
|
|
2235
2313
|
const weights = toWeightSpotBalanced(minBinId, maxBinId);
|
|
2236
|
-
|
|
2314
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2315
|
+
break;
|
|
2237
2316
|
}
|
|
2238
2317
|
case 2 /* Curve */: {
|
|
2239
2318
|
if (activeId < minBinId) {
|
|
2240
2319
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2241
|
-
|
|
2320
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2242
2321
|
}
|
|
2243
2322
|
if (activeId > maxBinId) {
|
|
2244
2323
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2245
|
-
|
|
2324
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2246
2325
|
}
|
|
2247
2326
|
const weights = toWeightCurve(minBinId, maxBinId, activeId);
|
|
2248
|
-
|
|
2327
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2328
|
+
break;
|
|
2249
2329
|
}
|
|
2250
2330
|
case 3 /* BidAsk */: {
|
|
2251
2331
|
if (activeId < minBinId) {
|
|
2252
2332
|
const weights2 = toWeightAscendingOrder(minBinId, maxBinId);
|
|
2253
|
-
|
|
2333
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2254
2334
|
}
|
|
2255
2335
|
if (activeId > maxBinId) {
|
|
2256
2336
|
const weights2 = toWeightDecendingOrder(minBinId, maxBinId);
|
|
2257
|
-
|
|
2337
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights2);
|
|
2258
2338
|
}
|
|
2259
2339
|
const weights = toWeightBidAsk(minBinId, maxBinId, activeId);
|
|
2260
|
-
|
|
2340
|
+
res = toAmountBothSide(activeId, binStep, amountX, amountY, amountXInActiveBin, amountYInActiveBin, weights);
|
|
2341
|
+
break;
|
|
2261
2342
|
}
|
|
2262
2343
|
default:
|
|
2263
2344
|
throw new Error(`Unsupported strategy type: ${strategyType}`);
|
|
2264
2345
|
}
|
|
2346
|
+
let amountXLeft = amountX;
|
|
2347
|
+
let amountYLeft = amountY;
|
|
2348
|
+
res.forEach((bin) => {
|
|
2349
|
+
amountXLeft = amountXLeft.sub(bin.amountX);
|
|
2350
|
+
amountYLeft = amountYLeft.sub(bin.amountY);
|
|
2351
|
+
});
|
|
2352
|
+
if (amountXLeft.gt(new import_bn10.default(0))) {
|
|
2353
|
+
const xAssigned = assignLeftAmountX(activeId, binStep, maxBinId, amountXLeft, strategyType);
|
|
2354
|
+
res = mergeBinDisplay(res, xAssigned);
|
|
2355
|
+
}
|
|
2356
|
+
if (amountYLeft.gt(new import_bn10.default(0))) {
|
|
2357
|
+
const yAssigned = assignLeftAmountY(activeId, minBinId, amountYLeft, strategyType);
|
|
2358
|
+
res = mergeBinDisplay(res, yAssigned);
|
|
2359
|
+
}
|
|
2360
|
+
return res;
|
|
2265
2361
|
}
|
|
2266
2362
|
|
|
2267
2363
|
// src/math/LiquidityHelper.ts
|
|
@@ -2317,7 +2413,7 @@ function getCoinXYForLiquidity(liquidity, reserveInSize, reserveOutSize, lpSuply
|
|
|
2317
2413
|
}
|
|
2318
2414
|
|
|
2319
2415
|
// src/math/percentage.ts
|
|
2320
|
-
var
|
|
2416
|
+
var import_bn11 = __toESM(require("bn.js"));
|
|
2321
2417
|
var Percentage = class {
|
|
2322
2418
|
numerator;
|
|
2323
2419
|
denominator;
|
|
@@ -2345,8 +2441,8 @@ var Percentage = class {
|
|
|
2345
2441
|
* @returns
|
|
2346
2442
|
*/
|
|
2347
2443
|
static fromFraction(numerator, denominator) {
|
|
2348
|
-
const num = typeof numerator === "number" ? new
|
|
2349
|
-
const denom = typeof denominator === "number" ? new
|
|
2444
|
+
const num = typeof numerator === "number" ? new import_bn11.default(numerator.toString()) : numerator;
|
|
2445
|
+
const denom = typeof denominator === "number" ? new import_bn11.default(denominator.toString()) : denominator;
|
|
2350
2446
|
return new Percentage(num, denom);
|
|
2351
2447
|
}
|
|
2352
2448
|
};
|
|
@@ -2446,7 +2542,7 @@ function adjustForCoinSlippage(tokenAmount, slippage, adjustUp) {
|
|
|
2446
2542
|
}
|
|
2447
2543
|
|
|
2448
2544
|
// src/math/SplitSwap.ts
|
|
2449
|
-
var
|
|
2545
|
+
var import_bn12 = __toESM(require("bn.js"));
|
|
2450
2546
|
var SplitUnit = /* @__PURE__ */ ((SplitUnit2) => {
|
|
2451
2547
|
SplitUnit2[SplitUnit2["FIVE"] = 5] = "FIVE";
|
|
2452
2548
|
SplitUnit2[SplitUnit2["TEN"] = 10] = "TEN";
|
|
@@ -2504,7 +2600,7 @@ function updateSplitSwapResult(maxIndex, currentIndex, splitSwapResult, stepResu
|
|
|
2504
2600
|
return splitSwapResult;
|
|
2505
2601
|
}
|
|
2506
2602
|
function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
2507
|
-
let currentLiquidity = new
|
|
2603
|
+
let currentLiquidity = new import_bn12.default(poolData.liquidity);
|
|
2508
2604
|
let { currentSqrtPrice } = poolData;
|
|
2509
2605
|
let splitSwapResult = {
|
|
2510
2606
|
amountInArray: [],
|
|
@@ -2567,7 +2663,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2567
2663
|
targetSqrtPrice,
|
|
2568
2664
|
currentLiquidity,
|
|
2569
2665
|
remainerAmount,
|
|
2570
|
-
new
|
|
2666
|
+
new import_bn12.default(poolData.feeRate),
|
|
2571
2667
|
byAmountIn
|
|
2572
2668
|
);
|
|
2573
2669
|
tempStepResult = stepResult;
|
|
@@ -2579,7 +2675,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2579
2675
|
splitSwapResult.amountOutArray[i] = splitSwapResult.amountOutArray[i].add(stepResult.amountOut);
|
|
2580
2676
|
splitSwapResult.feeAmountArray[i] = splitSwapResult.feeAmountArray[i].add(stepResult.feeAmount);
|
|
2581
2677
|
if (stepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2582
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2678
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
|
|
2583
2679
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2584
2680
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2585
2681
|
} else {
|
|
@@ -2604,7 +2700,7 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
|
|
|
2604
2700
|
break;
|
|
2605
2701
|
}
|
|
2606
2702
|
if (tempStepResult.nextSqrtPrice.eq(tick.sqrtPrice)) {
|
|
2607
|
-
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new
|
|
2703
|
+
signedLiquidityChange = a2b ? tick.liquidityNet.mul(new import_bn12.default(-1)) : tick.liquidityNet;
|
|
2608
2704
|
currentLiquidity = signedLiquidityChange.gt(ZERO) ? currentLiquidity.add(signedLiquidityChange) : currentLiquidity.sub(signedLiquidityChange.abs());
|
|
2609
2705
|
currentSqrtPrice = tick.sqrtPrice;
|
|
2610
2706
|
} else {
|
|
@@ -2829,7 +2925,7 @@ function buildPool(objects) {
|
|
|
2829
2925
|
const rewarders = [];
|
|
2830
2926
|
fields.rewarder_manager.fields.rewarders.forEach((item) => {
|
|
2831
2927
|
const { emissions_per_second } = item.fields;
|
|
2832
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
2928
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn13.default(emissions_per_second));
|
|
2833
2929
|
const emissionsEveryDay = Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24);
|
|
2834
2930
|
rewarders.push({
|
|
2835
2931
|
emissions_per_second,
|
|
@@ -3021,11 +3117,11 @@ function buildTickData(objects) {
|
|
|
3021
3117
|
const possition = {
|
|
3022
3118
|
objectId: getObjectId(objects),
|
|
3023
3119
|
index: asIntN(BigInt(valueItem.index.fields.bits)),
|
|
3024
|
-
sqrtPrice: new
|
|
3025
|
-
liquidityNet: new
|
|
3026
|
-
liquidityGross: new
|
|
3027
|
-
feeGrowthOutsideA: new
|
|
3028
|
-
feeGrowthOutsideB: new
|
|
3120
|
+
sqrtPrice: new import_bn13.default(valueItem.sqrt_price),
|
|
3121
|
+
liquidityNet: new import_bn13.default(valueItem.liquidity_net.fields.bits),
|
|
3122
|
+
liquidityGross: new import_bn13.default(valueItem.liquidity_gross),
|
|
3123
|
+
feeGrowthOutsideA: new import_bn13.default(valueItem.fee_growth_outside_a),
|
|
3124
|
+
feeGrowthOutsideB: new import_bn13.default(valueItem.fee_growth_outside_b),
|
|
3029
3125
|
rewardersGrowthOutside: valueItem.rewards_growth_outside
|
|
3030
3126
|
};
|
|
3031
3127
|
return possition;
|
|
@@ -3035,11 +3131,11 @@ function buildTickDataByEvent(fields) {
|
|
|
3035
3131
|
throw new ClmmpoolsError(`Invalid tick fields.`, "InvalidTickFields" /* InvalidTickFields */);
|
|
3036
3132
|
}
|
|
3037
3133
|
const index = asIntN(BigInt(fields.index.bits));
|
|
3038
|
-
const sqrtPrice = new
|
|
3039
|
-
const liquidityNet = new
|
|
3040
|
-
const liquidityGross = new
|
|
3041
|
-
const feeGrowthOutsideA = new
|
|
3042
|
-
const feeGrowthOutsideB = new
|
|
3134
|
+
const sqrtPrice = new import_bn13.default(fields.sqrt_price);
|
|
3135
|
+
const liquidityNet = new import_bn13.default(fields.liquidity_net.bits);
|
|
3136
|
+
const liquidityGross = new import_bn13.default(fields.liquidity_gross);
|
|
3137
|
+
const feeGrowthOutsideA = new import_bn13.default(fields.fee_growth_outside_a);
|
|
3138
|
+
const feeGrowthOutsideB = new import_bn13.default(fields.fee_growth_outside_b);
|
|
3043
3139
|
const rewardersGrowthOutside = fields.rewards_growth_outside || [];
|
|
3044
3140
|
const tick = {
|
|
3045
3141
|
objectId: "",
|
|
@@ -3058,7 +3154,7 @@ function buildClmmPositionName(pool_index, position_index) {
|
|
|
3058
3154
|
}
|
|
3059
3155
|
|
|
3060
3156
|
// src/utils/tick.ts
|
|
3061
|
-
var
|
|
3157
|
+
var import_bn14 = __toESM(require("bn.js"));
|
|
3062
3158
|
var TickUtil = class {
|
|
3063
3159
|
/**
|
|
3064
3160
|
* Get min tick index.
|
|
@@ -3098,22 +3194,22 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
3098
3194
|
let rewarder_growth_below = growthGlobal[i];
|
|
3099
3195
|
if (tickLower !== null) {
|
|
3100
3196
|
if (pool.current_tick_index < tickLowerIndex) {
|
|
3101
|
-
rewarder_growth_below = growthGlobal[i].sub(new
|
|
3197
|
+
rewarder_growth_below = growthGlobal[i].sub(new import_bn14.default(tickLower.rewardersGrowthOutside[i]));
|
|
3102
3198
|
} else {
|
|
3103
3199
|
rewarder_growth_below = tickLower.rewardersGrowthOutside[i];
|
|
3104
3200
|
}
|
|
3105
3201
|
}
|
|
3106
|
-
let rewarder_growth_above = new
|
|
3202
|
+
let rewarder_growth_above = new import_bn14.default(0);
|
|
3107
3203
|
if (tickUpper !== null) {
|
|
3108
3204
|
if (pool.current_tick_index >= tickUpperIndex) {
|
|
3109
|
-
rewarder_growth_above = growthGlobal[i].sub(new
|
|
3205
|
+
rewarder_growth_above = growthGlobal[i].sub(new import_bn14.default(tickUpper.rewardersGrowthOutside[i]));
|
|
3110
3206
|
} else {
|
|
3111
3207
|
rewarder_growth_above = tickUpper.rewardersGrowthOutside[i];
|
|
3112
3208
|
}
|
|
3113
3209
|
}
|
|
3114
3210
|
const rewGrowthInside = MathUtil.subUnderflowU128(
|
|
3115
|
-
MathUtil.subUnderflowU128(new
|
|
3116
|
-
new
|
|
3211
|
+
MathUtil.subUnderflowU128(new import_bn14.default(growthGlobal[i]), new import_bn14.default(rewarder_growth_below)),
|
|
3212
|
+
new import_bn14.default(rewarder_growth_above)
|
|
3117
3213
|
);
|
|
3118
3214
|
rewarderGrowthInside.push(rewGrowthInside);
|
|
3119
3215
|
}
|
|
@@ -3121,7 +3217,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
|
|
|
3121
3217
|
}
|
|
3122
3218
|
|
|
3123
3219
|
// src/utils/transaction-util.ts
|
|
3124
|
-
var
|
|
3220
|
+
var import_bn15 = __toESM(require("bn.js"));
|
|
3125
3221
|
var import_decimal10 = __toESM(require("decimal.js"));
|
|
3126
3222
|
var import_transactions = require("@mysten/sui/transactions");
|
|
3127
3223
|
function findAdjustCoin(coinPair) {
|
|
@@ -3430,7 +3526,7 @@ var _TransactionUtil = class {
|
|
|
3430
3526
|
const liquidityInput = ClmmPoolUtil.estLiquidityAndcoinAmountFromOneAmounts(
|
|
3431
3527
|
Number(params.tick_lower),
|
|
3432
3528
|
Number(params.tick_upper),
|
|
3433
|
-
new
|
|
3529
|
+
new import_bn15.default(coinAmount),
|
|
3434
3530
|
params.fix_amount_a,
|
|
3435
3531
|
true,
|
|
3436
3532
|
slippage,
|
|
@@ -4498,7 +4594,7 @@ var _TransactionUtil = class {
|
|
|
4498
4594
|
const basePath = splitPath.basePaths[i];
|
|
4499
4595
|
a2b.push(basePath.direction);
|
|
4500
4596
|
poolAddress.push(basePath.poolAddress);
|
|
4501
|
-
rawAmountLimit.push(new
|
|
4597
|
+
rawAmountLimit.push(new import_bn15.default(basePath.inputAmount.toString()));
|
|
4502
4598
|
if (i === 0) {
|
|
4503
4599
|
coinType.push(basePath.fromCoin, basePath.toCoin);
|
|
4504
4600
|
} else {
|
|
@@ -4506,8 +4602,8 @@ var _TransactionUtil = class {
|
|
|
4506
4602
|
}
|
|
4507
4603
|
}
|
|
4508
4604
|
const onePath = {
|
|
4509
|
-
amountIn: new
|
|
4510
|
-
amountOut: new
|
|
4605
|
+
amountIn: new import_bn15.default(splitPath.inputAmount.toString()),
|
|
4606
|
+
amountOut: new import_bn15.default(splitPath.outputAmount.toString()),
|
|
4511
4607
|
poolAddress,
|
|
4512
4608
|
a2b,
|
|
4513
4609
|
rawAmountLimit,
|
|
@@ -4864,9 +4960,9 @@ var TxBlock = class {
|
|
|
4864
4960
|
};
|
|
4865
4961
|
|
|
4866
4962
|
// src/utils/deepbook-utils.ts
|
|
4867
|
-
var
|
|
4963
|
+
var import_bn16 = __toESM(require("bn.js"));
|
|
4868
4964
|
var import_transactions3 = require("@mysten/sui/transactions");
|
|
4869
|
-
var FLOAT_SCALING = new
|
|
4965
|
+
var FLOAT_SCALING = new import_bn16.default(1e9);
|
|
4870
4966
|
var DeepbookUtils = class {
|
|
4871
4967
|
static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
|
|
4872
4968
|
if (senderAddress.length === 0) {
|
|
@@ -5012,9 +5108,9 @@ var DeepbookUtils = class {
|
|
|
5012
5108
|
static async preSwap(sdk, pool, a2b, amountIn) {
|
|
5013
5109
|
let isExceed = false;
|
|
5014
5110
|
let amountOut = ZERO;
|
|
5015
|
-
let remainAmount = new
|
|
5111
|
+
let remainAmount = new import_bn16.default(amountIn);
|
|
5016
5112
|
let feeAmount = ZERO;
|
|
5017
|
-
const initAmountIn = new
|
|
5113
|
+
const initAmountIn = new import_bn16.default(amountIn);
|
|
5018
5114
|
if (a2b) {
|
|
5019
5115
|
let bids = await this.getPoolBids(sdk, pool.poolID, pool.baseAsset, pool.quoteAsset);
|
|
5020
5116
|
if (bids === null) {
|
|
@@ -5024,16 +5120,16 @@ var DeepbookUtils = class {
|
|
|
5024
5120
|
return b.price - a.price;
|
|
5025
5121
|
});
|
|
5026
5122
|
for (let i = 0; i < bids.length; i += 1) {
|
|
5027
|
-
const curBidAmount = new
|
|
5028
|
-
const curBidPrice = new
|
|
5029
|
-
const fee = curBidAmount.mul(new
|
|
5123
|
+
const curBidAmount = new import_bn16.default(bids[i].quantity);
|
|
5124
|
+
const curBidPrice = new import_bn16.default(bids[i].price);
|
|
5125
|
+
const fee = curBidAmount.mul(new import_bn16.default(curBidPrice)).mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING).div(FLOAT_SCALING);
|
|
5030
5126
|
if (remainAmount.gt(curBidAmount)) {
|
|
5031
5127
|
remainAmount = remainAmount.sub(curBidAmount);
|
|
5032
5128
|
amountOut = amountOut.add(curBidAmount.mul(curBidPrice).div(FLOAT_SCALING).sub(fee));
|
|
5033
5129
|
feeAmount = feeAmount.add(fee);
|
|
5034
5130
|
} else {
|
|
5035
|
-
const curOut = remainAmount.mul(new
|
|
5036
|
-
const curFee = curOut.mul(new
|
|
5131
|
+
const curOut = remainAmount.mul(new import_bn16.default(bids[i].price)).div(FLOAT_SCALING);
|
|
5132
|
+
const curFee = curOut.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
5037
5133
|
amountOut = amountOut.add(curOut.sub(curFee));
|
|
5038
5134
|
remainAmount = remainAmount.sub(remainAmount);
|
|
5039
5135
|
feeAmount = feeAmount.add(curFee);
|
|
@@ -5048,15 +5144,15 @@ var DeepbookUtils = class {
|
|
|
5048
5144
|
isExceed = true;
|
|
5049
5145
|
}
|
|
5050
5146
|
for (let i = 0; i < asks.length; i += 1) {
|
|
5051
|
-
const curAskAmount = new
|
|
5052
|
-
const fee = curAskAmount.mul(new
|
|
5147
|
+
const curAskAmount = new import_bn16.default(asks[i].price).mul(new import_bn16.default(asks[i].quantity)).div(new import_bn16.default(1e9));
|
|
5148
|
+
const fee = curAskAmount.mul(new import_bn16.default(pool.takerFeeRate)).div(FLOAT_SCALING);
|
|
5053
5149
|
const curAskAmountWithFee = curAskAmount.add(fee);
|
|
5054
5150
|
if (remainAmount.gt(curAskAmount)) {
|
|
5055
|
-
amountOut = amountOut.add(new
|
|
5151
|
+
amountOut = amountOut.add(new import_bn16.default(asks[i].quantity));
|
|
5056
5152
|
remainAmount = remainAmount.sub(curAskAmountWithFee);
|
|
5057
5153
|
feeAmount = feeAmount.add(fee);
|
|
5058
5154
|
} else {
|
|
5059
|
-
const splitNums = new
|
|
5155
|
+
const splitNums = new import_bn16.default(asks[i].quantity).div(new import_bn16.default(pool.lotSize));
|
|
5060
5156
|
const splitAmount = curAskAmountWithFee.div(splitNums);
|
|
5061
5157
|
const swapSplitNum = remainAmount.div(splitAmount);
|
|
5062
5158
|
amountOut = amountOut.add(swapSplitNum.muln(pool.lotSize));
|
|
@@ -5376,7 +5472,7 @@ var PoolModule = class {
|
|
|
5376
5472
|
} catch (e) {
|
|
5377
5473
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "InvalidSwapCountUrl" /* InvalidSwapCountUrl */);
|
|
5378
5474
|
}
|
|
5379
|
-
const pools = json.data
|
|
5475
|
+
const { pools } = json.data;
|
|
5380
5476
|
if (!pools || pools.length === 0) {
|
|
5381
5477
|
throw new ClmmpoolsError(`Failed tp [arse response from ${url}].`, "PoolsNotFound" /* PoolsNotFound */);
|
|
5382
5478
|
}
|
|
@@ -5917,7 +6013,7 @@ var PoolModule = class {
|
|
|
5917
6013
|
};
|
|
5918
6014
|
|
|
5919
6015
|
// src/modules/positionModule.ts
|
|
5920
|
-
var
|
|
6016
|
+
var import_bn17 = __toESM(require("bn.js"));
|
|
5921
6017
|
var import_transactions5 = require("@mysten/sui/transactions");
|
|
5922
6018
|
var import_utils15 = require("@mysten/sui/utils");
|
|
5923
6019
|
var PositionModule = class {
|
|
@@ -6139,8 +6235,8 @@ var PositionModule = class {
|
|
|
6139
6235
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6140
6236
|
const { parsedJson } = valueData[i];
|
|
6141
6237
|
const posRrewarderResult = {
|
|
6142
|
-
feeOwedA: new
|
|
6143
|
-
feeOwedB: new
|
|
6238
|
+
feeOwedA: new import_bn17.default(parsedJson.fee_owned_a),
|
|
6239
|
+
feeOwedB: new import_bn17.default(parsedJson.fee_owned_b),
|
|
6144
6240
|
position_id: parsedJson.position_id
|
|
6145
6241
|
};
|
|
6146
6242
|
result.push(posRrewarderResult);
|
|
@@ -6516,7 +6612,7 @@ var PositionModule = class {
|
|
|
6516
6612
|
};
|
|
6517
6613
|
|
|
6518
6614
|
// src/modules/rewarderModule.ts
|
|
6519
|
-
var
|
|
6615
|
+
var import_bn18 = __toESM(require("bn.js"));
|
|
6520
6616
|
var import_transactions6 = require("@mysten/sui/transactions");
|
|
6521
6617
|
var RewarderModule = class {
|
|
6522
6618
|
_sdk;
|
|
@@ -6542,7 +6638,7 @@ var RewarderModule = class {
|
|
|
6542
6638
|
}
|
|
6543
6639
|
const emissionsEveryDay = [];
|
|
6544
6640
|
for (const rewarderInfo of rewarderInfos) {
|
|
6545
|
-
const emissionSeconds = MathUtil.fromX64(new
|
|
6641
|
+
const emissionSeconds = MathUtil.fromX64(new import_bn18.default(rewarderInfo.emissions_per_second));
|
|
6546
6642
|
emissionsEveryDay.push({
|
|
6547
6643
|
emissions: Math.floor(emissionSeconds.toNumber() * 60 * 60 * 24),
|
|
6548
6644
|
coin_address: rewarderInfo.coinAddress
|
|
@@ -6561,20 +6657,20 @@ var RewarderModule = class {
|
|
|
6561
6657
|
const currentPool = await this.sdk.Pool.getPool(poolID);
|
|
6562
6658
|
const lastTime = currentPool.rewarder_last_updated_time;
|
|
6563
6659
|
currentPool.rewarder_last_updated_time = currentTime.toString();
|
|
6564
|
-
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new
|
|
6660
|
+
if (Number(currentPool.liquidity) === 0 || currentTime.eq(new import_bn18.default(lastTime))) {
|
|
6565
6661
|
return currentPool;
|
|
6566
6662
|
}
|
|
6567
|
-
const timeDelta = currentTime.div(new
|
|
6663
|
+
const timeDelta = currentTime.div(new import_bn18.default(1e3)).sub(new import_bn18.default(lastTime)).add(new import_bn18.default(15));
|
|
6568
6664
|
const rewarderInfos = currentPool.rewarder_infos;
|
|
6569
6665
|
for (let i = 0; i < rewarderInfos.length; i += 1) {
|
|
6570
6666
|
const rewarderInfo = rewarderInfos[i];
|
|
6571
6667
|
const rewarderGrowthDelta = MathUtil.checkMulDivFloor(
|
|
6572
6668
|
timeDelta,
|
|
6573
|
-
new
|
|
6574
|
-
new
|
|
6669
|
+
new import_bn18.default(rewarderInfo.emissions_per_second),
|
|
6670
|
+
new import_bn18.default(currentPool.liquidity),
|
|
6575
6671
|
128
|
|
6576
6672
|
);
|
|
6577
|
-
this.growthGlobal[i] = new
|
|
6673
|
+
this.growthGlobal[i] = new import_bn18.default(rewarderInfo.growth_global).add(new import_bn18.default(rewarderGrowthDelta));
|
|
6578
6674
|
}
|
|
6579
6675
|
return currentPool;
|
|
6580
6676
|
}
|
|
@@ -6589,7 +6685,7 @@ var RewarderModule = class {
|
|
|
6589
6685
|
*/
|
|
6590
6686
|
async posRewardersAmount(poolID, positionHandle, positionID) {
|
|
6591
6687
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6592
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6688
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
|
|
6593
6689
|
const position = await this.sdk.Position.getPositionRewarders(positionHandle, positionID);
|
|
6594
6690
|
if (position === void 0) {
|
|
6595
6691
|
return [];
|
|
@@ -6610,7 +6706,7 @@ var RewarderModule = class {
|
|
|
6610
6706
|
*/
|
|
6611
6707
|
async poolRewardersAmount(accountAddress, poolID) {
|
|
6612
6708
|
const currentTime = Date.parse((/* @__PURE__ */ new Date()).toString());
|
|
6613
|
-
const pool = await this.updatePoolRewarder(poolID, new
|
|
6709
|
+
const pool = await this.updatePoolRewarder(poolID, new import_bn18.default(currentTime));
|
|
6614
6710
|
const positions = await this.sdk.Position.getPositionList(accountAddress, [poolID]);
|
|
6615
6711
|
const tickDatas = await this.getPoolLowerAndUpperTicks(pool.ticks_handle, positions);
|
|
6616
6712
|
const rewarderAmount = [ZERO, ZERO, ZERO];
|
|
@@ -6637,38 +6733,38 @@ var RewarderModule = class {
|
|
|
6637
6733
|
const growthInside = [];
|
|
6638
6734
|
const AmountOwed = [];
|
|
6639
6735
|
if (rewardersInside.length > 0) {
|
|
6640
|
-
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new
|
|
6641
|
-
if (growthDelta0.gt(new
|
|
6736
|
+
let growthDelta0 = MathUtil.subUnderflowU128(rewardersInside[0], new import_bn18.default(position.reward_growth_inside_0));
|
|
6737
|
+
if (growthDelta0.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6642
6738
|
growthDelta0 = ONE;
|
|
6643
6739
|
}
|
|
6644
|
-
const amountOwed_0 = MathUtil.checkMulShiftRight(new
|
|
6740
|
+
const amountOwed_0 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta0, 64, 128);
|
|
6645
6741
|
growthInside.push(rewardersInside[0]);
|
|
6646
6742
|
AmountOwed.push({
|
|
6647
|
-
amount_owed: new
|
|
6743
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_0).add(amountOwed_0),
|
|
6648
6744
|
coin_address: pool.rewarder_infos[0].coinAddress
|
|
6649
6745
|
});
|
|
6650
6746
|
}
|
|
6651
6747
|
if (rewardersInside.length > 1) {
|
|
6652
|
-
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new
|
|
6653
|
-
if (growthDelta_1.gt(new
|
|
6748
|
+
let growthDelta_1 = MathUtil.subUnderflowU128(rewardersInside[1], new import_bn18.default(position.reward_growth_inside_1));
|
|
6749
|
+
if (growthDelta_1.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6654
6750
|
growthDelta_1 = ONE;
|
|
6655
6751
|
}
|
|
6656
|
-
const amountOwed_1 = MathUtil.checkMulShiftRight(new
|
|
6752
|
+
const amountOwed_1 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_1, 64, 128);
|
|
6657
6753
|
growthInside.push(rewardersInside[1]);
|
|
6658
6754
|
AmountOwed.push({
|
|
6659
|
-
amount_owed: new
|
|
6755
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_1).add(amountOwed_1),
|
|
6660
6756
|
coin_address: pool.rewarder_infos[1].coinAddress
|
|
6661
6757
|
});
|
|
6662
6758
|
}
|
|
6663
6759
|
if (rewardersInside.length > 2) {
|
|
6664
|
-
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new
|
|
6665
|
-
if (growthDelta_2.gt(new
|
|
6760
|
+
let growthDelta_2 = MathUtil.subUnderflowU128(rewardersInside[2], new import_bn18.default(position.reward_growth_inside_2));
|
|
6761
|
+
if (growthDelta_2.gt(new import_bn18.default("3402823669209384634633745948738404"))) {
|
|
6666
6762
|
growthDelta_2 = ONE;
|
|
6667
6763
|
}
|
|
6668
|
-
const amountOwed_2 = MathUtil.checkMulShiftRight(new
|
|
6764
|
+
const amountOwed_2 = MathUtil.checkMulShiftRight(new import_bn18.default(position.liquidity), growthDelta_2, 64, 128);
|
|
6669
6765
|
growthInside.push(rewardersInside[2]);
|
|
6670
6766
|
AmountOwed.push({
|
|
6671
|
-
amount_owed: new
|
|
6767
|
+
amount_owed: new import_bn18.default(position.reward_amount_owed_2).add(amountOwed_2),
|
|
6672
6768
|
coin_address: pool.rewarder_infos[2].coinAddress
|
|
6673
6769
|
});
|
|
6674
6770
|
}
|
|
@@ -6782,8 +6878,8 @@ var RewarderModule = class {
|
|
|
6782
6878
|
for (let i = 0; i < valueData.length; i += 1) {
|
|
6783
6879
|
const { parsedJson } = valueData[i];
|
|
6784
6880
|
const posRrewarderResult = {
|
|
6785
|
-
feeOwedA: new
|
|
6786
|
-
feeOwedB: new
|
|
6881
|
+
feeOwedA: new import_bn18.default(parsedJson.fee_owned_a),
|
|
6882
|
+
feeOwedB: new import_bn18.default(parsedJson.fee_owned_b),
|
|
6787
6883
|
position_id: parsedJson.position_id
|
|
6788
6884
|
};
|
|
6789
6885
|
result.push(posRrewarderResult);
|
|
@@ -6846,7 +6942,7 @@ var RewarderModule = class {
|
|
|
6846
6942
|
};
|
|
6847
6943
|
for (let j = 0; j < params[i].rewarderInfo.length; j += 1) {
|
|
6848
6944
|
posRrewarderResult.rewarderAmountOwed.push({
|
|
6849
|
-
amount_owed: new
|
|
6945
|
+
amount_owed: new import_bn18.default(valueData[i].parsedJson.data[j]),
|
|
6850
6946
|
coin_address: params[i].rewarderInfo[j].coinAddress
|
|
6851
6947
|
});
|
|
6852
6948
|
}
|
|
@@ -7005,7 +7101,7 @@ var RewarderModule = class {
|
|
|
7005
7101
|
};
|
|
7006
7102
|
|
|
7007
7103
|
// src/modules/routerModule.ts
|
|
7008
|
-
var
|
|
7104
|
+
var import_bn19 = __toESM(require("bn.js"));
|
|
7009
7105
|
var import_cc_graph = require("@syntsugar/cc-graph");
|
|
7010
7106
|
var import_transactions7 = require("@mysten/sui/transactions");
|
|
7011
7107
|
function _pairSymbol(base, quote) {
|
|
@@ -7287,8 +7383,8 @@ var RouterModule = class {
|
|
|
7287
7383
|
if (swapWithMultiPoolParams != null) {
|
|
7288
7384
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7289
7385
|
const onePath2 = {
|
|
7290
|
-
amountIn: new
|
|
7291
|
-
amountOut: new
|
|
7386
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7387
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
7292
7388
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7293
7389
|
a2b: [preSwapResult2.aToB],
|
|
7294
7390
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7301,8 +7397,8 @@ var RouterModule = class {
|
|
|
7301
7397
|
priceSlippagePoint
|
|
7302
7398
|
};
|
|
7303
7399
|
const result2 = {
|
|
7304
|
-
amountIn: new
|
|
7305
|
-
amountOut: new
|
|
7400
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7401
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
7306
7402
|
paths: [onePath2],
|
|
7307
7403
|
a2b: preSwapResult2.aToB,
|
|
7308
7404
|
b2c: void 0,
|
|
@@ -7324,8 +7420,8 @@ var RouterModule = class {
|
|
|
7324
7420
|
if (swapWithMultiPoolParams != null) {
|
|
7325
7421
|
const preSwapResult2 = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7326
7422
|
const onePath2 = {
|
|
7327
|
-
amountIn: new
|
|
7328
|
-
amountOut: new
|
|
7423
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7424
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
7329
7425
|
poolAddress: [preSwapResult2.poolAddress],
|
|
7330
7426
|
a2b: [preSwapResult2.aToB],
|
|
7331
7427
|
rawAmountLimit: byAmountIn ? [preSwapResult2.estimatedAmountOut] : [preSwapResult2.estimatedAmountIn],
|
|
@@ -7338,8 +7434,8 @@ var RouterModule = class {
|
|
|
7338
7434
|
priceSlippagePoint
|
|
7339
7435
|
};
|
|
7340
7436
|
const result3 = {
|
|
7341
|
-
amountIn: new
|
|
7342
|
-
amountOut: new
|
|
7437
|
+
amountIn: new import_bn19.default(preSwapResult2.estimatedAmountIn),
|
|
7438
|
+
amountOut: new import_bn19.default(preSwapResult2.estimatedAmountOut),
|
|
7343
7439
|
paths: [onePath2],
|
|
7344
7440
|
a2b: preSwapResult2.aToB,
|
|
7345
7441
|
b2c: void 0,
|
|
@@ -7420,8 +7516,8 @@ var RouterModule = class {
|
|
|
7420
7516
|
if (swapWithMultiPoolParams != null) {
|
|
7421
7517
|
const preSwapResult = await this.sdk.Swap.preSwapWithMultiPool(swapWithMultiPoolParams);
|
|
7422
7518
|
const onePath = {
|
|
7423
|
-
amountIn: new
|
|
7424
|
-
amountOut: new
|
|
7519
|
+
amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
|
|
7520
|
+
amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
|
|
7425
7521
|
poolAddress: [preSwapResult.poolAddress],
|
|
7426
7522
|
a2b: [preSwapResult.aToB],
|
|
7427
7523
|
rawAmountLimit: byAmountIn ? [preSwapResult.estimatedAmountOut] : [preSwapResult.estimatedAmountIn],
|
|
@@ -7434,8 +7530,8 @@ var RouterModule = class {
|
|
|
7434
7530
|
priceSlippagePoint
|
|
7435
7531
|
};
|
|
7436
7532
|
const result = {
|
|
7437
|
-
amountIn: new
|
|
7438
|
-
amountOut: new
|
|
7533
|
+
amountIn: new import_bn19.default(preSwapResult.estimatedAmountIn),
|
|
7534
|
+
amountOut: new import_bn19.default(preSwapResult.estimatedAmountOut),
|
|
7439
7535
|
paths: [onePath],
|
|
7440
7536
|
a2b: preSwapResult.aToB,
|
|
7441
7537
|
b2c: void 0,
|
|
@@ -7519,13 +7615,13 @@ var RouterModule = class {
|
|
|
7519
7615
|
continue;
|
|
7520
7616
|
}
|
|
7521
7617
|
if (params[0].byAmountIn) {
|
|
7522
|
-
const amount = new
|
|
7618
|
+
const amount = new import_bn19.default(valueData[i].parsedJson.data.amount_out);
|
|
7523
7619
|
if (amount.gt(tempMaxAmount)) {
|
|
7524
7620
|
tempIndex = i;
|
|
7525
7621
|
tempMaxAmount = amount;
|
|
7526
7622
|
}
|
|
7527
7623
|
} else {
|
|
7528
|
-
const amount = params[i].stepNums > 1 ? new
|
|
7624
|
+
const amount = params[i].stepNums > 1 ? new import_bn19.default(valueData[i].parsedJson.data.amount_in) : new import_bn19.default(valueData[i].parsedJson.data.amount_in).add(new import_bn19.default(valueData[i].parsedJson.data.fee_amount));
|
|
7529
7625
|
if (amount.lt(tempMaxAmount)) {
|
|
7530
7626
|
tempIndex = i;
|
|
7531
7627
|
tempMaxAmount = amount;
|
|
@@ -7595,7 +7691,7 @@ var RouterModule = class {
|
|
|
7595
7691
|
};
|
|
7596
7692
|
|
|
7597
7693
|
// src/modules/swapModule.ts
|
|
7598
|
-
var
|
|
7694
|
+
var import_bn20 = __toESM(require("bn.js"));
|
|
7599
7695
|
var import_decimal11 = __toESM(require("decimal.js"));
|
|
7600
7696
|
var import_transactions8 = require("@mysten/sui/transactions");
|
|
7601
7697
|
var AMM_SWAP_MODULE = "amm_swap";
|
|
@@ -7711,13 +7807,13 @@ var SwapModule = class {
|
|
|
7711
7807
|
continue;
|
|
7712
7808
|
}
|
|
7713
7809
|
if (params.byAmountIn) {
|
|
7714
|
-
const amount = new
|
|
7810
|
+
const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
|
|
7715
7811
|
if (amount.gt(tempMaxAmount)) {
|
|
7716
7812
|
tempIndex = i;
|
|
7717
7813
|
tempMaxAmount = amount;
|
|
7718
7814
|
}
|
|
7719
7815
|
} else {
|
|
7720
|
-
const amount = new
|
|
7816
|
+
const amount = new import_bn20.default(valueData[i].parsedJson.data.amount_out);
|
|
7721
7817
|
if (amount.lt(tempMaxAmount)) {
|
|
7722
7818
|
tempIndex = i;
|
|
7723
7819
|
tempMaxAmount = amount;
|
|
@@ -7781,7 +7877,7 @@ var SwapModule = class {
|
|
|
7781
7877
|
return this.transformSwapData(params, valueData[0].parsedJson.data);
|
|
7782
7878
|
}
|
|
7783
7879
|
transformSwapData(params, data) {
|
|
7784
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7880
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
|
|
7785
7881
|
return {
|
|
7786
7882
|
poolAddress: params.pool.poolAddress,
|
|
7787
7883
|
currentSqrtPrice: params.currentSqrtPrice,
|
|
@@ -7798,7 +7894,7 @@ var SwapModule = class {
|
|
|
7798
7894
|
transformSwapWithMultiPoolData(params, jsonData) {
|
|
7799
7895
|
const { data } = jsonData;
|
|
7800
7896
|
console.log("json data. ", data);
|
|
7801
|
-
const estimatedAmountIn = data.amount_in && data.fee_amount ? new
|
|
7897
|
+
const estimatedAmountIn = data.amount_in && data.fee_amount ? new import_bn20.default(data.amount_in).add(new import_bn20.default(data.fee_amount)).toString() : "";
|
|
7802
7898
|
return {
|
|
7803
7899
|
poolAddress: params.poolAddress,
|
|
7804
7900
|
estimatedAmountIn,
|
|
@@ -9311,7 +9407,7 @@ var TokenModule = class {
|
|
|
9311
9407
|
};
|
|
9312
9408
|
|
|
9313
9409
|
// src/modules/routerModuleV2.ts
|
|
9314
|
-
var
|
|
9410
|
+
var import_bn21 = __toESM(require("bn.js"));
|
|
9315
9411
|
var import_decimal12 = __toESM(require("decimal.js"));
|
|
9316
9412
|
var import_uuid = require("uuid");
|
|
9317
9413
|
var import_axios = __toESM(require("axios"));
|
|
@@ -9355,12 +9451,12 @@ var RouterModuleV2 = class {
|
|
|
9355
9451
|
outputAmount: basePath.output_amount,
|
|
9356
9452
|
inputAmount: basePath.input_amount,
|
|
9357
9453
|
feeRate: basePath.fee_rate,
|
|
9358
|
-
currentSqrtPrice: new
|
|
9359
|
-
afterSqrtPrice: basePath.label === "Magma" ? new
|
|
9454
|
+
currentSqrtPrice: new import_bn21.default(basePath.current_sqrt_price.toString()),
|
|
9455
|
+
afterSqrtPrice: basePath.label === "Magma" ? new import_bn21.default(basePath.after_sqrt_price.toString()) : ZERO,
|
|
9360
9456
|
fromDecimal: basePath.from_decimal,
|
|
9361
9457
|
toDecimal: basePath.to_decimal,
|
|
9362
9458
|
currentPrice: this.calculatePrice(
|
|
9363
|
-
new
|
|
9459
|
+
new import_bn21.default(basePath.current_sqrt_price.toString()),
|
|
9364
9460
|
basePath.from_decimal,
|
|
9365
9461
|
basePath.to_decimal,
|
|
9366
9462
|
basePath.direction,
|
|
@@ -9443,7 +9539,7 @@ var RouterModuleV2 = class {
|
|
|
9443
9539
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9444
9540
|
from,
|
|
9445
9541
|
to,
|
|
9446
|
-
new
|
|
9542
|
+
new import_bn21.default(amount),
|
|
9447
9543
|
byAmountIn,
|
|
9448
9544
|
priceSplitPoint,
|
|
9449
9545
|
partner,
|
|
@@ -9455,7 +9551,7 @@ var RouterModuleV2 = class {
|
|
|
9455
9551
|
if (path.poolAddress.length > 1) {
|
|
9456
9552
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9457
9553
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9458
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9554
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9459
9555
|
const path0 = {
|
|
9460
9556
|
direction: path.a2b[0],
|
|
9461
9557
|
label: "Magma",
|
|
@@ -9472,7 +9568,7 @@ var RouterModuleV2 = class {
|
|
|
9472
9568
|
};
|
|
9473
9569
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9474
9570
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9475
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9571
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9476
9572
|
const path1 = {
|
|
9477
9573
|
direction: path.a2b[1],
|
|
9478
9574
|
label: "Magma",
|
|
@@ -9491,7 +9587,7 @@ var RouterModuleV2 = class {
|
|
|
9491
9587
|
} else {
|
|
9492
9588
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9493
9589
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9494
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9590
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9495
9591
|
const path0 = {
|
|
9496
9592
|
direction: path.a2b[0],
|
|
9497
9593
|
label: "Magma",
|
|
@@ -9576,7 +9672,7 @@ var RouterModuleV2 = class {
|
|
|
9576
9672
|
const priceResult = await this.sdk.Router.priceUseV1(
|
|
9577
9673
|
from,
|
|
9578
9674
|
to,
|
|
9579
|
-
new
|
|
9675
|
+
new import_bn21.default(amount),
|
|
9580
9676
|
byAmountIn,
|
|
9581
9677
|
priceSplitPoint,
|
|
9582
9678
|
partner,
|
|
@@ -9588,7 +9684,7 @@ var RouterModuleV2 = class {
|
|
|
9588
9684
|
if (path.poolAddress.length > 1) {
|
|
9589
9685
|
const fromDecimal0 = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9590
9686
|
const toDecimal0 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9591
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9687
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal0, toDecimal0) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal0, fromDecimal0);
|
|
9592
9688
|
const path0 = {
|
|
9593
9689
|
direction: path.a2b[0],
|
|
9594
9690
|
label: "Magma",
|
|
@@ -9605,7 +9701,7 @@ var RouterModuleV2 = class {
|
|
|
9605
9701
|
};
|
|
9606
9702
|
const fromDecimal1 = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9607
9703
|
const toDecimal1 = this.sdk.Router.tokenInfo(path.coinType[2]).decimals;
|
|
9608
|
-
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9704
|
+
const currentPrice1 = path.a2b[1] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), fromDecimal1, toDecimal1) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[1]), toDecimal1, fromDecimal1);
|
|
9609
9705
|
const path1 = {
|
|
9610
9706
|
direction: path.a2b[1],
|
|
9611
9707
|
label: "Magma",
|
|
@@ -9624,7 +9720,7 @@ var RouterModuleV2 = class {
|
|
|
9624
9720
|
} else {
|
|
9625
9721
|
const fromDecimal = this.sdk.Router.tokenInfo(path.coinType[0]).decimals;
|
|
9626
9722
|
const toDecimal = this.sdk.Router.tokenInfo(path.coinType[1]).decimals;
|
|
9627
|
-
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new
|
|
9723
|
+
const currentPrice = path.a2b[0] ? TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), fromDecimal, toDecimal) : TickMath.sqrtPriceX64ToPrice(new import_bn21.default(priceResult.currentSqrtPrice[0]), toDecimal, fromDecimal);
|
|
9628
9724
|
const path0 = {
|
|
9629
9725
|
direction: path.a2b[0],
|
|
9630
9726
|
label: "Magma",
|
|
@@ -10713,65 +10809,65 @@ var DlmmModule = class {
|
|
|
10713
10809
|
});
|
|
10714
10810
|
return tx;
|
|
10715
10811
|
}
|
|
10716
|
-
// Create a position by percent
|
|
10717
|
-
async mintPercent(params) {
|
|
10718
|
-
|
|
10719
|
-
|
|
10720
|
-
|
|
10721
|
-
|
|
10722
|
-
|
|
10723
|
-
|
|
10724
|
-
|
|
10725
|
-
|
|
10726
|
-
|
|
10727
|
-
|
|
10728
|
-
|
|
10729
|
-
|
|
10730
|
-
|
|
10731
|
-
|
|
10732
|
-
|
|
10733
|
-
|
|
10734
|
-
|
|
10735
|
-
|
|
10736
|
-
|
|
10737
|
-
|
|
10738
|
-
|
|
10739
|
-
|
|
10740
|
-
|
|
10741
|
-
|
|
10742
|
-
|
|
10743
|
-
|
|
10744
|
-
|
|
10745
|
-
}
|
|
10746
|
-
// Create a position by amount
|
|
10747
|
-
async createPositionByAmount(params) {
|
|
10748
|
-
|
|
10749
|
-
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
|
|
10770
|
-
|
|
10771
|
-
|
|
10772
|
-
|
|
10773
|
-
}
|
|
10774
|
-
async
|
|
10812
|
+
// // Create a position by percent
|
|
10813
|
+
// async mintPercent(params: MintPercentParams): Promise<Transaction> {
|
|
10814
|
+
// const tx = new Transaction()
|
|
10815
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10816
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10817
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10818
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10819
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10820
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10821
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10822
|
+
// const args = [
|
|
10823
|
+
// tx.object(params.pair),
|
|
10824
|
+
// tx.object(dlmmConfig.factory),
|
|
10825
|
+
// primaryCoinAInputs.targetCoin,
|
|
10826
|
+
// primaryCoinBInputs.targetCoin,
|
|
10827
|
+
// tx.pure.u64(params.amountATotal),
|
|
10828
|
+
// tx.pure.u64(params.amountBTotal),
|
|
10829
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10830
|
+
// tx.pure.vector('u64', params.binsAPercent),
|
|
10831
|
+
// tx.pure.vector('u64', params.binsBPercent),
|
|
10832
|
+
// tx.pure.address(params.to),
|
|
10833
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10834
|
+
// ]
|
|
10835
|
+
// tx.moveCall({
|
|
10836
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_percent`,
|
|
10837
|
+
// typeArguments,
|
|
10838
|
+
// arguments: args,
|
|
10839
|
+
// })
|
|
10840
|
+
// return tx
|
|
10841
|
+
// }
|
|
10842
|
+
// // Create a position by amount
|
|
10843
|
+
// async createPositionByAmount(params: MintAmountParams): Promise<Transaction> {
|
|
10844
|
+
// const tx = new Transaction()
|
|
10845
|
+
// tx.setSender(this.sdk.senderAddress)
|
|
10846
|
+
// const { dlmm_pool, integrate } = this.sdk.sdkOptions
|
|
10847
|
+
// const dlmmConfig = getPackagerConfigs(dlmm_pool)
|
|
10848
|
+
// const typeArguments = [params.coinTypeA, params.coinTypeB]
|
|
10849
|
+
// const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
|
|
10850
|
+
// const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
|
|
10851
|
+
// const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
|
|
10852
|
+
// const args = [
|
|
10853
|
+
// tx.object(params.pair),
|
|
10854
|
+
// tx.object(dlmmConfig.factory),
|
|
10855
|
+
// primaryCoinAInputs.targetCoin,
|
|
10856
|
+
// primaryCoinBInputs.targetCoin,
|
|
10857
|
+
// tx.pure.vector('u32', params.storageIds),
|
|
10858
|
+
// tx.pure.vector('u64', params.amountsA),
|
|
10859
|
+
// tx.pure.vector('u64', params.amountsB),
|
|
10860
|
+
// tx.pure.address(params.to),
|
|
10861
|
+
// tx.object(CLOCK_ADDRESS),
|
|
10862
|
+
// ]
|
|
10863
|
+
// tx.moveCall({
|
|
10864
|
+
// target: `${integrate.published_at}::${DlmmScript}::mint_amounts`,
|
|
10865
|
+
// typeArguments,
|
|
10866
|
+
// arguments: args,
|
|
10867
|
+
// })
|
|
10868
|
+
// return tx
|
|
10869
|
+
// }
|
|
10870
|
+
async addLiquidityByStrategy(params) {
|
|
10775
10871
|
if (params.rewards_token.length === 0) {
|
|
10776
10872
|
return this._raisePositionByAmounts(params);
|
|
10777
10873
|
}
|
|
@@ -10779,24 +10875,58 @@ var DlmmModule = class {
|
|
|
10779
10875
|
}
|
|
10780
10876
|
async _raisePositionByAmounts(params) {
|
|
10781
10877
|
const tx = new import_transactions12.Transaction();
|
|
10878
|
+
const slippage = new import_decimal13.default(params.slippage);
|
|
10879
|
+
const lower_slippage = new import_decimal13.default(1).sub(slippage.div(new import_decimal13.default(1e4)));
|
|
10880
|
+
const upper_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
|
|
10782
10881
|
tx.setSender(this.sdk.senderAddress);
|
|
10783
10882
|
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10784
10883
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10785
|
-
const
|
|
10884
|
+
const price = (0, import_calc_dlmm3.get_price_x128_from_real_id)(params.active_bin, params.bin_step);
|
|
10885
|
+
const min_price = new import_decimal13.default(price).mul(lower_slippage);
|
|
10886
|
+
const max_price = new import_decimal13.default(price).mul(upper_slippage);
|
|
10887
|
+
const active_min = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10888
|
+
const active_max = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10889
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB];
|
|
10786
10890
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10787
|
-
|
|
10788
|
-
|
|
10789
|
-
|
|
10790
|
-
|
|
10891
|
+
let amount_min = 0;
|
|
10892
|
+
let amount_max = 0;
|
|
10893
|
+
let primaryCoinAInputs;
|
|
10894
|
+
let primaryCoinBInputs;
|
|
10895
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10896
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10897
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10898
|
+
} else if (params.fixCoinA) {
|
|
10899
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10900
|
+
amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10901
|
+
amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10902
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10903
|
+
} else if (params.fixCoinB) {
|
|
10904
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10905
|
+
amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10906
|
+
amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10907
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10908
|
+
}
|
|
10909
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10910
|
+
} else if (params.fixCoinA) {
|
|
10911
|
+
params.amountBTotal = 0;
|
|
10912
|
+
} else if (params.fixCoinB) {
|
|
10913
|
+
params.amountATotal = 0;
|
|
10914
|
+
}
|
|
10791
10915
|
const args = [
|
|
10792
|
-
tx.object(params.
|
|
10916
|
+
tx.object(params.pair),
|
|
10793
10917
|
tx.object(dlmmConfig.factory),
|
|
10794
|
-
tx.object(params.
|
|
10918
|
+
tx.object(params.positionId),
|
|
10795
10919
|
primaryCoinAInputs.targetCoin,
|
|
10796
10920
|
primaryCoinBInputs.targetCoin,
|
|
10797
|
-
tx.pure.
|
|
10798
|
-
tx.pure.
|
|
10799
|
-
tx.pure.
|
|
10921
|
+
tx.pure.bool(params.fixCoinA),
|
|
10922
|
+
tx.pure.u64(params.amountATotal),
|
|
10923
|
+
tx.pure.bool(params.fixCoinB),
|
|
10924
|
+
tx.pure.u64(params.amountBTotal),
|
|
10925
|
+
tx.pure.u8(params.strategy),
|
|
10926
|
+
tx.pure.u32(active_min),
|
|
10927
|
+
tx.pure.u32(active_max),
|
|
10928
|
+
tx.pure.u64(amount_min),
|
|
10929
|
+
tx.pure.u64(amount_max),
|
|
10800
10930
|
tx.object(CLOCK_ADDRESS)
|
|
10801
10931
|
];
|
|
10802
10932
|
tx.moveCall({
|
|
@@ -10808,26 +10938,58 @@ var DlmmModule = class {
|
|
|
10808
10938
|
}
|
|
10809
10939
|
async _raisePositionByAmountsReward(params) {
|
|
10810
10940
|
const tx = new import_transactions12.Transaction();
|
|
10941
|
+
const slippage = new import_decimal13.default(params.slippage);
|
|
10942
|
+
const lower_slippage = new import_decimal13.default(1).sub(slippage.div(new import_decimal13.default(1e4)));
|
|
10943
|
+
const upper_slippage = new import_decimal13.default(1).plus(slippage.div(new import_decimal13.default(1e4)));
|
|
10811
10944
|
tx.setSender(this.sdk.senderAddress);
|
|
10812
|
-
const { dlmm_pool, integrate
|
|
10945
|
+
const { dlmm_pool, integrate } = this.sdk.sdkOptions;
|
|
10813
10946
|
const dlmmConfig = getPackagerConfigs(dlmm_pool);
|
|
10814
|
-
const
|
|
10815
|
-
const
|
|
10947
|
+
const price = (0, import_calc_dlmm3.get_price_x128_from_real_id)(params.active_bin, params.bin_step);
|
|
10948
|
+
const min_price = new import_decimal13.default(price).mul(lower_slippage);
|
|
10949
|
+
const max_price = new import_decimal13.default(price).mul(upper_slippage);
|
|
10950
|
+
const active_min = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(min_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10951
|
+
const active_max = (0, import_calc_dlmm3.get_storage_id_from_real_id)((0, import_calc_dlmm3.get_real_id_from_price_x128)(max_price.toDecimalPlaces(0).toString(), params.bin_step));
|
|
10952
|
+
const typeArguments = [params.coinTypeA, params.coinTypeB, ...params.rewards_token];
|
|
10816
10953
|
const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
|
|
10817
|
-
|
|
10818
|
-
|
|
10819
|
-
|
|
10820
|
-
|
|
10954
|
+
let amount_min = 0;
|
|
10955
|
+
let amount_max = 0;
|
|
10956
|
+
let primaryCoinAInputs;
|
|
10957
|
+
let primaryCoinBInputs;
|
|
10958
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10959
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10960
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10961
|
+
} else if (params.fixCoinA) {
|
|
10962
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
|
|
10963
|
+
amount_min = new import_decimal13.default(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10964
|
+
amount_max = new import_decimal13.default(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10965
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
|
|
10966
|
+
} else if (params.fixCoinB) {
|
|
10967
|
+
primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
|
|
10968
|
+
amount_min = new import_decimal13.default(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
|
|
10969
|
+
amount_max = new import_decimal13.default(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
|
|
10970
|
+
primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
|
|
10971
|
+
}
|
|
10972
|
+
if (params.fixCoinA && params.fixCoinB) {
|
|
10973
|
+
} else if (params.fixCoinA) {
|
|
10974
|
+
params.amountBTotal = 0;
|
|
10975
|
+
} else if (params.fixCoinB) {
|
|
10976
|
+
params.amountATotal = 0;
|
|
10977
|
+
}
|
|
10821
10978
|
const args = [
|
|
10822
|
-
tx.object(params.
|
|
10979
|
+
tx.object(params.pair),
|
|
10823
10980
|
tx.object(dlmmConfig.factory),
|
|
10824
|
-
tx.object(
|
|
10825
|
-
tx.object(params.position_id),
|
|
10981
|
+
tx.object(params.positionId),
|
|
10826
10982
|
primaryCoinAInputs.targetCoin,
|
|
10827
10983
|
primaryCoinBInputs.targetCoin,
|
|
10828
|
-
tx.pure.
|
|
10829
|
-
tx.pure.
|
|
10830
|
-
tx.pure.
|
|
10984
|
+
tx.pure.bool(params.fixCoinA),
|
|
10985
|
+
tx.pure.u64(params.amountATotal),
|
|
10986
|
+
tx.pure.bool(params.fixCoinB),
|
|
10987
|
+
tx.pure.u64(params.amountBTotal),
|
|
10988
|
+
tx.pure.u8(params.strategy),
|
|
10989
|
+
tx.pure.u32(active_min),
|
|
10990
|
+
tx.pure.u32(active_max),
|
|
10991
|
+
tx.pure.u64(amount_min),
|
|
10992
|
+
tx.pure.u64(amount_max),
|
|
10831
10993
|
tx.object(CLOCK_ADDRESS)
|
|
10832
10994
|
];
|
|
10833
10995
|
tx.moveCall({
|