-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathwallet.rs
704 lines (626 loc) · 24.1 KB
/
wallet.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
use super::ZKSWalletError;
use super::{
requests::transfer_request::TransferRequest, DeployRequest, DepositRequest, WithdrawRequest,
};
use crate::zks_utils::{
DEFAULT_ERC20_DEPOSIT_GAS_LIMIT, DEPOSIT_GAS_PER_PUBDATA_LIMIT, ERA_MAINNET_CHAIN_ID,
};
use crate::{
abi,
contracts::main_contract::{MainContract, MainContractInstance},
eip712::Eip712Transaction,
eip712::{hash_bytecode, Eip712Meta, Eip712TransactionRequest},
types::TransactionReceipt,
zks_provider::ZKSProvider,
zks_utils::{self, CONTRACT_DEPLOYER_ADDR, EIP712_TX_TYPE, ETHER_L1_ADDRESS, ETH_CHAIN_ID},
};
use ethers::{
abi::{decode, Abi, ParamType, Tokenizable},
prelude::{
encode_function_data,
k256::{
ecdsa::{RecoveryId, Signature as RecoverableSignature},
schnorr::signature::hazmat::PrehashSigner,
},
MiddlewareBuilder, SignerMiddleware,
},
providers::Middleware,
signers::{Signer, Wallet},
types::{
transaction::eip2718::TypedTransaction, Address, Bytes, Eip1559TransactionRequest, Log,
Signature, H160, H256, U256,
},
};
use lazy_static::lazy_static;
use serde_json::{Map, Value};
use std::collections::HashMap;
use std::{fs::File, io::BufReader, path::PathBuf, str::FromStr, sync::Arc};
use zksync_web3_rs::core::abi::Tokenize;
const RAW_ERC20_DEPOSIT_GAS_LIMIT: &str = include_str!("DepositERC20GasLimit.json");
lazy_static! {
static ref ERC20_DEPOSIT_GAS_LIMITS: HashMap<String, u64> = {
#![allow(clippy::expect_used)]
let mut m = HashMap::new();
let raw: Map<String, Value> = serde_json::from_str(RAW_ERC20_DEPOSIT_GAS_LIMIT)
.expect("Failed to parse DepositERC20GasLimit.json");
for (address, value) in raw.iter() {
m.insert(
address.to_owned(),
value
.as_u64()
.expect("Failed to ERC20 deposit gas limit for address {address:?}"),
);
}
m
};
}
#[derive(Clone, Debug)]
pub struct ZKSWallet<M, D>
where
M: Middleware + Clone,
D: PrehashSigner<(RecoverableSignature, RecoveryId)> + Clone,
{
/// Eth provider
pub eth_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>,
pub era_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>,
pub l2_wallet: Wallet<D>,
pub l1_wallet: Wallet<D>,
}
impl<M, D> ZKSWallet<M, D>
where
M: Middleware + 'static + Clone,
D: PrehashSigner<(RecoverableSignature, RecoveryId)> + Sync + Send + Clone,
{
pub fn new(
l2_wallet: Wallet<D>,
l1_wallet: Option<Wallet<D>>,
era_provider: Option<M>,
eth_provider: Option<M>,
) -> Result<Self, ZKSWalletError<M, D>> {
let l1_wallet = match l1_wallet {
Some(wallet) => wallet,
None => l2_wallet.clone().with_chain_id(ETH_CHAIN_ID),
};
Ok(Self {
l2_wallet: l2_wallet.clone(),
l1_wallet: l1_wallet.clone(),
era_provider: era_provider.map(|p| p.with_signer(l2_wallet).into()),
eth_provider: eth_provider.map(|p| p.with_signer(l1_wallet).into()),
})
}
pub fn connect_eth_provider(mut self, eth_provider: M) -> Self {
self.eth_provider = Some(eth_provider.with_signer(self.l1_wallet.clone()).into());
self
}
pub fn connect_era_provider(mut self, era_provider: M) -> Self {
self.era_provider = Some(era_provider.with_signer(self.l2_wallet.clone()).into());
self
}
pub fn connect_eth_signer(mut self, eth_signer: SignerMiddleware<M, Wallet<D>>) -> Self {
self.eth_provider = Some(eth_signer.into());
self
}
pub fn connect_era_signer(mut self, era_signer: SignerMiddleware<M, Wallet<D>>) -> Self {
self.era_provider = Some(era_signer.into());
self
}
// pub fn connect_eth(&mut self, host: &str, port: u16) {
// self.eth_provider = Provider::try_from(format!("http://{host}:{port}")).ok().map(|p| p.with_signer(self.wallet));
// }
// pub fn connect_era(&mut self, host: &str, port: u16) {
// self.era_provider = Provider::try_from(format!("http://{host}:{port}")).ok().map(|p| p.with_signer(self.wallet));
// }
pub fn l2_address(&self) -> Address {
self.l2_wallet.address()
}
pub fn l1_address(&self) -> Address {
self.l1_wallet.address()
}
pub fn l2_chain_id(&self) -> u64 {
self.l2_wallet.chain_id()
}
pub fn l1_chain_id(&self) -> u64 {
self.l1_wallet.chain_id()
}
pub fn get_eth_provider(
&self,
) -> Result<Arc<SignerMiddleware<M, Wallet<D>>>, ZKSWalletError<M, D>> {
match &self.eth_provider {
Some(eth_provider) => Ok(Arc::clone(eth_provider)),
None => Err(ZKSWalletError::NoL1ProviderError()),
}
}
pub fn get_era_provider(
&self,
) -> Result<Arc<SignerMiddleware<M, Wallet<D>>>, ZKSWalletError<M, D>> {
match &self.era_provider {
Some(era_provider) => Ok(Arc::clone(era_provider)),
None => Err(ZKSWalletError::NoL2ProviderError()),
}
}
pub async fn eth_balance(&self) -> Result<U256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
match &self.eth_provider {
// TODO: Should we have a balance_on_block method?
Some(eth_provider) => Ok(eth_provider.get_balance(self.l1_address(), None).await?),
None => Err(ZKSWalletError::CustomError("no eth provider".to_owned())),
}
}
pub async fn era_balance(&self) -> Result<U256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
match &self.era_provider {
// TODO: Should we have a balance_on_block method?
Some(era_provider) => Ok(era_provider.get_balance(self.l2_address(), None).await?),
None => Err(ZKSWalletError::CustomError("no era provider".to_owned())),
}
}
pub async fn transfer(
&self,
request: &TransferRequest,
// TODO: Support multiple-token transfers.
_token: Option<Address>,
) -> Result<H256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let era_provider = self.get_era_provider()?;
let mut transfer_request: Eip1559TransactionRequest = request.clone().into();
let fee = era_provider.estimate_fee(transfer_request.clone()).await?;
transfer_request = transfer_request.max_priority_fee_per_gas(fee.max_priority_fee_per_gas);
transfer_request = transfer_request.max_fee_per_gas(fee.max_fee_per_gas);
let transaction: TypedTransaction = transfer_request.into();
// TODO: add block as an override.
let transaction_receipt = era_provider
.send_transaction(transaction, None)
.await?
.await?
.ok_or(ZKSWalletError::CustomError(
"No transaction receipt".to_owned(),
))?;
Ok(transaction_receipt.transaction_hash)
}
pub async fn transfer_eip712(
&self,
request: &TransferRequest,
// TODO: Support multiple-token transfers.
_token: Option<Address>,
) -> Result<H256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let era_provider = self.get_era_provider()?;
let transaction_receipt = era_provider
.send_transaction_eip712(&self.l2_wallet, request.clone())
.await?
.await?
.ok_or(ZKSWalletError::CustomError(
"No transaction receipt".to_owned(),
))?;
Ok(transaction_receipt.transaction_hash)
}
pub async fn deposit(&self, request: &DepositRequest) -> Result<H256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let to = request.to.unwrap_or(self.l2_address());
let call_data = Bytes::default();
let l2_gas_limit: U256 = request.l2_gas_limit;
let l2_value = request.amount;
let gas_per_pubdata_byte: U256 = request.gas_per_pubdata_byte;
let gas_price = request
.gas_price
.unwrap_or(self.get_eth_provider()?.get_gas_price().await?);
let gas_limit: U256 = request.gas_limit;
let operator_tip: U256 = request.operator_tip;
let base_cost = self
.get_base_cost(gas_limit, gas_per_pubdata_byte, gas_price)
.await?;
let l1_value = base_cost + operator_tip + request.amount;
// let factory_deps = [];
let refund_recipient = self.l1_address();
// FIXME check base cost
let receipt = if request.token == ETHER_L1_ADDRESS {
let main_contract_address = self.get_era_provider()?.get_main_contract().await?;
let main_contract =
MainContractInstance::new(main_contract_address, self.get_eth_provider()?);
main_contract
.request_l2_transaction(
to,
l2_value,
call_data,
l2_gas_limit,
gas_per_pubdata_byte,
Default::default(),
refund_recipient,
gas_price,
gas_limit,
l1_value,
)
.await?
} else {
self.deposit_erc20_token(
request.token,
request.amount().to_owned(),
to,
operator_tip,
request.bridge_address,
None,
Some(gas_price),
)
.await?
};
Ok(receipt.transaction_hash)
}
async fn deposit_erc20_token(
&self,
l1_token_address: Address,
amount: U256,
to: Address,
operator_tip: U256,
bridge_address: Option<Address>,
max_fee_per_gas: Option<U256>,
gas_price: Option<U256>,
) -> Result<TransactionReceipt, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let eth_provider = self.get_eth_provider()?;
let era_provider = self.get_era_provider()?;
let gas_limit: U256 = {
let address_str = format!("{l1_token_address:?}");
let is_mainnet =
self.get_era_provider()?.get_chainid().await? == ERA_MAINNET_CHAIN_ID.into();
if is_mainnet {
(*ERC20_DEPOSIT_GAS_LIMITS)
.get(&address_str)
.unwrap_or(&DEFAULT_ERC20_DEPOSIT_GAS_LIMIT)
.to_owned()
} else {
DEFAULT_ERC20_DEPOSIT_GAS_LIMIT
}
}
.into();
// If the user has already provided max_fee_per_gas or gas_price, we will use
// it to calculate the base cost for the transaction
let gas_price = if let Some(max_fee_per_gas) = max_fee_per_gas {
max_fee_per_gas
} else if let Some(gas_price) = gas_price {
gas_price
} else {
era_provider.get_gas_price().await?
};
let l2_gas_limit = U256::from(3_000_000_u32);
let base_cost: U256 = self
.get_base_cost(
l2_gas_limit,
DEPOSIT_GAS_PER_PUBDATA_LIMIT.into(),
gas_price,
)
.await?;
// ERC20 token, `msg.value` is used only for the fee.
let value = base_cost + operator_tip;
let data: Bytes = {
let bridge_contract = abi::l1_bridge_contract();
#[allow(clippy::expect_used)]
let contract_function = bridge_contract
.function("deposit")
.expect("failed to get deposit function parameters");
let params = (
to,
l1_token_address,
amount,
l2_gas_limit,
U256::from(DEPOSIT_GAS_PER_PUBDATA_LIMIT),
);
#[allow(clippy::expect_used)]
contract_function
.encode_input(¶ms.into_tokens())
.expect("failed to encode deposit function parameters")
.into()
};
let chain_id = eth_provider.get_chainid().await?.as_u64();
let bridge_address: Address = match bridge_address {
Some(address) => address,
None => {
let bridge_contracts = era_provider.get_bridge_contracts().await?;
bridge_contracts.l1_erc20_default_bridge
}
};
let deposit_transaction = Eip1559TransactionRequest {
from: Some(self.get_eth_provider()?.address()),
to: Some(bridge_address.into()),
gas: Some(gas_limit),
value: Some(value),
data: Some(data),
nonce: None,
access_list: Default::default(),
max_priority_fee_per_gas: None, // FIXME
max_fee_per_gas: None, // FIXME
chain_id: Some(chain_id.into()),
};
let _approve_tx_receipt = self
.approve_erc20(bridge_address, amount, l1_token_address)
.await?;
let pending_transaction = eth_provider
.send_transaction(deposit_transaction, None)
.await?;
pending_transaction
.await?
.ok_or(ZKSWalletError::CustomError(
"no transaction receipt".to_owned(),
))
}
async fn approve_erc20(
&self,
bridge: Address,
amount: U256,
token: Address,
) -> Result<TransactionReceipt, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let provider = self.get_eth_provider()?;
let function_signature =
"function approve(address spender,uint256 amount) public virtual returns (bool)";
let parameters = [format!("{bridge:?}"), format!("{amount:?}")];
let response = provider
.send(
&self.l1_wallet,
token,
function_signature,
Some(parameters.into()),
None,
)
.await?;
response.await?.ok_or(ZKSWalletError::CustomError(
"No transaction receipt for erc20 approval".to_owned(),
))
}
async fn get_base_cost(
&self,
gas_limit: U256,
gas_per_pubdata_byte: U256,
gas_price: U256,
) -> Result<U256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let main_contract_address = self.get_era_provider()?.get_main_contract().await?;
let main_contract = MainContract::new(main_contract_address, self.get_eth_provider()?);
let base_cost: U256 = main_contract
.l_2_transaction_base_cost(gas_price, gas_limit, gas_per_pubdata_byte)
.call()
.await?;
Ok(base_cost)
}
pub async fn deploy_from_bytecode<T>(
&self,
contract_bytecode: &[u8],
contract_dependencies: Option<Vec<Vec<u8>>>,
// TODO: accept constructor parameters.
_constructor_parameters: Option<T>,
) -> Result<H160, ZKSWalletError<M, D>>
where
M: ZKSProvider,
T: Tokenizable,
{
let era_provider = self.get_era_provider()?;
let custom_data = Eip712Meta::new().factory_deps({
let mut factory_deps = Vec::new();
if let Some(contract_dependencies) = contract_dependencies {
factory_deps.extend(contract_dependencies);
}
factory_deps.push(contract_bytecode.to_vec());
factory_deps
});
let mut contract_deployer_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
contract_deployer_path.push("src/abi/ContractDeployer.json");
let mut deploy_request = Eip712TransactionRequest::new()
.r#type(EIP712_TX_TYPE)
.from(self.l2_address())
.to(Address::from_str(CONTRACT_DEPLOYER_ADDR).map_err(|e| {
ZKSWalletError::CustomError(format!("invalid contract deployer address: {e}"))
})?)
.chain_id(self.l2_chain_id())
.nonce(
era_provider
.get_transaction_count(self.l2_address(), None)
.await?,
)
.gas_price(era_provider.get_gas_price().await?)
.max_fee_per_gas(era_provider.get_gas_price().await?)
.data({
let contract_deployer = Abi::load(BufReader::new(
File::open(contract_deployer_path).map_err(|e| {
ZKSWalletError::CustomError(format!(
"failed to open ContractDeployer abi: {e}"
))
})?,
))
.map_err(|e| {
ZKSWalletError::CustomError(format!("failed to load ContractDeployer abi: {e}"))
})?;
let create = contract_deployer.function("create").map_err(|e| {
ZKSWalletError::CustomError(format!("failed to get create function: {e}"))
})?;
// TODO: User could provide this instead of defaulting.
let salt = [0_u8; 32];
let bytecode_hash = hash_bytecode(contract_bytecode)?;
let call_data = Bytes::default();
encode_function_data(create, (salt, bytecode_hash, call_data))?
})
.custom_data(custom_data.clone());
let fee = era_provider.estimate_fee(deploy_request.clone()).await?;
deploy_request = deploy_request
.max_priority_fee_per_gas(fee.max_priority_fee_per_gas)
.max_fee_per_gas(fee.max_fee_per_gas)
.gas_limit(fee.gas_limit);
let signable_data: Eip712Transaction = deploy_request.clone().try_into()?;
let signature: Signature = self.l2_wallet.sign_typed_data(&signable_data).await?;
deploy_request =
deploy_request.custom_data(custom_data.custom_signature(signature.to_vec()));
let encoded_rlp = &*deploy_request.rlp_signed(signature)?;
let pending_transaction = era_provider
.send_raw_transaction([&[EIP712_TX_TYPE], encoded_rlp].concat().into())
.await?;
// TODO: Should we wait here for the transaction to be confirmed on-chain?
let transaction_receipt = pending_transaction
.await?
.ok_or(ZKSWalletError::CustomError(
"no transaction receipt".to_owned(),
))?;
let contract_address =
transaction_receipt
.contract_address
.ok_or(ZKSWalletError::CustomError(
"no contract address".to_owned(),
))?;
Ok(contract_address)
}
pub async fn deploy(&self, request: &DeployRequest) -> Result<H160, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let era_provider = self.get_era_provider()?;
let eip712_request: Eip712TransactionRequest = request.clone().try_into()?;
let transaction_receipt = era_provider
.send_transaction_eip712(&self.l2_wallet, eip712_request)
.await?
.await?
.ok_or(ZKSWalletError::CustomError(
"No transaction receipt".to_owned(),
))?;
transaction_receipt
.contract_address
.ok_or(ZKSWalletError::CustomError(
"No contract address".to_owned(),
))
}
pub async fn withdraw(&self, request: &WithdrawRequest) -> Result<H256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let era_provider = self.get_era_provider()?;
let transaction_receipt = era_provider
.send_transaction_eip712(&self.l2_wallet, request.clone())
.await?
.await?
.ok_or(ZKSWalletError::CustomError(
"No transaction receipt".to_owned(),
))?;
Ok(transaction_receipt.transaction_hash)
}
pub async fn finalize_withdraw(&self, tx_hash: H256) -> Result<H256, ZKSWalletError<M, D>>
where
M: ZKSProvider,
{
let era_provider = self.get_era_provider()?;
let eth_provider = self.get_eth_provider()?;
let withdrawal_receipt = era_provider.get_transaction_receipt(tx_hash).await?.ok_or(
ZKSWalletError::CustomError("Error getting transaction receipt of withdraw".to_owned()),
)?;
let messenger_contract_address = Address::from_str(zks_utils::CONTRACTS_L1_MESSENGER_ADDR)
.map_err(|error| {
ZKSWalletError::CustomError(format!("failed to parse contract address: {error}"))
})?;
let logs: Vec<Log> = withdrawal_receipt
.logs
.into_iter()
.filter(|log| {
//log.topics[0] == topic &&
log.address == messenger_contract_address
})
.collect();
// Get all the parameters needed to call the finalizeWithdrawal function on the main contract contract.
let (_, l2_to_l1_log_index) = serde_json::from_value::<Vec<Value>>(
withdrawal_receipt
.other
.get("l2ToL1Logs")
.ok_or(ZKSWalletError::CustomError(
"Field not present in receipt".to_owned(),
))?
.clone(),
)
.map_err(|err| {
ZKSWalletError::CustomError(format!("Error getting logs in receipt: {err:?}"))
})?
.iter()
.zip(0_u64..)
.find(|(log, _)| {
if let Some(sender) = log.get("sender") {
sender == zks_utils::CONTRACTS_L1_MESSENGER_ADDR
} else {
false
}
})
.ok_or(ZKSWalletError::CustomError(
"Error getting log index parameter".to_owned(),
))?;
let filtered_log = logs
.get(0)
.ok_or(ZKSWalletError::CustomError(
"Error getting log in receipt".to_owned(),
))?
.clone();
let proof = era_provider
.get_l2_to_l1_log_proof(tx_hash, Some(l2_to_l1_log_index))
.await?
.ok_or(ZKSWalletError::CustomError(
"Error getting proof parameter".to_owned(),
))?;
let main_contract = era_provider.get_main_contract().await?;
let merkle_proof: Vec<H256> = proof.merkle_proof;
let l1_batch_number = era_provider.get_l1_batch_number().await?;
let l2_message_index = U256::from(proof.id);
let l2_tx_number_in_block: String = serde_json::from_value::<String>(
withdrawal_receipt
.other
.get("l1BatchTxIndex")
.ok_or(ZKSWalletError::CustomError(
"Field not present in receipt".to_owned(),
))?
.clone(),
)
.map_err(|err| ZKSWalletError::CustomError(format!("Failed to deserialize field {err}")))?;
let message: Bytes = decode(&[ParamType::Bytes], &filtered_log.data)
.map_err(|e| ZKSWalletError::CustomError(format!("failed to decode log data: {e}")))?
.get(0)
.ok_or(ZKSWalletError::CustomError(
"Message not found in decoded data".to_owned(),
))?
.clone()
.into_bytes()
.ok_or(ZKSWalletError::CustomError(
"Could not convert message to bytes".to_owned(),
))?
.into();
let parameters = [
format!("{l1_batch_number:?}"),
format!("{l2_message_index:?}"),
l2_tx_number_in_block,
hex::encode(&message),
format!("{merkle_proof:?}")
.replace('"', "")
.replace(' ', ""),
];
let function_signature = "function finalizeEthWithdrawal(uint256 _l2BlockNumber,uint256 _l2MessageIndex,uint16 _l2TxNumberInBlock,bytes calldata _message,bytes32[] calldata _merkleProof) external";
let transaction_receipt = eth_provider
.send(
&self.l1_wallet,
main_contract,
function_signature,
Some(parameters.into()),
None,
)
.await?
.await?
.ok_or(ZKSWalletError::CustomError(
"No transaction receipt".to_owned(),
))?;
Ok(transaction_receipt.transaction_hash)
}
}