zksync-era icon indicating copy to clipboard operation
zksync-era copied to clipboard

feat: Custom Base Token Gas Price Oracle

Open jrchatruc opened this issue 1 year ago • 0 comments

What ❔

This PR adds a new NativeTokenFetcher component to be used by custom base token stacks. It's in charge of caching the latest conversion rate between the native token and eth so gas prices can be converted accordingly (both l1_gas_price and l1_pubdata_price).

A new config toml file is added holding the configuration for it, currently just a host and poll_interval variables to get the host from which the conversion rate is queried and how often the conversion rate is refreshed.

TODO:

  • [x] Connect the fetcher with the places where l1_gas_price and l1_pubdata_price are determined.

There is an example flask app in the root of the repo on this PR called erc20_example.py that just returns a random conversion rate between 1 and a 100, which you can run with

flask --app erc20_example run

to quickly test out the fetcher component. This will be deleted once proper tests are written.

Why ❔

Gas Prices in a custom base token setting need to be in the native currency of the chain. These prices are partially determined by l1 gas prices in L1, which are in eth, so a conversion is required.

Checklist

  • [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • [ ] Tests for the changes have been added / updated.
  • [ ] Documentation comments have been added / updated.
  • [ ] Code has been formatted via zk fmt and zk lint.
  • [ ] Spellcheck has been run via zk spellcheck.
  • [ ] Linkcheck has been run via zk linkcheck.

jrchatruc avatar Feb 01 '24 22:02 jrchatruc