update absorb script
This commit is contained in:
@@ -61,7 +61,7 @@ async function main() {
|
|||||||
|
|
||||||
let lastBlockNumber: number | undefined;
|
let lastBlockNumber: number | undefined;
|
||||||
|
|
||||||
// Compound V3 风格:while(true) 轮询
|
// while(true) 轮询
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
const currentBlockNumber = await hre.ethers.provider.getBlockNumber();
|
const currentBlockNumber = await hre.ethers.provider.getBlockNumber();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import hre from 'hardhat';
|
|||||||
import { Signer } from 'ethers';
|
import { Signer } from 'ethers';
|
||||||
|
|
||||||
const LOOKBACK_BLOCKS = 50000; // 查询最近 50000 个区块
|
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(
|
export async function liquidateUnderwaterBorrowers(
|
||||||
lendingContract: any,
|
lendingContract: any,
|
||||||
@@ -121,14 +120,20 @@ export async function liquidateUnderwaterBorrowers(
|
|||||||
const borrowBalance = await lendingContract.borrowBalanceOf(address);
|
const borrowBalance = await lendingContract.borrowBalanceOf(address);
|
||||||
const baseToken = await lendingContract.baseToken();
|
const baseToken = await lendingContract.baseToken();
|
||||||
const basePrice = await priceFeedContract.getPrice(baseToken);
|
const basePrice = await priceFeedContract.getPrice(baseToken);
|
||||||
|
|
||||||
// debtValue 计算:borrowBalance (6 decimals) * basePrice (30 decimals) / 1e6
|
// 动态获取 baseToken 的 decimals
|
||||||
const debtValue = (BigInt(borrowBalance) * BigInt(basePrice)) / BigInt(10) ** BigInt(6);
|
const baseTokenContract = await hre.ethers.getContractAt('IERC20Metadata', baseToken);
|
||||||
const debtValueInBaseUnit = Number(debtValue / (BigInt(10) ** BigInt(30))); // 转换为 USDC 单位
|
const baseDecimals = await baseTokenContract.decimals();
|
||||||
|
|
||||||
// LIQUIDATION_THRESHOLD 是 6 decimals,需要转换为 30 decimals 来和 debtValue 比较
|
// debtValue 计算:borrowBalance * basePrice / 10^decimals
|
||||||
// 10e6 * 1e24 = 10e30 (代表 $10)
|
// 结果精度为 30 decimals (价格精度)
|
||||||
if (debtValue >= BigInt(LIQUIDATION_THRESHOLD) * BigInt(10) ** BigInt(24)) {
|
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)}`);
|
console.log(`💰 Liquidatable: ${address}, Debt: $${debtValueInBaseUnit.toFixed(2)}`);
|
||||||
liquidatableAccounts.push(address);
|
liquidatableAccounts.push(address);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user