@magmaprotocol/magma-clmm-sdk 0.5.128 → 0.6.0

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.mjs CHANGED
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
 
8
8
  // src/modules/poolModule.ts
9
9
  import { normalizeSuiAddress } from "@mysten/sui/utils";
10
- import { Transaction as Transaction4 } from "@mysten/sui/transactions";
10
+ import { Transaction as Transaction5 } from "@mysten/sui/transactions";
11
11
 
12
12
  // src/utils/cachedContent.ts
13
13
  var cacheTime5min = 5 * 60 * 1e3;
@@ -71,6 +71,9 @@ var ClmmpoolsError = class extends Error {
71
71
  return e instanceof ClmmpoolsError && e.errorCode === code;
72
72
  }
73
73
  };
74
+ var handleMessageError = (code, message, details) => {
75
+ throw new ClmmpoolsError(message, code);
76
+ };
74
77
 
75
78
  // src/math/utils.ts
76
79
  var ZERO = new BN(0);
@@ -343,6 +346,9 @@ var SwapDirection = /* @__PURE__ */ ((SwapDirection2) => {
343
346
  return SwapDirection2;
344
347
  })(SwapDirection || {});
345
348
 
349
+ // src/types/zap.ts
350
+ var defaultSwapSlippage = 5e-3;
351
+
346
352
  // src/math/apr.ts
347
353
  import BN5 from "bn.js";
348
354
  import Decimal2 from "decimal.js";
@@ -1109,234 +1115,8 @@ var ClmmPoolUtil = class {
1109
1115
  }
1110
1116
  };
1111
1117
 
1112
- // src/utils/contracts.ts
1113
- import { normalizeSuiObjectId } from "@mysten/sui/utils";
1114
-
1115
- // src/utils/hex.ts
1116
- var HEX_REGEXP = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
1117
- function addHexPrefix(hex) {
1118
- return !hex.startsWith("0x") ? `0x${hex}` : hex;
1119
- }
1120
- function removeHexPrefix(hex) {
1121
- return hex.startsWith("0x") ? `${hex.slice(2)}` : hex;
1122
- }
1123
- function shortString(str, start = 4, end = 4) {
1124
- const slen = Math.max(start, 1);
1125
- const elen = Math.max(end, 1);
1126
- return `${str.slice(0, slen + 2)} ... ${str.slice(-elen)}`;
1127
- }
1128
- function shortAddress(address, start = 4, end = 4) {
1129
- return shortString(addHexPrefix(address), start, end);
1130
- }
1131
- function checkAddress(address, options = { leadingZero: true }) {
1132
- if (typeof address !== "string") {
1133
- return false;
1134
- }
1135
- let str = address;
1136
- if (options.leadingZero) {
1137
- if (!address.startsWith("0x")) {
1138
- return false;
1139
- }
1140
- str = str.substring(2);
1141
- }
1142
- return HEX_REGEXP.test(str);
1143
- }
1144
- function toBuffer(v) {
1145
- if (!Buffer.isBuffer(v)) {
1146
- if (Array.isArray(v)) {
1147
- v = Buffer.from(v);
1148
- } else if (typeof v === "string") {
1149
- if (exports.isHexString(v)) {
1150
- v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), "hex");
1151
- } else {
1152
- v = Buffer.from(v);
1153
- }
1154
- } else if (typeof v === "number") {
1155
- v = exports.intToBuffer(v);
1156
- } else if (v === null || v === void 0) {
1157
- v = Buffer.allocUnsafe(0);
1158
- } else if (v.toArray) {
1159
- v = Buffer.from(v.toArray());
1160
- } else {
1161
- throw new ClmmpoolsError(`Invalid type`, "InvalidType" /* InvalidType */);
1162
- }
1163
- }
1164
- return v;
1165
- }
1166
- function bufferToHex(buffer) {
1167
- return addHexPrefix(toBuffer(buffer).toString("hex"));
1168
- }
1169
- function hexToNumber(binaryData) {
1170
- const buffer = new ArrayBuffer(4);
1171
- const view = new DataView(buffer);
1172
- for (let i = 0; i < binaryData.length; i++) {
1173
- view.setUint8(i, binaryData.charCodeAt(i));
1174
- }
1175
- const number = view.getUint32(0, true);
1176
- return number;
1177
- }
1178
- function utf8to16(str) {
1179
- let out;
1180
- let i;
1181
- let c;
1182
- let char2;
1183
- let char3;
1184
- out = "";
1185
- const len = str.length;
1186
- i = 0;
1187
- while (i < len) {
1188
- c = str.charCodeAt(i++);
1189
- switch (c >> 4) {
1190
- case 0:
1191
- case 1:
1192
- case 2:
1193
- case 3:
1194
- case 4:
1195
- case 5:
1196
- case 6:
1197
- case 7:
1198
- out += str.charAt(i - 1);
1199
- break;
1200
- case 12:
1201
- case 13:
1202
- char2 = str.charCodeAt(i++);
1203
- out += String.fromCharCode((c & 31) << 6 | char2 & 63);
1204
- break;
1205
- case 14:
1206
- char2 = str.charCodeAt(i++);
1207
- char3 = str.charCodeAt(i++);
1208
- out += String.fromCharCode((c & 15) << 12 | (char2 & 63) << 6 | (char3 & 63) << 0);
1209
- break;
1210
- }
1211
- }
1212
- return out;
1213
- }
1214
- function hexToString(str) {
1215
- let val = "";
1216
- const newStr = removeHexPrefix(str);
1217
- const len = newStr.length / 2;
1218
- for (let i = 0; i < len; i++) {
1219
- val += String.fromCharCode(parseInt(newStr.substr(i * 2, 2), 16));
1220
- }
1221
- return utf8to16(val);
1222
- }
1223
-
1224
- // src/utils/contracts.ts
1225
- var EQUAL = 0;
1226
- var LESS_THAN = 1;
1227
- var GREATER_THAN = 2;
1228
- function cmp(a, b) {
1229
- if (a === b) {
1230
- return EQUAL;
1231
- }
1232
- if (a < b) {
1233
- return LESS_THAN;
1234
- }
1235
- return GREATER_THAN;
1236
- }
1237
- function compare(symbolX, symbolY) {
1238
- let i = 0;
1239
- const len = symbolX.length <= symbolY.length ? symbolX.length : symbolY.length;
1240
- const lenCmp = cmp(symbolX.length, symbolY.length);
1241
- while (i < len) {
1242
- const elemCmp = cmp(symbolX.charCodeAt(i), symbolY.charCodeAt(i));
1243
- i += 1;
1244
- if (elemCmp !== 0) {
1245
- return elemCmp;
1246
- }
1247
- }
1248
- return lenCmp;
1249
- }
1250
- function isSortedSymbols(symbolX, symbolY) {
1251
- return compare(symbolX, symbolY) === LESS_THAN;
1252
- }
1253
- function composeType(address, ...args) {
1254
- const generics = Array.isArray(args[args.length - 1]) ? args.pop() : [];
1255
- const chains = [address, ...args].filter(Boolean);
1256
- let result = chains.join("::");
1257
- if (generics && generics.length) {
1258
- result += `<${generics.join(", ")}>`;
1259
- }
1260
- return result;
1261
- }
1262
- function extractAddressFromType(type) {
1263
- return type.split("::")[0];
1264
- }
1265
- function extractStructTagFromType(type) {
1266
- try {
1267
- let _type = type.replace(/\s/g, "");
1268
- const genericsString = _type.match(/(<.+>)$/);
1269
- const generics = genericsString?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);
1270
- if (generics) {
1271
- _type = _type.slice(0, _type.indexOf("<"));
1272
- const tag = extractStructTagFromType(_type);
1273
- const structTag2 = {
1274
- ...tag,
1275
- type_arguments: generics.map((item) => extractStructTagFromType(item).source_address)
1276
- };
1277
- structTag2.type_arguments = structTag2.type_arguments.map((item) => {
1278
- return CoinAssist.isSuiCoin(item) ? item : extractStructTagFromType(item).source_address;
1279
- });
1280
- structTag2.source_address = composeType(structTag2.full_address, structTag2.type_arguments);
1281
- return structTag2;
1282
- }
1283
- const parts = _type.split("::");
1284
- const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
1285
- const structTag = {
1286
- full_address: _type,
1287
- address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
1288
- module: parts[1],
1289
- name: parts[2],
1290
- type_arguments: [],
1291
- source_address: ""
1292
- };
1293
- structTag.full_address = `${structTag.address}::${structTag.module}::${structTag.name}`;
1294
- structTag.source_address = composeType(structTag.full_address, structTag.type_arguments);
1295
- return structTag;
1296
- } catch (error) {
1297
- return {
1298
- full_address: type,
1299
- address: "",
1300
- module: "",
1301
- name: "",
1302
- type_arguments: [],
1303
- source_address: type
1304
- };
1305
- }
1306
- }
1307
- function normalizeCoinType(coinType) {
1308
- return extractStructTagFromType(coinType).source_address;
1309
- }
1310
- function fixSuiObjectId(value) {
1311
- if (value.toLowerCase().startsWith("0x")) {
1312
- return normalizeSuiObjectId(value);
1313
- }
1314
- return value;
1315
- }
1316
- var fixCoinType = (coinType, removePrefix = true) => {
1317
- const arr = coinType.split("::");
1318
- const address = arr.shift();
1319
- let normalizeAddress = normalizeSuiObjectId(address);
1320
- if (removePrefix) {
1321
- normalizeAddress = removeHexPrefix(normalizeAddress);
1322
- }
1323
- return `${normalizeAddress}::${arr.join("::")}`;
1324
- };
1325
- function patchFixSuiObjectId(data) {
1326
- for (const key in data) {
1327
- const type = typeof data[key];
1328
- if (type === "object") {
1329
- patchFixSuiObjectId(data[key]);
1330
- } else if (type === "string") {
1331
- const value = data[key];
1332
- if (value && !value.includes("::")) {
1333
- data[key] = fixSuiObjectId(value);
1334
- }
1335
- }
1336
- }
1337
- }
1338
-
1339
1118
  // src/math/CoinAssist.ts
1119
+ import { coinWithBalance } from "@mysten/sui/transactions";
1340
1120
  var COIN_TYPE = "0x2::coin::Coin";
1341
1121
  var COIN_TYPE_ARG_REGEX = /^0x2::coin::Coin<(.+)>$/;
1342
1122
  var DEFAULT_GAS_BUDGET_FOR_SPLIT = 1e3;
@@ -1541,6 +1321,92 @@ var CoinAssist = class {
1541
1321
  static calculateTotalBalance(coins) {
1542
1322
  return coins.reduce((partialSum, c) => partialSum + c.balance, BigInt(0));
1543
1323
  }
1324
+ static getCoinAmountObjId(coin_input, amount) {
1325
+ const coin_obj = coin_input.amount_coin_array.find((coin) => {
1326
+ if (!coin.used && d(coin.amount).eq(amount)) {
1327
+ coin.used = true;
1328
+ return true;
1329
+ }
1330
+ return false;
1331
+ });
1332
+ if (!coin_obj) {
1333
+ return handleMessageError("CoinNotFound" /* CoinNotFound */, `Coin not found for ${amount} ${coin_input.coin_type}`);
1334
+ }
1335
+ return coin_obj.coin_object_id;
1336
+ }
1337
+ static buildCoinWithBalance(amount, coin_type, tx) {
1338
+ if (amount === BigInt(0)) {
1339
+ if (CoinAssist.isSuiCoin(coin_type)) {
1340
+ return tx.add(coinWithBalance({ balance: amount, useGasCoin: false }));
1341
+ }
1342
+ }
1343
+ return tx.add(coinWithBalance({ balance: amount, type: coin_type }));
1344
+ }
1345
+ static buildMultiCoinInput(tx, all_coin_assets, coin_type, amount_arr) {
1346
+ const coin_assets = CoinAssist.getCoinAssets(coin_type, all_coin_assets);
1347
+ if (CoinAssist.isSuiCoin(coin_type)) {
1348
+ const amount_coins2 = tx.splitCoins(
1349
+ tx.gas,
1350
+ amount_arr.map((amount) => tx.pure.u64(amount))
1351
+ );
1352
+ const amount_coin_array2 = amount_arr.map((amount, index) => {
1353
+ return {
1354
+ coin_object_id: amount_coins2[index],
1355
+ amount: amount.toString(),
1356
+ used: false
1357
+ };
1358
+ });
1359
+ return {
1360
+ amount_coin_array: amount_coin_array2,
1361
+ coin_type,
1362
+ remain_coins: coin_assets
1363
+ };
1364
+ }
1365
+ const total_amount = amount_arr.reduce((acc, curr) => acc + curr, BigInt(0));
1366
+ const selected_coins_result = CoinAssist.selectCoinObjectIdGreaterThanOrEqual(coin_assets, total_amount);
1367
+ if (selected_coins_result.objectArray.length === 0) {
1368
+ return handleMessageError(
1369
+ "InsufficientBalance" /* InsufficientBalance */,
1370
+ `No enough coins for ${coin_type} expect ${total_amount} actual ${CoinAssist.calculateTotalBalance(coin_assets)}`
1371
+ );
1372
+ }
1373
+ const [target_coin, ...other_coins] = selected_coins_result.objectArray;
1374
+ if (other_coins.length > 0) {
1375
+ tx.mergeCoins(target_coin, [...other_coins]);
1376
+ }
1377
+ const amount_coins = tx.splitCoins(
1378
+ target_coin,
1379
+ amount_arr.map((amount) => tx.pure.u64(amount))
1380
+ );
1381
+ const amount_coin_array = amount_arr.map((amount, index) => {
1382
+ return {
1383
+ coin_object_id: amount_coins[index],
1384
+ amount: amount.toString(),
1385
+ used: false
1386
+ };
1387
+ });
1388
+ return {
1389
+ amount_coin_array,
1390
+ remain_coins: selected_coins_result.remainCoins,
1391
+ coin_type
1392
+ };
1393
+ }
1394
+ static fromBalance(balance, coin_type, tx) {
1395
+ const coin = tx.moveCall({
1396
+ target: `0x2::coin::from_balance`,
1397
+ typeArguments: [coin_type],
1398
+ arguments: [balance]
1399
+ });
1400
+ return coin;
1401
+ }
1402
+ static intoBalance(coin_obj, coin_type, tx) {
1403
+ const coin = tx.moveCall({
1404
+ target: `0x2::coin::into_balance`,
1405
+ typeArguments: [coin_type],
1406
+ arguments: [typeof coin_obj === "string" ? tx.object(coin_obj) : coin_obj]
1407
+ });
1408
+ return coin;
1409
+ }
1544
1410
  };
