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

Improving gas estimates for l2s #53

Merged
merged 14 commits into from
Feb 1, 2022
Merged

Conversation

snreynolds
Copy link
Member

@snreynolds snreynolds commented Jan 21, 2022

Noteable changes:

  • Moved buildTrade and buildSwapMethodParameters to a separate library so we can access them in the gasModel
  • On optimism the gasEstimate now considers the l1security fee
  • Added a GasDataProvider that reads from the gas oracle contract to get gas constants for the l1 security fee calculations
  • Surfaced initTicksCrossed, gasUseL1, and gasCostL1 to the logger so they’re printed at each run of the router (this was to help with manual gas estimation testing but can definitely be removed)
  • Moved gasCost constants to be readable by chainId and updated some Arbitrum estimates
  • Small nit change: added some logic so that if no protocols are specified in the CLI it defaults to V3 for chains that do not support v2

@snreynolds snreynolds marked this pull request as ready for review January 26, 2022 19:06
src/providers/v3/gas-data-provider.ts Outdated Show resolved Hide resolved
src/routers/alpha-router/alpha-router.ts Outdated Show resolved Hide resolved
src/routers/router.ts Outdated Show resolved Hide resolved
src/providers/v3/gas-data-provider.ts Outdated Show resolved Hide resolved
src/providers/v3/gas-data-provider.ts Show resolved Hide resolved
Copy link
Contributor

@willpote willpote left a comment

Choose a reason for hiding this comment

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

Nice! Just nits at this point!

Comment on lines 329 to 330
`Total initialized ticks crossed ${v3Route.initializedTicksCrossedList.length}`
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Each element in the initializedTIcksCrossedList is the number of ticks crossed for each pool so you need to sum them

Copy link
Member Author

@snreynolds snreynolds Feb 1, 2022

Choose a reason for hiding this comment

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

Right! Actually these can just be deleted - I just needed these data points when I was manual testing with arbirtrum and optimism (and I was only ever looking at a swap with 1 route).

If you think these are good to print out though in general, I can change it back to summing over all the routes.

@@ -318,5 +320,14 @@ export abstract class BaseCommand extends Command {
estimatedGasUsed: estimatedGasUsed.toString(),
gasPriceWei: gasPriceWei.toString(),
});
const hops = routeAmounts[0]?.poolAddresses.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

Have to sum across all the routeAmounts

src/providers/multicall-uniswap-provider.ts Outdated Show resolved Hide resolved
src/providers/multicall-uniswap-provider.ts Outdated Show resolved Hide resolved
@snreynolds snreynolds merged commit 3091eb2 into main Feb 1, 2022
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.

None yet

3 participants