-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathdeploy_enterpriseescrow.js
More file actions
139 lines (131 loc) Β· 3.99 KB
/
deploy_enterpriseescrow.js
File metadata and controls
139 lines (131 loc) Β· 3.99 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
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
// We require the Hardhat Runtime Environment explicitly here. This is optional
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const fs = require("fs");
const { address } = require("../test/helpers/constants");
const { Wallet } = require("ethers");
const { UV_FS_O_FILEMAP } = require("constants");
const ethers = hre.ethers;
require("dotenv").config();
const logging = true;
const show_verify = true;
const shouldDeployMock20 = false;
async function main() {
const url = process.env.NETWORK_RPC_URL;
console.log("Using RPC: " + url);
if (!url) {
console.error("Missing NETWORK_RPC_URL. Aborting..");
return null;
}
if (!process.env.ADDRESS_FILE) {
console.error("Missing ADDRESS_FILE. Aborting..");
return null;
}
const provider = new ethers.providers.JsonRpcProvider(url);
const network = provider.getNetwork();
// utils
const networkDetails = await network;
let wallet;
if (process.env.MNEMONIC)
wallet = new Wallet.fromMnemonic(process.env.MNEMONIC);
if (process.env.PRIVATE_KEY) wallet = new Wallet(process.env.PRIVATE_KEY);
if (!wallet) {
console.error("Missing MNEMONIC or PRIVATE_KEY. Aborting..");
return null;
}
owner = wallet.connect(provider);
let gasLimit = 3000000;
let gasPrice = null;
let sleepAmount = 10;
let OPFOwner = null;
let RouterAddress = null;
console.log("Using chain " + networkDetails.chainId);
switch (networkDetails.chainId) {
case 1:
networkName = "mainnet";
gasLimit = 6500000;
gasPrice = ethers.utils.parseUnits("0.08", "gwei");
break;
case 10:
networkName = "optimism";
gasPrice = ethers.utils.parseUnits("0.001200495", "gwei");
gasLimit = 6500000;
break;
case 11155111:
networkName = "sepolia";
gasPrice = ethers.utils.parseUnits("5", "gwei");
gasLimit = 6500000;
break;
}
let options;
if (gasPrice) {
options = { gasLimit: gasLimit, gasPrice: gasPrice };
} else {
options = { gasLimit };
}
console.log("Deployer nonce:", await owner.getTransactionCount());
const addressFile = process.env.ADDRESS_FILE;
let oldAddresses;
if (addressFile) {
try {
oldAddresses = JSON.parse(fs.readFileSync(addressFile));
} catch (e) {
console.log(e);
oldAddresses = {};
}
if (!oldAddresses[networkName]) oldAddresses[networkName] = {};
addresses = oldAddresses[networkName];
}
if (logging)
console.info(
"Use existing addresses:" + JSON.stringify(addresses, null, 2)
);
if (!addresses.EnterpriseFeeCollector) {
console.error("Missing EnterpriseFeeCollector address. Aborting..");
return null;
}
if (logging) console.info("Deploying EnterpriseEscrow");
const Escrow = await ethers.getContractFactory("EnterpriseEscrow", owner);
const deployEscrow = await Escrow.connect(owner).deploy(
addresses.EnterpriseFeeCollector,
options
);
await deployEscrow.deployTransaction.wait(1);
if (show_verify) {
console.log("\tRun the following to verify on etherscan");
console.log(
"\tnpx hardhat verify --network " +
networkName +
" " +
deployEscrow.address +
" " +
addresses.EnterpriseFeeCollector
);
}
addresses.EnterpriseEscrow = deployEscrow.address;
if (addressFile) {
// write address.json if needed
oldAddresses[networkName] = addresses;
try {
fs.writeFileSync(addressFile, JSON.stringify(oldAddresses, null, 2));
} catch (e) {
console.error(e);
}
}
}
async function sleep(s) {
return new Promise((resolve) => {
setTimeout(resolve, s * 1000);
});
}
// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});