@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,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./utils"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getAddressKey = exports.isSameAddress = exports.normalizeAddress = exports.isEvmAddress = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const EVM_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
6
|
+
const HEX_REGEX = /^0x[0-9a-fA-F]*$/;
|
|
7
|
+
/**
|
|
8
|
+
* Addresses in shared code are EVM hex or Solana base58. Base58 has no `0` in its alphabet, so it never matches.
|
|
9
|
+
* Base58 is case-sensitive, so it must never be checksummed, lowercased or compared through viem.
|
|
10
|
+
*/
|
|
11
|
+
function isEvmAddress(address) {
|
|
12
|
+
return EVM_ADDRESS_REGEX.test(address);
|
|
13
|
+
}
|
|
14
|
+
exports.isEvmAddress = isEvmAddress;
|
|
15
|
+
/** Checksums an EVM address and keeps any other address as it is. */
|
|
16
|
+
function normalizeAddress(address) {
|
|
17
|
+
return isEvmAddress(address) ? (0, viem_1.getAddress)(address) : address;
|
|
18
|
+
}
|
|
19
|
+
exports.normalizeAddress = normalizeAddress;
|
|
20
|
+
/** Compares EVM hex case-insensitively and any other address exactly. Empty input does not match. */
|
|
21
|
+
function isSameAddress(a, b) {
|
|
22
|
+
if (!a || !b) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return getAddressKey(a) === getAddressKey(b);
|
|
26
|
+
}
|
|
27
|
+
exports.isSameAddress = isSameAddress;
|
|
28
|
+
/** A map or set key: lowercased for EVM hex (addresses and hashes), unchanged for base58. */
|
|
29
|
+
function getAddressKey(address) {
|
|
30
|
+
return HEX_REGEX.test(address) ? address.toLowerCase() : address;
|
|
31
|
+
}
|
|
32
|
+
exports.getAddressKey = getAddressKey;
|
|
@@ -95,10 +95,20 @@ function parseError(error, errorDepth = 0) {
|
|
|
95
95
|
isUserError = type ? (0, transactionsErrors_1.getIsUserError)(type) : false;
|
|
96
96
|
isUserRejectedError = type ? (0, transactionsErrors_1.getIsUserRejectedError)(type) : false;
|
|
97
97
|
}
|
|
98
|
+
// ethers already classified it as a user rejection, whatever the wallet error looks like
|
|
99
|
+
if (typeof error === "object" && error?.code === "ACTION_REJECTED") {
|
|
100
|
+
txErrorType = transactionsErrors_1.TxErrorType.UserDenied;
|
|
101
|
+
isUserError = true;
|
|
102
|
+
isUserRejectedError = true;
|
|
103
|
+
}
|
|
98
104
|
}
|
|
99
105
|
catch (e) {
|
|
100
106
|
//
|
|
101
107
|
}
|
|
108
|
+
if (isCustomError(error)) {
|
|
109
|
+
contractError = error.name;
|
|
110
|
+
contractErrorArgs = error.args;
|
|
111
|
+
}
|
|
102
112
|
if (!contractError) {
|
|
103
113
|
const errorData = (error && typeof error === "object" ? extractErrorDataFromViemError(error) : undefined) ??
|
|
104
114
|
(0, transactionsErrors_1.extractDataFromError)(errorMessage) ??
|
|
@@ -60,9 +60,14 @@ const TX_ERROR_PATTERNS = {
|
|
|
60
60
|
{ msg: "couldn't connect to the network" },
|
|
61
61
|
],
|
|
62
62
|
};
|
|
63
|
+
// EIP-1193 and WalletConnect (CAIP-25) user rejection codes, as viem maps them; ethers' BrowserProvider maps only 4001.
|
|
64
|
+
// Checked after the patterns so they only classify otherwise unknown errors
|
|
65
|
+
const USER_REJECTED_REQUEST_CODES = [4001, 5000];
|
|
63
66
|
var CustomErrorName;
|
|
64
67
|
(function (CustomErrorName) {
|
|
65
68
|
CustomErrorName["DisabledMarket"] = "DisabledMarket";
|
|
69
|
+
CustomErrorName["EmptyDesignatedVesters"] = "EmptyDesignatedVesters";
|
|
70
|
+
CustomErrorName["EmptyStakeAmount"] = "EmptyStakeAmount";
|
|
66
71
|
CustomErrorName["EndOfOracleSimulation"] = "EndOfOracleSimulation";
|
|
67
72
|
CustomErrorName["ExternalCallFailed"] = "ExternalCallFailed";
|
|
68
73
|
CustomErrorName["InsufficientBridgeOutputAmount"] = "InsufficientBridgeOutputAmount";
|
|
@@ -77,6 +82,7 @@ var CustomErrorName;
|
|
|
77
82
|
CustomErrorName["InsufficientReserveForOpenInterest"] = "InsufficientReserveForOpenInterest";
|
|
78
83
|
CustomErrorName["OrderNotFulfillableAtAcceptablePrice"] = "OrderNotFulfillableAtAcceptablePrice";
|
|
79
84
|
CustomErrorName["InsufficientSwapOutputAmount"] = "InsufficientSwapOutputAmount";
|
|
85
|
+
CustomErrorName["InsufficientStrictTransferAllowance"] = "InsufficientStrictTransferAllowance";
|
|
80
86
|
CustomErrorName["InvalidCollateralTokenForMarket"] = "InvalidCollateralTokenForMarket";
|
|
81
87
|
CustomErrorName["InvalidDecreaseOrderSize"] = "InvalidDecreaseOrderSize";
|
|
82
88
|
CustomErrorName["InvalidOraclePrice"] = "InvalidOraclePrice";
|
|
@@ -88,6 +94,8 @@ var CustomErrorName;
|
|
|
88
94
|
CustomErrorName["MaxPoolUsdForDepositExceeded"] = "MaxPoolUsdForDepositExceeded";
|
|
89
95
|
CustomErrorName["MaxPriceAgeExceeded"] = "MaxPriceAgeExceeded";
|
|
90
96
|
CustomErrorName["MaxRelayFeeSwapExceeded"] = "MaxRelayFeeSwapExceeded";
|
|
97
|
+
CustomErrorName["MaxUnstakeRequestsExceeded"] = "MaxUnstakeRequestsExceeded";
|
|
98
|
+
CustomErrorName["MaxUnstakeRequestsOnTransfer"] = "MaxUnstakeRequestsOnTransfer";
|
|
91
99
|
CustomErrorName["MinPositionSize"] = "MinPositionSize";
|
|
92
100
|
CustomErrorName["NegativeExecutionPrice"] = "NegativeExecutionPrice";
|
|
93
101
|
CustomErrorName["OrderNotFound"] = "OrderNotFound";
|
|
@@ -96,11 +104,23 @@ var CustomErrorName;
|
|
|
96
104
|
CustomErrorName["PnlFactorExceededForLongs"] = "PnlFactorExceededForLongs";
|
|
97
105
|
CustomErrorName["PnlFactorExceededForShorts"] = "PnlFactorExceededForShorts";
|
|
98
106
|
CustomErrorName["PriceImpactLargerThanOrderSize"] = "PriceImpactLargerThanOrderSize";
|
|
107
|
+
CustomErrorName["SelfVestingTransfer"] = "SelfVestingTransfer";
|
|
108
|
+
CustomErrorName["StakingReceiverNotFresh"] = "StakingReceiverNotFresh";
|
|
109
|
+
CustomErrorName["StakingSenderHasPairAmounts"] = "StakingSenderHasPairAmounts";
|
|
110
|
+
CustomErrorName["StakingSenderHasVestedTokens"] = "StakingSenderHasVestedTokens";
|
|
99
111
|
CustomErrorName["SwapPriceImpactExceedsAmountIn"] = "SwapPriceImpactExceedsAmountIn";
|
|
112
|
+
CustomErrorName["TransferNotSignalled"] = "TransferNotSignalled";
|
|
113
|
+
CustomErrorName["TransferVesterConfigChanged"] = "TransferVesterConfigChanged";
|
|
100
114
|
CustomErrorName["UnableToWithdrawCollateral"] = "UnableToWithdrawCollateral";
|
|
115
|
+
CustomErrorName["UnstakeAmountExceedsStake"] = "UnstakeAmountExceedsStake";
|
|
116
|
+
CustomErrorName["UnstakeNotSignalled"] = "UnstakeNotSignalled";
|
|
101
117
|
CustomErrorName["UsdDeltaExceedsLongOpenInterest"] = "UsdDeltaExceedsLongOpenInterest";
|
|
102
118
|
CustomErrorName["UsdDeltaExceedsPoolValue"] = "UsdDeltaExceedsPoolValue";
|
|
103
119
|
CustomErrorName["UsdDeltaExceedsShortOpenInterest"] = "UsdDeltaExceedsShortOpenInterest";
|
|
120
|
+
CustomErrorName["VesterAccountFrozen"] = "VesterAccountFrozen";
|
|
121
|
+
CustomErrorName["VesterProvisioningNotComplete"] = "VesterProvisioningNotComplete";
|
|
122
|
+
CustomErrorName["VestingReceiverNotFresh"] = "VestingReceiverNotFresh";
|
|
123
|
+
CustomErrorName["VestingSenderHasOpenSession"] = "VestingSenderHasOpenSession";
|
|
104
124
|
})(CustomErrorName || (exports.CustomErrorName = CustomErrorName = {}));
|
|
105
125
|
function getIsUserRejectedError(errorType) {
|
|
106
126
|
return errorType === TxErrorType.UserDenied;
|
|
@@ -149,6 +169,9 @@ function extractTxnError(ex) {
|
|
|
149
169
|
}
|
|
150
170
|
}
|
|
151
171
|
}
|
|
172
|
+
if (typeof code === "number" && USER_REJECTED_REQUEST_CODES.includes(code)) {
|
|
173
|
+
return [message, TxErrorType.UserDenied, ex.data];
|
|
174
|
+
}
|
|
152
175
|
return [message, null, ex.data];
|
|
153
176
|
}
|
|
154
177
|
exports.extractTxnError = extractTxnError;
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.simulateExpressOrder = exports.buildSignedBatchOrderCalldata = exports.getBatchParamsLists = exports.buildBatchOrderCalldata = exports.getBatchTypedData = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const getAbi_1 = require("../../../abis/getAbi");
|
|
6
|
+
const contracts_1 = require("../../../configs/contracts");
|
|
6
7
|
const express_1 = require("../../../configs/express");
|
|
7
8
|
const metrics_1 = require("../../metrics");
|
|
8
9
|
const time_1 = require("../../time");
|
|
9
10
|
const uiFeeReceiver_1 = require("../../twap/uiFeeReceiver");
|
|
10
11
|
const relayParamsUtils_1 = require("./relayParamsUtils");
|
|
11
12
|
function getBatchTypedData({ chainId, signingChainId, batchParams, relayParams, account, subaccountApprovalHash, relayRouterAddress, }) {
|
|
13
|
+
const isV2_2_1 = (0, contracts_1.isContractsV2_2_1)(chainId);
|
|
12
14
|
const types = {
|
|
13
15
|
Batch: [
|
|
14
16
|
{ name: "account", type: "address" },
|
|
@@ -55,14 +57,15 @@ function getBatchTypedData({ chainId, signingChainId, batchParams, relayParams,
|
|
|
55
57
|
{ name: "triggerPrice", type: "uint256" },
|
|
56
58
|
{ name: "minOutputAmount", type: "uint256" },
|
|
57
59
|
{ name: "validFromTime", type: "uint256" },
|
|
60
|
+
...(isV2_2_1 ? [{ name: "decreasePositionSwapType", type: "uint256" }] : []),
|
|
58
61
|
{ name: "autoCancel", type: "bool" },
|
|
59
62
|
{ name: "executionFeeIncrease", type: "uint256" },
|
|
60
63
|
],
|
|
61
64
|
};
|
|
62
65
|
const domain = (0, relayParamsUtils_1.getGelatoRelayRouterDomain)(signingChainId ?? chainId, relayRouterAddress);
|
|
63
|
-
const paramsLists = getBatchParamsLists(batchParams);
|
|
66
|
+
const paramsLists = getBatchParamsLists(chainId, batchParams);
|
|
64
67
|
const message = {
|
|
65
|
-
account: subaccountApprovalHash ? account : viem_1.zeroAddress,
|
|
68
|
+
account: subaccountApprovalHash || isV2_2_1 ? account : viem_1.zeroAddress,
|
|
66
69
|
createOrderParamsList: paramsLists.createOrderParamsList,
|
|
67
70
|
updateOrderParamsList: paramsLists.updateOrderParamsList,
|
|
68
71
|
cancelOrderKeys: paramsLists.cancelOrderKeys,
|
|
@@ -81,7 +84,7 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
81
84
|
...relayParams,
|
|
82
85
|
signature,
|
|
83
86
|
};
|
|
84
|
-
const paramsLists = getBatchParamsLists(batchParams);
|
|
87
|
+
const paramsLists = getBatchParamsLists(chainId, batchParams);
|
|
85
88
|
const isSubaccount = subaccountApproval !== undefined;
|
|
86
89
|
const isMultichain = isGmxAccount && srcChainId !== undefined;
|
|
87
90
|
const relayRouterAddress = (0, relayParamsUtils_1.getExpressContractAddress)(chainId, {
|
|
@@ -93,7 +96,7 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
93
96
|
if (isMultichain) {
|
|
94
97
|
if (isSubaccount) {
|
|
95
98
|
callData = (0, viem_1.encodeFunctionData)({
|
|
96
|
-
abi:
|
|
99
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainSubaccountRouter"),
|
|
97
100
|
functionName: "batch",
|
|
98
101
|
args: [
|
|
99
102
|
relayParamsWithSignature,
|
|
@@ -107,7 +110,7 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
107
110
|
}
|
|
108
111
|
else {
|
|
109
112
|
callData = (0, viem_1.encodeFunctionData)({
|
|
110
|
-
abi:
|
|
113
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainOrderRouter"),
|
|
111
114
|
functionName: "batch",
|
|
112
115
|
args: [relayParamsWithSignature, account, BigInt(srcChainId), paramsLists],
|
|
113
116
|
});
|
|
@@ -116,7 +119,7 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
116
119
|
else {
|
|
117
120
|
if (isSubaccount) {
|
|
118
121
|
callData = (0, viem_1.encodeFunctionData)({
|
|
119
|
-
abi:
|
|
122
|
+
abi: (0, getAbi_1.getAbi)(chainId, "SubaccountGelatoRelayRouter"),
|
|
120
123
|
functionName: "batch",
|
|
121
124
|
args: [
|
|
122
125
|
relayParamsWithSignature,
|
|
@@ -129,7 +132,7 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
129
132
|
}
|
|
130
133
|
else {
|
|
131
134
|
callData = (0, viem_1.encodeFunctionData)({
|
|
132
|
-
abi:
|
|
135
|
+
abi: (0, getAbi_1.getAbi)(chainId, "GelatoRelayRouter"),
|
|
133
136
|
functionName: "batch",
|
|
134
137
|
args: [relayParamsWithSignature, account, paramsLists],
|
|
135
138
|
});
|
|
@@ -144,7 +147,8 @@ function buildBatchOrderCalldata({ chainId, batchParams, relayParamsPayload, sig
|
|
|
144
147
|
};
|
|
145
148
|
}
|
|
146
149
|
exports.buildBatchOrderCalldata = buildBatchOrderCalldata;
|
|
147
|
-
function getBatchParamsLists(batchParams) {
|
|
150
|
+
function getBatchParamsLists(chainId, batchParams) {
|
|
151
|
+
const isV2_2_1 = (0, contracts_1.isContractsV2_2_1)(chainId);
|
|
148
152
|
return {
|
|
149
153
|
createOrderParamsList: batchParams.createOrderParams.map((p) => ({
|
|
150
154
|
addresses: updateExpressOrdersAddresses(p.orderPayload.addresses),
|
|
@@ -164,6 +168,7 @@ function getBatchParamsLists(batchParams) {
|
|
|
164
168
|
triggerPrice: p.updatePayload.triggerPrice,
|
|
165
169
|
minOutputAmount: p.updatePayload.minOutputAmount,
|
|
166
170
|
validFromTime: p.updatePayload.validFromTime,
|
|
171
|
+
...(isV2_2_1 ? { decreasePositionSwapType: p.updatePayload.decreasePositionSwapType } : {}),
|
|
167
172
|
autoCancel: p.updatePayload.autoCancel,
|
|
168
173
|
executionFeeIncrease: p.updatePayload.executionFeeTopUp,
|
|
169
174
|
})),
|
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getBridgeOutTypedData = exports.buildAndSignBridgeOutTxn = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const getAbi_1 = require("../../../abis/getAbi");
|
|
6
6
|
const contracts_1 = require("../../../configs/contracts");
|
|
7
7
|
const express_1 = require("../../../configs/express");
|
|
8
|
+
const api_1 = require("../../multichain/api");
|
|
8
9
|
const time_1 = require("../../time");
|
|
9
10
|
const relayParamsUtils_1 = require("./relayParamsUtils");
|
|
10
11
|
async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParamsPayload, params, signer, account, emptySignature = false, relayerFeeTokenAddress, relayerFeeAmount, }) {
|
|
@@ -29,7 +30,7 @@ async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParamsPayloa
|
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
const bridgeOutCallData = (0, viem_1.encodeFunctionData)({
|
|
32
|
-
abi:
|
|
33
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
33
34
|
functionName: "bridgeOut",
|
|
34
35
|
args: [
|
|
35
36
|
{
|
|
@@ -38,7 +39,7 @@ async function buildAndSignBridgeOutTxn({ chainId, srcChainId, relayParamsPayloa
|
|
|
38
39
|
},
|
|
39
40
|
account,
|
|
40
41
|
BigInt(srcChainId),
|
|
41
|
-
params,
|
|
42
|
+
{ ...params, bridgeFee: params.bridgeFee ?? (0, api_1.getEmptyBridgeFeeParams)() },
|
|
42
43
|
],
|
|
43
44
|
});
|
|
44
45
|
return {
|
|
@@ -59,27 +60,61 @@ const BRIDGE_OUT_TYPES = {
|
|
|
59
60
|
{ name: "relayParams", type: "bytes32" },
|
|
60
61
|
],
|
|
61
62
|
};
|
|
63
|
+
const BRIDGE_OUT_TYPES_V2_2_1 = {
|
|
64
|
+
BridgeOut: [
|
|
65
|
+
{ name: "account", type: "address" },
|
|
66
|
+
{ name: "token", type: "address" },
|
|
67
|
+
{ name: "amount", type: "uint256" },
|
|
68
|
+
{ name: "minAmountOut", type: "uint256" },
|
|
69
|
+
{ name: "provider", type: "address" },
|
|
70
|
+
{ name: "data", type: "bytes" },
|
|
71
|
+
{ name: "bridgeFeeToken", type: "address" },
|
|
72
|
+
{ name: "bridgeFeeAmount", type: "uint256" },
|
|
73
|
+
{ name: "bridgeFeeSwapPath", type: "address[]" },
|
|
74
|
+
{ name: "bridgeFeeMinOutputAmount", type: "uint256" },
|
|
75
|
+
{ name: "relayParams", type: "bytes32" },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
62
78
|
/**
|
|
63
79
|
* EIP-712 typed-data describing a `MultichainTransferRouter.bridgeOut` call.
|
|
64
80
|
* Single source of truth shared by SDK signing helpers and server-side prepare flows.
|
|
65
81
|
*/
|
|
66
|
-
function getBridgeOutTypedData({ chainId, srcChainId, params, relayParams, }) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
provider: params.provider,
|
|
76
|
-
data: params.data,
|
|
77
|
-
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
78
|
-
},
|
|
82
|
+
function getBridgeOutTypedData({ chainId, srcChainId, params, relayParams, account, }) {
|
|
83
|
+
const domain = (0, relayParamsUtils_1.getGelatoRelayRouterDomain)(srcChainId, (0, contracts_1.getContract)(chainId, "MultichainTransferRouter"));
|
|
84
|
+
const message = {
|
|
85
|
+
token: params.token,
|
|
86
|
+
amount: params.amount,
|
|
87
|
+
minAmountOut: params.minAmountOut,
|
|
88
|
+
provider: params.provider,
|
|
89
|
+
data: params.data,
|
|
90
|
+
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
79
91
|
};
|
|
92
|
+
if ((0, contracts_1.isContractsV2_2_1)(chainId)) {
|
|
93
|
+
const bridgeFee = params.bridgeFee ?? (0, api_1.getEmptyBridgeFeeParams)();
|
|
94
|
+
return {
|
|
95
|
+
domain,
|
|
96
|
+
types: BRIDGE_OUT_TYPES_V2_2_1,
|
|
97
|
+
primaryType: "BridgeOut",
|
|
98
|
+
message: {
|
|
99
|
+
...message,
|
|
100
|
+
account,
|
|
101
|
+
bridgeFeeToken: bridgeFee.feeToken,
|
|
102
|
+
bridgeFeeAmount: bridgeFee.feeAmount,
|
|
103
|
+
bridgeFeeSwapPath: bridgeFee.feeSwapPath,
|
|
104
|
+
bridgeFeeMinOutputAmount: bridgeFee.minOutputAmount,
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return { domain, types: BRIDGE_OUT_TYPES, primaryType: "BridgeOut", message };
|
|
80
109
|
}
|
|
81
110
|
exports.getBridgeOutTypedData = getBridgeOutTypedData;
|
|
82
111
|
async function signBridgeOutPayload({ signer, relayParams, params, chainId, srcChainId, }) {
|
|
83
|
-
const { domain, types, message } = getBridgeOutTypedData({
|
|
112
|
+
const { domain, types, message } = getBridgeOutTypedData({
|
|
113
|
+
chainId,
|
|
114
|
+
srcChainId,
|
|
115
|
+
params,
|
|
116
|
+
relayParams,
|
|
117
|
+
account: signer.address,
|
|
118
|
+
});
|
|
84
119
|
return signer.signTypedData(domain, types, message);
|
|
85
120
|
}
|
|
@@ -1,35 +1,48 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.signRegisterCode = exports.signSetTraderReferralCode = void 0;
|
|
3
|
+
exports.signRegisterCode = exports.signSetTraderReferralCode = exports.getReferralCodeTypedData = void 0;
|
|
4
4
|
const contracts_1 = require("../../../configs/contracts");
|
|
5
5
|
const relayParamsUtils_1 = require("./relayParamsUtils");
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
function getReferralCodeTypedData({ primaryType, chainId, srcChainId, relayParams, referralCode, account, }) {
|
|
7
|
+
const isV2_2_1 = (0, contracts_1.isContractsV2_2_1)(chainId);
|
|
8
|
+
return {
|
|
9
|
+
domain: (0, relayParamsUtils_1.getGelatoRelayRouterDomain)(srcChainId ?? chainId, (0, contracts_1.getContract)(chainId, "MultichainOrderRouter")),
|
|
10
|
+
types: {
|
|
11
|
+
[primaryType]: [
|
|
12
|
+
...(isV2_2_1 ? [{ name: "account", type: "address" }] : []),
|
|
13
|
+
{ name: "referralCode", type: "bytes32" },
|
|
14
|
+
{ name: "relayParams", type: "bytes32" },
|
|
15
|
+
],
|
|
16
|
+
},
|
|
17
|
+
message: {
|
|
18
|
+
...(isV2_2_1 ? { account } : {}),
|
|
19
|
+
referralCode,
|
|
20
|
+
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
21
|
+
},
|
|
17
22
|
};
|
|
18
|
-
|
|
23
|
+
}
|
|
24
|
+
exports.getReferralCodeTypedData = getReferralCodeTypedData;
|
|
25
|
+
async function signSetTraderReferralCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
26
|
+
const { domain, types, message } = getReferralCodeTypedData({
|
|
27
|
+
primaryType: "SetTraderReferralCode",
|
|
28
|
+
chainId,
|
|
29
|
+
srcChainId,
|
|
30
|
+
relayParams,
|
|
31
|
+
referralCode,
|
|
32
|
+
account: signer.address,
|
|
33
|
+
});
|
|
34
|
+
return signer.signTypedData(domain, types, message);
|
|
19
35
|
}
|
|
20
36
|
exports.signSetTraderReferralCode = signSetTraderReferralCode;
|
|
21
37
|
async function signRegisterCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
22
|
-
const types = {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
32
|
-
};
|
|
33
|
-
return signer.signTypedData(domain, types, typedData);
|
|
38
|
+
const { domain, types, message } = getReferralCodeTypedData({
|
|
39
|
+
primaryType: "RegisterCode",
|
|
40
|
+
chainId,
|
|
41
|
+
srcChainId,
|
|
42
|
+
relayParams,
|
|
43
|
+
referralCode,
|
|
44
|
+
account: signer.address,
|
|
45
|
+
});
|
|
46
|
+
return signer.signTypedData(domain, types, message);
|
|
34
47
|
}
|
|
35
48
|
exports.signRegisterCode = signRegisterCode;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.hashRelayParams = exports.getRawRelayerParams = exports.getBestFeeSwapStrategy = exports.getRelayerFeeParams = exports.getGelatoRelayRouterDomain = exports.getExpressContractAddress = void 0;
|
|
4
7
|
const viem_1 = require("viem");
|
|
5
8
|
const abis_1 = require("../../../abis");
|
|
9
|
+
const RelayParamsV2_2_1_1 = __importDefault(require("../../../abis/RelayParamsV2_2_1"));
|
|
6
10
|
const contracts_1 = require("../../../configs/contracts");
|
|
7
11
|
const types_1 = require("../../orders/types");
|
|
8
12
|
const orderTransactions_1 = require("../../orderTransactions");
|
|
@@ -167,11 +171,12 @@ function getRawRelayerParams({ chainId, gasPaymentTokenAddress, relayerFeeTokenA
|
|
|
167
171
|
fee: feeParams,
|
|
168
172
|
desChainId: BigInt(chainId),
|
|
169
173
|
userNonce: BigInt((0, time_1.nowInSeconds)()),
|
|
174
|
+
eip6492SignatureWrapperHash: viem_1.zeroHash,
|
|
170
175
|
};
|
|
171
176
|
}
|
|
172
177
|
exports.getRawRelayerParams = getRawRelayerParams;
|
|
173
178
|
function hashRelayParams(relayParams) {
|
|
174
|
-
const
|
|
179
|
+
const values = [
|
|
175
180
|
{
|
|
176
181
|
tokens: relayParams.oracleParams.tokens,
|
|
177
182
|
providers: relayParams.oracleParams.providers,
|
|
@@ -194,7 +199,10 @@ function hashRelayParams(relayParams) {
|
|
|
194
199
|
relayParams.userNonce,
|
|
195
200
|
relayParams.deadline,
|
|
196
201
|
relayParams.desChainId,
|
|
197
|
-
]
|
|
198
|
-
|
|
202
|
+
];
|
|
203
|
+
if ((0, contracts_1.isContractsV2_2_1)(Number(relayParams.desChainId))) {
|
|
204
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)(RelayParamsV2_2_1_1.default, [...values, relayParams.eip6492SignatureWrapperHash]));
|
|
205
|
+
}
|
|
206
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)(abis_1.abis.RelayParams, values));
|
|
199
207
|
}
|
|
200
208
|
exports.hashRelayParams = hashRelayParams;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const chains_1 = require("../../../configs/chains");
|
|
5
|
+
const multicall_1 = require("../multicall");
|
|
6
|
+
const ETH_USDC_MARKET = "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336";
|
|
7
|
+
const marketsData = {
|
|
8
|
+
[ETH_USDC_MARKET]: {
|
|
9
|
+
marketTokenAddress: ETH_USDC_MARKET,
|
|
10
|
+
indexTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
11
|
+
longTokenAddress: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
12
|
+
shortTokenAddress: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
|
|
13
|
+
isSameCollaterals: false,
|
|
14
|
+
isSpotOnly: false,
|
|
15
|
+
name: "ETH/USD [WETH-USDC]",
|
|
16
|
+
data: "",
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
(0, vitest_1.describe)("buildMarketsConfigsRequest", () => {
|
|
20
|
+
(0, vitest_1.it)("hashes the keys of a market without pre-built keys", async () => {
|
|
21
|
+
// The keys of this market are pre-built for Arbitrum only, so on Avalanche they are hashed at runtime
|
|
22
|
+
const params = { marketsAddresses: [ETH_USDC_MARKET], marketsData };
|
|
23
|
+
const prebuiltRequest = await (0, multicall_1.buildMarketsConfigsRequest)(chains_1.ARBITRUM, params);
|
|
24
|
+
const hashedRequest = await (0, multicall_1.buildMarketsConfigsRequest)(chains_1.AVALANCHE, params);
|
|
25
|
+
(0, vitest_1.expect)(hashedRequest[`${ETH_USDC_MARKET}-dataStore`].calls).toEqual(prebuiltRequest[`${ETH_USDC_MARKET}-dataStore`].calls);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -7,6 +7,7 @@ const dataStore_1 = require("../../configs/dataStore");
|
|
|
7
7
|
const hash_1 = require("../hash");
|
|
8
8
|
const markets_1 = require("./");
|
|
9
9
|
const objects_1 = require("../objects");
|
|
10
|
+
const hashKeys_1 = require("./hashKeys");
|
|
10
11
|
function buildMarketsRiskValuesRequest(chainId, markets) {
|
|
11
12
|
const dataStoreAddress = (0, contracts_1.getContract)(chainId, "DataStore");
|
|
12
13
|
return markets.reduce((request, market) => {
|
|
@@ -150,10 +151,7 @@ async function buildMarketsValuesRequest(chainId, { marketsAddresses, marketsDat
|
|
|
150
151
|
},
|
|
151
152
|
},
|
|
152
153
|
};
|
|
153
|
-
const prebuiltHashedKeys = prebuilt_1.HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress];
|
|
154
|
-
if (!prebuiltHashedKeys) {
|
|
155
|
-
throw new Error(`No pre-built hashed market keys found for the market ${marketAddress}.`);
|
|
156
|
-
}
|
|
154
|
+
const prebuiltHashedKeys = prebuilt_1.HASHED_MARKET_VALUES_KEYS[chainId]?.[marketAddress] ?? (0, hashKeys_1.hashMarketValuesKeys)(market);
|
|
157
155
|
request[`${marketAddress}-dataStore`] = {
|
|
158
156
|
contractAddress: dataStoreAddress,
|
|
159
157
|
abiId: "DataStore",
|
|
@@ -278,10 +276,10 @@ async function buildMarketsConfigsRequest(chainId, { marketsAddresses, marketsDa
|
|
|
278
276
|
const request = {};
|
|
279
277
|
for (const marketAddress of marketsAddresses || []) {
|
|
280
278
|
const market = (0, objects_1.getByKey)(marketsData, marketAddress);
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
throw new Error(`No pre-built hashed config keys found for the market ${marketAddress}.`);
|
|
279
|
+
if (!market) {
|
|
280
|
+
throw new Error(`No market data found for the market ${marketAddress}.`);
|
|
284
281
|
}
|
|
282
|
+
const prebuiltHashedKeys = prebuilt_1.HASHED_MARKET_CONFIG_KEYS[chainId]?.[marketAddress] ?? (0, hashKeys_1.hashMarketConfigKeys)(market);
|
|
285
283
|
request[`${marketAddress}-dataStore`] = {
|
|
286
284
|
contractAddress: dataStoreAddress,
|
|
287
285
|
abiId: "DataStore",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeSameChainWithdraw = exports.executeSameChainDeposit = exports.buildCrossChainWithdrawBridgeOutParams = exports.buildSameChainWithdrawTxn = exports.buildSameChainWithdrawBridgeOutParams = exports.buildSameChainDepositTxn = void 0;
|
|
3
|
+
exports.executeSameChainWithdraw = exports.executeSameChainDeposit = exports.buildCrossChainWithdrawBridgeOutParams = exports.buildSameChainWithdrawTxn = exports.buildSameChainWithdrawBridgeOutParams = exports.getEmptyBridgeFeeParams = exports.buildSameChainDepositTxn = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
const
|
|
5
|
+
const getAbi_1 = require("../../abis/getAbi");
|
|
6
6
|
const contracts_1 = require("../../configs/contracts");
|
|
7
7
|
const multichain_1 = require("../../configs/multichain");
|
|
8
8
|
const tokens_1 = require("../../configs/tokens");
|
|
@@ -24,25 +24,25 @@ function buildSameChainDepositTxn(request) {
|
|
|
24
24
|
}
|
|
25
25
|
depositTokenAddress = wrappedAddress;
|
|
26
26
|
sendCall = (0, viem_1.encodeFunctionData)({
|
|
27
|
-
abi:
|
|
27
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
28
28
|
functionName: "sendWnt",
|
|
29
29
|
args: [multichainVault, amount],
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
else {
|
|
33
33
|
sendCall = (0, viem_1.encodeFunctionData)({
|
|
34
|
-
abi:
|
|
34
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
35
35
|
functionName: "sendTokens",
|
|
36
36
|
args: [tokenAddress, multichainVault, amount],
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
const bridgeInCall = (0, viem_1.encodeFunctionData)({
|
|
40
|
-
abi:
|
|
40
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
41
41
|
functionName: "bridgeIn",
|
|
42
42
|
args: [account, depositTokenAddress],
|
|
43
43
|
});
|
|
44
44
|
const data = (0, viem_1.encodeFunctionData)({
|
|
45
|
-
abi:
|
|
45
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
46
46
|
functionName: "multicall",
|
|
47
47
|
args: [[sendCall, bridgeInCall]],
|
|
48
48
|
});
|
|
@@ -53,6 +53,15 @@ function buildSameChainDepositTxn(request) {
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
exports.buildSameChainDepositTxn = buildSameChainDepositTxn;
|
|
56
|
+
function getEmptyBridgeFeeParams() {
|
|
57
|
+
return {
|
|
58
|
+
feeToken: viem_1.zeroAddress,
|
|
59
|
+
feeAmount: 0n,
|
|
60
|
+
feeSwapPath: [],
|
|
61
|
+
minOutputAmount: 0n,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
exports.getEmptyBridgeFeeParams = getEmptyBridgeFeeParams;
|
|
56
65
|
function buildSameChainWithdrawBridgeOutParams(params) {
|
|
57
66
|
return {
|
|
58
67
|
token: params.tokenAddress,
|
|
@@ -70,9 +79,9 @@ function buildSameChainWithdrawTxn(request) {
|
|
|
70
79
|
const { chainId, bridgeOutParams } = request;
|
|
71
80
|
const router = (0, contracts_1.getContract)(chainId, "MultichainTransferRouter");
|
|
72
81
|
const data = (0, viem_1.encodeFunctionData)({
|
|
73
|
-
abi:
|
|
82
|
+
abi: (0, getAbi_1.getAbi)(chainId, "MultichainTransferRouter"),
|
|
74
83
|
functionName: "transferOut",
|
|
75
|
-
args: [bridgeOutParams],
|
|
84
|
+
args: [{ ...bridgeOutParams, bridgeFee: bridgeOutParams.bridgeFee ?? getEmptyBridgeFeeParams() }],
|
|
76
85
|
});
|
|
77
86
|
return { to: router, data, value: 0n };
|
|
78
87
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatAmountHumanParts = exports.formatNumberHuman = exports.formatNumberHumanParts = exports.formatPercentageDisplay = exports.formatUsdPrice = exports.formatUsdPriceParts = exports.formatRatePercentage = exports.formatTokenAmountWithUsd = exports.formatTokenAmountWithUsdParts = exports.formatTokenAmount = exports.formatPercentage = exports.formatDeltaUsd = exports.formatDeltaUsdParts = exports.formatBigUsd = exports.formatBigUsdParts = exports.formatUsd = exports.formatUsdParts = exports.adjustForDecimals = exports.bigintToNumber = exports.trimZeroDecimals = exports.numberToBigint = exports.applyFactor = exports.roundsToZero = exports.roundUpMagnitudeDivision = exports.formatPriceImpactBps = exports.formatBasisPoints = exports.getBasisPoints = exports.basisPointsToFloat = exports.toBigInt = exports.expandDecimals = exports.safeDivide = exports.isNonZero = exports.TRIGGER_PREFIX_BELOW = exports.TRIGGER_PREFIX_ABOVE = exports.PERCENT_PRECISION_DECIMALS = exports.isUint256 = exports.parseUint256DecimalString = exports.MaxInt256 = exports.MaxUint256 = exports.BN_NEGATIVE_ONE = exports.BN_ONE = exports.BN_ZERO = exports.FLOAT_PRECISION_SQRT = exports.FLOAT_PRECISION_SQRT_DECIMALS = exports.PRECISION = exports.PRECISION_DECIMALS = exports.BASIS_POINTS_DECIMALS = exports.BASIS_POINTS_DIVISOR_BIGINT = exports.BASIS_POINTS_DIVISOR = exports.USD_DECIMALS = void 0;
|
|
4
|
-
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.numberWithCommasParts = exports.formatFactor = exports.formatBalanceAmount = exports.formatAmountHuman = void 0;
|
|
4
|
+
exports.absDiffBps = exports.clamp = exports.calculateDisplayDecimals = exports.deserializeBigIntsInObject = exports.serializeBigIntsInObject = exports.removeTrailingZeros = exports.maxbigint = exports.minBigNumber = exports.roundBigIntToDecimals = exports.roundToOrder = exports.roundToTwoDecimals = exports.roundUpDivision = exports.parseValue = exports.toBigNumberWithDecimals = exports.roundWithDecimals = exports.getPlusOrMinusSymbol = exports.padDecimals = exports.limitDecimals = exports.getLimitedDisplay = exports.formatAmountFree = exports.formatArrayAmount = exports.formatKeyAmount = exports.formatAmount = exports.numberWithCommas = exports.numberWithCommasParts = exports.formatFactor = exports.truncateToBalanceDisplayDecimals = exports.formatBalanceAmount = exports.formatAmountHuman = void 0;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const bigmath_1 = require("../bigmath");
|
|
7
7
|
const parts_1 = require("./parts");
|
|
@@ -432,6 +432,12 @@ function formatBalanceAmount(amount, tokenDecimals, tokenSymbol, { showZero = fa
|
|
|
432
432
|
return `${sign}${value}`;
|
|
433
433
|
}
|
|
434
434
|
exports.formatBalanceAmount = formatBalanceAmount;
|
|
435
|
+
function truncateToBalanceDisplayDecimals(amount, tokenDecimals, isStable = false) {
|
|
436
|
+
const displayDecimals = calculateDisplayDecimals(amount, tokenDecimals, 1, isStable);
|
|
437
|
+
const displayStep = expandDecimals(1, Math.max(tokenDecimals - displayDecimals, 0));
|
|
438
|
+
return amount - (amount % displayStep);
|
|
439
|
+
}
|
|
440
|
+
exports.truncateToBalanceDisplayDecimals = truncateToBalanceDisplayDecimals;
|
|
435
441
|
function formatFactor(factor) {
|
|
436
442
|
if (factor == 0n) {
|
|
437
443
|
return "0";
|