-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelpers.js
More file actions
64 lines (58 loc) · 2.1 KB
/
helpers.js
File metadata and controls
64 lines (58 loc) · 2.1 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
57
58
59
60
61
62
63
64
const hre = require("hardhat");
const fs = require("fs");
const { ethers } = hre;
const deploymentAddress = require("../deployment/deploymentAddresses.json");
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async function verify(address, args) {
if (hre.network.name !== "hardhat" && hre.network.name !== "localhost") {
let retry = 20;
console.log("Sleeping before verification...");
while ((await ethers.provider.getCode(address).catch((err) => console.log("err", err))).length <= 3 && retry >= 0) {
await sleep(5000);
--retry;
}
console.log(address);
await hre
.run("verify:verify", {
address,
})
.catch(() => console.log("Verification failed"));
}
}
function getAddressSaver(path, network, isLog) {
const addresses = require(path);
if (!addresses[network]) {
addresses[network] = {};
}
if (!addresses[network].old) {
addresses[network].old = {};
}
if (!addresses[network].new) {
addresses[network].new = {};
}
function saveAddress(contractName, address, isNewMigration) {
if (isNewMigration) {
addresses[network].old = addresses[network].new;
addresses[network].new = {};
}
addresses[network].new[contractName] = address;
if (isLog) console.log(`${contractName} deployed to ${address}`);
fs.writeFileSync(path, JSON.stringify(addresses, null, 4));
return addresses[network].new;
}
return saveAddress;
}
async function getBridgeContract() {
console.log("Connecting with bridge...");
const network = (await ethers.getDefaultProvider().getNetwork()).name;
const bridgeAddress = deploymentAddress[network].new.bridge;
const bridge = await ethers.getContractAt("/contracts/EthErc20FastBridge.sol:EthErc20FastBridge", bridgeAddress);
console.log("Connected!");
return bridge;
}
exports.sleep = sleep;
exports.verify = verify;
exports.getAddressSaver = getAddressSaver;
exports.getBridgeContract = getBridgeContract;