@@ -2,19 +2,7 @@ import axios from "axios";
2
2
import { DeploymentsExtension } from "hardhat-deploy/types" ;
3
3
import { task , types } from "hardhat/config" ;
4
4
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" ;
18
6
import { IonicComptroller$Type } from "../../artifacts/contracts/compound/ComptrollerInterface.sol/IonicComptroller" ;
19
7
20
8
const LOG = process . env . LOG ? true : false ;
@@ -212,18 +200,16 @@ task("revenue:admin:withdraw", "Calculate the fees accrued from admin fees")
212
200
. addParam ( "threshold" , "Threshold for ionic fee seizing denominated in native" , "0.01" , types . string )
213
201
. setAction ( async ( taskArgs , hre ) => {
214
202
const publicClient = await hre . viem . getPublicClient ( ) ;
203
+ const { deployer } = await hre . getNamedAccounts ( ) ;
215
204
const cgId = "ethereum" ;
216
205
217
206
const { pools, mpo } = await setUpFeeCalculation ( hre ) ;
218
207
for ( const pool of pools ) {
219
208
const comptroller = await hre . viem . getContractAt ( "IonicComptroller" , pool . comptroller ) ;
220
- // Skip Polygon Jarvis jFiat
221
- if ( comptroller === null || comptroller . address === "0xD265ff7e5487E9DD556a4BB900ccA6D087Eb3AD2" ) {
222
- continue ;
223
- }
224
209
const markets = await comptroller . read . getAllMarkets ( ) ;
225
210
const threshold = parseEther ( taskArgs . threshold ) ;
226
211
const priceUsd = await cgPrice ( cgId ) ;
212
+ console . log ( "priceUsd: " , priceUsd ) ;
227
213
228
214
for ( const market of markets ) {
229
215
const cToken = await hre . viem . getContractAt ( "ICErc20" , market ) ;
@@ -240,15 +226,38 @@ task("revenue:admin:withdraw", "Calculate the fees accrued from admin fees")
240
226
// const accTx = await cToken.accrueInterest();
241
227
// await accTx.wait();
242
228
console . log ( `Withdrawing fee from ${ await cToken . read . symbol ( ) } (underlying: ${ underlying } )` ) ;
229
+ console . log ( "deployer: " , deployer ) ;
243
230
const tx = await cToken . write . _withdrawIonicFees ( [ ionicFee ] ) ;
244
231
await publicClient . waitForTransactionReceipt ( { hash : tx } ) ;
232
+ console . log ( "tx: " , tx ) ;
245
233
console . log (
246
- `Pool: ${ comptroller } - Market: ${ market } (underlying: ${ underlying } ) - Ionic Fee: ${ formatEther (
234
+ `Pool: ${ comptroller . address } - Market: ${ market } (underlying: ${ underlying } ) - Ionic Fee: ${ formatEther (
247
235
nativeFee
248
236
) } `
249
237
) ;
250
238
} 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 } ` ) ;
252
261
}
253
262
}
254
263
}
0 commit comments