Skip to content

Commit e0a38b2

Browse files
committed
fixes
1 parent 80adb73 commit e0a38b2

File tree

2 files changed

+41
-63
lines changed

2 files changed

+41
-63
lines changed

zkstack_cli/crates/zkstack/src/abi.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ abigen!(
1212
function chainTypeManager(uint256)(address)
1313
function chainAssetHandler() external view returns (address)
1414
function owner()(address)
15+
function messageRoot()(address)
16+
]"
17+
);
18+
19+
abigen!(
20+
MessageRootAbi,
21+
r"[
22+
function getProofData(uint256,uint256,uint256,bytes32,bytes32[]) view returns (tuple(uint256 settlementLayerChainId,uint256 settlementLayerBatchNumber,uint256 settlementLayerBatchRootMask,uint256 batchLeafProofLen,bytes32 batchSettlementRoot,bytes32 chainIdLeaf,uint256 ptr,bool finalProofNode))
1523
]"
1624
);
1725

zkstack_cli/crates/zkstack/src/commands/chain/gateway/migrate_token_balances.rs

Lines changed: 33 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use zksync_system_constants::{
3838
use zksync_types::{L2ChainId, H256};
3939

4040
use crate::{
41+
abi::{BridgehubAbi, MessageRootAbi, ZkChainAbi},
4142
commands::dev::commands::{rich_account, rich_account::args::RichAccountArgs},
4243
messages::MSG_CHAIN_NOT_INITIALIZED,
4344
utils::forge::{fill_forge_private_key, WalletOwner},
@@ -51,21 +52,6 @@ lazy_static! {
5152
])
5253
.unwrap(),
5354
);
54-
static ref MESSAGE_ROOT_ABI: BaseContract = BaseContract::from(
55-
parse_abi(&[
56-
"function getProofData(uint256,uint256,uint256,bytes32,bytes32[]) view returns (tuple(uint256 settlementLayerChainId,uint256 settlementLayerBatchNumber,uint256 settlementLayerBatchRootMask,uint256 batchLeafProofLen,bytes32 batchSettlementRoot,bytes32 chainIdLeaf,uint256 ptr,bool finalProofNode))"
57-
]).unwrap()
58-
);
59-
static ref BRIDGEHUB_ABI: BaseContract = BaseContract::from(
60-
parse_abi(&[
61-
"function getZKChain(uint256) view returns (address)"
62-
]).unwrap()
63-
);
64-
static ref GETTERS_ABI: BaseContract = BaseContract::from(
65-
parse_abi(&[
66-
"function getTotalBatchesExecuted() view returns (uint256)"
67-
]).unwrap()
68-
);
6955
}
7056

7157
#[derive(Debug, Serialize, Deserialize, Parser)]
@@ -213,15 +199,15 @@ pub async fn migrate_token_balances_from_gateway(
213199

214200
let mut tx_hashes = Vec::new();
215201
let mut asset_ids = Vec::new();
216-
let rpc_url = if to_gateway { &l2_rpc_url } else { &gw_rpc_url };
217-
let provider = Provider::<Http>::try_from(rpc_url.as_str())?;
218-
let chain_id = provider.get_chainid().await?.as_u64();
202+
let l2_provider = Provider::<Http>::try_from(l2_rpc_url.as_str())?;
203+
let l2_chain_id = l2_provider.get_chainid().await?.as_u64();
219204

220-
let signer = wallet.private_key.clone().unwrap().with_chain_id(chain_id);
221-
let client = Arc::new(SignerMiddleware::new(provider.clone(), signer));
222-
let mut next_nonce = client
223-
.get_transaction_count(wallet.address, Some(BlockId::Number(BlockNumber::Pending)))
224-
.await?;
205+
let l2_signer = wallet
206+
.private_key
207+
.clone()
208+
.unwrap()
209+
.with_chain_id(l2_chain_id);
210+
let l2_client = Arc::new(SignerMiddleware::new(l2_provider.clone(), l2_signer));
225211

226212
// Get bridged token count and asset IDs
227213
let ntv = Contract::new(
@@ -230,7 +216,7 @@ pub async fn migrate_token_balances_from_gateway(
230216
"function bridgedTokensCount() view returns (uint256)",
231217
"function bridgedTokens(uint256) view returns (bytes32)",
232218
])?,
233-
client.clone(),
219+
l2_client.clone(),
234220
);
235221
let count: U256 = ntv
236222
.method::<_, U256>("bridgedTokensCount", ())?
@@ -249,7 +235,7 @@ pub async fn migrate_token_balances_from_gateway(
249235
let router = Contract::new(
250236
L2_ASSET_ROUTER_ADDRESS,
251237
parse_abi(&["function BASE_TOKEN_ASSET_ID() view returns (bytes32)"])?,
252-
Arc::new(provider),
238+
l2_client.clone(),
253239
);
254240
let base_token_asset_id = router
255241
.method::<_, [u8; 32]>("BASE_TOKEN_ASSET_ID", ())?
@@ -270,6 +256,15 @@ pub async fn migrate_token_balances_from_gateway(
270256
)
271257
};
272258

