- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
Latest commit
101 lines (85 loc) · 3.37 KB
/
Copy pathdeploy.js
File metadata and controls
101 lines (85 loc) · 3.37 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
consthre=require("hardhat");
require("dotenv").config();
const{NETWORKS_LOOKUP,POLYGON_SCAN_STUB}=require("./constants.js")
constconstructorArgs=require('./constructorArgs');
constadminAccounts=require('./adminTestAccounts');
letnetworkName,networkId,contractAbi
constmain=async()=>{
constworldcoin_addr=process.env.WORLDID_ADDR
console.log("worldcoin addr: "+worldcoin_addr)
constdays=60*60*24*1000
constwithdrawBuffer=3*days
constd3ventContractFactory=awaithre.ethers.getContractFactory('d3vent');
constd3ventContract=awaitd3ventContractFactory.deploy(...constructorArgs);
awaitd3ventContract.deployed();
console.log("Contract deployed to: ",d3ventContract.address);
console.log(POLYGON_SCAN_STUB+d3ventContract.address);
constcontractNetwork=awaitd3ventContract.provider.getNetwork()
networkId=contractNetwork.chainId.toString()
// if not Hardhat i.e. local do some pipeline actions
if(networkId!="31337"){
networkName=NETWORKS_LOOKUP.get(networkId)
// output contract address to current address quick reference file and log file
console.log("writing contract address reference files")
// log the deployment addresses to quick reference file
awaitwriteFileDeployAddr(d3ventContract.address)
// create an export file for contract address. pipeline: imported by the frontend
awaitwriteExportContractAddr("../client/contract/contractAddress.js",d3ventContract.address)
// create and abi file. pipeline: imported by the frontend
awaitwriteABI()
// setup teammate test accounts as contract admins
for(constaccountofadminAccounts){
console.log("adding admin account: ",account)
try{
awaitd3ventContract.addAdmin(account)
if(!(awaitd3ventContract.isAdmin(account))){throw"couldn't verify account added: ",account}
}catch(err){
console.log(err)
}
}
}
}
main()
.then(()=>process.exit(0))
.catch((error)=>{
console.error(error);
process.exit(1);
});
asyncfunctionwriteFileDeployAddr(contractAddress){
constfs=require('fs');
letisoTime=newDate(Date.now()).toISOString().replace("T"," ").slice(0,19)
letcontent=isoTime+"\t"+contractAddress+'\t'+networkName+'\t'+networkId+"\n"
console.log(content)
// just the current/latest one
fs.writeFileSync('./deployAddress.txt',content,err=>{
if(err){console.error(err)}
})
// keep a history
fs.appendFileSync('./deployAddressesLog.txt',content,err=>{
if(err){console.error(err)}
})
}
asyncfunctionwriteExportContractAddr(filepath,contractAddress){
constfs=require('fs');
constcontent="module.exports = [\n "+contractAddress+"\n]"
console.log(filepath)
console.log(content)
fs.writeFileSync(filepath,content,err=>{
if(err){
console.error(err)
}
})
}
// pipeline: take the abi out of the contract artifacts file and create
// an abi.json file and create an abi file for the front end to import
asyncfunctionwriteABI(){
constfs=require('fs');
constcontractArtifacts=fs.readFileSync('./artifacts/contracts/d3vent.sol/d3vent.json','utf8');
constabi=JSON.parse(contractArtifacts).abi;
fs.writeFileSync('../client/contract/abi.json',JSON.stringify(abi,null,2),err=>{
if(err){
console.error(err)
}
})
console.log(abi)
}