Skip to content

Commit 729745e

Browse files
committed
add deploy_vesting script
1 parent 38b1c26 commit 729745e

File tree

1 file changed

+153
-0
lines changed

1 file changed

+153
-0
lines changed

scripts/deploy_vesting.js

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// We require the Hardhat Runtime Environment explicitly here. This is optional
2+
// but useful for running the script in a standalone fashion through `node <script>`.
3+
//
4+
// When running the script with `hardhat run <script>` you'll find the Hardhat
5+
// Runtime Environment's members available in the global scope.
6+
const hre = require("hardhat");
7+
const fs = require("fs");
8+
const { address } = require("../test/helpers/constants");
9+
const { Wallet } = require("ethers");
10+
const { UV_FS_O_FILEMAP } = require("constants");
11+
const ethers = hre.ethers;
12+
require("dotenv").config();
13+
const logging = true;
14+
const show_verify = true;
15+
async function main() {
16+
const url = process.env.NETWORK_RPC_URL;
17+
console.log("Using RPC: "+url);
18+
if (!url) {
19+
console.error("Missing NETWORK_RPC_URL. Aborting..");
20+
return null;
21+
}
22+
if( !process.env.ADDRESS_FILE){
23+
console.error("Missing ADDRESS_FILE. Aborting..");
24+
return null;
25+
}
26+
const provider = new ethers.providers.JsonRpcProvider(url);
27+
const network = provider.getNetwork();
28+
// utils
29+
const networkDetails = await network;
30+
31+
32+
let wallet;
33+
if (process.env.MNEMONIC)
34+
wallet = new Wallet.fromMnemonic(process.env.MNEMONIC);
35+
if (process.env.PRIVATE_KEY) wallet = new Wallet(process.env.PRIVATE_KEY);
36+
if (!wallet) {
37+
console.error("Missing MNEMONIC or PRIVATE_KEY. Aborting..");
38+
return null;
39+
}
40+
owner = wallet.connect(provider);
41+
let gasLimit = 3000000;
42+
let gasPrice = null;
43+
let sleepAmount = 10;
44+
console.log("Using chain "+networkDetails.chainId);
45+
switch (networkDetails.chainId) {
46+
case 1:
47+
networkName = "mainnet";
48+
productionNetwork = true;
49+
OPFOwner = "0x0d27cd67c4A3fd3Eb9C7C757582f59089F058167";
50+
routerOwner = OPFOwner;
51+
OceanTokenAddress = "0x967da4048cD07aB37855c090aAF366e4ce1b9F48";
52+
break;
53+
54+
default:
55+
OPFOwner = "0x0d27cd67c4A3fd3Eb9C7C757582f59089F058167";
56+
networkName = "development";
57+
routerOwner = OPFOwner;
58+
shouldDeployOceanMock = true;
59+
sleepAmount = 0
60+
break;
61+
}
62+
63+
let options
64+
if(gasPrice){
65+
options = {gasLimit: gasLimit, gasPrice: gasPrice}
66+
}
67+
else{
68+
options = { gasLimit }
69+
}
70+
const addressFile = process.env.ADDRESS_FILE;
71+
let oldAddresses;
72+
if (addressFile) {
73+
try {
74+
oldAddresses = JSON.parse(fs.readFileSync(addressFile));
75+
} catch (e) {
76+
console.log(e);
77+
oldAddresses = {};
78+
}
79+
if (!oldAddresses[networkName]) oldAddresses[networkName] = {};
80+
addresses = oldAddresses[networkName];
81+
}
82+
if (logging)
83+
console.info(
84+
"Use existing addresses:" + JSON.stringify(addresses, null, 2)
85+
);
86+
87+
if (!addresses || !addresses.chainId) {
88+
console.error("Missing addresses. Aborting..");
89+
return null;
90+
}
91+
92+
93+
94+
if (logging) console.info("Deploying VestingWallet0");
95+
const VestingWallet0 = await ethers.getContractFactory(
96+
"VestingWalletLinear",
97+
owner
98+
);
99+
const block = await provider.getBlock("latest")
100+
const blockTimestamp = block.timestamp
101+
const endDate = "2024-03-14"
102+
const endDateUnix = parseInt(new Date(endDate).getTime() / 1000)
103+
const vestingPeriod = endDateUnix - blockTimestamp
104+
const deployVestingWallet0 = await VestingWallet0.connect(owner).deploy(addresses.Splitter, blockTimestamp, vestingPeriod, options)
105+
await deployVestingWallet0.deployTransaction.wait();
106+
addresses.VestingWalletA = deployVestingWallet0.address;
107+
if (show_verify) {
108+
console.log("\tRun the following to verify on etherscan");
109+
console.log("\tnpx hardhat verify --network " + networkName + " " + addresses.VestingWalletA+" "+addresses.Splitter+" "+blockTimestamp+" "+vestingPeriod)
110+
}
111+
if (sleepAmount > 0) await sleep(sleepAmount)
112+
113+
//ownerships
114+
if (routerOwner != owner.address) {
115+
if (logging) console.info("Moving vesting ownership to " + routerOwner)
116+
tx = await deployVestingWallet0.connect(owner).transferOwnership(routerOwner, options)
117+
await tx.wait();
118+
}
119+
120+
121+
if (addressFile) {
122+
// write address.json if needed
123+
oldAddresses[networkName] = addresses;
124+
if (logging)
125+
console.info(
126+
"writing to " +
127+
addressFile +
128+
"\r\n" +
129+
JSON.stringify(oldAddresses, null, 2)
130+
);
131+
try {
132+
fs.writeFileSync(addressFile, JSON.stringify(oldAddresses, null, 2));
133+
} catch (e) {
134+
console.error(e);
135+
}
136+
}
137+
}
138+
139+
140+
141+
async function sleep(s) {
142+
return new Promise((resolve) => {
143+
setTimeout(resolve, s*1000)
144+
})
145+
}
146+
// We recommend this pattern to be able to use async/await everywhere
147+
// and properly handle errors.
148+
main()
149+
.then(() => process.exit(0))
150+
.catch((error) => {
151+
console.error(error);
152+
process.exit(1);
153+
});

0 commit comments

Comments
 (0)