Skip to content

Commit

Permalink
attempt liquidations vault by vault
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Nov 13, 2023
1 parent a8d12fb commit 26e02fe
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/liquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ const { getNetwork } = require('./networks');

const scheduleLiquidation = async _ => {
const network = getNetwork('arbitrum');
schedule.scheduleJob('*/5 * * * *', async _ => {
console.log('checking for liquidations ...')
const manager = await getContract(network.name, 'SmartVaultManager');
let tokenId = 1;
schedule.scheduleJob('* * * * *', async _ => {
const provider = new ethers.getDefaultProvider(network.rpc)
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);
console.log(`attempting liquidation vault #${tokenId}`);
try {
const provider = new ethers.getDefaultProvider(network.rpc)
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);
if ((await provider.getBalance(wallet.address)) < ethers.utils.parseEther('0.01')) {
console.error('error: Liquidator wallet balance too low');
}
await (await getContract(network.name, 'SmartVaultManager')).connect(wallet).liquidateVaults()
console.log(network.name, 'vault-liquidated');
} catch(e) {
console.log(network.name, e.reason)
await manager.connect(wallet).liquidateVault(tokenId);
console.log(`liquidated: ${tokenId}`);
} catch (e) {
console.log(`liquidation attempt failed`);
}
tokenId++;
if (tokenId > await manager.connect(wallet).totalSupply()) tokenId = 1;
});
}

Expand Down

0 comments on commit 26e02fe

Please sign in to comment.