-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d724465
commit 68bf194
Showing
7 changed files
with
405 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use alloy::{ | ||
network::EthereumWallet, | ||
primitives::{address, U256}, | ||
providers::ProviderBuilder, | ||
signers::local::PrivateKeySigner, | ||
}; | ||
use alloy_zksync::{ | ||
provider::{zksync_provider, ZksyncProviderWithWallet, ETHER_L1_ADDRESS}, | ||
wallet::ZksyncWallet, | ||
}; | ||
use anyhow::Result; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
// standard RPC urls for the L1 and L2 local nodes spun up by ZKSync CLI: | ||
// More general info on the local setup can be found here: | ||
// https://docs.zksync.io/zksync-era/tooling/local-setup/dockerized-l1-l2-nodes | ||
// and how to spin it up locally: | ||
// https://docs.zksync.io/zksync-era/tooling/zksync-cli/running-a-node | ||
let l1_rpc_url = "http://127.0.0.1:8545".parse()?; | ||
let l2_rpc_url = "http://127.0.0.1:3050".parse()?; | ||
// one of the test rich wallets created by the local setup | ||
// https://github.com/matter-labs/local-setup/blob/main/rich-wallets.json | ||
let signer: PrivateKeySigner = | ||
"0x7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110" | ||
.parse() | ||
.expect("should parse private key"); | ||
let wallet = EthereumWallet::from(signer.clone()); | ||
|
||
let l1_provider = ProviderBuilder::new() | ||
.with_recommended_fillers() | ||
.wallet(wallet) | ||
.on_http(l1_rpc_url); | ||
|
||
let zksync_wallet: ZksyncWallet = ZksyncWallet::from(signer.clone()); | ||
let zksync_provider = zksync_provider() | ||
.with_recommended_fillers() | ||
.wallet(zksync_wallet) | ||
.on_http(l2_rpc_url); | ||
|
||
// use another test rich wallet as a receiver | ||
// https://github.com/matter-labs/local-setup/blob/main/rich-wallets.json | ||
let receiver = address!("a61464658AfeAf65CccaaFD3a512b69A83B77618"); | ||
// 0.00007 ETH | ||
let deposit_amount = U256::from(70000000000000_u64); | ||
let l1_token_address = ETHER_L1_ADDRESS; | ||
let deposit_l1_receipt = zksync_provider | ||
.deposit(l1_token_address, receiver, deposit_amount, &l1_provider) | ||
.await | ||
.unwrap(); | ||
|
||
let deposit_l2_receipt = deposit_l1_receipt | ||
.get_l2_tx()? | ||
.with_required_confirmations(1) | ||
.with_timeout(Some(std::time::Duration::from_secs(60 * 5))) | ||
.get_receipt() | ||
.await?; | ||
|
||
println!("L2 deposit transaction receipt: {:#?}", deposit_l2_receipt); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
alloy::sol! { | ||
#[allow(missing_docs)] | ||
struct L2TransactionRequestDirect { | ||
uint256 chainId; | ||
uint256 mintValue; | ||
address l2Contract; | ||
uint256 l2Value; | ||
bytes l2Calldata; | ||
uint256 l2GasLimit; | ||
uint256 l2GasPerPubdataByteLimit; | ||
bytes[] factoryDeps; | ||
address refundRecipient; | ||
} | ||
|
||
#[allow(missing_docs)] | ||
struct L2CanonicalTransaction { | ||
uint256 txType; | ||
uint256 from; | ||
uint256 to; | ||
uint256 gasLimit; | ||
uint256 gasPerPubdataByteLimit; | ||
uint256 maxFeePerGas; | ||
uint256 maxPriorityFeePerGas; | ||
uint256 paymaster; | ||
uint256 nonce; | ||
uint256 value; | ||
uint256[4] reserved; | ||
bytes data; | ||
bytes signature; | ||
uint256[] factoryDeps; | ||
bytes paymasterInput; | ||
bytes reservedDynamic; | ||
} | ||
|
||
#[allow(missing_docs)] | ||
#[sol(rpc)] | ||
contract Bridgehub { | ||
function requestL2TransactionDirect( | ||
L2TransactionRequestDirect memory request | ||
) external payable returns (bytes32 canonicalTxHash); | ||
|
||
function l2TransactionBaseCost( | ||
uint256 _chainId, | ||
uint256 _gasPrice, | ||
uint256 _l2GasLimit, | ||
uint256 _l2GasPerPubdataByteLimit | ||
) external view returns (uint256); | ||
|
||
event NewPriorityRequest( | ||
uint256 txId, | ||
bytes32 txHash, | ||
uint64 expirationTimestamp, | ||
L2CanonicalTransaction transaction, | ||
bytes[] factoryDeps | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod bridge_hub; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod l1; | ||
pub mod l2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.