Skip to content

feat: Support LP token swaps on UniswapV2 #30

Description

@kayibal

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions