@gmx-io/sdk 2.4.0 → 2.7.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/README.md +25 -0
- package/build/cjs/scripts/generate-synthetics-abis.js +17 -2
- package/build/cjs/src/abis/ChainlinkPriceFeedProvider.js +27 -0
- 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/Pausable.js +11 -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 +8 -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 +3 -0
- package/build/cjs/src/configs/contracts.js +27 -18
- package/build/cjs/src/configs/dataStore.js +13 -3
- package/build/cjs/src/configs/express.js +1 -0
- package/build/cjs/src/configs/tokens.js +3 -0
- package/build/cjs/src/utils/__tests__/address.spec.js +50 -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__/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/transactionsErrors.js +17 -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/multichain/__tests__/api.spec.js +11 -1
- package/build/cjs/src/utils/multichain/api.js +19 -9
- 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/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/tradeHistory/utils.js +6 -6
- package/build/esm/scripts/generate-synthetics-abis.js +17 -2
- package/build/esm/src/abis/ChainlinkPriceFeedProvider.js +25 -0
- 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/Pausable.js +9 -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 +8 -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 +3 -0
- package/build/esm/src/configs/contracts.js +25 -17
- package/build/esm/src/configs/dataStore.js +8 -0
- package/build/esm/src/configs/express.js +1 -0
- package/build/esm/src/configs/tokens.js +3 -0
- package/build/esm/src/utils/__tests__/address.spec.js +48 -0
- 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__/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/transactionsErrors.js +17 -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/multichain/__tests__/api.spec.js +11 -1
- package/build/esm/src/utils/multichain/api.js +17 -8
- 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/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/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/ChainlinkPriceFeedProvider.d.ts +41 -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/Pausable.d.ts +12 -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 +6201 -4194
- 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/contracts.d.ts +6 -0
- package/build/types/src/configs/dataStore.d.ts +4 -0
- 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/multichain/api.d.ts +10 -1
- package/build/types/src/utils/orderTransactions/api.d.ts +2 -3
- package/build/types/src/utils/orderTransactions/utils.d.ts +5 -2
- 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/package.json +1 -1
|
@@ -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;
|
|
@@ -120,13 +120,23 @@ function decodeMulticall(data) {
|
|
|
120
120
|
const [decodedDstEid] = (0, viem_1.decodeAbiParameters)([{ type: "uint32" }], params.data);
|
|
121
121
|
(0, vitest_1.expect)(decodedDstEid).toBe(multichain_1.CHAIN_ID_TO_ENDPOINT_ID[chains_1.SOURCE_BASE_MAINNET]);
|
|
122
122
|
});
|
|
123
|
-
(0, vitest_1.it)("
|
|
123
|
+
(0, vitest_1.it)("leaves 50 bps for the bridge fee when slippage is unspecified", () => {
|
|
124
124
|
const params = (0, api_1.buildCrossChainWithdrawBridgeOutParams)({
|
|
125
125
|
tokenAddress: USDC_ARBITRUM,
|
|
126
126
|
amount: 1000000n,
|
|
127
127
|
dstChainId: chains_1.SOURCE_BASE_MAINNET,
|
|
128
128
|
stargateAddress: STARGATE_USDC_ARBITRUM,
|
|
129
129
|
});
|
|
130
|
+
(0, vitest_1.expect)(params.minAmountOut).toBe(995000n);
|
|
131
|
+
});
|
|
132
|
+
(0, vitest_1.it)("keeps minAmountOut equal to amount with zero slippage", () => {
|
|
133
|
+
const params = (0, api_1.buildCrossChainWithdrawBridgeOutParams)({
|
|
134
|
+
tokenAddress: USDC_ARBITRUM,
|
|
135
|
+
amount: 1000000n,
|
|
136
|
+
dstChainId: chains_1.SOURCE_BASE_MAINNET,
|
|
137
|
+
stargateAddress: STARGATE_USDC_ARBITRUM,
|
|
138
|
+
slippageBps: 0,
|
|
139
|
+
});
|
|
130
140
|
(0, vitest_1.expect)(params.minAmountOut).toBe(1000000n);
|
|
131
141
|
});
|
|
132
142
|
});
|
|
@@ -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.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS = 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,13 +79,14 @@ 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
|
}
|
|
79
88
|
exports.buildSameChainWithdrawTxn = buildSameChainWithdrawTxn;
|
|
89
|
+
exports.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS = 50;
|
|
80
90
|
/**
|
|
81
91
|
* `BridgeOutParams.data` for cross-chain delivery is a single `uint32 dstEid`
|
|
82
92
|
* pointing at the destination LayerZero endpoint; the on-chain provider takes
|
|
@@ -85,7 +95,7 @@ exports.buildSameChainWithdrawTxn = buildSameChainWithdrawTxn;
|
|
|
85
95
|
* `utils/express/utils/bridgeOutUtils`.
|
|
86
96
|
*/
|
|
87
97
|
function buildCrossChainWithdrawBridgeOutParams(params) {
|
|
88
|
-
const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps =
|
|
98
|
+
const { tokenAddress, amount, dstChainId, stargateAddress, slippageBps = exports.DEFAULT_CROSS_CHAIN_WITHDRAW_SLIPPAGE_BPS, } = params;
|
|
89
99
|
if (!Number.isInteger(slippageBps) || slippageBps < 0 || slippageBps >= 10000) {
|
|
90
100
|
throw new Error(`slippageBps must be an integer in range [0, 10000), got ${slippageBps}`);
|
|
91
101
|
}
|
|
@@ -180,7 +180,7 @@ function parsePrepareResponse(raw) {
|
|
|
180
180
|
}
|
|
181
181
|
// the express chain stays on the origin that served it: prepare and submit pin that origin by request id, submit and status reuse it
|
|
182
182
|
function chainKeys(prepared) {
|
|
183
|
-
return [prepared.requestId
|
|
183
|
+
return [prepared.requestId];
|
|
184
184
|
}
|
|
185
185
|
async function prepareOrder(ctx, request) {
|
|
186
186
|
return (0, chainPins_1.postJsonPinning)(ctx.api, "/v1/orders/txns/prepare", request, chainKeys, {
|
|
@@ -189,7 +189,7 @@ async function prepareOrder(ctx, request) {
|
|
|
189
189
|
}
|
|
190
190
|
exports.prepareOrder = prepareOrder;
|
|
191
191
|
async function submitOrder(ctx, request) {
|
|
192
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId
|
|
192
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/v1/orders/txns/submit", request);
|
|
193
193
|
}
|
|
194
194
|
exports.submitOrder = submitOrder;
|
|
195
195
|
async function prepareEditOrder(ctx, request) {
|
|
@@ -211,7 +211,7 @@ async function prepareCollateral(ctx, request) {
|
|
|
211
211
|
}
|
|
212
212
|
exports.prepareCollateral = prepareCollateral;
|
|
213
213
|
async function fetchOrderStatus(ctx, request) {
|
|
214
|
-
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId
|
|
214
|
+
return (0, chainPins_1.postJsonPinned)(ctx.api, [request.requestId], "/v1/orders/txns/status", request);
|
|
215
215
|
}
|
|
216
216
|
exports.fetchOrderStatus = fetchOrderStatus;
|
|
217
217
|
async function signPreparedOrder(prepared, signer, chainId, accountAddress) {
|
|
@@ -240,7 +240,6 @@ async function executeExpressOrder(ctx, request, signer, accountAddress) {
|
|
|
240
240
|
requestId: prepared.requestId,
|
|
241
241
|
signature,
|
|
242
242
|
from: accountAddress ?? signer.address,
|
|
243
|
-
idempotencyKey: prepared.idempotencyKey,
|
|
244
243
|
eip712Data: {
|
|
245
244
|
batchParams: prepared.payload.batchParams,
|
|
246
245
|
relayParams: prepared.payload.relayParams,
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getIsInvalidBatchReceiver = exports.getBatchIsNativePayment = exports.getIsEmptyBatch = exports.getBatchSwapsCount = exports.getBatchRequiredActions = exports.encodeExchangeRouterMulticall = exports.buildCancelOrderMulticall = exports.buildUpdateOrderMulticall = exports.buildCreateOrderMulticall = exports.getBatchOrderMulticallPayload = exports.getExternalCallsPayload = exports.getEmptyExternalCallsPayload = exports.combineExternalCalls = exports.getBatchExternalCalls = exports.buildTokenTransfersParamsForIncreaseOrSwap = exports.buildTokenTransfersParamsForDecrease = exports.getBatchExternalSwapGasLimit = exports.getBatchTotalPayCollateralAmount = exports.getExpressBatchOrderParams = exports.getBatchExecutionFeeEstimates = exports.getBatchTotalExecutionFee = exports.buildUpdateOrderPayload = exports.getIsTwapOrderPayload = exports.buildTwapOrdersPayloads = exports.buildDecreaseOrderPayload = exports.buildIncreaseOrderPayload = exports.buildSwapOrderPayload = void 0;
|
|
7
7
|
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
8
|
const viem_1 = require("viem");
|
|
9
|
-
const
|
|
10
|
-
const index_1 = require("../../abis/index");
|
|
9
|
+
const getAbi_1 = require("../../abis/getAbi");
|
|
11
10
|
const Token_1 = __importDefault(require("../../abis/Token"));
|
|
12
11
|
const chains_1 = require("../../configs/chains");
|
|
13
12
|
const contracts_1 = require("../../configs/contracts");
|
|
@@ -294,6 +293,7 @@ function buildUpdateOrderPayload(p) {
|
|
|
294
293
|
minOutputAmount: p.minOutputAmount,
|
|
295
294
|
autoCancel: p.autoCancel,
|
|
296
295
|
validFromTime: 0n,
|
|
296
|
+
decreasePositionSwapType: p.decreasePositionSwapType,
|
|
297
297
|
executionFeeTopUp: p.executionFeeTopUp,
|
|
298
298
|
},
|
|
299
299
|
};
|
|
@@ -567,7 +567,7 @@ function combineTransfers(tokenTransfers) {
|
|
|
567
567
|
}
|
|
568
568
|
return { tokenTransfers: Object.values(transfersMap), value };
|
|
569
569
|
}
|
|
570
|
-
function getBatchOrderMulticallPayload({ params }) {
|
|
570
|
+
function getBatchOrderMulticallPayload({ chainId, params, }) {
|
|
571
571
|
const { createOrderParams, updateOrderParams, cancelOrderParams } = params;
|
|
572
572
|
const multicall = [];
|
|
573
573
|
let value = 0n;
|
|
@@ -586,7 +586,7 @@ function getBatchOrderMulticallPayload({ params }) {
|
|
|
586
586
|
multicall.push(...cancelMulticall);
|
|
587
587
|
value += cancelValue;
|
|
588
588
|
}
|
|
589
|
-
const { encodedMulticall, callData } = encodeExchangeRouterMulticall(multicall);
|
|
589
|
+
const { encodedMulticall, callData } = encodeExchangeRouterMulticall(chainId, multicall);
|
|
590
590
|
return { multicall, value, encodedMulticall, callData };
|
|
591
591
|
}
|
|
592
592
|
exports.getBatchOrderMulticallPayload = getBatchOrderMulticallPayload;
|
|
@@ -640,6 +640,7 @@ function buildUpdateOrderMulticall(updateTxn) {
|
|
|
640
640
|
updatePayload.triggerPrice,
|
|
641
641
|
updatePayload.minOutputAmount,
|
|
642
642
|
0n,
|
|
643
|
+
...((0, contracts_1.isContractsV2_2_1)(chainId) ? [updatePayload.decreasePositionSwapType] : []),
|
|
643
644
|
updatePayload.autoCancel,
|
|
644
645
|
],
|
|
645
646
|
});
|
|
@@ -662,14 +663,14 @@ function buildCancelOrderMulticall({ params }) {
|
|
|
662
663
|
};
|
|
663
664
|
}
|
|
664
665
|
exports.buildCancelOrderMulticall = buildCancelOrderMulticall;
|
|
665
|
-
function encodeExchangeRouterMulticall(multicall) {
|
|
666
|
+
function encodeExchangeRouterMulticall(chainId, multicall) {
|
|
666
667
|
const encodedMulticall = multicall.map((call) => (0, viem_1.encodeFunctionData)({
|
|
667
|
-
abi:
|
|
668
|
+
abi: (0, getAbi_1.getAbi)(chainId, "ExchangeRouter"),
|
|
668
669
|
functionName: call.method,
|
|
669
670
|
args: call.params,
|
|
670
671
|
}));
|
|
671
672
|
const callData = (0, viem_1.encodeFunctionData)({
|
|
672
|
-
abi:
|
|
673
|
+
abi: (0, getAbi_1.getAbi)(chainId, "ExchangeRouter"),
|
|
673
674
|
functionName: "multicall",
|
|
674
675
|
args: [encodedMulticall],
|
|
675
676
|
});
|
|
@@ -1,30 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.encodeReferralCode = exports.decodeReferralCode = exports.MAX_REFERRAL_CODE_LENGTH = void 0;
|
|
3
|
+
exports.encodeReferralCode = exports.decodeReferralCode = exports.isReferralCodeHex = exports.REFERRAL_CODE_REGEX = exports.MAX_REFERRAL_CODE_LENGTH = void 0;
|
|
4
4
|
exports.MAX_REFERRAL_CODE_LENGTH = 20;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
6
|
const utils_1 = require("viem/utils");
|
|
7
|
+
exports.REFERRAL_CODE_REGEX = /^\w+$/;
|
|
8
|
+
const BYTES32_HEX_REGEX = /^0x[0-9a-fA-F]{64}$/;
|
|
9
|
+
function isReferralCodeHex(value) {
|
|
10
|
+
return typeof value === "string" && BYTES32_HEX_REGEX.test(value);
|
|
11
|
+
}
|
|
12
|
+
exports.isReferralCodeHex = isReferralCodeHex;
|
|
13
|
+
/**
|
|
14
|
+
* Codes registered through the UI are letters, digits and `_` right-padded with zeros. The contract accepts any
|
|
15
|
+
* bytes32, so anything else (e.g. left-padded addresses, hashes, other text) is returned as the original hex.
|
|
16
|
+
*/
|
|
7
17
|
function decodeReferralCode(hexCode) {
|
|
8
|
-
if (!hexCode || hexCode === viem_1.zeroHash) {
|
|
18
|
+
if (!hexCode || !isReferralCodeHex(hexCode) || hexCode === viem_1.zeroHash) {
|
|
9
19
|
return "";
|
|
10
20
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let code = "";
|
|
19
|
-
const cleaned = hexCode.substring(2);
|
|
20
|
-
for (let i = 0; i < 32; i++) {
|
|
21
|
-
code += String.fromCharCode(parseInt(cleaned.substring(i * 2, i * 2 + 2), 16));
|
|
22
|
-
}
|
|
23
|
-
return code.trim();
|
|
21
|
+
const bytes = (0, utils_1.hexToBytes)(hexCode);
|
|
22
|
+
const firstZeroIndex = bytes.indexOf(0);
|
|
23
|
+
const textLength = firstZeroIndex === -1 ? bytes.length : firstZeroIndex;
|
|
24
|
+
const text = String.fromCharCode(...bytes.subarray(0, textLength));
|
|
25
|
+
// only the characters `encodeReferralCode` keeps, so the text never points to a different code
|
|
26
|
+
if (!exports.REFERRAL_CODE_REGEX.test(text) || bytes.subarray(textLength).some((byte) => byte !== 0)) {
|
|
27
|
+
return hexCode;
|
|
24
28
|
}
|
|
29
|
+
return text;
|
|
25
30
|
}
|
|
26
31
|
exports.decodeReferralCode = decodeReferralCode;
|
|
27
32
|
function encodeReferralCode(code) {
|
|
33
|
+
if (isReferralCodeHex(code)) {
|
|
34
|
+
// not an address, so no checksum casing; lowercase matches what chain and subgraph return
|
|
35
|
+
return code.toLowerCase();
|
|
36
|
+
}
|
|
28
37
|
let final = code.replace(/[^\w_]/g, ""); // replace everything other than numbers, string and underscor to ''
|
|
29
38
|
if (final.length > exports.MAX_REFERRAL_CODE_LENGTH) {
|
|
30
39
|
return viem_1.zeroHash;
|
|
@@ -1,30 +1,49 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSubaccountApprovalTypedData = void 0;
|
|
3
|
+
exports.getSubaccountApprovalTypedData = exports.SUBACCOUNT_APPROVAL_TYPES_V2_2_1 = exports.SUBACCOUNT_APPROVAL_TYPES = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
+
const contracts_1 = require("../../configs/contracts");
|
|
5
6
|
const dataStore_1 = require("../../configs/dataStore");
|
|
6
7
|
const express_1 = require("../express");
|
|
8
|
+
exports.SUBACCOUNT_APPROVAL_TYPES = {
|
|
9
|
+
SubaccountApproval: [
|
|
10
|
+
{ name: "subaccount", type: "address" },
|
|
11
|
+
{ name: "shouldAdd", type: "bool" },
|
|
12
|
+
{ name: "expiresAt", type: "uint256" },
|
|
13
|
+
{ name: "maxAllowedCount", type: "uint256" },
|
|
14
|
+
{ name: "actionType", type: "bytes32" },
|
|
15
|
+
{ name: "nonce", type: "uint256" },
|
|
16
|
+
{ name: "desChainId", type: "uint256" },
|
|
17
|
+
{ name: "deadline", type: "uint256" },
|
|
18
|
+
{ name: "integrationId", type: "bytes32" },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
exports.SUBACCOUNT_APPROVAL_TYPES_V2_2_1 = {
|
|
22
|
+
SubaccountApproval: [
|
|
23
|
+
{ name: "account", type: "address" },
|
|
24
|
+
{ name: "subaccount", type: "address" },
|
|
25
|
+
{ name: "shouldAdd", type: "bool" },
|
|
26
|
+
{ name: "expiresAt", type: "uint256" },
|
|
27
|
+
{ name: "maxAllowedCount", type: "uint256" },
|
|
28
|
+
{ name: "actionType", type: "bytes32" },
|
|
29
|
+
{ name: "nonce", type: "uint256" },
|
|
30
|
+
{ name: "desChainId", type: "uint256" },
|
|
31
|
+
{ name: "deadline", type: "uint256" },
|
|
32
|
+
{ name: "integrationId", type: "bytes32" },
|
|
33
|
+
{ name: "revocationCounter", type: "uint256" },
|
|
34
|
+
{ name: "eip6492SignatureWrapperHash", type: "bytes32" },
|
|
35
|
+
],
|
|
36
|
+
};
|
|
7
37
|
function getSubaccountApprovalTypedData(params) {
|
|
8
|
-
const { chainId, subaccountAddress, shouldAdd, expiresAt, maxAllowedCount, nonce, signingChainId } = params;
|
|
38
|
+
const { chainId, subaccountAddress, shouldAdd, expiresAt, maxAllowedCount, nonce, account, revocationCounter, signingChainId, } = params;
|
|
39
|
+
const isV2_2_1 = (0, contracts_1.isContractsV2_2_1)(chainId);
|
|
9
40
|
const relayRouterAddress = (0, express_1.getExpressContractAddress)(chainId, {
|
|
10
41
|
isSubaccount: true,
|
|
11
42
|
isMultichain: false,
|
|
12
43
|
scope: "subaccount",
|
|
13
44
|
});
|
|
14
45
|
const domain = (0, express_1.getGelatoRelayRouterDomain)((signingChainId ?? chainId), relayRouterAddress);
|
|
15
|
-
const types =
|
|
16
|
-
SubaccountApproval: [
|
|
17
|
-
{ name: "subaccount", type: "address" },
|
|
18
|
-
{ name: "shouldAdd", type: "bool" },
|
|
19
|
-
{ name: "expiresAt", type: "uint256" },
|
|
20
|
-
{ name: "maxAllowedCount", type: "uint256" },
|
|
21
|
-
{ name: "actionType", type: "bytes32" },
|
|
22
|
-
{ name: "nonce", type: "uint256" },
|
|
23
|
-
{ name: "desChainId", type: "uint256" },
|
|
24
|
-
{ name: "deadline", type: "uint256" },
|
|
25
|
-
{ name: "integrationId", type: "bytes32" },
|
|
26
|
-
],
|
|
27
|
-
};
|
|
46
|
+
const types = isV2_2_1 ? exports.SUBACCOUNT_APPROVAL_TYPES_V2_2_1 : exports.SUBACCOUNT_APPROVAL_TYPES;
|
|
28
47
|
const message = {
|
|
29
48
|
subaccount: subaccountAddress,
|
|
30
49
|
shouldAdd,
|
|
@@ -35,6 +54,9 @@ function getSubaccountApprovalTypedData(params) {
|
|
|
35
54
|
desChainId: chainId.toString(),
|
|
36
55
|
deadline: expiresAt.toString(),
|
|
37
56
|
integrationId: viem_1.zeroHash,
|
|
57
|
+
...(isV2_2_1
|
|
58
|
+
? { account, revocationCounter: revocationCounter.toString(), eip6492SignatureWrapperHash: viem_1.zeroHash }
|
|
59
|
+
: {}),
|
|
38
60
|
};
|
|
39
61
|
return {
|
|
40
62
|
domain,
|
|
@@ -2,27 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.hashSubaccountApproval = void 0;
|
|
4
4
|
const viem_1 = require("viem");
|
|
5
|
-
|
|
5
|
+
const contracts_1 = require("../../configs/contracts");
|
|
6
|
+
const SUBACCOUNT_APPROVAL_COMPONENTS = [
|
|
7
|
+
{ name: "subaccount", type: "address" },
|
|
8
|
+
{ name: "shouldAdd", type: "bool" },
|
|
9
|
+
{ name: "expiresAt", type: "uint256" },
|
|
10
|
+
{ name: "maxAllowedCount", type: "uint256" },
|
|
11
|
+
{ name: "actionType", type: "bytes32" },
|
|
12
|
+
{ name: "nonce", type: "uint256" },
|
|
13
|
+
{ name: "desChainId", type: "uint256" },
|
|
14
|
+
{ name: "deadline", type: "uint256" },
|
|
15
|
+
{ name: "integrationId", type: "bytes32" },
|
|
16
|
+
{ name: "signature", type: "bytes" },
|
|
17
|
+
];
|
|
18
|
+
const SUBACCOUNT_APPROVAL_COMPONENTS_V2_2_1 = [
|
|
19
|
+
{ name: "subaccount", type: "address" },
|
|
20
|
+
{ name: "shouldAdd", type: "bool" },
|
|
21
|
+
{ name: "expiresAt", type: "uint256" },
|
|
22
|
+
{ name: "maxAllowedCount", type: "uint256" },
|
|
23
|
+
{ name: "actionType", type: "bytes32" },
|
|
24
|
+
{ name: "nonce", type: "uint256" },
|
|
25
|
+
{ name: "desChainId", type: "uint256" },
|
|
26
|
+
{ name: "deadline", type: "uint256" },
|
|
27
|
+
{ name: "integrationId", type: "bytes32" },
|
|
28
|
+
{ name: "revocationCounter", type: "uint256" },
|
|
29
|
+
{ name: "eip6492SignatureWrapperHash", type: "bytes32" },
|
|
30
|
+
{ name: "signature", type: "bytes" },
|
|
31
|
+
];
|
|
32
|
+
function hashSubaccountApproval(chainId, approval) {
|
|
6
33
|
if (!approval || !approval.subaccount) {
|
|
7
34
|
return viem_1.zeroHash;
|
|
8
35
|
}
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
{ name: "subaccount", type: "address" },
|
|
14
|
-
{ name: "shouldAdd", type: "bool" },
|
|
15
|
-
{ name: "expiresAt", type: "uint256" },
|
|
16
|
-
{ name: "maxAllowedCount", type: "uint256" },
|
|
17
|
-
{ name: "actionType", type: "bytes32" },
|
|
18
|
-
{ name: "nonce", type: "uint256" },
|
|
19
|
-
{ name: "desChainId", type: "uint256" },
|
|
20
|
-
{ name: "deadline", type: "uint256" },
|
|
21
|
-
{ name: "integrationId", type: "bytes32" },
|
|
22
|
-
{ name: "signature", type: "bytes" },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
], [approval]);
|
|
36
|
+
const components = (0, contracts_1.isContractsV2_2_1)(chainId)
|
|
37
|
+
? SUBACCOUNT_APPROVAL_COMPONENTS_V2_2_1
|
|
38
|
+
: SUBACCOUNT_APPROVAL_COMPONENTS;
|
|
39
|
+
const encodedData = (0, viem_1.encodeAbiParameters)([{ type: "tuple", components }], [approval]);
|
|
26
40
|
return (0, viem_1.keccak256)(encodedData);
|
|
27
41
|
}
|
|
28
42
|
exports.hashSubaccountApproval = hashSubaccountApproval;
|