1- import  {  addTransaction  }  from  "../logging" ; 
1+ import  {  prepareAndLogTransaction  }  from  "../logging" ; 
22
33import  {  addUnderlyingsToMpo  }  from  "./utils" ; 
4- import  {  Address ,  encodeFunctionData  }  from  "viem" ; 
4+ import  {  Address ,  Hex ,   zeroAddress  }  from  "viem" ; 
55import  {  underlying  }  from  "../utils" ; 
66import  {  ChainlinkFeedBaseCurrency  }  from  "../../../../monorepo/packages/types" ; 
77import  {  ChainlinkDeployFnParams  }  from  "../../types" ; 
@@ -12,29 +12,31 @@ export const deployChainlinkOracle = async ({
1212  deployments, 
1313  deployConfig, 
1414  assets, 
15-   chainlinkAssets
15+   chainlinkAssets, 
16+   namePostfix
1617} : ChainlinkDeployFnParams ) : Promise < {  cpo : any ;  chainLinkv2 : any  } >  =>  { 
1718  const  {  deployer }  =  await  getNamedAccounts ( ) ; 
1819  const  publicClient  =  await  viem . getPublicClient ( ) ; 
19-   const  walletClient  =  await  viem . getWalletClient ( deployer  as  Address ) ; 
20-   let  tx ; 
20+   let  tx : Hex ; 
2121
2222  //// Chainlink Oracle 
2323
24+   const  contractName  =  [ "ChainlinkPriceOracleV2" ,  namePostfix ] . join ( "_" ) ; 
25+ 
2426  console . log ( "deployConfig.stableToken: " ,  deployConfig . stableToken ) ; 
2527  console . log ( "deployConfig.nativeTokenUsdChainlinkFeed: " ,  deployConfig . nativeTokenUsdChainlinkFeed ) ; 
26-   const  cpo  =  await  deployments . deploy ( "ChainlinkPriceOracleV2" ,  { 
28+   const  cpo  =  await  deployments . deploy ( contractName ,  { 
29+     contract : "ChainlinkPriceOracleV2" , 
2730    from : deployer , 
2831    args : [ ] , 
2932    log : true , 
3033    proxy : { 
3134      execute : { 
3235        init : { 
3336          methodName : "initialize" , 
34-           args : [ deployConfig . stableToken ,  deployConfig . nativeTokenUsdChainlinkFeed ] 
37+           args : [ deployConfig . stableToken ,  zeroAddress ] 
3538        } 
3639      } , 
37-       owner : deployer , 
3840      proxyContract : "OpenZeppelinTransparentProxy" 
3941    } , 
4042    waitConfirmations : 1 
@@ -44,7 +46,7 @@ export const deployChainlinkOracle = async ({
4446
4547  const  chainLinkv2  =  await  viem . getContractAt ( 
4648    "ChainlinkPriceOracleV2" , 
47-     ( await  deployments . get ( "ChainlinkPriceOracleV2" ) ) . address  as  Address 
49+     ( await  deployments . get ( contractName ) ) . address  as  Address 
4850  ) ; 
4951
5052  const  chainlinkAssetsToChange  =  [ ] ; 
@@ -75,37 +77,20 @@ export const deployChainlinkOracle = async ({
7577      await  publicClient . waitForTransactionReceipt ( {  hash : tx  } ) ; 
7678      console . log ( `Set ${ usdBasedFeeds . length }   USD price feeds for ChainlinkPriceOracleV2 at ${ tx }  ` ) ; 
7779    }  else  { 
78-       const  tx  =  await  walletClient . prepareTransactionRequest ( { 
79-         account : ( await  chainLinkv2 . read . owner ( ) )  as  Address , 
80-         to : chainLinkv2 . address , 
81-         data : encodeFunctionData ( { 
82-           abi : chainLinkv2 . abi , 
83-           functionName : "setPriceFeeds" , 
84-           args : [ 
85-             usdBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
86-             usdBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
87-             feedCurrency 
88-           ] 
89-         } ) 
90-       } ) ; 
91-       addTransaction ( { 
92-         to : tx . to , 
93-         value : tx . value  ? tx . value . toString ( )  : "0" , 
94-         data : null , 
95-         contractMethod : { 
96-           inputs : [ 
97-             {  internalType : "address[]" ,  name : "underlyings" ,  type : "address[]"  } , 
98-             {  internalType : "address[]" ,  name : "feeds" ,  type : "address[]"  } , 
99-             {  internalType : "uint8" ,  name : "baseCurrency" ,  type : "uint8"  } 
100-           ] , 
101-           name : "setPriceFeeds" , 
102-           payable : false 
103-         } , 
104-         contractInputsValues : { 
105-           underlyings : usdBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
106-           feeds : usdBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
107-           baseCurrency : feedCurrency 
108-         } 
80+       await  prepareAndLogTransaction ( { 
81+         contractInstance : chainLinkv2 , 
82+         description : `Set ${ usdBasedFeeds . length }   USD price feeds for ChainlinkPriceOracleV2` , 
83+         functionName : "setPriceFeeds" , 
84+         args : [ 
85+           usdBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
86+           usdBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
87+           feedCurrency 
88+         ] , 
89+         inputs : [ 
90+           {  internalType : "address[]" ,  name : "underlyings" ,  type : "address[]"  } , 
91+           {  internalType : "address[]" ,  name : "feeds" ,  type : "address[]"  } , 
92+           {  internalType : "uint8" ,  name : "baseCurrency" ,  type : "uint8"  } 
93+         ] 
10994      } ) ; 
11095      console . log ( `Logged Transaction to set ${ usdBasedFeeds . length }   USD price feeds for ChainlinkPriceOracleV2` ) ; 
11196    } 
@@ -121,37 +106,20 @@ export const deployChainlinkOracle = async ({
121106      await  publicClient . waitForTransactionReceipt ( {  hash : tx  } ) ; 
122107      console . log ( `Set ${ ethBasedFeeds . length }   native price feeds for ChainlinkPriceOracleV2` ) ; 
123108    }  else  { 
124-       tx  =  await  walletClient . prepareTransactionRequest ( { 
125-         account : ( await  chainLinkv2 . read . owner ( ) )  as  Address , 
126-         to : chainLinkv2 . address , 
127-         data : encodeFunctionData ( { 
128-           abi : chainLinkv2 . abi , 
129-           functionName : "setPriceFeeds" , 
130-           args : [ 
131-             ethBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
132-             ethBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
133-             feedCurrency 
134-           ] 
135-         } ) 
136-       } ) ; 
137-       addTransaction ( { 
138-         to : tx . to , 
139-         value : tx . value  ? tx . value . toString ( )  : "0" , 
140-         data : null , 
141-         contractMethod : { 
142-           inputs : [ 
143-             {  internalType : "address[]" ,  name : "underlyings" ,  type : "address[]"  } , 
144-             {  internalType : "address[]" ,  name : "feeds" ,  type : "address[]"  } , 
145-             {  internalType : "uint8" ,  name : "baseCurrency" ,  type : "uint8"  } 
146-           ] , 
147-           name : "setPriceFeeds" , 
148-           payable : false 
149-         } , 
150-         contractInputsValues : { 
151-           underlyings : ethBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
152-           feeds : ethBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
153-           baseCurrency : feedCurrency 
154-         } 
109+       await  prepareAndLogTransaction ( { 
110+         contractInstance : chainLinkv2 , 
111+         description : `Set ${ ethBasedFeeds . length }   USD price feeds for ChainlinkPriceOracleV2` , 
112+         functionName : "setPriceFeeds" , 
113+         args : [ 
114+           ethBasedFeeds . map ( ( c )  =>  underlying ( assets ,  c . symbol ) ) , 
115+           ethBasedFeeds . map ( ( c )  =>  c . aggregator ) , 
116+           feedCurrency 
117+         ] , 
118+         inputs : [ 
119+           {  internalType : "address[]" ,  name : "underlyings" ,  type : "address[]"  } , 
120+           {  internalType : "address[]" ,  name : "feeds" ,  type : "address[]"  } , 
121+           {  internalType : "uint8" ,  name : "baseCurrency" ,  type : "uint8"  } 
122+         ] 
155123      } ) ; 
156124      console . log ( `Logged Transaction to set ${ ethBasedFeeds . length }   ETH price feeds for ChainlinkPriceOracleV2` ) ; 
157125    } 
@@ -163,44 +131,28 @@ export const deployChainlinkOracle = async ({
163131    "MasterPriceOracle" , 
164132    ( await  deployments . get ( "MasterPriceOracle" ) ) . address  as  Address 
165133  ) ; 
166-   await  addUnderlyingsToMpo ( mpo  as  any ,  underlyings ,  chainLinkv2 . address ,  deployer ,  publicClient ,   walletClient ) ; 
134+   await  addUnderlyingsToMpo ( mpo  as  any ,  underlyings ,  chainLinkv2 . address ,  deployer ,  publicClient ) ; 
167135
168136  const  addressesProvider  =  await  viem . getContractAt ( 
169137    "AddressesProvider" , 
170138    ( await  deployments . get ( "AddressesProvider" ) ) . address  as  Address 
171139  ) ; 
172-   const  chainLinkv2Address  =  await  addressesProvider . read . getAddress ( [ "ChainlinkPriceOracleV2" ] ) ; 
140+   const  chainLinkv2Address  =  await  addressesProvider . read . getAddress ( [ contractName ] ) ; 
173141  if  ( chainLinkv2Address  !==  chainLinkv2 . address )  { 
174142    if  ( ( ( await  addressesProvider . read . owner ( ) )  as  Address ) . toLowerCase ( )  ===  deployer . toLowerCase ( ) )  { 
175-       tx  =  await  addressesProvider . write . setAddress ( [ "ChainlinkPriceOracleV2" ,  chainLinkv2 . address ] ) ; 
143+       tx  =  await  addressesProvider . write . setAddress ( [ contractName ,  chainLinkv2 . address ] ) ; 
176144      await  publicClient . waitForTransactionReceipt ( {  hash : tx  } ) ; 
177-       console . log ( `setAddress ChainlinkPriceOracleV2  at ${ tx }  ` ) ; 
145+       console . log ( `setAddress ${ contractName }   at ${ tx }  ` ) ; 
178146    }  else  { 
179-       tx  =  await  walletClient . prepareTransactionRequest ( { 
180-         account : ( await  addressesProvider . read . owner ( ) )  as  Address , 
181-         to : addressesProvider . address , 
182-         data : encodeFunctionData ( { 
183-           abi : addressesProvider . abi , 
184-           functionName : "setAddress" , 
185-           args : [ "ChainlinkPriceOracleV2" ,  chainLinkv2 . address ] 
186-         } ) 
187-       } ) ; 
188-       addTransaction ( { 
189-         to : tx . to , 
190-         value : tx . value  ? tx . value . toString ( )  : "0" , 
191-         data : null , 
192-         contractMethod : { 
193-           inputs : [ 
194-             {  internalType : "string" ,  name : "id" ,  type : "string"  } , 
195-             {  internalType : "address" ,  name : "newAddress" ,  type : "address"  } 
196-           ] , 
197-           name : "setAddress" , 
198-           payable : false 
199-         } , 
200-         contractInputsValues : { 
201-           id : "ChainlinkPriceOracleV2" , 
202-           newAddress : chainLinkv2 . address 
203-         } 
147+       await  prepareAndLogTransaction ( { 
148+         contractInstance : addressesProvider , 
149+         description : `setAddress ${ contractName }  ` , 
150+         functionName : "setAddress" , 
151+         args : [ contractName ,  chainLinkv2 . address ] , 
152+         inputs : [ 
153+           {  internalType : "string" ,  name : "id" ,  type : "string"  } , 
154+           {  internalType : "address" ,  name : "newAddress" ,  type : "address"  } 
155+         ] 
204156      } ) ; 
205157      console . log ( "Logged Transaction to setAddress ChainlinkPriceOracleV2 on AddressProvider" ) ; 
206158    } 
0 commit comments