Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate Etherscan Contract Verification #50

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"WrapAndUnWrap":{"mainnet":{"address":"0x3Aa5ebB10DC797CAC828524e59A333d0A371443c","args":[]}},"WrapAndUnWrapProxy":{"mainnet":{"address":"0xc6e7DF5E7b4f2A278906862b61205850344D4e7d","args":[]}},"WrapAndUnWrapSushi":{"mainnet":{"address":"0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44","args":[]}},"WrapAndUnWrapSushiProxy":{"mainnet":{"address":"0xa85233C63b9Ee964Add6F2cffe00Fd84eb32338f","args":[]}},"TokenRewards":{"mainnet":{"address":"0x09635F643e140090A9A8Dcd712eD6285858ceBef","args":[]}},"TokenRewardsProxy":{"mainnet":{"address":"0xc5a5C42992dECbae36851359345FE25997F5C42d","args":[]}},"PlexusOracle":{"mainnet":{"address":"0xc3e53F4d16Ae77Db1c982e75a937B9f60FE63690","args":[]}},"PlexusOracleProxy":{"mainnet":{"address":"0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB","args":[]}},"Tier2FarmController":{"mainnet":{"address":"0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8","args":[]}},"Tier2FarmControllerProxy":{"mainnet":{"address":"0x851356ae760d987E095750cCeb3bC6014560891C","args":[]}},"Tier1FarmController":{"mainnet":{"address":"0x998abeb3E57409262aE5b751f60747921B33613E","args":[]}},"Tier1FarmControllerProxy":{"mainnet":{"address":"0x70e0bA845a1A0F2DA3359C97E0285013525FFC49","args":[]}},"Core":{"mainnet":{"address":"0x0E801D84Fa97b50751Dbf25036d067dCf18858bF","args":[]}},"CoreProxy":{"mainnet":{"address":"0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf","args":[]}},"Tier2AaveFarmController":{"mainnet":{"address":"0x36C02dA8a0983159322a80FFE9F24b1acfF8B570","args":[]}},"Tier2AaveFarmControllerProxy":{"mainnet":{"address":"0x809d550fca64d94Bd9F66E60752A544199cfAC3D","args":[]}},"Tier2PickleFarmController":{"mainnet":{"address":"0x5f3f1dBD7B74C6B46e8c44f98792A1dAf8d69154","args":[]}},"Tier2PickleFarmControllerProxy":{"mainnet":{"address":"0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575","args":[]}},"LP2LP":{"mainnet":{"address":"0x2bdCC0de6bE1f7D2ee689a0342D76F52E8EFABa3","args":[]}},"LP2LPProxy":{"mainnet":{"address":"0x7969c5eD335650692Bc04293B07F5BF2e7A673C0","args":[]}},"Tier2AggregatorFarmController":{"mainnet":{"address":"0xFD471836031dc5108809D173A067e8486B9047A3","args":[]}},"Tier2AggregatorFarmControllerProxy":{"mainnet":{"address":"0xcbEAF3BDe82155F56486Fb5a1072cb8baAf547cc","args":[]}}}
11 changes: 9 additions & 2 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require("dotenv").config();
require('@nomiclabs/hardhat-waffle');
require('@nomiclabs/hardhat-solhint');
require('solidity-coverage');
require("@nomiclabs/hardhat-etherscan");

module.exports = {
defaultNetwork: "hardhat",
Expand Down Expand Up @@ -40,7 +41,7 @@ module.exports = {
url: process.env.RPC_NODE_URL,
chainId: 1
},

kovan: {
gas: "auto",
gasPrice: "auto",
Expand All @@ -51,7 +52,13 @@ module.exports = {
},
url: process.env.RPC_NODE_URL_KOVAN,
chainId: 42
}
},
},

etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: process.env.ETHERSCAN_API_KEY
},

