Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.

Commit 45a1172

Browse files
committed
feat: add task for updating fees
1 parent 388c62f commit 45a1172

File tree

3 files changed

+112
-4
lines changed

3 files changed

+112
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node_modules/
1515
ionic-contracts.iml
1616
cache_hardhat
1717
transactions.json
18+
*transactions.json

hardhat.config.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,10 @@ const config: HardhatUserConfig = {
2929
}
3030
]
3131
},
32-
external: {
33-
contracts: [{ artifacts: "./out" }]
34-
},
3532
paths: {
3633
sources: "./contracts",
3734
tests: "./contracts/test",
38-
artifacts: "./out"
35+
artifacts: "./artifacts"
3936
},
4037
networks: {
4138
local: {
@@ -59,6 +56,14 @@ const config: HardhatUserConfig = {
5956
url: "https://rpc.gobob.xyz",
6057
accounts: [process.env.DEPLOYER!]
6158
}
59+
},
60+
etherscan: {
61+
apiKey: {
62+
base: "4RTI7UU6PR6Q2S2NJB4FAKK8Z6FTN3ZQRN"
63+
}
64+
},
65+
sourcify: {
66+
enabled: true
6267
}
6368
};
6469

tasks/market/admin.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { task, types } from "hardhat/config";
22
import { Address, Hash, parseUnits, zeroAddress } from "viem";
3+
import { prepareAndLogTransaction } from "../../chainDeploy/helpers/logging";
34

45
export default task("market:unsupport", "Unsupport a market")
56
.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
3031
console.log(`mined tx ${tx}`);
3132
});
3233

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+
33135
task("market:mint-pause", "Pauses minting on a market")
34136
.addParam("markets", "The address of the CTokens", undefined, types.string)
35137
.addOptionalParam("paused", "If the market should be paused or not", true, types.boolean)

0 commit comments

Comments
 (0)