Modules

accountGetter

This module is used for getting liquidatable accounts from contracts after every ACCOUNT_POLL_INTERVAL_MS. Accounts with liquidatable amount less than SINGLE_LIQUIDATION_THRESHOLD will be discarded.

Methods

  • updateAllAccounts()

    • Get all accounts information in DeFiner, and save them in a in-memory datastructure.

  • isLiquidatable(account)

    • Return whether a given account is liquidatable or not.

  • updateLiquidatableAccounts()

    • Get all liquidatable accounts from allAccountInfo based on SINGLE_LIQUIDATION_THRESHOLD.

Variables

  • allAccountsInfo

    • An array that saves all the accounts information in DeFiner.

  • liquidatableAccountsInfo

    • An array that saves all liquidatable accounts' information.

oracleGetter

This module is used for getting price from chainlink oracle after every ORACLE_PRICE_POLL_INTERVAL_MS.

Methods

  • updateOraclePrice()

    • Update price from chainlink oracle.

Variables

  • oraclePrice

    • This is the P1P_1 price from chainlink oracle. It's a map contains value for all kinds of token.

tradingGetter

This module is used for getting price from trading venue after every TRADING_PRICE_POLL_INTERVAL_MS. You can specify TRADING_VENUE_URL in the configuration to designate the trading venue you want to use.

Methods

  • updateTradingPrice()

    • Update price from trading venue.

Variables

  • tradingPrice

    • This is the P2P_2 price from trading venue (centralized or decentralized). It's a map that contains value for all kinds of token.

gasUpdator

This module is used for update gas price after every GAS_PRICE_UPDATE_INTERVAL_MS from GAS_STATION_URL. The real gas price will be GAS_PRICE_MULTIPLIER * fast price from GAS_STATION_URL.

Methods

  • updateGasPrice()

    • Get the newest gas price from GAS_STATION_URL.

  • usedGasPrice()

    • Return fastGasPrice * GAS_PRICE_MULTIPLIER as the gas price that actually will be used.

Variables

  • fastGasPrice

    • Fast gas price.

  • standardGasPrice

    • Standard gas price.

  • slowGasPrice

    • Slow gas price.

liquidateHelper

This module is used for triggering transaction on DeFiner's contract, which will enable the liquidator account to call liquidate function on the contract.

Methods

  • liquidate(address, token)

    • Call liquidate function on SavingAccount.sol

Variables

  • liquidateRecords

    • Record all the liquidating information on DeFiner's platform.

tradingHelper

This module is used for trading on exchanges for trading accounts. You can specify TRADING_VENUE_URL in the configuration to designate the trading venue you want to use.

Methods

  • tradeSome(token, amount)

    • Open a short position for given token and amount.

Variables

  • tradingRecords

    • Record all the trading information on trading venue.

transactionHelper

Helper to trigger the a whole liquidation process if an account has P2/P1P_2/P_1 greater or equal to TRIGGER_THRESHOLD.

Methods

  • updateP1Value()

    • Update P1P_1 value for all liquidatable accounts.

  • updateP2Value()

    • Update P2P_2 value for all liquidatable accounts.

  • isQualified(account)

    • Return whether one account is qualified that P2/P1P_2/P_1greater or equal to TRIGGER_THRESHOLD to qualifiedAccounts.

  • updateQualifiedAccounts()

    • Push all accounts with P2/P1P_2/P_1greater or equal to TRIGGER_THRESHOLD to qualifiedAccounts, adn filter out all accounts that is no longer available.

  • liquidateOneAccount()

    • Poll one account from qualifiedAccounts and check whether it's still qualified. If yes start liquidation other wise remove it from qualifiedAccounts.

Variables

  • qualifiedAccounts

    • An array or priority queue in the order of their P2/P1P_2/P_1value.

rebalanceHelper

This module is used to help rebalance after the asset in the liquidator's account accumulates to REBALANCE_THRESHOLD. It should also handle leftover to make sure all positions are closed in the trading account before exiting.

Methods

  • rebalance()

    • Transfer the asset from liquidator's account to trading helper's account. And transfer money from trading helper's account to liquidator's account. Close position on trading helper's side.

  • updateValue()

    • Update currentValue according to all the transactions that have been made.

  • checkAmount()

    • Check whether the asset has been accumulated to TRADING_THRESHOLD.

Variables

  • currentValue

    • The total amount of unrebalanced asset's value in liquidator's account.