mocha: {
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
"scripts": {
"test": "npx hardhat test",
"build": "hardhat compile",
"clean": "npx hardhat clean",
"console": "hardhat console",
"verify": "yarn hint && yarn test",
"lint": "yarn solhint 'contracts/**/*.sol' && yarn prettier -c './**/*.js'",
"format": "yarn prettier --write contracts/*.sol && yarn prettier --write test/*.js",
"hint": "solhint \"contracts/**/*.sol\"",
"coverage": "yarn hardhat coverage --testfiles \"test/*.js\""
"coverage": "yarn hardhat coverage --testfiles \"test/*.js\"",
"deploy": "npx hardhat run scripts/deploy.js",
"verify": "npx hardhat run scripts/verify.js"
},
"repository": {
"type": "git",
Expand All @@ -31,6 +33,7 @@
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.1",
"@nomiclabs/hardhat-etherscan": "^2.1.3",
"@nomiclabs/hardhat-solhint": "^2.0.0",
"@nomiclabs/hardhat-waffle": "^2.0.1",
"chai": "^4.3.3",
Expand Down
67 changes: 43 additions & 24 deletions scripts/deploy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
const config = require('../config.json');
const fs = require('fs');
let root = {}
let network = 'mainnet'

async function main() {
const addr = config.addresses;

const netinfo = await ethers.provider.getNetwork();
var network = netinfo.name;
network = netinfo.name;
if (network === "unknown")
network = "mainnet";

Expand Down Expand Up @@ -32,7 +35,7 @@ async function main() {

// plexus reward token
const PlexusCoin = await ethers.getContractFactory('PlexusTestCoin');

// get the signers
let owner, addr1;
[owner, addr1, ...addrs] = await ethers.getSigners();
Expand All @@ -44,8 +47,8 @@ async function main() {

// then deploy the contracts and wait for them to be mined
const wrapper = await deployWithProxy(
Wrapper,
OwnableProxy,
Wrapper,
OwnableProxy,
'WrapAndUnWrap',
addr.tokens.WETH[network],
addr.swaps.uniswap[network],
Expand All @@ -57,8 +60,8 @@ async function main() {
console.log("Wrapper is deployed at: ", wrapper.address);

const wrapperSushi = await deployWithProxy(
WrapperSushi,
OwnableProxy,
WrapperSushi,
OwnableProxy,
'WrapAndUnWrapSushi',
addr.tokens.WETH[network],
addr.swaps.sushiswap[network],
Expand All @@ -77,44 +80,44 @@ async function main() {
console.log("TokenRewards is deployed at: ", tokenRewards.address);

const plexusOracle = await deployWithProxy(
PlexusOracle,
OwnableProxy,
PlexusOracle,
OwnableProxy,
'PlexusOracle',
addr.swaps.uniswap[network],
addr.tokens.USDC[network]
);
console.log("PlexusOracle is deployed at: ", plexusOracle.address);

const tier2Farm = await deployWithProxy(
Tier2Farm,
OwnableProxy,
Tier2Farm,
OwnableProxy,
'Tier2FarmController',
addr.AutoStake[network],
addr.tokens.FARM[network]
);
console.log("Tier2Farm is deployed at: ", tier2Farm.address);

const tier1Staking = await deployWithProxy(
Tier1Staking,
OwnableProxy,
Tier1Staking,
OwnableProxy,
'Tier1FarmController',
tier2Farm.address,
plexusOracle.address
);
console.log("Tier1Staking is deployed at: ", tier1Staking.address);

const core = await deployWithProxy(
Core,
OwnableProxy,
Core,
OwnableProxy,
'Core',
addr.tokens.WETH[network],
wrapper.address
);
console.log("Core is deployed at: ", core.address);

const tier2Aave = await deployWithProxy(
Tier2Aave,
OwnableProxy,
Tier2Aave,
OwnableProxy,
'Tier2AaveFarmController',
addr.AaveLendingPoolV2[network],
addr.tokens.DAI[network],
Expand All @@ -123,25 +126,25 @@ async function main() {
console.log("Tier2Aave is deployed at: ", tier2Aave.address);

const tier2Pickle = await deployWithProxy(
Tier2Pickle,
OwnableProxy,
Tier2Pickle,
OwnableProxy,
'Tier2PickleFarmController',
addr.StakingRewards[network],
addr.tokens.PICKLE[network]
);
console.log("Tier2Pickle is deployed at: ", tier2Pickle.address);

const lp2lp = await deployWithProxy(
LP2LP,
OwnableProxy,
LP2LP,
OwnableProxy,
'LP2LP',
addr.tokens.vBNT[network]
);
console.log("LP2LP is deployed at: ", lp2lp.address);

const tier2Aggregator = await deployWithProxy(
Tier2Aggregator,
OwnableProxy,
Tier2Aggregator,
OwnableProxy,
'Tier2AggregatorFarmController',
addr.tokens.pUNI_V2[network],
addr.tokens.UNI_V2[network]
Expand All @@ -156,7 +159,7 @@ async function main() {
console.log("Setting up contracts... ");
await tokenRewards.updateOracleAddress(plexusOracle.address);
await tokenRewards.updateStakingTokenAddress(plexusCoin.address);

await plexusOracle.updateRewardAddress(tokenRewards.address);
await plexusOracle.updateCoreAddress(core.address);
await plexusOracle.updateTier1Address(tier1Staking.address);
Expand All @@ -181,20 +184,36 @@ async function main() {
await tier2Aave.changeOwner(tier1Staking.address);
await tier2Pickle.changeOwner(tier1Staking.address);

console.log("Write addresses")
const json = JSON.stringify(root);

fs.writeFileSync('addresses.json', json);

console.log("");
console.log("Successfully Deployed!");
console.log("============================================================");
}

const deployWithProxy = async(contractFactory, proxyFactory, factoryName, ...params) => {
let deployedContract = await (await contractFactory.deploy()).deployed();
await writeAddress(factoryName, deployedContract.address, [])
const deployedProxy = await (await proxyFactory.deploy(deployedContract.address)).deployed();
await deployedContract.setProxy(deployedProxy.address);
deployedContract = await ethers.getContractAt(factoryName, deployedProxy.address);
await deployedContract.initialize(...params);
await writeAddress(factoryName + 'Proxy', deployedProxy.address, [])

return deployedContract;
}


const writeAddress = async (factoryName, address, args) => {
root[factoryName] = {}
root[factoryName][network] = {
address,
args
}
}

main()
.then(() => process.exit(0))
.catch(error => {
Expand Down
78 changes: 78 additions & 0 deletions scripts/verify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
const addresses = require('../addresses.json');
const hre = require("hardhat");

async function main() {
const netinfo = await ethers.provider.getNetwork();
let network = netinfo.name;
if (network === "unknown")
network = "mainnet";

// Verify Wrapper and Wrapper Proxy
const wrapper = addresses.WrapAndUnWrap
verifyContract(wrapper, network)
const wrapperProxy = addresses.WrapAndUnWrapProxy
verifyContract(wrapperProxy, network)
const wrapperSushi = addresses.WrapAndUnWrapSushi
verifyContract(wrapperSushi, network)
const wrapperSushiProxy = addresses.WrapAndUnWrapSushiProxy
verifyContract(wrapperSushiProxy, network)
const tokenRewards = addresses.TokenRewards
verifyContract(tokenRewards, network)
const tokenRewardsProxy = addresses.TokenRewardsProxy
verifyContract(tokenRewardsProxy, network)
const plexusOracle = addresses.PlexusOracle
verifyContract(plexusOracle, network)
const plexusOracleProxy = addresses.PlexusOracleProxy
verifyContract(plexusOracleProxy, network)
const tier1Staking = addresses.Tier1FarmController
verifyContract(tier1Staking, network)
const tier1StakingProxy = addresses.Tier1FarmControllerProxy
verifyContract(tier1StakingProxy, network)
const core = addresses.Core
verifyContract(core, network)
const coreProxy = addresses.CoreProxy
verifyContract(coreProxy, network)
const tier2Farm = addresses.Tier2FarmController
verifyContract(tier2Farm, network)
const tier2FarmProxy = addresses.Tier2FarmControllerProxy
verifyContract(tier2FarmProxy, network)
const tier2Aave = addresses.Tier2AaveFarmController
verifyContract(tier2Aave, network)
const tier2AaveProxy = addresses.Tier2AaveFarmControllerProxy
verifyContract(tier2AaveProxy, network)
const tier2Pickle = addresses.Tier2PickleFarmController
verifyContract(tier2Pickle, network)
const tier2PickleProxy = addresses.Tier2PickleFarmControllerProxy
verifyContract(tier2PickleProxy, network)
const lP2LP = addresses.LP2LP
verifyContract(lP2LP, network)
const lP2LPProxy = addresses.LP2LPProxy
verifyContract(lP2LPProxy, network)
const tier2Aggregator = addresses.Tier2AggregatorFarmController
verifyContract(tier2Aggregator, network)
const tier2AggregatorProxy = addresses.Tier2AggregatorFarmControllerProxy
verifyContract(tier2AggregatorProxy, network)

console.log("============================================================");
}

function verifyContract(contractInfo, network) {
if (contractInfo) {
const contract = contractInfo[network]
if (contract) {
if (contract && contract.address.length > 0) {
hre.run("verify:verify", {
address: contract.address,
constructorArguments: contract.args || [],
});
}
}
}
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});