Skip to content

Commit 0a179e2

Browse files
committed
Adds hardhat-deploy scripts for proxy contracts
1 parent 223a4c0 commit 0a179e2

7 files changed

+272
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { DeployFunction } from 'hardhat-deploy/types';
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3+
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
5+
const { deployments, getUnnamedAccounts } = hre;
6+
const { deploy, log } = deployments;
7+
8+
const [deployerAddress] = await getUnnamedAccounts();
9+
if (!deployerAddress) {
10+
throw new Error("No deployer address found.");
11+
}
12+
log(`Deployer address: ${deployerAddress}`);
13+
14+
const proxyAddress = process.env.PROXY;
15+
if (!proxyAddress) {
16+
throw new Error("PROXY environment variable not set. Please provide the address of the proxy contract.");
17+
}
18+
if (!hre.ethers.isAddress(proxyAddress)) {
19+
throw new Error(`Invalid address provided for PROXY: ${proxyAddress}`);
20+
}
21+
log(`Proxy address: ${proxyAddress}`);
22+
23+
await deployments
24+
.get("InverseApi3ReaderProxyV1")
25+
.catch(async () => {
26+
return deploy("InverseApi3ReaderProxyV1", {
27+
from: deployerAddress,
28+
args: [proxyAddress],
29+
log: true,
30+
});
31+
});
32+
};
33+
34+
export default func;
35+
func.tags = ['InverseApi3ReaderProxyV1'];
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { DeployFunction, DeploymentsExtension } from 'hardhat-deploy/types';
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3+
4+
const deployTestFeed = async (deployments: DeploymentsExtension, deployerAddress: string) => {
5+
const { address: scaledApi3FeedProxyV1Address } = await deployments
6+
.get("ScaledApi3FeedProxyV1")
7+
.catch(async () => {
8+
return deployments.deploy("ScaledApi3FeedProxyV1", {
9+
from: deployerAddress,
10+
args: ["0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473", 8],
11+
log: true,
12+
});
13+
});
14+
return scaledApi3FeedProxyV1Address;
15+
}
16+
17+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
18+
const { deployments, getUnnamedAccounts, network } = hre;
19+
const { deploy, log } = deployments;
20+
21+
const [deployerAddress] = await getUnnamedAccounts();
22+
if (!deployerAddress) {
23+
throw new Error("No deployer address found.");
24+
}
25+
log(`Deployer address: ${deployerAddress}`);
26+
27+
const feedAddress = network.name !== "hardhat" ? process.env.FEED : await deployTestFeed(deployments, deployerAddress);
28+
if (!feedAddress) {
29+
throw new Error("FEED environment variable not set. Please provide the address of the AggregatorV2V3Interface contract.");
30+
}
31+
if (!hre.ethers.isAddress(feedAddress)) {
32+
throw new Error(`Invalid address provided for FEED: ${feedAddress}`);
33+
}
34+
log(`Feed address: ${feedAddress}`);
35+
36+
await deployments
37+
.get("NormalizedApi3ReaderProxyV1")
38+
.catch(async () => {
39+
return deploy("NormalizedApi3ReaderProxyV1", {
40+
from: deployerAddress,
41+
args: [feedAddress],
42+
log: true,
43+
});
44+
});
45+
};
46+
47+
export default func;
48+
func.tags = ['NormalizedApi3ReaderProxyV1'];
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { DeployFunction } from 'hardhat-deploy/types';
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3+
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
5+
const { deployments, getUnnamedAccounts } = hre;
6+
const { deploy, log } = deployments;
7+
8+
const [deployerAddress] = await getUnnamedAccounts();
9+
if (!deployerAddress) {
10+
throw new Error("No deployer address found.");
11+
}
12+
log(`Deployer address: ${deployerAddress}`);
13+
14+
const proxy1Address = process.env.PROXY1;
15+
if (!proxy1Address) {
16+
throw new Error("PROXY1 environment variable not set. Please provide the address of the first proxy contract.");
17+
}
18+
if (!hre.ethers.isAddress(proxy1Address)) {
19+
throw new Error(`Invalid address provided for PROXY1: ${proxy1Address}`);
20+
}
21+
log(`Proxy 1 address: ${proxy1Address}`);
22+
23+
const proxy2Address = process.env.PROXY2;
24+
if (!proxy2Address) {
25+
throw new Error("PROXY2 environment variable not set. Please provide the address of the second proxy contract.");
26+
}
27+
if (!hre.ethers.isAddress(proxy2Address)) {
28+
throw new Error(`Invalid address provided for PROXY2: ${proxy2Address}`);
29+
}
30+
log(`Proxy 2 address: ${proxy2Address}`);
31+
32+
await deployments
33+
.get("ProductApi3ReaderProxyV1")
34+
.catch(async () => {
35+
return deploy("ProductApi3ReaderProxyV1", {
36+
from: deployerAddress,
37+
args: [proxy1Address, proxy2Address],
38+
log: true,
39+
});
40+
});
41+
};
42+
43+
export default func;
44+
func.tags = ['ProductApi3ReaderProxyV1'];
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { DeployFunction, DeploymentsExtension } from 'hardhat-deploy/types';
2+
import { HardhatRuntimeEnvironment } from 'hardhat/types';
3+
4+
const deployTestProxy = async (deployments: DeploymentsExtension, deployerAddress: string) => {
5+
const { address: inverseApi3ReaderProxyV1Address } = await deployments
6+
.get("InverseApi3ReaderProxyV1")
7+
.catch(async () => {
8+
return deployments.deploy("InverseApi3ReaderProxyV1", {
9+
from: deployerAddress,
10+
args: ["0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473"],
11+
log: true,
12+
});
13+
});
14+
return inverseApi3ReaderProxyV1Address;
15+
}
16+
17+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
18+
const { deployments, getUnnamedAccounts, network } = hre;
19+
const { deploy, log } = deployments;
20+
21+
const [deployerAddress] = await getUnnamedAccounts();
22+
if (!deployerAddress) {
23+
throw new Error("No deployer address found.");
24+
}
25+
log(`Deployer address: ${deployerAddress}`);
26+
27+
const proxyAddress = network.name !== "hardhat" ? process.env.PROXY : await deployTestProxy(deployments, deployerAddress);
28+
if (!proxyAddress) {
29+
throw new Error("PROXY environment variable not set. Please provide the address of the Api3ReaderProxy contract.");
30+
}
31+
if (!hre.ethers.isAddress(proxyAddress)) {
32+
throw new Error(`Invalid address provided for PROXY: ${proxyAddress}`);
33+
}
34+
log(`Proxy address: ${proxyAddress}`);
35+
36+
const decimals = process.env.DECIMALS ? parseInt(process.env.DECIMALS) : 18;
37+
log(`Decimals: ${decimals}`);
38+
39+
await deployments
40+
.get("ScaledApi3FeedProxyV1")
41+
.catch(async () => {
42+
return deploy("ScaledApi3FeedProxyV1", {
43+
from: deployerAddress,
44+
args: [proxyAddress, decimals],
45+
log: true,
46+
});
47+
});
48+
};
49+
50+
export default func;
51+
func.tags = ['ScaledApi3FeedProxyV1'];

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { hardhatConfig } from '@api3/contracts';
22
import '@nomicfoundation/hardhat-toolbox';
3+
import 'hardhat-deploy';
34
import type { HardhatUserConfig } from 'hardhat/config';
45

