Merge pull request #218 from 67P/feature/217-rsk_deployment
Refactor deployment script, add error handling
This commit is contained in:
commit
1d1f2bb4ed
@ -1,72 +1,107 @@
|
|||||||
const { ethers, upgrades } = require("hardhat");
|
const { ethers, upgrades } = require("hardhat"); const path = require("path"); const fileInject = require("./helpers/file_inject.js");
|
||||||
const path = require("path");
|
|
||||||
const fileInject = require("./helpers/file_inject.js");
|
function handleError(error) {
|
||||||
|
console.error(error.message);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const network = await hre.ethers.provider.getNetwork();
|
const network = await hre.ethers.provider.getNetwork();
|
||||||
const networkId = network.chainId;
|
const networkId = network.chainId;
|
||||||
console.log(`Deploying to network #${networkId}`);
|
console.log(`Deploying to network #${networkId}`);
|
||||||
|
|
||||||
const Contributor = await ethers.getContractFactory("Contributor");
|
const contractFactories = {};
|
||||||
const Contribution = await ethers.getContractFactory("Contribution");
|
const contracts = {};
|
||||||
const Token = await ethers.getContractFactory("Token");
|
|
||||||
const Reimbursement = await ethers.getContractFactory("Reimbursement");
|
|
||||||
|
|
||||||
const contributor = await upgrades.deployProxy(Contributor, []);
|
contractFactories.Contributor = await ethers.getContractFactory("Contributor");
|
||||||
await contributor.deployed();
|
contractFactories.Contribution = await ethers.getContractFactory("Contribution");
|
||||||
console.log("Contributor deployed to:", contributor.address);
|
contractFactories.Token = await ethers.getContractFactory("Token");
|
||||||
|
contractFactories.Reimbursement = await ethers.getContractFactory("Reimbursement");
|
||||||
|
|
||||||
|
async function deployContractProxy (contractName, params=[]) {
|
||||||
|
let contract = await upgrades.deployProxy(contractFactories[contractName], params)
|
||||||
|
.catch(handleError);
|
||||||
|
|
||||||
|
contracts[contractName] = contract;
|
||||||
|
|
||||||
|
await contract.deployed().then(() => {
|
||||||
|
console.log(`${contractName} deployed to:`, contract.address);
|
||||||
console.log("...waiting for 1 confirmation");
|
console.log("...waiting for 1 confirmation");
|
||||||
await contributor.deployTransaction.wait();
|
}).catch(handleError);
|
||||||
|
|
||||||
const blocksToWait = 40320; // 7 days; 15 seconds block time
|
await contract.deployTransaction.wait().catch(handleError);
|
||||||
const contribution = await upgrades.deployProxy(Contribution, [blocksToWait]);
|
}
|
||||||
await contribution.deployed();
|
|
||||||
console.log("Contribution deployed to:", contribution.address);
|
|
||||||
console.log("...waiting for 1 confirmation");
|
|
||||||
await contribution.deployTransaction.wait();
|
|
||||||
|
|
||||||
const token = await upgrades.deployProxy(Token, []);
|
const blocksVetoPeriod = 40320; // 7 days; 15 seconds block time
|
||||||
await token.deployed();
|
|
||||||
console.log("Token deployed to:", token.address);
|
|
||||||
console.log("...waiting for 1 confirmation");
|
|
||||||
await token.deployTransaction.wait();
|
|
||||||
|
|
||||||
const reimbursement = await upgrades.deployProxy(Reimbursement, []);
|
await deployContractProxy('Contributor');
|
||||||
await reimbursement.deployed();
|
await deployContractProxy('Contribution', [ blocksVetoPeriod ]);
|
||||||
console.log("Reimbursement deployed to:", reimbursement.address);
|
await deployContractProxy('Token');
|
||||||
console.log("...waiting for 1 confirmation");
|
await deployContractProxy('Reimbursement');
|
||||||
await reimbursement.deployTransaction.wait();
|
|
||||||
|
|
||||||
await contributor
|
console.log('Calling Contributor#setTokenContract')
|
||||||
.setTokenContract(token.address)
|
await contracts.Contributor.functions
|
||||||
.then((response) => response.wait());
|
.setTokenContract(contracts.Token.address)
|
||||||
await contributor
|
.then(res => {
|
||||||
.setContributionContract(contribution.address)
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
.then((response) => response.wait());
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
await contribution
|
console.log('Calling Contributor#setContributionContract')
|
||||||
.setTokenContract(token.address)
|
await contracts.Contributor.functions
|
||||||
.then((response) => response.wait());
|
.setContributionContract(contracts.Contribution.address)
|
||||||
await contribution
|
.then(res => {
|
||||||
.setContributorContract(contributor.address)
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
.then((response) => response.wait());
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
await token
|
|
||||||
.setContributionContract(contribution.address)
|
|
||||||
.then((response) => response.wait());
|
|
||||||
await token
|
|
||||||
.setContributorContract(contributor.address)
|
|
||||||
.then((response) => response.wait());
|
|
||||||
|
|
||||||
await reimbursement
|
console.log('Calling Contribution#setTokenContract')
|
||||||
.setContributorContract(contributor.address)
|
await contracts.Contribution.functions
|
||||||
.then((response) => response.wait());
|
.setTokenContract(contracts.Token.address)
|
||||||
|
.then(res => {
|
||||||
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
|
|
||||||
|
console.log('Calling Contribution#setContributorContract')
|
||||||
|
await contracts.Contribution.functions
|
||||||
|
.setContributorContract(contracts.Contributor.address)
|
||||||
|
.then(res => {
|
||||||
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
|
console.log('Calling Token#setContributionContract')
|
||||||
|
await contracts.Token.functions
|
||||||
|
.setContributionContract(contracts.Contribution.address)
|
||||||
|
.then(res => {
|
||||||
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
|
console.log('Calling Token#setContributorContract')
|
||||||
|
await contracts.Token.functions
|
||||||
|
.setContributorContract(contracts.Contributor.address)
|
||||||
|
.then(res => {
|
||||||
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
|
console.log('Calling Reimbursement#setContributorContract')
|
||||||
|
await contracts.Reimbursement.functions
|
||||||
|
.setContributorContract(contracts.Contributor.address)
|
||||||
|
.then(res => {
|
||||||
|
console.log(`...transaction published: ${res.hash}`);
|
||||||
|
return res.wait();
|
||||||
|
}).catch(handleError);
|
||||||
|
|
||||||
const addresses = {
|
const addresses = {
|
||||||
Contributor: contributor.address,
|
Contributor: contracts.Contributor.address,
|
||||||
Contribution: contribution.address,
|
Contribution: contracts.Contribution.address,
|
||||||
Token: token.address,
|
Token: contracts.Token.address,
|
||||||
Reimbursement: reimbursement.address,
|
Reimbursement: contracts.Reimbursement.address,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Writing addresses.json");
|
console.log("Writing addresses.json");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user