Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(API): Pass gasPrice into relayerFeeDetails call + add OP_STACK_L1_DATA_FEE_MARKUP #1366

Merged
merged 7 commits into from
Jan 10, 2025
Next Next commit
improve(API): Pass gasPrice into relayerFeeDetails call
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
nicholaspai committed Jan 9, 2025
commit 5cdec8800539f04985f31d009e6477b6333f926e
2 changes: 2 additions & 0 deletions api/_utils.ts
Original file line number Diff line number Diff line change
@@ -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;
@@ -1975,6 +1976,7 @@ export function getCachedFillGasUsage(
buildDepositForSimulation(deposit),
overrides?.relayerAddress,
{
gasPrice,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing this in avoids a redundant SDK.GasPriceOracle.getGasPriceEstimate call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if we don't pass in this gas price, then this function will return gasCosts that we use in the relayerFeeCalculator but it recomputes the gas price without any multipliers. So, the resultant tokenGasCost is likely too low

// 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)
33 changes: 17 additions & 16 deletions api/limits.ts
Original file line number Diff line number Diff line change
@@ -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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we are using this tokenGasCost that wasn't dependent on the gasPrice we computed in the latestGasPriceCache(destinationChainId).get() call, which means that this tokenGasCost estimate is low

),
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,
}),
@@ -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",