56
const config: HardhatUserConfig = {

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"scripts": {
2424
"build": "pnpm build:hardhat && tsc -p tsconfig.build.json",
2525
"build:hardhat": "hardhat --config hardhat.build.config.ts compile",
26+
"deploy:InverseApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags InverseApi3ReaderProxyV1",
27+
"deploy:NormalizedApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags NormalizedApi3ReaderProxyV1",
28+
"deploy:ProductApi3ReaderProxyV1": "hardhat deploy --network $NETWORK --tags ProductApi3ReaderProxyV1",
29+
"deploy:ScaledApi3FeedProxyV1": "hardhat deploy --network $NETWORK --tags ScaledApi3FeedProxyV1",
2630
"lint": "pnpm run prettier:check && pnpm run lint:eslint && pnpm run lint:solhint",
2731
"lint:solhint": "solhint ./contracts/**/*.sol",
2832
"lint:eslint": "eslint . --ext .js,.ts",
@@ -47,6 +51,7 @@
4751
"ethers": "^6.14.0",
4852
"glob": "^11.0.2",
4953
"hardhat": "^2.24.0",
54+
"hardhat-deploy": "^1.0.2",
5055
"prettier": "^3.5.3",
5156
"prettier-plugin-solidity": "^2.0.0",
5257
"solhint": "^5.1.0",

0 commit comments

Comments
 (0)