// STEP 1: CHECK ACCOUNT LIQUIDITY
// Get instance of Comptroller contract and connect signer for sending transactions
const comptrollerAddress = getContractAddress('Comptroller', chainId);
const comptroller = new Contract(comptrollerAddress, comptrollerAbi, signer);
// Define the address to liquidate and check their liquidity
const borrowerToLiquidate = '0x0000000000000000000000000000000000000001';
const [errorCode, liquidity, shortfall] = await comptroller.getAccountLiquidity(borrowerToLiquidate);
// Make sure there were no errors reading the data
if (errorCode.toString() !== '0') {
logFailure(`Could not read liquidity. Received error code ${errorCode}. Exiting script`);
// There were no errors, so now we check if we have an excess or a shortfall.
// One and only one of `shortfall` and `liquidity` will be above zero. (Since
// our chosen account above has no shortfall, you'll need to comment out the
// return statements to move past this section)
if (shortfall.gt(Zero)) {
logSuccess(`Account is undercollateralized and can be liquidated! Shortfall amount: ${shortfall}`);
} else if (liquidity.gt(Zero)) {
logFailure(`Account has excess liquidity and is safe. Amount of liquidity: ${liquidity}. Exiting script`);
logFailure('Account has no liquidity and no shortfall. Exiting script.');