Skip to content

Commit

Permalink
suggested factory name
Browse files Browse the repository at this point in the history
  • Loading branch information
aazhou1 committed Dec 21, 2024
1 parent 42e08f5 commit 1686beb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 44 deletions.
1 change: 1 addition & 0 deletions .github/workflows/deploy-strategy-hardhat-mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
cache: yarn
- run: yarn install
- run: rm -rf src/test/kontrol/
- run: yarn hardhat compile
- run: yarn mainnet:deploy-strategy
env:
ASSET_ADDRESS: ${{ github.event.inputs.asset }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-strategy-hardhat-sepolia.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
cache: yarn
- run: yarn install
- run: rm -rf src/test/kontrol/
- run: yarn hardhat compile
- run: yarn sepolia:deploy-strategy
env:
ASSET_ADDRESS: ${{ github.event.inputs.asset }}
Expand Down
66 changes: 22 additions & 44 deletions hardhat-scripts/deploy-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hre from "hardhat";
import { ethers } from "hardhat"; // Use direct ethers import
import "@nomiclabs/hardhat-ethers";
import { NonceManager } from "@ethersproject/experimental";
import dotenv from "dotenv";
Expand All @@ -13,7 +13,7 @@ function stringToAddressArray(input: string): string[] {
if (!input) return [];
return input.split(",").map((addr) => {
const trimmed = addr.trim();
if (!hre.ethers.utils.isAddress(trimmed)) {
if (!ethers.utils.isAddress(trimmed)) {
throw new Error(`Invalid address: ${trimmed}`);
}
return trimmed;
Expand All @@ -37,7 +37,7 @@ async function checkUnderlyingVaultAsset(
underlyingVault: string,
managedSigner: Signer
) {
const vault = await hre.ethers.getContractAt(
const vault = await ethers.getContractAt(
"IERC4626",
underlyingVault,
managedSigner
Expand Down Expand Up @@ -84,14 +84,14 @@ async function deployEventEmitter(managedSigner: Signer) {
const devops = process.env.DEVOPS_ADDRESS!;

const EventEmitter = (
await hre.ethers.getContractFactory("TermVaultEventEmitter")
await ethers.getContractFactory("TermVaultEventEmitter")
).connect(managedSigner);
const eventEmitterImpl = await EventEmitter.deploy();
await eventEmitterImpl.deployed();

console.log("Deployed event emitter impl to:", eventEmitterImpl.address);

const Proxy = (await hre.ethers.getContractFactory("ERC1967Proxy")).connect(
const Proxy = (await ethers.getContractFactory("ERC1967Proxy")).connect(
managedSigner
);
const initData = EventEmitter.interface.encodeFunctionData("initialize", [
Expand All @@ -107,15 +107,14 @@ async function deployEventEmitter(managedSigner: Signer) {

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

return hre.ethers.getContractAt(
return ethers.getContractAt(
"TermVaultEventEmitter",
eventEmitterProxy.address,
managedSigner
);
}

async function main() {
await hre.run('compile');
// Try both Foundry and Hardhat artifact locations
const possibleArtifactPaths = [
path.join(process.cwd(), 'out/Strategy.sol/Strategy.json'),
Expand All @@ -137,18 +136,8 @@ for (const artifactPath of possibleArtifactPaths) {
}
}

// Log how Hardhat sees the contract
const artifactNames = await hre.artifacts.getAllFullyQualifiedNames();
console.log("All available artifacts:", artifactNames);

// Try getting the factory with explicit artifact loading
const artifact = await hre.artifacts.readArtifact("Strategy");
console.log("Hardhat found artifact:", {
name: artifact.contractName,
sourceName: artifact.sourceName
});
// Get the deployer's address and setup managed signer
const [deployer] = await hre.ethers.getSigners();
const [deployer] = await ethers.getSigners();
const managedSigner = new NonceManager(deployer as any) as unknown as Signer;

// Deploy EventEmitter first
Expand All @@ -163,9 +152,13 @@ console.log("Hardhat found artifact:", {
console.log(JSON.stringify(params));
console.log(await managedSigner.getAddress())

// Deploy Strategy
const strategyArtifact = await hre.artifacts.readArtifact("Strategy");
const Strategy = await hre.ethers.getContractFactoryFromArtifact(strategyArtifact);
// Match your working pattern exactly
const Strategy = await ethers.getContractFactory(
"Strategy",
{
signer: managedSigner,
}
);

const connectedStrategy = Strategy.connect(
managedSigner
Expand Down Expand Up @@ -199,37 +192,22 @@ console.log("Hardhat found artifact:", {
}
});
// Create a struct that exactly matches the constructor's tuple type
const deployParams = {
_name: strategyName,
_symbol: strategySymbol,
_params: {
asset: params.asset,
yearnVaultAddress: params.yearnVaultAddress,
discountRateAdapterAddress: params.discountRateAdapterAddress,
eventEmitter: params.eventEmitter,
deployer: params.deployer,
termController: params.termController,
repoTokenConcentrationLimit: params.repoTokenConcentrationLimit,
timeToMaturityThreshold: params.timeToMaturityThreshold,
newRequiredReserveRatio: params.newRequiredReserveRatio,
discountRateMarkup: params.discountRateMarkup
}
};

// Try deploying with the exact parameter names matching the ABI
const strategy = await connectedStrategy.deploy(
deployParams._name,
deployParams._symbol,
deployParams._params
const strategy = await Strategy.deploy(
strategyName,
strategySymbol,
params
);

await strategy.deployed();


console.log(JSON.stringify(strategy));
await strategy.deployed();

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

// Post-deployment setup
const strategyContract = await hre.ethers.getContractAt(
const strategyContract = await ethers.getContractAt(
"ITokenizedStrategy",
strategy.address,
managedSigner
Expand Down

0 comments on commit 1686beb

Please sign in to comment.