From 09f88105090009cc39f8ba900044ddca41e13aaf Mon Sep 17 00:00:00 2001 From: Fedor Sakharov Date: Wed, 24 Apr 2024 13:25:04 +0200 Subject: [PATCH] feat: Adds filtering of erc20 tokens by their l2 address (#447) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # What ❔ Sometimes we only want a specific set of tokens or even no tokens at all to be finalized. If we want no erc20 tokens to be finalized, say, in the event that we only want to do ETH withdrawals, this option can be set to ``` ONLY_FINALIZE_THESE_TOKENS="[]" ``` ## Why ❔ ## 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 `cargo fmt`. --- README.md | 1 + bin/withdrawal-finalizer/src/config.rs | 4 ++++ bin/withdrawal-finalizer/src/main.rs | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 574687a9..1603be1b 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ Deployment is done by deploying a dockerized image of the service. | `CUSTOM_TOKEN_ADDRESSES` | (Optional) Adds a predefined list of tokens to finalize. May be useful in case of custom bridge setups when the regular technique of finding token deployments does not work. | | `ENABLE_WITHDRAWAL_METERING` | (Optional, default: `"true"`) By default Finalizer collects metrics about withdrawn token volumens. Users may optionally switch off this metering. | | `ETH_FINALIZATION_THRESHOLD`| (Optional, default: "0") Finalizer will only finalize ETH withdrawals that are greater or equal to this value | +| `ONLY_FINALIZE_THESE_TOKENS` | (Optional, default: `None`) If specified, creates a whitelist of erc20 tokens that will be finalized. The configuration structure describing the service config can be found in [`config.rs`](https://github.com/matter-labs/zksync-withdrawal-finalizer/blob/main/bin/withdrawal-finalizer/src/config.rs) diff --git a/bin/withdrawal-finalizer/src/config.rs b/bin/withdrawal-finalizer/src/config.rs index 6cf88923..de701cc5 100644 --- a/bin/withdrawal-finalizer/src/config.rs +++ b/bin/withdrawal-finalizer/src/config.rs @@ -86,6 +86,10 @@ pub struct Config { #[envconfig(from = "ONLY_L1_RECIPIENTS")] pub only_l1_recipients: Option, + + /// Only finalize these tokens specified by their L2 addresses + #[envconfig(from = "ONLY_FINALIZE_THESE_TOKENS")] + pub only_finalize_these_tokens: Option, } #[derive(Deserialize, Serialize, Debug, Eq, PartialEq)] diff --git a/bin/withdrawal-finalizer/src/main.rs b/bin/withdrawal-finalizer/src/main.rs index 27c6306d..63b31591 100644 --- a/bin/withdrawal-finalizer/src/main.rs +++ b/bin/withdrawal-finalizer/src/main.rs @@ -202,11 +202,16 @@ async fn main() -> Result<()> { tokens.extend_from_slice(custom_tokens.0.as_slice()); } - tracing::info!("tokens {tokens:?}"); if let Some(ref custom_tokens) = config.custom_token_deployer_addresses { tokens.extend_from_slice(custom_tokens.0.as_slice()); } + if let Some(only_finalize_these_tokens) = config.only_finalize_these_tokens { + tokens.retain(|token| only_finalize_these_tokens.0.contains(token)); + } + + tracing::info!("tokens {tokens:?}"); + let l2_events = L2EventsListener::new( config.api_web3_json_rpc_ws_url.as_str(), config