@gmx-io/sdk 1.5.0-alpha-9 → 1.5.0-alpha-10
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/subsquid-codegen.js +1 -1
- package/build/cjs/src/clients/v2/__tests__/data.spec.js +85 -0
- package/build/cjs/src/clients/v2/__tests__/decrease.spec.js +471 -0
- package/build/cjs/src/clients/v2/__tests__/editCancel.spec.js +259 -0
- package/build/cjs/src/clients/v2/__tests__/errors.spec.js +261 -0
- package/build/cjs/src/clients/v2/__tests__/increase.spec.js +764 -0
- package/build/cjs/src/clients/v2/__tests__/subaccount.spec.js +74 -0
- package/build/cjs/src/clients/v2/__tests__/swap.spec.js +192 -0
- package/build/cjs/src/clients/v2/__tests__/testUtil.js +136 -0
- package/build/cjs/src/clients/v2/index.js +162 -27
- package/build/cjs/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +48 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketConfigKeys.json +342 -0
- package/build/cjs/src/codegen/prebuilt/hashedMarketValuesKeys.json +90 -0
- package/build/cjs/src/codegen/subsquid.js +323 -1
- package/build/cjs/src/configs/chains.js +11 -1
- package/build/cjs/src/configs/contracts.js +7 -7
- package/build/cjs/src/configs/markets.js +56 -2
- package/build/cjs/src/configs/tokens.js +63 -132
- package/build/cjs/src/test/mock.js +1 -1
- package/build/cjs/src/utils/__tests__/markets.spec.js +10 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/cjs/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/cjs/src/utils/__tests__/positions.spec.js +59 -7
- package/build/cjs/src/utils/__tests__/uiFeeReceiver.spec.js +34 -0
- package/build/cjs/src/utils/balances/api.js +65 -0
- package/build/cjs/src/utils/buyback/api.js +7 -0
- package/build/cjs/src/utils/buyback/types.js +2 -0
- package/build/cjs/src/utils/errors/index.js +1 -0
- package/build/cjs/src/utils/errors/isIgnoredEstimateGasError.js +23 -0
- package/build/cjs/src/utils/express/index.js +18 -0
- package/build/cjs/src/utils/express/types.js +2 -0
- package/build/cjs/src/utils/express/utils/batchOrderUtils.js +218 -0
- package/build/cjs/src/utils/express/utils/bridgeOutUtils.js +73 -0
- package/build/cjs/src/utils/express/utils/estimateExpressParams.js +244 -0
- package/build/cjs/src/utils/express/utils/expressParamsUtils.js +22 -0
- package/build/cjs/src/utils/express/utils/fetchGelatoGasTankBalance.js +13 -0
- package/build/cjs/src/utils/express/utils/gelatoRelayUtils.js +77 -0
- package/build/cjs/src/utils/express/utils/globalExpressParams.js +40 -0
- package/build/cjs/src/utils/express/utils/index.js +27 -0
- package/build/cjs/src/utils/express/utils/oracleParamsUtils.js +49 -0
- package/build/cjs/src/utils/express/utils/referralUtils.js +35 -0
- package/build/cjs/src/utils/express/utils/relayParamsUtils.js +208 -0
- package/build/cjs/src/utils/fees/priceImpact.js +1 -2
- package/build/cjs/src/utils/http/http.js +86 -13
- package/build/cjs/src/utils/markets/utils.js +8 -0
- package/build/cjs/src/utils/metrics/index.js +7 -0
- package/build/cjs/src/utils/numbers/utils.js +29 -27
- package/build/cjs/src/utils/orderTransactions/api.js +88 -0
- package/build/cjs/src/utils/orderTransactions/index.js +2 -0
- package/build/cjs/src/utils/orderTransactions/simulation.js +141 -0
- package/build/cjs/src/utils/orderTransactions/utils.js +4 -1
- package/build/cjs/src/utils/orderTransactions/validateTypedData.js +100 -0
- package/build/cjs/src/utils/positions/utils.js +5 -19
- package/build/cjs/src/utils/rpc/createViemRpc.js +39 -0
- package/build/cjs/src/utils/rpc/index.js +5 -0
- package/build/cjs/src/utils/signer/index.js +5 -0
- package/build/cjs/src/utils/signer/privateKeySigner.js +42 -0
- package/build/cjs/src/utils/subaccount/api.js +22 -0
- package/build/cjs/src/utils/subaccount/generateSubaccount.js +19 -0
- package/build/cjs/src/utils/subaccount/getEmptySubaccountApproval.js +24 -0
- package/build/cjs/src/utils/subaccount/getSubaccountApprovalTypedData.js +51 -0
- package/build/cjs/src/utils/subaccount/hashSubaccountApproval.js +28 -0
- package/build/cjs/src/utils/subaccount/index.js +30 -0
- package/build/cjs/src/utils/subaccount/types.js +2 -0
- package/build/cjs/src/utils/swap/swapPath.js +4 -1
- package/build/cjs/src/utils/trade/types.js +1 -1
- package/build/cjs/src/utils/tradeHistory/utils.js +14 -28
- package/build/cjs/src/utils/twap/index.js +4 -1
- package/build/cjs/src/utils/twap/uiFeeReceiver.js +23 -7
- package/build/esm/scripts/subsquid-codegen.js +1 -1
- package/build/esm/src/clients/v2/__tests__/data.spec.js +83 -0
- package/build/esm/src/clients/v2/__tests__/decrease.spec.js +469 -0
- package/build/esm/src/clients/v2/__tests__/editCancel.spec.js +257 -0
- package/build/esm/src/clients/v2/__tests__/errors.spec.js +259 -0
- package/build/esm/src/clients/v2/__tests__/increase.spec.js +762 -0
- package/build/esm/src/clients/v2/__tests__/subaccount.spec.js +72 -0
- package/build/esm/src/clients/v2/__tests__/swap.spec.js +190 -0
- package/build/esm/src/clients/v2/__tests__/testUtil.js +124 -0
- package/build/esm/src/clients/v2/index.js +136 -4
- package/build/esm/src/codegen/prebuilt/hashedKinkModelMarketRatesKeys.json +48 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketConfigKeys.json +342 -0
- package/build/esm/src/codegen/prebuilt/hashedMarketValuesKeys.json +90 -0
- package/build/esm/src/codegen/subsquid.js +321 -0
- package/build/esm/src/configs/chains.js +11 -1
- package/build/esm/src/configs/contracts.js +7 -7
- package/build/esm/src/configs/markets.js +55 -1
- package/build/esm/src/configs/tokens.js +62 -130
- package/build/esm/src/test/mock.js +1 -1
- package/build/esm/src/utils/__tests__/markets.spec.js +10 -0
- package/build/esm/src/utils/__tests__/orderTransactions/decreaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/increaseOrders.spec.js +2 -0
- package/build/esm/src/utils/__tests__/orderTransactions/swapOrders.spec.js +1 -0
- package/build/esm/src/utils/__tests__/positions.spec.js +60 -8
- package/build/esm/src/utils/__tests__/uiFeeReceiver.spec.js +35 -1
- package/build/esm/src/utils/balances/api.js +56 -0
- package/build/esm/src/utils/buyback/api.js +3 -0
- package/build/esm/src/utils/buyback/types.js +1 -0
- package/build/esm/src/utils/errors/index.js +1 -0
- package/build/esm/src/utils/errors/isIgnoredEstimateGasError.js +19 -0
- package/build/esm/src/utils/express/index.js +2 -0
- package/build/esm/src/utils/express/types.js +1 -0
- package/build/esm/src/utils/express/utils/batchOrderUtils.js +210 -0
- package/build/esm/src/utils/express/utils/bridgeOutUtils.js +69 -0
- package/build/esm/src/utils/express/utils/estimateExpressParams.js +238 -0
- package/build/esm/src/utils/express/utils/expressParamsUtils.js +16 -0
- package/build/esm/src/utils/express/utils/fetchGelatoGasTankBalance.js +9 -0
- package/build/esm/src/utils/express/utils/gelatoRelayUtils.js +71 -0
- package/build/esm/src/utils/express/utils/globalExpressParams.js +36 -0
- package/build/esm/src/utils/express/utils/index.js +11 -0
- package/build/esm/src/utils/express/utils/oracleParamsUtils.js +42 -0
- package/build/esm/src/utils/express/utils/referralUtils.js +30 -0
- package/build/esm/src/utils/express/utils/relayParamsUtils.js +198 -0
- package/build/esm/src/utils/fees/priceImpact.js +1 -2
- package/build/esm/src/utils/http/http.js +84 -12
- package/build/esm/src/utils/markets/utils.js +8 -0
- package/build/esm/src/utils/metrics/index.js +4 -0
- package/build/esm/src/utils/numbers/utils.js +25 -24
- package/build/esm/src/utils/orderTransactions/api.js +77 -0
- package/build/esm/src/utils/orderTransactions/index.js +2 -0
- package/build/esm/src/utils/orderTransactions/simulation.js +136 -0
- package/build/esm/src/utils/orderTransactions/utils.js +4 -1
- package/build/esm/src/utils/orderTransactions/validateTypedData.js +95 -0
- package/build/esm/src/utils/positions/utils.js +5 -19
- package/build/esm/src/utils/rpc/createViemRpc.js +35 -0
- package/build/esm/src/utils/rpc/index.js +1 -0
- package/build/esm/src/utils/signer/index.js +1 -0
- package/build/esm/src/utils/signer/privateKeySigner.js +38 -0
- package/build/esm/src/utils/subaccount/api.js +16 -0
- package/build/esm/src/utils/subaccount/generateSubaccount.js +15 -0
- package/build/esm/src/utils/subaccount/getEmptySubaccountApproval.js +20 -0
- package/build/esm/src/utils/subaccount/getSubaccountApprovalTypedData.js +47 -0
- package/build/esm/src/utils/subaccount/hashSubaccountApproval.js +24 -0
- package/build/esm/src/utils/subaccount/index.js +6 -0
- package/build/esm/src/utils/subaccount/types.js +1 -0
- package/build/esm/src/utils/swap/swapPath.js +5 -2
- package/build/esm/src/utils/trade/types.js +1 -1
- package/build/esm/src/utils/tradeHistory/utils.js +13 -26
- package/build/esm/src/utils/twap/index.js +1 -0
- package/build/esm/src/utils/twap/uiFeeReceiver.js +20 -6
- package/build/types/src/clients/v2/__tests__/data.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/decrease.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/editCancel.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/errors.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/increase.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/subaccount.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/swap.spec.d.ts +1 -0
- package/build/types/src/clients/v2/__tests__/testUtil.d.ts +25 -0
- package/build/types/src/clients/v2/index.d.ts +59 -1
- package/build/types/src/codegen/prebuilt/index.d.ts +480 -0
- package/build/types/src/codegen/subsquid.d.ts +1276 -44
- package/build/types/src/configs/chains.d.ts +10 -1
- package/build/types/src/configs/contracts.d.ts +6 -6
- package/build/types/src/configs/markets.d.ts +5 -0
- package/build/types/src/configs/tokens.d.ts +6 -1
- package/build/types/src/utils/balances/api.d.ts +39 -0
- package/build/types/src/utils/buyback/api.d.ts +5 -0
- package/build/types/src/utils/buyback/types.d.ts +15 -0
- package/build/types/src/utils/chains/types.d.ts +1 -0
- package/build/types/src/utils/errors/index.d.ts +1 -0
- package/build/types/src/utils/errors/isIgnoredEstimateGasError.d.ts +2 -0
- package/build/types/src/utils/express/index.d.ts +2 -0
- package/build/types/src/utils/express/types.d.ts +95 -0
- package/build/types/src/utils/express/utils/batchOrderUtils.d.ts +98 -0
- package/build/types/src/utils/express/utils/bridgeOutUtils.d.ts +21 -0
- package/build/types/src/utils/express/utils/estimateExpressParams.d.ts +37 -0
- package/build/types/src/utils/express/utils/expressParamsUtils.d.ts +19 -0
- package/build/types/src/utils/express/utils/fetchGelatoGasTankBalance.d.ts +5 -0
- package/build/types/src/utils/express/utils/gelatoRelayUtils.d.ts +25 -0
- package/build/types/src/utils/express/utils/globalExpressParams.d.ts +31 -0
- package/build/types/src/utils/express/utils/index.d.ts +11 -0
- package/build/types/src/utils/express/utils/oracleParamsUtils.d.ts +10 -0
- package/build/types/src/utils/express/utils/referralUtils.d.ts +17 -0
- package/build/types/src/utils/express/utils/relayParamsUtils.d.ts +63 -0
- package/build/types/src/utils/http/http.d.ts +16 -1
- package/build/types/src/utils/http/types.d.ts +3 -0
- package/build/types/src/utils/metrics/index.d.ts +4 -0
- package/build/types/src/utils/numbers/utils.d.ts +2 -5
- package/build/types/src/utils/orderTransactions/api.d.ts +158 -0
- package/build/types/src/utils/orderTransactions/index.d.ts +2 -0
- package/build/types/src/utils/orderTransactions/simulation.d.ts +26 -0
- package/build/types/src/utils/orderTransactions/validateTypedData.d.ts +6 -0
- package/build/types/src/utils/positions/utils.d.ts +1 -9
- package/build/types/src/utils/rpc/createViemRpc.d.ts +3 -0
- package/build/types/src/utils/rpc/index.d.ts +26 -0
- package/build/types/src/utils/signer/index.d.ts +23 -0
- package/build/types/src/utils/signer/privateKeySigner.d.ts +19 -0
- package/build/types/src/utils/subaccount/api.d.ts +50 -0
- package/build/types/src/utils/subaccount/generateSubaccount.d.ts +8 -0
- package/build/types/src/utils/subaccount/getEmptySubaccountApproval.d.ts +9 -0
- package/build/types/src/utils/subaccount/getSubaccountApprovalTypedData.d.ts +24 -0
- package/build/types/src/utils/subaccount/hashSubaccountApproval.d.ts +1 -0
- package/build/types/src/utils/subaccount/index.d.ts +7 -0
- package/build/types/src/utils/subaccount/types.d.ts +55 -0
- package/build/types/src/utils/tokens/types.d.ts +0 -1
- package/build/types/src/utils/trade/types.d.ts +1 -1
- package/build/types/src/utils/tradeHistory/utils.d.ts +0 -1
- package/build/types/src/utils/twap/index.d.ts +1 -0
- package/build/types/src/utils/twap/types.d.ts +2 -0
- package/build/types/src/utils/twap/uiFeeReceiver.d.ts +10 -2
- package/package.json +40 -3
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.estimateExpressParams = exports.getGasPaymentValidations = exports.getNeedTokenApprove = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const factors_1 = require("../../../configs/factors");
|
|
6
|
+
const tokens_1 = require("../../../configs/tokens");
|
|
7
|
+
const bigmath_1 = require("../../bigmath");
|
|
8
|
+
const errors_1 = require("../../errors");
|
|
9
|
+
const executionFee_1 = require("../../fees/executionFee");
|
|
10
|
+
const metrics_1 = require("../../metrics");
|
|
11
|
+
const numbers_1 = require("../../numbers");
|
|
12
|
+
const time_1 = require("../../time");
|
|
13
|
+
const expressParamsUtils_1 = require("./expressParamsUtils");
|
|
14
|
+
const relayParamsUtils_1 = require("./relayParamsUtils");
|
|
15
|
+
function getNeedTokenApprove(tokenAllowanceData, tokenAddress, amountToSpend, permits) {
|
|
16
|
+
if (tokenAddress === tokens_1.NATIVE_TOKEN_ADDRESS || amountToSpend === undefined || amountToSpend <= 0n) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (!tokenAllowanceData || !tokenAddress || tokenAllowanceData[tokenAddress] === undefined) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const shouldApprove = amountToSpend > tokenAllowanceData[tokenAddress];
|
|
23
|
+
const signedPermit = permits.find((permit) => permit.token === tokenAddress && BigInt(permit.value) >= amountToSpend && Number(permit.deadline) > (0, time_1.nowInSeconds)());
|
|
24
|
+
return shouldApprove && !signedPermit;
|
|
25
|
+
}
|
|
26
|
+
exports.getNeedTokenApprove = getNeedTokenApprove;
|
|
27
|
+
function getGasPaymentValidations({ gasPaymentToken, gasPaymentTokenAmount, gasPaymentTokenAsCollateralAmount, gasPaymentAllowanceData, tokenPermits, isGmxAccount, }) {
|
|
28
|
+
const gasTokenAmountWithBuffer = bigmath_1.bigMath.mulDiv(gasPaymentTokenAmount, 13n, 10n);
|
|
29
|
+
const totalGasPaymentTokenAmount = gasPaymentTokenAsCollateralAmount + gasTokenAmountWithBuffer;
|
|
30
|
+
const tokenBalance = isGmxAccount ? gasPaymentToken.gmxAccountBalance : gasPaymentToken.walletBalance;
|
|
31
|
+
const isOutGasTokenBalance = tokenBalance === undefined || totalGasPaymentTokenAmount > tokenBalance;
|
|
32
|
+
const needGasPaymentTokenApproval = isGmxAccount
|
|
33
|
+
? false
|
|
34
|
+
: getNeedTokenApprove(gasPaymentAllowanceData, gasPaymentToken.address, totalGasPaymentTokenAmount, tokenPermits);
|
|
35
|
+
return {
|
|
36
|
+
isOutGasTokenBalance,
|
|
37
|
+
needGasPaymentTokenApproval,
|
|
38
|
+
isValid: !isOutGasTokenBalance && !needGasPaymentTokenApproval,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
exports.getGasPaymentValidations = getGasPaymentValidations;
|
|
42
|
+
async function estimateExpressParams({ chainId, isGmxAccount, transactionParams, globalExpressParams, estimationMethod = "approximate", requireValidations = true, subaccount: rawSubaccount, throwOnInvalid = false, overrideGasLimit, rpc, simulationOrigin, stateOverride, metrics = metrics_1.noopMetrics, gasPaymentAllowanceData, getSubaccountValidations, }) {
|
|
43
|
+
if (requireValidations && !transactionParams.isValid) {
|
|
44
|
+
if (throwOnInvalid) {
|
|
45
|
+
throw new expressParamsUtils_1.ExpressEstimationError("transactionParams is invalid");
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
const { findFeeSwapPath, gasLimits, gasPaymentToken, relayerFeeToken, l1Reference, tokenPermits: rawTokenPermits, gasPrice, bufferBps, } = globalExpressParams;
|
|
50
|
+
const { expressTransactionBuilder, gasPaymentTokenAsCollateralAmount, executionFeeAmount, executionGasLimit, transactionPayloadGasLimit, transactionExternalCalls, subaccountActions, account, } = transactionParams;
|
|
51
|
+
const subaccountRouterAddress = rawSubaccount
|
|
52
|
+
? (0, relayParamsUtils_1.getExpressContractAddress)(chainId, {
|
|
53
|
+
isSubaccount: true,
|
|
54
|
+
isMultichain: isGmxAccount,
|
|
55
|
+
scope: "subaccount",
|
|
56
|
+
})
|
|
57
|
+
: undefined;
|
|
58
|
+
const subaccountValidations = rawSubaccount && getSubaccountValidations && subaccountRouterAddress
|
|
59
|
+
? getSubaccountValidations({
|
|
60
|
+
requiredActions: subaccountActions,
|
|
61
|
+
subaccount: rawSubaccount,
|
|
62
|
+
subaccountRouterAddress,
|
|
63
|
+
})
|
|
64
|
+
: undefined;
|
|
65
|
+
const subaccount = subaccountValidations?.isValid ? rawSubaccount : undefined;
|
|
66
|
+
const tokenPermits = isGmxAccount ? [] : rawTokenPermits;
|
|
67
|
+
// --- Pass 1: base estimate with assumed feeSwapsCount=1, oraclePriceCount=2 ---
|
|
68
|
+
const baseRelayerGasLimit = overrideGasLimit ??
|
|
69
|
+
(0, executionFee_1.estimateRelayerGasLimit)({
|
|
70
|
+
gasLimits,
|
|
71
|
+
tokenPermitsCount: tokenPermits.length,
|
|
72
|
+
feeSwapsCount: 1,
|
|
73
|
+
feeExternalCallsGasLimit: 0n,
|
|
74
|
+
oraclePriceCount: 2,
|
|
75
|
+
l1GasLimit: l1Reference?.gasLimit ?? 0n,
|
|
76
|
+
transactionPayloadGasLimit,
|
|
77
|
+
});
|
|
78
|
+
const baseRelayerFeeAmount = baseRelayerGasLimit * gasPrice;
|
|
79
|
+
const baseTotalRelayerFeeTokenAmount = baseRelayerFeeAmount + executionFeeAmount;
|
|
80
|
+
const baseRelayFeeParams = (0, relayParamsUtils_1.getRelayerFeeParams)({
|
|
81
|
+
chainId,
|
|
82
|
+
account,
|
|
83
|
+
gasPaymentToken,
|
|
84
|
+
relayerFeeToken,
|
|
85
|
+
relayerFeeAmount: baseRelayerFeeAmount,
|
|
86
|
+
totalRelayerFeeTokenAmount: baseTotalRelayerFeeTokenAmount,
|
|
87
|
+
gasPaymentTokenAsCollateralAmount,
|
|
88
|
+
transactionExternalCalls,
|
|
89
|
+
feeExternalSwapQuote: undefined,
|
|
90
|
+
findFeeSwapPath,
|
|
91
|
+
});
|
|
92
|
+
if (!baseRelayFeeParams) {
|
|
93
|
+
if (throwOnInvalid) {
|
|
94
|
+
throw new expressParamsUtils_1.ExpressEstimationError("baseRelayFeeParams is undefined");
|
|
95
|
+
}
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
const baseRelayParams = (0, relayParamsUtils_1.getRawRelayerParams)({
|
|
99
|
+
chainId,
|
|
100
|
+
gasPaymentTokenAddress: gasPaymentToken.address,
|
|
101
|
+
relayerFeeTokenAddress: relayerFeeToken.address,
|
|
102
|
+
feeParams: baseRelayFeeParams.feeParams,
|
|
103
|
+
externalCalls: baseRelayFeeParams.externalCalls,
|
|
104
|
+
tokenPermits,
|
|
105
|
+
});
|
|
106
|
+
// Build txn to measure calldata size for L1 gas buffer
|
|
107
|
+
const baseTxn = await expressTransactionBuilder({
|
|
108
|
+
relayParams: baseRelayParams,
|
|
109
|
+
gasPaymentParams: baseRelayFeeParams.gasPaymentParams,
|
|
110
|
+
subaccount,
|
|
111
|
+
});
|
|
112
|
+
const l1GasLimit = l1Reference
|
|
113
|
+
? (0, executionFee_1.approximateL1GasBuffer)({
|
|
114
|
+
l1Reference,
|
|
115
|
+
sizeOfData: BigInt((0, viem_1.size)(baseTxn.txnData.callData)),
|
|
116
|
+
})
|
|
117
|
+
: 0n;
|
|
118
|
+
// --- Determine gas limit ---
|
|
119
|
+
let gasLimit;
|
|
120
|
+
if (overrideGasLimit !== undefined) {
|
|
121
|
+
gasLimit = overrideGasLimit;
|
|
122
|
+
}
|
|
123
|
+
else if (estimationMethod === "estimateGas") {
|
|
124
|
+
if (!rpc || !simulationOrigin) {
|
|
125
|
+
throw new expressParamsUtils_1.ExpressEstimationError("rpc and simulationOrigin are required for estimateGas mode");
|
|
126
|
+
}
|
|
127
|
+
const baseGasPaymentValidations = getGasPaymentValidations({
|
|
128
|
+
gasPaymentToken,
|
|
129
|
+
gasPaymentTokenAsCollateralAmount,
|
|
130
|
+
gasPaymentTokenAmount: baseRelayFeeParams.gasPaymentParams.gasPaymentTokenAmount,
|
|
131
|
+
gasPaymentAllowanceData,
|
|
132
|
+
isGmxAccount,
|
|
133
|
+
tokenPermits,
|
|
134
|
+
});
|
|
135
|
+
if (baseGasPaymentValidations.isOutGasTokenBalance ||
|
|
136
|
+
baseGasPaymentValidations.needGasPaymentTokenApproval ||
|
|
137
|
+
!transactionParams.isValid) {
|
|
138
|
+
if (throwOnInvalid) {
|
|
139
|
+
throw new expressParamsUtils_1.ExpressEstimationInsufficientGasPaymentTokenBalanceError({
|
|
140
|
+
balance: isGmxAccount ? gasPaymentToken.gmxAccountBalance : gasPaymentToken.walletBalance,
|
|
141
|
+
requiredAmount: baseRelayFeeParams.gasPaymentParams.gasPaymentTokenAmount,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const estimated = await rpc.estimateGas({
|
|
148
|
+
from: simulationOrigin,
|
|
149
|
+
to: baseTxn.txnData.to,
|
|
150
|
+
data: baseTxn.txnData.callData,
|
|
151
|
+
value: 0n,
|
|
152
|
+
stateOverride,
|
|
153
|
+
});
|
|
154
|
+
gasLimit = estimated < 22000n ? 22000n : estimated;
|
|
155
|
+
gasLimit = (gasLimit * 11n) / 10n;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (!(0, errors_1.isIgnoredEstimateGasError)(error)) {
|
|
159
|
+
metrics.pushError((0, errors_1.extendError)(error, { data: { estimationMethod } }), "expressOrders.estimateGas");
|
|
160
|
+
}
|
|
161
|
+
if (throwOnInvalid) {
|
|
162
|
+
throw new expressParamsUtils_1.ExpressEstimationError("gas limit estimation failed");
|
|
163
|
+
}
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// approximate mode
|
|
169
|
+
gasLimit = (0, executionFee_1.estimateRelayerGasLimit)({
|
|
170
|
+
gasLimits,
|
|
171
|
+
tokenPermitsCount: tokenPermits.length,
|
|
172
|
+
feeSwapsCount: baseRelayFeeParams.feeParams.feeSwapPath.length,
|
|
173
|
+
feeExternalCallsGasLimit: baseRelayFeeParams.feeExternalSwapGasLimit,
|
|
174
|
+
oraclePriceCount: baseRelayParams.oracleParams.tokens.length,
|
|
175
|
+
l1GasLimit,
|
|
176
|
+
transactionPayloadGasLimit,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
// --- Pass 2: final fee calculation with actual gas limit ---
|
|
180
|
+
let relayerFeeAmount = (0, numbers_1.applyFactor)(gasLimit * gasPrice, gasLimits.gelatoRelayFeeMultiplierFactor);
|
|
181
|
+
const buffer = bigmath_1.bigMath.mulDiv(relayerFeeAmount, BigInt(bufferBps), factors_1.BASIS_POINTS_DIVISOR_BIGINT);
|
|
182
|
+
relayerFeeAmount += buffer;
|
|
183
|
+
const totalRelayerFeeTokenAmount = relayerFeeAmount + executionFeeAmount;
|
|
184
|
+
const finalRelayFeeParams = (0, relayParamsUtils_1.getRelayerFeeParams)({
|
|
185
|
+
chainId,
|
|
186
|
+
account,
|
|
187
|
+
gasPaymentToken,
|
|
188
|
+
relayerFeeToken,
|
|
189
|
+
relayerFeeAmount,
|
|
190
|
+
totalRelayerFeeTokenAmount,
|
|
191
|
+
gasPaymentTokenAsCollateralAmount,
|
|
192
|
+
transactionExternalCalls,
|
|
193
|
+
feeExternalSwapQuote: undefined,
|
|
194
|
+
findFeeSwapPath,
|
|
195
|
+
});
|
|
196
|
+
if (!finalRelayFeeParams) {
|
|
197
|
+
if (throwOnInvalid) {
|
|
198
|
+
throw new expressParamsUtils_1.ExpressEstimationError("finalRelayFeeParams is undefined");
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
const finalRelayParams = (0, relayParamsUtils_1.getRawRelayerParams)({
|
|
203
|
+
chainId,
|
|
204
|
+
gasPaymentTokenAddress: gasPaymentToken.address,
|
|
205
|
+
relayerFeeTokenAddress: relayerFeeToken.address,
|
|
206
|
+
feeParams: finalRelayFeeParams.feeParams,
|
|
207
|
+
externalCalls: finalRelayFeeParams.externalCalls,
|
|
208
|
+
tokenPermits,
|
|
209
|
+
});
|
|
210
|
+
// --- Validations ---
|
|
211
|
+
const gasPaymentValidations = getGasPaymentValidations({
|
|
212
|
+
gasPaymentToken,
|
|
213
|
+
gasPaymentTokenAmount: finalRelayFeeParams.gasPaymentParams.gasPaymentTokenAmount,
|
|
214
|
+
gasPaymentTokenAsCollateralAmount,
|
|
215
|
+
gasPaymentAllowanceData,
|
|
216
|
+
isGmxAccount,
|
|
217
|
+
tokenPermits,
|
|
218
|
+
});
|
|
219
|
+
if (requireValidations && !(0, expressParamsUtils_1.getIsValidExpressParams)({ chainId, gasPaymentValidations })) {
|
|
220
|
+
if (throwOnInvalid) {
|
|
221
|
+
throw new expressParamsUtils_1.ExpressEstimationInsufficientGasPaymentTokenBalanceError({
|
|
222
|
+
balance: isGmxAccount ? gasPaymentToken.gmxAccountBalance : gasPaymentToken.walletBalance,
|
|
223
|
+
requiredAmount: finalRelayFeeParams.gasPaymentParams.gasPaymentTokenAmount,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
return {
|
|
229
|
+
chainId,
|
|
230
|
+
subaccount,
|
|
231
|
+
relayParamsPayload: finalRelayParams,
|
|
232
|
+
gasPaymentParams: finalRelayFeeParams.gasPaymentParams,
|
|
233
|
+
executionFeeAmount,
|
|
234
|
+
executionGasLimit,
|
|
235
|
+
estimationMethod: estimationMethod ?? "approximate",
|
|
236
|
+
gasLimit,
|
|
237
|
+
l1GasLimit,
|
|
238
|
+
gasPrice,
|
|
239
|
+
subaccountValidations,
|
|
240
|
+
gasPaymentValidations,
|
|
241
|
+
isGmxAccount,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
exports.estimateExpressParams = estimateExpressParams;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIsValidExpressParams = exports.ExpressEstimationInsufficientGasPaymentTokenBalanceError = exports.ExpressEstimationError = void 0;
|
|
4
|
+
class ExpressEstimationError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.name = "ExpressEstimationError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.ExpressEstimationError = ExpressEstimationError;
|
|
11
|
+
class ExpressEstimationInsufficientGasPaymentTokenBalanceError extends ExpressEstimationError {
|
|
12
|
+
constructor(params) {
|
|
13
|
+
super();
|
|
14
|
+
this.params = params;
|
|
15
|
+
this.name = "ExpressEstimationInsufficientGasPaymentTokenBalanceError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.ExpressEstimationInsufficientGasPaymentTokenBalanceError = ExpressEstimationInsufficientGasPaymentTokenBalanceError;
|
|
19
|
+
function getIsValidExpressParams({ gasPaymentValidations, }) {
|
|
20
|
+
return gasPaymentValidations.isValid;
|
|
21
|
+
}
|
|
22
|
+
exports.getIsValidExpressParams = getIsValidExpressParams;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchGelatoGasTankBalance = void 0;
|
|
4
|
+
const express_1 = require("../../../configs/express");
|
|
5
|
+
const gelatoRelay_1 = require("../../gelatoRelay");
|
|
6
|
+
async function fetchGelatoGasTankBalance(chainId) {
|
|
7
|
+
const apiKey = express_1.GELATO_API_KEYS[chainId];
|
|
8
|
+
if (!apiKey)
|
|
9
|
+
return undefined;
|
|
10
|
+
const relayer = (0, gelatoRelay_1.getGelatoRelayerClient)(apiKey);
|
|
11
|
+
return relayer.getBalance();
|
|
12
|
+
}
|
|
13
|
+
exports.fetchGelatoGasTankBalance = fetchGelatoGasTankBalance;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.waitForGelatoTask = exports.sendToGelatoRelay = exports.GelatoRelayError = void 0;
|
|
4
|
+
const gasless_1 = require("@gelatocloud/gasless");
|
|
5
|
+
const viem_1 = require("viem");
|
|
6
|
+
const express_1 = require("../../../configs/express");
|
|
7
|
+
const utils_1 = require("../../gelatoRelay/utils");
|
|
8
|
+
class GelatoRelayError extends Error {
|
|
9
|
+
constructor(message, cause) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.cause = cause;
|
|
12
|
+
this.name = "GelatoRelayError";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.GelatoRelayError = GelatoRelayError;
|
|
16
|
+
async function sendToGelatoRelay({ chainId, txnData, }) {
|
|
17
|
+
const data = (0, viem_1.encodePacked)(["bytes", "address", "address", "uint256"], [txnData.callData, txnData.to, txnData.feeToken, txnData.feeAmount]);
|
|
18
|
+
const apiKey = express_1.GELATO_API_KEYS[chainId];
|
|
19
|
+
if (!apiKey) {
|
|
20
|
+
throw new GelatoRelayError(`Gelato API key not configured for chain ${chainId}`);
|
|
21
|
+
}
|
|
22
|
+
const relayerClient = (0, utils_1.getGelatoRelayerClient)(apiKey);
|
|
23
|
+
let taskId;
|
|
24
|
+
try {
|
|
25
|
+
taskId = await relayerClient.sendTransaction({
|
|
26
|
+
chainId,
|
|
27
|
+
to: txnData.to,
|
|
28
|
+
data: data,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
throw new GelatoRelayError(`Gelato relay failed: ${e?.message ?? String(e)}`, e);
|
|
33
|
+
}
|
|
34
|
+
if (!taskId) {
|
|
35
|
+
throw new GelatoRelayError("Gelato relay returned no taskId");
|
|
36
|
+
}
|
|
37
|
+
return { taskId, relayerClient };
|
|
38
|
+
}
|
|
39
|
+
exports.sendToGelatoRelay = sendToGelatoRelay;
|
|
40
|
+
async function waitForGelatoTask(relayerClient, taskId, options) {
|
|
41
|
+
try {
|
|
42
|
+
const receipt = await relayerClient.waitForReceipt({
|
|
43
|
+
id: taskId,
|
|
44
|
+
timeout: options?.timeout ?? 120000,
|
|
45
|
+
pollingInterval: options?.pollingInterval ?? 1000,
|
|
46
|
+
throwOnReverted: true,
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
transactionHash: receipt.transactionHash,
|
|
50
|
+
blockNumber: Number(receipt.blockNumber),
|
|
51
|
+
status: "success",
|
|
52
|
+
statusCode: utils_1.StatusCode.Success,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof gasless_1.TransactionRevertedError) {
|
|
57
|
+
return {
|
|
58
|
+
transactionHash: error.receipt.transactionHash,
|
|
59
|
+
blockNumber: undefined,
|
|
60
|
+
status: "failed",
|
|
61
|
+
statusCode: utils_1.StatusCode.Reverted,
|
|
62
|
+
message: error.errorMessage,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (error instanceof gasless_1.TransactionRejectedError) {
|
|
66
|
+
return {
|
|
67
|
+
transactionHash: undefined,
|
|
68
|
+
blockNumber: undefined,
|
|
69
|
+
status: "failed",
|
|
70
|
+
statusCode: utils_1.StatusCode.Rejected,
|
|
71
|
+
message: error.errorMessage,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.waitForGelatoTask = waitForGelatoTask;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildGlobalExpressParams = void 0;
|
|
4
|
+
const express_1 = require("../../../configs/express");
|
|
5
|
+
const types_1 = require("../../orders/types");
|
|
6
|
+
const swapPath_1 = require("../../swap/swapPath");
|
|
7
|
+
function buildGlobalExpressParams({ chainId, gasLimits, gasPrice, tokensData, marketsInfoData, gasPaymentTokenAddress, tokenPermits = [], l1Reference, bufferBps = express_1.EXPRESS_EXTRA_EXECUTION_FEE_BUFFER_BPS, }) {
|
|
8
|
+
const resolvedGasPaymentTokenAddress = gasPaymentTokenAddress ?? (0, express_1.getDefaultGasPaymentToken)(chainId);
|
|
9
|
+
const relayerFeeToken = (0, express_1.getRelayerFeeToken)(chainId);
|
|
10
|
+
const findFeeSwapPath = (0, swapPath_1.createFindSwapPath)({
|
|
11
|
+
chainId,
|
|
12
|
+
fromTokenAddress: resolvedGasPaymentTokenAddress,
|
|
13
|
+
toTokenAddress: relayerFeeToken.address,
|
|
14
|
+
marketsInfoData,
|
|
15
|
+
gasEstimationParams: {
|
|
16
|
+
gasPrice,
|
|
17
|
+
gasLimits,
|
|
18
|
+
tokensData,
|
|
19
|
+
},
|
|
20
|
+
swapPricingType: types_1.SwapPricingType.AtomicSwap,
|
|
21
|
+
});
|
|
22
|
+
const gasPaymentToken = tokensData[resolvedGasPaymentTokenAddress];
|
|
23
|
+
const resolvedRelayerFeeToken = tokensData[relayerFeeToken.address];
|
|
24
|
+
return {
|
|
25
|
+
chainId,
|
|
26
|
+
gasLimits,
|
|
27
|
+
gasPrice,
|
|
28
|
+
tokensData,
|
|
29
|
+
marketsInfoData,
|
|
30
|
+
gasPaymentTokenAddress: resolvedGasPaymentTokenAddress,
|
|
31
|
+
relayerFeeTokenAddress: relayerFeeToken.address,
|
|
32
|
+
gasPaymentToken,
|
|
33
|
+
relayerFeeToken: resolvedRelayerFeeToken,
|
|
34
|
+
tokenPermits,
|
|
35
|
+
l1Reference,
|
|
36
|
+
bufferBps,
|
|
37
|
+
findFeeSwapPath,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.buildGlobalExpressParams = buildGlobalExpressParams;
|
|
@@ -0,0 +1,27 @@
|
|
|
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("../types"), exports);
|
|
18
|
+
__exportStar(require("./oracleParamsUtils"), exports);
|
|
19
|
+
__exportStar(require("./relayParamsUtils"), exports);
|
|
20
|
+
__exportStar(require("./batchOrderUtils"), exports);
|
|
21
|
+
__exportStar(require("./gelatoRelayUtils"), exports);
|
|
22
|
+
__exportStar(require("./globalExpressParams"), exports);
|
|
23
|
+
__exportStar(require("./expressParamsUtils"), exports);
|
|
24
|
+
__exportStar(require("./estimateExpressParams"), exports);
|
|
25
|
+
__exportStar(require("./fetchGelatoGasTankBalance"), exports);
|
|
26
|
+
__exportStar(require("./bridgeOutUtils"), exports);
|
|
27
|
+
__exportStar(require("./referralUtils"), exports);
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getOracleParamsForRelayParams = void 0;
|
|
7
|
+
const uniq_1 = __importDefault(require("lodash/uniq"));
|
|
8
|
+
const contracts_1 = require("../../../configs/contracts");
|
|
9
|
+
const markets_1 = require("../../../configs/markets");
|
|
10
|
+
const tokens_1 = require("../../../configs/tokens");
|
|
11
|
+
const markets_2 = require("../../markets");
|
|
12
|
+
function getOracleParams({ chainId, tokenAddresses }) {
|
|
13
|
+
const uniqTokenAddresses = (0, uniq_1.default)(tokenAddresses.map((tokenAddress) => (0, tokens_1.convertTokenAddress)(chainId, tokenAddress, "wrapped")));
|
|
14
|
+
const chainLinkPriceFeedProvider = (0, contracts_1.getContract)(chainId, "ChainlinkPriceFeedProvider");
|
|
15
|
+
return {
|
|
16
|
+
tokens: uniqTokenAddresses,
|
|
17
|
+
providers: Array(uniqTokenAddresses.length).fill(chainLinkPriceFeedProvider),
|
|
18
|
+
data: Array(uniqTokenAddresses.length).fill("0x"),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function getOracleParamsForRelayParams({ chainId, gasPaymentTokenAddress, relayerFeeTokenAddress, feeSwapPath, externalCalls, }) {
|
|
22
|
+
const tokenAddresses = [gasPaymentTokenAddress, relayerFeeTokenAddress];
|
|
23
|
+
if (externalCalls) {
|
|
24
|
+
tokenAddresses.push(...externalCalls.sendTokens);
|
|
25
|
+
}
|
|
26
|
+
if (feeSwapPath.length) {
|
|
27
|
+
tokenAddresses.push(...getSwapPathOracleTokens({
|
|
28
|
+
chainId,
|
|
29
|
+
initialCollateralAddress: gasPaymentTokenAddress,
|
|
30
|
+
swapPath: feeSwapPath,
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
return getOracleParams({ chainId, tokenAddresses });
|
|
34
|
+
}
|
|
35
|
+
exports.getOracleParamsForRelayParams = getOracleParamsForRelayParams;
|
|
36
|
+
function getSwapPathOracleTokens({ chainId, initialCollateralAddress, swapPath, }) {
|
|
37
|
+
let currentToken = initialCollateralAddress;
|
|
38
|
+
const tokenAddresses = [initialCollateralAddress];
|
|
39
|
+
for (const marketAddress of swapPath) {
|
|
40
|
+
const marketConfig = markets_1.MARKETS[chainId]?.[marketAddress];
|
|
41
|
+
if (!marketConfig) {
|
|
42
|
+
throw new Error(`Market not found for oracle params: ${marketAddress}`);
|
|
43
|
+
}
|
|
44
|
+
const tokenOut = (0, markets_2.getOppositeCollateralFromConfig)(marketConfig, currentToken);
|
|
45
|
+
currentToken = tokenOut;
|
|
46
|
+
tokenAddresses.push(currentToken, marketConfig.indexTokenAddress);
|
|
47
|
+
}
|
|
48
|
+
return tokenAddresses;
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.signRegisterCode = exports.signSetTraderReferralCode = void 0;
|
|
4
|
+
const contracts_1 = require("../../../configs/contracts");
|
|
5
|
+
const relayParamsUtils_1 = require("./relayParamsUtils");
|
|
6
|
+
async function signSetTraderReferralCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
7
|
+
const types = {
|
|
8
|
+
SetTraderReferralCode: [
|
|
9
|
+
{ name: "referralCode", type: "bytes32" },
|
|
10
|
+
{ name: "relayParams", type: "bytes32" },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
const domain = (0, relayParamsUtils_1.getGelatoRelayRouterDomain)(srcChainId ?? chainId, (0, contracts_1.getContract)(chainId, "MultichainOrderRouter"));
|
|
14
|
+
const typedData = {
|
|
15
|
+
referralCode: referralCode,
|
|
16
|
+
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
17
|
+
};
|
|
18
|
+
return signer.signTypedData(domain, types, typedData);
|
|
19
|
+
}
|
|
20
|
+
exports.signSetTraderReferralCode = signSetTraderReferralCode;
|
|
21
|
+
async function signRegisterCode({ signer, relayParams, referralCode, chainId, srcChainId, }) {
|
|
22
|
+
const types = {
|
|
23
|
+
RegisterCode: [
|
|
24
|
+
{ name: "referralCode", type: "bytes32" },
|
|
25
|
+
{ name: "relayParams", type: "bytes32" },
|
|
26
|
+
],
|
|
27
|
+
};
|
|
28
|
+
const domain = (0, relayParamsUtils_1.getGelatoRelayRouterDomain)(srcChainId ?? chainId, (0, contracts_1.getContract)(chainId, "MultichainOrderRouter"));
|
|
29
|
+
const typedData = {
|
|
30
|
+
referralCode: referralCode,
|
|
31
|
+
relayParams: (0, relayParamsUtils_1.hashRelayParams)(relayParams),
|
|
32
|
+
};
|
|
33
|
+
return signer.signTypedData(domain, types, typedData);
|
|
34
|
+
}
|
|
35
|
+
exports.signRegisterCode = signRegisterCode;
|