-
Notifications
You must be signed in to change notification settings - Fork 1
/
verify.ts
182 lines (172 loc) · 5.38 KB
/
verify.ts
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { BigNumber } from "ethers";
import {
run,
ethers,
upgrades,
network,
rigsConfig,
rigsDeployment,
} from "hardhat";
async function main() {
console.log(`\nVerifying on '${network.name}'...`);
// Ensure deployments
if (rigsDeployment.contractAddress === "") {
throw Error(`no contractAddress entry for '${network.name}'`);
}
if (rigsDeployment.royaltyContractAddress === "") {
throw Error(`no royaltyContractAddress entry for '${network.name}'`);
}
if (rigsDeployment.pilotsAddress === "") {
throw Error(`no pilotsAddress entry for '${network.name}'`);
}
if (rigsDeployment.votingContractAddress === "") {
throw Error(`no votingContractAddress entry for '${network.name}'`);
}
if (rigsDeployment.missionContractAddress === "") {
throw Error(`no missionContractAddress entry for '${network.name}'`);
}
// Verify rigs
const rigs = (await ethers.getContractFactory("TablelandRigs")).attach(
rigsDeployment.contractAddress
);
let impl = await upgrades.erc1967.getImplementationAddress(rigs.address);
try {
await run("verify:verify", {
address: impl,
});
} catch (err) {
// Check if the error is via hardhat or etherscan where already verified contracts throw a halting error
// If it's an etherscan issue, "Reason: Already Verified" is embedded within a hardhat error message
if (
err.message === "Contract source code already verified" ||
err.message.includes("Reason: Already Verified")
) {
console.log(
`Rigs contract already verified: '${rigsDeployment.contractAddress}'`
);
} else throw err;
}
// Verify pilots
const pilots = (await ethers.getContractFactory("TablelandRigPilots")).attach(
rigsDeployment.pilotsAddress
);
impl = await upgrades.erc1967.getImplementationAddress(pilots.address);
try {
await run("verify:verify", {
address: impl,
});
} catch (err) {
if (
err.message === "Contract source code already verified" ||
err.message.includes("Reason: Already Verified")
) {
console.log(
`Pilots contract already verified: '${rigsDeployment.pilotsAddress}'`
);
} else throw err;
}
// Verify royalties contract
try {
await run("verify:verify", {
address: rigsDeployment.royaltyContractAddress,
constructorArguments: [
rigsConfig.royaltyReceivers,
rigsConfig.royaltyReceiverShares,
],
});
} catch (err) {
if (
err.message === "Contract source code already verified" ||
err.message.includes("Reason: Already Verified")
) {
console.log(
`Royalties contract already verified: '${rigsDeployment.royaltyContractAddress}'`
);
} else throw err;
}
// Verify voting contract
try {
const pilotSessionsTableId =
rigsDeployment.pilotSessionsTable.match(/.*_\d*_(\d*)/)![1];
const ftRewardsTableId =
rigsDeployment.ftRewardsTable.match(/.*_\d*_(\d*)/)![1];
const proposalsTableId =
rigsDeployment.proposalsTable.match(/.*_\d*_(\d*)/)![1];
const ftSnapshotTableId =
rigsDeployment.ftSnapshotTable.match(/.*_\d*_(\d*)/)![1];
const votesTableId = rigsDeployment.votesTable.match(/.*_\d*_(\d*)/)![1];
const optionsTableId =
rigsDeployment.optionsTable.match(/.*_\d*_(\d*)/)![1];
await run("verify:verify", {
address: rigsDeployment.votingContractAddress,
constructorArguments: [
{
id: BigNumber.from(proposalsTableId),
name: rigsDeployment.proposalsTable,
},
{
id: BigNumber.from(ftSnapshotTableId),
name: rigsDeployment.ftSnapshotTable,
},
{ id: BigNumber.from(votesTableId), name: rigsDeployment.votesTable },
{
id: BigNumber.from(optionsTableId),
name: rigsDeployment.optionsTable,
},
{
id: BigNumber.from(pilotSessionsTableId),
name: rigsDeployment.pilotSessionsTable,
},
{
id: BigNumber.from(ftRewardsTableId),
name: rigsDeployment.ftRewardsTable,
},
BigNumber.from(0),
],
});
} catch (err) {
if (
err.message === "Contract source code already verified" ||
err.message.includes("Reason: Already Verified")
) {
console.log(
`Voting contract already verified: '${rigsDeployment.votingContractAddress}'`
);
} else throw err;
}
// Verify missions contract
try {
const missionsTable =
rigsDeployment.missionsTable.match(/.*_\d*_(\d*)/)![1];
const missionContributionsTable =
rigsDeployment.missionContributionsTable.match(/.*_\d*_(\d*)/)![1];
await run("verify:verify", {
address: rigsDeployment.missionContractAddress,
constructorArguments: [
{
id: BigNumber.from(missionsTable),
name: rigsDeployment.missionsTable,
},
{
id: BigNumber.from(missionContributionsTable),
name: rigsDeployment.missionContributionsTable,
},
],
});
} catch (err) {
if (
err.message === "Contract source code already verified" ||
err.message.includes("Reason: Already Verified")
) {
console.log(
`Missions contract already verified: '${rigsDeployment.missionContractAddress}'`
);
} else throw err;
}
}
main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});