Skip to content

Commit

Permalink
hardhat deploy with verification
Browse files Browse the repository at this point in the history
  • Loading branch information
aazhou1 committed Dec 27, 2024
1 parent c73958f commit 779b6bb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 13 deletions.
43 changes: 32 additions & 11 deletions hardhat-scripts/deploy-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from "hardhat"; // Use direct ethers import
import { ethers, run } from "hardhat"; // Added run import for verification
import "@nomiclabs/hardhat-ethers";
import { NonceManager } from "@ethersproject/experimental";
import dotenv from "dotenv";
Expand All @@ -8,9 +8,25 @@ import path from 'path';
import { Strategy } from '../typechain-types/src/Strategy';
type StrategyParamsStruct = Strategy.StrategyParamsStruct;


dotenv.config();

async function verifyContract(address: string, constructorArguments: any[]) {
console.log("Verifying contract...");
try {
await run("verify:verify", {
address: address,
constructorArguments: constructorArguments,
});
console.log("Contract verified successfully");
} catch (error: any) {
if (error.message.includes("Already Verified")) {
console.log("Contract is already verified");
} else {
console.log("Error verifying contract:", error);
}
}
}

function stringToAddressArray(input: string): string[] {
if (!input) return [];
return input.split(",").map((addr) => {
Expand All @@ -22,15 +38,14 @@ function stringToAddressArray(input: string): string[] {
});
}

function stringToUintArray(input: string): string[] { // Changed return type to string[]
function stringToUintArray(input: string): string[] {
if (!input) return [];
return input.split(",").map((num) => {
const trimmed = num.trim();
// Just validate that it's a valid number string but return the string
if (isNaN(Number(trimmed))) {
throw new Error(`Invalid number: ${trimmed}`);
}
return trimmed; // Return the string instead of parsing to number
return trimmed;
});
}

Expand Down Expand Up @@ -88,10 +103,15 @@ async function deployEventEmitter(managedSigner: Signer) {
const EventEmitter = (
await ethers.getContractFactory("TermVaultEventEmitter")
).connect(managedSigner);

if (!eventEmitterImpl) {
const eventEmitterImplContract = await EventEmitter.deploy();
await eventEmitterImplContract.deployed();
console.log("Deployed event emitter impl to:", eventEmitterImplContract.address);

// Verify EventEmitter implementation
await verifyContract(eventEmitterImplContract.address, []);

eventEmitterImpl = eventEmitterImplContract.address;
}

Expand All @@ -109,9 +129,11 @@ async function deployEventEmitter(managedSigner: Signer) {
);
await eventEmitterProxy.deployed();
console.log("Using event emitter impl at:", eventEmitterImpl);

console.log("Deployed event emitter proxy to:", eventEmitterProxy.address);

// Verify Proxy contract
await verifyContract(eventEmitterProxy.address, [eventEmitterImpl, initData]);

return ethers.getContractAt(
"TermVaultEventEmitter",
eventEmitterProxy.address,
Expand All @@ -135,7 +157,6 @@ async function main() {
);
console.log(JSON.stringify(params));

// Match your working pattern exactly
const Strategy = await ethers.getContractFactory(
"Strategy",
{
Expand All @@ -146,19 +167,19 @@ async function main() {
const strategyMeta = process.env.STRATEGY_META!;
const [strategyName, strategySymbol] = strategyMeta.trim().split(",").map(x => x.trim())
console.log(`Deploying strategy with (${strategyName}, ${strategySymbol})`);


// Create a struct that exactly matches the constructor's tuple type
const strategy = await Strategy.deploy(
strategyName,
strategySymbol,
params
);

await strategy.deployed();

console.log("Deployed strategy to:", strategy.address);

// Verify Strategy contract
await verifyContract(strategy.address, [strategyName, strategySymbol, params]);

// Post-deployment setup
const strategyContract = await ethers.getContractAt(
"ITokenizedStrategy",
Expand Down Expand Up @@ -220,4 +241,4 @@ main()
.catch((error) => {
console.error(error);
process.exit(1);
});
});
6 changes: 6 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import glob from "glob";
import fs from "fs";
import "hardhat-abi-exporter";
import "@typechain/hardhat";
import "@nomicfoundation/hardhat-verify";



Expand Down Expand Up @@ -56,6 +57,11 @@ const config: HardhatUserConfig = {
flat: false,
format: "json",
},
etherscan: {
// Your API key for Etherscan
// Obtain one at https://etherscan.io/
apiKey: process.env.ETHERSCAN_API_KEY
},
typechain: {
outDir: "typechain-types",
target: "ethers-v5",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"devDependencies": {
"@ethersproject/experimental": "^5.7.0",
"@nomicfoundation/hardhat-foundry": "^1.1.3",
"@nomicfoundation/hardhat-verify": "^2.0.12",
"@nomiclabs/hardhat-ethers": "^2.0.0",
"@typechain/ethers-v5": "^11.1.2",
"@typechain/hardhat": "^6.1.2",
Expand Down
36 changes: 34 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"@ethersproject/logger" "^5.7.0"
"@ethersproject/properties" "^5.7.0"

"@ethersproject/[email protected]", "@ethersproject/address@^5.7.0":
"@ethersproject/[email protected]", "@ethersproject/address@^5.0.2", "@ethersproject/address@^5.7.0":
version "5.7.0"
resolved "https://registry.yarnpkg.com/@ethersproject/address/-/address-5.7.0.tgz#19b56c4d74a3b0a46bfdbb6cfcc0a153fc697f37"
integrity sha512-9wYhYt7aghVGo758POM5nqcOMaE168Q6aRLJZwUmiqSrAungkG74gSSeKEIR7ukixesdRZGPgVqme6vmxs1fkA==
Expand Down Expand Up @@ -503,6 +503,21 @@
dependencies:
picocolors "^1.1.0"

"@nomicfoundation/hardhat-verify@^2.0.12":
version "2.0.12"
resolved "https://registry.yarnpkg.com/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.12.tgz#480819a245a2db0b127e473c62079f7b4f16daa8"
integrity sha512-Lg3Nu7DCXASQRVI/YysjuAX2z8jwOCbS0w5tz2HalWGSTZThqA0v9N0v0psHbKNqzPJa8bNOeapIVSziyJTnAg==
dependencies:
"@ethersproject/abi" "^5.1.2"
"@ethersproject/address" "^5.0.2"
cbor "^8.1.0"
debug "^4.1.1"
lodash.clonedeep "^4.5.0"
picocolors "^1.1.0"
semver "^6.3.0"
table "^6.8.0"
undici "^5.14.0"

"@nomicfoundation/[email protected]":
version "0.1.2"
resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.2.tgz#3a9c3b20d51360b20affb8f753e756d553d49557"
Expand Down Expand Up @@ -1022,6 +1037,13 @@ camelcase@^6.0.0, camelcase@^6.2.0:
resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a"
integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==

cbor@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/cbor/-/cbor-8.1.0.tgz#cfc56437e770b73417a2ecbfc9caf6b771af60d5"
integrity sha512-DwGjNW9omn6EwP70aXsn7FQJx5kO12tX0bZkaTjzdVFM6/7nhA4t0EENocKGx6D2Bch9PE2KzCUf5SceBdeijg==
dependencies:
nofilter "^3.1.0"

chalk@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424"
Expand Down Expand Up @@ -1947,6 +1969,11 @@ lodash.camelcase@^4.3.0:
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha512-TwuEnCnxbc3rAvhf/LbG7tJUDzhqXyFnv3dtzLOPgCG/hODL7WFnsbwktkD7yUV0RrreP/l1PALq/YSg6VvjlA==

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==

lodash.truncate@^4.4.2:
version "4.4.2"
resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193"
Expand Down Expand Up @@ -2096,6 +2123,11 @@ node-gyp-build@^4.2.0:
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.8.4.tgz#8a70ee85464ae52327772a90d66c6077a900cfc8"
integrity sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==

nofilter@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/nofilter/-/nofilter-3.1.0.tgz#c757ba68801d41ff930ba2ec55bab52ca184aa66"
integrity sha512-l2NNj07e9afPnhAhvgVrCD/oy2Ai1yfLpuo3EpiO1jFTsB4sFz6oIfAfSZyQzVpkZQ9xS8ZS5g1jCBgq4Hwo0g==

normalize-path@^3.0.0, normalize-path@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-3.0.0.tgz#0dcd69ff23a1c9b11fd0978316644a0388216a65"
Expand Down Expand Up @@ -2651,7 +2683,7 @@ table-layout@^1.0.2:
typical "^5.2.0"
wordwrapjs "^4.0.0"

table@^6.8.1:
table@^6.8.0, table@^6.8.1:
version "6.9.0"
resolved "https://registry.yarnpkg.com/table/-/table-6.9.0.tgz#50040afa6264141c7566b3b81d4d82c47a8668f5"
integrity sha512-9kY+CygyYM6j02t5YFHbNz2FN5QmYGv9zAjVp4lCDjlCw7amdckXlEt/bjMhUIfj4ThGRE4gCUH5+yGnNuPo5A==
Expand Down

0 comments on commit 779b6bb

Please sign in to comment.