Flashbots Integration
Walkthrough showing how Oval uses Flashbot's MEV-share on Ethereum Sepolia testnet.
This technical example shows a script and a series of sample contracts to illustrate a complete end-to-end Oval workflow in Sepolia with Flashbots. This demonstration will highlight how a searcher monitors a Price Feed update in a data feed oracle, such as Chainlink. The searcher then participates in the Oval auction specific to that price update and subsequently executes the actual liquidation. This technical example also presents numerical examples to explain how the searcher realizes a profit from the liquidation and how the protocol also earns a share of the liquidation proceeds.
You can find the scripts in the oval-quickstart repository.
Running the sample Flashbots integration on Ethereum Sepolia
To demonstrate the integration, we will run a set of scripts against Sepolia. To start with you will need a few things to proceed:
Foundry Installation: Install Foundry from here.
Sepolia RPC URL: Use Infura or similar services.
Etherscan API Key for Sepolia: Optional, obtainable here.
Then, run the following commands to clone the quickstart and install the dependencies.
1. Deploy the demo contracts:
Run the following command in the root folder of the oval-quickstart repository.
2. Run the liquidation script with Flashbots in Sepolia:
First fill in the contracts addresses deployed in previous steps in a .env
file and the necessary keys and urls showed in /liquidation-demo-flashbots/.env.example
:
Then run the liquidation demo script from the /liquidation-demo-flashbots
folder in oval-quickstart
Overview of the liquidation demo workflow
Here’s a streamlined overview of this workflow:
A user creates a collateralized position in an example money market, named OvalLiquidationDemo.
The price feed used by OvalLiquidationDemo is updated, rendering the user's position undercollateralized and eligible for liquidation . Â
A searcher identifies this opportunity and submits a bundle to liquidate the user. This action triggers an auction within MEV-Share, a process similar to what a traditional Liquidator would do without Oval. In this auction, Searchers compete against each other, with the highest bidder winning the right to execute the liquidation .
The Searcher is required to include a payment to the builder within the bundle, representing their bid in the Order Flow Auction occurring in MEV-Share. This is a standard practice.
When submitting the liquidation bundle to the Oval Node, a price unlock bundle is added in front. For this demonstration, the searcher's bundle already includes this price unlock bundle, but this will not be the case in a production environment where the Oval Node would do this role (see Oval Node). The price unlock bundle contains refund instructions to compensate the protocol with a portion of the winning auction bid.
Once the winning bundle is selected, the Oval price feed update is used, making the new price available for use. Subsequently, the liquidation is executed, including both the payment to the builder and a kickback to the protocol. In this example, the protocol receives 90% of the builder's payment, equating to 90% of the MEV extracted from this transaction.
Contract Overview
This example involves the following contracts:
OvalLiquidationDemo: This is a mock money market contract where users can create ETH collateralized positions using the
updateCollateralisedPosition()
function. The contract assesses the collateralized value by obtaining the price from an Oval ofChainlinkOvalImmutable
, which reads from a mock Chainlink price feed,OvalLiquidationDemoPriceFeed
OvalLiquidationDemoPriceFeed: This mock price feed functions similarly to a Chainlink price feed. The owner has the ability to push new prices, a feature especially useful for the purposes of this demo.
ChainlinkOvalImmutable: This is the Oval contract that the money market references. It wraps the Chainlink price feed that we call
OvalLiquidationDemoPriceFeed
to supply prices to the consumer contract.PayBuilder: An auxiliary contract designed to facilitate the searcher in sending the builder payment transaction.
Liquidation script overview
We will now delve into the liquidation script, highlighting key aspects step by step:
Creating a Collateralized Position in a Mock Money Market: A user establishes a collateralized position using the following code:
Updating the Price Feed in OvalLiquidationDemo: This step renders the user's position undercollateralized and subject to liquidation. In a production environment, this update would typically be sent by a Chainlink oracle and detected in the public mempool by the searcher.
Submission of Liquidation Bundle by the Searcher: The searcher identifies the liquidation opportunity and submits a bundle to the Oval Node. In this demo, the searcher's bundle includes a price unlock bundle, although this won't be necessary in a production setting as this is done by the Oval Node. The price unlock bundle includes instructions for refunding a portion of the winning auction bid to the protocol.
Preparation of the Unlock and Liquidation Bundles: The searcher prepares the liquidation bundle, aiming to backrun the price update in the oracle. Notice the unlock price bundle prepended only needed in this testnet demo.
Configuring the Refund in the Searcher's Bundle: The searcher sets up a refund configuration within their bundle to transfer a percentage of the builder payment (90% in this demo) to the protocol. This configuration is also done by the Oval Node in production.
The following example output is run on Goerli, not Sepolia, but still illustrates the expected result.
Execution and Monitoring of the Liquidation Process: After submitting the searcher bundle to Flashbots, we wait for its inclusion. Once included, we can observe all the transactions involved in the liquidation. Here's an example log from this script on Goerli:
On the block explorer here https://goerli.etherscan.io/txs?block=10351968&p=2, we can verify all the transactions executed in the expected order in block 10351968.
The liquidation process concludes with the builder receiving 90% of the liquidation size, and a 90% kickback of the builder payment goes to the protocol. The figures align with our script's calculations.
Last updated