@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
|
@@ -37,6 +37,10 @@ export class LRUCache {
|
|
|
37
37
|
this.recentKeys.push(key);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
delete(key) {
|
|
41
|
+
this.cache.delete(key);
|
|
42
|
+
this.recentKeys = this.recentKeys.filter((k) => k !== key);
|
|
43
|
+
}
|
|
40
44
|
updateRecentKeys(key) {
|
|
41
45
|
// Move the key to the end (most recently used) of recentKeys
|
|
42
46
|
this.recentKeys = this.recentKeys.filter((k) => k !== key);
|
|
@@ -40,4 +40,22 @@ describe("LruCache", () => {
|
|
|
40
40
|
const cache = new LRUCache(2);
|
|
41
41
|
expect(() => cache.set(123, 1)).toThrow("Key must be a string");
|
|
42
42
|
});
|
|
43
|
+
it("should delete a key and remove it from recent keys", () => {
|
|
44
|
+
const cache = new LRUCache(2);
|
|
45
|
+
cache.set("a", 1);
|
|
46
|
+
cache.set("b", 2);
|
|
47
|
+
cache.delete("a");
|
|
48
|
+
expect(cache.has("a")).toBe(false);
|
|
49
|
+
expect(cache.get("a")).toBeUndefined();
|
|
50
|
+
cache.set("c", 3);
|
|
51
|
+
expect(cache.has("b")).toBe(true);
|
|
52
|
+
expect(cache.has("c")).toBe(true);
|
|
53
|
+
});
|
|
54
|
+
it("should handle deletion of non-existent key", () => {
|
|
55
|
+
const cache = new LRUCache(2);
|
|
56
|
+
cache.set("a", 1);
|
|
57
|
+
cache.delete("x");
|
|
58
|
+
expect(cache.has("a")).toBe(true);
|
|
59
|
+
expect(cache.get("a")).toBe(1);
|
|
60
|
+
});
|
|
43
61
|
});
|
|
@@ -192,18 +192,18 @@ describe("formatUsdPrice", () => {
|
|
|
192
192
|
expect(formatUsdPrice(-1n)).toBe("NA");
|
|
193
193
|
});
|
|
194
194
|
it("should calculate correct decimals if displayDecimals not passed", () => {
|
|
195
|
-
expect(formatUsdPrice(ONE_USD * 10000n)).toBe("
|
|
196
|
-
expect(formatUsdPrice(ONE_USD * 1000n)).toBe("
|
|
197
|
-
expect(formatUsdPrice(ONE_USD * 100n)).toBe("
|
|
198
|
-
expect(formatUsdPrice(ONE_USD * 10n)).toBe("
|
|
199
|
-
expect(formatUsdPrice(ONE_USD)).toBe("
|
|
200
|
-
expect(formatUsdPrice(ONE_USD / 10n)).toBe("
|
|
201
|
-
expect(formatUsdPrice(ONE_USD / 100n)).toBe("
|
|
202
|
-
expect(formatUsdPrice(ONE_USD / 1000n)).toBe("
|
|
203
|
-
expect(formatUsdPrice(ONE_USD / 10000n)).toBe("
|
|
204
|
-
expect(formatUsdPrice(ONE_USD / 100000n)).toBe("
|
|
205
|
-
expect(formatUsdPrice(ONE_USD / 1000000000n)).toBe("
|
|
206
|
-
expect(formatUsdPrice(ONE_USD / 10000000000n)).toBe("<
|
|
195
|
+
expect(formatUsdPrice(ONE_USD * 10000n)).toBe("$\u200a10,000.00");
|
|
196
|
+
expect(formatUsdPrice(ONE_USD * 1000n)).toBe("$\u200a1,000.00");
|
|
197
|
+
expect(formatUsdPrice(ONE_USD * 100n)).toBe("$\u200a100.000");
|
|
198
|
+
expect(formatUsdPrice(ONE_USD * 10n)).toBe("$\u200a10.0000");
|
|
199
|
+
expect(formatUsdPrice(ONE_USD)).toBe("$\u200a1.0000");
|
|
200
|
+
expect(formatUsdPrice(ONE_USD / 10n)).toBe("$\u200a0.10000");
|
|
201
|
+
expect(formatUsdPrice(ONE_USD / 100n)).toBe("$\u200a0.010000");
|
|
202
|
+
expect(formatUsdPrice(ONE_USD / 1000n)).toBe("$\u200a0.0010000");
|
|
203
|
+
expect(formatUsdPrice(ONE_USD / 10000n)).toBe("$\u200a0.0001000");
|
|
204
|
+
expect(formatUsdPrice(ONE_USD / 100000n)).toBe("$\u200a0.00001000");
|
|
205
|
+
expect(formatUsdPrice(ONE_USD / 1000000000n)).toBe("$\u200a0.000000001");
|
|
206
|
+
expect(formatUsdPrice(ONE_USD / 10000000000n)).toBe("< $\u200a0.000000001");
|
|
207
207
|
});
|
|
208
208
|
});
|
|
209
209
|
describe("formatAmountHuman", () => {
|
|
@@ -218,8 +218,8 @@ describe("formatAmountHuman", () => {
|
|
|
218
218
|
expect(formatAmountHuman(-1n * ONE_USD * 1000000n, USD_DECIMALS)).toBe("-1.0m");
|
|
219
219
|
});
|
|
220
220
|
it("should display dollar sign", () => {
|
|
221
|
-
expect(formatAmountHuman(ONE_USD, USD_DECIMALS, true)).toBe("
|
|
222
|
-
expect(formatAmountHuman(-1n * ONE_USD, USD_DECIMALS, true)).toBe("
|
|
221
|
+
expect(formatAmountHuman(ONE_USD, USD_DECIMALS, true)).toBe("$\u200a1.0");
|
|
222
|
+
expect(formatAmountHuman(-1n * ONE_USD, USD_DECIMALS, true)).toBe("-$\u200a1.0");
|
|
223
223
|
});
|
|
224
224
|
it("should display decimals", () => {
|
|
225
225
|
expect(formatAmountHuman(ONE_USD * 1000n, USD_DECIMALS, false, 2)).toBe("1.00k");
|
|
@@ -263,6 +263,8 @@ describe("formatBalanceAmount", () => {
|
|
|
263
263
|
expect(formatBalanceAmount(ONE_USD / 100000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("0.00000001");
|
|
264
264
|
expect(formatBalanceAmount(ONE_USD / 1000000000n, USD_DECIMALS, undefined, { isStable: true })).toBe("1.00e-9");
|
|
265
265
|
expect(formatBalanceAmount(0n, USD_DECIMALS, undefined, { isStable: true, showZero: true })).toBe("0.00");
|
|
266
|
+
expect(formatBalanceAmount(ONE_USD, USD_DECIMALS, undefined, { isStable: true, signed: true })).toBe("+1.00");
|
|
267
|
+
expect(formatBalanceAmount(-ONE_USD, USD_DECIMALS, undefined, { isStable: true, signed: true })).toBe("-1.00");
|
|
266
268
|
expect(formatBalanceAmount(0n, USD_DECIMALS, undefined, { isStable: true, showZero: false })).toBe("-");
|
|
267
269
|
});
|
|
268
270
|
});
|
|
@@ -292,8 +294,8 @@ describe("formatPercentage", () => {
|
|
|
292
294
|
expect(formatPercentage(undefined, { fallbackToZero: true })).toBe("0.00%");
|
|
293
295
|
});
|
|
294
296
|
it("should display signed percentage", () => {
|
|
295
|
-
expect(formatPercentage(100n, { signed: true })).toBe("
|
|
296
|
-
expect(formatPercentage(-100n, { signed: true })).toBe("
|
|
297
|
+
expect(formatPercentage(100n, { signed: true })).toBe("+\u200a1.00%");
|
|
298
|
+
expect(formatPercentage(-100n, { signed: true })).toBe("-\u200a1.00%");
|
|
297
299
|
});
|
|
298
300
|
it("should format with different displayDecimals", () => {
|
|
299
301
|
expect(formatPercentage(100n, { displayDecimals: 2 })).toBe("1.00%");
|
|
@@ -84,6 +84,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
84
84
|
shouldUnwrapNativeToken: true,
|
|
85
85
|
autoCancel: false,
|
|
86
86
|
referralCode: REFERRAL_CODE,
|
|
87
|
+
dataList: [],
|
|
87
88
|
},
|
|
88
89
|
params,
|
|
89
90
|
tokenTransfersParams: {
|
|
@@ -142,6 +143,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
142
143
|
shouldUnwrapNativeToken: true,
|
|
143
144
|
autoCancel: false,
|
|
144
145
|
referralCode: REFERRAL_CODE,
|
|
146
|
+
dataList: [],
|
|
145
147
|
},
|
|
146
148
|
params,
|
|
147
149
|
tokenTransfersParams: {
|
|
@@ -199,6 +201,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
199
201
|
shouldUnwrapNativeToken: false,
|
|
200
202
|
autoCancel: false,
|
|
201
203
|
referralCode: REFERRAL_CODE,
|
|
204
|
+
dataList: [],
|
|
202
205
|
},
|
|
203
206
|
params,
|
|
204
207
|
tokenTransfersParams: {
|
|
@@ -258,6 +261,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
258
261
|
shouldUnwrapNativeToken: true,
|
|
259
262
|
autoCancel: false,
|
|
260
263
|
referralCode: REFERRAL_CODE,
|
|
264
|
+
dataList: [],
|
|
261
265
|
},
|
|
262
266
|
params,
|
|
263
267
|
tokenTransfersParams: {
|
|
@@ -319,6 +323,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
319
323
|
shouldUnwrapNativeToken: true,
|
|
320
324
|
autoCancel: true,
|
|
321
325
|
referralCode: REFERRAL_CODE,
|
|
326
|
+
dataList: [],
|
|
322
327
|
},
|
|
323
328
|
params,
|
|
324
329
|
tokenTransfersParams: {
|
|
@@ -397,6 +402,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
397
402
|
shouldUnwrapNativeToken: true,
|
|
398
403
|
autoCancel: false,
|
|
399
404
|
referralCode: REFERRAL_CODE,
|
|
405
|
+
dataList: [],
|
|
400
406
|
},
|
|
401
407
|
params: {
|
|
402
408
|
...params,
|
|
@@ -492,6 +498,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
492
498
|
shouldUnwrapNativeToken: true,
|
|
493
499
|
autoCancel: false,
|
|
494
500
|
referralCode: REFERRAL_CODE,
|
|
501
|
+
dataList: [],
|
|
495
502
|
},
|
|
496
503
|
params: {
|
|
497
504
|
...params,
|
|
@@ -568,6 +575,7 @@ describe("Decrease Order Payloads", () => {
|
|
|
568
575
|
shouldUnwrapNativeToken: true,
|
|
569
576
|
autoCancel: false,
|
|
570
577
|
referralCode: zeroHash,
|
|
578
|
+
dataList: [],
|
|
571
579
|
},
|
|
572
580
|
params,
|
|
573
581
|
tokenTransfersParams: {
|
|
@@ -71,11 +71,13 @@ describe("Exchange Router Multicall", () => {
|
|
|
71
71
|
},
|
|
72
72
|
]);
|
|
73
73
|
expect(result.value).toBe(EXECUTION_FEE_AMOUNT + parseValue("1", WETH.decimals));
|
|
74
|
-
expect(result.encodedMulticall).
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
74
|
+
expect(result.encodedMulticall).toMatchInlineSnapshot(`
|
|
75
|
+
[
|
|
76
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d50000000000000000000000000000000000000000000000000de111a6b7de4000",
|
|
77
|
+
"0xf59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000320000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee63360000000000000000000000000000000000000000000000000000000000000000",
|
|
78
|
+
]
|
|
79
|
+
`);
|
|
80
|
+
expect(result.callData).toMatchInlineSnapshot(`"0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d50000000000000000000000000000000000000000000000000de111a6b7de4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000364f59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a000000000000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000320000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"`);
|
|
79
81
|
});
|
|
80
82
|
it("Token transfers with sendWnt + sendTokens", () => {
|
|
81
83
|
const params = {
|
|
@@ -105,12 +107,14 @@ describe("Exchange Router Multicall", () => {
|
|
|
105
107
|
},
|
|
106
108
|
]);
|
|
107
109
|
expect(result.value).toBe(EXECUTION_FEE_AMOUNT);
|
|
108
|
-
expect(result.encodedMulticall).
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
expect(result.encodedMulticall).toMatchInlineSnapshot(`
|
|
111
|
+
[
|
|
112
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000",
|
|
113
|
+
"0xe6d66ac8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d5000000000000000000000000000000000000000000000000000000003b9aca00",
|
|
114
|
+
"0xf59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a00000000000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000320000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee63360000000000000000000000000000000000000000000000000000000000000000",
|
|
115
|
+
]
|
|
116
|
+
`);
|
|
117
|
+
expect(result.callData).toMatchInlineSnapshot(`"0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064e6d66ac8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d5000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000364f59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a00000000000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000320000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"`);
|
|
114
118
|
});
|
|
115
119
|
it("Token transfers with update order top up", () => {
|
|
116
120
|
const ORDER_KEY = "0x1234567890123456789012345678901234567890123456789012345678901234";
|
|
@@ -153,11 +157,13 @@ describe("Exchange Router Multicall", () => {
|
|
|
153
157
|
},
|
|
154
158
|
]);
|
|
155
159
|
expect(result.value).toBe(EXECUTION_FEE_AMOUNT);
|
|
156
|
-
expect(result.encodedMulticall).
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
160
|
+
expect(result.encodedMulticall).toMatchInlineSnapshot(`
|
|
161
|
+
[
|
|
162
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000",
|
|
163
|
+
"0xdd5baad21234567890123456789012345678901234567890123456789012345678901234000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000043defc9dca00000000000000000000000000000000000000000000000000000044364c5bb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
164
|
+
]
|
|
165
|
+
`);
|
|
166
|
+
expect(result.callData).toMatchInlineSnapshot(`"0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4dd5baad21234567890123456789012345678901234567890123456789012345678901234000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000043defc9dca00000000000000000000000000000000000000000000000000000044364c5bb000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"`);
|
|
161
167
|
});
|
|
162
168
|
it("Token transfers with multiple orders, external swaps, update and cancel", () => {
|
|
163
169
|
const params1 = {
|
|
@@ -277,20 +283,22 @@ describe("Exchange Router Multicall", () => {
|
|
|
277
283
|
},
|
|
278
284
|
]);
|
|
279
285
|
expect(result.value).toBe(EXECUTION_FEE_AMOUNT * 3n + parseValue("1", WETH.decimals));
|
|
280
|
-
expect(result.encodedMulticall).
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
286
|
+
expect(result.encodedMulticall).toMatchInlineSnapshot(`
|
|
287
|
+
[
|
|
288
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000",
|
|
289
|
+
"0x7d39aaf1000000000000000000000000389cef541397e872dc04421f166b5bc2e0b374a50000000000000000000000000000000000000000000000000de0b6b3a7640000",
|
|
290
|
+
"0xd59922b0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006352a56caadc4f1e25cd6c75970fa768a3304e640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000012345678901234567890123456789012345678900000000000000000000000001234567890123456789012345678901234567890",
|
|
291
|
+
"0xf59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000300000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
292
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000",
|
|
293
|
+
"0xe6d66ac8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000389cef541397e872dc04421f166b5bc2e0b374a5000000000000000000000000000000000000000000000000000000003b9aca00",
|
|
294
|
+
"0xd59922b0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006352a56caadc4f1e25cd6c75970fa768a3304e6400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000012345678901234567890123456789012345678900000000000000000000000001234567890123456789012345678901234567890",
|
|
295
|
+
"0xf59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000300000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
296
|
+
"0x7d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000",
|
|
297
|
+
"0xdd5baad21234567890123456789012345678901234567890123456789012345678901234000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000043defc9dca00000000000000000000000000000000000000000000000000000044364c5bb0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
298
|
+
"0x7489ec231234567890123456789012345678901234567890123456789012345678901235",
|
|
299
|
+
]
|
|
300
|
+
`);
|
|
301
|
+
expect(result.callData).toMatchInlineSnapshot(`"0xac9650d80000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000026000000000000000000000000000000000000000000000000000000000000004a0000000000000000000000000000000000000000000000000000000000000082000000000000000000000000000000000000000000000000000000000000008a000000000000000000000000000000000000000000000000000000000000009400000000000000000000000000000000000000000000000000000000000000b800000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000000f8000000000000000000000000000000000000000000000000000000000000010a000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000447d39aaf1000000000000000000000000389cef541397e872dc04421f166b5bc2e0b374a50000000000000000000000000000000000000000000000000de0b6b3a7640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000204d59922b0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006352a56caadc4f1e25cd6c75970fa768a3304e640000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000000000000000000000000000000000000000000200000000000000000000000012345678901234567890123456789012345678900000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000344f59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000300000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064e6d66ac8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831000000000000000000000000389cef541397e872dc04421f166b5bc2e0b374a5000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000204d59922b0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000001a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000006352a56caadc4f1e25cd6c75970fa768a3304e6400000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab1000000000000000000000000000000000000000000000000000000000000000200000000000000000000000012345678901234567890123456789012345678900000000000000000000000001234567890123456789012345678901234567890000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000344f59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000300000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee633600000000000000000000000082af49447d8a07e3bd95bd0d56f35241523fbab100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4dd5baad21234567890123456789012345678901234567890123456789012345678901234000000000000000000000000000000000000314dc6448d9338c15b0a0000000000000000000000000000000000000000000000000000000000043defc9dca00000000000000000000000000000000000000000000000000000044364c5bb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000247489ec23123456789012345678901234567890123456789012345678901234567890123500000000000000000000000000000000000000000000000000000000"`);
|
|
294
302
|
});
|
|
295
303
|
});
|
|
296
304
|
});
|
|
@@ -84,6 +84,7 @@ describe("Increase Order Payloads", () => {
|
|
|
84
84
|
shouldUnwrapNativeToken: true,
|
|
85
85
|
autoCancel: false,
|
|
86
86
|
referralCode: REFERRAL_CODE,
|
|
87
|
+
dataList: [],
|
|
87
88
|
},
|
|
88
89
|
params,
|
|
89
90
|
tokenTransfersParams: {
|
|
@@ -142,6 +143,7 @@ describe("Increase Order Payloads", () => {
|
|
|
142
143
|
shouldUnwrapNativeToken: true,
|
|
143
144
|
autoCancel: false,
|
|
144
145
|
referralCode: REFERRAL_CODE,
|
|
146
|
+
dataList: [],
|
|
145
147
|
},
|
|
146
148
|
params,
|
|
147
149
|
tokenTransfersParams: {
|
|
@@ -199,6 +201,7 @@ describe("Increase Order Payloads", () => {
|
|
|
199
201
|
shouldUnwrapNativeToken: false,
|
|
200
202
|
autoCancel: false,
|
|
201
203
|
referralCode: REFERRAL_CODE,
|
|
204
|
+
dataList: [],
|
|
202
205
|
},
|
|
203
206
|
params,
|
|
204
207
|
tokenTransfersParams: {
|
|
@@ -263,6 +266,7 @@ describe("Increase Order Payloads", () => {
|
|
|
263
266
|
shouldUnwrapNativeToken: false,
|
|
264
267
|
autoCancel: false,
|
|
265
268
|
referralCode: REFERRAL_CODE,
|
|
269
|
+
dataList: [],
|
|
266
270
|
},
|
|
267
271
|
params,
|
|
268
272
|
tokenTransfersParams: {
|
|
@@ -336,6 +340,7 @@ describe("Increase Order Payloads", () => {
|
|
|
336
340
|
shouldUnwrapNativeToken: true,
|
|
337
341
|
autoCancel: false,
|
|
338
342
|
referralCode: REFERRAL_CODE,
|
|
343
|
+
dataList: [],
|
|
339
344
|
},
|
|
340
345
|
params,
|
|
341
346
|
tokenTransfersParams: {
|
|
@@ -416,6 +421,7 @@ describe("Increase Order Payloads", () => {
|
|
|
416
421
|
shouldUnwrapNativeToken: false,
|
|
417
422
|
autoCancel: false,
|
|
418
423
|
referralCode: REFERRAL_CODE,
|
|
424
|
+
dataList: [],
|
|
419
425
|
},
|
|
420
426
|
params,
|
|
421
427
|
tokenTransfersParams: {
|
|
@@ -487,6 +493,7 @@ describe("Increase Order Payloads", () => {
|
|
|
487
493
|
shouldUnwrapNativeToken: true,
|
|
488
494
|
autoCancel: false,
|
|
489
495
|
referralCode: REFERRAL_CODE,
|
|
496
|
+
dataList: [],
|
|
490
497
|
},
|
|
491
498
|
params,
|
|
492
499
|
tokenTransfersParams: {
|
|
@@ -565,6 +572,7 @@ describe("Increase Order Payloads", () => {
|
|
|
565
572
|
shouldUnwrapNativeToken: true,
|
|
566
573
|
autoCancel: false,
|
|
567
574
|
referralCode: REFERRAL_CODE,
|
|
575
|
+
dataList: [],
|
|
568
576
|
},
|
|
569
577
|
params: {
|
|
570
578
|
...params,
|
|
@@ -660,6 +668,7 @@ describe("Increase Order Payloads", () => {
|
|
|
660
668
|
shouldUnwrapNativeToken: true,
|
|
661
669
|
autoCancel: false,
|
|
662
670
|
referralCode: REFERRAL_CODE,
|
|
671
|
+
dataList: [],
|
|
663
672
|
},
|
|
664
673
|
params: {
|
|
665
674
|
...params,
|
|
@@ -737,6 +746,7 @@ describe("Increase Order Payloads", () => {
|
|
|
737
746
|
shouldUnwrapNativeToken: true,
|
|
738
747
|
autoCancel: false,
|
|
739
748
|
referralCode: zeroHash,
|
|
749
|
+
dataList: [],
|
|
740
750
|
},
|
|
741
751
|
params,
|
|
742
752
|
tokenTransfersParams: {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { zeroAddress, zeroHash } from "viem";
|
|
2
|
-
import { describe, expect, it, vi
|
|
2
|
+
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
3
3
|
import { ARBITRUM } from "../../../configs/chains";
|
|
4
4
|
import { getContract } from "../../../configs/contracts";
|
|
5
5
|
import { MARKETS } from "../../../configs/markets";
|
|
@@ -78,6 +78,7 @@ describe("Swap Order Payloads", () => {
|
|
|
78
78
|
shouldUnwrapNativeToken: true,
|
|
79
79
|
autoCancel: false,
|
|
80
80
|
referralCode: REFERRAL_CODE,
|
|
81
|
+
dataList: [],
|
|
81
82
|
},
|
|
82
83
|
params,
|
|
83
84
|
tokenTransfersParams: {
|
|
@@ -140,6 +141,7 @@ describe("Swap Order Payloads", () => {
|
|
|
140
141
|
shouldUnwrapNativeToken: true,
|
|
141
142
|
autoCancel: false,
|
|
142
143
|
referralCode: REFERRAL_CODE,
|
|
144
|
+
dataList: [],
|
|
143
145
|
},
|
|
144
146
|
params,
|
|
145
147
|
tokenTransfersParams: {
|
|
@@ -207,6 +209,7 @@ describe("Swap Order Payloads", () => {
|
|
|
207
209
|
shouldUnwrapNativeToken: false,
|
|
208
210
|
autoCancel: false,
|
|
209
211
|
referralCode: REFERRAL_CODE,
|
|
212
|
+
dataList: [],
|
|
210
213
|
},
|
|
211
214
|
params,
|
|
212
215
|
tokenTransfersParams: {
|
|
@@ -275,6 +278,7 @@ describe("Swap Order Payloads", () => {
|
|
|
275
278
|
shouldUnwrapNativeToken: false,
|
|
276
279
|
autoCancel: false,
|
|
277
280
|
referralCode: REFERRAL_CODE,
|
|
281
|
+
dataList: [],
|
|
278
282
|
},
|
|
279
283
|
params,
|
|
280
284
|
tokenTransfersParams: {
|
|
@@ -364,6 +368,7 @@ describe("Swap Order Payloads", () => {
|
|
|
364
368
|
shouldUnwrapNativeToken: true,
|
|
365
369
|
autoCancel: false,
|
|
366
370
|
referralCode: REFERRAL_CODE,
|
|
371
|
+
dataList: [],
|
|
367
372
|
},
|
|
368
373
|
params: {
|
|
369
374
|
...params,
|
|
@@ -440,6 +445,7 @@ describe("Swap Order Payloads", () => {
|
|
|
440
445
|
isLong: false,
|
|
441
446
|
shouldUnwrapNativeToken: true,
|
|
442
447
|
autoCancel: false,
|
|
448
|
+
dataList: [],
|
|
443
449
|
referralCode: zeroHash,
|
|
444
450
|
},
|
|
445
451
|
params,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it, vi, beforeEach } from "vitest";
|
|
2
|
+
import { expandDecimals, USD_DECIMALS } from "../numbers";
|
|
2
3
|
import { bigMath } from "../bigmath";
|
|
3
4
|
import { getPositionFee, getPriceImpactForPosition } from "../fees";
|
|
4
5
|
import { getCappedPoolPnl, getMarketPnl, getPoolUsdWithoutPnl } from "../markets";
|
|
@@ -88,9 +89,11 @@ describe("getPositionNetValue", () => {
|
|
|
88
89
|
closingFeeUsd: 5n,
|
|
89
90
|
uiFeeUsd: 20n,
|
|
90
91
|
pnl: 200n,
|
|
92
|
+
totalPendingImpactDeltaUsd: -100n,
|
|
93
|
+
priceImpactDiffUsd: 50n,
|
|
91
94
|
});
|
|
92
|
-
// netValue = 1000n - (10n+15n) -5n -20n + 200n
|
|
93
|
-
expect(result).toBe(
|
|
95
|
+
// netValue = 1000n - (10n+15n) -5n -20n + 200n -100n + 50n = 1100n
|
|
96
|
+
expect(result).toBe(1100n);
|
|
94
97
|
});
|
|
95
98
|
});
|
|
96
99
|
describe("getLeverage", () => {
|
|
@@ -121,11 +124,16 @@ describe("getLeverage", () => {
|
|
|
121
124
|
describe("getLiquidationPrice", () => {
|
|
122
125
|
beforeEach(() => {
|
|
123
126
|
getPositionFee.mockReturnValue({ positionFeeUsd: 50n });
|
|
124
|
-
getPriceImpactForPosition.mockReturnValue(-100n);
|
|
127
|
+
getPriceImpactForPosition.mockReturnValue({ priceImpactDeltaUsd: -100n, balanceWasImproved: false });
|
|
125
128
|
getIsEquivalentTokens.mockReturnValue(false);
|
|
126
129
|
});
|
|
127
130
|
it("returns undefined if sizeInUsd <= 0 or sizeInTokens <= 0", () => {
|
|
128
|
-
const marketInfo = {
|
|
131
|
+
const marketInfo = {
|
|
132
|
+
indexToken: {
|
|
133
|
+
decimals: 18,
|
|
134
|
+
prices: { minPrice: expandDecimals(1, USD_DECIMALS), maxPrice: expandDecimals(1, USD_DECIMALS) },
|
|
135
|
+
},
|
|
136
|
+
};
|
|
129
137
|
expect(getLiquidationPrice({
|
|
130
138
|
sizeInUsd: 0n,
|
|
131
139
|
sizeInTokens: 100n,
|
|
@@ -135,6 +143,7 @@ describe("getLiquidationPrice", () => {
|
|
|
135
143
|
marketInfo,
|
|
136
144
|
pendingFundingFeesUsd: 0n,
|
|
137
145
|
pendingBorrowingFeesUsd: 0n,
|
|
146
|
+
pendingImpactAmount: 0n,
|
|
138
147
|
minCollateralUsd: 100n,
|
|
139
148
|
isLong: true,
|
|
140
149
|
userReferralInfo: undefined,
|
|
@@ -148,6 +157,7 @@ describe("getLiquidationPrice", () => {
|
|
|
148
157
|
marketInfo,
|
|
149
158
|
pendingFundingFeesUsd: 0n,
|
|
150
159
|
pendingBorrowingFeesUsd: 0n,
|
|
160
|
+
pendingImpactAmount: 0n,
|
|
151
161
|
minCollateralUsd: 100n,
|
|
152
162
|
isLong: true,
|
|
153
163
|
userReferralInfo: undefined,
|
|
@@ -155,10 +165,16 @@ describe("getLiquidationPrice", () => {
|
|
|
155
165
|
});
|
|
156
166
|
it("computes liquidation price for non-equivalent tokens and isLong=true", () => {
|
|
157
167
|
getIsEquivalentTokens.mockReturnValue(false);
|
|
168
|
+
convertToUsd.mockReturnValue(1000n);
|
|
158
169
|
const marketInfo = {
|
|
159
|
-
indexToken: {
|
|
160
|
-
|
|
170
|
+
indexToken: {
|
|
171
|
+
decimals: 8,
|
|
172
|
+
prices: { minPrice: expandDecimals(1, USD_DECIMALS), maxPrice: expandDecimals(1, USD_DECIMALS) },
|
|
173
|
+
},
|
|
174
|
+
minCollateralFactorForLiquidation: 1000n, // 0.001
|
|
161
175
|
maxPositionImpactFactorForLiquidations: 500n, // 0.005
|
|
176
|
+
maxPositionImpactFactorPositive: 1000n, // 0.01
|
|
177
|
+
maxPositionImpactFactorNegative: 1000n, // 0.01
|
|
162
178
|
};
|
|
163
179
|
const result = getLiquidationPrice({
|
|
164
180
|
sizeInUsd: 1000n,
|
|
@@ -169,6 +185,7 @@ describe("getLiquidationPrice", () => {
|
|
|
169
185
|
marketInfo,
|
|
170
186
|
pendingFundingFeesUsd: 0n,
|
|
171
187
|
pendingBorrowingFeesUsd: 0n,
|
|
188
|
+
pendingImpactAmount: 0n,
|
|
172
189
|
minCollateralUsd: 200n,
|
|
173
190
|
isLong: true,
|
|
174
191
|
userReferralInfo: undefined,
|
|
@@ -2,8 +2,12 @@ export const bigMath = {
|
|
|
2
2
|
abs(x) {
|
|
3
3
|
return x < 0n ? -x : x;
|
|
4
4
|
},
|
|
5
|
-
mulDiv(x, y, z) {
|
|
6
|
-
|
|
5
|
+
mulDiv(x, y, z, roundUpMagnitude = false) {
|
|
6
|
+
const result = (x * y) / z;
|
|
7
|
+
if (roundUpMagnitude && this.mulmod(x, y, z) > 0n) {
|
|
8
|
+
return result + 1n;
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
7
11
|
},
|
|
8
12
|
max(max, ...rest) {
|
|
9
13
|
return rest.reduce((currentMax, val) => (currentMax < val ? val : currentMax), max);
|
|
@@ -31,4 +35,7 @@ export const bigMath = {
|
|
|
31
35
|
divRoundUp(x, y) {
|
|
32
36
|
return (x + y - 1n) / y;
|
|
33
37
|
},
|
|
38
|
+
mulmod(x, y, m) {
|
|
39
|
+
return (x * y) % m;
|
|
40
|
+
},
|
|
34
41
|
};
|
|
@@ -139,3 +139,34 @@ function hasStack(error) {
|
|
|
139
139
|
function hasName(error) {
|
|
140
140
|
return !!error && typeof error === "object" && typeof error.name === "string";
|
|
141
141
|
}
|
|
142
|
+
export class CustomError extends Error {
|
|
143
|
+
constructor({ name, message, args }) {
|
|
144
|
+
super(message);
|
|
145
|
+
this.isGmxCustomError = true;
|
|
146
|
+
this.name = name;
|
|
147
|
+
this.args = args;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
export function isCustomError(error) {
|
|
151
|
+
return error?.isGmxCustomError === true;
|
|
152
|
+
}
|
|
153
|
+
export function getCustomError(error) {
|
|
154
|
+
const data = error?.info?.error?.data ?? error?.data;
|
|
155
|
+
let prettyErrorName = error.name;
|
|
156
|
+
let prettyErrorMessage = error.message;
|
|
157
|
+
let prettyErrorArgs = undefined;
|
|
158
|
+
try {
|
|
159
|
+
const parsedError = decodeErrorResult({
|
|
160
|
+
abi: abis.CustomErrors,
|
|
161
|
+
data: data,
|
|
162
|
+
});
|
|
163
|
+
prettyErrorArgs = parsedError.args;
|
|
164
|
+
prettyErrorName = parsedError.errorName;
|
|
165
|
+
prettyErrorMessage = JSON.stringify(parsedError, null, 2);
|
|
166
|
+
}
|
|
167
|
+
catch (decodeError) {
|
|
168
|
+
return error;
|
|
169
|
+
}
|
|
170
|
+
const prettyError = new CustomError({ name: prettyErrorName, message: prettyErrorMessage, args: prettyErrorArgs });
|
|
171
|
+
return prettyError;
|
|
172
|
+
}
|