-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90fb019
commit 0ad1a94
Showing
7 changed files
with
143 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Signer } from "ethers"; | ||
import { task, types } from "hardhat/config"; | ||
import { EthereumProvider } from "hardhat/types"; | ||
|
||
import { | ||
EIP1193Provider, | ||
deployMastercopy, | ||
deployAllMastercopies, | ||
readMastercopy, | ||
} from "@gnosis-guild/zodiac-core"; | ||
|
||
task( | ||
"deploy:mastercopy", | ||
"For every version entry on the artifacts file, deploys a mastercopy into the current network" | ||
) | ||
.addOptionalParam( | ||
"contractName", | ||
"The name of the contractName to deploy", | ||
types.string | ||
) | ||
.addFlag( | ||
"current", | ||
"Deploy the latest version from disk instead of using mastercopies.json" //TODO: Improve the docs | ||
) | ||
.setAction(async ({ current, contractName }, hre) => { | ||
console.log("contractName", contractName); | ||
const [signer] = await hre.ethers.getSigners(); | ||
const provider = createEIP1193(hre.network.provider, signer); | ||
if (current) { | ||
// Logic to deploy the latest version from disk | ||
await deployLatestMastercopyFromDisk(provider, contractName); | ||
} else { | ||
// using mastercopies.json | ||
await deployAllMastercopies({ | ||
provider, | ||
}); | ||
} | ||
}); | ||
|
||
function createEIP1193( | ||
provider: EthereumProvider, | ||
signer: Signer | ||
): EIP1193Provider { | ||
return { | ||
request: async ({ method, params }) => { | ||
if (method == "eth_sendTransaction") { | ||
const { hash } = await signer.sendTransaction((params as any[])[0]); | ||
return hash; | ||
} | ||
|
||
return provider.request({ method, params }); | ||
}, | ||
}; | ||
} | ||
|
||
async function deployLatestMastercopyFromDisk( | ||
provider: EIP1193Provider, | ||
contract: string | ||
) { | ||
const latestArtifact = readMastercopy({ | ||
contractName: contract, | ||
}); | ||
|
||
const { address, noop } = await deployMastercopy({ | ||
...latestArtifact, | ||
provider, | ||
}); | ||
const { contractName, contractVersion } = latestArtifact; | ||
if (noop) { | ||
console.log( | ||
`🔄 ${contractName}@${contractVersion}: Already deployed at ${address}` | ||
); | ||
} else { | ||
console.log( | ||
`🚀 ${contractName}@${contractVersion}: Successfully deployed at ${address}` | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { task, types } from "hardhat/config"; | ||
import { | ||
readMastercopy, | ||
verifyAllMastercopies, | ||
} from "@gnosis-guild/zodiac-core"; | ||
import path from "path"; | ||
import fs from "fs"; | ||
|
||
const { ETHERSCAN_API_KEY } = process.env; | ||
|
||
task( | ||
"verify:mastercopy", | ||
"Verifies all mastercopies from the artifacts file, in the block explorer corresponding to the current network" | ||
) | ||
.addOptionalParam( | ||
"contractName", | ||
"The name of the contractName to verify", | ||
types.string | ||
) | ||
.addFlag( | ||
"current", | ||
"Verify the latest version from disk instead of using mastercopies.json" //TODO: Improve the docs | ||
) | ||
.setAction(async ({ current, contractName }, hre) => { | ||
if (!ETHERSCAN_API_KEY) { | ||
throw new Error("Missing ENV ETHERSCAN_API_KEY"); | ||
} | ||
|
||
const chainId = String((await hre.ethers.provider.getNetwork()).chainId); | ||
|
||
if (current && contractName) { | ||
const latestArtifact = readMastercopy({ | ||
contractName, | ||
}); | ||
const tempFilePath = path.join( | ||
hre.config.paths.cache, | ||
"latest-mastercopy.json" | ||
); | ||
fs.writeFileSync(tempFilePath, JSON.stringify([latestArtifact], null, 2)); | ||
|
||
const { address } = latestArtifact; | ||
console.log(`Verifying ${contractName} at address ${address}...`); | ||
|
||
await verifyAllMastercopies({ | ||
apiUrlOrChainId: chainId, | ||
apiKey: ETHERSCAN_API_KEY, | ||
mastercopyArtifactsFile: tempFilePath, | ||
}); | ||
fs.unlinkSync(tempFilePath); | ||
} else { | ||
await verifyAllMastercopies({ | ||
apiUrlOrChainId: chainId, | ||
apiKey: ETHERSCAN_API_KEY, | ||
}); | ||
} | ||
}); |