Skip to content

Commit

Permalink
(fix): fund chain governance with ZK token
Browse files Browse the repository at this point in the history
  • Loading branch information
Raid Ateir committed Oct 23, 2024
1 parent 2f136b8 commit a4c1d90
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
22 changes: 13 additions & 9 deletions .github/workflows/ci-core-reusable.yml
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,6 @@ jobs:
echo "ZK_L1_ADDRESS=$zkL1Address" >> $GITHUB_ENV
echo "Extracted ZK L1 Address: $zkL1Address"
- name: Gracefully shut down Era server
run: |
ERA_SERVER_PID=$(netstat -tuln | grep :3075 | awk '{print $7}' | cut -d'/' -f1)
if [ -n "$ERA_SERVER_PID" ]; then
kill -2 $ERA_SERVER_PID
echo "Gracefully shutting down Era server with PID: $ERA_SERVER_PID"
sleep 5 # Wait for the shutdown to complete
fi
- name: Read Custom Token address and set as environment variable
run: |
CUSTOM_TOKEN_ADDRESS=$(awk -F": " '/tokens:/ {found_tokens=1} found_tokens && /DAI:/ {found_dai=1} found_dai && /address:/ {print $2; exit}' ./configs/erc20.yaml)
Expand Down Expand Up @@ -281,6 +272,8 @@ jobs:
--prover-db-name=zksync_prover_localhost_validium \
--chain validium
ci_run zk_inception chain deploy-and-bridge-zk --chain era --only-funding-tx --verbose
- name: Create and initialize chain with Custom Token
run: |
ci_run zk_inception chain create \
Expand All @@ -304,6 +297,17 @@ jobs:
--prover-db-name=zksync_prover_localhost_custom_token \
--chain custom_token
ci_run zk_inception chain deploy-and-bridge-zk --chain era --only-funding-tx --verbose
- name: Gracefully shut down Era server
run: |
ERA_SERVER_PID=$(netstat -tuln | grep :3075 | awk '{print $7}' | cut -d'/' -f1)
if [ -n "$ERA_SERVER_PID" ]; then
kill -2 $ERA_SERVER_PID
echo "Gracefully shutting down Era server with PID: $ERA_SERVER_PID"
sleep 5 # Wait for the shutdown to complete
fi
- name: Initialize gateway chain
run: |
ci_run zk_inception chain create \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fs, fs::File, io::BufReader, path::PathBuf};

use anyhow::Context;
use clap::Parser;
use common::{
config::global_config,
forge::{Forge, ForgeScriptArgs},
Expand All @@ -15,7 +16,7 @@ use ethers::{
utils::hex,
};
use lazy_static::lazy_static;
use serde::Deserialize;
use serde::{Deserialize, Serialize};
use xshell::Shell;
use zksync_basic_types::{H256, U256, U64};
use zksync_types::L2ChainId;
Expand All @@ -26,6 +27,17 @@ use crate::{
utils::forge::{check_the_balance, fill_forge_private_key},
};

#[derive(Debug, Serialize, Deserialize, Parser)]
pub struct DeployAndBridgeZKArgs {
/// All ethereum environment related arguments
#[clap(flatten)]
#[serde(flatten)]
pub forge_args: ForgeScriptArgs,

#[clap(long)]
pub only_funding_tx: bool,
}

#[derive(Debug, Deserialize)]
struct JsonData {
transactions: Vec<Transaction>,
Expand All @@ -42,7 +54,8 @@ lazy_static! {
"function run() public",
"function supplyEraWallet(address addr, uint256 amount) public",
"function finalizeZkTokenWithdrawal(uint256 chainId, uint256 l2BatchNumber, uint256 l2MessageIndex, uint16 l2TxNumberInBatch, bytes memory message, bytes32[] memory merkleProof) public",
"function saveL1Address() public"
"function saveL1Address() public",
"function fundChainGovernor() public"
])
.unwrap(),
);
Expand All @@ -60,7 +73,7 @@ fn find_latest_json_file(directory: &str) -> Option<PathBuf> {
})
}

pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
pub async fn run(args: DeployAndBridgeZKArgs, shell: &Shell) -> anyhow::Result<()> {
// Setup
let ecosystem_config = EcosystemConfig::from_file(shell)?;

Expand Down Expand Up @@ -101,9 +114,25 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {
.for_network(L2::from(L2ChainId(chain_config.chain_id.0)))
.build();

if args.only_funding_tx {
let _hash = call_script(
shell,
args.forge_args.clone(),
&DEPLOY_AND_BRIDGE_ZK_TOKEN_INTERFACE
.encode("fundChainGovernor", ())
.unwrap(),
&ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
l1_url.clone(),
)
.await?;

return Ok(());
}

let _hash = call_script(
shell,
args.clone(),
args.forge_args.clone(),
&DEPLOY_AND_BRIDGE_ZK_TOKEN_INTERFACE
.encode(
"supplyEraWallet",
Expand All @@ -130,7 +159,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {

let _tx_hash = call_script_era(
shell,
args.clone(),
args.forge_args.clone(),
&calldata,
&ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
Expand Down Expand Up @@ -183,7 +212,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {

let _tx_hash = call_script(
shell,
args.clone(),
args.forge_args.clone(),
&calldata,
&ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
Expand All @@ -199,7 +228,7 @@ pub async fn run(args: ForgeScriptArgs, shell: &Shell) -> anyhow::Result<()> {

let _tx_hash = call_script(
shell,
args,
args.forge_args,
&calldata,
&ecosystem_config,
chain_config.get_wallets_config()?.governor_private_key(),
Expand Down
3 changes: 2 additions & 1 deletion zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use args::build_transactions::BuildTransactionsArgs;
pub(crate) use args::create::ChainCreateArgsFinal;
use clap::Subcommand;
pub(crate) use create::create_chain_inner;
use deploy_and_bridge_zk::DeployAndBridgeZKArgs;
use migrate_from_gateway::MigrateFromGatewayArgs;
use migrate_to_gateway::MigrateToGatewayArgs;
use xshell::Shell;
Expand Down Expand Up @@ -60,7 +61,7 @@ pub enum ChainCommands {
/// Migrate chain from gateway
MigrateFromGateway(MigrateFromGatewayArgs),
/// Deploy ZK token on Era and bridge it to L1
DeployAndBridgeZK(ForgeScriptArgs),
DeployAndBridgeZK(DeployAndBridgeZKArgs),
}

pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<()> {
Expand Down

0 comments on commit a4c1d90

Please sign in to comment.