259+
let rpc_url = if to_gateway { &l2_rpc_url } else { &gw_rpc_url };
260+
let provider = Provider::<Http>::try_from(rpc_url.as_str())?;
261+
let chain_id = provider.get_chainid().await?.as_u64();
262+
263+
let signer = wallet.private_key.clone().unwrap().with_chain_id(chain_id);
264+
let client = Arc::new(SignerMiddleware::new(provider.clone(), signer));
265+
let mut next_nonce = client
266+
.get_transaction_count(wallet.address, Some(BlockId::Number(BlockNumber::Pending)))
267+
.await?;
273268
let tracker = Contract::new(tracker_addr, parse_abi(&[method_sig])?, client);
274269

275270
// Send all initiate migration transactions
@@ -383,7 +378,7 @@ pub async fn migrate_token_balances_from_gateway(
383378
let tracker = Contract::new(
384379
L2_ASSET_TRACKER_ADDRESS,
385380
parse_abi(&["function tokenMigratedThisChain(bytes32) view returns (bool)"])?,
386-
Arc::new(Provider::<Http>::try_from(l2_rpc_url.as_str())?),
381+
l2_client.clone(),
387382
);
388383
for asset_id in asset_ids.iter().copied() {
389384
loop {
@@ -447,27 +442,9 @@ async fn wait_for_migration_ready(
447442
let l1_provider = get_ethers_provider(&l1_rpc_url)?;
448443
let zk_client = get_zk_client(l2_or_gw_rpc, source_chain_id)?;
449444

450-
let bridgehub = Contract::new(
451-
l1_bridgehub_addr,
452-
BRIDGEHUB_ABI.clone(),
453-
l1_provider.clone(),
454-
);
455-
let message_root_addr: Address = {
456-
let bridgehub_base = Contract::new(
457-
l1_bridgehub_addr,
458-
parse_abi(&["function messageRoot() view returns (address)"])?,
459-
l1_provider.clone(),
460-
);
461-
bridgehub_base
462-
.method::<_, Address>("messageRoot", ())?
463-
.call()
464-
.await?
465-
};
466-
let message_root = Contract::new(
467-
message_root_addr,
468-
MESSAGE_ROOT_ABI.clone(),
469-
l1_provider.clone(),
470-
);
445+
let bridgehub = BridgehubAbi::new(l1_bridgehub_addr, l1_provider.clone());
446+
let message_root_addr = bridgehub.message_root().call().await?;
447+
let message_root = MessageRootAbi::new(message_root_addr, l1_provider.clone());
471448

472449
let mut finalize_params = Vec::new();
473450
for tx_hash in tx_hashes {
@@ -498,18 +475,14 @@ async fn wait_for_migration_ready(
498475
continue;
499476
}
500477

501-
type ProofData = (U256, U256, U256, U256, H256, H256, U256, bool);
502478
let (settlement_chain_id, settlement_batch_number, ..) = message_root
503-
.method::<_, ProofData>(
504-
"getProofData",
505-
(
506-
U256::from(source_chain_id),
507-
U256::from(params.l2_batch_number.as_u64()),
508-
U256::from(params.l2_message_index.as_u64()),
509-
H256::zero(),
510-
params.proof.proof.clone(),
511-
),
512-
)?
479+
.get_proof_data(
480+
source_chain_id.into(),
481+
params.l2_batch_number.as_u64().into(),
482+
params.l2_message_index.as_u64().into(),
483+
H256::zero().into(),
484+
params.proof.proof.iter().map(|h| (*h).into()).collect(),
485+
)
513486
.call()
514487
.await?;
515488

@@ -529,13 +502,10 @@ async fn wait_for_migration_ready(
529502
.method("getZKChain", U256::from(chain_id))?
530503
.call()
531504
.await?;
532-
let getters = Contract::new(zk_chain_addr, GETTERS_ABI.clone(), l1_provider.clone());
505+
let getters = ZkChainAbi::new(zk_chain_addr, l1_provider.clone());
533506

534507
loop {
535-
let total_batches_executed: U256 = getters
536-
.method("getTotalBatchesExecuted", ())?
537-
.call()
538-
.await?;
508+
let total_batches_executed: U256 = getters.get_total_batches_executed().call().await?;
539509
if total_batches_executed >= U256::from(batch_number) {
540510
break;
541511
}

0 commit comments

Comments
 (0)