feat: add a script for getting typical remote gas amounts (#4782)

### Description

- Sometimes Jake requests an update on these for his own models, this
makes it easier for us to get it for him

### Drive-by changes

<!--
Are there any minor or drive-by changes also included?
-->

### Related issues

<!--
- Fixes #[issue number here]
-->

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

<!--
What kind of testing have these changes undergone?

None/Manual/Unit Tests
-->
pull/4789/head
Trevor Porter 3 weeks ago committed by GitHub
parent 8dbc2e636e
commit 1b5bfa3466
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      typescript/infra/config/environments/mainnet3/igp.ts
  2. 49
      typescript/infra/scripts/get-typical-remote-gas-amounts.ts
  3. 18
      typescript/infra/src/config/gas-oracle.ts

@ -23,13 +23,13 @@ import rawTokenPrices from './tokenPrices.json';
const tokenPrices: ChainMap<string> = rawTokenPrices;
const getOverheadWithOverrides = (local: ChainName, remote: ChainName) => {
export function getOverheadWithOverrides(local: ChainName, remote: ChainName) {
let overhead = getOverhead(local, remote, ethereumChainNames);
if (remote === 'moonbeam') {
overhead *= 4;
}
return overhead;
};
}
const storageGasOracleConfig: AllStorageGasOracleConfigs =
getAllStorageGasOracleConfigs(

@ -0,0 +1,49 @@
import { ChainMap } from '@hyperlane-xyz/sdk';
import { stringifyObject } from '@hyperlane-xyz/utils';
import { getOverheadWithOverrides } from '../config/environments/mainnet3/igp.js';
import { getTypicalRemoteGasAmount } from '../src/config/gas-oracle.js';
import { getArgs } from './agent-utils.js';
import { getEnvironmentConfig } from './core-utils.js';
// This script exists to print the typical local -> remote gas amounts for a given environment.
// This is useful for Jake to use in his own models for assessing message costs.
async function main() {
const args = await getArgs().argv;
if (args.environment !== 'mainnet3') {
throw new Error('This script only supports the mainnet3 environment');
}
const environmentConfig = getEnvironmentConfig(args.environment);
// Local -> Remote -> Amount of gas.
// Local is important because depending on the validator threshold, the cost
// to verify changes. Remote is important because the cost to execute the
// message can change depending on the chain (e.g. alt VMs, or some exceptions like Moonbeam
// that has non-standard EVM gas usage).
const amounts: ChainMap<ChainMap<number>> = {};
for (const local of environmentConfig.supportedChainNames) {
for (const remote of environmentConfig.supportedChainNames) {
if (local === remote) {
continue;
}
amounts[local] = amounts[local] || {};
amounts[local][remote] = getTypicalRemoteGasAmount(
local,
remote,
getOverheadWithOverrides,
);
}
}
console.log(stringifyObject(amounts, 'json', 2));
}
main().catch((err) => {
console.error(err);
process.exit(1);
});

@ -22,6 +22,10 @@ export type AllStorageGasOracleConfigs = ChainMap<
// Overcharge by 50% to account for market making risk
export const EXCHANGE_RATE_MARGIN_PCT = 50;
// Arbitrarily chosen as a typical amount of gas used in a message's handle function.
// Used for determining typical gas costs for a message.
export const TYPICAL_HANDLE_GAS_USAGE = 50_000;
// Gets the StorageGasOracleConfig for each remote chain for a particular local chain.
// Accommodates small non-integer gas prices by scaling up the gas price
// and scaling down the exchange rate by the same factor.
@ -81,7 +85,11 @@ function getLocalStorageGasOracleConfigOverride(
// If we have access to these, let's use the USD prices to apply some minimum
// typical USD payment heuristics.
if (getTokenUsdPrice && getOverhead) {
const typicalRemoteGasAmount = getOverhead(local, remote) + 50_000;
const typicalRemoteGasAmount = getTypicalRemoteGasAmount(
local,
remote,
getOverhead,
);
const typicalIgpQuoteUsd = getUsdQuote(
local,
gasPriceBn,
@ -112,6 +120,14 @@ function getLocalStorageGasOracleConfigOverride(
}, {});
}
export function getTypicalRemoteGasAmount(
local: ChainName,
remote: ChainName,
getOverhead: (local: ChainName, remote: ChainName) => number,
): number {
return getOverhead(local, remote) + TYPICAL_HANDLE_GAS_USAGE;
}
function getMinUsdCost(local: ChainName, remote: ChainName): number {
// By default, min cost is 20 cents
let minUsdCost = 0.2;

Loading…
Cancel
Save