1545
1411
 
1546
1412
  // src/math/collect-fees.ts
@@ -2154,6 +2020,97 @@ function d(value) {
2154
2020
  function decimalsMultiplier(decimals) {
2155
2021
  return d(10).pow(d(decimals).abs());
2156
2022
  }
2023
+ function toDecimalsAmount(amount, decimals, rounding = Decimal4.ROUND_DOWN) {
2024
+ const mul = decimalsMultiplier(d(decimals));
2025
+ return d(amount).mul(mul).toFixed(0, rounding).toString();
2026
+ }
2027
+ function asUintN(int, bits = 32) {
2028
+ return BigInt.asUintN(bits, BigInt(int)).toString();
2029
+ }
2030
+ function asIntN(int, bits = 32) {
2031
+ return Number(BigInt.asIntN(bits, BigInt(int)));
2032
+ }
2033
+ function fromDecimalsAmount(amount, decimals) {
2034
+ const mul = decimalsMultiplier(d(decimals));
2035
+ return d(amount).div(mul).toString();
2036
+ }
2037
+ var fixDEAdd = (num, precision, auto_fix = true) => {
2038
+ if (`${num}` === "0") {
2039
+ if (!parseFloat(precision) || !auto_fix)
2040
+ return "0";
2041
+ return "0.".padEnd(precision + 2, "0");
2042
+ }
2043
+ if (!num)
2044
+ return "--";
2045
+ const number = parseFloat(num);
2046
+ const strN = num.toString();
2047
+ const flag = number < 0;
2048
+ let result = strN;
2049
+ if (strN.toLowerCase().includes("e")) {
2050
+ const n = strN.match(/(\d+?)(?:\.(\d*))?e([+-])(\d+)/);
2051
+ if (!n) {
2052
+ return num.toString();
2053
+ }
2054
+ const nl = n[1] || "0";
2055
+ const nr = n[2] || "";
2056
+ const type = n[3];
2057
+ const floatN = parseInt(n[4], 10);
2058
+ let params = "";
2059
+ let pr = nr.substring(floatN) || "";
2060
+ if (pr)
2061
+ pr = `.${pr}`;
2062
+ if (type !== "-") {
2063
+ for (let i = 0; i < floatN; i++) {
2064
+ params += nr[i] || "0";
2065
+ }
2066
+ result = nl + params + pr;
2067
+ } else {
2068
+ let strL = "0";
2069
+ for (let i = 0; i < floatN; i++) {
2070
+ params = (nl[nl.length - i - 1] || "0") + params;
2071
+ }
2072
+ if (nl.length > floatN) {
2073
+ strL = nl.substring(0, nl.length - floatN);
2074
+ }
2075
+ result = `${strL}.${params}${nr}`;
2076
+ }
2077
+ }
2078
+ if (precision && auto_fix) {
2079
+ let pal = `${result.split(".")[0]}.`;
2080
+ const par = result.split(".")[1] || "";
2081
+ for (let i = 0; i < precision; i++) {
2082
+ pal += par[i] || "0";
2083
+ }
2084
+ result = pal;
2085
+ }
2086
+ return `${flag ? "-" : ""}${result}`;
2087
+ };
2088
+ function convertScientificToDecimal(num_str, precision = 9) {
2089
+ if (num_str === void 0) {
2090
+ return "";
2091
+ }
2092
+ const new_num = num_str?.toLowerCase();
2093
+ if (new_num.includes("e")) {
2094
+ if (new_num.includes("+")) {
2095
+ return fixDEAdd(new_num, precision);
2096
+ }
2097
+ const [base, exponent_str] = new_num.split("e");
2098
+ let integer_part = base;
2099
+ const exponent = Math.abs(parseInt(exponent_str, 10));
2100
+ let zeros = "";
2101
+ let integer_length = integer_part.length;
2102
+ if (base.includes(".")) {
2103
+ const [int_part, frac_part] = base.split(".");
2104
+ integer_part = int_part + frac_part;
2105
+ integer_length = int_part.length;
2106
+ }
2107
+ for (let i = 0; i < exponent - integer_length; i++) {
2108
+ zeros += "0";
2109
+ }
2110
+ return `0.${zeros}${integer_part}`.slice(0, precision + 2);
2111
+ }
2112
+ return num_str;
2113
+ }
2157
2114
 
2158
2115
  // src/math/LiquidityHelper.ts
2159
2116
  function withLiquiditySlippage(value, slippage, mode) {
@@ -2487,73 +2444,300 @@ function computeSplitSwap(a2b, byAmountIn, amounts, poolData, swapTicks) {
2487
2444
  currentSqrtPrice = tempStepResult.nextSqrtPrice;
2488
2445
  }
2489
2446
  }
2490
- if (byAmountIn) {
2491
- amounts.forEach((a, i) => {
2492
- splitSwapResult.isExceed.push(splitSwapResult.amountInArray[i].lt(a));
2493
- });
2494
- } else {
2495
- amounts.forEach((a, i) => {
2496
- splitSwapResult.isExceed.push(splitSwapResult.amountOutArray[i].lt(a));
2497
- });
2447
+ if (byAmountIn) {
2448
+ amounts.forEach((a, i) => {
2449
+ splitSwapResult.isExceed.push(splitSwapResult.amountInArray[i].lt(a));
2450
+ });
2451
+ } else {
2452
+ amounts.forEach((a, i) => {
2453
+ splitSwapResult.isExceed.push(splitSwapResult.amountOutArray[i].lt(a));
2454
+ });
2455
+ }
2456
+ return splitSwapResult;
2457
+ }
2458
+ var SplitSwap = class {
2459
+ minSplitUnit;
2460
+ amountArray;
2461
+ byAmountIn;
2462
+ a2b;
2463
+ clmmpool;
2464
+ ticks;
2465
+ splitSwapResult;
2466
+ constructor(amount, unit, clmmpool, a2b, byAmountIn, tickData) {
2467
+ this.minSplitUnit = unit;
2468
+ this.a2b = a2b;
2469
+ this.byAmountIn = byAmountIn;
2470
+ this.clmmpool = clmmpool;
2471
+ this.ticks = tickData;
2472
+ this.amountArray = [];
2473
+ this.createSplitSwapParams = this.createSplitSwapParams.bind(this);
2474
+ this.createSplitSwapParams(amount, unit);
2475
+ this.splitSwapResult = {
2476
+ amountInArray: [],
2477
+ amountOutArray: [],
2478
+ feeAmountArray: [],
2479
+ nextSqrtPriceArray: [],
2480
+ isExceed: []
2481
+ };
2482
+ this.computeSwap = this.computeSwap.bind(this);
2483
+ }
2484
+ createSplitSwapParams(amount, unit) {
2485
+ const amountArray = createSplitAmountArray(amount, unit);
2486
+ this.amountArray = amountArray;
2487
+ }
2488
+ computeSwap() {
2489
+ const pool = transClmmpoolDataWithoutTicks(this.clmmpool);
2490
+ this.splitSwapResult = computeSplitSwap(this.a2b, this.byAmountIn, this.amountArray, pool, this.ticks);
2491
+ return this.splitSwapResult;
2492
+ }
2493
+ };
2494
+
2495
+ // src/math/bin.ts
2496
+ import Decimal6 from "decimal.js";
2497
+ import { get_price_x128_from_real_id as get_price_x128_from_real_id2, get_real_id_from_price_x128 } from "@magmaprotocol/calc_almm";
2498
+ var BinMath = class {
2499
+ static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
2500
+ const twoDec = new Decimal6(2);
2501
+ const price = new Decimal6(get_price_x128_from_real_id2(binId, binStep));
2502
+ return price.div(twoDec.pow(128)).mul(Decimal6.pow(10, decimalsA - decimalsB));
2503
+ }
2504
+ static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
2505
+ const twoDec = new Decimal6(2);
2506
+ const tenDec = new Decimal6(10);
2507
+ const realid = get_real_id_from_price_x128(
2508
+ new Decimal6(price).mul(tenDec.pow(decimalsB - decimalsA)).mul(twoDec.pow(128)).toDecimalPlaces(0).toString(),
2509
+ binStep
2510
+ );
2511
+ return realid;
2512
+ }
2513
+ };
2514
+
2515
+ // src/utils/contracts.ts
2516
+ import { normalizeSuiObjectId } from "@mysten/sui/utils";
2517
+
2518
+ // src/utils/hex.ts
2519
+ var HEX_REGEXP = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/;
2520
+ function addHexPrefix(hex) {
2521
+ return !hex.startsWith("0x") ? `0x${hex}` : hex;
2522
+ }
2523
+ function removeHexPrefix(hex) {
2524
+ return hex.startsWith("0x") ? `${hex.slice(2)}` : hex;
2525
+ }
2526
+ function shortString(str, start = 4, end = 4) {
2527
+ const slen = Math.max(start, 1);
2528
+ const elen = Math.max(end, 1);
2529
+ return `${str.slice(0, slen + 2)} ... ${str.slice(-elen)}`;
2530
+ }
2531
+ function shortAddress(address, start = 4, end = 4) {
2532
+ return shortString(addHexPrefix(address), start, end);
2533
+ }
2534
+ function checkAddress(address, options = { leadingZero: true }) {
2535
+ if (typeof address !== "string") {
2536
+ return false;
2537
+ }
2538
+ let str = address;
2539
+ if (options.leadingZero) {
2540
+ if (!address.startsWith("0x")) {
2541
+ return false;
2542
+ }
2543
+ str = str.substring(2);
2544
+ }
2545
+ return HEX_REGEXP.test(str);
2546
+ }
2547
+ function toBuffer(v) {
2548
+ if (!Buffer.isBuffer(v)) {
2549
+ if (Array.isArray(v)) {
2550
+ v = Buffer.from(v);
2551
+ } else if (typeof v === "string") {
2552
+ if (exports.isHexString(v)) {
2553
+ v = Buffer.from(exports.padToEven(exports.stripHexPrefix(v)), "hex");
2554
+ } else {
2555
+ v = Buffer.from(v);
2556
+ }
2557
+ } else if (typeof v === "number") {
2558
+ v = exports.intToBuffer(v);
2559
+ } else if (v === null || v === void 0) {
2560
+ v = Buffer.allocUnsafe(0);
2561
+ } else if (v.toArray) {
2562
+ v = Buffer.from(v.toArray());
2563
+ } else {
2564
+ throw new ClmmpoolsError(`Invalid type`, "InvalidType" /* InvalidType */);
2565
+ }
2566
+ }
2567
+ return v;
2568
+ }
2569
+ function bufferToHex(buffer) {
2570
+ return addHexPrefix(toBuffer(buffer).toString("hex"));
2571
+ }
2572
+ function hexToNumber(binaryData) {
2573
+ const buffer = new ArrayBuffer(4);
2574
+ const view = new DataView(buffer);
2575
+ for (let i = 0; i < binaryData.length; i++) {
2576
+ view.setUint8(i, binaryData.charCodeAt(i));
2577
+ }
2578
+ const number = view.getUint32(0, true);
2579
+ return number;
2580
+ }
2581
+ function utf8to16(str) {
2582
+ let out;
2583
+ let i;
2584
+ let c;
2585
+ let char2;
2586
+ let char3;
2587
+ out = "";
2588
+ const len = str.length;
2589
+ i = 0;
2590
+ while (i < len) {
2591
+ c = str.charCodeAt(i++);
2592
+ switch (c >> 4) {
2593
+ case 0:
2594
+ case 1:
2595
+ case 2:
2596
+ case 3:
2597
+ case 4:
2598
+ case 5:
2599
+ case 6:
2600
+ case 7:
2601
+ out += str.charAt(i - 1);
2602
+ break;
2603
+ case 12:
2604
+ case 13:
2605
+ char2 = str.charCodeAt(i++);
2606
+ out += String.fromCharCode((c & 31) << 6 | char2 & 63);
2607
+ break;
2608
+ case 14:
2609
+ char2 = str.charCodeAt(i++);
2610
+ char3 = str.charCodeAt(i++);
2611
+ out += String.fromCharCode((c & 15) << 12 | (char2 & 63) << 6 | (char3 & 63) << 0);
2612
+ break;
2613
+ }
2614
+ }
2615
+ return out;
2616
+ }
2617
+ function hexToString(str) {
2618
+ let val = "";
2619
+ const newStr = removeHexPrefix(str);
2620
+ const len = newStr.length / 2;
2621
+ for (let i = 0; i < len; i++) {
2622
+ val += String.fromCharCode(parseInt(newStr.substr(i * 2, 2), 16));
2623
+ }
2624
+ return utf8to16(val);
2625
+ }
2626
+
2627
+ // src/utils/contracts.ts
2628
+ var EQUAL = 0;
2629
+ var LESS_THAN = 1;
2630
+ var GREATER_THAN = 2;
2631
+ function cmp(a, b) {
2632
+ if (a === b) {
2633
+ return EQUAL;
2634
+ }
2635
+ if (a < b) {
2636
+ return LESS_THAN;
2637
+ }
2638
+ return GREATER_THAN;
2639
+ }
2640
+ function compare(symbolX, symbolY) {
2641
+ let i = 0;
2642
+ const len = symbolX.length <= symbolY.length ? symbolX.length : symbolY.length;
2643
+ const lenCmp = cmp(symbolX.length, symbolY.length);
2644
+ while (i < len) {
2645
+ const elemCmp = cmp(symbolX.charCodeAt(i), symbolY.charCodeAt(i));
2646
+ i += 1;
2647
+ if (elemCmp !== 0) {
2648
+ return elemCmp;
2649
+ }
2650
+ }
2651
+ return lenCmp;
2652
+ }
2653
+ function isSortedSymbols(symbolX, symbolY) {
2654
+ return compare(symbolX, symbolY) === LESS_THAN;
2655
+ }
2656
+ function composeType(address, ...args) {
2657
+ const generics = Array.isArray(args[args.length - 1]) ? args.pop() : [];
2658
+ const chains = [address, ...args].filter(Boolean);
2659
+ let result = chains.join("::");
2660
+ if (generics && generics.length) {
2661
+ result += `<${generics.join(", ")}>`;
2498
2662
  }
2499
- return splitSwapResult;
2663
+ return result;
2500
2664
  }
