Skip to content

Commit

Permalink
(feat): ZK token works as gateway base token
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid Ateir committed Oct 16, 2024
1 parent 2565ce7 commit ff3e64c
Show file tree
Hide file tree
Showing 11 changed files with 454 additions and 9 deletions.
63 changes: 62 additions & 1 deletion .github/scripts/gateway_zktoken.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# zk_supervisor clean all

sudo rm -rf ./volumes && zk_supervisor clean containers && zk_inception up -o false

zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \
Expand All @@ -8,4 +10,63 @@ zk_inception ecosystem init --deploy-paymaster --deploy-erc20 \
--prover-db-name=zksync_prover_localhost_era \
--ignore-prerequisites --observability=false --skip-submodules-checkout \
--chain era \
--verbose
--verbose

zk_inception server --ignore-prerequisites --chain era &> ./era.log &

sleep 20

zk_inception chain extract-last-tx-hash --chain era --verbose

# Define the path to the TOML file
TOML_FILE="contracts/l1-contracts/script-out/output-deploy-zk-token.toml"

# Extract the l1Address from the TOML file
zkL1Address=$(grep -A 1 "\[ZK.l1Address\]" "$TOML_FILE" | grep "l1Address" | awk -F' = ' '{print $2}' | tr -d '"' | tr -d ' ' | tr -d '\n')

# Check if the address starts with 0x and remove it
if [[ $zkL1Address == 0x* ]]; then
zkL1Address="${zkL1Address:2}"
fi

# Output the extracted and sliced l1Address (for debugging purposes)
echo "Sliced l1Address: $zkL1Address"

zk_inception chain create \
--chain-name gateway \
--chain-id 505 \
--prover-mode no-proofs \
--wallet-creation localhost \
--l1-batch-commit-data-generator-mode rollup \
--base-token-address $zkL1Address \
--base-token-price-nominator 1 \
--base-token-price-denominator 1 \
--set-as-default false \
--ignore-prerequisites --skip-submodules-checkout --skip-contract-compilation-override

zk_inception chain init \
--deploy-paymaster \
--l1-rpc-url=http://localhost:8545 \
--server-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--server-db-name=zksync_server_localhost_gateway \
--prover-db-url=postgres://postgres:notsecurepassword@localhost:5432 \
--prover-db-name=zksync_prover_localhost_gateway \
--chain gateway --skip-submodules-checkout

zk_inception chain convert-to-gateway --chain gateway --ignore-prerequisites

zk_inception server --ignore-prerequisites --chain gateway &> ./gateway.log &

sleep 20

zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway

zk_inception chain migrate-from-gateway --chain era --gateway-chain-name gateway

zk_inception chain migrate-to-gateway --chain era --gateway-chain-name gateway

zk_inception server --ignore-prerequisites --chain era &> ./rollup.log &

sleep 20

# zk_supervisor test integration --no-deps --ignore-prerequisites --chain era
2 changes: 1 addition & 1 deletion contracts
11 changes: 8 additions & 3 deletions zk_toolbox/crates/common/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ abigen!(
function symbol() external view returns (string)
function decimals() external view returns (uint8)
function mint(address to, uint256 amount)
function transfer(address to, uint256 amount)
]"
);

