@@ -64,49 +64,87 @@ task("market:upgrade:safe", "Upgrades a market's implementation")
64
64
let { pluginAddress } = taskArgs ;
65
65
66
66
const cTokenDelegator = await viem . getContractAt ( "CErc20Delegator" , marketAddress ) ;
67
-
68
67
const cfe = await viem . getContractAt (
69
68
"CTokenFirstExtension" ,
70
69
( await deployments . get ( "CTokenFirstExtension" ) ) . address as Address
71
70
) ;
71
+ const ap = await viem . getContractAt (
72
+ "AddressesProvider" ,
73
+ ( await deployments . get ( "AddressesProvider" ) ) . address as Address
74
+ ) ;
75
+
72
76
const impl = await cTokenDelegator . read . implementation ( ) ;
73
77
const extensions = await cTokenDelegator . read . _listExtensions ( ) ;
74
-
78
+ const comptroller = await cTokenDelegator . read . comptroller ( ) ;
79
+ const comptrollerAsExt = await viem . getContractAt ( "IonicComptroller" , comptroller as Address ) ;
80
+ const ctokenAsExt = await viem . getContractAt ( "CTokenFirstExtension" , marketAddress )
81
+
75
82
if (
76
83
impl . toLowerCase ( ) != implementationAddress . toLowerCase ( ) ||
77
84
extensions . length == 0 ||
78
- extensions [ 0 ] . toLowerCase ( ) != cfe . address . toLowerCase ( )
85
+ extensions [ 1 ] . toLowerCase ( ) != cfe . address . toLowerCase ( )
79
86
) {
80
87
if ( ! pluginAddress ) {
81
88
pluginAddress = zeroAddress ;
82
89
}
83
-
84
- console . log ( extensions . length )
85
- console . log ( extensions [ 0 ] . toLowerCase ( ) )
86
- console . log ( cfe . address . toLowerCase ( ) )
87
-
88
90
const implementationData = encodeAbiParameters ( parseAbiParameters ( "address" ) , [ pluginAddress ] ) ;
89
-
90
91
console . log ( `Setting implementation to ${ implementationAddress } with plugin ${ pluginAddress } ` ) ;
91
92
92
- await prepareAndLogTransaction ( {
93
- contractInstance : cTokenDelegator ,
94
- functionName : "_setImplementationSafe" ,
95
- args : [ implementationAddress , implementationData ] ,
96
- description : `Setting new implementation on ${ cTokenDelegator . address } ` ,
97
- inputs : [
98
- { internalType : "address" , name : "implementation_" , type : "address" } ,
99
- { internalType : "bytes" , name : "implementationData" , type : "bytes" }
100
- ]
101
- } ) ;
93
+ const comptrollerAdmin = await comptrollerAsExt . read . admin ( )
94
+ if ( comptrollerAdmin . toLowerCase ( ) !== deployer . toLowerCase ( ) ) {
95
+ await prepareAndLogTransaction ( {
96
+ contractInstance : cTokenDelegator ,
97
+ functionName : "_setImplementationSafe" ,
98
+ args : [ implementationAddress , implementationData ] ,
99
+ description : `Setting new implementation on ${ cTokenDelegator . address } ` ,
100
+ inputs : [
101
+ { internalType : "address" , name : "implementation_" , type : "address" } ,
102
+ { internalType : "bytes" , name : "implementationData" , type : "bytes" }
103
+ ]
104
+ } ) ;
105
+ await prepareAndLogTransaction ( {
106
+ contractInstance : ctokenAsExt ,
107
+ functionName : "_setAddressesProvider" ,
108
+ args : [ ap . address ] ,
109
+ description : `Setting AddressesProvider on ${ marketAddress } ` ,
110
+ inputs : [
111
+ { internalType : "address" , name : "_ap" , type : "address" }
112
+ ]
113
+ } ) ;
114
+ } else {
115
+ console . log ( `Setting implementation to ${ implementationAddress } ` ) ;
116
+ const setImplementationTx = await cTokenDelegator . write . _setImplementationSafe ( [
117
+ implementationAddress ,
118
+ implementationData
119
+ ] ) ;
120
+ const receipt = await publicClient . waitForTransactionReceipt ( {
121
+ hash : setImplementationTx
122
+ } ) ;
123
+ if ( receipt . status !== "success" ) {
124
+ throw `Failed set implementation to ${ implementationAddress } ` ;
125
+ }
126
+ console . log (
127
+ `Implementation successfully set to ${ implementationAddress } : ${ setImplementationTx } `
128
+ ) ;
129
+
130
+ console . log ( `Setting AP to to ${ ap . address } ` ) ;
131
+ const setAPTX = await ctokenAsExt . write . _setAddressesProvider ( [ ap . address ] ) ;
132
+ const receiptAP = await publicClient . waitForTransactionReceipt ( {
133
+ hash : setAPTX
134
+ } ) ;
135
+ if ( receiptAP . status !== "success" ) {
136
+ throw `Failed set AP to ${ ap . address } ` ;
137
+ }
138
+ console . log ( `AP successfully set to ${ ap . address } ` ) ;
139
+ }
102
140
103
141
if ( pluginAddress != zeroAddress ) {
104
142
const cTokenPluginInstance = await viem . getContractAt ( "ICErc20Plugin" , marketAddress ) ;
105
143
console . log ( `with plugin ${ await cTokenPluginInstance . read . plugin ( ) } ` ) ;
106
144
}
107
145
} else {
108
146
console . log (
109
- `market ${ marketAddress } impl ${ impl } already eq ${ implementationAddress } and extension ${ cfe . address } eq ${ extensions [ 0 ] } `
147
+ `market ${ marketAddress } impl ${ impl } already eq ${ implementationAddress } and extension ${ cfe . address } eq ${ extensions [ 1 ] } `
110
148
) ;
111
149
}
112
150
} ) ;
@@ -126,7 +164,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
126
164
"FeeDistributor" ,
127
165
( await deployments . get ( "FeeDistributor" ) ) . address as Address
128
166
) ;
129
-
130
167
const ionicUniV3Liquidator = await viem . getContractAt (
131
168
"IonicUniV3Liquidator" ,
132
169
( await deployments . get ( "IonicUniV3Liquidator" ) ) . address as Address
@@ -163,24 +200,9 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
163
200
marketAddress : market ,
164
201
implementationAddress : latestImpl ,
165
202
} ) ;
166
- const ap = await viem . getContractAt (
167
- "AddressesProvider" ,
168
- ( await deployments . get ( "AddressesProvider" ) ) . address as Address
169
- ) ;
170
- const ctokenAsExt = await viem . getContractAt ( "CTokenFirstExtension" , market )
171
-
172
- await prepareAndLogTransaction ( {
173
- contractInstance : ctokenAsExt ,
174
- functionName : "_setAddressesProvider" ,
175
- args : [ ap . address ] ,
176
- description : `Setting AddressesProvider on ${ market } ` ,
177
- inputs : [
178
- { internalType : "address" , name : "_ap" , type : "address" }
179
- ]
180
- } ) ;
181
203
}
182
204
} catch ( e ) {
183
- console . error ( `error while upgrading the pool ${ JSON . stringify ( pool ) } ` , e ) ;
205
+ console . error ( `error while upgrading the pool` , e ) ;
184
206
}
185
207
}
186
208
} ) ;
0 commit comments