@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
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { getAddress } from "viem";
|
|
2
|
+
const EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
3
|
+
const HEX_REGEX = /^0x[0-9a-fA-F]*$/;
|
|
4
|
+
/**
|
|
5
|
+
* Addresses in shared code are EVM hex or Solana base58. Base58 has no `0` in its alphabet, so it never matches.
|
|
6
|
+
* Base58 is case-sensitive, so it must never be checksummed, lowercased or compared through viem.
|
|
7
|
+
*/
|
|
8
|
+
export function isEvmAddress(address) {
|
|
9
|
+
return EVM_ADDRESS_REGEX.test(address);
|
|
10
|
+
}
|
|
11
|
+
/** Checksums an EVM address and keeps any other address as it is. */
|
|
12
|
+
export function normalizeAddress(address) {
|
|
13
|
+
return isEvmAddress(address) ? getAddress(address) : address;
|
|
14
|
+
}
|
|
15
|
+
/** Compares EVM hex case-insensitively and any other address exactly. Empty input does not match. */
|
|
16
|
+
export function isSameAddress(a, b) {
|
|
17
|
+
if (!a || !b) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
return getAddressKey(a) === getAddressKey(b);
|
|
21
|
+
}
|
|
22
|
+
/** A map or set key: lowercased for EVM hex (addresses and hashes), unchanged for base58. */
|
|
23
|
+
export function getAddressKey(address) {
|
|
24
|
+
return HEX_REGEX.test(address) ? address.toLowerCase() : address;
|
|
25
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import cryptoJs from "crypto-js";
|
|
2
2
|
import { decodeErrorResult, } from "viem";
|
|
3
3
|
import { abis } from "../../abis";
|
|
4
|
-
import { CustomErrorName, extractDataFromError, extractTxnError, getIsUserError, getIsUserRejectedError, } from "./transactionsErrors";
|
|
4
|
+
import { CustomErrorName, TxErrorType, extractDataFromError, extractTxnError, getIsUserError, getIsUserRejectedError, } from "./transactionsErrors";
|
|
5
5
|
export function extractErrorDataFromViemError(error) {
|
|
6
6
|
if (!("walk" in error && typeof error.walk === "function")) {
|
|
7
7
|
return undefined;
|
|
@@ -87,10 +87,20 @@ export function parseError(error, errorDepth = 0) {
|
|
|
87
87
|
isUserError = type ? getIsUserError(type) : false;
|
|
88
88
|
isUserRejectedError = type ? getIsUserRejectedError(type) : false;
|
|
89
89
|
}
|
|
90
|
+
// ethers already classified it as a user rejection, whatever the wallet error looks like
|
|
91
|
+
if (typeof error === "object" && error?.code === "ACTION_REJECTED") {
|
|
92
|
+
txErrorType = TxErrorType.UserDenied;
|
|
93
|
+
isUserError = true;
|
|
94
|
+
isUserRejectedError = true;
|
|
95
|
+
}
|
|
90
96
|
}
|
|
91
97
|
catch (e) {
|
|
92
98
|
//
|
|
93
99
|
}
|
|
100
|
+
if (isCustomError(error)) {
|
|
101
|
+
contractError = error.name;
|
|
102
|
+
contractErrorArgs = error.args;
|
|
103
|
+
}
|
|
94
104
|
if (!contractError) {
|
|
95
105
|
const errorData = (error && typeof error === "object" ? extractErrorDataFromViemError(error) : undefined) ??
|
|
96
106
|
extractDataFromError(errorMessage) ??
|
|
@@ -57,9 +57,14 @@ const TX_ERROR_PATTERNS = {
|
|
|
57
57
|
{ msg: "couldn't connect to the network" },
|
|
58
58
|
],
|
|
59
59
|
};
|
|
60
|
+
// EIP-1193 and WalletConnect (CAIP-25) user rejection codes, as viem maps them; ethers' BrowserProvider maps only 4001.
|
|
61
|
+
// Checked after the patterns so they only classify otherwise unknown errors
|
|
62
|
+
const USER_REJECTED_REQUEST_CODES = [4001, 5000];
|
|
60
63
|
export var CustomErrorName;
|
|
61
64
|
(function (CustomErrorName) {
|
|
62
65
|
CustomErrorName["DisabledMarket"] = "DisabledMarket";
|
|
66
|
+
CustomErrorName["EmptyDesignatedVesters"] = "EmptyDesignatedVesters";
|
|
67
|
+
CustomErrorName["EmptyStakeAmount"] = "EmptyStakeAmount";
|
|
63
68
|
CustomErrorName["EndOfOracleSimulation"] = "EndOfOracleSimulation";
|
|
64
69
|
CustomErrorName["ExternalCallFailed"] = "ExternalCallFailed";
|
|
65
70
|
CustomErrorName["InsufficientBridgeOutputAmount"] = "InsufficientBridgeOutputAmount";
|
|
@@ -74,6 +79,7 @@ export var CustomErrorName;
|
|
|
74
79
|
CustomErrorName["InsufficientReserveForOpenInterest"] = "InsufficientReserveForOpenInterest";
|
|
75
80
|
CustomErrorName["OrderNotFulfillableAtAcceptablePrice"] = "OrderNotFulfillableAtAcceptablePrice";
|
|
76
81
|
CustomErrorName["InsufficientSwapOutputAmount"] = "InsufficientSwapOutputAmount";
|
|
82
|
+
CustomErrorName["InsufficientStrictTransferAllowance"] = "InsufficientStrictTransferAllowance";
|
|
77
83
|
CustomErrorName["InvalidCollateralTokenForMarket"] = "InvalidCollateralTokenForMarket";
|
|
78
84
|
CustomErrorName["InvalidDecreaseOrderSize"] = "InvalidDecreaseOrderSize";
|
|
79
85
|
CustomErrorName["InvalidOraclePrice"] = "InvalidOraclePrice";
|
|
@@ -85,6 +91,8 @@ export var CustomErrorName;
|
|
|
85
91
|
CustomErrorName["MaxPoolUsdForDepositExceeded"] = "MaxPoolUsdForDepositExceeded";
|
|
86
92
|
CustomErrorName["MaxPriceAgeExceeded"] = "MaxPriceAgeExceeded";
|
|
87
93
|
CustomErrorName["MaxRelayFeeSwapExceeded"] = "MaxRelayFeeSwapExceeded";
|
|
94
|
+
CustomErrorName["MaxUnstakeRequestsExceeded"] = "MaxUnstakeRequestsExceeded";
|
|
95
|
+
CustomErrorName["MaxUnstakeRequestsOnTransfer"] = "MaxUnstakeRequestsOnTransfer";
|
|
88
96
|
CustomErrorName["MinPositionSize"] = "MinPositionSize";
|
|
89
97
|
CustomErrorName["NegativeExecutionPrice"] = "NegativeExecutionPrice";
|
|
90
98
|
CustomErrorName["OrderNotFound"] = "OrderNotFound";
|
|
@@ -93,11 +101,23 @@ export var CustomErrorName;
|
|
|
93
101
|
CustomErrorName["PnlFactorExceededForLongs"] = "PnlFactorExceededForLongs";
|
|
94
102
|
CustomErrorName["PnlFactorExceededForShorts"] = "PnlFactorExceededForShorts";
|
|
95
103
|
CustomErrorName["PriceImpactLargerThanOrderSize"] = "PriceImpactLargerThanOrderSize";
|
|
104
|
+
CustomErrorName["SelfVestingTransfer"] = "SelfVestingTransfer";
|
|
105
|
+
CustomErrorName["StakingReceiverNotFresh"] = "StakingReceiverNotFresh";
|
|
106
|
+
CustomErrorName["StakingSenderHasPairAmounts"] = "StakingSenderHasPairAmounts";
|
|
107
|
+
CustomErrorName["StakingSenderHasVestedTokens"] = "StakingSenderHasVestedTokens";
|
|
96
108
|
CustomErrorName["SwapPriceImpactExceedsAmountIn"] = "SwapPriceImpactExceedsAmountIn";
|
|
109
|
+
CustomErrorName["TransferNotSignalled"] = "TransferNotSignalled";
|
|
110
|
+
CustomErrorName["TransferVesterConfigChanged"] = "TransferVesterConfigChanged";
|
|
97
111
|
CustomErrorName["UnableToWithdrawCollateral"] = "UnableToWithdrawCollateral";
|
|
112
|
+
CustomErrorName["UnstakeAmountExceedsStake"] = "UnstakeAmountExceedsStake";
|
|
113
|
+
CustomErrorName["UnstakeNotSignalled"] = "UnstakeNotSignalled";
|
|
98
114
|
CustomErrorName["UsdDeltaExceedsLongOpenInterest"] = "UsdDeltaExceedsLongOpenInterest";
|
|
99
115
|
CustomErrorName["UsdDeltaExceedsPoolValue"] = "UsdDeltaExceedsPoolValue";
|
|
100
116
|
CustomErrorName["UsdDeltaExceedsShortOpenInterest"] = "UsdDeltaExceedsShortOpenInterest";
|
|
117
|
+
CustomErrorName["VesterAccountFrozen"] = "VesterAccountFrozen";
|
|
118
|
+
CustomErrorName["VesterProvisioningNotComplete"] = "VesterProvisioningNotComplete";
|
|
119
|
+
CustomErrorName["VestingReceiverNotFresh"] = "VestingReceiverNotFresh";
|
|
120
|
+
CustomErrorName["VestingSenderHasOpenSession"] = "VestingSenderHasOpenSession";
|
|
101
121
|
})(CustomErrorName || (CustomErrorName = {}));
|
|
102
122
|
export function getIsUserRejectedError(errorType) {
|
|
103
123
|
return errorType === TxErrorType.UserDenied;
|
|
@@ -144,6 +164,9 @@ export function extractTxnError(ex) {
|
|
|
144
164
|
}
|
|
145
165
|
}
|
|
146
166
|
}
|
|
167
|
+
if (typeof code === "number" && USER_REJECTED_REQUEST_CODES.includes(code)) {
|
|
168
|
+
return [message, TxErrorType.UserDenied, ex.data];
|
|
169
|
+
}
|
|
147
170
|
return [message, null, ex.data];
|
|
148
171
|
}
|
|
149
172
|
/**
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { encodeFunctionData, zeroAddress, zeroHash } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { getAbi } from "../../../abis/getAbi";
|
|
3
|
+
import { isContractsV2_2_1 } from "../../../configs/contracts";
|
|
3
4
|
import { DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION } from "../../../configs/express";
|
|
4
5
|
import { noopMetrics } from "../../metrics";
|
|
5
6
|
import { nowInSeconds } from "../../time";
|
|
6
7
|
import { setOrderDataListMetadataIsExpress } from "../../twap/uiFeeReceiver";
|
|
7
8
|
import { getGelatoRelayRouterDomain, getExpressContractAddress, hashRelayParams } from "./relayParamsUtils";
|
|
8
9
|
export function getBatchTypedData({ chainId, signingChainId, batchParams, relayParams, account, subaccountApprovalHash, relayRouterAddress, }) {
|
|
10
|
+
const isV2_2_1 = isContractsV2_2_1(chainId);
|
|
9
11
|
const types = {
|
|
10
12
|
Batch: [
|
|
11
13
|
{ name: "account", type: "address" },
|
|
@@ -52,14 +54,15 @@ export function getBatchTypedData({ chainId, signingChainId, batchParams, relayP
|
|
|
52
54
|
{ name: "triggerPrice", type: "uint256" },
|
|
53
55
|
{ name: "minOutputAmount", type: "uint256" },
|
|
54
56
|
{ name: "validFromTime", type: "uint256" },
|
|
57
|
+
...(isV2_2_1 ? [{ name: "decreasePositionSwapType", type: "uint256" }] : []),
|
|
55
58
|
{ name: "autoCancel", type: "bool" },
|
|
56
59
|
{ name: "executionFeeIncrease", type: "uint256" },
|
|
57
60
|
],
|
|
58
61
|
};
|
|
59
62
|
const domain = getGelatoRelayRouterDomain(signingChainId ?? chainId, relayRouterAddress);
|
|
60
|
-
const paramsLists = getBatchParamsLists(batchParams);
|
|
63
|
+
const paramsLists = getBatchParamsLists(chainId, batchParams);
|
|
61
64
|
const message = {
|
|
62
|
-
account: subaccountApprovalHash ? account : zeroAddress,
|
|
65
|
+
account: subaccountApprovalHash || isV2_2_1 ? account : zeroAddress,
|
|
63
66
|
createOrderParamsList: paramsLists.createOrderParamsList,
|
|
64
67
|
updateOrderParamsList: paramsLists.updateOrderParamsList,
|
|
65
68
|
cancelOrderKeys: paramsLists.cancelOrderKeys,
|
|
@@ -77,7 +80,7 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
77
80
|
...relayParams,
|
|
78
81
|
signature,
|
|
79
82
|
};
|
|
80
|
-
const paramsLists = getBatchParamsLists(batchParams);
|
|
83
|
+
const paramsLists = getBatchParamsLists(chainId, batchParams);
|
|
81
84
|
const isSubaccount = subaccountApproval !== undefined;
|
|
82
85
|
const isMultichain = isGmxAccount && srcChainId !== undefined;
|
|
83
86
|
const relayRouterAddress = getExpressContractAddress(chainId, {
|
|
@@ -89,7 +92,7 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
89
92
|
if (isMultichain) {
|
|
90
93
|
if (isSubaccount) {
|
|
91
94
|
callData = encodeFunctionData({
|
|
92
|
-
abi:
|
|
95
|
+
abi: getAbi(chainId, "MultichainSubaccountRouter"),
|
|
93
96
|
functionName: "batch",
|
|
94
97
|
args: [
|
|
95
98
|
relayParamsWithSignature,
|
|
@@ -103,7 +106,7 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
103
106
|
}
|
|
104
107
|
else {
|
|
105
108
|
callData = encodeFunctionData({
|
|
106
|
-
abi:
|
|
109
|
+
abi: getAbi(chainId, "MultichainOrderRouter"),
|
|
107
110
|
functionName: "batch",
|
|
108
111
|
args: [relayParamsWithSignature, account, BigInt(srcChainId), paramsLists],
|
|
109
112
|
});
|
|
@@ -112,7 +115,7 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
112
115
|
else {
|
|
113
116
|
if (isSubaccount) {
|
|
114
117
|
callData = encodeFunctionData({
|
|
115
|
-
abi:
|
|
118
|
+
abi: getAbi(chainId, "SubaccountGelatoRelayRouter"),
|
|
116
119
|
functionName: "batch",
|
|
117
120
|
args: [
|
|
118
121
|
relayParamsWithSignature,
|
|
@@ -125,7 +128,7 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
125
128
|
}
|
|
126
129
|
else {
|
|
127
130
|
callData = encodeFunctionData({
|
|
128
|
-
abi:
|
|
131
|
+
abi: getAbi(chainId, "GelatoRelayRouter"),
|
|
129
132
|
functionName: "batch",
|
|
130
133
|
args: [relayParamsWithSignature, account, paramsLists],
|
|
131
134
|
});
|
|
@@ -139,7 +142,8 @@ export function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPaylo
|
|
|
139
142
|
relayRouterAddress,
|
|
140
143
|
};
|
|
141
144
|
}
|
|
142
|
-
export function getBatchParamsLists(batchParams) {
|
|
145
|
+
export function getBatchParamsLists(chainId, batchParams) {
|
|
146
|
+
const isV2_2_1 = isContractsV2_2_1(chainId);
|
|
143
147
|
return {
|
|
144
148
|
createOrderParamsList: batchParams.createOrderParams.map((p) => ({
|
|
145
149
|
addresses: updateExpressOrdersAddresses(p.orderPayload.addresses),
|
|
@@ -159,6 +163,7 @@ export function getBatchParamsLists(batchParams) {
|
|
|
159
163
|
triggerPrice: p.updatePayload.triggerPrice,
|
|
160
164
|
minOutputAmount: p.updatePayload.minOutputAmount,
|
|
161
165
|
validFromTime: p.updatePayload.validFromTime,
|
|
166
|
+
...(isV2_2_1 ? { decreasePositionSwapType: p.updatePayload.decreasePositionSwapType } : {}),
|
|
162
167
|
autoCancel: p.updatePayload.autoCancel,
|
|
163
168
|
executionFeeIncrease: p.updatePayload.executionFeeTopUp,
|
|
164
169
|
})),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { encodeFunctionData } from "viem";
|
|
2
|
-
import {
|
|
3
|
-
import { getContract } from "../../../configs/contracts";
|
|
2
|
+
import { getAbi } from "../../../abis/getAbi";
|
|
3
|
+
import { getContract, isContractsV2_2_1 } from "../../../configs/contracts";
|
|
4
4
|
import { DEFAULT_EXPRESS_ORDER_DEADLINE_DURATION } from "../../../configs/express";
|
|
5
|
+
import { getEmptyBridgeFeeParams } from "../../multichain/api";
|
|
5
6
|
import { nowInSeconds } from "../../time";
|
|
6
7
|
import { getGelatoRelayRouterDomain, hashRelayParams } from "./relayParamsUtils";
|
|
7
8
|
export async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParamsPayload, params, signer, account, emptySignature = false, relayerFeeTokenAddress, relayerFeeAmount, }) {
|
|
@@ -26,7 +27,7 @@ export async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParam
|
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
const bridgeOutCallData = encodeFunctionData({
|
|
29
|
-
abi:
|
|
30
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
30
31
|
functionName: "bridgeOut",
|
|
31
32
|
args: [
|
|
32
33
|
{
|
|
@@ -35,7 +36,7 @@ export async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParam
|
|
|
35
36
|
},
|
|
36
37
|
account,
|
|
37
38
|
BigInt(srcChainId),
|
|
38
|
-
params,
|
|
39
|
+
{ ...params, bridgeFee: params.bridgeFee ?? getEmptyBridgeFeeParams() },
|
|
39
40
|
],
|
|
40
41
|
});
|
|
41
42
|
return {
|
|
@@ -55,26 +56,60 @@ const BRIDGE_OUT_TYPES = {
|
|
|
55
56
|
{ name: "relayParams", type: "bytes32" },
|
|
56
57
|
],
|
|
57
58
|
};
|
|
59
|
+
const BRIDGE_OUT_TYPES_V2_2_1 = {
|
|
60
|
+
BridgeOut: [
|
|
61
|
+
{ name: "account", type: "address" },
|
|
62
|
+
{ name: "token", type: "address" },
|
|
63
|
+
{ name: "amount", type: "uint256" },
|
|
64
|
+
{ name: "minAmountOut", type: "uint256" },
|
|
65
|
+
{ name: "provider", type: "address" },
|
|
66
|
+
{ name: "data", type: "bytes" },
|
|
67
|
+
{ name: "bridgeFeeToken", type: "address" },
|
|
68
|
+
{ name: "bridgeFeeAmount", type: "uint256" },
|
|
69
|
+
{ name: "bridgeFeeSwapPath", type: "address[]" },
|
|
70
|
+
{ name: "bridgeFeeMinOutputAmount", type: "uint256" },
|
|
71
|
+
{ name: "relayParams", type: "bytes32" },
|
|
72
|
+
],
|
|
73
|
+
};
|
|
58
74
|
/**
|
|
59
75
|
* EIP-712 typed-data describing a `MultichainTransferRouter.bridgeOut` call.
|
|
60
76
|
* Single source of truth shared by SDK signing helpers and server-side prepare flows.
|
|
61
77
|
*/
|
|
62
|
-
export function getBridgeOutTypedData({ chainId, srcChainId, params, relayParams, }) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
provider: params.provider,
|
|
72
|
-
data: params.data,
|
|
73
|
-
relayParams: hashRelayParams(relayParams),
|
|
74
|
-
},
|
|
78
|
+
export function getBridgeOutTypedData({ chainId, srcChainId, params, relayParams, account, }) {
|
|
79
|
+
const domain = getGelatoRelayRouterDomain(srcChainId, getContract(chainId, "MultichainTransferRouter"));
|
|
80
|
+
const message = {
|
|
81
|
+
token: params.token,
|
|
82
|
+
amount: params.amount,
|
|
83
|
+
minAmountOut: params.minAmountOut,
|
|
84
|
+
provider: params.provider,
|
|
85
|
+
data: params.data,
|
|
86
|
+
relayParams: hashRelayParams(relayParams),
|
|
75
87
|
};
|
|
88
|
+
if (isContractsV2_2_1(chainId)) {
|
|
89
|
+
const bridgeFee = params.bridgeFee ?? getEmptyBridgeFeeParams();
|
|
90
|
+
return {
|
|
91
|
+
domain,
|
|
92
|
+
types: BRIDGE_OUT_TYPES_V2_2_1,
|
|
93
|
+
primaryType: "BridgeOut",
|
|
94
|
+
message: {
|
|
95
|
+
...message,
|
|
96
|
+
account,
|
|
97
|
+
bridgeFeeToken: bridgeFee.feeToken,
|
|
98
|
+
bridgeFeeAmount: bridgeFee.feeAmount,
|
|
99
|
+
bridgeFeeSwapPath: bridgeFee.feeSwapPath,
|
|
100
|
+
bridgeFeeMinOutputAmount: bridgeFee.minOutputAmount,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return { domain, types: BRIDGE_OUT_TYPES, primaryType: "BridgeOut", message };
|
|
76
105
|
}
|
|
77
106
|
async function signBridgeOutPayload({ signer, relayParams, params, chainId, srcChainId, }) {
|
|
78
|
-
const { domain, types, message } = getBridgeOutTypedData({
|
|
107
|
+
const { domain, types, message } = getBridgeOutTypedData({
|
|
108
|
+
chainId,
|
|
109
|
+
srcChainId,
|
|
110
|
+
params,
|
|
111
|
+
relayParams,
|
|
112
|
+
account: signer.address,
|
|
113
|
+
});
|
|
79
114
|
return signer.signTypedData(domain, types, message);
|
|
80
115
|
}
|
|
@@ -1,30 +1,42 @@
|
|
|
1
|
-
import { getContract } from "../../../configs/contracts";
|
|
1
|
+
import { getContract, isContractsV2_2_1 } from "../../../configs/contracts";
|
|
2
2
|
import { getGelatoRelayRouterDomain, hashRelayParams } from "./relayParamsUtils";
|
|
3
|
-
export
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
export function getReferralCodeTypedData({ primaryType, chainId, srcChainId, relayParams, referralCode, account, }) {
|
|
4
|
+
const isV2_2_1 = isContractsV2_2_1(chainId);
|
|
5
|
+
return {
|
|
6
|
+
domain: getGelatoRelayRouterDomain(srcChainId ?? chainId, getContract(chainId, "MultichainOrderRouter")),
|
|
7
|
+
types: {
|
|
8
|
+
[primaryType]: [
|
|
9
|
+
...(isV2_2_1 ? [{ name: "account", type: "address" }] : []),
|
|
10
|
+
{ name: "referralCode", type: "bytes32" },
|
|
11
|
+
{ name: "relayParams", type: "bytes32" },
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
message: {
|
|
15
|
+
...(isV2_2_1 ? { account } : {}),
|
|
16
|
+
referralCode,
|
|
17
|
+
relayParams: hashRelayParams(relayParams),
|
|
18
|
+
},
|
|
14
19
|
};
|
|
15
|
-
|
|
20
|
+
}
|
|
21
|
+
export async function signSetTraderReferralCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
22
|
+
const { domain, types, message } = getReferralCodeTypedData({
|
|
23
|
+
primaryType: "SetTraderReferralCode",
|
|
24
|
+
chainId,
|
|
25
|
+
srcChainId,
|
|
26
|
+
relayParams,
|
|
27
|
+
referralCode,
|
|
28
|
+
account: signer.address,
|
|
29
|
+
});
|
|
30
|
+
return signer.signTypedData(domain, types, message);
|
|
16
31
|
}
|
|
17
32
|
export async function signRegisterCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
18
|
-
const types = {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
relayParams: hashRelayParams(relayParams),
|
|
28
|
-
};
|
|
29
|
-
return signer.signTypedData(domain, types, typedData);
|
|
33
|
+
const { domain, types, message } = getReferralCodeTypedData({
|
|
34
|
+
primaryType: "RegisterCode",
|
|
35
|
+
chainId,
|
|
36
|
+
srcChainId,
|
|
37
|
+
relayParams,
|
|
38
|
+
referralCode,
|
|
39
|
+
account: signer.address,
|
|
40
|
+
});
|
|
41
|
+
return signer.signTypedData(domain, types, message);
|
|
30
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { encodeAbiParameters, keccak256 } from "viem";
|
|
1
|
+
import { encodeAbiParameters, keccak256, zeroHash } from "viem";
|
|
2
2
|
import { abis } from "../../../abis";
|
|
3
|
-
import
|
|
3
|
+
import RelayParamsV2_2_1 from "../../../abis/RelayParamsV2_2_1";
|
|
4
|
+
import { getContract, isContractsV2_2_1 } from "../../../configs/contracts";
|
|
4
5
|
import { SwapPricingType } from "../../orders/types";
|
|
5
6
|
import { combineExternalCalls, getEmptyExternalCallsPayload, getExternalCallsPayload, } from "../../orderTransactions";
|
|
6
7
|
import { getSwapAmountsByToValue } from "../../swap";
|
|
@@ -160,10 +161,11 @@ export function getRawRelayerParams({ chainId, gasPaymentTokenAddress, relayerFe
|
|
|
160
161
|
fee: feeParams,
|
|
161
162
|
desChainId: BigInt(chainId),
|
|
162
163
|
userNonce: BigInt(nowInSeconds()),
|
|
164
|
+
eip6492SignatureWrapperHash: zeroHash,
|
|
163
165
|
};
|
|
164
166
|
}
|
|
165
167
|
export function hashRelayParams(relayParams) {
|
|
166
|
-
const
|
|
168
|
+
const values = [
|
|
167
169
|
{
|
|
168
170
|
tokens: relayParams.oracleParams.tokens,
|
|
169
171
|
providers: relayParams.oracleParams.providers,
|
|
@@ -186,6 +188,9 @@ export function hashRelayParams(relayParams) {
|
|
|
186
188
|
relayParams.userNonce,
|
|
187
189
|
relayParams.deadline,
|
|
188
190
|
relayParams.desChainId,
|
|
189
|
-
]
|
|
190
|
-
|
|
191
|
+
];
|
|
192
|
+
if (isContractsV2_2_1(Number(relayParams.desChainId))) {
|
|
193
|
+
return keccak256(encodeAbiParameters(RelayParamsV2_2_1, [...values, relayParams.eip6492SignatureWrapperHash]));
|
|
194
|
+
}
|
|
195
|
+
return keccak256(encodeAbiParameters(abis.RelayParams, values));
|
|
191
196
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { ARBITRUM, AVALANCHE } from "../../../configs/chains";
|
|
3
|
+
import { buildMarketsConfigsRequest } from "../multicall";
|
|
4
|
+
const ETH_USDC_MARKET = "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336";
|
|
5
|
+
const marketsData = {
|
|
6
|
+
[ETH_USDC_MARKET]: {
|
|
7
|
+
marketTokenAddress: ETH_USDC_MARKET,
|
|
8
|
+
indexTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
9
|
+
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
10
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
11
|
+
isSameCollaterals: false,
|
|
12
|
+
isSpotOnly: false,
|
|
13
|
+
name: "ETH/USD [WETH-USDC]",
|
|
14
|
+
data: "",
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
describe("buildMarketsConfigsRequest", () => {
|
|
18
|
+
it("hashes the keys of a market without pre-built keys", async () => {
|
|
19
|
+
// The keys of this market are pre-built for Arbitrum only, so on Avalanche they are hashed at runtime
|
|
20
|
+
const params = { marketsAddresses: [ETH_USDC_MARKET], marketsData };
|
|
21
|
+
const prebuiltRequest = await buildMarketsConfigsRequest(ARBITRUM, params);
|
|
22
|
+
const hashedRequest = await buildMarketsConfigsRequest(AVALANCHE, params);
|
|
23
|
+
expect(hashedRequest[`${ETH_USDC_MARKET}-dataStore`].calls).toEqual(prebuiltRequest[`${ETH_USDC_MARKET}-dataStore`].calls);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -4,6 +4,7 @@ import { CLAIMABLE_FUNDING_AMOUNT, MAX_PNL_FACTOR_FOR_TRADERS_KEY, maxCollateral
|
|
|
4
4
|
import { hashDataMap } from "../hash";
|
|
5
5
|
import { getContractMarketPrices, getOiInTokensFromRawValues, getOiUsdFromRawValues } from "./";
|
|
6
6
|
import { getByKey } from "../objects";
|
|
7
|
+
import { hashMarketConfigKeys, hashMarketValuesKeys } from "./hashKeys";
|
|
7
8
|
export function buildMarketsRiskValuesRequest(chainId, markets) {
|
|
8
9
|
const dataStoreAddress = getContract(chainId, "DataStore");
|
|
9
10
|
return markets.reduce((request, market) => {
|
|
@@ -144,10 +145,7 @@ export async function buildMarketsValuesRequest(chainId, { marketsAddresses, mar
|
|
|
144
145
|
},
|
|
145
146
|
},
|
|
146
147
|
};
|
|
147
|
-
const prebuiltHashedKeys = HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress];
|
|
148
|
-
if (!prebuiltHashedKeys) {
|
|
149
|
-
throw new Error(`No pre-built hashed market keys found for the market ${marketAddress}.`);
|
|
150
|
-
}
|
|
148
|
+
const prebuiltHashedKeys = HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress] ?? hashMarketValuesKeys(market);
|
|
151
149
|
request[`${marketAddress}-dataStore`] = {
|
|
152
150
|
contractAddress: dataStoreAddress,
|
|
153
151
|
abiId: "DataStore",
|
|
@@ -270,10 +268,10 @@ export async function buildMarketsConfigsRequest(chainId, { marketsAddresses, ma
|
|
|
270
268
|
const request = {};
|
|
271
269
|
for (const marketAddress of marketsAddresses || []) {
|
|
272
270
|
const market = getByKey(marketsData, marketAddress);
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
throw new Error(`No pre-built hashed config keys found for the market ${marketAddress}.`);
|
|
271
|
+
if (!market) {
|
|
272
|
+
throw new Error(`No market data found for the market ${marketAddress}.`);
|
|
276
273
|
}
|
|
274
|
+
const prebuiltHashedKeys = HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress] ?? hashMarketConfigKeys(market);
|
|
277
275
|
request[`${marketAddress}-dataStore`] = {
|
|
278
276
|
contractAddress: dataStoreAddress,
|
|
279
277
|
abiId: "DataStore",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { encodeAbiParameters, encodeFunctionData, zeroAddress } from "viem";
|
|
2
|
-
import {
|
|
2
|
+
import { getAbi } from "../../abis/getAbi";
|
|
3
3
|
import { getContract } from "../../configs/contracts";
|
|
4
4
|
import { getLayerZeroEndpointId } from "../../configs/multichain";
|
|
5
5
|
import { getToken } from "../../configs/tokens";
|
|
@@ -21,25 +21,25 @@ export function buildSameChainDepositTxn(request) {
|
|
|
21
21
|
}
|
|
22
22
|
depositTokenAddress = wrappedAddress;
|
|
23
23
|
sendCall = encodeFunctionData({
|
|
24
|
-
abi:
|
|
24
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
25
25
|
functionName: "sendWnt",
|
|
26
26
|
args: [multichainVault, amount],
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
else {
|
|
30
30
|
sendCall = encodeFunctionData({
|
|
31
|
-
abi:
|
|
31
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
32
32
|
functionName: "sendTokens",
|
|
33
33
|
args: [tokenAddress, multichainVault, amount],
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
36
|
const bridgeInCall = encodeFunctionData({
|
|
37
|
-
abi:
|
|
37
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
38
38
|
functionName: "bridgeIn",
|
|
39
39
|
args: [account, depositTokenAddress],
|
|
40
40
|
});
|
|
41
41
|
const data = encodeFunctionData({
|
|
42
|
-
abi:
|
|
42
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
43
43
|
functionName: "multicall",
|
|
44
44
|
args: [[sendCall, bridgeInCall]],
|
|
45
45
|
});
|
|
@@ -49,6 +49,14 @@ export function buildSameChainDepositTxn(request) {
|
|
|
49
49
|
value: isNative ? amount : 0n,
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
export function getEmptyBridgeFeeParams() {
|
|
53
|
+
return {
|
|
54
|
+
feeToken: zeroAddress,
|
|
55
|
+
feeAmount: 0n,
|
|
56
|
+
feeSwapPath: [],
|
|
57
|
+
minOutputAmount: 0n,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
52
60
|
export function buildSameChainWithdrawBridgeOutParams(params) {
|
|
53
61
|
return {
|
|
54
62
|
token: params.tokenAddress,
|
|
@@ -65,9 +73,9 @@ export function buildSameChainWithdrawTxn(request) {
|
|
|
65
73
|
const { chainId, bridgeOutParams } = request;
|
|
66
74
|
const router = getContract(chainId, "MultichainTransferRouter");
|
|
67
75
|
const data = encodeFunctionData({
|
|
68
|
-
abi:
|
|
76
|
+
abi: getAbi(chainId, "MultichainTransferRouter"),
|
|
69
77
|
functionName: "transferOut",
|
|
70
|
-
args: [bridgeOutParams],
|
|
78
|
+
args: [{ ...bridgeOutParams, bridgeFee: bridgeOutParams.bridgeFee ?? getEmptyBridgeFeeParams() }],
|
|
71
79
|
});
|
|
72
80
|
return { to: router, data, value: 0n };
|
|
73
81
|
}
|
|
@@ -392,6 +392,11 @@ export function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZe
|
|
|
392
392
|
}
|
|
393
393
|
return `${sign}${value}`;
|
|
394
394
|
}
|
|
395
|
+
export function truncateToBalanceDisplayDecimals(amount, tokenDecimals, isStable = false) {
|
|
396
|
+
const displayDecimals = calculateDisplayDecimals(amount, tokenDecimals, 1, isStable);
|
|
397
|
+
const displayStep = expandDecimals(1, Math.max(tokenDecimals - displayDecimals, 0));
|
|
398
|
+
return amount - (amount % displayStep);
|
|
399
|
+
}
|
|
395
400
|
export function formatFactor(factor) {
|
|
396
401
|
if (factor == 0n) {
|
|
397
402
|
return "0";
|
|
@@ -175,7 +175,7 @@ function parsePrepareResponse(raw) {
|
|
|
175
175
|
}
|
|
176
176
|
// the express chain stays on the origin that served it: prepare and submit pin that origin by request id, submit and status reuse it
|
|
177
177
|
function chainKeys(prepared) {
|
|
178
|
-
return [prepared.requestId
|
|
178
|
+
return [prepared.requestId];
|
|
179
179
|
}
|
|
180
180
|
export async function prepareOrder(ctx, request) {
|
|
181
181
|
return postJsonPinning(ctx.api, "/v1/orders/txns/prepare", request, chainKeys, {
|
|
@@ -183,7 +183,7 @@ export async function prepareOrder(ctx, request) {
|
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
185
|
export async function submitOrder(ctx, request) {
|
|
186
|
-
return postJsonPinned(ctx.api, [request.requestId
|
|
186
|
+
return postJsonPinned(ctx.api, [request.requestId], "/v1/orders/txns/submit", request);
|
|
187
187
|
}
|
|
188
188
|
export async function prepareEditOrder(ctx, request) {
|
|
189
189
|
return postJsonPinning(ctx.api, "/v1/orders/txns/edit/prepare", request, chainKeys, {
|
|
@@ -201,7 +201,7 @@ export async function prepareCollateral(ctx, request) {
|
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
export async function fetchOrderStatus(ctx, request) {
|
|
204
|
-
return postJsonPinned(ctx.api, [request.requestId
|
|
204
|
+
return postJsonPinned(ctx.api, [request.requestId], "/v1/orders/txns/status", request);
|
|
205
205
|
}
|
|
206
206
|
export async function signPreparedOrder(prepared, signer, chainId, accountAddress) {
|
|
207
207
|
if (prepared.payloadType !== "typed-data") {
|
|
@@ -228,7 +228,6 @@ export async function executeExpressOrder(ctx, request, signer, accountAddress)
|
|
|
228
228
|
requestId: prepared.requestId,
|
|
229
229
|
signature,
|
|
230
230
|
from: accountAddress ?? signer.address,
|
|
231
|
-
idempotencyKey: prepared.idempotencyKey,
|
|
232
231
|
eip712Data: {
|
|
233
232
|
batchParams: prepared.payload.batchParams,
|
|
234
233
|
relayParams: prepared.payload.relayParams,
|