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: Use base fee multiplier option in SDK to resolve gas fees #1969

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

nicholaspai
Copy link
Member

@nicholaspai nicholaspai commented Dec 24, 2024

Builds on across-protocol/sdk#801 and applies relayer's base fee multiplier to new SDK parameter to scale the base fee in one use case:

  • Submitting transactions with an estimated gas fee via TransactionClient
  • Estimating fill costs via the ProfitClient
    • We decided against using the baseFeeMultiplier when estimating fill costs and instead using the default multiplier of 1.0. This ensures the fills are submitted using an estimated gas price based on current gas prices, which is fine for the filler because they know exactly when they are going to submit the fill.

We can test this by querying /api/gas-prices against the prod API deployment. The gas prices should be mostly in line otherwise the relayer will see too many deposits as unprofitable potentially

Comment on lines +187 to 188
maxFeePerGas: feeData.maxFeePerGas,
maxPriorityFeePerGas: scaleByNumber(feeData.maxPriorityFeePerGas, priorityScaler),
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are retaining the ability to scale the priority fee (which we probably need to), then we'd still need to adjust the base fee here. Otherwise we'd be eating into our base fee multiplier by increasing the priority fee.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok so do you suggest keeping the existing code here?

@nicholaspai nicholaspai requested a review from pxrl January 2, 2025 23:00
@nicholaspai nicholaspai changed the title improve(TransactionUtils): Use base fee multiplier improve: Use base fee multiplier option in SDK to resolve gas fees Jan 2, 2025
@@ -205,7 +205,9 @@ export class ProfitClient {

private async _getTotalGasCost(deposit: Deposit, relayer: string): Promise<TransactionCostEstimate> {
try {
return await this.relayerFeeQueries[deposit.destinationChainId].getGasCosts(deposit, relayer);
return await this.relayerFeeQueries[deposit.destinationChainId].getGasCosts(deposit, relayer, {
baseFeeMultiplier: this.gasPadding,
Copy link
Member Author

Choose a reason for hiding this comment

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

Using gasPadding here should align the relayer with the API

Copy link
Contributor

Choose a reason for hiding this comment

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

gasPadding has the valid range [0, 2] scaled to 18 decimals, so we need clamp this to a minimum of 1e18.

Copy link
Contributor

@pxrl pxrl Jan 3, 2025

Choose a reason for hiding this comment

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

I'm not 100% sure we want to do this though. The intention of the base fee multiplier is to account for time-based uncertainty around when the fill will be made. That's a problem in the API, but it's not a problem for the relayer because it's doing this calculation JIT, so it has a lot more certainty about when the fill would be submitted.

Additionally, the intention of gasPadding is to add some padding for the fill-time gas consumption (i.e. how many units of gas are consumed). This change would instead pad the base fee, which may then be discounted by the gasMultiplier.

tldr I think the relayer should probably retain its existing behaviour here, such that:

  • gasPadding is applied to the estimated gas consumption.
  • baseFeeMultiplier is 1x because the relayer does not really need to consider uncertainty about the base fee when the transaction lands (the base fee is already returned from the pending block).

provider,
priorityFeeScaler,
maxFeePerGasScaler,
await contract.populateTransaction[method](...(args as Array<unknown>), { value })
Copy link
Member Author

@nicholaspai nicholaspai Jan 3, 2025

Choose a reason for hiding this comment

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

getting gas price here should be same as the gas price used in estimating the fill cost in the ProfitClient

Not true anymore, I agree with Paul's comment: https://github.com/across-protocol/relayer/pull/1969/files#r1901762081

// Pass in unsignedTx here for better Linea gas price estimations via the Linea Viem provider.
const feeData = await gasPriceOracle.getGasPriceEstimate(provider, {
chainId,
baseFeeMultiplier: toBNWei(maxFeePerGasScaler),
Copy link
Contributor

Choose a reason for hiding this comment

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

We might want to clamp this to 1e18 as well.

@nicholaspai nicholaspai marked this pull request as ready for review January 3, 2025 16:28
@nicholaspai nicholaspai requested a review from pxrl January 3, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants