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

Work 78 - Adding the ability to Deploy other Chains #513

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
38 changes: 38 additions & 0 deletions packages/govern-create/deploy/factories.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HardhatRuntimeEnvironment } from 'hardhat/types'
import { DeployFunction } from 'hardhat-deploy/types'
import { network, ethers } from 'hardhat'

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre
Expand All @@ -26,6 +27,43 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
// deterministicDeployment: true,
})


const token = await deploy('GovernToken', {
from: deployer,
args: [
tokenFactory.address,
"GovernToken base",
"GTB",
0
],
log: true,
// deterministicDeployment: true,
})

const merkelDistributor = await deploy('MerkleDistributor', {
from: deployer,
log: true
})

const minter = await deploy('GovernMinter', {
from: deployer,
args: [
token.address,
tokenFactory.address,
merkelDistributor.address
]
})

try {
const tokenFactoryInstance = (await ethers.getContractFactory('GovernTokenFactory')).attach(tokenFactory.address);
await tokenFactoryInstance.setupBases(merkelDistributor.address,
minter.address,
token.address)
} catch (error) {
console.log(error);
}


await deploy('GovernBaseFactory', {
from: deployer,
Expand Down
10 changes: 8 additions & 2 deletions packages/govern-create/deploy/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TASK_ETHERSCAN_VERIFY } from 'hardhat-deploy'

import { verifyContract } from '../utils/etherscan'
import { ERC3000DefaultConfig } from 'erc3k/utils/ERC3000'
import { network } from 'hardhat'

const TWO_ADDRR = `0x${'00'.repeat(19)}02`

Expand All @@ -19,9 +20,14 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(
'Waiting for 2 minutes so Etherscan is aware of contracts before verifying'
)
await delay(120000) // Etherscan needs some time to process before trying to verify.
console.log('Starting to verify now')

if (network.name == 'fuji' || 'avalanche') {
console.log('Starting to verify now, Some network are fast some arent')
} else {
// Etherscan needs some time to process before trying to verify.
console.log('Starting to verify now')
await delay(120000)
}
await run(TASK_ETHERSCAN_VERIFY, {
apiKey: process.env.ETHERSCAN_KEY,
license: 'GPL-3.0',
Expand Down
9 changes: 9 additions & 0 deletions packages/govern-create/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ const config: HardhatUserConfig = {
url: 'https://rinkeby.infura.io/v3/7a03fcb37be7479da06f92c5117afd47',
accounts: PRIV_KEYS,
},
avalanche: {
url: 'https://api.avax.network/ext/bc/C/rpc',
accounts: PRIV_KEYS,
},
fuji: {
url: 'https://api.avax-test.network/ext/bc/C/rpc',
accounts: PRIV_KEYS,
blockGasLimit: 8000000
}
},
}

Expand Down
4 changes: 2 additions & 2 deletions packages/govern-create/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"devDependencies": {
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@nomiclabs/hardhat-etherscan": "^2.1.0",
"@nomiclabs/hardhat-etherscan": "^2.1.8",
"@nomiclabs/hardhat-waffle": "^2.0.0",
"@typechain/ethers-v5": "^4.0.0",
"@types/chai": "^4.2.13",
Expand All @@ -35,7 +35,7 @@
"ethereum-waffle": "^3.0.0",
"ethers": "^5.0.0",
"hardhat": "^2.1.1",
"hardhat-deploy": "^0.7.2",
"hardhat-deploy": "^0.9.22",
"hardhat-typechain": "^0.3.3",
"solidity-coverage": "^0.7.15",
"tmp-promise": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/govern-create/utils/etherscan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import HRE from 'hardhat'
import fs from 'fs'
import { file } from 'tmp-promise'

export const SUPPORTED_ETHERSCAN_NETWORKS = ['mainnet', 'rinkeby', 'rinkeby_staging']
export const SUPPORTED_ETHERSCAN_NETWORKS = ['mainnet', 'rinkeby', 'rinkeby_staging', 'fuji', 'avalanche', 'polygon', 'mumbai']

function delay(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
Expand Down
1 change: 1 addition & 0 deletions packages/govern-create/utils/network.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dotenv/config'

export const RINKEBY_URL = 'https://rinkeby.eth.aragon.network'
export const FUJI_URL = 'https://api.avax-test.network/ext/bc/C/rpc'

export function node_url(networkName: string): string {
if (networkName) {
Expand Down
8 changes: 4 additions & 4 deletions packages/govern-token/contracts/GovernMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ contract GovernMinter is ACL {
event MintedSingle(address indexed to, uint256 amount, bytes context);
event MintedMerkle(address indexed distributor, bytes32 indexed merkleRoot, uint256 totalAmount, bytes tree, bytes context);

constructor(GovernToken _token, address _initialMinter, MerkleDistributor _distributorBase) ACL(_initialMinter) public {
constructor(address _token, address _initialMinter, address _distributorBase) ACL(_initialMinter) public {
initialize(_token, _initialMinter, _distributorBase);
}

function initialize(GovernToken _token, address _initialMinter, MerkleDistributor _distributorBase) public initACL(_initialMinter) onlyInit("minter") {
token = _token;
distributorBase = address(_distributorBase);
function initialize(address _token, address _initialMinter, address _distributorBase) public initACL(_initialMinter) onlyInit("minter") {
token = GovernToken(_token);
distributorBase = _distributorBase;
_grant(MINT_ROLE, _initialMinter);
}

Expand Down
39 changes: 19 additions & 20 deletions packages/govern-token/contracts/GovernTokenFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ contract GovernTokenFactory {
event CreatedToken(GovernToken token, GovernMinter minter);

constructor() public {
setupBases();
// setupBases();
// This we disable since it fails for the contract code out of storage
}

function newToken(
Expand All @@ -36,7 +37,8 @@ contract GovernTokenFactory {
GovernMinter minter
) {
if (!_useProxies) {
(token, minter) = _deployContracts(_token.tokenName, _token.tokenSymbol, _token.tokenDecimals);
// (token, minter) = _deployContracts(_token.tokenName, _token.tokenSymbol, _token.tokenDecimals);
// The idea of deployContract is moved again with the contract code out of storage
} else {
token = GovernToken(tokenBase.clone(abi.encodeWithSelector(
token.initialize.selector,
Expand Down Expand Up @@ -78,14 +80,11 @@ contract GovernTokenFactory {
emit CreatedToken(token, minter);
}

function setupBases() private {
distributorBase = address(new MerkleDistributor(ERC20(tokenBase), bytes32(0)));
function setupBases(address _distributorBase, address _minter, address _token) public {
distributorBase = _distributorBase;

(GovernToken token, GovernMinter minter) = _deployContracts(
"GovernToken base",
"GTB",
0
);
GovernToken token = GovernToken(_token);
GovernMinter minter = GovernMinter(_minter);
token.changeMinter(address(minter));

// test the bases
Expand All @@ -97,15 +96,15 @@ contract GovernTokenFactory {
minterBase = address(minter);
}

function _deployContracts(
string memory _tokenName,
string memory _tokenSymbol,
uint8 _tokenDecimals
) internal returns (
GovernToken token,
GovernMinter minter
) {
token = new GovernToken(address(this), _tokenName, _tokenSymbol, _tokenDecimals);
minter = new GovernMinter(GovernToken(token), address(this), MerkleDistributor(distributorBase));
}
// function _deployContracts(
// string memory _tokenName,
// string memory _tokenSymbol,
// uint8 _tokenDecimals
// ) internal returns (
// GovernToken token,
// GovernMinter minter
// ) {
// token = new GovernToken(address(this), _tokenName, _tokenSymbol, _tokenDecimals);
// minter = new GovernMinter(GovernToken(token), address(this), MerkleDistributor(distributorBase));
// }
}
4 changes: 2 additions & 2 deletions packages/govern-token/contracts/MerkleDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ contract MerkleDistributor is Initializable {

event Claimed(uint256 indexed index, address indexed to, uint256 amount);

constructor(ERC20 _token, bytes32 _merkleRoot) public {
initialize(_token, _merkleRoot);
constructor() public {
initialize(ERC20(address(0)), bytes32(0));
}

function initialize(ERC20 _token, bytes32 _merkleRoot) public onlyInit("distributor") {
Expand Down
Loading