@gmx-io/sdk 1.2.1 → 1.3.1
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/abis/ClaimHandler.json +1 -16
- package/build/cjs/src/abis/CustomErrors.json +642 -61
- package/build/cjs/src/abis/DataStore.json +25 -6
- package/build/cjs/src/abis/EventEmitter.json +1 -6
- package/build/cjs/src/abis/ExchangeRouter.json +195 -290
- package/build/cjs/src/abis/GelatoRelayRouter.json +251 -98
- package/build/cjs/src/abis/GlvReader.json +60 -3
- package/build/cjs/src/abis/GlvRouter.json +144 -86
- package/build/cjs/src/abis/GovToken.json +1 -354
- package/build/cjs/src/abis/LayerZeroProvider.json +372 -0
- package/build/cjs/src/abis/Multicall.json +134 -38
- package/build/cjs/src/abis/MultichainClaimsRouter.json +1266 -0
- package/build/cjs/src/abis/MultichainGlvRouter.json +1150 -0
- package/build/cjs/src/abis/MultichainGmRouter.json +1449 -0
- package/build/cjs/src/abis/MultichainOrderRouter.json +1820 -0
- package/build/cjs/src/abis/MultichainSubaccountRouter.json +2069 -0
- package/build/cjs/src/abis/MultichainTransferRouter.json +915 -0
- package/build/cjs/src/abis/MultichainUtils.json +133 -0
- package/build/cjs/src/abis/MultichainVault.json +275 -0
- package/build/cjs/src/abis/ReferralStorage.json +69 -19
- package/build/cjs/src/abis/RelayParams.json +85 -48
- package/build/cjs/src/abis/SmartAccount.json +28 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouter.json +282 -148
- package/build/cjs/src/abis/SubaccountRouter.json +62 -118
- package/build/cjs/src/abis/SyntheticsReader.json +342 -474
- package/build/cjs/src/abis/SyntheticsRouter.json +1 -6
- package/build/cjs/src/abis/index.js +51 -7
- package/build/cjs/src/configs/__tests__/markets.spec.js +1 -1
- package/build/cjs/src/configs/__tests__/permits.spec.js +1 -1
- package/build/cjs/src/configs/__tests__/tokens.spec.js +1 -1
- package/build/cjs/src/configs/batch.js +48 -0
- package/build/cjs/src/configs/chains.js +41 -8
- package/build/cjs/src/configs/contracts.js +151 -41
- package/build/cjs/src/configs/dataStore.js +39 -5
- package/build/cjs/src/configs/express.js +4 -0
- package/build/cjs/src/configs/factors.js +1 -1
- package/build/cjs/src/configs/markets.js +128 -0
- package/build/cjs/src/configs/oracleKeeper.js +2 -0
- package/build/cjs/src/configs/tokens.js +217 -2
- package/build/cjs/src/modules/markets/index.js +9 -4
- package/build/cjs/src/modules/markets/query-builders.js +28 -8
- package/build/cjs/src/modules/orders/helpers.js +2 -2
- package/build/cjs/src/modules/orders/helpers.spec.js +1 -1
- package/build/cjs/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/transactions/createIncreaseOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/cjs/src/modules/orders/utils.js +4 -5
- package/build/cjs/src/modules/positions/positions.js +38 -5
- package/build/cjs/src/modules/utils/utils.js +1 -0
- package/build/cjs/src/prebuilt/hashedKinkModelMarketRatesKeys.json +146 -0
- package/build/cjs/src/prebuilt/hashedMarketConfigKeys.json +2207 -532
- package/build/cjs/src/prebuilt/hashedMarketValuesKeys.json +272 -0
- package/build/cjs/src/test/mock.js +9 -4
- package/build/cjs/src/types/subsquid.js +507 -1
- package/build/cjs/src/utils/LruCache.js +4 -0
- package/build/cjs/src/utils/__tests__/LruCache.spec.js +18 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +18 -16
- package/build/cjs/src/utils/__tests__/orderTransactions/batchUtils.spec.js +0 -1
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +8 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +38 -30
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +10 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +6 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +23 -6
- package/build/cjs/src/utils/bigmath.js +9 -2
- package/build/cjs/src/utils/errors/parseError.js +35 -1
- package/build/cjs/src/utils/fees/executionFee.js +5 -3
- package/build/cjs/src/utils/fees/index.js +8 -6
- package/build/cjs/src/utils/fees/priceImpact.js +94 -32
- package/build/cjs/src/utils/gelatoRelay.js +5 -0
- package/build/cjs/src/utils/marketKeysAndConfigs.js +24 -4
- package/build/cjs/src/utils/markets.js +10 -3
- package/build/cjs/src/utils/numbers.js +18 -17
- package/build/cjs/src/utils/orderTransactions.js +5 -1
- package/build/cjs/src/utils/positions.js +77 -9
- package/build/cjs/src/utils/prices.js +19 -13
- package/build/cjs/src/utils/swap/__tests__/mockRouting.spec.js +1 -0
- package/build/cjs/src/utils/swap/swapStats.js +6 -3
- package/build/cjs/src/utils/trade/decrease.js +470 -0
- package/build/cjs/src/utils/trade/{amounts.js → increase.js} +86 -31
- package/build/cjs/src/utils/tradeHistory.js +3 -0
- package/build/esm/src/abis/ClaimHandler.json +1 -16
- package/build/esm/src/abis/CustomErrors.json +642 -61
- package/build/esm/src/abis/DataStore.json +25 -6
- package/build/esm/src/abis/EventEmitter.json +1 -6
- package/build/esm/src/abis/ExchangeRouter.json +195 -290
- package/build/esm/src/abis/GelatoRelayRouter.json +251 -98
- package/build/esm/src/abis/GlvReader.json +60 -3
- package/build/esm/src/abis/GlvRouter.json +144 -86
- package/build/esm/src/abis/GovToken.json +1 -354
- package/build/esm/src/abis/LayerZeroProvider.json +372 -0
- package/build/esm/src/abis/Multicall.json +134 -38
- package/build/esm/src/abis/MultichainClaimsRouter.json +1266 -0
- package/build/esm/src/abis/MultichainGlvRouter.json +1150 -0
- package/build/esm/src/abis/MultichainGmRouter.json +1449 -0
- package/build/esm/src/abis/MultichainOrderRouter.json +1820 -0
- package/build/esm/src/abis/MultichainSubaccountRouter.json +2069 -0
- package/build/esm/src/abis/MultichainTransferRouter.json +915 -0
- package/build/esm/src/abis/MultichainUtils.json +133 -0
- package/build/esm/src/abis/MultichainVault.json +275 -0
- package/build/esm/src/abis/ReferralStorage.json +69 -19
- package/build/esm/src/abis/RelayParams.json +85 -48
- package/build/esm/src/abis/SmartAccount.json +28 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouter.json +282 -148
- package/build/esm/src/abis/SubaccountRouter.json +62 -118
- package/build/esm/src/abis/SyntheticsReader.json +342 -474
- package/build/esm/src/abis/SyntheticsRouter.json +1 -6
- package/build/esm/src/abis/index.js +51 -7
- package/build/esm/src/configs/__tests__/markets.spec.js +3 -3
- package/build/esm/src/configs/__tests__/permits.spec.js +2 -2
- package/build/esm/src/configs/__tests__/tokens.spec.js +2 -2
- package/build/esm/src/configs/batch.js +49 -1
- package/build/esm/src/configs/chains.js +40 -7
- package/build/esm/src/configs/contracts.js +152 -42
- package/build/esm/src/configs/dataStore.js +29 -1
- package/build/esm/src/configs/express.js +5 -1
- package/build/esm/src/configs/factors.js +1 -1
- package/build/esm/src/configs/markets.js +129 -1
- package/build/esm/src/configs/oracleKeeper.js +3 -1
- package/build/esm/src/configs/tokens.js +216 -2
- package/build/esm/src/modules/markets/index.js +9 -4
- package/build/esm/src/modules/markets/query-builders.js +28 -8
- package/build/esm/src/modules/orders/helpers.js +1 -1
- package/build/esm/src/modules/orders/helpers.spec.js +1 -1
- package/build/esm/src/modules/orders/transactions/createDecreaseOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/transactions/createIncreaseOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/transactions/createSwapOrderTxn.js +1 -0
- package/build/esm/src/modules/orders/utils.js +4 -5
- package/build/esm/src/modules/positions/positions.js +40 -7
- package/build/esm/src/modules/utils/utils.js +1 -0
- package/build/esm/src/prebuilt/hashedKinkModelMarketRatesKeys.json +146 -0
- package/build/esm/src/prebuilt/hashedMarketConfigKeys.json +2207 -532
- package/build/esm/src/prebuilt/hashedMarketValuesKeys.json +272 -0
- package/build/esm/src/test/mock.js +9 -4
- package/build/esm/src/types/subsquid.js +506 -0
- package/build/esm/src/utils/LruCache.js +4 -0
- package/build/esm/src/utils/__tests__/LruCache.spec.js +18 -0
- package/build/esm/src/utils/__tests__/numbers.spec.js +18 -16
- package/build/esm/src/utils/__tests__/orderTransactions/batchUtils.spec.js +0 -1
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +8 -0
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +38 -30
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +10 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +7 -1
- package/build/esm/src/utils/__tests__/positions.spec.js +23 -6
- package/build/esm/src/utils/bigmath.js +9 -2
- package/build/esm/src/utils/errors/parseError.js +31 -0
- package/build/esm/src/utils/fees/executionFee.js +5 -3
- package/build/esm/src/utils/fees/index.js +8 -6
- package/build/esm/src/utils/fees/priceImpact.js +88 -30
- package/build/esm/src/utils/gelatoRelay.js +2 -0
- package/build/esm/src/utils/marketKeysAndConfigs.js +25 -5
- package/build/esm/src/utils/markets.js +7 -1
- package/build/esm/src/utils/numbers.js +18 -17
- package/build/esm/src/utils/orderTransactions.js +5 -1
- package/build/esm/src/utils/positions.js +75 -11
- package/build/esm/src/utils/prices.js +20 -14
- package/build/esm/src/utils/swap/__tests__/mockRouting.spec.js +1 -0
- package/build/esm/src/utils/swap/swapStats.js +6 -3
- package/build/esm/src/utils/trade/decrease.js +460 -0
- package/build/esm/src/utils/trade/{amounts.js → increase.js} +87 -33
- package/build/esm/src/utils/tradeHistory.js +3 -0
- package/build/types/src/abis/index.d.ts +1 -1
- package/build/types/src/configs/batch.d.ts +2 -2
- package/build/types/src/configs/chains.d.ts +25 -20
- package/build/types/src/configs/contracts.d.ts +118 -10
- package/build/types/src/configs/dataStore.d.ts +16 -0
- package/build/types/src/configs/factors.d.ts +1 -1
- package/build/types/src/configs/markets.d.ts +2 -2
- package/build/types/src/configs/tokens.d.ts +1 -0
- package/build/types/src/index.d.ts +1 -1
- package/build/types/src/modules/base.d.ts +1 -1
- package/build/types/src/modules/markets/query-builders.d.ts +3 -2
- package/build/types/src/modules/markets/types.d.ts +2 -2
- package/build/types/src/modules/orders/transactions/createDecreaseOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/transactions/createIncreaseOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/transactions/createSwapOrderTxn.d.ts +1 -0
- package/build/types/src/modules/orders/utils.d.ts +6 -5
- package/build/types/src/types/fees.d.ts +1 -0
- package/build/types/src/types/markets.d.ts +10 -5
- package/build/types/src/types/orders.d.ts +1 -1
- package/build/types/src/types/positions.d.ts +26 -2
- package/build/types/src/types/sdk.d.ts +2 -2
- package/build/types/src/types/subsquid.d.ts +1259 -9
- package/build/types/src/types/tokens.d.ts +7 -0
- package/build/types/src/types/trade.d.ts +14 -3
- package/build/types/src/types/tradeHistory.d.ts +3 -0
- package/build/types/src/utils/LruCache.d.ts +1 -0
- package/build/types/src/utils/bigmath.d.ts +2 -1
- package/build/types/src/utils/errors/parseError.d.ts +11 -0
- package/build/types/src/utils/fees/executionFee.d.ts +6 -3
- package/build/types/src/utils/fees/index.d.ts +2 -2
- package/build/types/src/utils/fees/priceImpact.d.ts +33 -5
- package/build/types/src/utils/marketKeysAndConfigs.d.ts +9 -4
- package/build/types/src/utils/markets.d.ts +7 -0
- package/build/types/src/utils/multicall.d.ts +1 -1
- package/build/types/src/utils/numbers.d.ts +6 -3
- package/build/types/src/utils/orderTransactions.d.ts +6 -4
- package/build/types/src/utils/positions.d.ts +30 -0
- package/build/types/src/utils/prices.d.ts +4 -0
- package/build/types/src/utils/swap/swapValues.d.ts +1 -1
- package/build/types/src/utils/trade/decrease.d.ts +77 -0
- package/build/types/src/utils/trade/{amounts.d.ts → increase.d.ts} +16 -1
- package/package.json +2 -2
|
@@ -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.isContractError = exports.parseError = exports.extendError = void 0;
|
|
6
|
+
exports.getCustomError = exports.isCustomError = exports.CustomError = exports.isContractError = exports.parseError = exports.extendError = void 0;
|
|
7
7
|
const crypto_js_1 = __importDefault(require("crypto-js"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
9
|
const abis_1 = require("../../abis");
|
|
@@ -148,3 +148,37 @@ function hasStack(error) {
|
|
|
148
148
|
function hasName(error) {
|
|
149
149
|
return !!error && typeof error === "object" && typeof error.name === "string";
|
|
150
150
|
}
|
|
151
|
+
class CustomError extends Error {
|
|
152
|
+
constructor({ name, message, args }) {
|
|
153
|
+
super(message);
|
|
154
|
+
this.isGmxCustomError = true;
|
|
155
|
+
this.name = name;
|
|
156
|
+
this.args = args;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.CustomError = CustomError;
|
|
160
|
+
function isCustomError(error) {
|
|
161
|
+
return error?.isGmxCustomError === true;
|
|
162
|
+
}
|
|
163
|
+
exports.isCustomError = isCustomError;
|
|
164
|
+
function getCustomError(error) {
|
|
165
|
+
const data = error?.info?.error?.data ?? error?.data;
|
|
166
|
+
let prettyErrorName = error.name;
|
|
167
|
+
let prettyErrorMessage = error.message;
|
|
168
|
+
let prettyErrorArgs = undefined;
|
|
169
|
+
try {
|
|
170
|
+
const parsedError = (0, viem_1.decodeErrorResult)({
|
|
171
|
+
abi: abis_1.abis.CustomErrors,
|
|
172
|
+
data: data,
|
|
173
|
+
});
|
|
174
|
+
prettyErrorArgs = parsedError.args;
|
|
175
|
+
prettyErrorName = parsedError.errorName;
|
|
176
|
+
prettyErrorMessage = JSON.stringify(parsedError, null, 2);
|
|
177
|
+
}
|
|
178
|
+
catch (decodeError) {
|
|
179
|
+
return error;
|
|
180
|
+
}
|
|
181
|
+
const prettyError = new CustomError({ name: prettyErrorName, message: prettyErrorMessage, args: prettyErrorArgs });
|
|
182
|
+
return prettyError;
|
|
183
|
+
}
|
|
184
|
+
exports.getCustomError = getCustomError;
|
|
@@ -55,20 +55,22 @@ function approximateL1GasBuffer({ l1Reference, sizeOfData, }) {
|
|
|
55
55
|
return l1GasLimit;
|
|
56
56
|
}
|
|
57
57
|
exports.approximateL1GasBuffer = approximateL1GasBuffer;
|
|
58
|
-
function estimateBatchGasLimit({ gasLimits, createOrdersCount, updateOrdersCount, cancelOrdersCount, externalCallsGasLimit, }) {
|
|
58
|
+
function estimateBatchGasLimit({ gasLimits, createOrdersCount, updateOrdersCount, cancelOrdersCount, externalCallsGasLimit, isGmxAccount, }) {
|
|
59
59
|
const createOrdersGasLimit = gasLimits.createOrderGasLimit * BigInt(createOrdersCount);
|
|
60
60
|
const updateOrdersGasLimit = gasLimits.updateOrderGasLimit * BigInt(updateOrdersCount);
|
|
61
61
|
const cancelOrdersGasLimit = gasLimits.cancelOrderGasLimit * BigInt(cancelOrdersCount);
|
|
62
|
-
|
|
62
|
+
const gmxAccountOverhead = isGmxAccount ? gasLimits.gmxAccountCollateralGasLimit : 0n;
|
|
63
|
+
return (createOrdersGasLimit + updateOrdersGasLimit + cancelOrdersGasLimit + externalCallsGasLimit + gmxAccountOverhead);
|
|
63
64
|
}
|
|
64
65
|
exports.estimateBatchGasLimit = estimateBatchGasLimit;
|
|
65
|
-
function estimateBatchMinGasPaymentTokenAmount({ chainId, gasPaymentToken, relayFeeToken, gasPrice, gasLimits, l1Reference, tokensData, createOrdersCount = 1, updateOrdersCount = 0, cancelOrdersCount = 0, executionFeeAmount, }) {
|
|
66
|
+
function estimateBatchMinGasPaymentTokenAmount({ chainId, gasPaymentToken, isGmxAccount, relayFeeToken, gasPrice, gasLimits, l1Reference, tokensData, createOrdersCount = 1, updateOrdersCount = 0, cancelOrdersCount = 0, executionFeeAmount, }) {
|
|
66
67
|
const batchGasLimit = estimateBatchGasLimit({
|
|
67
68
|
gasLimits,
|
|
68
69
|
createOrdersCount,
|
|
69
70
|
updateOrdersCount,
|
|
70
71
|
cancelOrdersCount,
|
|
71
72
|
externalCallsGasLimit: 0n,
|
|
73
|
+
isGmxAccount,
|
|
72
74
|
});
|
|
73
75
|
const relayerGasLimit = estimateRelayerGasLimit({
|
|
74
76
|
gasLimits,
|
|
@@ -21,21 +21,23 @@ const numbers_1 = require("../numbers");
|
|
|
21
21
|
__exportStar(require("./estimateOraclePriceCount"), exports);
|
|
22
22
|
__exportStar(require("./executionFee"), exports);
|
|
23
23
|
__exportStar(require("./priceImpact"), exports);
|
|
24
|
-
function getSwapFee(marketInfo, swapAmount,
|
|
24
|
+
function getSwapFee(marketInfo, swapAmount, balanceWasImproved, isAtomicSwap) {
|
|
25
25
|
let factor;
|
|
26
26
|
if (isAtomicSwap) {
|
|
27
27
|
factor = marketInfo.atomicSwapFeeFactor;
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
|
-
factor =
|
|
30
|
+
factor = balanceWasImproved
|
|
31
|
+
? marketInfo.swapFeeFactorForBalanceWasImproved
|
|
32
|
+
: marketInfo.swapFeeFactorForBalanceWasNotImproved;
|
|
31
33
|
}
|
|
32
34
|
return (0, numbers_1.applyFactor)(swapAmount, factor);
|
|
33
35
|
}
|
|
34
36
|
exports.getSwapFee = getSwapFee;
|
|
35
|
-
function getPositionFee(marketInfo, sizeDeltaUsd,
|
|
36
|
-
const factor =
|
|
37
|
-
? marketInfo.
|
|
38
|
-
: marketInfo.
|
|
37
|
+
function getPositionFee(marketInfo, sizeDeltaUsd, balanceWasImproved, referralInfo, uiFeeFactor) {
|
|
38
|
+
const factor = balanceWasImproved
|
|
39
|
+
? marketInfo.positionFeeFactorForBalanceWasImproved
|
|
40
|
+
: marketInfo.positionFeeFactorForBalanceWasNotImproved;
|
|
39
41
|
let positionFeeUsd = (0, numbers_1.applyFactor)(sizeDeltaUsd, factor);
|
|
40
42
|
const uiFeeUsd = (0, numbers_1.applyFactor)(sizeDeltaUsd, uiFeeFactor ?? 0n);
|
|
41
43
|
if (!referralInfo) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.applyImpactFactor = exports.calculateImpactForCrossoverRebalance = exports.calculateImpactForSameSideRebalance = exports.getPriceImpactUsd = exports.getNextPoolAmountsParams = exports.getPriceImpactForSwap = exports.getPriceImpactForPosition = exports.getCappedPositionImpactUsd = exports.applySwapImpactWithCap = exports.getPriceImpactByAcceptablePrice = void 0;
|
|
3
|
+
exports.applyImpactFactor = exports.calculateImpactForCrossoverRebalance = exports.calculateImpactForSameSideRebalance = exports.getPriceImpactUsd = exports.getNextPoolAmountsParams = exports.getPriceImpactForSwap = exports.getProportionalPendingImpactValues = exports.getPriceImpactForPosition = exports.getMaxPositionImpactFactors = exports.capPositionImpactUsdByMaxPriceImpactFactor = exports.capPositionImpactUsdByMaxImpactPool = exports.getCappedPositionImpactUsd = exports.applySwapImpactWithCap = exports.getPriceImpactByAcceptablePrice = void 0;
|
|
4
4
|
const bigmath_1 = require("../bigmath");
|
|
5
5
|
const markets_1 = require("../markets");
|
|
6
6
|
const numbers_1 = require("../numbers");
|
|
@@ -48,26 +48,51 @@ function applySwapImpactWithCap(marketInfo, token, priceImpactDeltaUsd) {
|
|
|
48
48
|
return { impactDeltaAmount, cappedDiffUsd };
|
|
49
49
|
}
|
|
50
50
|
exports.applySwapImpactWithCap = applySwapImpactWithCap;
|
|
51
|
-
function getCappedPositionImpactUsd(marketInfo, sizeDeltaUsd, isLong, opts = {}) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
function getCappedPositionImpactUsd(marketInfo, sizeDeltaUsd, isLong, isIncrease, opts = {}) {
|
|
52
|
+
sizeDeltaUsd = isIncrease ? sizeDeltaUsd : sizeDeltaUsd * -1n;
|
|
53
|
+
const { priceImpactDeltaUsd, balanceWasImproved } = getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts);
|
|
54
|
+
if (priceImpactDeltaUsd < 0 && !opts.shouldCapNegativeImpact) {
|
|
55
|
+
return { priceImpactDeltaUsd, balanceWasImproved };
|
|
56
|
+
}
|
|
57
|
+
const cappedImpactUsd = capPositionImpactUsdByMaxPriceImpactFactor(marketInfo, sizeDeltaUsd, priceImpactDeltaUsd);
|
|
58
|
+
return {
|
|
59
|
+
priceImpactDeltaUsd: cappedImpactUsd,
|
|
60
|
+
balanceWasImproved,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.getCappedPositionImpactUsd = getCappedPositionImpactUsd;
|
|
64
|
+
function capPositionImpactUsdByMaxImpactPool(marketInfo, positionImpactDeltaUsd) {
|
|
65
|
+
if (positionImpactDeltaUsd < 0) {
|
|
66
|
+
return positionImpactDeltaUsd;
|
|
55
67
|
}
|
|
56
68
|
const { indexToken } = marketInfo;
|
|
57
|
-
const impactPoolAmount = marketInfo
|
|
69
|
+
const impactPoolAmount = marketInfo.positionImpactPoolAmount;
|
|
58
70
|
const maxPriceImpactUsdBasedOnImpactPool = (0, tokens_1.convertToUsd)(impactPoolAmount, indexToken.decimals, indexToken.prices.minPrice);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
cappedImpactUsd = maxPriceImpactUsdBasedOnImpactPool;
|
|
71
|
+
if (positionImpactDeltaUsd > maxPriceImpactUsdBasedOnImpactPool) {
|
|
72
|
+
positionImpactDeltaUsd = maxPriceImpactUsdBasedOnImpactPool;
|
|
62
73
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
74
|
+
return positionImpactDeltaUsd;
|
|
75
|
+
}
|
|
76
|
+
exports.capPositionImpactUsdByMaxImpactPool = capPositionImpactUsdByMaxImpactPool;
|
|
77
|
+
function capPositionImpactUsdByMaxPriceImpactFactor(marketInfo, sizeDeltaUsd, positionImpactDeltaUsd) {
|
|
78
|
+
const { maxPositiveImpactFactor, maxNegativeImpactFactor } = getMaxPositionImpactFactors(marketInfo);
|
|
79
|
+
const maxPriceImapctFactor = positionImpactDeltaUsd > 0 ? maxPositiveImpactFactor : maxNegativeImpactFactor;
|
|
80
|
+
const maxPriceImpactUsdBasedOnMaxPriceImpactFactor = (0, numbers_1.applyFactor)(bigmath_1.bigMath.abs(sizeDeltaUsd), maxPriceImapctFactor);
|
|
81
|
+
if (bigmath_1.bigMath.abs(positionImpactDeltaUsd) > maxPriceImpactUsdBasedOnMaxPriceImpactFactor) {
|
|
82
|
+
positionImpactDeltaUsd = maxPriceImpactUsdBasedOnMaxPriceImpactFactor * (positionImpactDeltaUsd > 0 ? 1n : -1n);
|
|
67
83
|
}
|
|
68
|
-
return
|
|
84
|
+
return positionImpactDeltaUsd;
|
|
69
85
|
}
|
|
70
|
-
exports.
|
|
86
|
+
exports.capPositionImpactUsdByMaxPriceImpactFactor = capPositionImpactUsdByMaxPriceImpactFactor;
|
|
87
|
+
function getMaxPositionImpactFactors(marketInfo) {
|
|
88
|
+
let maxPositiveImpactFactor = marketInfo.maxPositionImpactFactorPositive;
|
|
89
|
+
const maxNegativeImpactFactor = marketInfo.maxPositionImpactFactorNegative;
|
|
90
|
+
if (maxPositiveImpactFactor > maxNegativeImpactFactor) {
|
|
91
|
+
maxPositiveImpactFactor = maxNegativeImpactFactor;
|
|
92
|
+
}
|
|
93
|
+
return { maxPositiveImpactFactor, maxNegativeImpactFactor };
|
|
94
|
+
}
|
|
95
|
+
exports.getMaxPositionImpactFactors = getMaxPositionImpactFactors;
|
|
71
96
|
function getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts = {}) {
|
|
72
97
|
const { longInterestUsd, shortInterestUsd } = marketInfo;
|
|
73
98
|
const { currentLongUsd, currentShortUsd, nextLongUsd, nextShortUsd } = getNextOpenInterestParams({
|
|
@@ -76,7 +101,7 @@ function getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts = {})
|
|
|
76
101
|
usdDelta: sizeDeltaUsd,
|
|
77
102
|
isLong: isLong,
|
|
78
103
|
});
|
|
79
|
-
const
|
|
104
|
+
const { priceImpactDeltaUsd, balanceWasImproved } = getPriceImpactUsd({
|
|
80
105
|
currentLongUsd,
|
|
81
106
|
currentShortUsd,
|
|
82
107
|
nextLongUsd,
|
|
@@ -86,18 +111,24 @@ function getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts = {})
|
|
|
86
111
|
exponentFactor: marketInfo.positionImpactExponentFactor,
|
|
87
112
|
fallbackToZero: opts.fallbackToZero,
|
|
88
113
|
});
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
114
|
+
if (priceImpactDeltaUsd > 0) {
|
|
115
|
+
return {
|
|
116
|
+
priceImpactDeltaUsd,
|
|
117
|
+
balanceWasImproved,
|
|
118
|
+
};
|
|
91
119
|
}
|
|
92
120
|
if (bigmath_1.bigMath.abs(marketInfo.virtualInventoryForPositions) <= 0) {
|
|
93
|
-
return
|
|
121
|
+
return {
|
|
122
|
+
priceImpactDeltaUsd,
|
|
123
|
+
balanceWasImproved,
|
|
124
|
+
};
|
|
94
125
|
}
|
|
95
126
|
const virtualInventoryParams = getNextOpenInterestForVirtualInventory({
|
|
96
127
|
virtualInventory: marketInfo.virtualInventoryForPositions,
|
|
97
128
|
usdDelta: sizeDeltaUsd,
|
|
98
129
|
isLong: isLong,
|
|
99
130
|
});
|
|
100
|
-
const priceImpactUsdForVirtualInventory = getPriceImpactUsd({
|
|
131
|
+
const { priceImpactDeltaUsd: priceImpactUsdForVirtualInventory } = getPriceImpactUsd({
|
|
101
132
|
currentLongUsd: virtualInventoryParams.currentLongUsd,
|
|
102
133
|
currentShortUsd: virtualInventoryParams.currentShortUsd,
|
|
103
134
|
nextLongUsd: virtualInventoryParams.nextLongUsd,
|
|
@@ -107,9 +138,22 @@ function getPriceImpactForPosition(marketInfo, sizeDeltaUsd, isLong, opts = {})
|
|
|
107
138
|
exponentFactor: marketInfo.positionImpactExponentFactor,
|
|
108
139
|
fallbackToZero: opts.fallbackToZero,
|
|
109
140
|
});
|
|
110
|
-
return
|
|
141
|
+
return {
|
|
142
|
+
priceImpactDeltaUsd: priceImpactUsdForVirtualInventory < priceImpactDeltaUsd
|
|
143
|
+
? priceImpactUsdForVirtualInventory
|
|
144
|
+
: priceImpactDeltaUsd,
|
|
145
|
+
balanceWasImproved,
|
|
146
|
+
};
|
|
111
147
|
}
|
|
112
148
|
exports.getPriceImpactForPosition = getPriceImpactForPosition;
|
|
149
|
+
function getProportionalPendingImpactValues({ sizeInUsd, pendingImpactAmount, sizeDeltaUsd, indexToken, }) {
|
|
150
|
+
const proportionalPendingImpactDeltaAmount = sizeDeltaUsd !== 0n && sizeInUsd !== 0n
|
|
151
|
+
? bigmath_1.bigMath.mulDiv(pendingImpactAmount, sizeDeltaUsd, sizeInUsd, pendingImpactAmount < 0n)
|
|
152
|
+
: 0n;
|
|
153
|
+
const proportionalPendingImpactDeltaUsd = (0, tokens_1.convertToUsd)(proportionalPendingImpactDeltaAmount, indexToken.decimals, proportionalPendingImpactDeltaAmount > 0 ? indexToken.prices.minPrice : indexToken.prices.maxPrice);
|
|
154
|
+
return { proportionalPendingImpactDeltaAmount, proportionalPendingImpactDeltaUsd };
|
|
155
|
+
}
|
|
156
|
+
exports.getProportionalPendingImpactValues = getProportionalPendingImpactValues;
|
|
113
157
|
function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDeltaTokenB, opts = {}) {
|
|
114
158
|
const tokenAPoolType = (0, markets_1.getTokenPoolType)(marketInfo, tokenA.address);
|
|
115
159
|
const tokenBPoolType = (0, markets_1.getTokenPoolType)(marketInfo, tokenB.address);
|
|
@@ -129,7 +173,7 @@ function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDe
|
|
|
129
173
|
longDeltaUsd,
|
|
130
174
|
shortDeltaUsd,
|
|
131
175
|
});
|
|
132
|
-
const
|
|
176
|
+
const { priceImpactDeltaUsd, balanceWasImproved } = getPriceImpactUsd({
|
|
133
177
|
currentLongUsd: longPoolUsd,
|
|
134
178
|
currentShortUsd: shortPoolUsd,
|
|
135
179
|
nextLongUsd: nextLongPoolUsd,
|
|
@@ -139,13 +183,19 @@ function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDe
|
|
|
139
183
|
exponentFactor: marketInfo.swapImpactExponentFactor,
|
|
140
184
|
fallbackToZero: opts.fallbackToZero,
|
|
141
185
|
});
|
|
142
|
-
if (
|
|
143
|
-
return
|
|
186
|
+
if (priceImpactDeltaUsd > 0) {
|
|
187
|
+
return {
|
|
188
|
+
priceImpactDeltaUsd,
|
|
189
|
+
balanceWasImproved,
|
|
190
|
+
};
|
|
144
191
|
}
|
|
145
192
|
const virtualInventoryLong = marketInfo.virtualPoolAmountForLongToken;
|
|
146
193
|
const virtualInventoryShort = marketInfo.virtualPoolAmountForShortToken;
|
|
147
194
|
if (virtualInventoryLong <= 0 || virtualInventoryShort <= 0) {
|
|
148
|
-
return
|
|
195
|
+
return {
|
|
196
|
+
priceImpactDeltaUsd,
|
|
197
|
+
balanceWasImproved,
|
|
198
|
+
};
|
|
149
199
|
}
|
|
150
200
|
const virtualInventoryParams = getNextPoolAmountsParams({
|
|
151
201
|
marketInfo,
|
|
@@ -156,7 +206,7 @@ function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDe
|
|
|
156
206
|
longDeltaUsd,
|
|
157
207
|
shortDeltaUsd,
|
|
158
208
|
});
|
|
159
|
-
const priceImpactUsdForVirtualInventory = getPriceImpactUsd({
|
|
209
|
+
const { priceImpactDeltaUsd: priceImpactUsdForVirtualInventory } = getPriceImpactUsd({
|
|
160
210
|
currentLongUsd: virtualInventoryParams.longPoolUsd,
|
|
161
211
|
currentShortUsd: virtualInventoryParams.shortPoolUsd,
|
|
162
212
|
nextLongUsd: virtualInventoryParams.nextLongPoolUsd,
|
|
@@ -166,7 +216,12 @@ function getPriceImpactForSwap(marketInfo, tokenA, tokenB, usdDeltaTokenA, usdDe
|
|
|
166
216
|
exponentFactor: marketInfo.swapImpactExponentFactor,
|
|
167
217
|
fallbackToZero: opts.fallbackToZero,
|
|
168
218
|
});
|
|
169
|
-
return
|
|
219
|
+
return {
|
|
220
|
+
priceImpactDeltaUsd: priceImpactUsdForVirtualInventory < priceImpactDeltaUsd
|
|
221
|
+
? priceImpactUsdForVirtualInventory
|
|
222
|
+
: priceImpactDeltaUsd,
|
|
223
|
+
balanceWasImproved,
|
|
224
|
+
};
|
|
170
225
|
}
|
|
171
226
|
exports.getPriceImpactForSwap = getPriceImpactForSwap;
|
|
172
227
|
function getNextOpenInterestForVirtualInventory(p) {
|
|
@@ -233,7 +288,10 @@ function getPriceImpactUsd(p) {
|
|
|
233
288
|
const { nextLongUsd, nextShortUsd } = p;
|
|
234
289
|
if (nextLongUsd < 0 || nextShortUsd < 0) {
|
|
235
290
|
if (p.fallbackToZero) {
|
|
236
|
-
return
|
|
291
|
+
return {
|
|
292
|
+
priceImpactDeltaUsd: 0n,
|
|
293
|
+
balanceWasImproved: false,
|
|
294
|
+
};
|
|
237
295
|
}
|
|
238
296
|
else {
|
|
239
297
|
throw new Error("Negative pool amount");
|
|
@@ -242,11 +300,12 @@ function getPriceImpactUsd(p) {
|
|
|
242
300
|
const currentDiff = bigmath_1.bigMath.abs(p.currentLongUsd - p.currentShortUsd);
|
|
243
301
|
const nextDiff = bigmath_1.bigMath.abs(nextLongUsd - nextShortUsd);
|
|
244
302
|
const isSameSideRebalance = p.currentLongUsd < p.currentShortUsd === nextLongUsd < nextShortUsd;
|
|
245
|
-
let
|
|
303
|
+
let priceImpactDeltaUsd;
|
|
304
|
+
const balanceWasImproved = nextDiff < currentDiff;
|
|
246
305
|
if (isSameSideRebalance) {
|
|
247
306
|
const hasPositiveImpact = nextDiff < currentDiff;
|
|
248
307
|
const factor = hasPositiveImpact ? p.factorPositive : p.factorNegative;
|
|
249
|
-
|
|
308
|
+
priceImpactDeltaUsd = calculateImpactForSameSideRebalance({
|
|
250
309
|
currentDiff,
|
|
251
310
|
nextDiff,
|
|
252
311
|
hasPositiveImpact,
|
|
@@ -255,7 +314,7 @@ function getPriceImpactUsd(p) {
|
|
|
255
314
|
});
|
|
256
315
|
}
|
|
257
316
|
else {
|
|
258
|
-
|
|
317
|
+
priceImpactDeltaUsd = calculateImpactForCrossoverRebalance({
|
|
259
318
|
currentDiff,
|
|
260
319
|
nextDiff,
|
|
261
320
|
factorPositive: p.factorPositive,
|
|
@@ -263,7 +322,10 @@ function getPriceImpactUsd(p) {
|
|
|
263
322
|
exponentFactor: p.exponentFactor,
|
|
264
323
|
});
|
|
265
324
|
}
|
|
266
|
-
return
|
|
325
|
+
return {
|
|
326
|
+
priceImpactDeltaUsd,
|
|
327
|
+
balanceWasImproved,
|
|
328
|
+
};
|
|
267
329
|
}
|
|
268
330
|
exports.getPriceImpactUsd = getPriceImpactUsd;
|
|
269
331
|
/**
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.gelatoRelay = void 0;
|
|
4
7
|
const relay_sdk_1 = require("@gelatonetwork/relay-sdk");
|
|
8
|
+
const noop_1 = __importDefault(require("lodash/noop"));
|
|
5
9
|
exports.gelatoRelay = new relay_sdk_1.GelatoRelay();
|
|
10
|
+
exports.gelatoRelay.onError(noop_1.default);
|
|
@@ -122,11 +122,11 @@ function hashMarketConfigKeys(market) {
|
|
|
122
122
|
["bytes32", "bytes32", "address", "bool"],
|
|
123
123
|
[dataStore_1.MAX_PNL_FACTOR_KEY, dataStore_1.MAX_PNL_FACTOR_FOR_TRADERS_KEY, marketAddress, false],
|
|
124
124
|
],
|
|
125
|
-
|
|
125
|
+
positionFeeFactorForBalanceWasImproved: [
|
|
126
126
|
["bytes32", "address", "bool"],
|
|
127
127
|
[dataStore_1.POSITION_FEE_FACTOR_KEY, marketAddress, true],
|
|
128
128
|
],
|
|
129
|
-
|
|
129
|
+
positionFeeFactorForBalanceWasNotImproved: [
|
|
130
130
|
["bytes32", "address", "bool"],
|
|
131
131
|
[dataStore_1.POSITION_FEE_FACTOR_KEY, marketAddress, false],
|
|
132
132
|
],
|
|
@@ -150,10 +150,30 @@ function hashMarketConfigKeys(market) {
|
|
|
150
150
|
["bytes32", "address"],
|
|
151
151
|
[dataStore_1.MAX_POSITION_IMPACT_FACTOR_FOR_LIQUIDATIONS_KEY, marketAddress],
|
|
152
152
|
],
|
|
153
|
+
maxLendableImpactFactor: [
|
|
154
|
+
["bytes32", "address"],
|
|
155
|
+
[dataStore_1.MAX_LENDABLE_IMPACT_FACTOR_KEY, marketAddress],
|
|
156
|
+
],
|
|
157
|
+
maxLendableImpactFactorForWithdrawals: [
|
|
158
|
+
["bytes32", "address"],
|
|
159
|
+
[dataStore_1.MAX_LENDABLE_IMPACT_FACTOR_FOR_WITHDRAWALS_KEY, marketAddress],
|
|
160
|
+
],
|
|
161
|
+
maxLendableImpactUsd: [
|
|
162
|
+
["bytes32", "address"],
|
|
163
|
+
[dataStore_1.MAX_LENDABLE_IMPACT_USD_KEY, marketAddress],
|
|
164
|
+
],
|
|
165
|
+
lentPositionImpactPoolAmount: [
|
|
166
|
+
["bytes32", "address"],
|
|
167
|
+
[dataStore_1.LENT_POSITION_IMPACT_POOL_AMOUNT_KEY, marketAddress],
|
|
168
|
+
],
|
|
153
169
|
minCollateralFactor: [
|
|
154
170
|
["bytes32", "address"],
|
|
155
171
|
[dataStore_1.MIN_COLLATERAL_FACTOR_KEY, marketAddress],
|
|
156
172
|
],
|
|
173
|
+
minCollateralFactorForLiquidation: [
|
|
174
|
+
["bytes32", "address"],
|
|
175
|
+
[dataStore_1.MIN_COLLATERAL_FACTOR_FOR_LIQUIDATION_KEY, marketAddress],
|
|
176
|
+
],
|
|
157
177
|
minCollateralFactorForOpenInterestLong: [
|
|
158
178
|
["bytes32", "address", "bool"],
|
|
159
179
|
[dataStore_1.MIN_COLLATERAL_FACTOR_FOR_OPEN_INTEREST_MULTIPLIER_KEY, marketAddress, true],
|
|
@@ -166,11 +186,11 @@ function hashMarketConfigKeys(market) {
|
|
|
166
186
|
["bytes32", "address"],
|
|
167
187
|
[dataStore_1.POSITION_IMPACT_EXPONENT_FACTOR_KEY, marketAddress],
|
|
168
188
|
],
|
|
169
|
-
|
|
189
|
+
swapFeeFactorForBalanceWasImproved: [
|
|
170
190
|
["bytes32", "address", "bool"],
|
|
171
191
|
[dataStore_1.SWAP_FEE_FACTOR_KEY, marketAddress, true],
|
|
172
192
|
],
|
|
173
|
-
|
|
193
|
+
swapFeeFactorForBalanceWasNotImproved: [
|
|
174
194
|
["bytes32", "address", "bool"],
|
|
175
195
|
[dataStore_1.SWAP_FEE_FACTOR_KEY, marketAddress, false],
|
|
176
196
|
],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getIsMarketAvailableForExpressSwaps = exports.getPriceForPnl = exports.getOpenInterestInTokens = exports.getOpenInterestUsd = exports.getMarketPnl = exports.getMarketDivisor = exports.getReservedUsd = exports.getAvailableUsdLiquidityForCollateral = exports.getOppositeCollateral = exports.getMaxAllowedLeverageByMinCollateralFactor = exports.getMaxLeverageByMinCollateralFactor = exports.getCappedPoolPnl = exports.getPoolUsdWithoutPnl = exports.getTokenPoolType = exports.getContractMarketPrices = exports.getMarketPoolName = exports.getMarketIndexName = exports.getMarketFullName = void 0;
|
|
3
|
+
exports.getIsMarketAvailableForExpressSwaps = exports.getPriceForPnl = exports.getOpenInterestInTokens = exports.getOpenInterestUsd = exports.getMarketPnl = exports.getMarketDivisor = exports.getReservedUsd = exports.getAvailableUsdLiquidityForCollateral = exports.getOppositeCollateral = exports.getMaxAllowedLeverageByMinCollateralFactor = exports.getMaxLeverageByMinCollateralFactor = exports.getCappedPoolPnl = exports.getPoolUsdWithoutPnl = exports.getTokenPoolType = exports.getContractMarketPrices = exports.getMarketPoolName = exports.getMarketBaseName = exports.getMarketIndexName = exports.getMarketFullName = void 0;
|
|
4
4
|
const factors_1 = require("../configs/factors");
|
|
5
5
|
const tokens_1 = require("../configs/tokens");
|
|
6
6
|
const numbers_1 = require("./numbers");
|
|
@@ -12,15 +12,22 @@ function getMarketFullName(p) {
|
|
|
12
12
|
}
|
|
13
13
|
exports.getMarketFullName = getMarketFullName;
|
|
14
14
|
function getMarketIndexName(p) {
|
|
15
|
+
if (p.isSpotOnly) {
|
|
16
|
+
return `SWAP-ONLY`;
|
|
17
|
+
}
|
|
18
|
+
return `${getMarketBaseName(p)}/USD`;
|
|
19
|
+
}
|
|
20
|
+
exports.getMarketIndexName = getMarketIndexName;
|
|
21
|
+
function getMarketBaseName(p) {
|
|
15
22
|
const { isSpotOnly } = p;
|
|
16
23
|
const firstToken = "indexToken" in p ? p.indexToken : p.glvToken;
|
|
17
24
|
if (isSpotOnly) {
|
|
18
25
|
return `SWAP-ONLY`;
|
|
19
26
|
}
|
|
20
27
|
const prefix = (0, tokens_1.getTokenVisualMultiplier)(firstToken);
|
|
21
|
-
return `${prefix}${firstToken.baseSymbol || firstToken.symbol}
|
|
28
|
+
return `${prefix}${firstToken.baseSymbol || firstToken.symbol}`;
|
|
22
29
|
}
|
|
23
|
-
exports.
|
|
30
|
+
exports.getMarketBaseName = getMarketBaseName;
|
|
24
31
|
function getMarketPoolName(p, separator = "-") {
|
|
25
32
|
const { longToken, shortToken } = p;
|
|
26
33
|
return `${longToken.symbol}${separator}${shortToken.symbol}`;
|
|
@@ -112,7 +112,7 @@ function formatUsd(usd, opts = {}) {
|
|
|
112
112
|
const sign = usd < 0n ? "-" : maybePlus;
|
|
113
113
|
const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol} ` : "";
|
|
114
114
|
const displayUsd = (0, exports.formatAmount)(exceedingInfo.value, exports.USD_DECIMALS, displayDecimals, true);
|
|
115
|
-
return `${symbol}${sign}
|
|
115
|
+
return `${symbol}${sign}$\u200a${displayUsd}`;
|
|
116
116
|
}
|
|
117
117
|
exports.formatUsd = formatUsd;
|
|
118
118
|
function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
@@ -127,7 +127,7 @@ function formatDeltaUsd(deltaUsd, percentage, opts = {}) {
|
|
|
127
127
|
const percentageStr = percentage !== undefined ? ` (${sign}${formatPercentage(bigmath_1.bigMath.abs(percentage))})` : "";
|
|
128
128
|
const deltaUsdStr = (0, exports.formatAmount)(exceedingInfo.value, exports.USD_DECIMALS, 2, true);
|
|
129
129
|
const symbol = exceedingInfo.symbol ? `${exceedingInfo.symbol} ` : "";
|
|
130
|
-
return `${symbol}${sign}
|
|
130
|
+
return `${symbol}${sign}$\u200a${deltaUsdStr}${percentageStr}`;
|
|
131
131
|
}
|
|
132
132
|
exports.formatDeltaUsd = formatDeltaUsd;
|
|
133
133
|
function formatPercentage(percentage, opts = {}) {
|
|
@@ -138,7 +138,7 @@ function formatPercentage(percentage, opts = {}) {
|
|
|
138
138
|
}
|
|
139
139
|
return undefined;
|
|
140
140
|
}
|
|
141
|
-
const sign = signed ? getPlusOrMinusSymbol(percentage) : "";
|
|
141
|
+
const sign = signed ? `${getPlusOrMinusSymbol(percentage)}\u200a` : "";
|
|
142
142
|
return `${sign}${(0, exports.formatAmount)(bigmath_1.bigMath.abs(percentage), bps ? 2 : exports.PERCENT_PRECISION_DECIMALS, displayDecimals)}%`;
|
|
143
143
|
}
|
|
144
144
|
exports.formatPercentage = formatPercentage;
|
|
@@ -198,7 +198,7 @@ function formatRatePercentage(rate, opts) {
|
|
|
198
198
|
const signed = opts?.signed ?? true;
|
|
199
199
|
const plurOrMinus = signed ? getPlusOrMinusSymbol(rate) : "";
|
|
200
200
|
const amount = bigmath_1.bigMath.abs(rate * 100n);
|
|
201
|
-
return `${plurOrMinus}${(0, exports.formatAmount)(amount, 30, opts?.displayDecimals ?? 4)}%`;
|
|
201
|
+
return `${plurOrMinus}\u200a${(0, exports.formatAmount)(amount, 30, opts?.displayDecimals ?? 4)}%`;
|
|
202
202
|
}
|
|
203
203
|
exports.formatRatePercentage = formatRatePercentage;
|
|
204
204
|
function formatUsdPrice(price, opts = {}) {
|
|
@@ -233,7 +233,7 @@ function formatAmountHuman(amount, tokenDecimals, showDollar = false, displayDec
|
|
|
233
233
|
}
|
|
234
234
|
const isNegative = n < 0;
|
|
235
235
|
const absN = Math.abs(n);
|
|
236
|
-
const sign = showDollar ? "
|
|
236
|
+
const sign = showDollar ? "$\u200a" : "";
|
|
237
237
|
if (absN >= 1000000000) {
|
|
238
238
|
return `${isNegative ? "-" : ""}${sign}${(absN / 1000000000).toFixed(displayDecimals)}b`;
|
|
239
239
|
}
|
|
@@ -246,7 +246,7 @@ function formatAmountHuman(amount, tokenDecimals, showDollar = false, displayDec
|
|
|
246
246
|
return `${isNegative ? "-" : ""}${sign}${absN.toFixed(displayDecimals)}`;
|
|
247
247
|
}
|
|
248
248
|
exports.formatAmountHuman = formatAmountHuman;
|
|
249
|
-
function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZero = false, toExponential = true, isStable = false, } = {}) {
|
|
249
|
+
function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZero = false, toExponential = true, isStable = false, signed = false, } = {}) {
|
|
250
250
|
if (amount === undefined)
|
|
251
251
|
return "-";
|
|
252
252
|
if (amount === 0n) {
|
|
@@ -264,33 +264,34 @@ function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZero = fa
|
|
|
264
264
|
}
|
|
265
265
|
return "-";
|
|
266
266
|
}
|
|
267
|
+
const sign = signed || amount < 0n ? getPlusOrMinusSymbol(amount) : "";
|
|
267
268
|
const absAmount = bigmath_1.bigMath.abs(amount);
|
|
268
269
|
const absAmountFloat = bigintToNumber(absAmount, tokenDecimals);
|
|
269
270
|
let value = "";
|
|
270
271
|
const baseDecimals = isStable ? 2 : 4;
|
|
271
272
|
if (absAmountFloat >= 1)
|
|
272
|
-
value = (0, exports.formatAmount)(
|
|
273
|
+
value = (0, exports.formatAmount)(absAmount, tokenDecimals, baseDecimals, true);
|
|
273
274
|
else if (absAmountFloat >= 0.1)
|
|
274
|
-
value = (0, exports.formatAmount)(
|
|
275
|
+
value = (0, exports.formatAmount)(absAmount, tokenDecimals, baseDecimals + 1, true);
|
|
275
276
|
else if (absAmountFloat >= 0.01)
|
|
276
|
-
value = (0, exports.formatAmount)(
|
|
277
|
+
value = (0, exports.formatAmount)(absAmount, tokenDecimals, baseDecimals + 2, true);
|
|
277
278
|
else if (absAmountFloat >= 0.001)
|
|
278
|
-
value = (0, exports.formatAmount)(
|
|
279
|
+
value = (0, exports.formatAmount)(absAmount, tokenDecimals, baseDecimals + 3, true);
|
|
279
280
|
else if (absAmountFloat >= 1e-8)
|
|
280
|
-
value = (0, exports.formatAmount)(
|
|
281
|
+
value = (0, exports.formatAmount)(absAmount, tokenDecimals, 8, true);
|
|
281
282
|
else {
|
|
282
283
|
if (toExponential) {
|
|
283
|
-
value = bigintToNumber(
|
|
284
|
+
value = bigintToNumber(absAmount, tokenDecimals).toExponential(2);
|
|
284
285
|
}
|
|
285
286
|
else {
|
|
286
|
-
value = bigintToNumber(
|
|
287
|
+
value = bigintToNumber(absAmount, tokenDecimals).toFixed(8);
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
if (tokenSymbol) {
|
|
290
291
|
// Non-breaking space
|
|
291
|
-
return `${value} ${tokenSymbol}`;
|
|
292
|
+
return `${sign}${value} ${tokenSymbol}`;
|
|
292
293
|
}
|
|
293
|
-
return value
|
|
294
|
+
return `${sign}${value}`;
|
|
294
295
|
}
|
|
295
296
|
exports.formatBalanceAmount = formatBalanceAmount;
|
|
296
297
|
function formatFactor(factor) {
|
|
@@ -308,13 +309,13 @@ function formatFactor(factor) {
|
|
|
308
309
|
return (0, exports.formatAmount)(factor, 30, factorDecimals);
|
|
309
310
|
}
|
|
310
311
|
exports.formatFactor = formatFactor;
|
|
311
|
-
function numberWithCommas(x) {
|
|
312
|
+
function numberWithCommas(x, { showDollar = false } = {}) {
|
|
312
313
|
if (x === undefined || x === null) {
|
|
313
314
|
return "...";
|
|
314
315
|
}
|
|
315
316
|
const parts = x.toString().split(".");
|
|
316
317
|
parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
317
|
-
return parts.join(".")
|
|
318
|
+
return `${showDollar ? "$\u200a" : ""}${parts.join(".")}`;
|
|
318
319
|
}
|
|
319
320
|
exports.numberWithCommas = numberWithCommas;
|
|
320
321
|
const formatAmount = (amount, tokenDecimals, displayDecimals, useCommas, defaultValue, visualMultiplier) => {
|
|
@@ -7,6 +7,7 @@ exports.getIsInvalidBatchReceiver = exports.getBatchIsNativePayment = exports.ge
|
|
|
7
7
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
9
|
const ExchangeRouter_json_1 = __importDefault(require("../abis/ExchangeRouter.json"));
|
|
10
|
+
const index_1 = require("../abis/index");
|
|
10
11
|
const Token_json_1 = __importDefault(require("../abis/Token.json"));
|
|
11
12
|
const chains_1 = require("../configs/chains");
|
|
12
13
|
const contracts_1 = require("../configs/contracts");
|
|
@@ -48,6 +49,7 @@ function buildSwapOrderPayload(p) {
|
|
|
48
49
|
shouldUnwrapNativeToken: tokenTransfersParams.isNativePayment || tokenTransfersParams.isNativeReceive,
|
|
49
50
|
autoCancel: p.autoCancel,
|
|
50
51
|
referralCode: p.referralCode ?? viem_1.zeroHash,
|
|
52
|
+
dataList: [],
|
|
51
53
|
};
|
|
52
54
|
return {
|
|
53
55
|
params: p,
|
|
@@ -103,6 +105,7 @@ function buildIncreaseOrderPayload(p) {
|
|
|
103
105
|
shouldUnwrapNativeToken: tokenTransfersParams.isNativePayment,
|
|
104
106
|
autoCancel: p.autoCancel,
|
|
105
107
|
referralCode: p.referralCode ?? viem_1.zeroHash,
|
|
108
|
+
dataList: [],
|
|
106
109
|
};
|
|
107
110
|
return {
|
|
108
111
|
params: p,
|
|
@@ -154,6 +157,7 @@ function buildDecreaseOrderPayload(p) {
|
|
|
154
157
|
shouldUnwrapNativeToken: p.receiveTokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS,
|
|
155
158
|
autoCancel: p.autoCancel,
|
|
156
159
|
referralCode: p.referralCode ?? viem_1.zeroHash,
|
|
160
|
+
dataList: [],
|
|
157
161
|
};
|
|
158
162
|
return {
|
|
159
163
|
params: p,
|
|
@@ -588,7 +592,7 @@ function buildCancelOrderMulticall({ params }) {
|
|
|
588
592
|
exports.buildCancelOrderMulticall = buildCancelOrderMulticall;
|
|
589
593
|
function encodeExchangeRouterMulticall(multicall) {
|
|
590
594
|
const encodedMulticall = multicall.map((call) => (0, viem_1.encodeFunctionData)({
|
|
591
|
-
abi:
|
|
595
|
+
abi: index_1.abis.ExchangeRouter,
|
|
592
596
|
functionName: call.method,
|
|
593
597
|
args: call.params,
|
|
594
598
|
}));
|