fix: gas oracle overhead calculation (#4571)

fix: gas oracle overhead calculation

as spotted by @tkporter
https://canary.discord.com/channels/935678348330434570/1288601439006097498/1288602404950114334

---------

Signed-off-by: pbio <10051819+paulbalaji@users.noreply.github.com>
dan/local-svm-setup
Paul Balaji 2 months ago committed by GitHub
parent 3857cfb65a
commit 9f5a17b7a4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 12
      typescript/infra/config/environments/mainnet3/igp.ts
  2. 4
      typescript/infra/config/environments/test/igp.ts
  3. 6
      typescript/infra/config/environments/testnet4/igp.ts
  4. 17
      typescript/infra/src/config/gas-oracle.ts

@ -4,8 +4,8 @@ import { exclude, objMap } from '@hyperlane-xyz/utils';
import {
AllStorageGasOracleConfigs,
getAllStorageGasOracleConfigs,
getOverhead,
getTokenExchangeRateFromValues,
remoteOverhead,
} from '../../../src/config/gas-oracle.js';
import { ethereumChainNames } from './chains.js';
@ -16,9 +16,9 @@ import rawTokenPrices from './tokenPrices.json';
const tokenPrices: ChainMap<string> = rawTokenPrices;
const remoteOverheadWithOverrides = (chain: ChainName) => {
let overhead = remoteOverhead(chain, ethereumChainNames);
if (chain === 'moonbeam') {
const getOverheadWithOverrides = (local: ChainName, remote: ChainName) => {
let overhead = getOverhead(local, remote, ethereumChainNames);
if (remote === 'moonbeam') {
overhead *= 4;
}
return overhead;
@ -31,7 +31,7 @@ const storageGasOracleConfig: AllStorageGasOracleConfigs =
(local, remote) =>
getTokenExchangeRateFromValues(local, remote, tokenPrices),
(local) => parseFloat(tokenPrices[local]),
remoteOverheadWithOverrides,
getOverheadWithOverrides,
);
export const igp: ChainMap<IgpConfig> = objMap(
@ -49,7 +49,7 @@ export const igp: ChainMap<IgpConfig> = objMap(
overhead: Object.fromEntries(
exclude(local, supportedChainNames).map((remote) => [
remote,
remoteOverhead(remote, ethereumChainNames),
getOverheadWithOverrides(local, remote),
]),
),
oracleConfig: storageGasOracleConfig[local],

@ -17,8 +17,8 @@ export const igp: ChainMap<IgpConfig> = objMap(
exclude(chain, testChainNames).map((remote) => [
remote,
multisigIsmVerificationCost(
multisigIsm[remote].threshold,
multisigIsm[remote].validators.length,
multisigIsm[chain].threshold,
multisigIsm[chain].validators.length,
),
]),
);

@ -4,8 +4,8 @@ import { Address, exclude, objMap } from '@hyperlane-xyz/utils';
import {
AllStorageGasOracleConfigs,
getAllStorageGasOracleConfigs,
getOverhead,
getTokenExchangeRateFromValues,
remoteOverhead,
} from '../../../src/config/gas-oracle.js';
import { ethereumChainNames } from './chains.js';
@ -23,7 +23,7 @@ export const storageGasOracleConfig: AllStorageGasOracleConfigs =
(local, remote) =>
getTokenExchangeRateFromValues(local, remote, tokenPrices),
(local) => parseFloat(tokenPrices[local]),
(local) => remoteOverhead(local, ethereumChainNames),
(local, remote) => getOverhead(local, remote, ethereumChainNames),
);
export const igp: ChainMap<IgpConfig> = objMap(
@ -38,7 +38,7 @@ export const igp: ChainMap<IgpConfig> = objMap(
overhead: Object.fromEntries(
exclude(chain, supportedChainNames).map((remote) => [
remote,
remoteOverhead(remote, ethereumChainNames),
getOverhead(chain, remote, ethereumChainNames),
]),
),
};

@ -49,7 +49,7 @@ function getLocalStorageGasOracleConfig(
gasPrices: ChainMap<GasPriceConfig>,
getTokenExchangeRate: (local: ChainName, remote: ChainName) => BigNumber,
getTokenUsdPrice?: (chain: ChainName) => number,
remoteOverhead?: (remote: ChainName) => number,
getOverhead?: (local: ChainName, remote: ChainName) => number,
): StorageGasOracleConfig {
return remotes.reduce((agg, remote) => {
let exchangeRate = getTokenExchangeRate(local, remote);
@ -96,8 +96,8 @@ function getLocalStorageGasOracleConfig(
// If we have access to these, let's use the USD prices to apply some minimum
// typical USD payment heuristics.
if (getTokenUsdPrice && remoteOverhead) {
const typicalRemoteGasAmount = remoteOverhead(remote) + 50_000;
if (getTokenUsdPrice && getOverhead) {
const typicalRemoteGasAmount = getOverhead(local, remote) + 50_000;
const typicalIgpQuoteUsd = getUsdQuote(
local,
gasPriceBn,
@ -187,14 +187,15 @@ function getUsdQuote(
const FOREIGN_DEFAULT_OVERHEAD = 600_000;
// Overhead for interchain messaging
export function remoteOverhead(
export function getOverhead(
local: ChainName,
remote: ChainName,
ethereumChainNames: ChainName[],
): number {
return ethereumChainNames.includes(remote as any)
? multisigIsmVerificationCost(
defaultMultisigConfigs[remote].threshold,
defaultMultisigConfigs[remote].validators.length,
defaultMultisigConfigs[local].threshold,
defaultMultisigConfigs[local].validators.length,
)
: FOREIGN_DEFAULT_OVERHEAD; // non-ethereum overhead
}
@ -205,7 +206,7 @@ export function getAllStorageGasOracleConfigs(
gasPrices: ChainMap<GasPriceConfig>,
getTokenExchangeRate: (local: ChainName, remote: ChainName) => BigNumber,
getTokenUsdPrice?: (chain: ChainName) => number,
remoteOverhead?: (remote: ChainName) => number,
getOverhead?: (local: ChainName, remote: ChainName) => number,
): AllStorageGasOracleConfigs {
return chainNames.filter(isEthereumProtocolChain).reduce((agg, local) => {
const remotes = chainNames.filter((chain) => local !== chain);
@ -217,7 +218,7 @@ export function getAllStorageGasOracleConfigs(
gasPrices,
getTokenExchangeRate,
getTokenUsdPrice,
remoteOverhead,
getOverhead,
),
};
}, {}) as AllStorageGasOracleConfigs;

Loading…
Cancel
Save