-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathliquidateVault.js
29 lines (19 loc) · 1.15 KB
/
liquidateVault.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { getOpenVaults, calcCollateralRatio, Account, Vault, VAULT_IDS} from '@xbacked-dao/xbacked-sdk';
import dotenv from 'dotenv';
dotenv.config();
const account = new Account({network: "TestNet", mnemonic: process.env.SEED_PHRASE});
//Select the vault you want to use
const algoToxUSDVault = new Vault({id: VAULT_IDS.TestNet.algo});
// get all Vaults in the network
const availableVaults = await getOpenVaults({account: account,vault: algoToxUSDVault})
const vaultState = await account.getVaultState({vault: algoToxUSDVault})
console.log("CollateralPrice = ", vaultState.collateralPrice);
for (let i = 0; i < availableVaults.length; i++){
const currentVault = await algoToxUSDVault.getUserInfo({account: account, address: availableVaults[i]})
if (currentVault.collateralRatio < vaultState.liquidationCollateralRatio && currentVault.liquidating ){
await account.liquidateVault({address: availableVaults[i], debtAmount: 2 , vault: algoToxUSDVault})
console.log("New Collateral Ratio = ", calcCollateralRatio(vaultInfo.collateral, vaultState.collateralPrice, vaultInfo.vaultDebt))
console.log(vaultInfo)
break;
}
}