update absorb script

This commit is contained in:
2026-01-06 17:31:16 +08:00
parent eecae142a4
commit 5f2750c80e
2 changed files with 16 additions and 11 deletions

View File

@@ -61,7 +61,7 @@ async function main() {
let lastBlockNumber: number | undefined;
// Compound V3 风格:while(true) 轮询
// while(true) 轮询
while (true) {
try {
const currentBlockNumber = await hre.ethers.provider.getBlockNumber();

View File

@@ -2,7 +2,7 @@ import hre from 'hardhat';
import { Signer } from 'ethers';
const LOOKBACK_BLOCKS = 50000; // 查询最近 50000 个区块
const LIQUIDATION_THRESHOLD = 10e6; // $10 (USDC 6 decimals)
const LIQUIDATION_THRESHOLD = 10; // $10 的最小清算阈值(美元单位)
/**
* 获取最近活跃的地址(通过多个事件)
@@ -91,7 +91,6 @@ export async function getUniqueAddresses(
/**
* 检查并清算可清算账户
* 参考comet/scripts/liquidation_bot/liquidateUnderwaterBorrowers.ts
*/
export async function liquidateUnderwaterBorrowers(
lendingContract: any,
@@ -121,14 +120,20 @@ export async function liquidateUnderwaterBorrowers(
const borrowBalance = await lendingContract.borrowBalanceOf(address);
const baseToken = await lendingContract.baseToken();
const basePrice = await priceFeedContract.getPrice(baseToken);
// debtValue 计算borrowBalance (6 decimals) * basePrice (30 decimals) / 1e6
const debtValue = (BigInt(borrowBalance) * BigInt(basePrice)) / BigInt(10) ** BigInt(6);
const debtValueInBaseUnit = Number(debtValue / (BigInt(10) ** BigInt(30))); // 转换为 USDC 单位
// LIQUIDATION_THRESHOLD 是 6 decimals需要转换为 30 decimals 来和 debtValue 比较
// 10e6 * 1e24 = 10e30 (代表 $10)
if (debtValue >= BigInt(LIQUIDATION_THRESHOLD) * BigInt(10) ** BigInt(24)) {
// 动态获取 baseToken 的 decimals
const baseTokenContract = await hre.ethers.getContractAt('IERC20Metadata', baseToken);
const baseDecimals = await baseTokenContract.decimals();
// debtValue 计算borrowBalance * basePrice / 10^decimals
// 结果精度为 30 decimals (价格精度)
const debtValue = (BigInt(borrowBalance) * BigInt(basePrice)) / BigInt(10) ** BigInt(baseDecimals);
const debtValueInBaseUnit = Number(debtValue / (BigInt(10) ** BigInt(30))); // 转换为美元单位
// 将清算阈值(美元)转换为 30 decimals 精度进行比较
const thresholdValue = BigInt(LIQUIDATION_THRESHOLD) * BigInt(10) ** BigInt(30);
if (debtValue >= thresholdValue) {
console.log(`💰 Liquidatable: ${address}, Debt: $${debtValueInBaseUnit.toFixed(2)}`);
liquidatableAccounts.push(address);
} else {