Skip to content

Commit

Permalink
improve(API): Pass gasPrice into relayerFeeDetails call
Browse files Browse the repository at this point in the history
We should pass the pre-computed gas price into this call so that we don't query the gas price twice. Additionally, we can use the scaled up gas price value to derive the gas fee totals, which currently are not using the scaled up values
  • Loading branch information
nicholaspai committed Jan 9, 2025
1 parent 948b6f2 commit 5cdec88
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
2 changes: 2 additions & 0 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1948,6 +1948,7 @@ export function isContractCache(chainId: number, address: string) {

export function getCachedFillGasUsage(
deposit: Parameters<typeof buildDepositForSimulation>[0],
gasPrice: BigNumber,
overrides?: Partial<{
spokePoolAddress: string;
relayerAddress: string;
Expand Down Expand Up @@ -1975,6 +1976,7 @@ export function getCachedFillGasUsage(
buildDepositForSimulation(deposit),
overrides?.relayerAddress,
{
gasPrice,
// Scale the op stack L1 gas cost component by the base fee multiplier.
// Consider adding a new environment variable OP_STACK_L1_GAS_COST_MARKUP if we want finer-grained control.
opStackL1GasCostMultiplier: getGasMarkup(deposit.destinationChainId)
Expand Down
33 changes: 17 additions & 16 deletions api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,39 +164,30 @@ const handler = async (
message,
};

const [tokenPriceNative, _tokenPriceUsd, latestBlock, gasCosts, gasPrice] =
const [tokenPriceNative, _tokenPriceUsd, latestBlock, gasPrice] =
await Promise.all([
getCachedTokenPrice(
l1Token.address,
sdk.utils.getNativeTokenSymbol(destinationChainId).toLowerCase()
),
getCachedTokenPrice(l1Token.address, "usd"),
getCachedLatestBlock(HUB_POOL_CHAIN_ID),
// Only use cached gas units if message is not defined, i.e. standard for standard bridges
isMessageDefined
? undefined
: getCachedFillGasUsage(depositArgs, {
relayerAddress: relayer,
}),
latestGasPriceCache(destinationChainId).get(),
]);
const tokenPriceUsd = ethers.utils.parseUnits(_tokenPriceUsd.toString());

const [
relayerFeeDetails,
gasCosts,
multicallOutput,
fullRelayerBalances,
transferRestrictedBalances,
fullRelayerMainnetBalances,
] = await Promise.all([
getRelayerFeeDetails(
depositArgs,
tokenPriceNative,
relayer,
gasPrice,
gasCosts?.nativeGasCost,
gasCosts?.tokenGasCost
),
isMessageDefined
? undefined // Only use cached gas units if message is not defined, i.e. standard for standard bridges
: getCachedFillGasUsage(depositArgs, gasPrice, {
relayerAddress: relayer,
}),
callViaMulticall3(provider, multiCalls, {
blockTag: latestBlock.number,
}),
Expand Down Expand Up @@ -226,6 +217,16 @@ const handler = async (
)
),
]);
// This call should not make any additional RPC queries if gasCosts is defined--for any deposit
// with an empty message.
const relayerFeeDetails = await getRelayerFeeDetails(
depositArgs,
tokenPriceNative,
relayer,
gasPrice,
gasCosts?.nativeGasCost,
gasCosts?.tokenGasCost
);
logger.debug({
at: "Limits",
message: "Relayer fee details from SDK",
Expand Down

0 comments on commit 5cdec88

Please sign in to comment.