|
| 1 | +import type { HardhatRuntimeEnvironment } from 'hardhat/types'; |
| 2 | +import type { DeploymentsExtension } from 'hardhat-deploy/types'; |
| 3 | + |
| 4 | +import { getDeploymentName } from '../src'; |
| 5 | + |
| 6 | +export const CONTRACT_NAME = 'ScaledApi3FeedProxyV1'; |
| 7 | + |
| 8 | +const deployTestProxy = async (deployments: DeploymentsExtension, deployerAddress: string) => { |
| 9 | + const { address: inverseApi3ReaderProxyV1Address } = await deployments |
| 10 | + .get('InverseApi3ReaderProxyV1') |
| 11 | + .catch(async () => { |
| 12 | + return deployments.deploy('InverseApi3ReaderProxyV1', { |
| 13 | + from: deployerAddress, |
| 14 | + args: ['0x5b0cf2b36a65a6BB085D501B971e4c102B9Cd473'], |
| 15 | + log: true, |
| 16 | + }); |
| 17 | + }); |
| 18 | + return inverseApi3ReaderProxyV1Address; |
| 19 | +}; |
| 20 | + |
| 21 | +module.exports = async (hre: HardhatRuntimeEnvironment) => { |
| 22 | + const { getUnnamedAccounts, deployments, network, ethers, run } = hre; |
| 23 | + const { deploy, log } = deployments; |
| 24 | + |
| 25 | + const [deployerAddress] = await getUnnamedAccounts(); |
| 26 | + if (!deployerAddress) { |
| 27 | + throw new Error('No deployer address found.'); |
| 28 | + } |
| 29 | + log(`Deployer address: ${deployerAddress}`); |
| 30 | + |
| 31 | + if (!process.env.DECIMALS) { |
| 32 | + throw new Error('DECIMALS environment variable not set. Please provide the number of decimals to use.'); |
| 33 | + } |
| 34 | + const decimals = Number.parseInt(process.env.DECIMALS, 10); |
| 35 | + log(`Decimals: ${decimals}`); |
| 36 | + |
| 37 | + const proxyAddress = |
| 38 | + network.name === 'hardhat' ? await deployTestProxy(deployments, deployerAddress) : process.env.PROXY; |
| 39 | + if (!proxyAddress) { |
| 40 | + throw new Error('PROXY environment variable not set. Please provide the address of the Api3ReaderProxy contract.'); |
| 41 | + } |
| 42 | + if (!ethers.isAddress(proxyAddress)) { |
| 43 | + throw new Error(`Invalid address provided for PROXY: ${proxyAddress}`); |
| 44 | + } |
| 45 | + log(`Proxy address: ${proxyAddress}`); |
| 46 | + |
| 47 | + const isLocalNetwork = network.name === 'hardhat' || network.name === 'localhost'; |
| 48 | + |
| 49 | + const confirmations = isLocalNetwork ? 1 : 5; |
| 50 | + log(`Deployment confirmations: ${confirmations}`); |
| 51 | + |
| 52 | + const constructorArgs = [proxyAddress, decimals]; |
| 53 | + const constructorArgTypes = ['address', 'uint8']; |
| 54 | + |
| 55 | + const deploymentName = getDeploymentName(CONTRACT_NAME, constructorArgTypes, constructorArgs); |
| 56 | + log(`Generated deterministic deployment name for this instance: ${deploymentName}`); |
| 57 | + |
| 58 | + const deployment = await deploy(deploymentName, { |
| 59 | + contract: CONTRACT_NAME, |
| 60 | + from: deployerAddress, |
| 61 | + args: constructorArgs, |
| 62 | + log: true, |
| 63 | + waitConfirmations: confirmations, |
| 64 | + }); |
| 65 | + |
| 66 | + if (isLocalNetwork) { |
| 67 | + log('Skipping verification on local network.'); |
| 68 | + return; |
| 69 | + } |
| 70 | + |
| 71 | + log( |
| 72 | + `Attempting verification of ${deploymentName} (contract type ${CONTRACT_NAME}) at ${deployment.address} (already waited for confirmations)...` |
| 73 | + ); |
| 74 | + await run('verify:verify', { |
| 75 | + address: deployment.address, |
| 76 | + constructorArguments: deployment.args, |
| 77 | + }); |
| 78 | +}; |
| 79 | +module.exports.tags = [CONTRACT_NAME]; |
0 commit comments