This repository was archived by the owner on Feb 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Liquidation
adamant-al edited this page Jun 27, 2023
·
9 revisions
In this example we will liquidate a borrow based on oXCN (XCN) asset underlying for 0xb5Cd64ba87E6f7FBD356b517BB7a279040C8Ac2a address.
See detailed description on the Onyx blog.
Enter markets with borrow-asset:
await Comptroller.enterMarkets([oXCN.address])Allow oTokens contract and Comptroller to transfer tokens:
await XCN.approve(oXCN.address, bank)
await XCN.approve(Comptroller.address, bank)Check the balances and liquidity:
await oXCN.callStatic.balanceOfUnderlying(signerAddress) // $0
await Comptroller.getAccountLiquidity(borrowerAddress) // Check borrower account liquidity, it's negative, -> liquidate his borrow
await Comptroller.getAssetsIn(borrowerAddress) // Returns the address of oXCN contract, it means the collateral is supplied by oXCN tokensGet borrow balance in the underlying for oXCN token (XCN):
const borrowedBalance = await oXCN.callStatic.borrowBalanceCurrent(borrowerAddress)Liquidate a half of borrowed balance:
oXCN.liquidateBorrow(borrowerAddress, borrowedBalance.div(2), oXCN.address)After emitted event LiquidateBorrow, which means successful borrow liquidation, check balances again:
await XCN.balanceOf(signerAddress) // The liquidator's balance decreased due to spending XCN tokens to liquidate half of the borrow
await oXCN.callStatic.balanceOfUnderlying(signerAddress) // The liquidator's oXCN balance increased due to seized collateral from the borrower and liquidation bonusBorrower account liquidity is increased and became positive after the liquidation.
To run the liquidation scenario: npm run liquidation