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' ] ;
0 commit comments