1
- import { task } from "hardhat/config" ;
1
+ import { task , types } from "hardhat/config" ;
2
2
import { Address , formatUnits } from "viem" ;
3
3
4
- import { assets as modeAssets } from "../../../monorepo/packages/chains/src/mode/assets" ;
4
+ import { assets as modeAssets } from "../../../../monorepo/packages/chains/src/mode/assets" ;
5
+ import { assetSymbols } from "../../../../monorepo/packages/types/dist" ;
6
+ import { prepareAndLogTransaction } from "../../../chainDeploy/helpers/logging" ;
5
7
8
+ const COMPTROLLER = "0xfb3323e24743caf4add0fdccfb268565c0685556" ;
6
9
task ( "market:set-cf:mode:main" , "Sets caps on a market" ) . setAction ( async ( _ , { viem, run } ) => {
7
- const COMPTROLLER = "0xfb3323e24743caf4add0fdccfb268565c0685556" ;
8
10
for ( const asset of modeAssets ) {
9
11
const pool = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
10
12
const cToken = await pool . read . cTokensByUnderlying ( [ asset . underlying ] ) ;
@@ -19,6 +21,55 @@ task("market:set-cf:mode:main", "Sets caps on a market").setAction(async (_, { v
19
21
}
20
22
} ) ;
21
23
24
+ task ( "mode:irm:set-prudentia" , "Set new IRM to ctoken" ) . setAction (
25
+ async ( _ , { viem, deployments, getNamedAccounts } ) => {
26
+ const { deployer } = await getNamedAccounts ( ) ;
27
+ const toSet : { symbol : string ; irm : string } [ ] = [
28
+ { symbol : assetSymbols . USDC , irm : "PrudentiaInterestRateModel_USDC" } ,
29
+ { symbol : assetSymbols . USDT , irm : "PrudentiaInterestRateModel_USDT" } ,
30
+ { symbol : assetSymbols . WETH , irm : "PrudentiaInterestRateModel_WETH" }
31
+ ] ;
32
+ const assets = modeAssets . filter ( ( a ) => toSet . map ( ( a ) => a . symbol ) . includes ( a . symbol ) ) ;
33
+ console . log (
34
+ "assets: " ,
35
+ assets . map ( ( a ) => a . symbol )
36
+ ) ;
37
+ const pool = await viem . getContractAt ( "IonicComptroller" , COMPTROLLER ) ;
38
+ const ffd = await viem . getContractAt (
39
+ "FeeDistributor" ,
40
+ ( await deployments . get ( "FeeDistributor" ) ) . address as Address
41
+ ) ;
42
+ const admin = await ffd . read . owner ( ) ;
43
+ for ( const asset of assets ) {
44
+ const cTokenAddress = await pool . read . cTokensByUnderlying ( [ asset . underlying ] ) ;
45
+ console . log ( "cToken: " , cTokenAddress ) ;
46
+ const publicClient = await viem . getPublicClient ( ) ;
47
+
48
+ const cToken = await viem . getContractAt ( "ICErc20" , cTokenAddress ) ;
49
+ const irm = toSet . find ( ( a ) => a . symbol === asset . symbol ) ?. irm ;
50
+ if ( ! irm ) {
51
+ throw new Error ( `IRM not found for ${ asset . symbol } ` ) ;
52
+ }
53
+ const irmDeployment = await deployments . get ( irm ) ;
54
+ console . log ( "admin.toLowerCase(): " , admin . toLowerCase ( ) ) ;
55
+ console . log ( "deployer.toLowerCase(): " , deployer . toLowerCase ( ) ) ;
56
+ if ( admin . toLowerCase ( ) !== deployer . toLowerCase ( ) ) {
57
+ await prepareAndLogTransaction ( {
58
+ contractInstance : cToken ,
59
+ functionName : "_setInterestRateModel" ,
60
+ args : [ irmDeployment . address ] ,
61
+ description : `Set IRM of ${ await cToken . read . underlying ( ) } to ${ irmDeployment . address } ` ,
62
+ inputs : [ { internalType : "address" , name : "newInterestRateModel" , type : "address" } ]
63
+ } ) ;
64
+ } else {
65
+ const tx = await cToken . write . _setInterestRateModel ( [ irmDeployment . address as Address ] ) ;
66
+ await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
67
+ console . log ( `Set IRM of ${ await cToken . read . underlying ( ) } to ${ irmDeployment . address } ` ) ;
68
+ }
69
+ }
70
+ }
71
+ ) ;
72
+
22
73
task ( "prudentia:upgrade:pool" , "Upgrades a pool to the latest comptroller implementation" ) . setAction (
23
74
async ( _ , { viem, deployments, getNamedAccounts } ) => {
24
75
const { deployer } = await getNamedAccounts ( ) ;
0 commit comments