@layerzerolabs/verify-contract 1.0.422 → 1.0.423
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/constants/blockExplorerApi.json +3 -1
- package/index.js +28 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# Verify-Contract
|
|
3
2
|
|
|
3
|
+
## Setup
|
|
4
4
|
- Ensure you fill out the missing API keys inside your .env (copy the values from .env.example)
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Usage
|
|
8
8
|
|
|
9
9
|
- Inside your deploy script:
|
|
10
10
|
|
|
11
11
|
``const verify = require('@layerzerolabs/verify-contract')``
|
|
12
12
|
|
|
13
|
-
``await verify(hre.network.name, [
|
|
13
|
+
``await verify(hre.network.name, ["ContractName1", "ContractName2"])``
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
"optimism": "api-optimistic.etherscan.io",
|
|
15
15
|
"optimism-goerli": "api-goerli-optimistic.etherscan.io",
|
|
16
16
|
"gnosis": "api.gnosisscan.io",
|
|
17
|
-
"zkpolygon": "api-zkevm.polygonscan.com",
|
|
17
|
+
"zkpolygon-mainnet": "api-zkevm.polygonscan.com",
|
|
18
18
|
"base-mainnet": "api.basescan.org",
|
|
19
|
+
"zkconsensys-mainnet": "api.lineascan.build",
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
"aptos": "",
|
|
21
23
|
"celo": "",
|
package/index.js
CHANGED
|
@@ -109,7 +109,7 @@ function getBaseAndRemainingContract(contractName, contractBuildInfo) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
|
|
112
|
-
module.exports = async function (network,
|
|
112
|
+
module.exports = async function (network, contracts) {
|
|
113
113
|
if(!BLOCK_EXPLORER_API_URL[network]) {
|
|
114
114
|
throw `Unsupported block explorer network: ${network}`
|
|
115
115
|
}
|
|
@@ -117,35 +117,38 @@ module.exports = async function (network, contract) {
|
|
|
117
117
|
throw `Missing API key for network: ${network}`
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (test[0][0]
|
|
132
|
-
|
|
120
|
+
for (const contract of contracts) {
|
|
121
|
+
const contractName = `/${contract}.sol`
|
|
122
|
+
|
|
123
|
+
// get the build files/artifacts
|
|
124
|
+
const contractDeployment = JSON.parse(FileSystem.readFileSync(`./deployments/${network}/${contract}.json`, "utf8"))
|
|
125
|
+
// iterate the build-info to find the correct build file
|
|
126
|
+
let contractBuildInfo
|
|
127
|
+
FileSystem.readdirSync(`./artifacts/build-info/`).forEach(fileName => {
|
|
128
|
+
const f = JSON.parse(FileSystem.readFileSync(`./artifacts/build-info/${fileName}`, "utf8"))
|
|
129
|
+
|
|
130
|
+
let test = Object.entries(f["input"]["sources"]).filter(([k, v]) => k.includes(contractName))
|
|
131
|
+
if (test[0] && test[0][0]) {
|
|
132
|
+
if (test[0][0].includes(contractName)) {
|
|
133
|
+
contractBuildInfo = f
|
|
134
|
+
}
|
|
133
135
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!contractBuildInfo) throw `Could not find contract: ${contractName} inside of build-info!`
|
|
136
|
+
})
|
|
137
|
+
if (!contractBuildInfo) throw `Could not find contract: ${contractName} inside of build-info!`
|
|
137
138
|
|
|
138
|
-
|
|
139
|
+
console.log(`\n\nVerifying... Network: ${network}, contractName: ${contractName}, address: ${contractDeployment["address"]}`)
|
|
139
140
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
141
|
+
// parse and filter out the extra build files, because the verifier freaks out if too many contracts to check
|
|
142
|
+
const [baseContract, remainingContracts] = getBaseAndRemainingContract(contractName, contractBuildInfo)
|
|
143
|
+
contractBuildInfo["input"]["sources"] = getContractInheritance(baseContract[1]["content"], remainingContracts, Object.fromEntries([baseContract]))
|
|
143
144
|
|
|
144
|
-
|
|
145
|
-
|
|
145
|
+
// format the put request
|
|
146
|
+
const putObj = formatPutObj(baseContract, contractBuildInfo, contractDeployment, contract, network)
|
|
147
|
+
|
|
148
|
+
const response = await makeRequest(`${BLOCK_EXPLORER_API_URL[network]}`, putObj)
|
|
149
|
+
console.log(JSON.parse(response))
|
|
150
|
+
}
|
|
146
151
|
|
|
147
|
-
const response = await makeRequest(`${BLOCK_EXPLORER_API_URL[network]}`, putObj)
|
|
148
|
-
console.log(JSON.parse(response))
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
async function makeRequest(url, data) {
|