Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support LP token swaps on UniswapV2 #30

Open
kayibal opened this issue Jan 28, 2025 · 0 comments
Open

feat: Support LP token swaps on UniswapV2 #30

kayibal opened this issue Jan 28, 2025 · 0 comments

Comments

@kayibal
Copy link
Contributor

kayibal commented Jan 28, 2025

Support selling and buying LP tokens on the UniswapV2Executor.

Corresponding simulation issue:
propeller-heads/tycho-simulation#129

The Executor contract should use the same steps the simulation logic uses:

  • Sell LP token
    • check is the input token is an LP token
    • burn the LP token in exchange for two reserves
    • sell one of the reserves on the pool to provide a single reserve to the caller
  • Buy LP token
    • check if the output token is an LP token
    • take one of the reserves and swap it to the second reserve
      • This will require a method that uses the current spot price to determine how much of one reserve should be swapped for the other.
    • then deposit both reserves to receive the LP token

Most of this logic is already implemented in the UniswapV2Router02 [docs] [code] in the following methods: addLiquidity, removeLiquidity, addLiquidityETH, removeLiquidityETH. We can perhaps copy these methods into our UniswapV2Executor to avoid some calls to an external contract (and maybe save gas).

On the encoding side, nothing needs to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant