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

Commit 1924616

Browse files
committed
fix: revenue
1 parent 8822c69 commit 1924616

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

tasks/admin/revenue.ts

+28-19
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,7 @@ import axios from "axios";
22
import { DeploymentsExtension } from "hardhat-deploy/types";
33
import { task, types } from "hardhat/config";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
5-
import {
6-
Address,
7-
Chain,
8-
formatEther,
9-
GetContractReturnType,
10-
Hash,
11-
HttpTransport,
12-
LocalAccount,
13-
parseEther,
14-
WalletClient,
15-
WalletRpcSchema
16-
} from "viem";
17-
import { ionicComptrollerAbi } from "../../generated";
5+
import { Address, formatEther, GetContractReturnType, parseEther } from "viem";
186
import { IonicComptroller$Type } from "../../artifacts/contracts/compound/ComptrollerInterface.sol/IonicComptroller";
197

208
const LOG = process.env.LOG ? true : false;
@@ -212,18 +200,16 @@ task("revenue:admin:withdraw", "Calculate the fees accrued from admin fees")
212200
.addParam("threshold", "Threshold for ionic fee seizing denominated in native", "0.01", types.string)
213201
.setAction(async (taskArgs, hre) => {
214202
const publicClient = await hre.viem.getPublicClient();
203+
const { deployer } = await hre.getNamedAccounts();
215204
const cgId = "ethereum";
216205

217206
const { pools, mpo } = await setUpFeeCalculation(hre);
218207
for (const pool of pools) {
219208
const comptroller = await hre.viem.getContractAt("IonicComptroller", pool.comptroller);
220-
// Skip Polygon Jarvis jFiat
221-
if (comptroller === null || comptroller.address === "0xD265ff7e5487E9DD556a4BB900ccA6D087Eb3AD2") {
222-
continue;
223-
}
224209
const markets = await comptroller.read.getAllMarkets();
225210
const threshold = parseEther(taskArgs.threshold);
226211
const priceUsd = await cgPrice(cgId);
212+
console.log("priceUsd: ", priceUsd);
227213

228214
for (const market of markets) {
229215
const cToken = await hre.viem.getContractAt("ICErc20", market);
@@ -240,15 +226,38 @@ task("revenue:admin:withdraw", "Calculate the fees accrued from admin fees")
240226
// const accTx = await cToken.accrueInterest();
241227
// await accTx.wait();
242228
console.log(`Withdrawing fee from ${await cToken.read.symbol()} (underlying: ${underlying})`);
229+
console.log("deployer: ", deployer);
243230
const tx = await cToken.write._withdrawIonicFees([ionicFee]);
244231
await publicClient.waitForTransactionReceipt({ hash: tx });
232+
console.log("tx: ", tx);
245233
console.log(
246-
`Pool: ${comptroller} - Market: ${market} (underlying: ${underlying}) - Ionic Fee: ${formatEther(
234+
`Pool: ${comptroller.address} - Market: ${market} (underlying: ${underlying}) - Ionic Fee: ${formatEther(
247235
nativeFee
248236
)}`
249237
);
250238
} else {
251-
console.log(`Pool: ${comptroller} - Market: ${market} - No Ionic Fees`);
239+
console.log(`Pool: ${comptroller.address} - Market: ${market} - No Ionic Fees: ${ionicFee}`);
240+
}
241+
242+
const adminFee = await cToken.read.totalAdminFees();
243+
const nativeFeeAdmin = (adminFee * nativePrice) / 10n ** 18n;
244+
245+
console.log("USD FEE VALUE", parseFloat(formatEther(nativeFeeAdmin)) * priceUsd);
246+
console.log("USD THRESHOLD VALUE", parseFloat(taskArgs.threshold) * priceUsd);
247+
if (adminFee > threshold) {
248+
// const accTx = await cToken.accrueInterest();
249+
// await accTx.wait();
250+
console.log(`Withdrawing fee from ${await cToken.read.symbol()} (underlying: ${underlying})`);
251+
const tx = await cToken.write._withdrawAdminFees([ionicFee]);
252+
await publicClient.waitForTransactionReceipt({ hash: tx });
253+
console.log("tx: ", tx);
254+
console.log(
255+
`Pool: ${comptroller.address} - Market: ${market} (underlying: ${underlying}) - Admin Fee: ${formatEther(
256+
nativeFeeAdmin
257+
)}`
258+
);
259+
} else {
260+
console.log(`Pool: ${comptroller.address} - Market: ${market} - No Ionic Fees: ${ionicFee}`);
252261
}
253262
}
254263
}

0 commit comments

Comments
 (0)