🤖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.
Parameters | Description | Attribute |
---|---|---|
_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. | ERC20 address, initially will be just WETH - 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 |
_perpetualDEXIndex | Index for derivative dex to be used (right now only MCDEX is integrated, and its corresponding index is 0). | Integer |
_usdLemma | Address of USDLemma contract. | ERC20 address, always will be:0xdb41ab644abca7f5ac579a5cf2f41e606c2d6abc |
_poolFee | Fee tier for the USDL<>WETH uniswap V3 pool you will arbitrage. | Integer, you can pass in: 500, 3000 or 10000. Those respectively correspond to the following Uniswap fees: 0.05% 0.3% and 1%. |
_swapRouter | Router for stateless execution of swaps against Uniswap V3 address, here. | Smart contract address, will always be: 0xE592427A0AEce92De3Edee1F18E0157C05861564 |
_flashLender | Smart contract address |
arb
Function purpose: execute the arbitrage steps listed above.
Argument | Description | Attribute |
---|---|---|
amountOfCollateralToBorrow | Amount of WETH to borrow via the flashloan. Here is a reference script for how to calculate that sum. | 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