@gmx-io/sdk 2.3.2 → 2.6.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/scripts/generate-synthetics-abis.js +17 -2
- package/build/cjs/src/abis/CustomErrors.js +98 -0
- package/build/cjs/src/abis/CustomErrorsV2_2_1.js +5565 -0
- package/build/cjs/src/abis/ExchangeRouterV2_2_1.js +1462 -0
- package/build/cjs/src/abis/GelatoRelayRouterV2_2_1.js +1945 -0
- package/build/cjs/src/abis/GlvReaderV2_2_1.js +1681 -0
- package/build/cjs/src/abis/MultichainClaimsRouterV2_2_1.js +1281 -0
- package/build/cjs/src/abis/MultichainGlvRouterV2_2_1.js +1176 -0
- package/build/cjs/src/abis/MultichainGmRouterV2_2_1.js +1480 -0
- package/build/cjs/src/abis/MultichainOrderRouterV2_2_1.js +2065 -0
- package/build/cjs/src/abis/MultichainSubaccountRouterV2_2_1.js +2160 -0
- package/build/cjs/src/abis/MultichainTransferRouterV2_2_1.js +1033 -0
- package/build/cjs/src/abis/RelayParamsV2_2_1.js +56 -0
- package/build/cjs/src/abis/RewardRouterV3.js +675 -0
- package/build/cjs/src/abis/SubaccountGelatoRelayRouterV2_2_1.js +2502 -0
- package/build/cjs/src/abis/SyntheticsReaderV2_2_1.js +5279 -0
- package/build/cjs/src/abis/__tests__/fixtures/arbitrumSepoliaReaders.json +8 -0
- package/build/cjs/src/abis/__tests__/getAbi.spec.js +84 -0
- package/build/cjs/src/abis/getAbi.js +42 -0
- package/build/cjs/src/abis/index.js +4 -1
- package/build/cjs/src/clients/v1/modules/orders/orders.js +5 -3
- package/build/cjs/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
- package/build/cjs/src/clients/v1/modules/orders/transactions/updateOrderTxn.js +21 -25
- package/build/cjs/src/clients/v1/modules/orders/utils.js +6 -7
- package/build/cjs/src/clients/v1/modules/trades/trades.js +4 -3
- package/build/cjs/src/clients/v1/multicall.js +2 -1
- package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +0 -2
- package/build/cjs/src/clients/v2/__tests__/editCancel.spec.js +0 -3
- package/build/cjs/src/clients/v2/__tests__/globalCleanup.js +0 -1
- package/build/cjs/src/clients/v2/__tests__/increase.spec.js +0 -2
- package/build/cjs/src/clients/v2/__tests__/subaccountLifecycle.spec.js +0 -1
- package/build/cjs/src/clients/v2/__tests__/testUtil.js +0 -1
- package/build/cjs/src/configs/__tests__/markets.spec.js +8 -1
- package/build/cjs/src/configs/chains.js +16 -1
- package/build/cjs/src/configs/contracts.js +27 -18
- package/build/cjs/src/configs/dataStore.js +13 -3
- package/build/cjs/src/configs/markets.js +12 -7
- package/build/cjs/src/configs/tokens.js +12 -7
- package/build/cjs/src/utils/__tests__/address.spec.js +50 -0
- package/build/cjs/src/utils/__tests__/numbers.spec.js +24 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +41 -4
- package/build/cjs/src/utils/__tests__/orderTransactions/updateOrder.spec.js +4 -0
- package/build/cjs/src/utils/__tests__/parseError.spec.js +61 -0
- package/build/cjs/src/utils/__tests__/referrals.spec.js +36 -4
- package/build/cjs/src/utils/address/index.js +17 -0
- package/build/cjs/src/utils/address/utils.js +32 -0
- package/build/cjs/src/utils/errors/parseError.js +10 -0
- package/build/cjs/src/utils/errors/transactionsErrors.js +23 -0
- package/build/cjs/src/utils/express/utils/batchOrderUtils.js +14 -9
- package/build/cjs/src/utils/express/utils/bridgeOutUtils.js +52 -17
- package/build/cjs/src/utils/express/utils/referralUtils.js +38 -25
- package/build/cjs/src/utils/express/utils/relayParamsUtils.js +11 -3
- package/build/cjs/src/utils/markets/__tests__/multicall.spec.js +27 -0
- package/build/cjs/src/utils/markets/multicall.js +5 -7
- package/build/cjs/src/utils/multichain/api.js +17 -8
- package/build/cjs/src/utils/numbers/utils.js +7 -1
- package/build/cjs/src/utils/orderTransactions/api.js +3 -4
- package/build/cjs/src/utils/orderTransactions/utils.js +8 -7
- package/build/cjs/src/utils/orders/utils.js +8 -1
- package/build/cjs/src/utils/paxos/__tests__/api.spec.js +23 -3
- package/build/cjs/src/utils/paxos/api.js +6 -0
- package/build/cjs/src/utils/referrals/utils.js +24 -15
- package/build/cjs/src/utils/subaccount/getEmptySubaccountApproval.js +2 -0
- package/build/cjs/src/utils/subaccount/getSubaccountApprovalTypedData.js +37 -15
- package/build/cjs/src/utils/subaccount/hashSubaccountApproval.js +32 -18
- package/build/cjs/src/utils/subaccount/index.js +4 -1
- package/build/cjs/src/utils/subaccount/sdkClient.js +1 -1
- package/build/cjs/src/utils/subaccount/state.js +10 -1
- package/build/cjs/src/utils/swap/preparedSwapData.js +6 -4
- package/build/cjs/src/utils/swap/swapPath.js +1 -1
- package/build/cjs/src/utils/trade/__tests__/decreaseMarginCheck.spec.js +224 -0
- package/build/cjs/src/utils/trade/__tests__/getMaxWithdrawAmount.spec.js +128 -9
- package/build/cjs/src/utils/trade/decrease.js +198 -33
- package/build/cjs/src/utils/trade/decreaseMarginCheck.js +157 -0
- package/build/cjs/src/utils/trade/increaseMarginCheck.js +27 -15
- package/build/cjs/src/utils/trade/index.js +1 -0
- package/build/cjs/src/utils/tradeHistory/utils.js +6 -6
- package/build/esm/scripts/generate-synthetics-abis.js +17 -2
- package/build/esm/src/abis/CustomErrors.js +98 -0
- package/build/esm/src/abis/CustomErrorsV2_2_1.js +5563 -0
- package/build/esm/src/abis/ExchangeRouterV2_2_1.js +1460 -0
- package/build/esm/src/abis/GelatoRelayRouterV2_2_1.js +1943 -0
- package/build/esm/src/abis/GlvReaderV2_2_1.js +1679 -0
- package/build/esm/src/abis/MultichainClaimsRouterV2_2_1.js +1279 -0
- package/build/esm/src/abis/MultichainGlvRouterV2_2_1.js +1174 -0
- package/build/esm/src/abis/MultichainGmRouterV2_2_1.js +1478 -0
- package/build/esm/src/abis/MultichainOrderRouterV2_2_1.js +2063 -0
- package/build/esm/src/abis/MultichainSubaccountRouterV2_2_1.js +2158 -0
- package/build/esm/src/abis/MultichainTransferRouterV2_2_1.js +1031 -0
- package/build/esm/src/abis/RelayParamsV2_2_1.js +54 -0
- package/build/esm/src/abis/RewardRouterV3.js +673 -0
- package/build/esm/src/abis/SubaccountGelatoRelayRouterV2_2_1.js +2500 -0
- package/build/esm/src/abis/SyntheticsReaderV2_2_1.js +5277 -0
- package/build/esm/src/abis/__tests__/fixtures/arbitrumSepoliaReaders.json +8 -0
- package/build/esm/src/abis/__tests__/getAbi.spec.js +79 -0
- package/build/esm/src/abis/getAbi.js +35 -0
- package/build/esm/src/abis/index.js +4 -1
- package/build/esm/src/clients/v1/modules/orders/orders.js +5 -3
- package/build/esm/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.js +3 -1
- package/build/esm/src/clients/v1/modules/orders/transactions/updateOrderTxn.js +21 -25
- package/build/esm/src/clients/v1/modules/orders/utils.js +6 -7
- package/build/esm/src/clients/v1/modules/trades/trades.js +4 -3
- package/build/esm/src/clients/v1/multicall.js +2 -1
- package/build/esm/src/clients/v2/__tests__/decrease.spec.js +0 -2
- package/build/esm/src/clients/v2/__tests__/editCancel.spec.js +0 -3
- package/build/esm/src/clients/v2/__tests__/globalCleanup.js +0 -1
- package/build/esm/src/clients/v2/__tests__/increase.spec.js +0 -2
- package/build/esm/src/clients/v2/__tests__/subaccountLifecycle.spec.js +0 -1
- package/build/esm/src/clients/v2/__tests__/testUtil.js +0 -1
- package/build/esm/src/configs/__tests__/markets.spec.js +9 -2
- package/build/esm/src/configs/chains.js +14 -0
- package/build/esm/src/configs/contracts.js +25 -17
- package/build/esm/src/configs/dataStore.js +8 -0
- package/build/esm/src/configs/markets.js +13 -8
- package/build/esm/src/configs/tokens.js +13 -8
- package/build/esm/src/utils/__tests__/address.spec.js +48 -0
- package/build/esm/src/utils/__tests__/numbers.spec.js +25 -1
- package/build/esm/src/utils/__tests__/orderTransactions/exchangeRouterMulticall.spec.js +43 -6
- package/build/esm/src/utils/__tests__/orderTransactions/updateOrder.spec.js +5 -1
- package/build/esm/src/utils/__tests__/parseError.spec.js +62 -1
- package/build/esm/src/utils/__tests__/referrals.spec.js +37 -5
- package/build/esm/src/utils/address/index.js +1 -0
- package/build/esm/src/utils/address/utils.js +25 -0
- package/build/esm/src/utils/errors/parseError.js +11 -1
- package/build/esm/src/utils/errors/transactionsErrors.js +23 -0
- package/build/esm/src/utils/express/utils/batchOrderUtils.js +14 -9
- package/build/esm/src/utils/express/utils/bridgeOutUtils.js +53 -18
- package/build/esm/src/utils/express/utils/referralUtils.js +37 -25
- package/build/esm/src/utils/express/utils/relayParamsUtils.js +10 -5
- package/build/esm/src/utils/markets/__tests__/multicall.spec.js +25 -0
- package/build/esm/src/utils/markets/multicall.js +5 -7
- package/build/esm/src/utils/multichain/api.js +15 -7
- package/build/esm/src/utils/numbers/utils.js +5 -0
- package/build/esm/src/utils/orderTransactions/api.js +3 -4
- package/build/esm/src/utils/orderTransactions/utils.js +9 -8
- package/build/esm/src/utils/orders/utils.js +6 -0
- package/build/esm/src/utils/paxos/__tests__/api.spec.js +23 -3
- package/build/esm/src/utils/paxos/api.js +6 -0
- package/build/esm/src/utils/referrals/utils.js +23 -15
- package/build/esm/src/utils/subaccount/getEmptySubaccountApproval.js +2 -0
- package/build/esm/src/utils/subaccount/getSubaccountApprovalTypedData.js +36 -14
- package/build/esm/src/utils/subaccount/hashSubaccountApproval.js +32 -18
- package/build/esm/src/utils/subaccount/index.js +2 -2
- package/build/esm/src/utils/subaccount/sdkClient.js +2 -2
- package/build/esm/src/utils/subaccount/state.js +8 -0
- package/build/esm/src/utils/swap/preparedSwapData.js +6 -4
- package/build/esm/src/utils/swap/swapPath.js +2 -2
- package/build/esm/src/utils/trade/__tests__/decreaseMarginCheck.spec.js +222 -0
- package/build/esm/src/utils/trade/__tests__/getMaxWithdrawAmount.spec.js +129 -10
- package/build/esm/src/utils/trade/decrease.js +195 -32
- package/build/esm/src/utils/trade/decreaseMarginCheck.js +152 -0
- package/build/esm/src/utils/trade/increaseMarginCheck.js +25 -14
- package/build/esm/src/utils/trade/index.js +1 -0
- package/build/esm/src/utils/tradeHistory/utils.js +6 -6
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/types/scripts/generate-synthetics-abis.d.ts +6 -0
- package/build/types/src/abis/CustomErrors.d.ts +160 -0
- package/build/types/src/abis/CustomErrorsV2_2_1.d.ts +4174 -0
- package/build/types/src/abis/ExchangeRouterV2_2_1.d.ts +1128 -0
- package/build/types/src/abis/GelatoRelayRouterV2_2_1.d.ts +1508 -0
- package/build/types/src/abis/GlvReaderV2_2_1.d.ts +1293 -0
- package/build/types/src/abis/MultichainClaimsRouterV2_2_1.d.ts +985 -0
- package/build/types/src/abis/MultichainGlvRouterV2_2_1.d.ts +906 -0
- package/build/types/src/abis/MultichainGmRouterV2_2_1.d.ts +1142 -0
- package/build/types/src/abis/MultichainOrderRouterV2_2_1.d.ts +1601 -0
- package/build/types/src/abis/MultichainSubaccountRouterV2_2_1.d.ts +1678 -0
- package/build/types/src/abis/MultichainTransferRouterV2_2_1.d.ts +793 -0
- package/build/types/src/abis/RelayParamsV2_2_1.d.ts +118 -0
- package/build/types/src/abis/RewardRouterV3.d.ts +1129 -0
- package/build/types/src/abis/SubaccountGelatoRelayRouterV2_2_1.d.ts +1946 -0
- package/build/types/src/abis/SyntheticsReaderV2_2_1.d.ts +4075 -0
- package/build/types/src/abis/__tests__/getAbi.spec.d.ts +1 -0
- package/build/types/src/abis/getAbi.d.ts +17051 -0
- package/build/types/src/abis/index.d.ts +6700 -4744
- package/build/types/src/clients/v1/modules/orders/transactions/createIncreaseOrderTxn.d.ts +2 -1
- package/build/types/src/clients/v1/modules/orders/transactions/updateOrderTxn.d.ts +8 -3
- package/build/types/src/configs/chains.d.ts +6 -2
- package/build/types/src/configs/contracts.d.ts +6 -0
- package/build/types/src/configs/dataStore.d.ts +4 -0
- package/build/types/src/configs/markets.d.ts +4 -4
- package/build/types/src/utils/__tests__/address.spec.d.ts +1 -0
- package/build/types/src/utils/address/index.d.ts +1 -0
- package/build/types/src/utils/address/utils.d.ts +11 -0
- package/build/types/src/utils/errors/transactionsErrors.d.ts +18 -1
- package/build/types/src/utils/express/types.d.ts +1 -0
- package/build/types/src/utils/express/utils/batchOrderUtils.d.ts +4 -3
- package/build/types/src/utils/express/utils/bridgeOutUtils.d.ts +8 -2
- package/build/types/src/utils/express/utils/referralUtils.d.ts +21 -0
- package/build/types/src/utils/markets/__tests__/multicall.spec.d.ts +1 -0
- package/build/types/src/utils/multichain/api.d.ts +8 -0
- package/build/types/src/utils/numbers/utils.d.ts +1 -0
- package/build/types/src/utils/orderTransactions/api.d.ts +1 -3
- package/build/types/src/utils/orderTransactions/utils.d.ts +5 -2
- package/build/types/src/utils/orders/utils.d.ts +1 -0
- package/build/types/src/utils/paxos/types.d.ts +2 -0
- package/build/types/src/utils/referrals/utils.d.ts +7 -1
- package/build/types/src/utils/subaccount/api.d.ts +1 -0
- package/build/types/src/utils/subaccount/getSubaccountApprovalTypedData.d.ts +4 -0
- package/build/types/src/utils/subaccount/hashSubaccountApproval.d.ts +2 -1
- package/build/types/src/utils/subaccount/index.d.ts +2 -2
- package/build/types/src/utils/subaccount/state.d.ts +2 -1
- package/build/types/src/utils/subaccount/types.d.ts +3 -1
- package/build/types/src/utils/trade/__tests__/decreaseMarginCheck.spec.d.ts +1 -0
- package/build/types/src/utils/trade/decrease.d.ts +18 -0
- package/build/types/src/utils/trade/decreaseMarginCheck.d.ts +52 -0
- package/build/types/src/utils/trade/increaseMarginCheck.d.ts +11 -1
- package/build/types/src/utils/trade/index.d.ts +1 -0
- package/build/types/src/utils/trade/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export const CONTRACTS = {
|
|
|
8
8
|
Reader: "0x2b43c90D1B727cEe1Df34925bcd5Ace52Ec37694",
|
|
9
9
|
GlpManager: "0x3963FfC9dff443c2A94f21b129D429891E32ec18",
|
|
10
10
|
RewardRouter: "0x5E4766F932ce00aA4a1A82d3Da85adf15C5694A1",
|
|
11
|
+
RewardRouterV3: "0xF6Ba2B1a33c5bdA5D7Cd5FD971E859430F465719",
|
|
11
12
|
GlpRewardRouter: "0xB95DB5B167D75e6d04227CfFFA61069348d271F5",
|
|
12
13
|
RewardReader: "0x8BFb8e82Ee4569aee78D03235ff465Bd436D40E0",
|
|
13
14
|
GovToken: "0x2A29D3a792000750807cc401806d6fd539928481",
|
|
@@ -74,6 +75,7 @@ export const CONTRACTS = {
|
|
|
74
75
|
Reader: "0x2eFEE1950ededC65De687b40Fd30a7B5f4544aBd",
|
|
75
76
|
GlpManager: "0xD152c7F25db7F4B95b7658323c5F33d176818EE4",
|
|
76
77
|
RewardRouter: "0x091eD806490Cc58Fd514441499e58984cCce0630",
|
|
78
|
+
RewardRouterV3: "0xcA9b890200c9de2fD36a69f0EDaE22665DC729cD",
|
|
77
79
|
GlpRewardRouter: "0xB70B91CE0771d3f4c81D87660f71Da31d48eB3B3",
|
|
78
80
|
RewardReader: "0x04Fc11Bd28763872d143637a7c768bD96E44c1b6",
|
|
79
81
|
GovToken: "0x0ff183E29f1924ad10475506D7722169010CecCb",
|
|
@@ -173,6 +175,7 @@ export const CONTRACTS = {
|
|
|
173
175
|
VaultReader: zeroAddress,
|
|
174
176
|
GlpManager: zeroAddress,
|
|
175
177
|
RewardRouter: zeroAddress,
|
|
178
|
+
RewardRouterV3: zeroAddress,
|
|
176
179
|
RewardReader: zeroAddress,
|
|
177
180
|
GlpRewardRouter: zeroAddress,
|
|
178
181
|
StakedGmxTracker: zeroAddress,
|
|
@@ -207,6 +210,7 @@ export const CONTRACTS = {
|
|
|
207
210
|
Reader: zeroAddress,
|
|
208
211
|
GlpManager: zeroAddress,
|
|
209
212
|
RewardRouter: zeroAddress,
|
|
213
|
+
RewardRouterV3: zeroAddress,
|
|
210
214
|
RewardReader: zeroAddress,
|
|
211
215
|
GlpRewardRouter: zeroAddress,
|
|
212
216
|
NATIVE_TOKEN: "0x1D308089a2D1Ced3f1Ce36B1FcaF815b07217be3",
|
|
@@ -267,31 +271,31 @@ export const CONTRACTS = {
|
|
|
267
271
|
// Synthetics
|
|
268
272
|
DataStore: "0xCF4c2C4c53157BcC01A596e3788fFF69cBBCD201",
|
|
269
273
|
EventEmitter: "0xa973c2692C1556E1a3d478e745e9a75624AEDc73",
|
|
270
|
-
ExchangeRouter: "
|
|
271
|
-
SubaccountRouter: "
|
|
274
|
+
ExchangeRouter: "0x3Fb6d5429612588510341eA60AacC282dB264295",
|
|
275
|
+
SubaccountRouter: "0xb72922b646d617515ED68A30a63Fe88B51277858",
|
|
272
276
|
DepositVault: "0x809Ea82C394beB993c2b6B0d73b8FD07ab92DE5A",
|
|
273
277
|
WithdrawalVault: "0x7601c9dBbDCf1f5ED1E7Adba4EFd9f2cADa037A5",
|
|
274
278
|
OrderVault: "0x1b8AC606de71686fd2a1AEDEcb6E0EFba28909a2",
|
|
275
279
|
ShiftVault: "0x6b6F9B7B9a6b69942DAE74FB95E694ec277117af",
|
|
276
|
-
SyntheticsReader: "
|
|
280
|
+
SyntheticsReader: "0x1543f5e73b9d329d7DE25ADC98120F13D29bC53b",
|
|
277
281
|
SyntheticsRouter: "0x72F13a44C8ba16a678CAD549F17bc9e06d2B8bD2",
|
|
278
|
-
SimulationRouter: "
|
|
279
|
-
GlvReader: "
|
|
280
|
-
GlvRouter: "
|
|
282
|
+
SimulationRouter: "0x94dF25454a27237b51b72E91A41076a40b4bF3dE",
|
|
283
|
+
GlvReader: "0xdC1d1039Dc78B82Ef5e3F6F7461a30b21082FD93",
|
|
284
|
+
GlvRouter: "0x15bCdc0F55083D359dDACe542F807Ba93ba4661B",
|
|
281
285
|
GlvVault: "0x40bD50de0977c68ecB958ED4A065E14E1091ce64",
|
|
282
|
-
GelatoRelayRouter: "
|
|
283
|
-
SubaccountGelatoRelayRouter: "
|
|
284
|
-
MultichainClaimsRouter: "
|
|
285
|
-
MultichainGlvRouter: "
|
|
286
|
-
MultichainGmRouter: "
|
|
287
|
-
MultichainOrderRouter: "
|
|
288
|
-
MultichainSubaccountRouter: "
|
|
289
|
-
MultichainTransferRouter: "
|
|
286
|
+
GelatoRelayRouter: "0x0384909F08B93EB7B8Bf7c1a0b0B1c2F50233aea",
|
|
287
|
+
SubaccountGelatoRelayRouter: "0x842826C68d52Cd54b2C2Dee539C84d5249e02CA0",
|
|
288
|
+
MultichainClaimsRouter: "0xc79199213ca050ad02B07394eD2aE95257C1FF31",
|
|
289
|
+
MultichainGlvRouter: "0xb86aC18dEB4C16364820C5D7BEf76496B391bfc5",
|
|
290
|
+
MultichainGmRouter: "0x29155BFBFDe3f3a191ae6999C83cF96c7d3DD0F4",
|
|
291
|
+
MultichainOrderRouter: "0xf41C2ad38b78Ab4661093947F58179CAaCf84FB5",
|
|
292
|
+
MultichainSubaccountRouter: "0x43998d11d3C2703022d213A0888320C477d09C0d",
|
|
293
|
+
MultichainTransferRouter: "0xA51c25bE642429e6B6316075a22f11DA6a2e57E8",
|
|
290
294
|
MultichainVault: "0xCd46EF5ed7d08B345c47b5a193A719861Aa2CD91",
|
|
291
|
-
LayerZeroProvider: "
|
|
292
|
-
ChainlinkPriceFeedProvider: "
|
|
295
|
+
LayerZeroProvider: "0x3b67943bFB5aEdF411f509924EF9D2225332A62A",
|
|
296
|
+
ChainlinkPriceFeedProvider: "0x7780E11552D5d070f971C5683466F9eB110afF32",
|
|
293
297
|
ReferralStorage: "0xBbCdA58c228Bb29B5769778181c81Ac8aC546c11",
|
|
294
|
-
ClaimHandler: "
|
|
298
|
+
ClaimHandler: "0x511512C6dbD5fFC0c4f1A14E5f4De66D2BAF2d3E",
|
|
295
299
|
// External
|
|
296
300
|
Multicall: "0xD84793ae65842fFac5C20Ab8eaBD699ea1FC79F3",
|
|
297
301
|
NATIVE_TOKEN: "0x980B62Da83eFf3D4576C647993b0c1D7faf17c73",
|
|
@@ -309,6 +313,7 @@ export const CONTRACTS = {
|
|
|
309
313
|
Vault: zeroAddress,
|
|
310
314
|
PositionRouter: zeroAddress,
|
|
311
315
|
RewardRouter: zeroAddress,
|
|
316
|
+
RewardRouterV3: zeroAddress,
|
|
312
317
|
StakedGmxTracker: zeroAddress,
|
|
313
318
|
BonusGmxTracker: zeroAddress,
|
|
314
319
|
FeeGmxTracker: zeroAddress,
|
|
@@ -328,6 +333,9 @@ export const CONTRACTS = {
|
|
|
328
333
|
GlpRewardRouter: zeroAddress,
|
|
329
334
|
},
|
|
330
335
|
};
|
|
336
|
+
export function isContractsV2_2_1(chainId) {
|
|
337
|
+
return chainId === ARBITRUM_SEPOLIA;
|
|
338
|
+
}
|
|
331
339
|
export function getContract(chainId, name) {
|
|
332
340
|
if (!CONTRACTS[chainId]) {
|
|
333
341
|
throw new Error(`Unknown chainId ${chainId}`);
|
|
@@ -89,6 +89,7 @@ export const MAX_ALLOWED_SUBACCOUNT_ACTION_COUNT = hashString("MAX_ALLOWED_SUBAC
|
|
|
89
89
|
export const SUBACCOUNT_ACTION_COUNT = hashString("SUBACCOUNT_ACTION_COUNT");
|
|
90
90
|
export const SUBACCOUNT_ORDER_ACTION = hashString("SUBACCOUNT_ORDER_ACTION");
|
|
91
91
|
export const SUBACCOUNT_INTEGRATION_ID = hashString("SUBACCOUNT_INTEGRATION_ID");
|
|
92
|
+
export const SUBACCOUNT_REVOCATION_COUNTER = hashString("SUBACCOUNT_REVOCATION_COUNTER");
|
|
92
93
|
export const SUBACCOUNT_AUTO_TOP_UP_AMOUNT = hashString("SUBACCOUNT_AUTO_TOP_UP_AMOUNT");
|
|
93
94
|
export const GLV_MAX_MARKET_TOKEN_BALANCE_USD = hashString("GLV_MAX_MARKET_TOKEN_BALANCE_USD");
|
|
94
95
|
export const MIN_COLLATERAL_FACTOR_FOR_LIQUIDATION_KEY = hashString("MIN_COLLATERAL_FACTOR_FOR_LIQUIDATION");
|
|
@@ -107,6 +108,7 @@ export const SUBACCOUNT_EXPIRES_AT = hashString("SUBACCOUNT_EXPIRES_AT");
|
|
|
107
108
|
export const MULTICHAIN_BALANCE = hashString("MULTICHAIN_BALANCE");
|
|
108
109
|
export const PRICE_FEED_KEY = hashString("PRICE_FEED");
|
|
109
110
|
export const GASLESS_FEATURE_DISABLED_KEY = hashString("GASLESS_FEATURE_DISABLED");
|
|
111
|
+
export const SIGNAL_UNSTAKE_FEATURE_DISABLED_KEY = hashString("SIGNAL_UNSTAKE_FEATURE_DISABLED");
|
|
110
112
|
export const GELATO_RELAY_FEE_MULTIPLIER_FACTOR_KEY = hashString("GELATO_RELAY_FEE_MULTIPLIER_FACTOR");
|
|
111
113
|
export const REQUEST_EXPIRATION_TIME_KEY = hashString("REQUEST_EXPIRATION_TIME");
|
|
112
114
|
export const GMX_SIMULATION_ORIGIN = "0x" + keccakString("GMX SIMULATION ORIGIN").slice(-40);
|
|
@@ -335,6 +337,9 @@ export function maxLendableImpactUsdKey(market) {
|
|
|
335
337
|
export function subaccountIntegrationIdKey(account, subaccount) {
|
|
336
338
|
return hashData(["bytes32", "address", "address"], [SUBACCOUNT_INTEGRATION_ID, account, subaccount]);
|
|
337
339
|
}
|
|
340
|
+
export function subaccountRevocationCounterKey(account, subaccount) {
|
|
341
|
+
return hashData(["bytes32", "address", "address"], [SUBACCOUNT_REVOCATION_COUNTER, account, subaccount]);
|
|
342
|
+
}
|
|
338
343
|
export function subaccountAutoTopUpAmountKey(account, subaccount) {
|
|
339
344
|
return hashData(["bytes32", "address", "address"], [SUBACCOUNT_AUTO_TOP_UP_AMOUNT, account, subaccount]);
|
|
340
345
|
}
|
|
@@ -347,6 +352,9 @@ export function priceFeedKey(token) {
|
|
|
347
352
|
export function gaslessFeatureDisabledKey(module) {
|
|
348
353
|
return hashData(["bytes32", "address"], [GASLESS_FEATURE_DISABLED_KEY, module]);
|
|
349
354
|
}
|
|
355
|
+
export function signalUnstakeFeatureDisabledKey(rewardRouter) {
|
|
356
|
+
return hashData(["bytes32", "address"], [SIGNAL_UNSTAKE_FEATURE_DISABLED_KEY, rewardRouter]);
|
|
357
|
+
}
|
|
350
358
|
export function claimTermsKey(distributionId) {
|
|
351
359
|
return hashData(["bytes32", "uint256"], [CLAIM_TERMS_KEY, distributionId]);
|
|
352
360
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Avoid adding client-side code here, as it can break the build process.
|
|
4
4
|
*/
|
|
5
5
|
import { zeroAddress } from "viem";
|
|
6
|
-
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, MEGAETH } from "./chains";
|
|
6
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, MEGAETH, isSolanaNetwork, } from "./chains";
|
|
7
7
|
import { convertTokenAddress, getToken, getTokenBySymbol } from "./tokens";
|
|
8
8
|
export const SWAP_GRAPH_MAX_MARKETS_PER_TOKEN = 5;
|
|
9
9
|
export const UI_MAX_LEVERAGE_BY_MARKET = {
|
|
@@ -1292,14 +1292,19 @@ export const MARKETS = {
|
|
|
1292
1292
|
},
|
|
1293
1293
|
},
|
|
1294
1294
|
};
|
|
1295
|
+
function getMarketsConfigMap(chainId) {
|
|
1296
|
+
// Solana markets stay in the app (src/config/gmsol): SDK configs ship in the EVM main bundle
|
|
1297
|
+
return isSolanaNetwork(chainId) ? {} : MARKETS[chainId];
|
|
1298
|
+
}
|
|
1295
1299
|
export function getMarketsByChainId(chainId) {
|
|
1296
|
-
|
|
1300
|
+
const markets = getMarketsConfigMap(chainId);
|
|
1301
|
+
if (!markets) {
|
|
1297
1302
|
throw new Error(`Markets not found for chainId ${chainId}`);
|
|
1298
1303
|
}
|
|
1299
|
-
return
|
|
1304
|
+
return markets;
|
|
1300
1305
|
}
|
|
1301
1306
|
export function getMarketByLabel(chainId, label) {
|
|
1302
|
-
const marketsByAddress =
|
|
1307
|
+
const marketsByAddress = getMarketsConfigMap(chainId);
|
|
1303
1308
|
if (!marketsByAddress) {
|
|
1304
1309
|
throw new Error(`Markets not found for chainId ${chainId}`);
|
|
1305
1310
|
}
|
|
@@ -1345,10 +1350,10 @@ export const fixTokenSymbolFromMarketLabel = (chainId, symbol) => {
|
|
|
1345
1350
|
return symbol;
|
|
1346
1351
|
};
|
|
1347
1352
|
export function isMarketTokenAddress(chainId, marketTokenAddress) {
|
|
1348
|
-
return Boolean(
|
|
1353
|
+
return Boolean(getMarketsConfigMap(chainId)?.[marketTokenAddress]);
|
|
1349
1354
|
}
|
|
1350
1355
|
export function getTokenAddressByMarket(chainId, marketTokenAddress, tokenType) {
|
|
1351
|
-
const market =
|
|
1356
|
+
const market = getMarketsConfigMap(chainId)[marketTokenAddress];
|
|
1352
1357
|
if (tokenType === "index") {
|
|
1353
1358
|
return convertTokenAddress(chainId, market.indexTokenAddress, "native");
|
|
1354
1359
|
}
|
|
@@ -1366,10 +1371,10 @@ export function getTokenSymbolByMarket(chainId, marketTokenAddress, tokenType) {
|
|
|
1366
1371
|
return getToken(chainId, tokenAddress).symbol;
|
|
1367
1372
|
}
|
|
1368
1373
|
export function getIsSpotOnlyMarket(chainId, marketTokenAddress) {
|
|
1369
|
-
return
|
|
1374
|
+
return getMarketsConfigMap(chainId)[marketTokenAddress].indexTokenAddress === zeroAddress;
|
|
1370
1375
|
}
|
|
1371
1376
|
export function getMarketIsSameCollaterals(chainId, marketTokenAddress) {
|
|
1372
|
-
const market =
|
|
1377
|
+
const market = getMarketsConfigMap(chainId)[marketTokenAddress];
|
|
1373
1378
|
if (!market) {
|
|
1374
1379
|
return false;
|
|
1375
1380
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { zeroAddress } from "viem";
|
|
2
|
-
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, MEGAETH } from "./chains";
|
|
2
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA, AVALANCHE, AVALANCHE_FUJI, MEGAETH, SOLANA_NETWORK_ID, isSolanaNetwork, } from "./chains";
|
|
3
3
|
import { getContract } from "./contracts";
|
|
4
4
|
export const NATIVE_TOKEN_ADDRESS = zeroAddress;
|
|
5
5
|
export const GM_STUB_ADDRESS = "<GM-ADDRESS>";
|
|
@@ -1890,15 +1890,15 @@ export const SYNTHETIC_TOKENS = {};
|
|
|
1890
1890
|
export const TOKENS_BY_SYMBOL_MAP = {};
|
|
1891
1891
|
export const WRAPPED_TOKENS_MAP = {};
|
|
1892
1892
|
export const NATIVE_TOKENS_MAP = {};
|
|
1893
|
-
const
|
|
1894
|
-
for (let j = 0; j <
|
|
1895
|
-
const chainId =
|
|
1893
|
+
const NETWORK_IDS = [ARBITRUM, AVALANCHE, AVALANCHE_FUJI, ARBITRUM_SEPOLIA, MEGAETH, SOLANA_NETWORK_ID];
|
|
1894
|
+
for (let j = 0; j < NETWORK_IDS.length; j++) {
|
|
1895
|
+
const chainId = NETWORK_IDS[j];
|
|
1896
1896
|
TOKENS_MAP[chainId] = {};
|
|
1897
1897
|
TOKENS_BY_SYMBOL_MAP[chainId] = {};
|
|
1898
1898
|
SYNTHETIC_TOKENS[chainId] = [];
|
|
1899
1899
|
V1_TOKENS[chainId] = [];
|
|
1900
1900
|
V2_TOKENS[chainId] = [];
|
|
1901
|
-
let tokens =
|
|
1901
|
+
let tokens = getTokens(chainId);
|
|
1902
1902
|
let wrappedTokenAddress;
|
|
1903
1903
|
for (let i = 0; i < tokens.length; i++) {
|
|
1904
1904
|
const token = tokens[i];
|
|
@@ -1921,7 +1921,9 @@ for (let j = 0; j < CHAIN_IDS.length; j++) {
|
|
|
1921
1921
|
SYNTHETIC_TOKENS[chainId].push(token);
|
|
1922
1922
|
}
|
|
1923
1923
|
}
|
|
1924
|
-
|
|
1924
|
+
if (!isSolanaNetwork(chainId)) {
|
|
1925
|
+
NATIVE_TOKENS_MAP[chainId].wrappedAddress = wrappedTokenAddress;
|
|
1926
|
+
}
|
|
1925
1927
|
}
|
|
1926
1928
|
export function getSyntheticTokens(chainId) {
|
|
1927
1929
|
return SYNTHETIC_TOKENS[chainId];
|
|
@@ -1933,7 +1935,8 @@ export function getNativeToken(chainId) {
|
|
|
1933
1935
|
return NATIVE_TOKENS_MAP[chainId];
|
|
1934
1936
|
}
|
|
1935
1937
|
export function getTokens(chainId) {
|
|
1936
|
-
|
|
1938
|
+
// Solana tokens stay in the app (src/config/gmsol): SDK configs ship in the EVM main bundle
|
|
1939
|
+
return isSolanaNetwork(chainId) ? [] : TOKENS[chainId];
|
|
1937
1940
|
}
|
|
1938
1941
|
export function getV1Tokens(chainId) {
|
|
1939
1942
|
return V1_TOKENS[chainId];
|
|
@@ -2057,7 +2060,9 @@ export function getStableTokens(chainId) {
|
|
|
2057
2060
|
return getTokens(chainId).filter((t) => t.isStable);
|
|
2058
2061
|
}
|
|
2059
2062
|
export function getCategoryTokenAddresses(chainId, category) {
|
|
2060
|
-
return
|
|
2063
|
+
return getTokens(chainId)
|
|
2064
|
+
.filter((token) => token.categories?.includes(category))
|
|
2065
|
+
.map((token) => token.address);
|
|
2061
2066
|
}
|
|
2062
2067
|
export const createTokensMap = (tokens) => {
|
|
2063
2068
|
return tokens.reduce((acc, token) => {
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { isAddressEqual } from "viem";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { getAddressKey, isEvmAddress, isSameAddress, normalizeAddress } from "../address";
|
|
4
|
+
const EVM_CHECKSUMMED = "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1";
|
|
5
|
+
const EVM_LOWERCASE = EVM_CHECKSUMMED.toLowerCase();
|
|
6
|
+
const EVM_WRONG_CHECKSUM = "0x82AF49447D8a07e3bd95BD0d56f35241523fBab1";
|
|
7
|
+
const SOLANA_ADDRESS = "So11111111111111111111111111111111111111112";
|
|
8
|
+
const SOLANA_ADDRESS_CASE_CHANGED = "so11111111111111111111111111111111111111112";
|
|
9
|
+
const KEY_32 = `0x${"ab".repeat(32)}`;
|
|
10
|
+
const KEY_32_UPPER = `0x${"AB".repeat(32)}`;
|
|
11
|
+
describe("isEvmAddress", () => {
|
|
12
|
+
it("tells EVM hex from base58", () => {
|
|
13
|
+
expect(isEvmAddress(EVM_LOWERCASE)).toBe(true);
|
|
14
|
+
expect(isEvmAddress(SOLANA_ADDRESS)).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
describe("normalizeAddress", () => {
|
|
18
|
+
it("checksums EVM addresses and keeps base58 as it is", () => {
|
|
19
|
+
expect(normalizeAddress(EVM_LOWERCASE)).toBe(EVM_CHECKSUMMED);
|
|
20
|
+
expect(normalizeAddress(SOLANA_ADDRESS)).toBe(SOLANA_ADDRESS);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
describe("isSameAddress", () => {
|
|
24
|
+
it.each([
|
|
25
|
+
[EVM_CHECKSUMMED, EVM_LOWERCASE, true],
|
|
26
|
+
[EVM_CHECKSUMMED, EVM_WRONG_CHECKSUM, true],
|
|
27
|
+
[EVM_LOWERCASE, SOLANA_ADDRESS, false],
|
|
28
|
+
["", "", false],
|
|
29
|
+
["", EVM_LOWERCASE, false],
|
|
30
|
+
[undefined, undefined, false],
|
|
31
|
+
[KEY_32, KEY_32_UPPER, true],
|
|
32
|
+
[SOLANA_ADDRESS, SOLANA_ADDRESS, true],
|
|
33
|
+
[SOLANA_ADDRESS, SOLANA_ADDRESS_CASE_CHANGED, false],
|
|
34
|
+
])("isSameAddress(%s, %s) is %s", (a, b, expected) => {
|
|
35
|
+
expect(isSameAddress(a, b)).toBe(expected);
|
|
36
|
+
});
|
|
37
|
+
it("matches viem for a valid checksum and its lowercase form", () => {
|
|
38
|
+
expect(isSameAddress(EVM_CHECKSUMMED, EVM_LOWERCASE)).toBe(isAddressEqual(EVM_CHECKSUMMED, EVM_LOWERCASE));
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("getAddressKey", () => {
|
|
42
|
+
it("lowercases EVM hex, including a 32-byte key, and keeps base58 case", () => {
|
|
43
|
+
expect(getAddressKey(EVM_CHECKSUMMED)).toBe(EVM_LOWERCASE);
|
|
44
|
+
expect(getAddressKey("0xABCDEF")).toBe("0xabcdef");
|
|
45
|
+
expect(getAddressKey(KEY_32_UPPER)).toBe(KEY_32);
|
|
46
|
+
expect(getAddressKey(SOLANA_ADDRESS)).toBe(SOLANA_ADDRESS);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import { BASIS_POINTS_DIVISOR_BIGINT, USD_DECIMALS } from "../../configs/factors";
|
|
3
|
-
import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatBasisPoints, formatPriceImpactBps, formatFactor, formatNumberHuman, formatPercentage, formatTokenAmount, formatUsdPrice, getBasisPoints, isUint256, MaxUint256, numberToBigint, parseUint256DecimalString, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, parseValue, removeTrailingZeros, trimZeroDecimals, roundWithDecimals, roundUpMagnitudeDivision, roundsToZero, toBigNumberWithDecimals, formatUsd, formatUsdParts, formatDeltaUsd, formatDeltaUsdParts, formatBigUsd, formatBigUsdParts, formatUsdPriceParts, formatAmountHumanParts, formatTokenAmountWithUsd, formatTokenAmountWithUsdParts, numberWithCommas, numberWithCommasParts, numberParts, joinNumberParts, isNumberParts, USD_PART, } from "../numbers";
|
|
3
|
+
import { applyFactor, basisPointsToFloat, bigintToNumber, BN_NEGATIVE_ONE, BN_ONE, BN_ZERO, expandDecimals, formatAmount, formatAmountHuman, formatBalanceAmount, formatBasisPoints, formatPriceImpactBps, formatFactor, formatNumberHuman, formatPercentage, formatTokenAmount, formatUsdPrice, getBasisPoints, isUint256, MaxUint256, numberToBigint, parseUint256DecimalString, PERCENT_PRECISION_DECIMALS, PRECISION, PRECISION_DECIMALS, parseValue, removeTrailingZeros, trimZeroDecimals, truncateToBalanceDisplayDecimals, roundWithDecimals, roundUpMagnitudeDivision, roundsToZero, toBigNumberWithDecimals, formatUsd, formatUsdParts, formatDeltaUsd, formatDeltaUsdParts, formatBigUsd, formatBigUsdParts, formatUsdPriceParts, formatAmountHumanParts, formatTokenAmountWithUsd, formatTokenAmountWithUsdParts, numberWithCommas, numberWithCommasParts, numberParts, joinNumberParts, isNumberParts, USD_PART, } from "../numbers";
|
|
4
4
|
const ONE_USD = 1000000000000000000000000000000n;
|
|
5
5
|
describe("numbers utils", () => {
|
|
6
6
|
it("constants", () => {
|
|
@@ -330,6 +330,30 @@ describe("formatAmountHuman", () => {
|
|
|
330
330
|
expect(formatAmountHuman(ONE_USD * 1500000n, USD_DECIMALS, false, 0)).toBe("2m");
|
|
331
331
|
});
|
|
332
332
|
});
|
|
333
|
+
describe("truncateToBalanceDisplayDecimals", () => {
|
|
334
|
+
it("rounds a stable amount down to the two decimals its balance is shown with", () => {
|
|
335
|
+
// 135.938928 USDC is shown as 135.94; the largest amount that can be typed back as shown is 135.93
|
|
336
|
+
expect(truncateToBalanceDisplayDecimals(135938928n, 6, true)).toBe(135930000n);
|
|
337
|
+
expect(formatBalanceAmount(135930000n, 6, undefined, { isStable: true })).toBe("135.93");
|
|
338
|
+
});
|
|
339
|
+
it("keeps an amount that is already at display precision", () => {
|
|
340
|
+
expect(truncateToBalanceDisplayDecimals(135930000n, 6, true)).toBe(135930000n);
|
|
341
|
+
expect(truncateToBalanceDisplayDecimals(0n, 6, true)).toBe(0n);
|
|
342
|
+
});
|
|
343
|
+
it("uses the finer precision small and non-stable amounts are shown with", () => {
|
|
344
|
+
// 0.0494382912 ETH is shown with 6 decimals
|
|
345
|
+
const amount = 49438291200000000n;
|
|
346
|
+
const truncated = truncateToBalanceDisplayDecimals(amount, 18);
|
|
347
|
+
expect(truncated).toBe(49438000000000000n);
|
|
348
|
+
expect(formatBalanceAmount(truncated, 18)).toBe("0.049438");
|
|
349
|
+
});
|
|
350
|
+
it.each([135938928n, 99999999n, 1005000n, 104999n, 9999n])("never exceeds the amount and always reads back as displayed (%s)", (amount) => {
|
|
351
|
+
const truncated = truncateToBalanceDisplayDecimals(amount, 6, true);
|
|
352
|
+
const displayed = formatBalanceAmount(truncated, 6, undefined, { isStable: true, showZero: true });
|
|
353
|
+
expect(truncated).toBeLessThanOrEqual(amount);
|
|
354
|
+
expect(parseValue(displayed.replace(/,/g, ""), 6)).toBe(truncated);
|
|
355
|
+
});
|
|
356
|
+
});
|
|
333
357
|
describe("formatBalanceAmount", () => {
|
|
334
358
|
const NBSP = "\u00a0";
|
|
335
359
|
it("should display balance amount", () => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { beforeAll, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { ARBITRUM } from "../../../configs/chains";
|
|
2
|
+
import { ARBITRUM, ARBITRUM_SEPOLIA } from "../../../configs/chains";
|
|
3
3
|
import { getContract } from "../../../configs/contracts";
|
|
4
4
|
import { MARKETS } from "../../../configs/markets";
|
|
5
5
|
import { getTokenBySymbol, getWrappedToken, NATIVE_TOKEN_ADDRESS } from "../../../configs/tokens";
|
|
6
6
|
import { MOCK_GAS_PRICE, mockExternalSwap } from "../../../test/mock";
|
|
7
7
|
import { parseValue, USD_DECIMALS } from "../../numbers";
|
|
8
|
-
import { OrderType } from "../../orders/types";
|
|
8
|
+
import { DecreasePositionSwapType, OrderType } from "../../orders/types";
|
|
9
9
|
import { buildIncreaseOrderPayload, buildUpdateOrderPayload, getBatchOrderMulticallPayload, } from "../../orderTransactions";
|
|
10
10
|
beforeAll(() => {
|
|
11
11
|
vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
@@ -59,7 +59,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
59
59
|
updateOrderParams: [],
|
|
60
60
|
cancelOrderParams: [],
|
|
61
61
|
};
|
|
62
|
-
const result = getBatchOrderMulticallPayload({ params: batchParams });
|
|
62
|
+
const result = getBatchOrderMulticallPayload({ chainId: CHAIN_ID, params: batchParams });
|
|
63
63
|
expect(result.multicall).toEqual([
|
|
64
64
|
{
|
|
65
65
|
method: "sendWnt",
|
|
@@ -91,7 +91,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
91
91
|
updateOrderParams: [],
|
|
92
92
|
cancelOrderParams: [],
|
|
93
93
|
};
|
|
94
|
-
const result = getBatchOrderMulticallPayload({ params: batchParams });
|
|
94
|
+
const result = getBatchOrderMulticallPayload({ chainId: CHAIN_ID, params: batchParams });
|
|
95
95
|
expect(result.multicall).toEqual([
|
|
96
96
|
{
|
|
97
97
|
method: "sendWnt",
|
|
@@ -116,6 +116,41 @@ describe("Exchange Router Multicall", () => {
|
|
|
116
116
|
`);
|
|
117
117
|
expect(result.callData).toMatchInlineSnapshot(`"0xac9650d800000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000018000000000000000000000000000000000000000000000000000000000000000447d39aaf100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d500000000000000000000000000000000000000000000000000005af3107a4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000064e6d66ac8000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000031ef83a530fde1b38ee9a18093a333d8bbbc40d5000000000000000000000000000000000000000000000000000000003b9aca00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000364f59c48eb00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000314dc6448d9338c15b0a00000000000000000000000000000000000000000000000000000000000000003b9aca000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000448d9c199600000000000000000000000000000000000000000000000000000005af3107a400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f2742351cc0eca941ff90bf489789ee6169cbeacfdd38eba60012218fac1b7e50000000000000000000000000000000000000000000000000000000000000320000000000000000000000000123456789012345678901234567890123456789000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000098765432109876543210987654321098765432100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000100000000000000000000000070d95587d40a2caf56bd97485ab3eec10bee6336000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"`);
|
|
118
118
|
});
|
|
119
|
+
it("Update order passes the order swap type on Arbitrum Sepolia", () => {
|
|
120
|
+
const updateOrderPayload = buildUpdateOrderPayload({
|
|
121
|
+
chainId: ARBITRUM_SEPOLIA,
|
|
122
|
+
orderKey: "0x1234567890123456789012345678901234567890123456789012345678901234",
|
|
123
|
+
orderType: OrderType.LimitDecrease,
|
|
124
|
+
sizeDeltaUsd: parseValue("1000", USD_DECIMALS),
|
|
125
|
+
triggerPrice: parseValue("1200", USD_DECIMALS),
|
|
126
|
+
acceptablePrice: parseValue("1194", USD_DECIMALS),
|
|
127
|
+
minOutputAmount: 0n,
|
|
128
|
+
autoCancel: false,
|
|
129
|
+
executionFeeTopUp: 0n,
|
|
130
|
+
indexTokenAddress: getWrappedToken(ARBITRUM_SEPOLIA).address,
|
|
131
|
+
validFromTime: 0n,
|
|
132
|
+
decreasePositionSwapType: DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
|
|
133
|
+
});
|
|
134
|
+
const result = getBatchOrderMulticallPayload({
|
|
135
|
+
chainId: ARBITRUM_SEPOLIA,
|
|
136
|
+
params: { createOrderParams: [], updateOrderParams: [updateOrderPayload], cancelOrderParams: [] },
|
|
137
|
+
});
|
|
138
|
+
expect(result.multicall).toEqual([
|
|
139
|
+
{
|
|
140
|
+
method: "updateOrder",
|
|
141
|
+
params: [
|
|
142
|
+
updateOrderPayload.updatePayload.orderKey,
|
|
143
|
+
updateOrderPayload.updatePayload.sizeDeltaUsd,
|
|
144
|
+
updateOrderPayload.updatePayload.acceptablePrice,
|
|
145
|
+
updateOrderPayload.updatePayload.triggerPrice,
|
|
146
|
+
updateOrderPayload.updatePayload.minOutputAmount,
|
|
147
|
+
0n,
|
|
148
|
+
DecreasePositionSwapType.SwapPnlTokenToCollateralToken,
|
|
149
|
+
updateOrderPayload.updatePayload.autoCancel,
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
]);
|
|
153
|
+
});
|
|
119
154
|
it("Token transfers with update order top up", () => {
|
|
120
155
|
const ORDER_KEY = "0x1234567890123456789012345678901234567890123456789012345678901234";
|
|
121
156
|
const updateParams = {
|
|
@@ -130,6 +165,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
130
165
|
executionFeeTopUp: EXECUTION_FEE_AMOUNT,
|
|
131
166
|
indexTokenAddress: WETH.address,
|
|
132
167
|
validFromTime: 0n,
|
|
168
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
133
169
|
};
|
|
134
170
|
const updateOrderPayload = buildUpdateOrderPayload(updateParams);
|
|
135
171
|
const batchParams = {
|
|
@@ -137,7 +173,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
137
173
|
updateOrderParams: [updateOrderPayload],
|
|
138
174
|
cancelOrderParams: [],
|
|
139
175
|
};
|
|
140
|
-
const result = getBatchOrderMulticallPayload({ params: batchParams });
|
|
176
|
+
const result = getBatchOrderMulticallPayload({ chainId: CHAIN_ID, params: batchParams });
|
|
141
177
|
expect(result.multicall).toEqual([
|
|
142
178
|
{
|
|
143
179
|
method: "sendWnt",
|
|
@@ -208,6 +244,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
208
244
|
executionFeeTopUp: EXECUTION_FEE_AMOUNT,
|
|
209
245
|
indexTokenAddress: WETH.address,
|
|
210
246
|
validFromTime: 0n,
|
|
247
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
211
248
|
};
|
|
212
249
|
const updateOrderPayload = buildUpdateOrderPayload(updateParams);
|
|
213
250
|
const createOrderPayload1 = buildIncreaseOrderPayload(params1);
|
|
@@ -217,7 +254,7 @@ describe("Exchange Router Multicall", () => {
|
|
|
217
254
|
updateOrderParams: [updateOrderPayload],
|
|
218
255
|
cancelOrderParams: [{ orderKey: CANCEL_ORDER_KEY }],
|
|
219
256
|
};
|
|
220
|
-
const result = getBatchOrderMulticallPayload({ params: batchParams });
|
|
257
|
+
const result = getBatchOrderMulticallPayload({ chainId: CHAIN_ID, params: batchParams });
|
|
221
258
|
expect(result.multicall).toEqual([
|
|
222
259
|
{
|
|
223
260
|
method: "sendWnt",
|
|
@@ -3,7 +3,7 @@ import { ARBITRUM } from "../../../configs/chains";
|
|
|
3
3
|
import { getTokenBySymbol, getWrappedToken } from "../../../configs/tokens";
|
|
4
4
|
import { MOCK_GAS_PRICE } from "../../../test/mock";
|
|
5
5
|
import { parseValue, USD_DECIMALS } from "../../numbers";
|
|
6
|
-
import { OrderType } from "../../orders/types";
|
|
6
|
+
import { DecreasePositionSwapType, OrderType } from "../../orders/types";
|
|
7
7
|
import { buildUpdateOrderPayload } from "../../orderTransactions";
|
|
8
8
|
beforeAll(() => {
|
|
9
9
|
vi.spyOn(Math, "random").mockReturnValue(0.5);
|
|
@@ -29,6 +29,7 @@ describe("Update Order Payloads", () => {
|
|
|
29
29
|
executionFeeTopUp: 0n,
|
|
30
30
|
indexTokenAddress: WETH.address,
|
|
31
31
|
validFromTime: 0n,
|
|
32
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
32
33
|
};
|
|
33
34
|
const result = buildUpdateOrderPayload(params);
|
|
34
35
|
expect(result).toEqual({
|
|
@@ -41,6 +42,7 @@ describe("Update Order Payloads", () => {
|
|
|
41
42
|
minOutputAmount: parseValue("0.8", USDC.decimals),
|
|
42
43
|
autoCancel: false,
|
|
43
44
|
validFromTime: 0n,
|
|
45
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
44
46
|
executionFeeTopUp: 0n,
|
|
45
47
|
},
|
|
46
48
|
});
|
|
@@ -58,6 +60,7 @@ describe("Update Order Payloads", () => {
|
|
|
58
60
|
executionFeeTopUp: EXECUTION_FEE_AMOUNT,
|
|
59
61
|
indexTokenAddress: WETH.address,
|
|
60
62
|
validFromTime: 0n,
|
|
63
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
61
64
|
};
|
|
62
65
|
const result = buildUpdateOrderPayload(params);
|
|
63
66
|
expect(result).toEqual({
|
|
@@ -70,6 +73,7 @@ describe("Update Order Payloads", () => {
|
|
|
70
73
|
minOutputAmount: 0n,
|
|
71
74
|
autoCancel: false,
|
|
72
75
|
validFromTime: 0n,
|
|
76
|
+
decreasePositionSwapType: DecreasePositionSwapType.NoSwap,
|
|
73
77
|
executionFeeTopUp: EXECUTION_FEE_AMOUNT,
|
|
74
78
|
},
|
|
75
79
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CallExecutionError, ContractFunctionExecutionError, ContractFunctionRevertedError, InvalidInputRpcError, RpcRequestError, InsufficientFundsError, encodeErrorResult, } from "viem";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { abis } from "../../abis";
|
|
4
|
-
import { decodeSimulationErrorFromViemError, parseError } from "../errors";
|
|
4
|
+
import { CustomError, decodeSimulationErrorFromViemError, extendError, parseError } from "../errors";
|
|
5
5
|
import { TxErrorType } from "../errors/transactionsErrors";
|
|
6
6
|
describe("parseError", () => {
|
|
7
7
|
describe("general errors", () => {
|
|
@@ -113,6 +113,54 @@ describe("parseError", () => {
|
|
|
113
113
|
errorGroup: "Txn Error: USER_DENIED",
|
|
114
114
|
}));
|
|
115
115
|
});
|
|
116
|
+
it.each([
|
|
117
|
+
["The user rejected the request"],
|
|
118
|
+
["Request rejected"],
|
|
119
|
+
["MetaMask Typed Message Signature: User denied message signature."],
|
|
120
|
+
])("should treat EIP-1193 code 4001 as a user rejection: %s", (message) => {
|
|
121
|
+
// ethers v6 ACTION_REJECTED keeps the wallet error in info.error
|
|
122
|
+
const error = {
|
|
123
|
+
code: "ACTION_REJECTED",
|
|
124
|
+
message: "user rejected action",
|
|
125
|
+
info: { error: { code: 4001, message } },
|
|
126
|
+
};
|
|
127
|
+
expect(parseError(error)).toEqual(expect.objectContaining({
|
|
128
|
+
txErrorType: TxErrorType.UserDenied,
|
|
129
|
+
isUserError: true,
|
|
130
|
+
isUserRejectedError: true,
|
|
131
|
+
}));
|
|
132
|
+
});
|
|
133
|
+
it("should trust the ethers ACTION_REJECTED code when the wallet error has another code", () => {
|
|
134
|
+
const error = {
|
|
135
|
+
code: "ACTION_REJECTED",
|
|
136
|
+
message: "user rejected action",
|
|
137
|
+
info: { error: { code: -32603, message: "User denied message signature" } },
|
|
138
|
+
};
|
|
139
|
+
expect(parseError(error)).toEqual(expect.objectContaining({
|
|
140
|
+
errorMessage: "User denied message signature",
|
|
141
|
+
txErrorType: TxErrorType.UserDenied,
|
|
142
|
+
isUserRejectedError: true,
|
|
143
|
+
errorGroup: "Txn Error: USER_DENIED",
|
|
144
|
+
}));
|
|
145
|
+
});
|
|
146
|
+
it.each([
|
|
147
|
+
["EIP-1193", 4001],
|
|
148
|
+
["WalletConnect CAIP-25", 5000],
|
|
149
|
+
])("should treat a raw %s rejection code with an unknown message as a user rejection", (_standard, code) => {
|
|
150
|
+
const error = { code, message: "Request rejected" };
|
|
151
|
+
expect(parseError(error)).toEqual(expect.objectContaining({ txErrorType: TxErrorType.UserDenied, isUserRejectedError: true }));
|
|
152
|
+
});
|
|
153
|
+
it("should keep message patterns ahead of code 4001", () => {
|
|
154
|
+
const error = { code: 4001, message: "Request expired" };
|
|
155
|
+
expect(parseError(error)).toEqual(expect.objectContaining({ txErrorType: TxErrorType.Expired, isUserRejectedError: false }));
|
|
156
|
+
});
|
|
157
|
+
it("should not treat other EIP-1193 provider codes as a user rejection", () => {
|
|
158
|
+
const error = {
|
|
159
|
+
code: 4100,
|
|
160
|
+
message: "The requested account and/or method has not been authorized by the user.",
|
|
161
|
+
};
|
|
162
|
+
expect(parseError(error)).toEqual(expect.objectContaining({ isUserRejectedError: false }));
|
|
163
|
+
});
|
|
116
164
|
it("should handle ethers v6 insufficient funds error", () => {
|
|
117
165
|
const error = {
|
|
118
166
|
info: {
|
|
@@ -299,6 +347,19 @@ describe("parseError", () => {
|
|
|
299
347
|
}));
|
|
300
348
|
});
|
|
301
349
|
});
|
|
350
|
+
describe("custom errors", () => {
|
|
351
|
+
it("reads the contract error that the order simulation rethrows as a CustomError", () => {
|
|
352
|
+
const args = { estimatedRemainingCollateralUsd: 90n };
|
|
353
|
+
const error = extendError(new CustomError({ name: "UnableToWithdrawCollateral", message: "{}", args }), {
|
|
354
|
+
errorContext: "simulation",
|
|
355
|
+
});
|
|
356
|
+
expect(parseError(error)).toEqual(expect.objectContaining({
|
|
357
|
+
contractError: "UnableToWithdrawCollateral",
|
|
358
|
+
contractErrorArgs: args,
|
|
359
|
+
errorContext: "simulation",
|
|
360
|
+
}));
|
|
361
|
+
});
|
|
362
|
+
});
|
|
302
363
|
});
|
|
303
364
|
describe("decodeSimulationErrorFromViemError", () => {
|
|
304
365
|
it("decodes the nested SimulationRouter sentinel from ExternalCallFailed", () => {
|
|
@@ -1,16 +1,48 @@
|
|
|
1
|
-
import { zeroHash } from "viem";
|
|
1
|
+
import { padHex, stringToHex, zeroHash } from "viem";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
3
|
import { decodeReferralCode, encodeReferralCode, MAX_REFERRAL_CODE_LENGTH } from "../referrals";
|
|
4
|
+
// real codes on Arbitrum
|
|
5
|
+
const ADDRESS_CODE = "0x0000000000000000000000006076934cde1fd93bbfada76a555065886a8b159d";
|
|
6
|
+
const HASH_CODE = "0x3542f3fa9016e9921dfc406f05601f17faecc338c73eb738ebf21a825eb96747";
|
|
7
|
+
function rightPadded(text) {
|
|
8
|
+
return padHex(stringToHex(text), { size: 32, dir: "right" });
|
|
9
|
+
}
|
|
4
10
|
describe("utils/referrals", () => {
|
|
5
11
|
it("decode(encode(x)) === x", () => {
|
|
6
|
-
const code
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
expect(decoded).toEqual(code);
|
|
12
|
+
for (const code of ["test", "H4X", "test_12", "2031", "A".repeat(MAX_REFERRAL_CODE_LENGTH)]) {
|
|
13
|
+
expect(decodeReferralCode(encodeReferralCode(code))).toEqual(code);
|
|
14
|
+
}
|
|
10
15
|
});
|
|
11
16
|
it("decodeReferralCode defaults", () => {
|
|
12
17
|
expect(decodeReferralCode()).toEqual("");
|
|
13
18
|
expect(decodeReferralCode(zeroHash)).toEqual("");
|
|
19
|
+
expect(decodeReferralCode("0x74657374")).toEqual("");
|
|
20
|
+
expect(decodeReferralCode(`0x${"zz".repeat(32)}`)).toEqual("");
|
|
21
|
+
});
|
|
22
|
+
it.each([
|
|
23
|
+
// protocol codes are longer than the UI limit
|
|
24
|
+
[rightPadded("EARNED_TRADER_DISCOUNT_5"), "EARNED_TRADER_DISCOUNT_5"],
|
|
25
|
+
[`0x${"61".repeat(32)}`, "a".repeat(32)],
|
|
26
|
+
...[
|
|
27
|
+
ADDRESS_CODE,
|
|
28
|
+
HASH_CODE,
|
|
29
|
+
// non-printable byte
|
|
30
|
+
"0x7465017400000000000000000000000000000000000000000000000000000000",
|
|
31
|
+
// non-zero byte after the padding
|
|
32
|
+
"0x7465737400000000000000000000000000000000000000000000000000000001",
|
|
33
|
+
// printable text the UI can't encode back to the same bytes
|
|
34
|
+
...["my-code", "a b", "a&b", "0x6076...159d"].map(rightPadded),
|
|
35
|
+
// UTF-8 "тест"
|
|
36
|
+
"0xd182d0b5d181d182000000000000000000000000000000000000000000000000",
|
|
37
|
+
].map((hex) => [hex, hex]),
|
|
38
|
+
])("decodeReferralCode(%s) is %s PRO-4493", (hex, expected) => {
|
|
39
|
+
expect(decodeReferralCode(hex)).toEqual(expected);
|
|
40
|
+
});
|
|
41
|
+
it("encodeReferralCode keeps bytes32 hex codes, lowercased PRO-4493", () => {
|
|
42
|
+
expect(encodeReferralCode(ADDRESS_CODE)).toEqual(ADDRESS_CODE);
|
|
43
|
+
expect(encodeReferralCode(HASH_CODE)).toEqual(HASH_CODE);
|
|
44
|
+
expect(encodeReferralCode(decodeReferralCode(HASH_CODE))).toEqual(HASH_CODE);
|
|
45
|
+
expect(encodeReferralCode(HASH_CODE.toUpperCase().replace("0X", "0x"))).toEqual(HASH_CODE);
|
|
14
46
|
});
|
|
15
47
|
it("encodeReferralCode defaults", () => {
|
|
16
48
|
expect(encodeReferralCode(new Array(MAX_REFERRAL_CODE_LENGTH + 1).fill("0").join(""))).toEqual(zeroHash);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./utils";
|