Skip to content

feat: Support LP token swaps on UniswapV2 #129

@kayibal

Description

@kayibal

Context

Swapping into and out of LP tokens is not widely supported likely due to the complexity of receiving or spending multiple tokens during the transaction. We will handle the additional tokens within the same pool, ensuring that the process of interacting with LP tokens mimics the simplicity of a standard-token swap.

Key Interfaces

No interface changes are required within this repository to support this feature. All necessary logic is to be implemented within the ProtocolSim trait.

Technical Details

  • Add the following fields to the struct:

    • liquidity
    • total_supply
  • Implement the following methods:

    • mint: Handle the addition of liquidity and LP token issuance.
    • burn: Handle the removal of liquidity and LP token redemption.
  • Adjust the get_amount_out logic:

    • Trigger the mint and burn methods as needed.
    • Swap any remaining amount of the superfluous token into the out_token.
  • Implement spot price estimation for cases involving LP tokens:

    • Example: If a pool has 10 LP tokens, 10 ETH, and 1000 USDC:
    • Spot price for 1 LP token in USDC:
    • 1 LP = 1 ETH * spot_price(ETH, USDC) + 100 USDC = 200 USDC
  • Update Executor contracts: feat: Support LP token swaps on UniswapV2 tycho-execution#30

  • Update Indexing logic: feat: Support LP token swaps on UniswapV2 tycho-protocol-sdk#141

Dialogue / Q&A

  • Q: Why are we swapping on a pool after withdrawing liquidity?
    A: We are aware that this approach is suboptimal but are prioritizing simplicity over optimization for this implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions