1
- import { addTransaction } from "../logging" ;
1
+ import { prepareAndLogTransaction } from "../logging" ;
2
2
3
3
import { addUnderlyingsToMpo } from "./utils" ;
4
- import { Address , encodeFunctionData } from "viem" ;
4
+ import { Address , Hex , zeroAddress } from "viem" ;
5
5
import { underlying } from "../utils" ;
6
6
import { ChainlinkFeedBaseCurrency } from "../../../../monorepo/packages/types" ;
7
7
import { ChainlinkDeployFnParams } from "../../types" ;
@@ -12,29 +12,31 @@ export const deployChainlinkOracle = async ({
12
12
deployments,
13
13
deployConfig,
14
14
assets,
15
- chainlinkAssets
15
+ chainlinkAssets,
16
+ namePostfix
16
17
} : ChainlinkDeployFnParams ) : Promise < { cpo : any ; chainLinkv2 : any } > => {
17
18
const { deployer } = await getNamedAccounts ( ) ;
18
19
const publicClient = await viem . getPublicClient ( ) ;
19
- const walletClient = await viem . getWalletClient ( deployer as Address ) ;
20
- let tx ;
20
+ let tx : Hex ;
21
21
22
22
//// Chainlink Oracle
23
23
24
+ const contractName = [ "ChainlinkPriceOracleV2" , namePostfix ] . join ( "_" ) ;
25
+
24
26
console . log ( "deployConfig.stableToken: " , deployConfig . stableToken ) ;
25
27
console . log ( "deployConfig.nativeTokenUsdChainlinkFeed: " , deployConfig . nativeTokenUsdChainlinkFeed ) ;
26
- const cpo = await deployments . deploy ( "ChainlinkPriceOracleV2" , {
28
+ const cpo = await deployments . deploy ( contractName , {
29
+ contract : "ChainlinkPriceOracleV2" ,
27
30
from : deployer ,
28
31
args : [ ] ,
29
32
log : true ,
30
33
proxy : {
31
34
execute : {
32
35
init : {
33
36
methodName : "initialize" ,
34
- args : [ deployConfig . stableToken , deployConfig . nativeTokenUsdChainlinkFeed ]
37
+ args : [ deployConfig . stableToken , zeroAddress ]
35
38
}
36
39
} ,
37
- owner : deployer ,
38
40
proxyContract : "OpenZeppelinTransparentProxy"
39
41
} ,
40
42
waitConfirmations : 1
@@ -44,7 +46,7 @@ export const deployChainlinkOracle = async ({
44
46
45
47
const chainLinkv2 = await viem . getContractAt (
46
48
"ChainlinkPriceOracleV2" ,
47
- ( await deployments . get ( "ChainlinkPriceOracleV2" ) ) . address as Address
49
+ ( await deployments . get ( contractName ) ) . address as Address
48
50
) ;
49
51
50
52
const chainlinkAssetsToChange = [ ] ;
@@ -75,37 +77,20 @@ export const deployChainlinkOracle = async ({
75
77
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
76
78
console . log ( `Set ${ usdBasedFeeds . length } USD price feeds for ChainlinkPriceOracleV2 at ${ tx } ` ) ;
77
79
} 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
+ ]
109
94
} ) ;
110
95
console . log ( `Logged Transaction to set ${ usdBasedFeeds . length } USD price feeds for ChainlinkPriceOracleV2` ) ;
111
96
}
@@ -121,37 +106,20 @@ export const deployChainlinkOracle = async ({
121
106
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
122
107
console . log ( `Set ${ ethBasedFeeds . length } native price feeds for ChainlinkPriceOracleV2` ) ;
123
108
} 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
+ ]
155
123
} ) ;
156
124
console . log ( `Logged Transaction to set ${ ethBasedFeeds . length } ETH price feeds for ChainlinkPriceOracleV2` ) ;
157
125
}
@@ -163,44 +131,28 @@ export const deployChainlinkOracle = async ({
163
131
"MasterPriceOracle" ,
164
132
( await deployments . get ( "MasterPriceOracle" ) ) . address as Address
165
133
) ;
166
- await addUnderlyingsToMpo ( mpo as any , underlyings , chainLinkv2 . address , deployer , publicClient , walletClient ) ;
134
+ await addUnderlyingsToMpo ( mpo as any , underlyings , chainLinkv2 . address , deployer , publicClient ) ;
167
135
168
136
const addressesProvider = await viem . getContractAt (
169
137
"AddressesProvider" ,
170
138
( await deployments . get ( "AddressesProvider" ) ) . address as Address
171
139
) ;
172
- const chainLinkv2Address = await addressesProvider . read . getAddress ( [ "ChainlinkPriceOracleV2" ] ) ;
140
+ const chainLinkv2Address = await addressesProvider . read . getAddress ( [ contractName ] ) ;
173
141
if ( chainLinkv2Address !== chainLinkv2 . address ) {
174
142
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 ] ) ;
176
144
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
177
- console . log ( `setAddress ChainlinkPriceOracleV2 at ${ tx } ` ) ;
145
+ console . log ( `setAddress ${ contractName } at ${ tx } ` ) ;
178
146
} 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
+ ]
204
156
} ) ;
205
157
console . log ( "Logged Transaction to setAddress ChainlinkPriceOracleV2 on AddressProvider" ) ;
206
158
}
0 commit comments