-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path02-arb-to-gnosis-inbox.ts
97 lines (79 loc) · 2.91 KB
/
02-arb-to-gnosis-inbox.ts
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
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import getContractAddress from "../../deploy-helpers/getContractAddress";
import { ethers } from "hardhat";
enum SenderChains {
ARBITRUM = 42161,
ARBITRUM_SEPOLIA = 421614,
HARDHAT = 31337,
}
const paramsByChainId = {
ARBITRUM: {
epochPeriod: 3600, // 1 hours
},
ARBITRUM_SEPOLIA: {
epochPeriod: 3600, // 1 hours
},
HARDHAT: {
epochPeriod: 600, // 10 minutes
},
};
const deployInbox: DeployFunction = async (hre: HardhatRuntimeEnvironment) => {
const { ethers, deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;
// fallback to hardhat node signers on local network
const [namedAccounts, signers, rawChainId] = await Promise.all([
getNamedAccounts(),
hre.ethers.getSigners(),
getChainId(),
]);
const deployer = namedAccounts.deployer ?? signers[0].address;
const chainId = Number(rawChainId);
console.log("deploying to chainId %s with deployer %s", chainId, deployer);
const { epochPeriod } = paramsByChainId[SenderChains[chainId]];
// Hack to predict the deployment address on the sender chain.
// TODO: use deterministic deployments
// ----------------------------------------------------------------------------------------------
const hardhatDeployer = async () => {
let nonce = await ethers.provider.getTransactionCount(deployer);
const arbitrumBridgeAddress = getContractAddress(deployer, nonce + 5);
const arbSysMock = await deploy("ArbSysMock", {
from: deployer,
contract: "ArbSysMockWithBridge",
args: [arbitrumBridgeAddress],
log: true,
});
const routerAddress = getContractAddress(deployer, nonce + 6);
console.log("calculated future router for nonce %d: %s", nonce + 6, routerAddress);
const receiverGateway = await deployments.get("ArbToGnosisReceiverGateway");
const veaInbox = await deploy("VeaInboxArbToGnosis", {
from: deployer,
contract: "VeaInboxArbToGnosisMock",
args: [epochPeriod, routerAddress, arbSysMock.address],
log: true,
});
await deploy("ArbToGnosisSenderGateway", {
from: deployer,
contract: "SenderGatewayMock",
args: [veaInbox.address, receiverGateway.address],
gasLimit: 4000000,
log: true,
});
};
// ----------------------------------------------------------------------------------------------
const liveDeployer = async () => {};
// ----------------------------------------------------------------------------------------------
if (chainId === 31337) {
await hardhatDeployer();
} else {
await liveDeployer();
}
};
deployInbox.tags = ["ArbToGnosisInbox"];
deployInbox.skip = async ({ getChainId }) => {
const chainId = Number(await getChainId());
console.log(chainId);
return !SenderChains[chainId];
};
deployInbox.runAtTheEnd = true;
export default deployInbox;