-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Base Token Fundamentals (#2204)
## What ❔ This PR puts in place the major pieces needed in the Base Token flow as described in the [design doc](https://www.notion.so/matterlabs/Custom-Base-Token-Tech-Design-74e158112f24463c82d96415bed76d04). This PR adds a preliminary flow of: - Periodically fetch the new price from an external API - Update the conversion ration in the DB - Have the Fee Model use the latest stored conversion ratio In the scope of this PR: - Introducing BaseTokenAdjuster to the Node Framework - Adding the DB migration and the associated DAL - Adding the proper configs for this layer to work - Conditionally updating the gas price with a BaseToken<->ETH conversion ratio such that it's used in charging the gas in the base token and estimating gas for txs. - Unit + Integration tests Out of scope of this PR: - Protocol contract changes needed for a base token chain to work (these are already merged) - Using an external API to fetch prices - Updating the L1 with the conversion ratio - Observability, API redundancy, ## Why ❔ Multiple ZK Chains are ready to go on mainnet with a custom token used as the gas token. ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. - [x] Spellcheck has been run via `zk spellcheck`. --------- Co-authored-by: Ivan Schasny <[email protected]>
- Loading branch information
Showing
59 changed files
with
1,211 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::time::Duration; | ||
|
||
use serde::Deserialize; | ||
|
||
/// By default the ratio persister will run every 30 seconds. | ||
pub const DEFAULT_INTERVAL_MS: u64 = 30_000; | ||
|
||
#[derive(Debug, Clone, PartialEq, Deserialize)] | ||
pub struct BaseTokenAdjusterConfig { | ||
/// How often to spark a new cycle of the ratio persister to fetch external prices and persis ratios. | ||
#[serde(default = "BaseTokenAdjusterConfig::default_interval")] | ||
pub price_polling_interval_ms: u64, | ||
} | ||
|
||
impl Default for BaseTokenAdjusterConfig { | ||
fn default() -> Self { | ||
Self { | ||
price_polling_interval_ms: Self::default_interval(), | ||
} | ||
} | ||
} | ||
|
||
impl BaseTokenAdjusterConfig { | ||
fn default_interval() -> u64 { | ||
DEFAULT_INTERVAL_MS | ||
} | ||
|
||
pub fn price_polling_interval(&self) -> Duration { | ||
Duration::from_millis(self.price_polling_interval_ms) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...lib/dal/.sqlx/query-0fc8ede1d0962938d606c6352335afce09869d43eb88ec7fdb526ce8491e35d9.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
...lib/dal/.sqlx/query-c5aef75dbeb520c965a0996abed9713f437db492e2075ca69e11e2ef5728ccaa.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
core/lib/dal/migrations/20240611121747_add_base_token_ratio_table.down.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS base_token_ratios; |
Oops, something went wrong.