Skip to content

Commit

Permalink
Use already deployed erc20 tokens
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Aug 12, 2024
1 parent a892e59 commit 684ddc5
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 21 deletions.
1 change: 0 additions & 1 deletion zk_toolbox/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion zk_toolbox/crates/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ url.workspace = true
xshell.workspace = true
thiserror.workspace = true
strum.workspace = true
lazy_static = "1.5.0"
14 changes: 11 additions & 3 deletions zk_toolbox/crates/config/src/ecosystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ use zksync_basic_types::L2ChainId;
use crate::{
consts::{
CONFIGS_PATH, CONFIG_NAME, CONTRACTS_FILE, ECOSYSTEM_PATH, ERA_CHAIN_ID,
ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY, LOCAL_DB_PATH,
WALLETS_FILE,
ERC20_CONFIGS_FILE, ERC20_DEPLOYMENT_FILE, INITIAL_DEPLOYMENT_FILE, L1_CONTRACTS_FOUNDRY,
LOCAL_DB_PATH, WALLETS_FILE,
},
create_localhost_wallets,
forge_interface::deploy_ecosystem::input::{Erc20DeploymentConfig, InitialDeploymentConfig},
forge_interface::deploy_ecosystem::{
input::{Erc20DeploymentConfig, InitialDeploymentConfig},
output::{ERC20Tokens, Erc20Token},
},
traits::{FileConfigWithDefaultName, ReadConfig, SaveConfig, ZkToolboxConfig},
ChainConfig, ChainConfigInternal, ContractsConfig, WalletsConfig,
};
Expand Down Expand Up @@ -169,6 +172,11 @@ impl EcosystemConfig {
pub fn get_erc20_deployment_config(&self) -> anyhow::Result<Erc20DeploymentConfig> {
Erc20DeploymentConfig::read(self.get_shell(), self.config.join(ERC20_DEPLOYMENT_FILE))
}
pub fn get_erc20_tokens(&self) -> Vec<Erc20Token> {
ERC20Tokens::read(self.get_shell(), self.config.join(ERC20_CONFIGS_FILE))
.map(|tokens| tokens.tokens.values().cloned().collect())
.unwrap_or_default()
}

pub fn get_wallets(&self) -> anyhow::Result<WalletsConfig> {
let path = self.config.join(WALLETS_FILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct L1StateTransitionOutput {
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct TokenDeployErc20Output {
pub struct Erc20Token {
pub address: Address,
pub name: String,
pub symbol: String,
Expand All @@ -89,12 +89,12 @@ pub struct TokenDeployErc20Output {
}

#[derive(Debug, Deserialize, Serialize, Clone)]
pub struct DeployErc20Output {
pub tokens: HashMap<String, TokenDeployErc20Output>,
pub struct ERC20Tokens {
pub tokens: HashMap<String, Erc20Token>,
}

impl FileConfigWithDefaultName for DeployErc20Output {
impl FileConfigWithDefaultName for ERC20Tokens {
const FILE_NAME: &'static str = ERC20_CONFIGS_FILE;
}

impl ZkToolboxConfig for DeployErc20Output {}
impl ZkToolboxConfig for ERC20Tokens {}
26 changes: 19 additions & 7 deletions zk_toolbox/crates/zk_inception/src/commands/chain/args/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{path::PathBuf, str::FromStr};
use anyhow::{bail, Context};
use clap::{Parser, ValueEnum};
use common::{Prompt, PromptConfirm, PromptSelect};
use config::forge_interface::deploy_ecosystem::output::Erc20Token;
use serde::{Deserialize, Serialize};
use slugify_rs::slugify;
use strum::{Display, EnumIter, IntoEnumIterator};
Expand Down Expand Up @@ -71,6 +72,7 @@ impl ChainCreateArgs {
self,
number_of_chains: u32,
l1_network: &L1Network,
possible_erc20: Vec<Erc20Token>,
) -> anyhow::Result<ChainCreateArgsFinal> {
let mut chain_name = self
.chain_name
Expand Down Expand Up @@ -151,14 +153,24 @@ impl ChainCreateArgs {
&& self.base_token_price_denominator.is_none()
&& self.base_token_price_nominator.is_none()
{
let base_token_selection =
PromptSelect::new(MSG_BASE_TOKEN_SELECTION_PROMPT, BaseTokenSelection::iter())
.ask();
let mut token_selection: Vec<_> =
BaseTokenSelection::iter().map(|a| a.to_string()).collect();

match base_token_selection {
BaseTokenSelection::Eth => BaseToken::eth(),
BaseTokenSelection::Custom => {
let address = Prompt::new(MSG_BASE_TOKEN_ADDRESS_PROMPT).ask();
let erc20_tokens = &mut (possible_erc20
.iter()
.map(|t| format!("{:?}", t.address))
.collect());
token_selection.append(erc20_tokens);
let base_token_selection =
PromptSelect::new(MSG_BASE_TOKEN_SELECTION_PROMPT, token_selection).ask();
match base_token_selection.as_str() {
"Eth" => BaseToken::eth(),
other => {
let address = if other == "Custom" {
Prompt::new(MSG_BASE_TOKEN_ADDRESS_PROMPT).ask()
} else {
H160::from_str(other)?
};
let nominator = Prompt::new(MSG_BASE_TOKEN_PRICE_NOMINATOR_PROMPT)
.validate_with(number_validator)
.ask();
Expand Down
2 changes: 2 additions & 0 deletions zk_toolbox/crates/zk_inception/src/commands/chain/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ fn create(
ecosystem_config: &mut EcosystemConfig,
shell: &Shell,
) -> anyhow::Result<()> {
let tokens = ecosystem_config.get_erc20_tokens();
let args = args
.fill_values_with_prompt(
ecosystem_config.list_of_chains().len() as u32,
&ecosystem_config.l1_network,
tokens,
)
.context(MSG_ARGS_VALIDATOR_ERR)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl EcosystemCreateArgs {
// Make the only chain as a default one
self.chain.set_as_default = Some(true);

let chain = self.chain.fill_values_with_prompt(0, &l1_network)?;
let chain = self.chain.fill_values_with_prompt(0, &l1_network, vec![])?;

let start_containers = self.start_containers.unwrap_or_else(|| {
PromptConfirm::new(MSG_START_CONTAINERS_PROMPT)
Expand Down
6 changes: 3 additions & 3 deletions zk_toolbox/crates/zk_inception/src/commands/ecosystem/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use config::{
input::{
DeployErc20Config, DeployL1Config, Erc20DeploymentConfig, InitialDeploymentConfig,
},
output::{DeployErc20Output, DeployL1Output},
output::{DeployL1Output, ERC20Tokens},
},
script_params::{DEPLOY_ECOSYSTEM_SCRIPT_PARAMS, DEPLOY_ERC20_SCRIPT_PARAMS},
},
Expand Down Expand Up @@ -164,7 +164,7 @@ async fn deploy_erc20(
contracts_config: &ContractsConfig,
forge_args: ForgeScriptArgs,
l1_rpc_url: String,
) -> anyhow::Result<DeployErc20Output> {
) -> anyhow::Result<ERC20Tokens> {
let deploy_config_path = DEPLOY_ERC20_SCRIPT_PARAMS.input(&ecosystem_config.link_to_code);
let wallets = ecosystem_config.get_wallets()?;
DeployErc20Config::new(
Expand Down Expand Up @@ -194,7 +194,7 @@ async fn deploy_erc20(
forge.run(shell)?;
spinner.finish();

let result = DeployErc20Output::read(
let result = ERC20Tokens::read(
shell,
DEPLOY_ERC20_SCRIPT_PARAMS.output(&ecosystem_config.link_to_code),
)?;
Expand Down

0 comments on commit 684ddc5

Please sign in to comment.