@hyperlane-xyz/sdk 1.3.0 → 1.3.1
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/dist/HyperlaneApp.d.ts.map +1 -1
- package/dist/HyperlaneApp.js +1 -1
- package/dist/HyperlaneApp.js.map +1 -1
- package/dist/consts/environments/index.d.ts +0 -18
- package/dist/consts/environments/index.d.ts.map +1 -1
- package/dist/consts/environments/mainnet.json +0 -9
- package/dist/consts/environments/testnet.json +1 -10
- package/dist/contracts.d.ts +0 -1
- package/dist/contracts.d.ts.map +1 -1
- package/dist/contracts.js +3 -12
- package/dist/contracts.js.map +1 -1
- package/dist/core/CoreDeployer.hardhat-test.d.ts +2 -0
- package/dist/core/CoreDeployer.hardhat-test.d.ts.map +1 -0
- package/dist/core/CoreDeployer.hardhat-test.js +93 -0
- package/dist/core/CoreDeployer.hardhat-test.js.map +1 -0
- package/dist/core/HyperlaneCore.d.ts +2 -1
- package/dist/core/HyperlaneCore.d.ts.map +1 -1
- package/dist/core/HyperlaneCore.js +14 -10
- package/dist/core/HyperlaneCore.js.map +1 -1
- package/dist/core/HyperlaneCoreDeployer.d.ts +6 -11
- package/dist/core/HyperlaneCoreDeployer.d.ts.map +1 -1
- package/dist/core/HyperlaneCoreDeployer.js +18 -19
- package/dist/core/HyperlaneCoreDeployer.js.map +1 -1
- package/dist/core/TestCoreDeployer.d.ts +14 -6
- package/dist/core/TestCoreDeployer.d.ts.map +1 -1
- package/dist/core/TestCoreDeployer.js +12 -6
- package/dist/core/TestCoreDeployer.js.map +1 -1
- package/dist/deploy/HyperlaneAppChecker.d.ts +4 -0
- package/dist/deploy/HyperlaneAppChecker.d.ts.map +1 -1
- package/dist/deploy/HyperlaneAppChecker.js +23 -18
- package/dist/deploy/HyperlaneAppChecker.js.map +1 -1
- package/dist/deploy/HyperlaneDeployer.d.ts +15 -16
- package/dist/deploy/HyperlaneDeployer.d.ts.map +1 -1
- package/dist/deploy/HyperlaneDeployer.js +60 -103
- package/dist/deploy/HyperlaneDeployer.js.map +1 -1
- package/dist/deploy/utils.d.ts +6 -0
- package/dist/deploy/utils.d.ts.map +1 -0
- package/dist/deploy/utils.js +13 -0
- package/dist/deploy/utils.js.map +1 -0
- package/dist/gas/HyperlaneIgpChecker.d.ts +4 -0
- package/dist/gas/HyperlaneIgpChecker.d.ts.map +1 -1
- package/dist/gas/HyperlaneIgpChecker.js +10 -0
- package/dist/gas/HyperlaneIgpChecker.js.map +1 -1
- package/dist/gas/HyperlaneIgpDeployer.d.ts +7 -13
- package/dist/gas/HyperlaneIgpDeployer.d.ts.map +1 -1
- package/dist/gas/HyperlaneIgpDeployer.js +17 -33
- package/dist/gas/HyperlaneIgpDeployer.js.map +1 -1
- package/dist/gas/calculator.d.ts +186 -0
- package/dist/gas/calculator.d.ts.map +1 -0
- package/dist/gas/calculator.hardhat-test.d.ts +2 -0
- package/dist/gas/calculator.hardhat-test.d.ts.map +1 -0
- package/dist/gas/calculator.hardhat-test.js +59 -0
- package/dist/gas/calculator.hardhat-test.js.map +1 -0
- package/dist/gas/calculator.js +301 -0
- package/dist/gas/calculator.js.map +1 -0
- package/dist/gas/calculator.test.d.ts +2 -0
- package/dist/gas/calculator.test.d.ts.map +1 -0
- package/dist/gas/calculator.test.js +197 -0
- package/dist/gas/calculator.test.js.map +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/middleware/account/InterchainAccountChecker.d.ts +2 -2
- package/dist/middleware/account/InterchainAccountChecker.d.ts.map +1 -1
- package/dist/middleware/account/InterchainAccountChecker.js +2 -2
- package/dist/middleware/account/InterchainAccountChecker.js.map +1 -1
- package/dist/middleware/account/InterchainAccountDeployer.d.ts +6 -6
- package/dist/middleware/account/InterchainAccountDeployer.d.ts.map +1 -1
- package/dist/middleware/account/InterchainAccountDeployer.js +19 -13
- package/dist/middleware/account/InterchainAccountDeployer.js.map +1 -1
- package/dist/middleware/account/accounts.hardhat-test.js +4 -9
- package/dist/middleware/account/accounts.hardhat-test.js.map +1 -1
- package/dist/middleware/accounts.hardhat-test.d.ts +2 -0
- package/dist/middleware/accounts.hardhat-test.d.ts.map +1 -0
- package/dist/middleware/accounts.hardhat-test.js +67 -0
- package/dist/middleware/accounts.hardhat-test.js.map +1 -0
- package/dist/middleware/deploy.d.ts +28 -0
- package/dist/middleware/deploy.d.ts.map +1 -0
- package/dist/middleware/deploy.js +124 -0
- package/dist/middleware/deploy.js.map +1 -0
- package/dist/middleware/liquidity-layer/LiquidityLayerApp.d.ts.map +1 -1
- package/dist/middleware/liquidity-layer/LiquidityLayerApp.js +3 -0
- package/dist/middleware/liquidity-layer/LiquidityLayerApp.js.map +1 -1
- package/dist/middleware/liquidity-layer/LiquidityLayerRouterDeployer.d.ts +12 -5
- package/dist/middleware/liquidity-layer/LiquidityLayerRouterDeployer.d.ts.map +1 -1
- package/dist/middleware/liquidity-layer/LiquidityLayerRouterDeployer.js +28 -19
- package/dist/middleware/liquidity-layer/LiquidityLayerRouterDeployer.js.map +1 -1
- package/dist/middleware/liquidity-layer/liquidity-layer.hardhat-test.js +2 -2
- package/dist/middleware/liquidity-layer/liquidity-layer.hardhat-test.js.map +1 -1
- package/dist/middleware/queries.hardhat-test.d.ts +2 -0
- package/dist/middleware/queries.hardhat-test.d.ts.map +1 -0
- package/dist/middleware/queries.hardhat-test.js +73 -0
- package/dist/middleware/queries.hardhat-test.js.map +1 -0
- package/dist/middleware/query/InterchainQueryChecker.d.ts +2 -2
- package/dist/middleware/query/InterchainQueryChecker.d.ts.map +1 -1
- package/dist/middleware/query/InterchainQueryChecker.js +2 -2
- package/dist/middleware/query/InterchainQueryChecker.js.map +1 -1
- package/dist/middleware/query/InterchainQueryDeployer.d.ts +10 -5
- package/dist/middleware/query/InterchainQueryDeployer.d.ts.map +1 -1
- package/dist/middleware/query/InterchainQueryDeployer.js +31 -4
- package/dist/middleware/query/InterchainQueryDeployer.js.map +1 -1
- package/dist/middleware/query/queries.hardhat-test.js +2 -2
- package/dist/middleware/query/queries.hardhat-test.js.map +1 -1
- package/dist/providers/MultiProvider.d.ts +1 -1
- package/dist/providers/MultiProvider.js +1 -1
- package/dist/proxy.d.ts +24 -0
- package/dist/proxy.d.ts.map +1 -0
- package/dist/proxy.js +39 -0
- package/dist/proxy.js.map +1 -0
- package/dist/router/GasRouterDeployer.d.ts +4 -5
- package/dist/router/GasRouterDeployer.d.ts.map +1 -1
- package/dist/router/GasRouterDeployer.js +5 -9
- package/dist/router/GasRouterDeployer.js.map +1 -1
- package/dist/router/HyperlaneRouterChecker.d.ts.map +1 -1
- package/dist/router/HyperlaneRouterChecker.js +2 -3
- package/dist/router/HyperlaneRouterChecker.js.map +1 -1
- package/dist/router/HyperlaneRouterDeployer.d.ts +5 -7
- package/dist/router/HyperlaneRouterDeployer.d.ts.map +1 -1
- package/dist/router/HyperlaneRouterDeployer.js +10 -14
- package/dist/router/HyperlaneRouterDeployer.js.map +1 -1
- package/dist/router/ProxiedRouterChecker.d.ts +8 -0
- package/dist/router/ProxiedRouterChecker.d.ts.map +1 -0
- package/dist/router/ProxiedRouterChecker.js +26 -0
- package/dist/router/ProxiedRouterChecker.js.map +1 -0
- package/dist/router/ProxiedRouterDeployer.d.ts +13 -0
- package/dist/router/ProxiedRouterDeployer.d.ts.map +1 -0
- package/dist/router/ProxiedRouterDeployer.js +35 -0
- package/dist/router/ProxiedRouterDeployer.js.map +1 -0
- package/dist/router/app.d.ts +14 -0
- package/dist/router/app.d.ts.map +1 -0
- package/dist/router/app.js +31 -0
- package/dist/router/app.js.map +1 -0
- package/dist/router/types.d.ts +1 -2
- package/dist/router/types.d.ts.map +1 -1
- package/dist/test/testUtils.d.ts.map +1 -1
- package/dist/utils/objects.d.ts.map +1 -1
- package/dist/utils/objects.js +4 -1
- package/dist/utils/objects.js.map +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import { types } from '@hyperlane-xyz/utils';
|
|
3
|
+
import { CoreEnvironment, HyperlaneCore } from '../core/HyperlaneCore';
|
|
4
|
+
import { MultiProvider } from '../providers/MultiProvider';
|
|
5
|
+
import { ChainName } from '../types';
|
|
6
|
+
import { TokenPriceGetter } from './token-prices';
|
|
7
|
+
export interface InterchainGasCalculatorConfig {
|
|
8
|
+
/**
|
|
9
|
+
* A multiplier applied to the estimated origin token payment amount.
|
|
10
|
+
* This should be high enough to account for movements in token exchange
|
|
11
|
+
* rates and gas prices.
|
|
12
|
+
* Only used for gas payment estimates that are not quoted on-chain.
|
|
13
|
+
* @defaultValue 1.25
|
|
14
|
+
*/
|
|
15
|
+
paymentEstimateMultiplier?: string;
|
|
16
|
+
/**
|
|
17
|
+
* An amount of additional gas to add to the estimated gas of processing a message.
|
|
18
|
+
* Only used when estimating a payment from a message.
|
|
19
|
+
* Only used for gas payment estimates that are not quoted on-chain.
|
|
20
|
+
* @defaultValue 50,000
|
|
21
|
+
*/
|
|
22
|
+
messageGasEstimateBuffer?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Used to get the native token prices of the origin and destination chains.
|
|
25
|
+
* Only used for gas payment estimates that are not quoted on-chain.
|
|
26
|
+
* @defaultValue An instance of DefaultTokenPriceGetter.
|
|
27
|
+
*/
|
|
28
|
+
tokenPriceGetter?: TokenPriceGetter;
|
|
29
|
+
}
|
|
30
|
+
export interface ParsedMessage {
|
|
31
|
+
origin: ChainName;
|
|
32
|
+
sender: string;
|
|
33
|
+
destination: ChainName;
|
|
34
|
+
recipient: string;
|
|
35
|
+
body: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Calculates interchain gas payments.
|
|
39
|
+
*/
|
|
40
|
+
export declare class InterchainGasCalculator {
|
|
41
|
+
private core;
|
|
42
|
+
private multiProvider;
|
|
43
|
+
private tokenPriceGetter;
|
|
44
|
+
private paymentEstimateMultiplier;
|
|
45
|
+
private messageGasEstimateBuffer;
|
|
46
|
+
static fromEnvironment<Env extends CoreEnvironment>(env: Env, multiProvider: MultiProvider, config?: InterchainGasCalculatorConfig): InterchainGasCalculator;
|
|
47
|
+
constructor(multiProvider: MultiProvider, core: HyperlaneCore, config?: InterchainGasCalculatorConfig);
|
|
48
|
+
/**
|
|
49
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
50
|
+
* Calls the default ISM IGP's `quoteGasPayment` function to get the amount of native tokens
|
|
51
|
+
* required to pay for interchain gas.
|
|
52
|
+
* The default ISM IGP will add any gas overhead amounts related to the Mailbox
|
|
53
|
+
* and default ISM on the destination to the provided gasAmount.
|
|
54
|
+
* @param origin The name of the origin chain.
|
|
55
|
+
* @param destination The name of the destination chain.
|
|
56
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
57
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
58
|
+
* or ISM, so this gas amount is only required to cover the usage of the `handle`
|
|
59
|
+
* function.
|
|
60
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
61
|
+
*/
|
|
62
|
+
quoteGasPaymentForDefaultIsmIgp(origin: ChainName, destination: ChainName, gasAmount: BigNumber): Promise<BigNumber>;
|
|
63
|
+
/**
|
|
64
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
65
|
+
* Calls the "base" IGP's `quoteGasPayment` function to get the amount of native tokens
|
|
66
|
+
* required to pay for interchain gas.
|
|
67
|
+
* This IGP will not apply any overhead gas to the provided gasAmount.
|
|
68
|
+
* @param origin The name of the origin chain.
|
|
69
|
+
* @param destination The name of the destination chain.
|
|
70
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
71
|
+
* This is expected to be the total amount of gas that a transaction would use
|
|
72
|
+
* on the destination chain. This should consider intrinsic transaction gas,
|
|
73
|
+
* Mailbox overhead gas costs, ISM gas costs, and the recipient's handle function
|
|
74
|
+
* gas cost.
|
|
75
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
76
|
+
*/
|
|
77
|
+
quoteGasPayment(origin: ChainName, destination: ChainName, gasAmount: BigNumber): Promise<BigNumber>;
|
|
78
|
+
/**
|
|
79
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
80
|
+
* Calls the origin's default IGP's `quoteGasPayment` function to get the
|
|
81
|
+
* amount of native tokens required to pay for interchain gas.
|
|
82
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
83
|
+
* and ISM to the provided gasAmount.
|
|
84
|
+
* @param origin The name of the origin chain.
|
|
85
|
+
* @param destination The name of the destination chain.
|
|
86
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
87
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
88
|
+
* or ISM, so this gas amount is only required to cover the usage of the `handle`
|
|
89
|
+
* function.
|
|
90
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
91
|
+
*/
|
|
92
|
+
quoteGasPaymentForIGP(origin: ChainName, destination: ChainName, gasAmount: BigNumber, interchainGasPaymasterAddress: types.Address): Promise<BigNumber>;
|
|
93
|
+
/**
|
|
94
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
95
|
+
* Given an amount of gas to consume on the destination chain, calculates the
|
|
96
|
+
* estimated payment denominated in the native token of the origin chain.
|
|
97
|
+
* Considers the exchange rate between the native tokens of the origin and
|
|
98
|
+
* destination chains and the suggested gas price of the destination chain.
|
|
99
|
+
* @param origin The name of the origin chain.
|
|
100
|
+
* @param destination The name of the destination chain.
|
|
101
|
+
* @param gas The amount of gas to pay for on the destination chain.
|
|
102
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs on the
|
|
103
|
+
* destination chain.
|
|
104
|
+
*/
|
|
105
|
+
estimatePaymentForGas(origin: ChainName, destination: ChainName, gas: BigNumber): Promise<BigNumber>;
|
|
106
|
+
/**
|
|
107
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
108
|
+
* Given an amount of gas the message's recipient `handle` function is expected
|
|
109
|
+
* to use, calculates the estimated payment denominated in the native
|
|
110
|
+
* token of the origin chain. Considers the exchange rate between the native
|
|
111
|
+
* tokens of the origin and destination chains, the suggested gas price on
|
|
112
|
+
* the destination chain, gas costs incurred by a relayer when submitting a signed
|
|
113
|
+
* checkpoint to the destination chain, and the overhead gas cost in Inbox of processing
|
|
114
|
+
* a message.
|
|
115
|
+
* @param origin The name of the origin chain.
|
|
116
|
+
* @param destination The name of the destination chain.
|
|
117
|
+
* @param handleGas The amount of gas the recipient `handle` function
|
|
118
|
+
* is estimated to use.
|
|
119
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs of the
|
|
120
|
+
* message on the destination chain.
|
|
121
|
+
*/
|
|
122
|
+
estimatePaymentForHandleGas(origin: ChainName, destination: ChainName, handleGas: BigNumber): Promise<BigNumber>;
|
|
123
|
+
/**
|
|
124
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
125
|
+
* Calculates the estimated payment to process the message on its destination chain,
|
|
126
|
+
* denominated in the native token of the origin chain. The gas used by the message's
|
|
127
|
+
* recipient handler function is estimated in an eth_estimateGas call to the
|
|
128
|
+
* destination chain, and is then used to calculate the payment using
|
|
129
|
+
* Currently made private as it does not work properly for Arbitrum.
|
|
130
|
+
* {@link estimatePaymentForHandleGasAmount}.
|
|
131
|
+
* @param message The parsed message to estimate payment for.
|
|
132
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs of the
|
|
133
|
+
* message on the destination chain.
|
|
134
|
+
*/
|
|
135
|
+
protected estimatePaymentForMessage(message: ParsedMessage): Promise<BigNumber>;
|
|
136
|
+
/**
|
|
137
|
+
* Using the exchange rates provided by tokenPriceGetter, returns the amount of
|
|
138
|
+
* `toChain` native tokens equivalent in value to the provided `fromAmount` of
|
|
139
|
+
* `fromChain` native tokens. Accounts for differences in the decimals of the tokens.
|
|
140
|
+
* @param fromChain The chain whose native token is being converted from.
|
|
141
|
+
* @param toChain The chain whose native token is being converted into.
|
|
142
|
+
* @param fromAmount The amount of `fromChain` native tokens to convert from.
|
|
143
|
+
* @returns The amount of `toChain` native tokens whose value is equivalent to
|
|
144
|
+
* `fromAmount` of `fromChain` native tokens.
|
|
145
|
+
*/
|
|
146
|
+
protected convertBetweenTokens(fromChain: ChainName, toChain: ChainName, value: BigNumber): Promise<BigNumber>;
|
|
147
|
+
/**
|
|
148
|
+
* Gets a suggested gas price for a chain.
|
|
149
|
+
* @param chainName The name of the chain to get the gas price for
|
|
150
|
+
* @returns The suggested gas price in wei on the destination chain.
|
|
151
|
+
*/
|
|
152
|
+
protected getGasPrice(chain: ChainName): Promise<BigNumber>;
|
|
153
|
+
/**
|
|
154
|
+
* Gets the number of decimals of the provided chain's native token.
|
|
155
|
+
* @param chain The chain.
|
|
156
|
+
* @returns The number of decimals of `chain`'s native token.
|
|
157
|
+
*/
|
|
158
|
+
protected tokenDecimals(chain: ChainName): number;
|
|
159
|
+
/**
|
|
160
|
+
* Estimates the amount of gas used by message's recipient `handle` function
|
|
161
|
+
* on its destination chain. This does not assume the Inbox of the destination
|
|
162
|
+
* chain has a checkpoint that the message is included in, and does not
|
|
163
|
+
* consider intrinsic gas or any "overhead" gas incurred by Inbox.process.
|
|
164
|
+
* The estimated gas returned is the sum of:
|
|
165
|
+
* 1. The estimated gas consumption of a direct call to the `handle`
|
|
166
|
+
* function of the recipient address using the correct parameters and
|
|
167
|
+
* setting the `from` address of the transaction to the address of the inbox.
|
|
168
|
+
* 2. A buffer to account for inaccuracies in the above estimation.
|
|
169
|
+
* @param message The message to estimate recipient `handle` gas usage for.
|
|
170
|
+
* @returns The estimated gas required by the message's recipient handle function
|
|
171
|
+
* on the destination chain.
|
|
172
|
+
*/
|
|
173
|
+
protected estimateGasForHandle(message: ParsedMessage): Promise<BigNumber>;
|
|
174
|
+
/**
|
|
175
|
+
* @returns A generous estimation of the gas consumption of all process
|
|
176
|
+
* operations within Inbox.sol, including intrinsic gas. Does not include any gas
|
|
177
|
+
* consumed within a message's recipient `handle` function.
|
|
178
|
+
*/
|
|
179
|
+
protected estimateGasForProcess(origin: ChainName, destination: ChainName): Promise<BigNumber>;
|
|
180
|
+
/**
|
|
181
|
+
* @returns The intrinsic gas of a basic transaction. Note this does not consider calldata
|
|
182
|
+
* costs or potentially different intrinsic gas costs for different chains.
|
|
183
|
+
*/
|
|
184
|
+
protected intrinsicGas(): BigNumber;
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=calculator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../src/gas/calculator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAuB,MAAM,QAAQ,CAAC;AAGxD,OAAO,EAAE,KAAK,EAAS,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,OAAO,EAA6B,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AA+B7E,MAAM,WAAW,6BAA6B;IAC5C;;;;;;OAMG;IACH,yBAAyB,CAAC,EAAE,MAAM,CAAC;IACnC;;;;;OAKG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,SAAS,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,IAAI,CAAgB;IAC5B,OAAO,CAAC,aAAa,CAAgB;IAErC,OAAO,CAAC,gBAAgB,CAAmB;IAE3C,OAAO,CAAC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,GACf,OAAO,CAAC,SAAS,CAAC;IAiBrB;;;;OAIG;cACa,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IAQjE;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,KAAK,EAAE,SAAS,GAAG,MAAM;IAOjD;;;;;;;;;;;;;OAaG;cACa,oBAAoB,CAClC,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,SAAS,CAAC;IA+BrB;;;;OAIG;cACa,qBAAqB,CACnC,MAAM,EAAE,SAAS,EACjB,WAAW,EAAE,SAAS,GACrB,OAAO,CAAC,SAAS,CAAC;IAWrB;;;OAGG;IACH,SAAS,CAAC,YAAY,IAAI,SAAS;CAGpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.hardhat-test.d.ts","sourceRoot":"","sources":["../../src/gas/calculator.hardhat-test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const chai_1 = require("chai");
|
|
13
|
+
const ethers_1 = require("ethers");
|
|
14
|
+
const hardhat_1 = require("hardhat");
|
|
15
|
+
const chains_1 = require("../consts/chains");
|
|
16
|
+
const HyperlaneCore_1 = require("../core/HyperlaneCore");
|
|
17
|
+
const TestCoreDeployer_1 = require("../core/TestCoreDeployer");
|
|
18
|
+
const MultiProvider_1 = require("../providers/MultiProvider");
|
|
19
|
+
const calculator_1 = require("./calculator");
|
|
20
|
+
describe('InterchainGasCalculator', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
const localChain = chains_1.Chains.test1;
|
|
22
|
+
const remoteChain = chains_1.Chains.test2;
|
|
23
|
+
const testGasAmount = ethers_1.BigNumber.from('100000');
|
|
24
|
+
let signer;
|
|
25
|
+
let multiProvider;
|
|
26
|
+
let calculator;
|
|
27
|
+
let igp;
|
|
28
|
+
before(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
[signer] = yield hardhat_1.ethers.getSigners();
|
|
30
|
+
multiProvider = MultiProvider_1.MultiProvider.createTestMultiProvider({ signer });
|
|
31
|
+
const coreDeployer = new TestCoreDeployer_1.TestCoreDeployer(multiProvider);
|
|
32
|
+
const coreContractsMaps = yield coreDeployer.deploy();
|
|
33
|
+
const core = new HyperlaneCore_1.HyperlaneCore(coreContractsMaps, multiProvider);
|
|
34
|
+
calculator = new calculator_1.InterchainGasCalculator(multiProvider, core);
|
|
35
|
+
igp = coreContractsMaps[localChain].interchainGasPaymaster.address;
|
|
36
|
+
}));
|
|
37
|
+
describe('quoteGasPaymentForDefaultIsmIgp', () => {
|
|
38
|
+
it("calls the default ISM IGP's quoteGasPayment function", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
+
const quote = yield calculator.quoteGasPaymentForDefaultIsmIgp(localChain, remoteChain, testGasAmount);
|
|
40
|
+
// (100,000 gas amount + 151,966 overhead) * 10 gas price
|
|
41
|
+
(0, chai_1.expect)(quote).to.equal(ethers_1.BigNumber.from('2519660'));
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
describe('quoteGasPayment', () => {
|
|
45
|
+
it("calls the IGP's quoteGasPayment function", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
+
const quote = yield calculator.quoteGasPayment(localChain, remoteChain, testGasAmount);
|
|
47
|
+
// 100,000 gas amount * 10 gas price
|
|
48
|
+
(0, chai_1.expect)(quote).to.equal(ethers_1.BigNumber.from('1000000'));
|
|
49
|
+
}));
|
|
50
|
+
});
|
|
51
|
+
describe('quoteGasPaymentForIGP', () => {
|
|
52
|
+
it("calls the provided IGP's quoteGasPayment", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
|
+
const quote = yield calculator.quoteGasPaymentForIGP(localChain, remoteChain, testGasAmount, igp);
|
|
54
|
+
// 100,000 gas amount * 10 gas price
|
|
55
|
+
(0, chai_1.expect)(quote).to.equal(ethers_1.BigNumber.from('1000000'));
|
|
56
|
+
}));
|
|
57
|
+
});
|
|
58
|
+
}));
|
|
59
|
+
//# sourceMappingURL=calculator.hardhat-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.hardhat-test.js","sourceRoot":"","sources":["../../src/gas/calculator.hardhat-test.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,+BAA8B;AAC9B,mCAAmC;AACnC,qCAAiC;AAIjC,6CAA0C;AAC1C,yDAAsD;AACtD,+DAA4D;AAC5D,8DAA2D;AAE3D,6CAAuD;AAEvD,QAAQ,CAAC,yBAAyB,EAAE,GAAS,EAAE;IAC7C,MAAM,UAAU,GAAG,eAAM,CAAC,KAAK,CAAC;IAChC,MAAM,WAAW,GAAG,eAAM,CAAC,KAAK,CAAC;IAEjC,MAAM,aAAa,GAAG,kBAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAE/C,IAAI,MAAyB,CAAC;IAC9B,IAAI,aAA4B,CAAC;IAEjC,IAAI,UAAmC,CAAC;IACxC,IAAI,GAAkB,CAAC;IAEvB,MAAM,CAAC,GAAS,EAAE;QAChB,CAAC,MAAM,CAAC,GAAG,MAAM,gBAAM,CAAC,UAAU,EAAE,CAAC;QAErC,aAAa,GAAG,6BAAa,CAAC,uBAAuB,CAAC,EAAE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YACxD,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,qBAAqB,CAClD,UAAU,EACV,WAAW,EACX,aAAa,EACb,GAAG,CACJ,CAAC;YAEF,oCAAoC;YACpC,IAAA,aAAM,EAAC,KAAK,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,kBAAS,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACpD,CAAC,CAAA,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAA,CAAC,CAAC"}
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.InterchainGasCalculator = void 0;
|
|
16
|
+
const coingecko_api_1 = __importDefault(require("coingecko-api"));
|
|
17
|
+
const ethers_1 = require("ethers");
|
|
18
|
+
const core_1 = require("@hyperlane-xyz/core");
|
|
19
|
+
const utils_1 = require("@hyperlane-xyz/utils");
|
|
20
|
+
const HyperlaneCore_1 = require("../core/HyperlaneCore");
|
|
21
|
+
const number_1 = require("../utils/number");
|
|
22
|
+
const token_prices_1 = require("./token-prices");
|
|
23
|
+
/**
|
|
24
|
+
* A note on arithmetic:
|
|
25
|
+
* The ethers.BigNumber implementation behaves very similar to Solidity's
|
|
26
|
+
* number handling by not supporting decimals. To avoid adding another big
|
|
27
|
+
* number implementation as a dependency, we use ethers.FixedNumber, a
|
|
28
|
+
* fixed point implementation intended to model how Solidity's half-supported
|
|
29
|
+
* fixed point numbers work, see https://docs.soliditylang.org/en/v0.8.13/types.html#fixed-point-numbers).
|
|
30
|
+
*
|
|
31
|
+
* Generally, ceiling is used rather than floor here to err on the side of over-
|
|
32
|
+
* estimating amounts.
|
|
33
|
+
*/
|
|
34
|
+
// If a chain doesn't specify how many decimals their native token has, 18 is used.
|
|
35
|
+
const DEFAULT_TOKEN_DECIMALS = 18;
|
|
36
|
+
// Intrinsic gas for a transaction. Does not consider calldata costs or differences in
|
|
37
|
+
// intrinsic gas for different chains.
|
|
38
|
+
const GAS_INTRINSIC = 21000;
|
|
39
|
+
// The gas used to process a message when the quorum size is zero.
|
|
40
|
+
// Includes intrinsic gas, mailbox overhead gas, all other gas that does not scale with the
|
|
41
|
+
// quorum size. Excludes the cost of the recipient's handle function.
|
|
42
|
+
const GAS_OVERHEAD_BASE = 155000;
|
|
43
|
+
// The amount of gas used for each signature when a signed checkpoint
|
|
44
|
+
// is submitted for verification.
|
|
45
|
+
// Really observed to be about 6500, but rounding up for safety.
|
|
46
|
+
const GAS_OVERHEAD_PER_SIGNATURE = 7500;
|
|
47
|
+
/**
|
|
48
|
+
* Calculates interchain gas payments.
|
|
49
|
+
*/
|
|
50
|
+
class InterchainGasCalculator {
|
|
51
|
+
constructor(multiProvider, core, config) {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
this.multiProvider = multiProvider;
|
|
54
|
+
this.core = core;
|
|
55
|
+
if (config === null || config === void 0 ? void 0 : config.tokenPriceGetter) {
|
|
56
|
+
this.tokenPriceGetter = config.tokenPriceGetter;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const coinGecko = new coingecko_api_1.default();
|
|
60
|
+
this.tokenPriceGetter = new token_prices_1.CoinGeckoTokenPriceGetter(coinGecko);
|
|
61
|
+
}
|
|
62
|
+
this.paymentEstimateMultiplier = ethers_1.FixedNumber.from((_a = config === null || config === void 0 ? void 0 : config.paymentEstimateMultiplier) !== null && _a !== void 0 ? _a : '1.25');
|
|
63
|
+
this.messageGasEstimateBuffer = ethers_1.BigNumber.from((_b = config === null || config === void 0 ? void 0 : config.messageGasEstimateBuffer) !== null && _b !== void 0 ? _b : 50000);
|
|
64
|
+
}
|
|
65
|
+
static fromEnvironment(env, multiProvider, config) {
|
|
66
|
+
const core = HyperlaneCore_1.HyperlaneCore.fromEnvironment(env, multiProvider);
|
|
67
|
+
return new InterchainGasCalculator(multiProvider, core, config);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
71
|
+
* Calls the default ISM IGP's `quoteGasPayment` function to get the amount of native tokens
|
|
72
|
+
* required to pay for interchain gas.
|
|
73
|
+
* The default ISM IGP will add any gas overhead amounts related to the Mailbox
|
|
74
|
+
* and default ISM on the destination to the provided gasAmount.
|
|
75
|
+
* @param origin The name of the origin chain.
|
|
76
|
+
* @param destination The name of the destination chain.
|
|
77
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
78
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
79
|
+
* or ISM, so this gas amount is only required to cover the usage of the `handle`
|
|
80
|
+
* function.
|
|
81
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
82
|
+
*/
|
|
83
|
+
quoteGasPaymentForDefaultIsmIgp(origin, destination, gasAmount) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const igpAddress = this.core.getContracts(origin).defaultIsmInterchainGasPaymaster;
|
|
86
|
+
return this.quoteGasPaymentForIGP(origin, destination, gasAmount, igpAddress.address);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
91
|
+
* Calls the "base" IGP's `quoteGasPayment` function to get the amount of native tokens
|
|
92
|
+
* required to pay for interchain gas.
|
|
93
|
+
* This IGP will not apply any overhead gas to the provided gasAmount.
|
|
94
|
+
* @param origin The name of the origin chain.
|
|
95
|
+
* @param destination The name of the destination chain.
|
|
96
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
97
|
+
* This is expected to be the total amount of gas that a transaction would use
|
|
98
|
+
* on the destination chain. This should consider intrinsic transaction gas,
|
|
99
|
+
* Mailbox overhead gas costs, ISM gas costs, and the recipient's handle function
|
|
100
|
+
* gas cost.
|
|
101
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
102
|
+
*/
|
|
103
|
+
quoteGasPayment(origin, destination, gasAmount) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const igpAddress = this.core.getContracts(origin).interchainGasPaymaster;
|
|
106
|
+
return this.quoteGasPaymentForIGP(origin, destination, gasAmount, igpAddress.address);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Only intended for IGPs that quote gas payments on-chain.
|
|
111
|
+
* Calls the origin's default IGP's `quoteGasPayment` function to get the
|
|
112
|
+
* amount of native tokens required to pay for interchain gas.
|
|
113
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
114
|
+
* and ISM to the provided gasAmount.
|
|
115
|
+
* @param origin The name of the origin chain.
|
|
116
|
+
* @param destination The name of the destination chain.
|
|
117
|
+
* @param gasAmount The amount of gas to use when calling `quoteGasPayment`.
|
|
118
|
+
* The default IGP is expected to add any gas overhead related to the Mailbox
|
|
119
|
+
* or ISM, so this gas amount is only required to cover the usage of the `handle`
|
|
120
|
+
* function.
|
|
121
|
+
* @returns The amount of native tokens required to pay for interchain gas.
|
|
122
|
+
*/
|
|
123
|
+
quoteGasPaymentForIGP(origin, destination, gasAmount, interchainGasPaymasterAddress) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const originProvider = this.multiProvider.getProvider(origin);
|
|
126
|
+
const igp = core_1.InterchainGasPaymaster__factory.connect(interchainGasPaymasterAddress, originProvider);
|
|
127
|
+
const domainId = this.multiProvider.getDomainId(destination);
|
|
128
|
+
return igp.quoteGasPayment(domainId, gasAmount);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
133
|
+
* Given an amount of gas to consume on the destination chain, calculates the
|
|
134
|
+
* estimated payment denominated in the native token of the origin chain.
|
|
135
|
+
* Considers the exchange rate between the native tokens of the origin and
|
|
136
|
+
* destination chains and the suggested gas price of the destination chain.
|
|
137
|
+
* @param origin The name of the origin chain.
|
|
138
|
+
* @param destination The name of the destination chain.
|
|
139
|
+
* @param gas The amount of gas to pay for on the destination chain.
|
|
140
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs on the
|
|
141
|
+
* destination chain.
|
|
142
|
+
*/
|
|
143
|
+
estimatePaymentForGas(origin, destination, gas) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const destinationGasPrice = yield this.getGasPrice(destination);
|
|
146
|
+
const destinationGasCost = gas.mul(destinationGasPrice);
|
|
147
|
+
const originGasCost = yield this.convertBetweenTokens(destination, origin, destinationGasCost);
|
|
148
|
+
// Applies a multiplier
|
|
149
|
+
return (0, number_1.mulBigAndFixed)(originGasCost, this.paymentEstimateMultiplier, true);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
154
|
+
* Given an amount of gas the message's recipient `handle` function is expected
|
|
155
|
+
* to use, calculates the estimated payment denominated in the native
|
|
156
|
+
* token of the origin chain. Considers the exchange rate between the native
|
|
157
|
+
* tokens of the origin and destination chains, the suggested gas price on
|
|
158
|
+
* the destination chain, gas costs incurred by a relayer when submitting a signed
|
|
159
|
+
* checkpoint to the destination chain, and the overhead gas cost in Inbox of processing
|
|
160
|
+
* a message.
|
|
161
|
+
* @param origin The name of the origin chain.
|
|
162
|
+
* @param destination The name of the destination chain.
|
|
163
|
+
* @param handleGas The amount of gas the recipient `handle` function
|
|
164
|
+
* is estimated to use.
|
|
165
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs of the
|
|
166
|
+
* message on the destination chain.
|
|
167
|
+
*/
|
|
168
|
+
estimatePaymentForHandleGas(origin, destination, handleGas) {
|
|
169
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
170
|
+
const destinationGas = handleGas.add(yield this.estimateGasForProcess(origin, destination));
|
|
171
|
+
return this.estimatePaymentForGas(origin, destination, destinationGas);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Only intended for IGPs that do *not* quote gas payments on-chain.
|
|
176
|
+
* Calculates the estimated payment to process the message on its destination chain,
|
|
177
|
+
* denominated in the native token of the origin chain. The gas used by the message's
|
|
178
|
+
* recipient handler function is estimated in an eth_estimateGas call to the
|
|
179
|
+
* destination chain, and is then used to calculate the payment using
|
|
180
|
+
* Currently made private as it does not work properly for Arbitrum.
|
|
181
|
+
* {@link estimatePaymentForHandleGasAmount}.
|
|
182
|
+
* @param message The parsed message to estimate payment for.
|
|
183
|
+
* @returns An estimated amount of origin chain tokens to cover gas costs of the
|
|
184
|
+
* message on the destination chain.
|
|
185
|
+
*/
|
|
186
|
+
estimatePaymentForMessage(message) {
|
|
187
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
188
|
+
const handleGas = yield this.estimateGasForHandle(message);
|
|
189
|
+
return this.estimatePaymentForHandleGas(message.origin, message.destination, handleGas);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Using the exchange rates provided by tokenPriceGetter, returns the amount of
|
|
194
|
+
* `toChain` native tokens equivalent in value to the provided `fromAmount` of
|
|
195
|
+
* `fromChain` native tokens. Accounts for differences in the decimals of the tokens.
|
|
196
|
+
* @param fromChain The chain whose native token is being converted from.
|
|
197
|
+
* @param toChain The chain whose native token is being converted into.
|
|
198
|
+
* @param fromAmount The amount of `fromChain` native tokens to convert from.
|
|
199
|
+
* @returns The amount of `toChain` native tokens whose value is equivalent to
|
|
200
|
+
* `fromAmount` of `fromChain` native tokens.
|
|
201
|
+
*/
|
|
202
|
+
convertBetweenTokens(fromChain, toChain, value) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
// Does not factor in differing token decimals.
|
|
205
|
+
const exchangeRate = yield this.tokenPriceGetter.getTokenExchangeRate(fromChain, toChain);
|
|
206
|
+
// 1/100th of a cent
|
|
207
|
+
const PRECISION = 1000;
|
|
208
|
+
return (0, number_1.convertDecimalValue)(value.mul(Math.round(exchangeRate * PRECISION)).div(PRECISION), this.tokenDecimals(fromChain), this.tokenDecimals(toChain));
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Gets a suggested gas price for a chain.
|
|
213
|
+
* @param chainName The name of the chain to get the gas price for
|
|
214
|
+
* @returns The suggested gas price in wei on the destination chain.
|
|
215
|
+
*/
|
|
216
|
+
getGasPrice(chain) {
|
|
217
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
218
|
+
const provider = this.multiProvider.getProvider(chain);
|
|
219
|
+
if (provider == undefined) {
|
|
220
|
+
throw new Error(`Missing provider for ${chain}`);
|
|
221
|
+
}
|
|
222
|
+
return provider.getGasPrice();
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Gets the number of decimals of the provided chain's native token.
|
|
227
|
+
* @param chain The chain.
|
|
228
|
+
* @returns The number of decimals of `chain`'s native token.
|
|
229
|
+
*/
|
|
230
|
+
tokenDecimals(chain) {
|
|
231
|
+
var _a, _b, _c;
|
|
232
|
+
return ((_c = (_b = (_a = this.multiProvider.tryGetChainMetadata(chain)) === null || _a === void 0 ? void 0 : _a.nativeToken) === null || _b === void 0 ? void 0 : _b.decimals) !== null && _c !== void 0 ? _c : DEFAULT_TOKEN_DECIMALS);
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Estimates the amount of gas used by message's recipient `handle` function
|
|
236
|
+
* on its destination chain. This does not assume the Inbox of the destination
|
|
237
|
+
* chain has a checkpoint that the message is included in, and does not
|
|
238
|
+
* consider intrinsic gas or any "overhead" gas incurred by Inbox.process.
|
|
239
|
+
* The estimated gas returned is the sum of:
|
|
240
|
+
* 1. The estimated gas consumption of a direct call to the `handle`
|
|
241
|
+
* function of the recipient address using the correct parameters and
|
|
242
|
+
* setting the `from` address of the transaction to the address of the inbox.
|
|
243
|
+
* 2. A buffer to account for inaccuracies in the above estimation.
|
|
244
|
+
* @param message The message to estimate recipient `handle` gas usage for.
|
|
245
|
+
* @returns The estimated gas required by the message's recipient handle function
|
|
246
|
+
* on the destination chain.
|
|
247
|
+
*/
|
|
248
|
+
estimateGasForHandle(message) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
250
|
+
const provider = this.multiProvider.getProvider(message.destination);
|
|
251
|
+
const mailbox = this.core.getContracts(message.destination).mailbox
|
|
252
|
+
.contract;
|
|
253
|
+
const handlerInterface = new ethers_1.ethers.utils.Interface([
|
|
254
|
+
'function handle(uint32,bytes32,bytes)',
|
|
255
|
+
]);
|
|
256
|
+
// Estimates a direct call to the `handle` function of the recipient
|
|
257
|
+
// with the `from` address set to the inbox.
|
|
258
|
+
// This includes intrinsic gas.
|
|
259
|
+
const directHandleCallGas = yield provider.estimateGas({
|
|
260
|
+
to: utils_1.utils.bytes32ToAddress(message.recipient),
|
|
261
|
+
from: mailbox.address,
|
|
262
|
+
data: handlerInterface.encodeFunctionData('handle', [
|
|
263
|
+
this.multiProvider.getChainId(message.origin),
|
|
264
|
+
utils_1.utils.addressToBytes32(message.sender),
|
|
265
|
+
message.body,
|
|
266
|
+
]),
|
|
267
|
+
});
|
|
268
|
+
// Subtract intrinsic gas, which is included in directHandleCallGas.
|
|
269
|
+
// Note the "real" intrinsic gas will always be higher than this.intrinsicGas
|
|
270
|
+
// due to calldata costs, but this is desired because subtracting the lower bound
|
|
271
|
+
// this.intrinsicGas will result in a more generous final estimate.
|
|
272
|
+
return directHandleCallGas
|
|
273
|
+
.add(this.messageGasEstimateBuffer)
|
|
274
|
+
.sub(this.intrinsicGas());
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* @returns A generous estimation of the gas consumption of all process
|
|
279
|
+
* operations within Inbox.sol, including intrinsic gas. Does not include any gas
|
|
280
|
+
* consumed within a message's recipient `handle` function.
|
|
281
|
+
*/
|
|
282
|
+
estimateGasForProcess(origin, destination) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
// TODO: Check the recipient module
|
|
285
|
+
const module = this.core.getContracts(destination).multisigIsm;
|
|
286
|
+
const threshold = yield module.threshold(this.multiProvider.getDomainId(origin));
|
|
287
|
+
return ethers_1.BigNumber.from(threshold)
|
|
288
|
+
.mul(GAS_OVERHEAD_PER_SIGNATURE)
|
|
289
|
+
.add(GAS_OVERHEAD_BASE);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* @returns The intrinsic gas of a basic transaction. Note this does not consider calldata
|
|
294
|
+
* costs or potentially different intrinsic gas costs for different chains.
|
|
295
|
+
*/
|
|
296
|
+
intrinsicGas() {
|
|
297
|
+
return ethers_1.BigNumber.from(GAS_INTRINSIC);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
exports.InterchainGasCalculator = InterchainGasCalculator;
|
|
301
|
+
//# sourceMappingURL=calculator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../src/gas/calculator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kEAAsC;AACtC,mCAAwD;AAExD,8CAAsE;AACtE,gDA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