Skip to content

Commit

Permalink
start liquidations at random cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
ewansheldon committed Nov 13, 2023
1 parent cfeee20 commit 7c55e47
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/liquidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ const { getContract } = require("./contractFactory");
const { ethers } = require('ethers');
const { getNetwork } = require('./networks');

const getVaultSupply = async (manager, wallet) => {
const getVaultSupply = async (wallet, manager) => {
try {
return await manager.connect(wallet).totalSupply();
} catch (_) {
return await getVaultSupply(wallet);
return await getVaultSupply(wallet, manager);
}
}

const scheduleLiquidation = async _ => {
const network = getNetwork('arbitrum');
const manager = await getContract(network.name, 'SmartVaultManager');
let tokenId = 1;
const provider = new ethers.getDefaultProvider(network.rpc)
const wallet = new ethers.Wallet(process.env.WALLET_PRIVATE_KEY, provider);
let tokenId = Math.floor(Math.random() * await getVaultSupply(wallet, manager)) + 1;
let running = false;
schedule.scheduleJob('*/15 * * * * *', async _ => {
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);
Expand All @@ -29,7 +29,7 @@ const scheduleLiquidation = async _ => {
console.log(`liquidation attempt failed`);
}
tokenId++;
if (tokenId > await getVaultSupply(manager, wallet)) tokenId = 1;
if (tokenId > await getVaultSupply(wallet, manager)) tokenId = 1;
running = false;
}
});
Expand Down

0 comments on commit 7c55e47

Please sign in to comment.