2501
- var SplitSwap = class {
2502
- minSplitUnit;
2503
- amountArray;
2504
- byAmountIn;
2505
- a2b;
2506
- clmmpool;
2507
- ticks;
2508
- splitSwapResult;
2509
- constructor(amount, unit, clmmpool, a2b, byAmountIn, tickData) {
2510
- this.minSplitUnit = unit;
2511
- this.a2b = a2b;
2512
- this.byAmountIn = byAmountIn;
2513
- this.clmmpool = clmmpool;
2514
- this.ticks = tickData;
2515
- this.amountArray = [];
2516
- this.createSplitSwapParams = this.createSplitSwapParams.bind(this);
2517
- this.createSplitSwapParams(amount, unit);
2518
- this.splitSwapResult = {
2519
- amountInArray: [],
2520
- amountOutArray: [],
2521
- feeAmountArray: [],
2522
- nextSqrtPriceArray: [],
2523
- isExceed: []
2665
+ function extractAddressFromType(type) {
2666
+ return type.split("::")[0];
2667
+ }
2668
+ function extractStructTagFromType(type) {
2669
+ try {
2670
+ let _type = type.replace(/\s/g, "");
2671
+ const genericsString = _type.match(/(<.+>)$/);
2672
+ const generics = genericsString?.[0]?.match(/(\w+::\w+::\w+)(?:<.*?>(?!>))?/g);
2673
+ if (generics) {
2674
+ _type = _type.slice(0, _type.indexOf("<"));
2675
+ const tag = extractStructTagFromType(_type);
2676
+ const structTag2 = {
2677
+ ...tag,
2678
+ type_arguments: generics.map((item) => extractStructTagFromType(item).source_address)
2679
+ };
2680
+ structTag2.type_arguments = structTag2.type_arguments.map((item) => {
2681
+ return CoinAssist.isSuiCoin(item) ? item : extractStructTagFromType(item).source_address;
2682
+ });
2683
+ structTag2.source_address = composeType(structTag2.full_address, structTag2.type_arguments);
2684
+ return structTag2;
2685
+ }
2686
+ const parts = _type.split("::");
2687
+ const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
2688
+ const structTag = {
2689
+ full_address: _type,
2690
+ address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
2691
+ module: parts[1],
2692
+ name: parts[2],
2693
+ type_arguments: [],
2694
+ source_address: ""
2695
+ };
2696
+ structTag.full_address = `${structTag.address}::${structTag.module}::${structTag.name}`;
2697
+ structTag.source_address = composeType(structTag.full_address, structTag.type_arguments);
2698
+ return structTag;
2699
+ } catch (error) {
2700
+ return {
2701
+ full_address: type,
2702
+ address: "",
2703
+ module: "",
2704
+ name: "",
2705
+ type_arguments: [],
2706
+ source_address: type
2524
2707
  };
2525
- this.computeSwap = this.computeSwap.bind(this);
2526
2708
  }
2527
- createSplitSwapParams(amount, unit) {
2528
- const amountArray = createSplitAmountArray(amount, unit);
2529
- this.amountArray = amountArray;
2709
+ }
2710
+ function normalizeCoinType(coinType) {
2711
+ return extractStructTagFromType(coinType).source_address;
2712
+ }
2713
+ function fixSuiObjectId(value) {
2714
+ if (value.toLowerCase().startsWith("0x")) {
2715
+ return normalizeSuiObjectId(value);
2530
2716
  }
2531
- computeSwap() {
2532
- const pool = transClmmpoolDataWithoutTicks(this.clmmpool);
2533
- this.splitSwapResult = computeSplitSwap(this.a2b, this.byAmountIn, this.amountArray, pool, this.ticks);
2534
- return this.splitSwapResult;
2717
+ return value;
2718
+ }
2719
+ var fixCoinType = (coinType, removePrefix = true) => {
2720
+ const arr = coinType.split("::");
2721
+ const address = arr.shift();
2722
+ let normalizeAddress = normalizeSuiObjectId(address);
2723
+ if (removePrefix) {
2724
+ normalizeAddress = removeHexPrefix(normalizeAddress);
2535
2725
  }
2726
+ return `${normalizeAddress}::${arr.join("::")}`;
2536
2727
  };
2537
-
2538
- // src/math/bin.ts
2539
- import Decimal6 from "decimal.js";
2540
- import { get_price_x128_from_real_id as get_price_x128_from_real_id2, get_real_id_from_price_x128 } from "@magmaprotocol/calc_almm";
2541
- var BinMath = class {
2542
- static getPriceOfBinByBinId(binId, binStep, decimalsA, decimalsB) {
2543
- const twoDec = new Decimal6(2);
2544
- const price = new Decimal6(get_price_x128_from_real_id2(binId, binStep));
2545
- return price.div(twoDec.pow(128)).mul(Decimal6.pow(10, decimalsA - decimalsB));
2546
- }
2547
- static getBinIdFromPrice(price, binStep, decimalsA, decimalsB) {
2548
- const twoDec = new Decimal6(2);
2549
- const tenDec = new Decimal6(10);
2550
- const realid = get_real_id_from_price_x128(
2551
- new Decimal6(price).mul(tenDec.pow(decimalsB - decimalsA)).mul(twoDec.pow(128)).toDecimalPlaces(0).toString(),
2552
- binStep
2553
- );
2554
- return realid;
2728
+ function patchFixSuiObjectId(data) {
2729
+ for (const key in data) {
2730
+ const type = typeof data[key];
2731
+ if (type === "object") {
2732
+ patchFixSuiObjectId(data[key]);
2733
+ } else if (type === "string") {
2734
+ const value = data[key];
2735
+ if (value && !value.includes("::")) {
2736
+ data[key] = fixSuiObjectId(value);
2737
+ }
2738
+ }
2555
2739
  }
2556
- };
2740
+ }
2557
2741
 
2558
2742
  // src/utils/objects.ts
2559
2743
  function getSuiObjectData(resp) {
@@ -2663,20 +2847,6 @@ function hasPublicTransfer(data) {
2663
2847
  }
2664
2848
 
2665
2849
  // src/utils/common.ts
2666
- function toDecimalsAmount(amount, decimals) {
2667
- const mul = decimalsMultiplier(d(decimals));
2668
- return Number(d(amount).mul(mul));
2669
- }
2670
- function asUintN(int, bits = 32) {
2671
- return BigInt.asUintN(bits, BigInt(int)).toString();
2672
- }
2673
- function asIntN(int, bits = 32) {
2674
- return Number(BigInt.asIntN(bits, BigInt(int)));
2675
- }
2676
- function fromDecimalsAmount(amount, decimals) {
2677
- const mul = decimalsMultiplier(d(decimals));
2678
- return Number(d(amount).div(mul));
2679
- }
2680
2850
  function secretKeyToEd25519Keypair(secretKey, ecode = "hex") {
2681
2851
  if (secretKey instanceof Uint8Array) {
2682
2852
  const key = Buffer.from(secretKey);
@@ -3003,7 +3173,7 @@ function getRewardInTickRange(pool, tickLower, tickUpper, tickLowerIndex, tickUp
3003
3173
  // src/utils/transaction-util.ts
3004
3174
  import BN15 from "bn.js";
3005
3175
  import Decimal7 from "decimal.js";
3006
- import { Transaction } from "@mysten/sui/transactions";
3176
+ import { Transaction as Transaction2 } from "@mysten/sui/transactions";
3007
3177
  function findAdjustCoin(coinPair) {
3008
3178
  const isAdjustCoinA = CoinAssist.isSuiCoin(coinPair.coinTypeA);
3009
3179
  const isAdjustCoinB = CoinAssist.isSuiCoin(coinPair.coinTypeB);
@@ -3094,7 +3264,7 @@ var _TransactionUtil = class {
3094
3264
  if (amount < 0) {
3095
3265
  throw new ClmmpoolsError(`gas Insufficient balance`, "InsufficientBalance" /* InsufficientBalance */);
3096
3266
  }
3097
- const newTx = new Transaction();
3267
+ const newTx = new Transaction2();
3098
3268
  return { fixAmount: amount, newTx };
3099
3269
  }
3100
3270
  }
@@ -3184,7 +3354,7 @@ var _TransactionUtil = class {
3184
3354
  if (sdk.senderAddress.length === 0) {
3185
3355
  throw Error("this config sdk senderAddress is empty");
3186
3356
  }
3187
- tx = tx || new Transaction();
3357
+ tx = tx || new Transaction2();
3188
3358
  let primaryCoinAInputs;
3189
3359
  let primaryCoinBInputs;
3190
3360
  if (inputCoinA == null || inputCoinB == null) {
@@ -3242,7 +3412,7 @@ var _TransactionUtil = class {
3242
3412
  if (sdk.senderAddress.length === 0) {
3243
3413
  throw Error("this config sdk senderAddress is empty");
3244
3414
  }
3245
- tx = tx || new Transaction();
3415
+ tx = tx || new Transaction2();
3246
3416
  let primaryCoinAInputs;
3247
3417
  let primaryCoinBInputs;
3248
3418
  if (inputCoinA == null || inputCoinB == null) {
@@ -3539,7 +3709,7 @@ var _TransactionUtil = class {
3539
3709
  * @returns
3540
3710
  */
3541
3711
  static buildSwapTransaction(sdk, params, allCoinAsset) {
3542
- let tx = new Transaction();
3712
+ let tx = new Transaction2();
3543
3713
  tx.setSender(sdk.senderAddress);
3544
3714
  const primaryCoinInputA = _TransactionUtil.buildCoinForAmount(
3545
3715
  tx,
@@ -3559,7 +3729,7 @@ var _TransactionUtil = class {
3559
3729
  return tx;
3560
3730
  }
3561
3731
  static buildCreateLockTransaction(sdk, params, allCoinAsset) {
3562
- let tx = new Transaction();
3732
+ let tx = new Transaction2();
3563
3733
  tx.setSender(sdk.senderAddress);
3564
3734
  const { magma_token } = getPackagerConfigs(sdk.sdkOptions.ve33);
3565
3735
  const lockCoinInput = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.amount), magma_token, false, true);
@@ -3588,7 +3758,7 @@ var _TransactionUtil = class {
3588
3758
  }
3589
3759
  static buildIncreaseLockAmountTransaction(sdk, params, allCoinAsset) {
3590
3760
  const { magma_token } = getPackagerConfigs(sdk.sdkOptions.ve33);
3591
- let tx = new Transaction();
3761
+ let tx = new Transaction2();
3592
3762
  tx.setSender(sdk.senderAddress);
3593
3763
  const lockCoinInput = _TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(params.amount), magma_token, false, true);
3594
3764
  tx = _TransactionUtil.buildIncreaseLockAmountTransactionArgs(tx, params, sdk.sdkOptions, lockCoinInput);
@@ -3609,7 +3779,7 @@ var _TransactionUtil = class {
3609
3779
  }
3610
3780
  // public fun merge<T>(self: &mut VotingEscrow<T>, from_lock: Lock, to_lock: &mut Lock, clock: &Clock, ctx: &mut TxContext) {
3611
3781
  static buildMergeLockTransaction(sdk, params) {
3612
- const tx = new Transaction();
3782
+ const tx = new Transaction2();
3613
3783
  tx.setSender(sdk.senderAddress);
3614
3784
  const { integrate, ve33 } = sdk.sdkOptions;
3615
3785
  const { voter_id, voting_escrow_id, magma_token, distribution_cfg } = getPackagerConfigs(ve33);
@@ -3632,7 +3802,7 @@ var _TransactionUtil = class {
3632
3802
  }
3633
3803
  // public fun transfer<T>(lock: Lock, ve: &mut VotingEscrow<T>, to: address, clock: &Clock, ctx: &mut TxContext) {
3634
3804
  static buildTransferLockTransaction(sdk, params) {
3635
- const tx = new Transaction();
3805
+ const tx = new Transaction2();
3636
3806
  tx.setSender(sdk.senderAddress);
3637
3807
  const { integrate, ve33 } = sdk.sdkOptions;
3638
3808
  const { voting_escrow_id, magma_token } = getPackagerConfigs(ve33);
@@ -3648,7 +3818,7 @@ var _TransactionUtil = class {
3648
3818
  }
3649
3819
  // public fun increase_unlock_time<T>(self: &mut VotingEscrow<T>, lock: &mut Lock, lock_duration: u64, clock: &Clock, ctx: &mut TxContext) {
3650
3820
  static buildIncreaseUnlockTimeTransaction(sdk, params) {
3651
- const tx = new Transaction();
3821
+ const tx = new Transaction2();
3652
3822
  tx.setSender(sdk.senderAddress);
3653
3823
  const oneDay = 24 * 60 * 60;
3654
3824
  const newLockDuration = Math.ceil((params.newLockEndAt - Date.now() / 1e3) / oneDay);
@@ -3666,7 +3836,7 @@ var _TransactionUtil = class {
3666
3836
  }
3667
3837
  // public fun lock_permanent<T>(self: &mut VotingEscrow<T>, lock: &mut Lock, clock: &Clock, ctx: &mut TxContext) {
3668
3838
  static buildLockPermanentTransaction(sdk, params) {
3669
- const tx = new Transaction();
3839
+ const tx = new Transaction2();
3670
3840
  tx.setSender(sdk.senderAddress);
3671
3841
  const { integrate, ve33 } = sdk.sdkOptions;
3672
3842
  const { voting_escrow_id, magma_token } = getPackagerConfigs(ve33);
@@ -3681,7 +3851,7 @@ var _TransactionUtil = class {
3681
3851
  return tx;
3682
3852
  }
3683
3853
  static buildUnlockPermanentTransaction(sdk, params) {
3684
- const tx = new Transaction();
3854
+ const tx = new Transaction2();
3685
3855
  tx.setSender(sdk.senderAddress);
3686
3856
  const { integrate, ve33 } = sdk.sdkOptions;
3687
3857
  const { voting_escrow_id, magma_token, distribution_cfg, voter_id } = getPackagerConfigs(ve33);
@@ -3702,7 +3872,7 @@ var _TransactionUtil = class {
3702
3872
  return tx;
3703
3873
  }
3704
3874
  static buildBurnLockTransaction(sdk, lockId) {
3705
- const tx = new Transaction();
3875
+ const tx = new Transaction2();
3706
3876
  tx.setSender(sdk.senderAddress);
3707
3877
  const { integrate, ve33 } = sdk.sdkOptions;
3708
3878
  const { voting_escrow_id, magma_token, distribution_cfg, voter_id } = getPackagerConfigs(ve33);
@@ -3723,7 +3893,7 @@ var _TransactionUtil = class {
3723
3893
  return tx;
3724
3894
  }
3725
3895
  static buildSplitLockTransaction(sdk, lockId, splitAmount) {
3726
- const tx = new Transaction();
3896
+ const tx = new Transaction2();
3727
3897
  tx.setSender(sdk.senderAddress);
3728
3898
  const { integrate, ve33 } = sdk.sdkOptions;
3729
3899
  const { voting_escrow_id, magma_token, distribution_cfg, voter_id } = getPackagerConfigs(ve33);
@@ -3745,7 +3915,7 @@ var _TransactionUtil = class {
3745
3915
  return tx;
3746
3916
  }
3747
3917
  static buildVoteTransaction(sdk, params) {
3748
- const tx = new Transaction();
3918
+ const tx = new Transaction2();
3749
3919
  tx.setSender(sdk.senderAddress);
3750
3920
  const { integrate, ve33 } = sdk.sdkOptions;
3751
3921
  const { distribution_cfg, voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -3773,7 +3943,7 @@ var _TransactionUtil = class {
3773
3943
  return tx;
3774
3944
  }
3775
3945
  static buildClaimVotingRewardsTransaction(sdk, params) {
3776
- const tx = new Transaction();
3946
+ const tx = new Transaction2();
3777
3947
  tx.setSender(sdk.senderAddress);
3778
3948
  const { integrate, ve33 } = sdk.sdkOptions;
3779
3949
  const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -3788,7 +3958,7 @@ var _TransactionUtil = class {
3788
3958
  return tx;
3789
3959
  }
3790
3960
  static buildClaimVotingRewardsPoolsTransaction(sdk, params) {
3791
- const tx = new Transaction();
3961
+ const tx = new Transaction2();
3792
3962
  tx.setSender(sdk.senderAddress);
3793
3963
  const { integrate, distribution, ve33 } = sdk.sdkOptions;
3794
3964
  const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -3807,7 +3977,7 @@ var _TransactionUtil = class {
3807
3977
  return tx;
3808
3978
  }
3809
3979
  static buildClaimAndLockRebases(sdk, params) {
3810
- const tx = new Transaction();
3980
+ const tx = new Transaction2();
3811
3981
  tx.setSender(sdk.senderAddress);
3812
3982
  const { integrate, ve33 } = sdk.sdkOptions;
3813
3983
  const { voting_escrow_id, magma_token, reward_distributor_id } = getPackagerConfigs(ve33);
@@ -3822,7 +3992,7 @@ var _TransactionUtil = class {
3822
3992
  return tx;
3823
3993
  }
3824
3994
  static buildPoke(sdk, params) {
3825
- const tx = new Transaction();
3995
+ const tx = new Transaction2();
3826
3996
  tx.setSender(sdk.senderAddress);
3827
3997
  const { integrate, ve33 } = sdk.sdkOptions;
3828
3998
  const { distribution_cfg, voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -3843,7 +4013,7 @@ var _TransactionUtil = class {
3843
4013
  return tx;
3844
4014
  }
3845
4015
  static buildClaimVotingBribe(sdk, locks, incentive_tokens) {
3846
- const tx = new Transaction();
4016
+ const tx = new Transaction2();
3847
4017
  tx.setSender(sdk.senderAddress);
3848
4018
  const { integrate, distribution, ve33 } = sdk.sdkOptions;
3849
4019
  const { voting_escrow_id, magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -3971,7 +4141,7 @@ var _TransactionUtil = class {
3971
4141
  * @returns
3972
4142
  */
3973
4143
  static buildSwapTransactionWithoutTransferCoins(sdk, params, allCoinAsset) {
3974
- const tx = new Transaction();
4144
+ const tx = new Transaction2();
3975
4145
  tx.setSender(sdk.senderAddress);
3976
4146
  const primaryCoinInputA = _TransactionUtil.buildCoinForAmount(
3977
4147
  tx,
@@ -4237,7 +4407,7 @@ var _TransactionUtil = class {
4237
4407
  }
4238
4408
  // ------------------------------------------router-v1-------------------------------------------------//
4239
4409
  static async buildRouterSwapTransaction(sdk, params, byAmountIn, allCoinAsset, recipient) {
4240
- let tx = new Transaction();
4410
+ let tx = new Transaction2();
4241
4411
  if (params.paths.length > 1) {
4242
4412
  params.partner = "";
4243
4413
  }
@@ -4550,7 +4720,7 @@ var _TransactionUtil = class {
4550
4720
  return { fromCoin, toCoin, tx };
4551
4721
  }
4552
4722
  static async buildAggregatorSwapTransaction(sdk, param, allCoinAsset, partner, priceSlippagePoint, recipient) {
4553
- let tx = new Transaction();
4723
+ let tx = new Transaction2();
4554
4724
  const amountLimit = param.byAmountIn ? Math.round(param.outputAmount * (1 - priceSlippagePoint)) : Math.round(param.inputAmount * (1 + priceSlippagePoint));
4555
4725
  const fromCoinBuildResult = _TransactionUtil.buildCoinForAmount(
4556
4726
  tx,
@@ -4733,7 +4903,7 @@ __publicField(TransactionUtil, "callMintZeroValueCoin", (txb, coinType) => {
4733
4903
  });
4734
4904
 
4735
4905
  // src/utils/tx-block.ts
4736
- import { Transaction as Transaction2 } from "@mysten/sui/transactions";
4906
+ import { Transaction as Transaction3 } from "@mysten/sui/transactions";
4737
4907
  function checkInvalidSuiAddress(address) {
4738
4908
  if (!address.startsWith("0x") || address.length !== 66) {
4739
4909
  return false;
@@ -4743,7 +4913,7 @@ function checkInvalidSuiAddress(address) {
4743
4913
  var TxBlock = class {
4744
4914
  txBlock;
4745
4915
  constructor() {
4746
- this.txBlock = new Transaction2();
4916
+ this.txBlock = new Transaction3();
4747
4917
  }
4748
4918
  /**
4749
4919
  * Transfer sui to many recipoents.
@@ -4811,7 +4981,7 @@ var TxBlock = class {
4811
4981
 
4812
4982
  // src/utils/deepbook-utils.ts
4813
4983
  import BN16 from "bn.js";
4814
- import { Transaction as Transaction3 } from "@mysten/sui/transactions";
4984
+ import { Transaction as Transaction4 } from "@mysten/sui/transactions";
4815
4985
  var FLOAT_SCALING = new BN16(1e9);
4816
4986
  var DeepbookUtils = class {
4817
4987
  static createAccountCap(senderAddress, sdkOptions, tx, isTransfer = false) {
@@ -4892,7 +5062,7 @@ var DeepbookUtils = class {
4892
5062
  static async getPoolAsks(sdk, poolAddress, baseCoin, quoteCoin) {
4893
5063
  const { simulationAccount } = sdk.sdkOptions;
4894
5064
  const { deepbook_endpoint_v2 } = sdk.sdkOptions;
4895
- const tx = new Transaction3();
5065
+ const tx = new Transaction4();
4896
5066
  const asks = [];
4897
5067
  const typeArguments = [baseCoin, quoteCoin];
4898
5068
  const args = [tx.object(poolAddress), tx.pure.u64("0"), tx.pure.u64("999999999999"), tx.object(CLOCK_ADDRESS)];
@@ -4925,7 +5095,7 @@ var DeepbookUtils = class {
4925
5095
  static async getPoolBids(sdk, poolAddress, baseCoin, quoteCoin) {
4926
5096
  const { simulationAccount } = sdk.sdkOptions;
4927
5097
  const { deepbook_endpoint_v2 } = sdk.sdkOptions;
4928
- const tx = new Transaction3();
5098
+ const tx = new Transaction4();
4929
5099
  const bids = [];
4930
5100
  const typeArguments = [baseCoin, quoteCoin];
4931
5101
  const args = [tx.object(poolAddress), tx.pure.u64("0"), tx.pure.u64("999999999999"), tx.object(CLOCK_ADDRESS)];
@@ -5029,7 +5199,7 @@ var DeepbookUtils = class {
5029
5199
  }
5030
5200
  static async simulateSwap(sdk, poolID, baseCoin, quoteCoin, a2b, amount) {
5031
5201
  const { deepbook_endpoint_v2 } = sdk.sdkOptions;
5032
- let tx = new Transaction3();
5202
+ let tx = new Transaction4();
5033
5203
  const accountCapStr = await this.getAccountCap(sdk);
5034
5204
  let accountCap;
5035
5205
  if (accountCapStr === "") {
@@ -5484,7 +5654,7 @@ var PoolModule = class {
5484
5654
  * @returns {Promise<Transaction>} A promise that resolves to the transaction payload.
5485
5655
  */
5486
5656
  async creatPool(params) {
5487
- const tx = new Transaction4();
5657
+ const tx = new Transaction5();
5488
5658
  const { integrate, clmm_pool } = this.sdk.sdkOptions;
5489
5659
  const eventConfig = getPackagerConfigs(clmm_pool);
5490
5660
  const globalPauseStatusObjectId = eventConfig.global_config_id;
@@ -5515,7 +5685,7 @@ var PoolModule = class {
5515
5685
  if (!checkInvalidSuiAddress(this._sdk.senderAddress)) {
5516
5686
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
5517
5687
  }
5518
- const tx = new Transaction4();
5688
+ const tx = new Transaction5();
5519
5689
  tx.setSender(this.sdk.senderAddress);
5520
5690
  const { integrate, clmm_pool } = this.sdk.sdkOptions;
5521
5691
  const eventConfig = getPackagerConfigs(clmm_pool);
@@ -5580,7 +5750,7 @@ var PoolModule = class {
5580
5750
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
5581
5751
  const ticks = [];
5582
5752
  const typeArguments = [params.coinTypeA, params.coinTypeB];
5583
- const tx = new Transaction4();
5753
+ const tx = new Transaction5();
5584
5754
  const start = tx.makeMoveVec({
5585
5755
  elements: params.start.map((index) => tx.pure.u32(index)),
5586
5756
  type: "u32"
@@ -5625,7 +5795,7 @@ var PoolModule = class {
5625
5795
  const limit = 512;
5626
5796
  while (true) {
5627
5797
  const typeArguments = [params.coinTypeA, params.coinTypeB];
5628
- const tx = new Transaction4();
5798
+ const tx = new Transaction5();
5629
5799
  const vecStart = tx.makeMoveVec({
5630
5800
  elements: start.map((id) => tx.pure.address(id)),
5631
5801
  type: void 0
@@ -5809,7 +5979,7 @@ var PoolModule = class {
5809
5979
  * @returns {Promise<Transaction>} A promise that resolves to the transaction payload.
5810
5980
  */
5811
5981
  async claimPartnerRefFeePayload(partnerCap, partner, coinType) {
5812
- const tx = new Transaction4();
5982
+ const tx = new Transaction5();
5813
5983
  const { clmm_pool } = this.sdk.sdkOptions;
5814
5984
  const { global_config_id } = getPackagerConfigs(clmm_pool);
5815
5985
  const typeArguments = [coinType];
@@ -5858,7 +6028,7 @@ var PoolModule = class {
5858
6028
 
5859
6029
  // src/modules/positionModule.ts
5860
6030
  import BN17 from "bn.js";
5861
- import { Transaction as Transaction5 } from "@mysten/sui/transactions";
6031
+ import { Transaction as Transaction6 } from "@mysten/sui/transactions";
5862
6032
  import { isValidSuiObjectId } from "@mysten/sui/utils";
5863
6033
  var PositionModule = class {
5864
6034
  _sdk;
@@ -5915,8 +6085,8 @@ var PositionModule = class {
5915
6085
  * @param {boolean} calculateRewarder Whether to calculate the rewarder of the position.
5916
6086
  * @returns {Promise<Position>} Position object.
5917
6087
  */
5918
- async getPosition(positionHandle, positionID, calculateRewarder = true, showDisplay = true) {
5919
- let position = await this.getSimplePosition(positionID, showDisplay);
6088
+ async getPosition(positionHandle, positionID, calculateRewarder = true, showDisplay = true, forceRefresh = false) {
6089
+ let position = await this.getSimplePosition(positionID, showDisplay, forceRefresh);
5920
6090
  if (calculateRewarder) {
5921
6091
  position = await this.updatePositionRewarders(positionHandle, position);
5922
6092
  }
@@ -5928,8 +6098,8 @@ var PositionModule = class {
5928
6098
  * @param {boolean} calculateRewarder Whether to calculate the rewarder of the position.
5929
6099
  * @returns {Promise<Position>} Position object.
5930
6100
  */
5931
- async getPositionById(positionID, calculateRewarder = true, showDisplay = true) {
5932
- const position = await this.getSimplePosition(positionID, showDisplay);
6101
+ async getPositionById(positionID, calculateRewarder = true, showDisplay = true, forceRefresh = false) {
6102
+ const position = await this.getSimplePosition(positionID, showDisplay, forceRefresh);
5933
6103
  if (calculateRewarder) {
5934
6104
  const pool = await this._sdk.Pool.getPool(position.pool, false);
5935
6105
  const result = await this.updatePositionRewarders(pool.position_manager.positions_handle, position);
@@ -5942,10 +6112,10 @@ var PositionModule = class {
5942
6112
  * @param {string} positionID The ID of the position to get.
5943
6113
  * @returns {Promise<Position>} Position object.
5944
6114
  */
5945
- async getSimplePosition(positionID, showDisplay = true) {
6115
+ async getSimplePosition(positionID, showDisplay = true, forceRefresh = false) {
5946
6116
  const cacheKey = `${positionID}_getPositionList`;
5947
6117
  let position = this.getSimplePositionByCache(positionID);
5948
- if (position === void 0) {
6118
+ if (forceRefresh || position === void 0) {
5949
6119
  const objectDataResponses = await this.sdk.fullClient.getObject({
5950
6120
  id: positionID,
5951
6121
  options: { showContent: true, showType: true, showDisplay, showOwner: true }
@@ -6042,7 +6212,7 @@ var PositionModule = class {
6042
6212
  */
6043
6213
  async fetchPosFeeAmount(params) {
6044
6214
  const { clmm_pool, integrate, simulationAccount } = this.sdk.sdkOptions;
6045
- const tx = new Transaction5();
6215
+ const tx = new Transaction6();
6046
6216
  for (const paramItem of params) {
6047
6217
  const typeArguments = [paramItem.coinTypeA, paramItem.coinTypeB];
6048
6218
  const args = [
@@ -6187,7 +6357,7 @@ var PositionModule = class {
6187
6357
  const tick_lower = asUintN(BigInt(params.tick_lower)).toString();
6188
6358
  const tick_upper = asUintN(BigInt(params.tick_upper)).toString();
6189
6359
  const typeArguments = [params.coinTypeA, params.coinTypeB];
6190
- tx = tx || new Transaction5();
6360
+ tx = tx || new Transaction6();
6191
6361
  const needOpenPosition = !isValidSuiObjectId(params.pos_id);
6192
6362
  const max_amount_a = BigInt(params.max_amount_a);
6193
6363
  const max_amount_b = BigInt(params.max_amount_b);
@@ -6267,7 +6437,7 @@ var PositionModule = class {
6267
6437
  }
6268
6438
  const { clmm_pool, integrate } = this.sdk.sdkOptions;
6269
6439
  const functionName = "remove_liquidity";
6270
- tx = tx || new Transaction5();
6440
+ tx = tx || new Transaction6();
6271
6441
  const typeArguments = [params.coinTypeA, params.coinTypeB];
6272
6442
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
6273
6443
  tx = TransactionUtil.createCollectRewarderAndFeeParams(this._sdk, tx, params, allCoinAsset);
@@ -6297,7 +6467,7 @@ var PositionModule = class {
6297
6467
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6298
6468
  }
6299
6469
  const { clmm_pool, integrate } = this.sdk.sdkOptions;
6300
- tx = tx || new Transaction5();
6470
+ tx = tx || new Transaction6();
6301
6471
  const typeArguments = [params.coinTypeA, params.coinTypeB];
6302
6472
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress);
6303
6473
  tx = TransactionUtil.createCollectRewarderAndFeeParams(this._sdk, tx, params, allCoinAsset);
@@ -6322,7 +6492,7 @@ var PositionModule = class {
6322
6492
  */
6323
6493
  openPositionTransactionPayload(params, tx) {
6324
6494
  const { clmm_pool, integrate } = this.sdk.sdkOptions;
6325
- tx = tx || new Transaction5();
6495
+ tx = tx || new Transaction6();
6326
6496
  const typeArguments = [params.coinTypeA, params.coinTypeB];
6327
6497
  const tick_lower = asUintN(BigInt(params.tick_lower)).toString();
6328
6498
  const tick_upper = asUintN(BigInt(params.tick_upper)).toString();
@@ -6350,7 +6520,7 @@ var PositionModule = class {
6350
6520
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6351
6521
  }
6352
6522
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null, true);
6353
- tx = tx || new Transaction5();
6523
+ tx = tx || new Transaction6();
6354
6524
  const primaryCoinAInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), params.coinTypeA, false);
6355
6525
  const primaryCoinBInput = TransactionUtil.buildCoinForAmount(tx, allCoinAsset, BigInt(0), params.coinTypeB, false);
6356
6526
  const coinA = inputCoinA ?? primaryCoinAInput.targetCoin;
@@ -6457,7 +6627,7 @@ var PositionModule = class {
6457
6627
 
6458
6628
  // src/modules/rewarderModule.ts
6459
6629
  import BN18 from "bn.js";
6460
- import { Transaction as Transaction6 } from "@mysten/sui/transactions";
6630
+ import { Transaction as Transaction7 } from "@mysten/sui/transactions";
6461
6631
  var RewarderModule = class {
6462
6632
  _sdk;
6463
6633
  growthGlobal;
@@ -6694,7 +6864,7 @@ var RewarderModule = class {
6694
6864
  */
6695
6865
  async fetchPosFeeAmount(params) {
6696
6866
  const { clmm_pool, integrate, simulationAccount } = this.sdk.sdkOptions;
6697
- const tx = new Transaction6();
6867
+ const tx = new Transaction7();
6698
6868
  for (const paramItem of params) {
6699
6869
  const typeArguments = [paramItem.coinTypeA, paramItem.coinTypeB];
6700
6870
  const args = [
@@ -6737,7 +6907,7 @@ var RewarderModule = class {
6737
6907
  */
6738
6908
  async fetchPosRewardersAmount(params) {
6739
6909
  const { clmm_pool, integrate, simulationAccount } = this.sdk.sdkOptions;
6740
- const tx = new Transaction6();
6910
+ const tx = new Transaction7();
6741
6911
  for (const paramItem of params) {
6742
6912
  const typeArguments = [paramItem.coinTypeA, paramItem.coinTypeB];
6743
6913
  const args = [
@@ -6846,7 +7016,7 @@ var RewarderModule = class {
6846
7016
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6847
7017
  }
6848
7018
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
6849
- let tx = new Transaction6();
7019
+ let tx = new Transaction7();
6850
7020
  tx = TransactionUtil.createCollectRewarderAndFeeParams(this._sdk, tx, params, allCoinAsset);
6851
7021
  return tx;
6852
7022
  }
@@ -6862,7 +7032,7 @@ var RewarderModule = class {
6862
7032
  throw new ClmmpoolsError("this config sdk senderAddress is not set right", "InvalidSendAddress" /* InvalidSendAddress */);
6863
7033
  }
6864
7034
  const allCoinAsset = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress, null);
6865
- tx = tx || new Transaction6();
7035
+ tx = tx || new Transaction7();
6866
7036
  const coinIdList = [];
6867
7037
  params.forEach((item) => {
6868
7038
  const coinTypeA = normalizeCoinType(item.coinTypeA);
@@ -6947,7 +7117,7 @@ var RewarderModule = class {
6947
7117
  // src/modules/routerModule.ts
6948
7118
  import BN19 from "bn.js";
6949
7119
  import { Graph, GraphEdge, GraphVertex } from "@syntsugar/cc-graph";
6950
- import { Transaction as Transaction7 } from "@mysten/sui/transactions";
7120
+ import { Transaction as Transaction8 } from "@mysten/sui/transactions";
6951
7121
  function _pairSymbol(base, quote) {
6952
7122
  return {
6953
7123
  pair: `${base}-${quote}`,
@@ -7397,7 +7567,7 @@ var RouterModule = class {
7397
7567
  return null;
7398
7568
  }
7399
7569
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
7400
- const tx = new Transaction7();
7570
+ const tx = new Transaction8();
7401
7571
  for (const param of params) {
7402
7572
  if (param.stepNums > 1) {
7403
7573
  const args = [
@@ -7537,7 +7707,7 @@ var RouterModule = class {
7537
7707
  // src/modules/swapModule.ts
7538
7708
  import BN20 from "bn.js";
7539
7709
  import Decimal8 from "decimal.js";
7540
- import { Transaction as Transaction8 } from "@mysten/sui/transactions";
7710
+ import { Transaction as Transaction9 } from "@mysten/sui/transactions";
7541
7711
  var AMM_SWAP_MODULE = "amm_swap";
7542
7712
  var POOL_STRUCT = "Pool";
7543
7713
  var SwapModule = class {
@@ -7607,7 +7777,7 @@ var SwapModule = class {
7607
7777
  */
7608
7778
  async preSwapWithMultiPool(params) {
7609
7779
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
7610
- const tx = new Transaction8();
7780
+ const tx = new Transaction9();
7611
7781
  const typeArguments = [params.coinTypeA, params.coinTypeB];
7612
7782
  for (let i = 0; i < params.poolAddresses.length; i += 1) {
7613
7783
  const args = [
@@ -7685,7 +7855,7 @@ var SwapModule = class {
7685
7855
  async preswap(params) {
7686
7856
  const { integrate, simulationAccount, clmm_pool } = this.sdk.sdkOptions;
7687
7857
  const { global_config_id } = getPackagerConfigs(clmm_pool);
7688
- const tx = new Transaction8();
7858
+ const tx = new Transaction9();
7689
7859
  const typeArguments = [params.coinTypeA, params.coinTypeB];
7690
7860
  const args = [
7691
7861
  tx.object(global_config_id),
@@ -7852,7 +8022,7 @@ var SwapModule = class {
7852
8022
  };
7853
8023
 
7854
8024
  // src/modules/lockModule.ts
7855
- import { Transaction as Transaction9 } from "@mysten/sui/transactions";
8025
+ import { Transaction as Transaction10 } from "@mysten/sui/transactions";
7856
8026
  var LockModule = class {
7857
8027
  _sdk;
7858
8028
  constructor(sdk) {
@@ -7949,7 +8119,7 @@ var LockModule = class {
7949
8119
  if (this._sdk.senderAddress.length === 0) {
7950
8120
  throw Error("this config sdk senderAddress is empty");
7951
8121
  }
7952
- const tx = new Transaction9();
8122
+ const tx = new Transaction10();
7953
8123
  tx.setSender(this.sdk.senderAddress);
7954
8124
  const { integrate, ve33 } = this.sdk.sdkOptions;
7955
8125
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
@@ -7984,7 +8154,7 @@ var LockModule = class {
7984
8154
  if (incentiveTokens.length === 1) {
7985
8155
  targetFunc = `${integrate.published_at}::${Voter}::claim_voting_bribes_for_single_pool`;
7986
8156
  }
7987
- const tx = new Transaction9();
8157
+ const tx = new Transaction10();
7988
8158
  tx.setSender(this.sdk.senderAddress);
7989
8159
  const args = [tx.object(voter_id), tx.object(voting_escrow_id), tx.object(lockId), tx.object(poolId), tx.object(CLOCK_ADDRESS)];
7990
8160
  tx.moveCall({
@@ -8228,7 +8398,7 @@ var LockModule = class {
8228
8398
  return lockInfo;
8229
8399
  }
8230
8400
  async aLockSummary(lock_id) {
8231
- const tx = new Transaction9();
8401
+ const tx = new Transaction10();
8232
8402
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8233
8403
  const { voting_escrow_id, magma_token, voter_id, reward_distributor_id } = getPackagerConfigs(ve33);
8234
8404
  const typeArguments = [magma_token];
@@ -8274,14 +8444,14 @@ var LockModule = class {
8274
8444
  }
8275
8445
  // Return: lock_id => ALockSummary
8276
8446
  async getAllLockSummary(lock_ids) {
8277
- let tx = new Transaction9();
8447
+ let tx = new Transaction10();
8278
8448
  for (const lock_id of lock_ids) {
8279
8449
  tx = await this._aLockSummary(lock_id, tx);
8280
8450
  }
8281
8451
  return this._parseLockSummary(tx);
8282
8452
  }
8283
8453
  async _aLockSummary(lock_id, tx) {
8284
- tx = tx || new Transaction9();
8454
+ tx = tx || new Transaction10();
8285
8455
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8286
8456
  const { voting_escrow_id, magma_token, voter_id, reward_distributor_id } = getPackagerConfigs(ve33);
8287
8457
  const typeArguments = [magma_token];
@@ -8324,7 +8494,7 @@ var LockModule = class {
8324
8494
  return res;
8325
8495
  }
8326
8496
  async allLockSummary() {
8327
- const tx = new Transaction9();
8497
+ const tx = new Transaction10();
8328
8498
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8329
8499
  const { voting_escrow_id, magma_token, voter_id, minter_id } = getPackagerConfigs(ve33);
8330
8500
  const typeArguments = [magma_token];
@@ -8369,7 +8539,7 @@ var LockModule = class {
8369
8539
  return summary;
8370
8540
  }
8371
8541
  async poolWeights(pools) {
8372
- const tx = new Transaction9();
8542
+ const tx = new Transaction10();
8373
8543
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8374
8544
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8375
8545
  const typeArguments = [magma_token];
@@ -8404,14 +8574,14 @@ var LockModule = class {
8404
8574
  return poolWeights;
8405
8575
  }
8406
8576
  async getAllVotingFeeRewardTokens(lock_ids) {
8407
- let tx = new Transaction9();
8577
+ let tx = new Transaction10();
8408
8578
  for (const lock_id of lock_ids) {
8409
8579
  tx = await this._getVotingFeeRewardTokens(lock_id, tx);
8410
8580
  }
8411
8581
  return this._parseVotingFeeRewardTokens(tx);
8412
8582
  }
8413
8583
  async _getVotingFeeRewardTokens(lock_id, tx) {
8414
- tx = tx || new Transaction9();
8584
+ tx = tx || new Transaction10();
8415
8585
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8416
8586
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8417
8587
  const typeArguments = [magma_token];
@@ -8452,7 +8622,7 @@ var LockModule = class {
8452
8622
  return poolFeeRewardTokens;
8453
8623
  }
8454
8624
  async getVotingFeeRewardTokens(lock_id) {
8455
- const tx = new Transaction9();
8625
+ const tx = new Transaction10();
8456
8626
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8457
8627
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8458
8628
  const typeArguments = [magma_token];
@@ -8489,14 +8659,14 @@ var LockModule = class {
8489
8659
  }
8490
8660
  // tokens
8491
8661
  async getAllBribeRewardTokensOfLock(lock_ids) {
8492
- let tx = new Transaction9();
8662
+ let tx = new Transaction10();
8493
8663
  for (const lock_id of lock_ids) {
8494
8664
  tx = await this._getVotingBribeRewardTokens(lock_id, tx);
8495
8665
  }
8496
8666
  return this._parseVotingBribeRewardTokens(tx);
8497
8667
  }
8498
8668
  async _getVotingBribeRewardTokens(lock_id, tx) {
8499
- tx = tx || new Transaction9();
8669
+ tx = tx || new Transaction10();
8500
8670
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8501
8671
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8502
8672
  const typeArguments = [magma_token];
@@ -8538,7 +8708,7 @@ var LockModule = class {
8538
8708
  }
8539
8709
  // Return PoolId => tokens
8540
8710
  async getVotingBribeRewardTokens(lock_id) {
8541
- const tx = new Transaction9();
8711
+ const tx = new Transaction10();
8542
8712
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8543
8713
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8544
8714
  const typeArguments = [magma_token];
@@ -8574,7 +8744,7 @@ var LockModule = class {
8574
8744
  return poolBirbeRewardTokens;
8575
8745
  }
8576
8746
  async getAllFeeRewards(fee_tokens) {
8577
- let tx = new Transaction9();
8747
+ let tx = new Transaction10();
8578
8748
  fee_tokens.forEach((tokens, lock_id) => {
8579
8749
  tx = this._getFeeRewards(lock_id, tokens, tx);
8580
8750
  });
@@ -8590,7 +8760,7 @@ var LockModule = class {
8590
8760
  return tx;
8591
8761
  }
8592
8762
  _getFeeRewardsInner(lock_id, token_a, token_b, tx) {
8593
- tx = tx || new Transaction9();
8763
+ tx = tx || new Transaction10();
8594
8764
  const { integrate, ve33 } = this.sdk.sdkOptions;
8595
8765
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8596
8766
  const typeArguments = [magma_token, token_a, token_b];
@@ -8650,7 +8820,7 @@ var LockModule = class {
8650
8820
  }
8651
8821
  // if you have many tokens, call this function multi times
8652
8822
  async _getPoolFeeRewards(lock_id, token_a, token_b, poolFeeRewardTokens) {
8653
- const tx = new Transaction9();
8823
+ const tx = new Transaction10();
8654
8824
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8655
8825
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8656
8826
  const typeArguments = [magma_token, token_a, token_b];
@@ -8688,7 +8858,7 @@ var LockModule = class {
8688
8858
  // params: lock_id => incentive_tokens
8689
8859
  // lock_id => Pool => rewardTokens
8690
8860
  async getAllIncentiveRewards(lock_incentive_tokens) {
8691
- let tx = new Transaction9();
8861
+ let tx = new Transaction10();
8692
8862
  lock_incentive_tokens.forEach((tokens, lock_id) => {
8693
8863
  tx = this._getIncentiveRewards(lock_id, tokens, tx);
8694
8864
  });
@@ -8702,7 +8872,7 @@ var LockModule = class {
8702
8872
  return this._getIncentiveRewardsInner(lock_id, incentive_tokens.slice(i), tx);
8703
8873
  }
8704
8874
  _getIncentiveRewardsInner(locksId, incentive_tokens, tx) {
8705
- tx = tx || new Transaction9();
8875
+ tx = tx || new Transaction10();
8706
8876
  if (incentive_tokens.length > 3) {
8707
8877
  throw Error("Too many tokens");
8708
8878
  }
@@ -8774,7 +8944,7 @@ var LockModule = class {
8774
8944
  if (incentive_tokens.length > 3) {
8775
8945
  throw Error("Too many tokens");
8776
8946
  }
8777
- const tx = new Transaction9();
8947
+ const tx = new Transaction10();
8778
8948
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8779
8949
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8780
8950
  const typeArguments = [magma_token, ...incentive_tokens];
@@ -8813,7 +8983,7 @@ var LockModule = class {
8813
8983
  return poolBribeRewardTokens;
8814
8984
  }
8815
8985
  async getPoolBribeRewardTokens(pool_id) {
8816
- const tx = new Transaction9();
8986
+ const tx = new Transaction10();
8817
8987
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8818
8988
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8819
8989
  const typeArguments = [magma_token];
@@ -8849,7 +9019,7 @@ var LockModule = class {
8849
9019
  return poolBirbeRewardTokens;
8850
9020
  }
8851
9021
  async getLockVotingStats(lockId) {
8852
- const tx = new Transaction9();
9022
+ const tx = new Transaction10();
8853
9023
  const { integrate, simulationAccount, ve33 } = this.sdk.sdkOptions;
8854
9024
  const { magma_token, voter_id } = getPackagerConfigs(ve33);
8855
9025
  const args = [tx.object(voter_id), tx.object(lockId), tx.object(CLOCK_ADDRESS)];
@@ -8892,7 +9062,7 @@ var LockModule = class {
8892
9062
 
8893
9063
  // src/modules/tokenModule.ts
8894
9064
  import { Base64 } from "js-base64";
8895
- import { Transaction as Transaction10 } from "@mysten/sui/transactions";
9065
+ import { Transaction as Transaction11 } from "@mysten/sui/transactions";
8896
9066
  import { normalizeSuiObjectId as normalizeSuiObjectId2 } from "@mysten/sui/utils";
8897
9067
  var TokenModule = class {
8898
9068
  _sdk;
@@ -9028,7 +9198,7 @@ var TokenModule = class {
9028
9198
  }
9029
9199
  const tokenConfig = getPackagerConfigs(token);
9030
9200
  while (true) {
9031
- const tx = new Transaction10();
9201
+ const tx = new Transaction11();
9032
9202
  tx.moveCall({
9033
9203
  target: `${token.published_at}::coin_list::${isOwnerRequest ? "fetch_full_list_with_limit" : "fetch_all_registered_coin_info_with_limit"}`,
9034
9204
  arguments: isOwnerRequest ? [tx.pure.address(tokenConfig.coin_registry_id), tx.pure.address(listOwnerAddr), tx.pure.u64(index), tx.pure.u64(limit)] : [tx.pure.address(tokenConfig.coin_registry_id), tx.pure.u64(index), tx.pure.u64(limit)]
@@ -9071,7 +9241,7 @@ var TokenModule = class {
9071
9241
  }
9072
9242
  const tokenConfig = getPackagerConfigs(token);
9073
9243
  while (true) {
9074
- const tx = new Transaction10();
9244
+ const tx = new Transaction11();
9075
9245
  tx.moveCall({
9076
9246
  target: `${token.published_at}::lp_list::${isOwnerRequest ? "fetch_full_list_with_limit" : "fetch_all_registered_coin_info_with_limit"}`,
9077
9247
  arguments: isOwnerRequest ? [tx.pure.address(tokenConfig.pool_registry_id), tx.pure.address(listOwnerAddr), tx.pure.u64(index), tx.pure.u64(limit)] : [tx.pure.address(tokenConfig.pool_registry_id), tx.pure.u64(index), tx.pure.u64(limit)]
@@ -10229,7 +10399,7 @@ var RpcModule = class extends SuiClient {
10229
10399
  };
10230
10400
 
10231
10401
  // src/modules/gaugeModule.ts
10232
- import { Transaction as Transaction11 } from "@mysten/sui/transactions";
10402
+ import { Transaction as Transaction12 } from "@mysten/sui/transactions";
10233
10403
  var GaugeModule = class {
10234
10404
  _sdk;
10235
10405
  constructor(sdk) {
@@ -10239,7 +10409,7 @@ var GaugeModule = class {
10239
10409
  return this._sdk;
10240
10410
  }
10241
10411
  async depositPosition(params) {
10242
- const tx = new Transaction11();
10412
+ const tx = new Transaction12();
10243
10413
  tx.setSender(this.sdk.senderAddress);
10244
10414
  const poolGauge = await this.getPoolGaguers();
10245
10415
  const gauge = poolGauge.get(params.poolId);
@@ -10266,7 +10436,7 @@ var GaugeModule = class {
10266
10436
  return tx;
10267
10437
  }
10268
10438
  async withdrawPosition(params) {
10269
- const tx = new Transaction11();
10439
+ const tx = new Transaction12();
10270
10440
  tx.setSender(this.sdk.senderAddress);
10271
10441
  const poolGauge = await this.sdk.Gauge.getPoolGaguers();
10272
10442
  const gauge = poolGauge.get(params.poolId);
@@ -10321,7 +10491,7 @@ var GaugeModule = class {
10321
10491
  return res;
10322
10492
  }
10323
10493
  async getUserStakedPositionInfoOfPool(userAddr, pool, gauger, poolCoinA, poolCoinB) {
10324
- const tx = new Transaction11();
10494
+ const tx = new Transaction12();
10325
10495
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
10326
10496
  const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10327
10497
  const typeArguments = [poolCoinA, poolCoinB, magma_token];
@@ -10345,7 +10515,7 @@ var GaugeModule = class {
10345
10515
  return res;
10346
10516
  }
10347
10517
  async getPoolGaguers() {
10348
- const tx = new Transaction11();
10518
+ const tx = new Transaction12();
10349
10519
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
10350
10520
  const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10351
10521
  const typeArguments = [magma_token];
@@ -10385,7 +10555,7 @@ var GaugeModule = class {
10385
10555
  return poolCoins;
10386
10556
  }
10387
10557
  async getEmissions() {
10388
- const tx = new Transaction11();
10558
+ const tx = new Transaction12();
10389
10559
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
10390
10560
  const { magma_token, minter_id, voting_escrow_id } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10391
10561
  const typeArguments = [magma_token];
@@ -10419,7 +10589,7 @@ var GaugeModule = class {
10419
10589
  return res;
10420
10590
  }
10421
10591
  async getRewardByPosition(params) {
10422
- const tx = new Transaction11();
10592
+ const tx = new Transaction12();
10423
10593
  const { integrate } = this.sdk.sdkOptions;
10424
10594
  const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10425
10595
  const typeArguments = [params.coinTypeA, params.coinTypeB, magma_token];
@@ -10432,7 +10602,7 @@ var GaugeModule = class {
10432
10602
  return tx;
10433
10603
  }
10434
10604
  async getAllRewardByPositions(paramsList) {
10435
- const tx = new Transaction11();
10605
+ const tx = new Transaction12();
10436
10606
  const { integrate } = this.sdk.sdkOptions;
10437
10607
  const { magma_token } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10438
10608
  paramsList.forEach((params) => {
@@ -10447,7 +10617,7 @@ var GaugeModule = class {
10447
10617
  return tx;
10448
10618
  }
10449
10619
  async getEpochRewardByPool(pool, incentive_tokens) {
10450
- const tx = new Transaction11();
10620
+ const tx = new Transaction12();
10451
10621
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
10452
10622
  const { magma_token, voter_id } = getPackagerConfigs(this.sdk.sdkOptions.ve33);
10453
10623
  const typeArguments = [magma_token, ...incentive_tokens];
@@ -10479,7 +10649,7 @@ var GaugeModule = class {
10479
10649
  };
10480
10650
 
10481
10651
  // src/modules/almm.ts
10482
- import { Transaction as Transaction12 } from "@mysten/sui/transactions";
10652
+ import { Transaction as Transaction13 } from "@mysten/sui/transactions";
10483
10653
  import {
10484
10654
  get_price_x128_from_real_id as get_price_x128_from_real_id3,
10485
10655
  get_real_id,
@@ -10579,7 +10749,7 @@ var AlmmModule = class {
10579
10749
  }
10580
10750
  // eg: fetch pool active_index
10581
10751
  async fetchPairParams(params) {
10582
- const tx = new Transaction12();
10752
+ const tx = new Transaction13();
10583
10753
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
10584
10754
  const typeArguments = [params.coinTypeA, params.coinTypeB];
10585
10755
  const args = [tx.object(params.pair)];
@@ -10624,7 +10794,7 @@ var AlmmModule = class {
10624
10794
  const storage_id = get_storage_id_from_real_id(
10625
10795
  BinMath.getBinIdFromPrice(params.priceTokenBPerTokenA, params.bin_step, params.coinADecimal, params.coinBDecimal)
10626
10796
  );
10627
- const tx = new Transaction12();
10797
+ const tx = new Transaction13();
10628
10798
  tx.setSender(this.sdk.senderAddress);
10629
10799
  const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
10630
10800
  const { global_config_id } = getPackagerConfigs(clmm_pool);
@@ -10645,7 +10815,7 @@ var AlmmModule = class {
10645
10815
  });
10646
10816
  return tx;
10647
10817
  }
10648
- async mintByStrategy(params) {
10818
+ async mintByStrategy(params, tx) {
10649
10819
  if (params.fixCoinA && params.fixCoinB) {
10650
10820
  if (params.amountATotal === 0 || params.amountBTotal === 0) {
10651
10821
  if (params.active_bin < params.max_bin && params.active_bin > params.min_bin) {
@@ -10657,7 +10827,9 @@ var AlmmModule = class {
10657
10827
  }
10658
10828
  }
10659
10829
  }
10660
- const tx = new Transaction12();
10830
+ if (!tx) {
10831
+ tx = new Transaction13();
10832
+ }
10661
10833
  const slippage = new Decimal10(params.slippage);
10662
10834
  const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
10663
10835
  const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
@@ -10676,18 +10848,18 @@ var AlmmModule = class {
10676
10848
  let primaryCoinAInputs;
10677
10849
  let primaryCoinBInputs;
10678
10850
  if (params.fixCoinA && params.fixCoinB) {
10679
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10680
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10851
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10852
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10681
10853
  } else if (params.fixCoinA) {
10682
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10854
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10683
10855
  amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10684
10856
  amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10685
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10857
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true).targetCoin;
10686
10858
  } else if (params.fixCoinB) {
10687
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10859
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10688
10860
  amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10689
10861
  amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10690
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
10862
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true).targetCoin;
10691
10863
  }
10692
10864
  if (params.fixCoinA && params.fixCoinB) {
10693
10865
  } else if (params.fixCoinA) {
@@ -10698,8 +10870,8 @@ var AlmmModule = class {
10698
10870
  const args = [
10699
10871
  tx.object(params.pair),
10700
10872
  tx.object(almmConfig.factory),
10701
- primaryCoinAInputs.targetCoin,
10702
- primaryCoinBInputs.targetCoin,
10873
+ primaryCoinAInputs,
10874
+ primaryCoinBInputs,
10703
10875
  tx.pure.bool(params.fixCoinA),
10704
10876
  tx.pure.u64(params.amountATotal),
10705
10877
  tx.pure.bool(params.fixCoinB),
@@ -10720,72 +10892,15 @@ var AlmmModule = class {
10720
10892
  });
10721
10893
  return tx;
10722
10894
  }
10723
- // // Create a position by percent
10724
- // async mintPercent(params: MintPercentParams): Promise<Transaction> {
10725
- // const tx = new Transaction()
10726
- // tx.setSender(this.sdk.senderAddress)
10727
- // const { almm_pool, integrate } = this.sdk.sdkOptions
10728
- // const almmConfig = getPackagerConfigs(almm_pool)
10729
- // const typeArguments = [params.coinTypeA, params.coinTypeB]
10730
- // const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
10731
- // const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
10732
- // const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
10733
- // const args = [
10734
- // tx.object(params.pair),
10735
- // tx.object(almmConfig.factory),
10736
- // primaryCoinAInputs.targetCoin,
10737
- // primaryCoinBInputs.targetCoin,
10738
- // tx.pure.u64(params.amountATotal),
10739
- // tx.pure.u64(params.amountBTotal),
10740
- // tx.pure.vector('u32', params.storageIds),
10741
- // tx.pure.vector('u64', params.binsAPercent),
10742
- // tx.pure.vector('u64', params.binsBPercent),
10743
- // tx.pure.address(params.to),
10744
- // tx.object(CLOCK_ADDRESS),
10745
- // ]
10746
- // tx.moveCall({
10747
- // target: `${integrate.published_at}::${AlmmScript}::mint_percent`,
10748
- // typeArguments,
10749
- // arguments: args,
10750
- // })
10751
- // return tx
10752
- // }
10753
- // // Create a position by amount
10754
- // async createPositionByAmount(params: MintAmountParams): Promise<Transaction> {
10755
- // const tx = new Transaction()
10756
- // tx.setSender(this.sdk.senderAddress)
10757
- // const { almm_pool, integrate } = this.sdk.sdkOptions
10758
- // const almmConfig = getPackagerConfigs(almm_pool)
10759
- // const typeArguments = [params.coinTypeA, params.coinTypeB]
10760
- // const allCoins = await this._sdk.getOwnerCoinAssets(this._sdk.senderAddress)
10761
- // const primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true)
10762
- // const primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true)
10763
- // const args = [
10764
- // tx.object(params.pair),
10765
- // tx.object(almmConfig.factory),
10766
- // primaryCoinAInputs.targetCoin,
10767
- // primaryCoinBInputs.targetCoin,
10768
- // tx.pure.vector('u32', params.storageIds),
10769
- // tx.pure.vector('u64', params.amountsA),
10770
- // tx.pure.vector('u64', params.amountsB),
10771
- // tx.pure.address(params.to),
10772
- // tx.object(CLOCK_ADDRESS),
10773
- // ]
10774
- // tx.moveCall({
10775
- // target: `${integrate.published_at}::${AlmmScript}::mint_amounts`,
10776
- // typeArguments,
10777
- // arguments: args,
10778
- // })
10779
- // return tx
10780
- // }
10781
- async addLiquidityByStrategy(params) {
10895
+ async addLiquidityByStrategy(params, tx) {
10896
+ tx = tx || new Transaction13();
10782
10897
  if (params.rewards_token.length === 0) {
10783
- return this._raisePositionByAmounts(params);
10898
+ return this._raisePositionByAmounts(params, tx);
10784
10899
  }
10785
- return this._raisePositionByAmountsReward(params);
10900
+ return this._raisePositionByAmountsReward(params, tx);
10786
10901
  }
10787
- async _raisePositionByAmounts(params) {
10788
- const tx = new Transaction12();
10902
+ async _raisePositionByAmounts(params, tx) {
10903
+ tx = tx || new Transaction13();
10789
10904
  const slippage = new Decimal10(params.slippage);
10790
10905
  const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
10791
10906
  const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
@@ -10804,18 +10919,18 @@ var AlmmModule = class {
10804
10919
  let primaryCoinAInputs;
10805
10920
  let primaryCoinBInputs;
10806
10921
  if (params.fixCoinA && params.fixCoinB) {
10807
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10808
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10922
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10923
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10809
10924
  } else if (params.fixCoinA) {
10810
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10925
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10811
10926
  amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10812
10927
  amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10813
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10928
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true).targetCoin;
10814
10929
  } else if (params.fixCoinB) {
10815
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10930
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10816
10931
  amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10817
10932
  amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10818
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
10933
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true).targetCoin;
10819
10934
  }
10820
10935
  if (params.fixCoinA && params.fixCoinB) {
10821
10936
  } else if (params.fixCoinA) {
@@ -10827,8 +10942,8 @@ var AlmmModule = class {
10827
10942
  tx.object(params.pair),
10828
10943
  tx.object(almmConfig.factory),
10829
10944
  tx.object(params.positionId),
10830
- primaryCoinAInputs.targetCoin,
10831
- primaryCoinBInputs.targetCoin,
10945
+ primaryCoinAInputs,
10946
+ primaryCoinBInputs,
10832
10947
  tx.pure.bool(params.fixCoinA),
10833
10948
  tx.pure.u64(params.amountATotal),
10834
10949
  tx.pure.bool(params.fixCoinB),
@@ -10847,8 +10962,8 @@ var AlmmModule = class {
10847
10962
  });
10848
10963
  return tx;
10849
10964
  }
10850
- async _raisePositionByAmountsReward(params) {
10851
- const tx = new Transaction12();
10965
+ async _raisePositionByAmountsReward(params, tx) {
10966
+ tx = tx || new Transaction13();
10852
10967
  const slippage = new Decimal10(params.slippage);
10853
10968
  const lower_slippage = new Decimal10(1).sub(slippage.div(new Decimal10(1e4)));
10854
10969
  const upper_slippage = new Decimal10(1).plus(slippage.div(new Decimal10(1e4)));
@@ -10867,18 +10982,18 @@ var AlmmModule = class {
10867
10982
  let primaryCoinAInputs;
10868
10983
  let primaryCoinBInputs;
10869
10984
  if (params.fixCoinA && params.fixCoinB) {
10870
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10871
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10985
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10986
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10872
10987
  } else if (params.fixCoinA) {
10873
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true);
10988
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountATotal), params.coinTypeA, false, true).targetCoin;
10874
10989
  amount_min = new Decimal10(params.amountBTotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10875
10990
  amount_max = new Decimal10(params.amountBTotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10876
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true);
10991
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeB, false, true).targetCoin;
10877
10992
  } else if (params.fixCoinB) {
10878
- primaryCoinBInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true);
10993
+ primaryCoinBInputs = params.coin_object_id_b ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(params.amountBTotal), params.coinTypeB, false, true).targetCoin;
10879
10994
  amount_min = new Decimal10(params.amountATotal).mul(lower_slippage).toDecimalPlaces(0).toNumber();
10880
10995
  amount_max = new Decimal10(params.amountATotal).mul(upper_slippage).toDecimalPlaces(0).toNumber();
10881
- primaryCoinAInputs = TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true);
10996
+ primaryCoinAInputs = params.coin_object_id_a ?? TransactionUtil.buildCoinForAmount(tx, allCoins, BigInt(amount_max), params.coinTypeA, false, true).targetCoin;
10882
10997
  }
10883
10998
  if (params.fixCoinA && params.fixCoinB) {
10884
10999
  } else if (params.fixCoinA) {
@@ -10891,8 +11006,8 @@ var AlmmModule = class {
10891
11006
  tx.object(almmConfig.factory),
10892
11007
  tx.object(almm_pool.config.rewarder_global_vault),
10893
11008
  tx.object(params.positionId),
10894
- primaryCoinAInputs.targetCoin,
10895
- primaryCoinBInputs.targetCoin,
11009
+ primaryCoinAInputs,
11010
+ primaryCoinBInputs,
10896
11011
  tx.pure.bool(params.fixCoinA),
10897
11012
  tx.pure.u64(params.amountATotal),
10898
11013
  tx.pure.bool(params.fixCoinB),
@@ -10911,8 +11026,8 @@ var AlmmModule = class {
10911
11026
  });
10912
11027
  return tx;
10913
11028
  }
10914
- async burnPosition(params) {
10915
- const tx = new Transaction12();
11029
+ async burnPosition(params, tx) {
11030
+ tx = tx || new Transaction13();
10916
11031
  tx.setSender(this.sdk.senderAddress);
10917
11032
  const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
10918
11033
  const clmmConfigs = getPackagerConfigs(clmm_pool);
@@ -10938,7 +11053,7 @@ var AlmmModule = class {
10938
11053
  return tx;
10939
11054
  }
10940
11055
  async shrinkPosition(params) {
10941
- const tx = new Transaction12();
11056
+ const tx = new Transaction13();
10942
11057
  tx.setSender(this.sdk.senderAddress);
10943
11058
  const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
10944
11059
  const clmmConfigs = getPackagerConfigs(clmm_pool);
@@ -10971,7 +11086,7 @@ var AlmmModule = class {
10971
11086
  return tx;
10972
11087
  }
10973
11088
  async collectFeeAndRewardList(paramsList) {
10974
- let tx = new Transaction12();
11089
+ let tx = new Transaction13();
10975
11090
  for (let index = 0; index < paramsList.length; index++) {
10976
11091
  const params = paramsList[index];
10977
11092
  tx = await this.collectFeeAndReward(params);
@@ -10980,7 +11095,7 @@ var AlmmModule = class {
10980
11095
  }
10981
11096
  async collectFeeAndReward(params, tx) {
10982
11097
  if (!tx) {
10983
- tx = new Transaction12();
11098
+ tx = new Transaction13();
10984
11099
  }
10985
11100
  tx = await this.collectFees(params);
10986
11101
  if (params.rewards_token.length > 0) {
@@ -10989,7 +11104,7 @@ var AlmmModule = class {
10989
11104
  return tx;
10990
11105
  }
10991
11106
  async collectReward(params, transaction) {
10992
- const tx = transaction || new Transaction12();
11107
+ const tx = transaction || new Transaction13();
10993
11108
  tx.setSender(this.sdk.senderAddress);
10994
11109
  const { integrate, clmm_pool, almm_pool } = this.sdk.sdkOptions;
10995
11110
  const clmmConfigs = getPackagerConfigs(clmm_pool);
@@ -11014,7 +11129,7 @@ var AlmmModule = class {
11014
11129
  return tx;
11015
11130
  }
11016
11131
  async collectFees(params, transaction) {
11017
- const tx = transaction || new Transaction12();
11132
+ const tx = transaction || new Transaction13();
11018
11133
  tx.setSender(this.sdk.senderAddress);
11019
11134
  const { integrate, almm_pool } = this.sdk.sdkOptions;
11020
11135
  const almmConfig = getPackagerConfigs(almm_pool);
@@ -11029,7 +11144,7 @@ var AlmmModule = class {
11029
11144
  return tx;
11030
11145
  }
11031
11146
  async createPairAddLiquidity(params) {
11032
- const tx = new Transaction12();
11147
+ const tx = new Transaction13();
11033
11148
  tx.setSender(this.sdk.senderAddress);
11034
11149
  const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
11035
11150
  const { global_config_id } = getPackagerConfigs(clmm_pool);
@@ -11067,7 +11182,7 @@ var AlmmModule = class {
11067
11182
  return tx;
11068
11183
  }
11069
11184
  async swap(params) {
11070
- const tx = new Transaction12();
11185
+ const tx = new Transaction13();
11071
11186
  tx.setSender(this.sdk.senderAddress);
11072
11187
  const { clmm_pool, almm_pool, integrate } = this.sdk.sdkOptions;
11073
11188
  const { global_config_id } = getPackagerConfigs(clmm_pool);
@@ -11110,7 +11225,7 @@ var AlmmModule = class {
11110
11225
  return tx;
11111
11226
  }
11112
11227
  async fetchBins(params) {
11113
- const tx = new Transaction12();
11228
+ const tx = new Transaction13();
11114
11229
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
11115
11230
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11116
11231
  const args = [tx.object(params.pair), tx.pure.u64(params.offset), tx.pure.u64(params.limit)];
@@ -11260,7 +11375,7 @@ var AlmmModule = class {
11260
11375
  for (const item of allPosition) {
11261
11376
  poolMap.add(item.pool);
11262
11377
  }
11263
- const poolList = await this.getPoolInfo(Array.from(poolMap));
11378
+ const poolList = await this.getPoolInfo(Array.from(poolMap), false);
11264
11379
  const _params = [];
11265
11380
  for (const pool of poolList) {
11266
11381
  _params.push({
@@ -11275,7 +11390,7 @@ var AlmmModule = class {
11275
11390
  const positionsFeesRes = [];
11276
11391
  for (const item of allPosition) {
11277
11392
  const pool = poolList.find((pool2) => pool2.pool_id === item.pool);
11278
- const tx = new Transaction12();
11393
+ const tx = new Transaction13();
11279
11394
  this._getPositionLiquidity(
11280
11395
  {
11281
11396
  pair: item.pool,
@@ -11431,14 +11546,14 @@ var AlmmModule = class {
11431
11546
  return out;
11432
11547
  }
11433
11548
  async getPositionsLiquidity(params) {
11434
- let tx = new Transaction12();
11549
+ let tx = new Transaction13();
11435
11550
  for (const param of params) {
11436
11551
  tx = await this._getPositionLiquidity(param, tx);
11437
11552
  }
11438
11553
  return this._parsePositionLiquidity(tx);
11439
11554
  }
11440
11555
  async _getPositionLiquidity(params, tx) {
11441
- tx = tx || new Transaction12();
11556
+ tx = tx || new Transaction13();
11442
11557
  const { integrate } = this.sdk.sdkOptions;
11443
11558
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11444
11559
  const args = [tx.object(params.pair), tx.object(params.positionId)];
@@ -11477,7 +11592,7 @@ var AlmmModule = class {
11477
11592
  return out;
11478
11593
  }
11479
11594
  async getPairLiquidity(params) {
11480
- const tx = new Transaction12();
11595
+ const tx = new Transaction13();
11481
11596
  const { integrate, simulationAccount } = this.sdk.sdkOptions;
11482
11597
  const typeArguments = [params.coinTypeA, params.coinTypeB];
11483
11598
  const args = [tx.object(params.pair)];
@@ -11530,14 +11645,14 @@ var AlmmModule = class {
11530
11645
  return out;
11531
11646
  }
11532
11647
  async getEarnedFees(params) {
11533
- let tx = new Transaction12();
11648
+ let tx = new Transaction13();
11534
11649
  for (const param of params) {
11535
11650
  tx = await this._getEarnedFees(param, tx);
11536
11651
  }
11537
11652
  return this._parseEarnedFees(tx);
11538
11653
  }
11539
11654
  async _getEarnedFees(params, tx) {
11540
- tx = tx || new Transaction12();
11655
+ tx = tx || new Transaction13();
11541
11656
  const { integrate } = this.sdk.sdkOptions;
11542
11657
  const typeArguments = [params.coin_a, params.coin_b];
11543
11658
  const args = [tx.object(params.pool_id), tx.object(params.position_id)];
@@ -11572,7 +11687,7 @@ var AlmmModule = class {
11572
11687
  return out;
11573
11688
  }
11574
11689
  async getEarnedRewards(params) {
11575
- let tx = new Transaction12();
11690
+ let tx = new Transaction13();
11576
11691
  for (const param of params) {
11577
11692
  if (param.rewards_token.length !== 0) {
11578
11693
  tx = await this._getEarnedRewards(param, tx);
@@ -11581,7 +11696,7 @@ var AlmmModule = class {
11581
11696
  return this._parseEarnedRewards(tx);
11582
11697
  }
11583
11698
  async _getEarnedRewards(params, tx) {
11584
- tx = tx || new Transaction12();
11699
+ tx = tx || new Transaction13();
11585
11700
  const { integrate } = this.sdk.sdkOptions;
11586
11701
  const typeArguments = [params.coin_a, params.coin_b, ...params.rewards_token];
11587
11702
  const args = [tx.object(params.pool_id), tx.object(params.position_id), tx.object(CLOCK_ADDRESS)];
@@ -11631,14 +11746,14 @@ var AlmmModule = class {
11631
11746
  }
11632
11747
  // return pool_id => reward_tokens
11633
11748
  async getPairRewarders(params) {
11634
- let tx = new Transaction12();
11749
+ let tx = new Transaction13();
11635
11750
  for (const param of params) {
11636
11751
  tx = await this._getPairRewarders(param, tx);
11637
11752
  }
11638
11753
  return this._parsePairRewarders(tx);
11639
11754
  }
11640
11755
  async _getPairRewarders(params, tx) {
11641
- tx = tx || new Transaction12();
11756
+ tx = tx || new Transaction13();
11642
11757
  const { integrate } = this.sdk.sdkOptions;
11643
11758
  const typeArguments = [params.coin_a, params.coin_b];
11644
11759
  const args = [tx.object(params.pool_id)];
@@ -12243,11 +12358,13 @@ export {
12243
12358
  composeType,
12244
12359
  computeSwap,
12245
12360
  computeSwapStep,
12361
+ convertScientificToDecimal,
12246
12362
  createSplitAmountArray,
12247
12363
  createSplitArray,
12248
12364
  d,
12249
12365
  decimalsMultiplier,
12250
12366
  src_default as default,
12367
+ defaultSwapSlippage,
12251
12368
  estPoolAPR,
12252
12369
  estPositionAPRWithDeltaMethod,
12253
12370
  estPositionAPRWithMultiMethod,