@@ -64,45 +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
90
const implementationData = encodeAbiParameters ( parseAbiParameters ( "address" ) , [ pluginAddress ] ) ;
85
-
86
91
console . log ( `Setting implementation to ${ implementationAddress } with plugin ${ pluginAddress } ` ) ;
87
92
88
- await prepareAndLogTransaction ( {
89
- contractInstance : cTokenDelegator ,
90
- functionName : "_setImplementationSafe" ,
91
- args : [ implementationAddress , implementationData ] ,
92
- description : `Setting new implementation on ${ cTokenDelegator . address } ` ,
93
- inputs : [
94
- { internalType : "address" , name : "implementation_" , type : "address" } ,
95
- { internalType : "bytes" , name : "implementationData" , type : "bytes" }
96
- ]
97
- } ) ;
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
+ }
98
140
99
141
if ( pluginAddress != zeroAddress ) {
100
142
const cTokenPluginInstance = await viem . getContractAt ( "ICErc20Plugin" , marketAddress ) ;
101
143
console . log ( `with plugin ${ await cTokenPluginInstance . read . plugin ( ) } ` ) ;
102
144
}
103
145
} else {
104
146
console . log (
105
- `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 ] } `
106
148
) ;
107
149
}
108
150
} ) ;
@@ -122,12 +164,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
122
164
"FeeDistributor" ,
123
165
( await deployments . get ( "FeeDistributor" ) ) . address as Address
124
166
) ;
125
-
126
- const addressProvider = await viem . getContractAt (
127
- "AddressesProvider" ,
128
- ( await deployments . get ( "AddressesProvider" ) ) . address as Address
129
- ) ;
130
-
131
167
const ionicUniV3Liquidator = await viem . getContractAt (
132
168
"IonicUniV3Liquidator" ,
133
169
( await deployments . get ( "IonicUniV3Liquidator" ) ) . address as Address
@@ -145,20 +181,6 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
145
181
]
146
182
} ) ;
147
183
148
- await prepareAndLogTransaction ( {
149
- contractInstance : addressProvider ,
150
- functionName : "setAddress" ,
151
- args : [
152
- "PoolLens" ,
153
- ( await deployments . get ( "PoolLens" ) ) . address as Address
154
- ] ,
155
- description : `Setting PoolLens id on AddressProvider` ,
156
- inputs : [
157
- { internalType : "string" , name : "id" , type : "string" } ,
158
- { internalType : "address" , name : "newAddress" , type : "address" }
159
- ]
160
- } ) ;
161
-
162
184
const [ , pools ] = await poolDirectory . read . getActivePools ( ) ;
163
185
for ( let i = 0 ; i < pools . length ; i ++ ) {
164
186
const pool = pools [ i ] ;
@@ -178,24 +200,9 @@ task("markets:upgrade-and-setup", "Upgrades all markets and sets addresses provi
178
200
marketAddress : market ,
179
201
implementationAddress : latestImpl ,
180
202
} ) ;
181
- const ap = await viem . getContractAt (
182
- "AddressesProvider" ,
183
- ( await deployments . get ( "AddressesProvider" ) ) . address as Address
184
- ) ;
185
- const ctokenAsExt = await viem . getContractAt ( "CTokenFirstExtension" , market )
186
-
187
- await prepareAndLogTransaction ( {
188
- contractInstance : ctokenAsExt ,
189
- functionName : "_setAddressesProvider" ,
190
- args : [ ap . address ] ,
191
- description : `Setting AddressesProvider on ${ market } ` ,
192
- inputs : [
193
- { internalType : "address" , name : "_ap" , type : "address" }
194
- ]
195
- } ) ;
196
203
}
197
204
} catch ( e ) {
198
- console . error ( `error while upgrading the pool ${ JSON . stringify ( pool ) } ` , e ) ;
205
+ console . error ( `error while upgrading the pool` , e ) ;
199
206
}
200
207
}
201
208
} ) ;
0 commit comments