Chapter 2: LPToken

In Chapter 1: SelfPeggingAsset (SPA) Pool, we learned about the automated exchange booth (the SPA Pool) where users can swap tokens. We also mentioned that people called Liquidity Providers (LPs) deposit the tokens needed for these swaps. But how does the pool keep track of who deposited what and how much they own?

That’s where the LPToken comes in!

What Problem Does the LPToken Solve?

Imagine you and your friends decide to pool your pocket money together to run a lemonade stand. You put in $10, and your friend puts in $10. How do you prove you own half of the money in the cash box? You need some kind of receipt or share certificate.

Similarly, when a Liquidity Provider deposits tokens into the SelfPeggingAsset (SPA) Pool, they need proof of their contribution and their share of the pool’s total assets. The LPToken serves exactly this purpose.

What is an LPToken?

The LPToken is a special type of digital token that represents your share of the assets locked inside a specific SelfPeggingAsset (SPA) Pool.

Think back to the shared soup pot (the SPA Pool) analogy from Chapter 1.

Key Feature: It’s a Rebasing Token

This is the most important and perhaps trickiest part to understand initially. Unlike regular tokens where your balance only changes if you send or receive them, an LPToken’s balance can change automatically over time.

So, even if the number of shares you hold stays the same, but the value of each share will increase as the pool earns fees. This “automatic” balance adjustment is called rebasing ( although there can be other aspects to rebasing but leave them for later).

How Do I Get and Use LPTokens?

  1. Getting LPTokens (Minting):

    (We won’t show the SPA Pool’s mint function here, but know that it triggers the LPToken minting process).

  2. Holding LPTokens:

  3. Getting Your Tokens Back (Burning):

    (Again, the SPA Pool’s redeem function triggers the LPToken burning process).

  4. Transferring LPTokens:

    // --- File: LPToken.sol (Conceptual Snippet) ---
    
    // Alice wants to transfer 50 shares to Bob
    // Assume 'lpToken' is the deployed LPToken contract instance
    // Assume Alice currently holds 100 shares
    
    // Alice calls transferShares
    lpToken.transferShares(bob_address, 50);
    // Now Alice holds 50 shares, Bob holds 50 shares.
    // The actual token VALUE of these 50 shares will depend
    // on the pool's total value at any given time.