On-chain guardian contract
The idea behind the on-chain guardian is straightforward: on-chain liquidation mechanics significantly speeds up the entire process of buying out the liquidated collateral, as well as burning of EOSDT “bad debt” on the liquidator smart contract. In order to achieve this, we’ve made some amendments to our contract logic. Let’s get into the specifics:
- New table ltvratios on eosdtcntractThe entries (table rows) in this table are updated every time someone interacts with EOSDT smart contracts by calling some action or transferring tokens to the system. The table contains the most up-to-date information on all position collateralization ratios.
- Refactored eosdtcntract margincall actions.
We initially intended to make this contract a liquidity pool, as in people supply EOSDT or EOS to the guardian contract, which constantly monitors the state of the liquidator. If there are non-zero balances on the liquidator, the guardian performs the necessary actions to buy out non-zero balances from liquidator.
But to speed up the process and give our community something useful early on, we decided to provide a basic functionality: the contract will accept EOSDT transfers, will try to liquidate bad debt, then go to exchanges to convert purchased collateral back into EOSDT, returning it (and the profit) to the caller.
The guardian contract is pretty simple under the hood:
if EOSDT is transferred
if bad debt on eosdtliqdatr > 0
transfer EOSDT to liquidator (collateral auction)
receive liquidated EOS
go to DEX, sell EOS for EOSDT
EOSDT received >= EOSDT paid? YES: proceed. NO: revert
From the user’s perspective, the process looks like transferring EOSDT to the smart contract and receiving the transferred amount back (assuming there’s no “bad debt” to buy out from liquidator, or there wasn’t enough liquidity on the DEX to convert purchased EOS collateral back into EOSDT) or more EOSDT.
We will update the guardian contract to act as a liquidity pool for performing liquidations in the nearest future.
- Transfer EOSDT when there is a non-zero amount of "bad debt" in the liquidator contract and get EOS collateral at a 3% discount.
- Transfer NUT when nut_collat_balance is non-zero to buy out excess EOS collateral at a 6% discount.
- Transfer EOS when surplus_debt is non-zero (non-zero equilibrium fee, which is not the case right now) on the liquidator contract to buy out EOSDT at a 3% discount.
Thanks to on-chain margin calls and the new guardian contract, interacting with the liquidator contract has never been easier: guardian.js is now basically a script that handles user accounts and transfers EOSDT to the guardian contract.