|
1 | 1 | import { task, types } from "hardhat/config";
|
2 | 2 | import { Address, Hash, parseUnits, zeroAddress } from "viem";
|
| 3 | +import { prepareAndLogTransaction } from "../../chainDeploy/helpers/logging"; |
3 | 4 |
|
4 | 5 | export default task("market:unsupport", "Unsupport a market")
|
5 | 6 | .addParam("pool", "Comptroller Address", undefined, types.string)
|
@@ -30,6 +31,107 @@ task("market:set:ltv", "Set the LTV (loan to value / collateral factor) of a mar
|
30 | 31 | console.log(`mined tx ${tx}`);
|
31 | 32 | });
|
32 | 33 |
|
| 34 | +task("markets:set:fees", "Set the fees of all markets").setAction(async (_, { viem, deployments, run }) => { |
| 35 | + const DESIRED_ADMIN_FEE = "0"; |
| 36 | + const DESIRED_RESERVE_FACTOR = "0.05"; |
| 37 | + |
| 38 | + const poolDirectory = await viem.getContractAt( |
| 39 | + "PoolDirectory", |
| 40 | + (await deployments.get("PoolDirectory")).address as Address |
| 41 | + ); |
| 42 | + |
| 43 | + const [, poolData] = await poolDirectory.read.getActivePools(); |
| 44 | + |
| 45 | + for (const pool of poolData) { |
| 46 | + const comptroller = await viem.getContractAt("IonicComptroller", pool.comptroller); |
| 47 | + |
| 48 | + const markets = await comptroller.read.getAllMarkets(); |
| 49 | + |
| 50 | + for (const market of markets) { |
| 51 | + await run("market:set:admin-fee", { marketAddress: market, fee: DESIRED_ADMIN_FEE }); |
| 52 | + await run("market:set:reserve-factor", { marketAddress: market, factor: DESIRED_RESERVE_FACTOR }); |
| 53 | + } |
| 54 | + } |
| 55 | +}); |
| 56 | + |
| 57 | +task("market:set:admin-fee") |
| 58 | + .addParam("marketAddress", "Address of the market", undefined, types.string) |
| 59 | + .addParam("fee", "The fee as a floating point value between 0 and 1", undefined, types.string) |
| 60 | + .setAction(async ({ marketAddress, fee }, { viem, getNamedAccounts, deployments }) => { |
| 61 | + const { deployer } = await getNamedAccounts(); |
| 62 | + console.log("deployer: ", deployer); |
| 63 | + const publicClient = await viem.getPublicClient(); |
| 64 | + const market = await viem.getContractAt("ICErc20", marketAddress); |
| 65 | + const feeMantissa = parseUnits(fee, 18); |
| 66 | + console.log(`will set the admin fee of market ${marketAddress} to ${feeMantissa}`); |
| 67 | + const currentFee = await market.read.adminFeeMantissa(); |
| 68 | + console.log("currentFee: ", currentFee); |
| 69 | + if (currentFee === feeMantissa) { |
| 70 | + console.log(`Admin fee is already set to ${feeMantissa}`); |
| 71 | + return; |
| 72 | + } |
| 73 | + const feeDistributor = await viem.getContractAt( |
| 74 | + "FeeDistributor", |
| 75 | + (await deployments.get("FeeDistributor")).address as Address |
| 76 | + ); |
| 77 | + |
| 78 | + const admin = await feeDistributor.read.owner(); |
| 79 | + console.log("admin: ", admin); |
| 80 | + if (admin.toLowerCase() !== deployer.toLowerCase()) { |
| 81 | + await prepareAndLogTransaction({ |
| 82 | + contractInstance: market, |
| 83 | + functionName: "_setAdminFee", |
| 84 | + args: [String(feeMantissa)], |
| 85 | + description: "Set Admin Fee", |
| 86 | + inputs: [{ internalType: "uint256", name: "newAdminFeeMantissa", type: "uint256" }] |
| 87 | + }); |
| 88 | + } else { |
| 89 | + const tx = await market.write._setAdminFee([feeMantissa]); |
| 90 | + console.log(`_setAdminFee tx ${tx}`); |
| 91 | + await publicClient.waitForTransactionReceipt({ hash: tx }); |
| 92 | + console.log(`mined tx ${tx}`); |
| 93 | + } |
| 94 | + }); |
| 95 | + |
| 96 | +task("market:set:reserve-factor") |
| 97 | + .addParam("marketAddress", "Address of the market", undefined, types.string) |
| 98 | + .addParam("factor", "The factor as a floating point value between 0 and 1", undefined, types.string) |
| 99 | + .setAction(async ({ marketAddress, factor }, { viem, getNamedAccounts, deployments }) => { |
| 100 | + const { deployer } = await getNamedAccounts(); |
| 101 | + console.log("deployer: ", deployer); |
| 102 | + const publicClient = await viem.getPublicClient(); |
| 103 | + const market = await viem.getContractAt("ICErc20", marketAddress); |
| 104 | + const factorMantissa = parseUnits(factor, 18); |
| 105 | + console.log(`will set the reserve factor of market ${marketAddress} to ${factorMantissa}`); |
| 106 | + const currentFactor = await market.read.reserveFactorMantissa(); |
| 107 | + console.log("currentFactor: ", currentFactor); |
| 108 | + if (currentFactor === factorMantissa) { |
| 109 | + console.log(`Reserve factor is already set to ${factorMantissa}`); |
| 110 | + return; |
| 111 | + } |
| 112 | + |
| 113 | + const feeDistributor = await viem.getContractAt( |
| 114 | + "FeeDistributor", |
| 115 | + (await deployments.get("FeeDistributor")).address as Address |
| 116 | + ); |
| 117 | + const admin = await feeDistributor.read.owner(); |
| 118 | + console.log("admin: ", admin); |
| 119 | + if (admin.toLowerCase() !== deployer.toLowerCase()) { |
| 120 | + await prepareAndLogTransaction({ |
| 121 | + contractInstance: market, |
| 122 | + functionName: "_setReserveFactor", |
| 123 | + args: [String(factorMantissa)], |
| 124 | + description: "Set Reserve Factor", |
| 125 | + inputs: [{ internalType: "uint256", name: "newReserveFactorMantissa", type: "uint256" }] |
| 126 | + }); |
| 127 | + } else { |
| 128 | + const tx = await market.write._setReserveFactor([factorMantissa]); |
| 129 | + console.log(`_setReserveFactor tx ${tx}`); |
| 130 | + await publicClient.waitForTransactionReceipt({ hash: tx }); |
| 131 | + console.log(`mined tx ${tx}`); |
| 132 | + } |
| 133 | + }); |
| 134 | + |
33 | 135 | task("market:mint-pause", "Pauses minting on a market")
|
34 | 136 | .addParam("markets", "The address of the CTokens", undefined, types.string)
|
35 | 137 | .addOptionalParam("paused", "If the market should be paused or not", true, types.boolean)
|
|
0 commit comments