Skip to content

Commit

Permalink
throttle liquidation runs
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Nov 13, 2023
1 parent 2b6843e commit 8369420
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/liquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ const scheduleLiquidation = async _ => {
let tokenId = 1;
let running = false;
schedule.scheduleJob('* * * * *', async _ => {
if (running) return;
running = true;
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 {
await manager.connect(wallet).liquidateVault(tokenId);
console.log(`liquidated: ${tokenId}`);
} catch (e) {
console.log(`liquidation attempt failed`);
if (!running) {
running = true;
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 {
await manager.connect(wallet).liquidateVault(tokenId);
console.log(`liquidated: ${tokenId}`);
} catch (e) {
console.log(`liquidation attempt failed`);
}
tokenId++;
if (tokenId > await getVaultSupply()) tokenId = 1;
running = false;
}
tokenId++;
if (tokenId > await getVaultSupply()) tokenId = 1;
running = false;
});
}

Expand Down

0 comments on commit 8369420

Please sign in to comment.