Skip to content

Commit

Permalink
feat: Adds filtering of erc20 tokens by their l2 address (#447)
Browse files Browse the repository at this point in the history
# 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 ❔

<!-- Why are these changes done? What goal do they contribute to? What
are the principles behind them? -->
<!-- Example: PR templates ensure PR reviewers, observers, and future
iterators are in context about the evolution of repos. -->

## Checklist

<!-- Check your PR fulfills the following items. -->
<!-- For draft PRs check the boxes as you complete them. -->

- [ ] 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`.
  • Loading branch information
montekki authored Apr 24, 2024
1 parent ec719b5 commit 09f8810
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions bin/withdrawal-finalizer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ pub struct Config {

#[envconfig(from = "ONLY_L1_RECIPIENTS")]
pub only_l1_recipients: Option<AddrList>,

/// Only finalize these tokens specified by their L2 addresses
#[envconfig(from = "ONLY_FINALIZE_THESE_TOKENS")]
pub only_finalize_these_tokens: Option<AddrList>,
}

#[derive(Deserialize, Serialize, Debug, Eq, PartialEq)]
Expand Down
7 changes: 6 additions & 1 deletion bin/withdrawal-finalizer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09f8810

Please sign in to comment.