How to run an arbitrage bot?
Every time USDL deviates from its 1 USD peg, an almost riskless arbitrage opportunity arises. The only potential downside is having to pay gas costs for a transaction that doesn't go through. See here for the high level details explaining the concepts behind the price stability mechanism.
Contract: LemmaUniswapV3ArbBot
This contract is a reference implementation for an arbitrage bot that profits off of the price deviations of USDL. The high level steps in this implementation are:
Check if USDL has deviated from its 1 USD price on the Uniswap v3 WETH<>USDL pool
If USDL is worth more than 1 USD, then in a single transaction, the following happens:
A flashloan is used to borrow WETH
The WETH is used to mint USDL
The USDL is swapped for WETH in the Uniswap pool
The loan is repaid using the the profits in WETH
If USDL is worth less than 1 USD, then in a single transaction, the following happens:
A flashloan is used to borrow WETH
The WETH is swapped for USDL in the Uniswap pool
The USDL is redeemed for 1 USD worth of WETH
The loan is repaid using the the profits in WETH
The repository with the reference contract implementation can be found here: https://github.com/lemma-finance/usdl-arbitrageur
Public Functions
constructor
Function purpose: initializes the bot contract & points it to the chosen Uniswap v3 pair to arbitrage (in the example above that would be the USDL/WETH pair) and to the USDLemma contracts.
_collateral
Address for the collateral type to be used in the arbitrage.
eg. for a USDL<>WETH arbitrage, the _collateral address would be the WETH address.
_perpetualDEXIndex
Index for derivative dex to be used (right now only MCDEX is integrated, and its corresponding index is 0).
Integer
_usdLemma
_poolFee
Integer, you can pass in: 500, 3000 or 10000. Those respectively correspond to the following Uniswap fees: 0.05% 0.3% and 1%.
_swapRouter
_flashLender
Smart contract address
arb
Function purpose: execute the arbitrage steps listed above.
amountOfCollateralToBorrow
Amount of WETH to borrow via the flashloan.
WETH, 18 decimals
amountOfUSDLToMint
Amount of USDL to be minted. If USDL needs to be redeemed then this should be 0.
USD, 18 decimals
Last updated