Expand Down Expand Up @@ -97,17 +98,21 @@ pub async fn mint_token(
let contract = TokenContract::new(token_address, client);

let mut pending_calls = vec![];
for address in addresses {
let mut pending_txs = vec![];
for address in addresses.clone() {
pending_calls.push(contract.mint(address, amount.into()));
}

let mut pending_txs = vec![];
for address in addresses {
pending_calls.push(contract.transfer(address, amount.into()));
}

for call in &pending_calls {
let call = call.send().await;
match call {
// It's safe to set such low number of confirmations and low interval for localhost
Ok(call) => pending_txs.push(call.confirmations(3).interval(Duration::from_millis(30))),
Err(e) => logger::error(format!("Minting is not successful {e}")),
Err(e) => logger::error(format!("Minting or transfer is not successful {e}")),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ impl Default for Erc20DeploymentConfig {
implementation: String::from("TestnetERC20Token.sol"),
mint: U256::from_str("9000000000000000000000").unwrap(),
},
Erc20DeploymentTokensConfig {
name: String::from("ZK"),
symbol: String::from("ZK"),
decimals: 8,
implementation: String::from("TestnetERC20Token.sol"),
mint: U256::from_str("9000000000000000000000").unwrap(),
},
],
}
}
Expand Down
6 changes: 6 additions & 0 deletions zk_toolbox/crates/config/src/forge_interface/script_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ pub const GATEWAY_PREPARATION: ForgeScriptParams = ForgeScriptParams {
output: "script-out/output-gateway-preparation-l1.toml",
script_path: "deploy-scripts/GatewayPreparation.s.sol",
};

pub const ZK_PREPARATION: ForgeScriptParams = ForgeScriptParams {
input: "script-config/config-deploy-zk.toml",
output: "script-out/output-deploy-zk-token.toml",
script_path: "deploy-scripts/DeployZKAndBridgeToL1.s.sol",
};
20 changes: 20 additions & 0 deletions zk_toolbox/crates/config/src/wallet_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,25 @@ pub fn create_localhost_wallets(
&base_path,
5,
)?),
governance: Some(Wallet::from_mnemonic(
&eth_mnemonic.test_mnemonic,
&base_path,
6,
)?),
chain_admin: Some(Wallet::from_mnemonic(
&eth_mnemonic.test_mnemonic,
&base_path,
7,
)?),
deployer_gateway: Some(Wallet::from_mnemonic(
&eth_mnemonic.test_mnemonic,
&base_path,
8,
)?),
governor_gateway: Some(Wallet::from_mnemonic(
&eth_mnemonic.test_mnemonic,
&base_path,
9,
)?),
})
}
12 changes: 12 additions & 0 deletions zk_toolbox/crates/config/src/wallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct WalletsConfig {
pub fee_account: Wallet,
pub governor: Wallet,
pub token_multiplier_setter: Option<Wallet>,
pub governance: Option<Wallet>,
pub chain_admin: Option<Wallet>,
pub deployer_gateway: Option<Wallet>,
pub governor_gateway: Option<Wallet>,
}

impl WalletsConfig {
Expand All @@ -28,6 +32,10 @@ impl WalletsConfig {
fee_account: Wallet::random(rng),
governor: Wallet::random(rng),
token_multiplier_setter: Some(Wallet::random(rng)),
governance: Some(Wallet::random(rng)),
chain_admin: Some(Wallet::random(rng)),
deployer_gateway: Some(Wallet::random(rng)),
governor_gateway: Some(Wallet::random(rng)),
}
}

Expand All @@ -40,6 +48,10 @@ impl WalletsConfig {
fee_account: Wallet::empty(),
governor: Wallet::empty(),
token_multiplier_setter: Some(Wallet::empty()),
governance: Some(Wallet::empty()),
chain_admin: Some(Wallet::empty()),
deployer_gateway: Some(Wallet::empty()),
governor_gateway: Some(Wallet::empty()),
}
}
pub fn deployer_private_key(&self) -> Option<H256> {
Expand Down
27 changes: 24 additions & 3 deletions zk_toolbox/crates/zk_inception/src/commands/chain/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,30 @@ pub async fn mint_base_token(
let wallets = ecosystem_config.get_wallets()?;
let chain_wallets = chain_config.get_wallets_config()?;
let base_token = &chain_config.base_token;
let addresses = vec![wallets.governor.address, chain_wallets.governor.address];
let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128
/ base_token.denominator as u128;
let addresses = vec![
wallets.governor.address,
wallets
.deployer_gateway
.ok_or(anyhow::Error::msg("Deployer gateway address is missing"))?
.address,
wallets
.governor_gateway
.ok_or(anyhow::Error::msg("Governor gateway address is missing"))?
.address,
wallets
.governance
.ok_or(anyhow::Error::msg("Governance address is missing"))?
.address,
wallets
.chain_admin
.ok_or(anyhow::Error::msg("Chain admin address address is missing"))?
.address,
chain_wallets.governor.address,
];

let amount = 1000000000000000000;
// let amount = AMOUNT_FOR_DISTRIBUTION_TO_WALLETS * base_token.nominator as u128
// / base_token.denominator as u128;
common::ethereum::mint_token(
wallets.governor,
base_token.address,
Expand Down
Loading

0 comments on commit ff3e64c

Please sign in to comment.