Exactly Protocol
  • Getting started
    • 🔔Welcome
    • ➡️Introduction
    • ❔FAQ
    • 🔗Quick Links
  • Governance
    • 🏛️Exactly Protocol Governance
      • ✍️Proposals and Voting
      • ⚡Snapshot
      • 📄Exactly Improvement Proposal (EXAIP) Template
    • ⚫Exactly Protocol (EXA)
      • 📊EXA Tokenomics
      • ⚪EscrowedEXA (esEXA)
      • EXA Staking Program (stEXA)
  • EXA APP
    • The Exa App
    • How the Exa App works
    • The Exa App Webauthn Owner Plugin
    • Exa Plugin
    • Exa App FAQs
  • Guides
    • ⚙️Protocol
      • Auditor
      • MarketETHRouter
      • Market
        • ERC-4626
      • PriceFeedWrapper
      • PriceFeedDouble
      • InterestRateModel
      • RewardsController
    • 🛰️Peripheral Contracts
      • 🌀DebtManager
      • ⚫EXA
      • ⚪esEXA
      • 🪂Airdrop
      • 👀Previewer (read-only)
      • 👓DebtPreviewer (read-only)
      • RatePreviewer (read-only)
    • ✨Features
      • Bad Debt Clearing
      • Dynamic Close Factor
      • Earnings Accumulator
      • Cross-Asset Leverager & Deleverager
      • Liquidity Reserve
      • Rewards Distribution Model
      • Rate Manipulation Prevention
      • Rollover
    • 💲Fixed Rate Operations
      • 📥Deposits
      • 📤Borrows
    • 🔢Parameters
    • 📈Interest Rates Curves
    • ♻️Liquidations
      • 🤖Exactly's Bot
    • ⛓️Smart Contract Addresses
    • 🌐The Graph
    • 🔮Chainlink Price Feeds
  • Security
    • 🔎Audits
    • 🔑Access Control
    • 🛡️Hypernative
    • 🧪Testing
    • 🧯Emergency Procedure
    • 🐛Bug Bounty Program
  • Resources
    • 📃White Paper
    • 🔣Math Paper v1
    • 🔣Math Paper v2
    • 🤝Partnerships
    • 📺Presentations
    • 📣Brand Assets
  • Legal
    • ⚖️Terms and Conditions of Use
    • 🔏Privacy Policy
    • 🍪Cookies Policy
Powered by GitBook
On this page
  • How does it work?
  • Flash loan contract
  • Structure

Was this helpful?

  1. Guides
  2. Liquidations

Exactly's Bot

PreviousLiquidationsNextSmart Contract Addresses

Last updated 1 year ago

Was this helpful?

At Exactly, we developed our own open-source team-driven liquidation bot. You can check out the code here: .

We strongly advise and invite anyone interested in participating in Exactly's liquidations to fork from it and build on top.

How does it work?

The liquidation bot analyzes the users' positions using the events emitted by the protocol with the minimum number of calls to the contracts, thus making the bot more efficient in recreating such states.

After connecting to the RPC provider through a WebSocket, the bot subscribes to receive the events stream.

Each one of those events is parsed and transcribed into the user's data.

Whenever there's an idle moment on receiving new events, the bot does a check for liquidations.

If a position is in a state to be (with a less than 1), the liquidation function in the is called.

Important: to avoid reentrancy issues on Uniswap's contract, the bot must pick a pair of assets that is not the same pair of debt/collateral.

After this call, the bot liquidates the user's debt seizing the collateral with the highest value.

After the liquidations, the bot waits for more events and recreates the user's positions.

Flash loan contract

The flash loan contract calls the liquidation function in the .

It checks its amount on the specific debt asset available on the contract's balance to repay the user's debt. In case it has less than the amount needed to liquidate the user, it does as follow:

  1. Borrow on Uniswap V3 the difference between what it has and the user's debt

  2. Waits for a callback notifying it that the amount was received

  3. Repays the debt

  4. Receives the collateral

  5. Swaps it to the same as the user's debt

  6. Repays Uniswap V3

Structure

The project is structured as follows:

  • main.rs

    • Setups the bot to connect correctly to RPC Provider.

    • Starts the service and handles most of the errors.

  • service.rs: It's where most of the tasks are executed.

    • A subscription to the event's stream is made on the main thread.

    • Each event received is parsed.

    • Positions are created

    • A debounce for idleness is made in another thread.

    • When the bot is idle, this thread checks for liquidations

  • borrower.rs: This structure is used to store users' data.

  • exactly_oracle.rs: Helper to access price protocol used by the .protocol.

  • fixed_lender.rs: Stores updated information created by the protocol's emitted events about all the markets.

  • exactly_events.rs: Redirect the events to suitable structures.

  • config.rs: Handle environment variables such as RPC provider link access, wallet's private key, etc.

♻️
🤖
https://github.com/exactly/liquidation-bot
protocol
flash loan contract
liquidated
Health Factor