update liquidation bot scripts
This commit is contained in:
@@ -91,13 +91,13 @@ async function main() {
|
||||
console.log("\n添加 USDC 到白名单...");
|
||||
const usdcParams = {
|
||||
weight: 1000, // 1000/10000 = 10%
|
||||
maxUsdyAmount: ethers.parseUnits("30000000", 6), // 3000万 USDC
|
||||
maxUsdyAmount: ethers.parseUnits("30000000", 18), // 3000万 USDC
|
||||
isStable: true // USDC是稳定币
|
||||
};
|
||||
|
||||
const usdcTx = await vault.setWhitelistedToken(
|
||||
usdcAddress,
|
||||
6, // Todo USDC在Arbitrum测试网是6位精度
|
||||
18, // USDC的精度是18
|
||||
usdcParams.weight,
|
||||
usdcParams.maxUsdyAmount,
|
||||
usdcParams.isStable
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -12,9 +12,9 @@ contract TestFun is Script {
|
||||
function run() external {
|
||||
|
||||
address from = 0xa013422A5918CD099C63c8CC35283EACa99a705d;
|
||||
address to = 0xfdbFD4656b74aD16F23264121eD9F58219f5C3Cf;
|
||||
address to = 0x7f9eEA491eE53045594ee4669327f0355aCd0e58;
|
||||
|
||||
bytes memory data = hex"2e1a7d4d000000000000000000000000000000000000000000000005f68e8131ecf80000";
|
||||
bytes memory data = hex"7229bc3c0000000000000000000000000000000000000000000000000de0b6b3a7640000";
|
||||
|
||||
vm.startPrank(from);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user