-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathUnlockVaultFromL1.s.sol
More file actions
56 lines (47 loc) · 1.89 KB
/
UnlockVaultFromL1.s.sol
File metadata and controls
56 lines (47 loc) · 1.89 KB
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import "forge-std/src/Script.sol";
import "forge-std/src/console.sol";
import "../src/AccessKey.sol";
import "@zksync-contracts/l1-contracts/bridgehub/IBridgehub.sol";
interface IVault {
function unlock() external;
}
/// @title UnlockVaultFromL1
/// @notice This script unlocks the vault on L2 by sending a cross-chain message from L1
/// @dev The script uses the AccessKey contract to send the message to the BridgeHub
/// @dev Should not be used in production
contract UnlockVaultFromL1 is Script {
function run() external {
// Load env vars
address accessKeyAddress = vm.envAddress("ACCESS_KEY_ADDRESS");
address vaultAddress = vm.envAddress("VAULT_ADDRESS");
address bridgeHubAddress = vm.envAddress("BRIDGE_HUB_ADDRESS");
uint256 chainId = vm.envUint("L2_CHAIN_ID");
uint256 gasLimit = vm.envOr("L2_GAS_LIMIT", uint256(350_000));
uint256 gasPerPubdataByteLimit = vm.envOr("L2_PUBDATA_BYTE_LIMIT", uint256(800));
vm.startBroadcast();
// Encode the calldata for the L2 vault's unlock() function
bytes memory unlockData = abi.encodeWithSelector(IVault.unlock.selector);
// Get base cost from the BridgeHub contract
IBridgehub bridge = IBridgehub(bridgeHubAddress);
uint256 gasPrice = tx.gasprice;
uint256 baseCost = bridge.l2TransactionBaseCost(
chainId,
gasPrice,
gasLimit,
gasPerPubdataByteLimit
);
// Call AccessKey to send the cross-chain message
AccessKey(accessKeyAddress).unlockVaultOnL2{ value: baseCost }(
chainId,
bridgeHubAddress,
vaultAddress,
unlockData,
gasLimit,
gasPerPubdataByteLimit,
baseCost
);
vm.stopBroadcast();
}
}