From 7c55e4730b6c18488fd02f51c2d60dbc2d6ac42d Mon Sep 17 00:00:00 2001 From: Ewan Sheldon Date: Mon, 13 Nov 2023 17:41:02 +0100 Subject: [PATCH] start liquidations at random cursor --- src/liquidation.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liquidation.js b/src/liquidation.js index 0be9882..cc871f8 100644 --- a/src/liquidation.js +++ b/src/liquidation.js @@ -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); @@ -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; } });