The goal is to
- Continuously monitor the impermanent loss incurred for a position in Uniswap V3
- And if there is a loss, we need to exit the position
- It has to be 100% automated (the end user should not be expected to be online signing the transaction when the liquidity is pulled out)
We can use the Uniswap V3's subgraph to know a position's details like tokens, price at the time of providing liquidity, etc. We will also know the current tick in the pool.
We can use the following Impermanent Loss Calculation.
When the loss crosses a threshold (like say 50%), we need to trigger the recovery process.
We need to deploy a simple smart contract that wraps around Uniswap V3's LP exiting function and trigger this function when the above monitoring logic is executed. The output of this should result in the wallet having the tokens back with the position fuly exited.
After exiting the liquidity, it will be great if all the tokens are converted back to USDC at the current market price and deposited into the user's wallet