@gmx-io/sdk 2.1.1 → 2.2.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/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +0 -48
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +0 -408
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +0 -90
- package/build/cjs/src/configs/chains.js +9 -1
- package/build/cjs/src/configs/markets.js +0 -42
- package/build/cjs/src/configs/tokens.js +0 -57
- package/build/cjs/src/test/fixtures/arbitrumMarkets.json +0 -45
- package/build/cjs/src/test/fixtures/arbitrumTickers.json +0 -40
- package/build/cjs/src/test/fixtures/arbitrumTokens.json +0 -5
- package/build/cjs/src/utils/__tests__/numbers.spec.js +79 -0
- package/build/cjs/src/utils/errors/transactionsErrors.js +1 -0
- package/build/cjs/src/utils/numbers/index.js +1 -0
- package/build/cjs/src/utils/numbers/parts.js +48 -0
- package/build/cjs/src/utils/numbers/utils.js +67 -26
- package/build/cjs/src/utils/orderTransactions/utils.js +55 -1
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +0 -48
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +0 -408
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +0 -90
- package/build/esm/src/configs/chains.js +7 -0
- package/build/esm/src/configs/markets.js +0 -42
- package/build/esm/src/configs/tokens.js +0 -57
- package/build/esm/src/test/fixtures/arbitrumMarkets.json +0 -45
- package/build/esm/src/test/fixtures/arbitrumTickers.json +0 -40
- package/build/esm/src/test/fixtures/arbitrumTokens.json +0 -5
- package/build/esm/src/utils/__tests__/numbers.spec.js +80 -1
- package/build/esm/src/utils/errors/transactionsErrors.js +1 -0
- package/build/esm/src/utils/numbers/index.js +1 -0
- package/build/esm/src/utils/numbers/parts.js +41 -0
- package/build/esm/src/utils/numbers/utils.js +57 -24
- package/build/esm/src/utils/orderTransactions/utils.js +53 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/src/codegen/prebuilt/index.d.ts +42 -588
- package/build/types/src/configs/chains.d.ts +1 -0
- package/build/types/src/utils/errors/transactionsErrors.d.ts +1 -0
- package/build/types/src/utils/numbers/index.d.ts +1 -0
- package/build/types/src/utils/numbers/parts.d.ts +12 -0
- package/build/types/src/utils/numbers/utils.d.ts +25 -9
- package/build/types/src/utils/orderTransactions/utils.d.ts +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isNumberParts = exports.joinNumberParts = exports.numberParts = exports.multiplierPart = exports.USD_PART = exports.USD_SYMBOL = void 0;
|
|
4
|
+
exports.USD_SYMBOL = "$ ";
|
|
5
|
+
exports.USD_PART = { kind: "currency", text: exports.USD_SYMBOL };
|
|
6
|
+
function multiplierPart(text) {
|
|
7
|
+
return { kind: "multiplier", text };
|
|
8
|
+
}
|
|
9
|
+
exports.multiplierPart = multiplierPart;
|
|
10
|
+
function numberParts(...inputs) {
|
|
11
|
+
const parts = [];
|
|
12
|
+
const push = (part) => {
|
|
13
|
+
if (!part.text) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const last = parts[parts.length - 1];
|
|
17
|
+
if (part.kind === "text" && last?.kind === "text") {
|
|
18
|
+
parts[parts.length - 1] = { kind: "text", text: last.text + part.text };
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
parts.push(part);
|
|
22
|
+
};
|
|
23
|
+
for (const input of inputs) {
|
|
24
|
+
if (input === undefined) {
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (typeof input === "string") {
|
|
28
|
+
push({ kind: "text", text: input });
|
|
29
|
+
}
|
|
30
|
+
else if (Array.isArray(input)) {
|
|
31
|
+
input.forEach(push);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
push(input);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return parts;
|
|
38
|
+
}
|
|
39
|
+
exports.numberParts = numberParts;
|
|
40
|
+
function joinNumberParts(parts) {
|
|
41
|
+
return parts.map((part) => part.text).join("");
|
|
42
|
+
}
|
|
43
|
+
exports.joinNumberParts = joinNumberParts;
|
|
44
|
+
function isNumberParts(value) {
|
|
45
|
+
return (Array.isArray(value) &&
|
|
46
|
+
value.every((item) => typeof item === "object" && item !== null && "kind" in item && "text" in item && typeof item.text === "string"));
|
|
47
|
+
}
|
|
48
|
+
exports.isNumberParts = isNumberParts;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = void 0;
|
|
3
|
+
exports.formatAmountHumanParts = exports.formatNumberHuman = exports.formatNumberHumanParts = exports.formatPercentageDisplay = exports.formatUsdPrice = exports.formatUsdPriceParts = exports.formatRatePercentage = exports.formatTokenAmountWithUsd = exports.formatTokenAmountWithUsdParts = exports.formatTokenAmount = exports.formatPercentage = exports.formatDeltaUsd = exports.formatDeltaUsdParts = exports.formatBigUsd = exports.formatBigUsdParts = exports.formatUsd = exports.formatUsdParts = exports.adjustForDecimals = exports.bigintToNumber = exports.trimZeroDecimals = exports.numberToBigint = exports.applyFactor = exports.roundsToZero = exports.roundUpMagnitudeDivision = exports.formatPriceImpactBps = exports.formatBasisPoints = exports.getBasisPoints = exports.basisPointsToFloat = exports.toBigInt = exports.expandDecimals = exports.safeDivide = exports.isNonZero = exports.TRIGGER_PREFIX_BELOW = exports.TRIGGER_PREFIX_ABOVE = exports.PERCENT_PRECISION_DECIMALS = exports.isUint256 = exports.parseUint256DecimalString = exports.MaxInt256 = exports.MaxUint256 = exports.BN_NEGATIVE_ONE = exports.BN_ONE = exports.BN_ZERO = exports.FLOAT_PRECISION_SQRT = exports.FLOAT_PRECISION_SQRT_DECIMALS = exports.PRECISION = exports.PRECISION_DECIMALS = exports.BASIS_POINTS_DECIMALS = exports.BASIS_POINTS_DIVISOR_BIGINT = exports.BASIS_POINTS_DIVISOR = exports.USD_DECIMALS = void 0;
|
|
4
|
+
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.numberWithCommasParts = exports.formatFactor = exports.formatBalanceAmount = exports.formatAmountHuman = void 0;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const bigmath_1 = require("../bigmath");
|
|
7
|
+
const parts_1 = require("./parts");
|
|
7
8
|
exports.USD_DECIMALS = 30;
|
|
8
9
|
exports.BASIS_POINTS_DIVISOR = 10000;
|
|
9
10
|
exports.BASIS_POINTS_DIVISOR_BIGINT = 10000n;
|
|
@@ -175,7 +176,7 @@ function adjustForDecimals(amount, divDecimals, mulDecimals) {
|
|
|
175
176
|
return (amount * expandDecimals(1, mulDecimals)) / expandDecimals(1, divDecimals);
|
|
176
177
|
}
|
|
177
178
|
exports.adjustForDecimals = adjustForDecimals;
|
|
178
|
-
function
|
|
179
|
+
function formatUsdParts(usd, opts = {}) {
|
|
179
180
|
const { fallbackToZero = false, displayDecimals = 2 } = opts;
|
|
180
181
|
if (typeof usd !== "bigint") {
|
|
181
182
|
if (fallbackToZero) {
|
|
@@ -201,17 +202,29 @@ function formatUsd(usd, opts = {}) {
|
|
|
201
202
|
const sign = usd < 0n ? "-" : maybePlus;
|
|
202
203
|
const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol}\u00a0` : "";
|
|
203
204
|
const displayUsd = (0, exports.formatAmount)(exceedingInfo.value, exports.USD_DECIMALS, displayDecimals, true);
|
|
204
|
-
return
|
|
205
|
+
return (0, parts_1.numberParts)(symbol, sign, parts_1.USD_PART, displayUsd);
|
|
206
|
+
}
|
|
207
|
+
exports.formatUsdParts = formatUsdParts;
|
|
208
|
+
function formatUsd(usd, opts = {}) {
|
|
209
|
+
const parts = formatUsdParts(usd, opts);
|
|
210
|
+
return parts && (0, parts_1.joinNumberParts)(parts);
|
|
205
211
|
}
|
|
206
212
|
exports.formatUsd = formatUsd;
|
|
213
|
+
function formatBigUsdParts(amount, opts = {}) {
|
|
214
|
+
return formatUsdParts(amount, {
|
|
215
|
+
maxThreshold: "9999999999999999999999999",
|
|
216
|
+
displayDecimals: opts.displayDecimals ?? 0,
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
exports.formatBigUsdParts = formatBigUsdParts;
|
|
207
220
|
function formatBigUsd(amount, opts = {}) {
|
|
208
|
-
return
|
|
221
|
+
return (0, parts_1.joinNumberParts)(formatBigUsdParts(amount, opts));
|
|
209
222
|
}
|
|
210
223
|
exports.formatBigUsd = formatBigUsd;
|
|
211
|
-
function
|
|
224
|
+
function formatDeltaUsdParts(deltaUsd, percentage, opts = {}) {
|
|
212
225
|
if (typeof deltaUsd !== "bigint") {
|
|
213
226
|
if (opts.fallbackToZero) {
|
|
214
|
-
return
|
|
227
|
+
return (0, parts_1.numberParts)(formatUsdParts(0n), ` (${(0, exports.formatAmount)(0n, 2, 2)}%)`);
|
|
215
228
|
}
|
|
216
229
|
return undefined;
|
|
217
230
|
}
|
|
@@ -220,7 +233,12 @@ function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
|
220
233
|
const percentageStr = percentage !== undefined && !opts.hidePercentage ? ` (${sign}${formatPercentage(bigmath_1.bigMath.abs(percentage))})` : "";
|
|
221
234
|
const deltaUsdStr = (0, exports.formatAmount)(exceedingInfo.value, exports.USD_DECIMALS, 2, true);
|
|
222
235
|
const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol} ` : "";
|
|
223
|
-
return
|
|
236
|
+
return (0, parts_1.numberParts)(symbol, sign, parts_1.USD_PART, deltaUsdStr, percentageStr);
|
|
237
|
+
}
|
|
238
|
+
exports.formatDeltaUsdParts = formatDeltaUsdParts;
|
|
239
|
+
function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
240
|
+
const parts = formatDeltaUsdParts(deltaUsd, percentage, opts);
|
|
241
|
+
return parts && (0, parts_1.joinNumberParts)(parts);
|
|
224
242
|
}
|
|
225
243
|
exports.formatDeltaUsd = formatDeltaUsd;
|
|
226
244
|
function formatPercentage(percentage, opts = {}) {
|
|
@@ -272,7 +290,7 @@ function formatTokenAmount(amount, tokenDecimals, symbol, opts = {}) {
|
|
|
272
290
|
return `${amountStr}${symbolStr}`;
|
|
273
291
|
}
|
|
274
292
|
exports.formatTokenAmount = formatTokenAmount;
|
|
275
|
-
function
|
|
293
|
+
function formatTokenAmountWithUsdParts(tokenAmount, usdAmount, tokenSymbol, tokenDecimals, opts = {}) {
|
|
276
294
|
if (typeof tokenAmount !== "bigint" || typeof usdAmount !== "bigint" || !tokenSymbol || !tokenDecimals) {
|
|
277
295
|
if (!opts.fallbackToZero) {
|
|
278
296
|
return undefined;
|
|
@@ -283,11 +301,16 @@ function formatTokenAmountWithUsd(tokenAmount, usdAmount, tokenSymbol, tokenDeci
|
|
|
283
301
|
useCommas: true,
|
|
284
302
|
displayPlus: opts.displayPlus,
|
|
285
303
|
});
|
|
286
|
-
const
|
|
304
|
+
const usdParts = formatUsdParts(usdAmount, {
|
|
287
305
|
fallbackToZero: opts.fallbackToZero,
|
|
288
306
|
displayPlus: opts.displayPlus,
|
|
289
307
|
});
|
|
290
|
-
return `${tokenStr} (
|
|
308
|
+
return (0, parts_1.numberParts)(`${tokenStr} (`, usdParts, ")");
|
|
309
|
+
}
|
|
310
|
+
exports.formatTokenAmountWithUsdParts = formatTokenAmountWithUsdParts;
|
|
311
|
+
function formatTokenAmountWithUsd(tokenAmount, usdAmount, tokenSymbol, tokenDecimals, opts = {}) {
|
|
312
|
+
const parts = formatTokenAmountWithUsdParts(tokenAmount, usdAmount, tokenSymbol, tokenDecimals, opts);
|
|
313
|
+
return parts && (0, parts_1.joinNumberParts)(parts);
|
|
291
314
|
}
|
|
292
315
|
exports.formatTokenAmountWithUsd = formatTokenAmountWithUsd;
|
|
293
316
|
/**
|
|
@@ -304,19 +327,24 @@ function formatRatePercentage(rate, opts) {
|
|
|
304
327
|
return `${plurOrMinus}\u200a${(0, exports.formatAmount)(amount, 30, opts?.displayDecimals ?? 4)}%`;
|
|
305
328
|
}
|
|
306
329
|
exports.formatRatePercentage = formatRatePercentage;
|
|
307
|
-
function
|
|
330
|
+
function formatUsdPriceParts(price, opts = {}) {
|
|
308
331
|
if (price === undefined) {
|
|
309
332
|
return;
|
|
310
333
|
}
|
|
311
334
|
if (price < 0n) {
|
|
312
|
-
return "NA";
|
|
335
|
+
return (0, parts_1.numberParts)("NA");
|
|
313
336
|
}
|
|
314
337
|
const decimals = calculateDisplayDecimals(price, undefined, opts.visualMultiplier);
|
|
315
|
-
return
|
|
338
|
+
return formatUsdParts(price, {
|
|
316
339
|
...opts,
|
|
317
340
|
displayDecimals: decimals,
|
|
318
341
|
});
|
|
319
342
|
}
|
|
343
|
+
exports.formatUsdPriceParts = formatUsdPriceParts;
|
|
344
|
+
function formatUsdPrice(price, opts = {}) {
|
|
345
|
+
const parts = formatUsdPriceParts(price, opts);
|
|
346
|
+
return parts && (0, parts_1.joinNumberParts)(parts);
|
|
347
|
+
}
|
|
320
348
|
exports.formatUsdPrice = formatUsdPrice;
|
|
321
349
|
function formatPercentageDisplay(percentage, hideThreshold) {
|
|
322
350
|
if (hideThreshold && percentage < hideThreshold) {
|
|
@@ -325,33 +353,42 @@ function formatPercentageDisplay(percentage, hideThreshold) {
|
|
|
325
353
|
return `${percentage}%`;
|
|
326
354
|
}
|
|
327
355
|
exports.formatPercentageDisplay = formatPercentageDisplay;
|
|
328
|
-
function
|
|
356
|
+
function formatNumberHumanParts(n, showDollar = false, displayDecimals = 1) {
|
|
329
357
|
// For large numbers, we can neglect the decimals to avoid decimals in cases like 9999999.99999
|
|
330
358
|
if (n >= 1000000) {
|
|
331
359
|
n = Math.round(n);
|
|
332
360
|
}
|
|
333
361
|
const isNegative = n < 0;
|
|
334
362
|
const absN = Math.abs(n);
|
|
335
|
-
const sign =
|
|
363
|
+
const sign = isNegative ? "-" : "";
|
|
364
|
+
const currency = showDollar ? parts_1.USD_PART : undefined;
|
|
336
365
|
// Promote the suffix when the displayed value rounds to 1000 in the smaller unit.
|
|
337
366
|
if (Number((absN / 1000000).toFixed(displayDecimals)) >= 1000) {
|
|
338
|
-
return
|
|
367
|
+
return (0, parts_1.numberParts)(sign, currency, `${(absN / 1000000000).toFixed(displayDecimals)}b`);
|
|
339
368
|
}
|
|
340
369
|
if (Number((absN / 1000).toFixed(displayDecimals)) >= 1000) {
|
|
341
|
-
return
|
|
370
|
+
return (0, parts_1.numberParts)(sign, currency, `${(absN / 1000000).toFixed(displayDecimals)}m`);
|
|
342
371
|
}
|
|
343
372
|
if (Number(absN.toFixed(displayDecimals)) >= 1000) {
|
|
344
|
-
return
|
|
373
|
+
return (0, parts_1.numberParts)(sign, currency, `${(absN / 1000).toFixed(displayDecimals)}k`);
|
|
345
374
|
}
|
|
346
|
-
return
|
|
375
|
+
return (0, parts_1.numberParts)(sign, currency, absN.toFixed(displayDecimals));
|
|
376
|
+
}
|
|
377
|
+
exports.formatNumberHumanParts = formatNumberHumanParts;
|
|
378
|
+
function formatNumberHuman(n, showDollar = false, displayDecimals = 1) {
|
|
379
|
+
return (0, parts_1.joinNumberParts)(formatNumberHumanParts(n, showDollar, displayDecimals));
|
|
347
380
|
}
|
|
348
381
|
exports.formatNumberHuman = formatNumberHuman;
|
|
349
|
-
function
|
|
382
|
+
function formatAmountHumanParts(amount, tokenDecimals, showDollar = false, displayDecimals = 1) {
|
|
350
383
|
if (amount === undefined) {
|
|
351
|
-
return "...";
|
|
384
|
+
return (0, parts_1.numberParts)("...");
|
|
352
385
|
}
|
|
353
386
|
let n = Number((0, exports.formatAmount)(amount, tokenDecimals));
|
|
354
|
-
return
|
|
387
|
+
return formatNumberHumanParts(n, showDollar, displayDecimals);
|
|
388
|
+
}
|
|
389
|
+
exports.formatAmountHumanParts = formatAmountHumanParts;
|
|
390
|
+
function formatAmountHuman(amount, tokenDecimals, showDollar = false, displayDecimals = 1) {
|
|
391
|
+
return (0, parts_1.joinNumberParts)(formatAmountHumanParts(amount, tokenDecimals, showDollar, displayDecimals));
|
|
355
392
|
}
|
|
356
393
|
exports.formatAmountHuman = formatAmountHuman;
|
|
357
394
|
function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZero = false, toExponential = true, isStable = false, signed = false, } = {}) {
|
|
@@ -410,13 +447,17 @@ function formatFactor(factor) {
|
|
|
410
447
|
return (0, exports.formatAmount)(factor, exports.PRECISION_DECIMALS, factorDecimals);
|
|
411
448
|
}
|
|
412
449
|
exports.formatFactor = formatFactor;
|
|
413
|
-
function
|
|
450
|
+
function numberWithCommasParts(x, { showDollar = false } = {}) {
|
|
414
451
|
if (x === undefined || x === null) {
|
|
415
|
-
return "...";
|
|
452
|
+
return (0, parts_1.numberParts)("...");
|
|
416
453
|
}
|
|
417
454
|
const parts = x.toString().split(".");
|
|
418
455
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
419
|
-
return
|
|
456
|
+
return (0, parts_1.numberParts)(showDollar ? parts_1.USD_PART : undefined, parts.join("."));
|
|
457
|
+
}
|
|
458
|
+
exports.numberWithCommasParts = numberWithCommasParts;
|
|
459
|
+
function numberWithCommas(x, opts = {}) {
|
|
460
|
+
return (0, parts_1.joinNumberParts)(numberWithCommasParts(x, opts));
|
|
420
461
|
}
|
|
421
462
|
exports.numberWithCommas = numberWithCommas;
|
|
422
463
|
const formatAmount = (amount, tokenDecimals, displayDecimals, useCommas, defaultValue, visualMultiplier) => {
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getIsInvalidBatchReceiver = exports.getBatchIsNativePayment = exports.getIsEmptyBatch = exports.getBatchSwapsCount = exports.getBatchRequiredActions = exports.encodeExchangeRouterMulticall = exports.buildCancelOrderMulticall = exports.buildUpdateOrderMulticall = exports.buildCreateOrderMulticall = exports.getBatchOrderMulticallPayload = exports.getExternalCallsPayload = exports.getEmptyExternalCallsPayload = exports.combineExternalCalls = exports.getBatchExternalCalls = exports.buildTokenTransfersParamsForIncreaseOrSwap = exports.buildTokenTransfersParamsForDecrease = exports.getBatchExternalSwapGasLimit = exports.getBatchTotalPayCollateralAmount = exports.getBatchTotalExecutionFee = exports.buildUpdateOrderPayload = exports.getIsTwapOrderPayload = exports.buildTwapOrdersPayloads = exports.buildDecreaseOrderPayload = exports.buildIncreaseOrderPayload = exports.buildSwapOrderPayload = void 0;
|
|
6
|
+
exports.getIsInvalidBatchReceiver = exports.getBatchIsNativePayment = exports.getIsEmptyBatch = exports.getBatchSwapsCount = exports.getBatchRequiredActions = exports.encodeExchangeRouterMulticall = exports.buildCancelOrderMulticall = exports.buildUpdateOrderMulticall = exports.buildCreateOrderMulticall = exports.getBatchOrderMulticallPayload = exports.getExternalCallsPayload = exports.getEmptyExternalCallsPayload = exports.combineExternalCalls = exports.getBatchExternalCalls = exports.buildTokenTransfersParamsForIncreaseOrSwap = exports.buildTokenTransfersParamsForDecrease = exports.getBatchExternalSwapGasLimit = exports.getBatchTotalPayCollateralAmount = exports.getExpressBatchOrderParams = exports.getBatchExecutionFeeEstimates = exports.getBatchTotalExecutionFee = exports.buildUpdateOrderPayload = exports.getIsTwapOrderPayload = exports.buildTwapOrdersPayloads = exports.buildDecreaseOrderPayload = exports.buildIncreaseOrderPayload = exports.buildSwapOrderPayload = void 0;
|
|
7
7
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
9
|
const ExchangeRouter_1 = __importDefault(require("../../abis/ExchangeRouter"));
|
|
@@ -12,6 +12,7 @@ const Token_1 = __importDefault(require("../../abis/Token"));
|
|
|
12
12
|
const chains_1 = require("../../configs/chains");
|
|
13
13
|
const contracts_1 = require("../../configs/contracts");
|
|
14
14
|
const tokens_1 = require("../../configs/tokens");
|
|
15
|
+
const bigmath_1 = require("../bigmath");
|
|
15
16
|
const numbers_1 = require("../numbers");
|
|
16
17
|
const objects_1 = require("../objects");
|
|
17
18
|
const orders_1 = require("../orders");
|
|
@@ -328,6 +329,59 @@ function getBatchTotalExecutionFee({ batchParams, tokensData, chainId, allowEmpt
|
|
|
328
329
|
};
|
|
329
330
|
}
|
|
330
331
|
exports.getBatchTotalExecutionFee = getBatchTotalExecutionFee;
|
|
332
|
+
function getBatchExecutionFeeEstimates(batchParams) {
|
|
333
|
+
return batchParams.createOrderParams.map((co) => ({
|
|
334
|
+
executionFee: co.orderPayload.numbers.executionFee,
|
|
335
|
+
gasLimit: co.params.executionGasLimit,
|
|
336
|
+
}));
|
|
337
|
+
}
|
|
338
|
+
exports.getBatchExecutionFeeEstimates = getBatchExecutionFeeEstimates;
|
|
339
|
+
// Expects wallet-priced params: apply once, right before estimating or signing for the relay
|
|
340
|
+
function getExpressBatchOrderParams(chainId, batchParams) {
|
|
341
|
+
const allowance = (0, chains_1.getExecutionFeePriorityFeeAllowance)(chainId);
|
|
342
|
+
if (allowance === 0n) {
|
|
343
|
+
return batchParams;
|
|
344
|
+
}
|
|
345
|
+
const orderVaultAddress = (0, contracts_1.getContract)(chainId, "OrderVault");
|
|
346
|
+
return {
|
|
347
|
+
...batchParams,
|
|
348
|
+
updateOrderParams: batchParams.updateOrderParams.map((uo) => {
|
|
349
|
+
const delta = bigmath_1.bigMath.min(allowance * (uo.params.executionGasLimit ?? 0n), uo.updatePayload.executionFeeTopUp);
|
|
350
|
+
if (delta === 0n) {
|
|
351
|
+
return uo;
|
|
352
|
+
}
|
|
353
|
+
return {
|
|
354
|
+
...uo,
|
|
355
|
+
params: { ...uo.params, executionFeeTopUp: uo.params.executionFeeTopUp - delta },
|
|
356
|
+
updatePayload: { ...uo.updatePayload, executionFeeTopUp: uo.updatePayload.executionFeeTopUp - delta },
|
|
357
|
+
};
|
|
358
|
+
}),
|
|
359
|
+
createOrderParams: batchParams.createOrderParams.map((co) => {
|
|
360
|
+
const delta = bigmath_1.bigMath.min(allowance * co.params.executionGasLimit, co.orderPayload.numbers.executionFee);
|
|
361
|
+
if (delta === 0n) {
|
|
362
|
+
return co;
|
|
363
|
+
}
|
|
364
|
+
return {
|
|
365
|
+
...co,
|
|
366
|
+
params: { ...co.params, executionFeeAmount: co.params.executionFeeAmount - delta },
|
|
367
|
+
orderPayload: {
|
|
368
|
+
...co.orderPayload,
|
|
369
|
+
numbers: { ...co.orderPayload.numbers, executionFee: co.orderPayload.numbers.executionFee - delta },
|
|
370
|
+
},
|
|
371
|
+
tokenTransfersParams: co.tokenTransfersParams
|
|
372
|
+
? {
|
|
373
|
+
...co.tokenTransfersParams,
|
|
374
|
+
value: co.tokenTransfersParams.value - delta,
|
|
375
|
+
tokenTransfers: co.tokenTransfersParams.tokenTransfers.map((transfer) => transfer.tokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS && transfer.destination === orderVaultAddress
|
|
376
|
+
? { ...transfer, amount: transfer.amount - delta }
|
|
377
|
+
: transfer),
|
|
378
|
+
}
|
|
379
|
+
: co.tokenTransfersParams,
|
|
380
|
+
};
|
|
381
|
+
}),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
exports.getExpressBatchOrderParams = getExpressBatchOrderParams;
|
|
331
385
|
function getBatchTotalPayCollateralAmount(batchParams) {
|
|
332
386
|
const payAmounts = {};
|
|
333
387
|
for (const co of batchParams.createOrderParams) {
|
|
@@ -282,14 +282,6 @@
|
|
|
282
282
|
"aboveOptimalUsageBorrowingFactorLong": "0xd7e6ebc67d8a1efac7d3bdb3de25751ed70ca8d24396fa72bf394e1bfdf9d61d",
|
|
283
283
|
"aboveOptimalUsageBorrowingFactorShort": "0xb2b835d37acd5ec71cd8204137bde17eba583baf15e4c3427b11d04301847f89"
|
|
284
284
|
},
|
|
285
|
-
"0x8ea4Fb801493DaD8724F90Fb2e279534fa591366": {
|
|
286
|
-
"optimalUsageFactorLong": "0xf2803b94b8853f3aa5b152198b80419c1ce4d2f2718da8bf0d5529968388075e",
|
|
287
|
-
"optimalUsageFactorShort": "0x6d27cd6bfb659b84fcfaff740ecb0c0ecdf629d66e27e0e0e1596f013597ddf5",
|
|
288
|
-
"baseBorrowingFactorLong": "0xb8fd82ba634da57a851dfa6016f470370fdb5969477a455cbe66d0d4b696d4ea",
|
|
289
|
-
"baseBorrowingFactorShort": "0xabe589596666a3fefc9a90c0d33a6c03f313c6a0b7200711c7f46464aeb0a652",
|
|
290
|
-
"aboveOptimalUsageBorrowingFactorLong": "0xd9deb27462a35266851c84848218affb6db31b6d46732e0877aa5543c5c66f0b",
|
|
291
|
-
"aboveOptimalUsageBorrowingFactorShort": "0x898133354b4736630cebac61f4dd922f240a8f0f4235b8d9faf8bedfc239e919"
|
|
292
|
-
},
|
|
293
285
|
"0xD0a1AFDDE31Eb51e8b53bdCE989EB8C2404828a4": {
|
|
294
286
|
"optimalUsageFactorLong": "0x79837f3b2010f2a070a4e4461159c803c9da9d19cd9ec06ecb975580e550fd31",
|
|
295
287
|
"optimalUsageFactorShort": "0x8044d373dc026daa0543e32c47c7598de5354e407641eaa50f42d04e35611ecc",
|
|
@@ -394,14 +386,6 @@
|
|
|
394
386
|
"aboveOptimalUsageBorrowingFactorLong": "0xb475539acd5162224a3444af5ed246ef1c5f1781f0198e64c95b37cc4450657c",
|
|
395
387
|
"aboveOptimalUsageBorrowingFactorShort": "0x426620bfe0cf820a058a0ad05777b46059bb1efc4b2a701ae95e3c5870ae8998"
|
|
396
388
|
},
|
|
397
|
-
"0x71237F8C3d1484495A136022E16840b70fF84a69": {
|
|
398
|
-
"optimalUsageFactorLong": "0xe78d90436e4f45557db2590938ae3427582bf3a318e2651e12f3dd213a352034",
|
|
399
|
-
"optimalUsageFactorShort": "0xfbc253dd98f105b62bf0c5849cf609d18cc13d612eea7279ed487a25b58a4755",
|
|
400
|
-
"baseBorrowingFactorLong": "0x069e2770f165efc344965bb98a763bc21a17400dba57862e82f7503b6b380bcd",
|
|
401
|
-
"baseBorrowingFactorShort": "0x9cc3615eb65b850dde0b0e3781a05a1f9d85603c01711bc222ddc6180371c1ba",
|
|
402
|
-
"aboveOptimalUsageBorrowingFactorLong": "0x4a8ee117b6672c37927123502ce297de2635aa41c65abe3d3478309ecf34356f",
|
|
403
|
-
"aboveOptimalUsageBorrowingFactorShort": "0x5330b7b1cdcb45be564a288bb155e768d2cb1692db038f1ea490066b4eca7f00"
|
|
404
|
-
},
|
|
405
389
|
"0xfD46a5702D4d97cE0164375744c65F0c31A3901b": {
|
|
406
390
|
"optimalUsageFactorLong": "0x69bcb16a411df2667d192a9dbdce7e83dca9e4ad0f5aee7470c52e4b1f2a85b2",
|
|
407
391
|
"optimalUsageFactorShort": "0x3d9046829f2508278155fb182e2ec3abd41645cd9a1aa316da9632c94059495c",
|
|
@@ -410,22 +394,6 @@
|
|
|
410
394
|
"aboveOptimalUsageBorrowingFactorLong": "0xc527d93e9d44fb570d38404f23058cae3075da4f1a8efbd78dbf36605a3800fa",
|
|
411
395
|
"aboveOptimalUsageBorrowingFactorShort": "0x515d88908e8665dd2b428afe6651d772fa316a392f1d400aba6f5fd41566120b"
|
|
412
396
|
},
|
|
413
|
-
"0x6CB901Cc64c024C3Fe4404c940FF9a3Acc229D2C": {
|
|
414
|
-
"optimalUsageFactorLong": "0x1e5bb6dba07fa3ceb8c5c8daae37f216dcd2448ad5a9b4002e7db744ddffdd0b",
|
|
415
|
-
"optimalUsageFactorShort": "0xc8c365c4745d2f8c71a2e05508187d91087d20ca11d91b1567f45eb3b95212fe",
|
|
416
|
-
"baseBorrowingFactorLong": "0x9cae983ed9f771f1f0e3fdd2178dcfa196aa5d91279694d9084094aa4d080361",
|
|
417
|
-
"baseBorrowingFactorShort": "0x2c8a24ea5f7901a52cae791a67525e85c9b039734ed502d4ab2480438cd4749b",
|
|
418
|
-
"aboveOptimalUsageBorrowingFactorLong": "0xbca34723d022fa40f2810a0fd97d01ab7cf91b5ccd73daf3a58201e8a63024c8",
|
|
419
|
-
"aboveOptimalUsageBorrowingFactorShort": "0xcaad63fb8495d0c171ae4f1f51f20c608b50e4f02e0dcb309ad23e0514f006b8"
|
|
420
|
-
},
|
|
421
|
-
"0x71B7fF592a974e2B501D8A7a11f5c42DcD365244": {
|
|
422
|
-
"optimalUsageFactorLong": "0x4df2fd67550df5878f250dc3dfc57b4dfd817ab08161308a6ace735707dc5bc9",
|
|
423
|
-
"optimalUsageFactorShort": "0x744d75016b4e200d7f96d21778a4600dfd84ee5e9b1949a286d94946e0aab22c",
|
|
424
|
-
"baseBorrowingFactorLong": "0xd6fb0ee5064962ff9215cb492b64147df4ff1f6adf9faa5c60119c7fbec47eb3",
|
|
425
|
-
"baseBorrowingFactorShort": "0x65fe5393c061ab7d27cd72701d489da67744c1b55b7c7fe16cab085261ab0448",
|
|
426
|
-
"aboveOptimalUsageBorrowingFactorLong": "0xa9295d2e694a5b5d50e29c04beefdb81d63ab8943ebce56438e55885a49ac1f8",
|
|
427
|
-
"aboveOptimalUsageBorrowingFactorShort": "0x159e758331eb4a112ef150765d702c60888bbe1dbac094baf4b90a0bd5f6f69b"
|
|
428
|
-
},
|
|
429
397
|
"0xbD48149673724f9cAeE647bb4e9D9dDaF896Efeb": {
|
|
430
398
|
"optimalUsageFactorLong": "0x71f1ef34bafaf3150e1fdf5e6b1e8d31832eaa5d88f9f108a4503e5a5e41588b",
|
|
431
399
|
"optimalUsageFactorShort": "0xa4f72902a52e390bc8ceccf65289e6dfffcea902f35e4fc669475113c3e45546",
|
|
@@ -778,14 +746,6 @@
|
|
|
778
746
|
"aboveOptimalUsageBorrowingFactorLong": "0x91551ab540048fa5892c9ea76f705ce83d782d9adc2fbbc3dbc0704f24d45136",
|
|
779
747
|
"aboveOptimalUsageBorrowingFactorShort": "0x39ae0e51cbb91af2399430ab64e4690dcd3c6a5693c849ea0a4b3a42b87617dd"
|
|
780
748
|
},
|
|
781
|
-
"0x6EeE8098dBC106aEde99763FA5F955A5bBc42C50": {
|
|
782
|
-
"optimalUsageFactorLong": "0xc5d3ef57932d40b9ef196a4a57eeae3c1027a32ef7b6a34cf166069979fe4213",
|
|
783
|
-
"optimalUsageFactorShort": "0x42f11677ada1c42fa727a2ea741dbb6f5b666389aa17ca02adac73c44d3d9a2f",
|
|
784
|
-
"baseBorrowingFactorLong": "0x1778bc0fad1c076dc361d0f5202dd46515c98bc5436b8a59504340dd36793b21",
|
|
785
|
-
"baseBorrowingFactorShort": "0x806893df271d661e281f8bc7fcc8f76b34873d4d2dbd5c744e172825170f2cf7",
|
|
786
|
-
"aboveOptimalUsageBorrowingFactorLong": "0x030d1ce870a32ceba468c3ad1799ba63042f03a68006edf75a9d57e11222edfb",
|
|
787
|
-
"aboveOptimalUsageBorrowingFactorShort": "0xecf06f84c969631a27bfd2ffef485a24b8ebfd9b96e5012177fd4e90c6404403"
|
|
788
|
-
},
|
|
789
749
|
"0xb3588455858a49D3244237CEe00880CcB84b91Dd": {
|
|
790
750
|
"optimalUsageFactorLong": "0x94c4aa621db98cbda9d6162bb79826bbf4b96cd285eb90464ec1785e169674cb",
|
|
791
751
|
"optimalUsageFactorShort": "0x80cf5d6b6ee1b3fd0397a7ee9dc2ebbafdf1ac30da22a880755edd7ebd8ec9d5",
|
|
@@ -1326,14 +1286,6 @@
|
|
|
1326
1286
|
"aboveOptimalUsageBorrowingFactorLong": "0x385cfbaddf7c612dc705c771a6e5b624ee4864e7136c2ea934422fa1db893563",
|
|
1327
1287
|
"aboveOptimalUsageBorrowingFactorShort": "0x57605e0c3285622481bd93af6fef15b512c931b5db53b9a072c8d86dd6621c6a"
|
|
1328
1288
|
},
|
|
1329
|
-
"0xe19da27Bf9733c429445E289B662bECDCa6ce10b": {
|
|
1330
|
-
"optimalUsageFactorLong": "0xd1ab5e55b2308a1fc00f0a4dcfa2bec105ae69918cf2032de077717e35624e27",
|
|
1331
|
-
"optimalUsageFactorShort": "0xdf7b1d9202e4bb2e7abb6a573cc70593772b89fa9a7e9bad4e139938666044a9",
|
|
1332
|
-
"baseBorrowingFactorLong": "0x3241b54354e87d5ae06a41e4aeaa6a34115dadf063d9621f814b2e11099307c8",
|
|
1333
|
-
"baseBorrowingFactorShort": "0x3755d19ffde034f5b43c13d0b7904191836ca26a80930493bba489db125153f9",
|
|
1334
|
-
"aboveOptimalUsageBorrowingFactorLong": "0x80a3a0af00d7c7d55e7bfffde6bc8ea69b652dafd94d7ebe4f20b2a4cdb7537b",
|
|
1335
|
-
"aboveOptimalUsageBorrowingFactorShort": "0xe08a60ae243116c5d4e8f5c2df48367eb2edac52889485b82e216877ffb4ff34"
|
|
1336
|
-
},
|
|
1337
1289
|
"0x94cE6F65188a92F297C7f0A5A7B3cAd9013450F8": {
|
|
1338
1290
|
"optimalUsageFactorLong": "0xdad8117f7fee5bcf38f4a80a250f295a804aacddbe6d0aa0f54ed0505ee815f8",
|
|
1339
1291
|
"optimalUsageFactorShort": "0xf6cdc9a2c99dfe219352a58f2333c48cc3b3c26c6dea227e6ff149fb94577358",
|