@@ -114,3 +114,58 @@ task("market:upgrade:safe", "Upgrades a market's implementation")
114
114
) ;
115
115
}
116
116
} ) ;
117
+
118
+ task ( "markets:setAddressesProvider" , "Upgrades all pools comptroller implementations whose autoimplementatoins are on" )
119
+ . addFlag ( "forceUpgrade" , "If the pool upgrade should be forced" )
120
+ . setAction ( async ( { forceUpgrade } , { viem, getChainId, deployments, run } ) => {
121
+ const publicClient = await viem . getPublicClient ( ) ;
122
+
123
+ const poolDirectory = await viem . getContractAt (
124
+ "PoolDirectory" ,
125
+ ( await deployments . get ( "PoolDirectory" ) ) . address as Address
126
+ ) ;
127
+ const feeDistributor = await viem . getContractAt (
128
+ "FeeDistributor" ,
129
+ ( await deployments . get ( "FeeDistributor" ) ) . address as Address
130
+ ) ;
131
+
132
+ await run ( "market:set-latest" ) ;
133
+
134
+ const [ , pools ] = await poolDirectory . read . getActivePools ( ) ;
135
+ for ( let i = 0 ; i < pools . length ; i ++ ) {
136
+ const pool = pools [ i ] ;
137
+ console . log ( "pool" , { name : pool . name , address : pool . comptroller } ) ;
138
+
139
+ try {
140
+ const comptrollerAsExtension = await viem . getContractAt ( "IonicComptroller" , pool . comptroller ) ;
141
+ const markets = await comptrollerAsExtension . read . getAllMarkets ( ) ;
142
+ for ( let j = 0 ; j < markets . length ; j ++ ) {
143
+ const market = markets [ j ] ;
144
+ console . log ( `market address ${ market } ` ) ;
145
+ const cTokenInstance = await viem . getContractAt ( "ICErc20" , market ) ;
146
+ const [ latestImpl ] = await feeDistributor . read . latestCErc20Delegate ( [
147
+ await cTokenInstance . read . delegateType ( )
148
+ ] ) ;
149
+ await run ( "market:upgrade:safe" , {
150
+ marketAddress : market ,
151
+ implementationAddress : latestImpl ,
152
+ } ) ;
153
+ const ap = await viem . getContractAt (
154
+ "AddressesProvider" ,
155
+ ( await deployments . get ( "AddressesProvider" ) ) . address as Address
156
+ ) ;
157
+ const ctokenAsExt = await viem . getContractAt ( "CTokenFirstExtension" , market )
158
+ const setAPTX = await ctokenAsExt . write . _setAddressesProvider ( ap ) ;
159
+ const receipt = await publicClient . waitForTransactionReceipt ( {
160
+ hash : setAPTX
161
+ } ) ;
162
+ if ( receipt . status !== "success" ) {
163
+ throw `Failed to set AddressesProvider` ;
164
+ }
165
+ console . log ( `AddressesProvider successfully set to ${ ap } ` ) ;
166
+ }
167
+ } catch ( e ) {
168
+ console . error ( `error while upgrading the pool ${ JSON . stringify ( pool ) } ` , e ) ;
169
+ }
170
+ }
171
+ } ) ;
0 commit comments