Skip to content

Adds hardhat-deploy scripts for proxy contracts #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: morpho-market
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions deploy/001_deploy_InverseApi3ReaderProxyV1.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files are somehow excluded from linter (or not linted).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so 🤔

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts } = hre;
const { deploy, log } = deployments;

const [deployerAddress] = await getUnnamedAccounts();
if (!deployerAddress) {
throw new Error("No deployer address found.");
}
log(`Deployer address: ${deployerAddress}`);

const proxyAddress = process.env.PROXY;
if (!proxyAddress) {
throw new Error("PROXY environment variable not set. Please provide the address of the proxy contract.");
}
if (!hre.ethers.isAddress(proxyAddress)) {
throw new Error(`Invalid address provided for PROXY: ${proxyAddress}`);
}
log(`Proxy address: ${proxyAddress}`);

await deployments
.get("InverseApi3ReaderProxyV1")
.catch(async () => {
return deploy("InverseApi3ReaderProxyV1", {
from: deployerAddress,
args: [proxyAddress],
log: true,
});
});
};

export default func;
func.tags = ['InverseApi3ReaderProxyV1'];
48 changes: 48 additions & 0 deletions deploy/002_deploy_NormalizedApi3ReaderProxyV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { DeployFunction, DeploymentsExtension } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployTestFeed = async (deployments: DeploymentsExtension, deployerAddress: string) => {
const { address: scaledApi3FeedProxyV1Address } = await deployments
.get("ScaledApi3FeedProxyV1")
.catch(async () => {
return deployments.deploy("ScaledApi3FeedProxyV1", {
from: deployerAddress,
args: ["0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473", 8],
log: true,
});
});
return scaledApi3FeedProxyV1Address;
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts, network } = hre;
const { deploy, log } = deployments;

const [deployerAddress] = await getUnnamedAccounts();
if (!deployerAddress) {
throw new Error("No deployer address found.");
}
log(`Deployer address: ${deployerAddress}`);

const feedAddress = network.name !== "hardhat" ? process.env.FEED : await deployTestFeed(deployments, deployerAddress);
if (!feedAddress) {
throw new Error("FEED environment variable not set. Please provide the address of the AggregatorV2V3Interface contract.");
}
if (!hre.ethers.isAddress(feedAddress)) {
throw new Error(`Invalid address provided for FEED: ${feedAddress}`);
}
log(`Feed address: ${feedAddress}`);

await deployments
.get("NormalizedApi3ReaderProxyV1")
.catch(async () => {
return deploy("NormalizedApi3ReaderProxyV1", {
from: deployerAddress,
args: [feedAddress],
log: true,
});
});
};

export default func;
func.tags = ['NormalizedApi3ReaderProxyV1'];
44 changes: 44 additions & 0 deletions deploy/003_deploy_ProductApi3ReaderProxyV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { DeployFunction } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts } = hre;
const { deploy, log } = deployments;

const [deployerAddress] = await getUnnamedAccounts();
if (!deployerAddress) {
throw new Error("No deployer address found.");
}
log(`Deployer address: ${deployerAddress}`);

const proxy1Address = process.env.PROXY1;
if (!proxy1Address) {
throw new Error("PROXY1 environment variable not set. Please provide the address of the first proxy contract.");
}
if (!hre.ethers.isAddress(proxy1Address)) {
throw new Error(`Invalid address provided for PROXY1: ${proxy1Address}`);
}
log(`Proxy 1 address: ${proxy1Address}`);

const proxy2Address = process.env.PROXY2;
if (!proxy2Address) {
throw new Error("PROXY2 environment variable not set. Please provide the address of the second proxy contract.");
}
if (!hre.ethers.isAddress(proxy2Address)) {
throw new Error(`Invalid address provided for PROXY2: ${proxy2Address}`);
}
log(`Proxy 2 address: ${proxy2Address}`);

await deployments
.get("ProductApi3ReaderProxyV1")
.catch(async () => {
return deploy("ProductApi3ReaderProxyV1", {
from: deployerAddress,
args: [proxy1Address, proxy2Address],
log: true,
});
});
};

export default func;
func.tags = ['ProductApi3ReaderProxyV1'];
51 changes: 51 additions & 0 deletions deploy/004_deploy_ScaledApi3FeedProxyV1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { DeployFunction, DeploymentsExtension } from 'hardhat-deploy/types';
import { HardhatRuntimeEnvironment } from 'hardhat/types';

const deployTestProxy = async (deployments: DeploymentsExtension, deployerAddress: string) => {
const { address: inverseApi3ReaderProxyV1Address } = await deployments
.get("InverseApi3ReaderProxyV1")
.catch(async () => {
return deployments.deploy("InverseApi3ReaderProxyV1", {
from: deployerAddress,
args: ["0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473"],
log: true,
});
});
return inverseApi3ReaderProxyV1Address;
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getUnnamedAccounts, network } = hre;
const { deploy, log } = deployments;

const [deployerAddress] = await getUnnamedAccounts();
if (!deployerAddress) {
throw new Error("No deployer address found.");
}
log(`Deployer address: ${deployerAddress}`);

const proxyAddress = network.name !== "hardhat" ? process.env.PROXY : await deployTestProxy(deployments, deployerAddress);
if (!proxyAddress) {
throw new Error("PROXY environment variable not set. Please provide the address of the Api3ReaderProxy contract.");
}
if (!hre.ethers.isAddress(proxyAddress)) {
throw new Error(`Invalid address provided for PROXY: ${proxyAddress}`);
}
log(`Proxy address: ${proxyAddress}`);

const decimals = process.env.DECIMALS ? parseInt(process.env.DECIMALS) : 18;
log(`Decimals: ${decimals}`);

await deployments
.get("ScaledApi3FeedProxyV1")
.catch(async () => {
return deploy("ScaledApi3FeedProxyV1", {
from: deployerAddress,
args: [proxyAddress, decimals],
log: true,
});
});
};

export default func;
func.tags = ['ScaledApi3FeedProxyV1'];
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { hardhatConfig } from '@api3/contracts';
import '@nomicfoundation/hardhat-toolbox';
import 'hardhat-deploy';
import type { HardhatUserConfig } from 'hardhat/config';

const config: HardhatUserConfig = {
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"scripts": {
"build": "pnpm build:hardhat && tsc -p tsconfig.build.json",
"build:hardhat": "hardhat --config hardhat.build.config.ts compile",
"deploy:InverseApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags InverseApi3ReaderProxyV1",
"deploy:NormalizedApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags NormalizedApi3ReaderProxyV1",
"deploy:ProductApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags ProductApi3ReaderProxyV1",
"deploy:ScaledApi3FeedProxyV1": "hardhat deploy --network $NETWORK --tags ScaledApi3FeedProxyV1",
"lint": "pnpm run prettier:check && pnpm run lint:eslint && pnpm run lint:solhint",
"lint:solhint": "solhint ./contracts/**/*.sol",
"lint:eslint": "eslint . --ext .js,.ts",
Expand All @@ -47,6 +51,7 @@
"ethers": "^6.14.0",
"glob": "^11.0.2",
"hardhat": "^2.24.0",
"hardhat-deploy": "^1.0.2",
"prettier": "^3.5.3",
"prettier-plugin-solidity": "^2.0.0",
"solhint": "^5.1.0",
Expand Down
Loading