update liquidation bot scripts
This commit is contained in:
@@ -33,7 +33,6 @@ async function main() {
|
||||
|
||||
console.log('📋 Contract Addresses:');
|
||||
console.log(' Lending Proxy:', deployment.lendingProxy);
|
||||
console.log(' Price Feed:', deployment.lendingPriceFeedProxy);
|
||||
console.log(' Base Token (USDC):', deployment.usdcAddress);
|
||||
console.log('');
|
||||
|
||||
@@ -49,12 +48,6 @@ async function main() {
|
||||
signer
|
||||
);
|
||||
|
||||
const priceFeedContract = await hre.ethers.getContractAt(
|
||||
'LendingPriceFeed',
|
||||
deployment.lendingPriceFeedProxy,
|
||||
signer
|
||||
);
|
||||
|
||||
console.log('✅ Contracts initialized\n');
|
||||
console.log('==========================================');
|
||||
console.log('🔄 Starting main loop...\n');
|
||||
@@ -75,7 +68,6 @@ async function main() {
|
||||
// 执行清算逻辑
|
||||
await liquidateUnderwaterBorrowers(
|
||||
lendingContract,
|
||||
priceFeedContract,
|
||||
signer
|
||||
);
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import hre from 'hardhat';
|
||||
import { Signer } from 'ethers';
|
||||
|
||||
const LOOKBACK_BLOCKS = 10000; // 查询最近 50000 个区块
|
||||
const LIQUIDATION_THRESHOLD = 1; // $10 的最小清算阈值(美元单位)
|
||||
|
||||
/**
|
||||
* 获取最近活跃的地址(通过多个事件)
|
||||
@@ -94,7 +93,6 @@ export async function getUniqueAddresses(
|
||||
*/
|
||||
export async function liquidateUnderwaterBorrowers(
|
||||
lendingContract: any,
|
||||
priceFeedContract: any,
|
||||
signer: Signer
|
||||
): Promise<boolean> {
|
||||
// 步骤 1: 获取最近活跃的地址
|
||||
@@ -116,29 +114,8 @@ export async function liquidateUnderwaterBorrowers(
|
||||
const isLiquidatable = await lendingContract.isLiquidatable(address);
|
||||
|
||||
if (isLiquidatable) {
|
||||
// 应用清算阈值过滤(防止清算小额账户,gas 成本过高)
|
||||
const borrowBalance = await lendingContract.borrowBalanceOf(address);
|
||||
const baseToken = await lendingContract.baseToken();
|
||||
const basePrice = await priceFeedContract.getPrice(baseToken);
|
||||
|
||||
// 动态获取 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 {
|
||||
console.log(`⏭️ Skip (below threshold): ${address}, Debt: $${debtValueInBaseUnit.toFixed(2)}`);
|
||||
}
|
||||
console.log(`💰 Liquidatable: ${address}`);
|
||||
liquidatableAccounts.push(address);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error checking ${address}:`, error);
|
||||
|
||||
Reference in New Issue
Block a user