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!
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.
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.
Why? Because the SPA Pool collects trading fees! As people swap tokens in the pool, small fees are added back into the pool’s total assets.
How it Works: Imagine the soup pot magically gets bigger as more flavors (fees) are added. Your original receipt still says “1 Share”, but that “1 Share” now represents a slightly larger amount of the total soup.
Your Balance Adjusts: The LPToken contract is smart. It knows the total value in the pool (totalSupply
) and the total number of shares issued (totalShares
). It calculates your actual token balance based on your number of shares (shares[your_address]
) relative to the total.
Your LPToken Balance = (Your Shares / Total Shares) * Total Pool Value (in LPToken terms)
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).
Getting LPTokens (Minting):
mint
function (as briefly mentioned in Chapter 1).(We won’t show the SPA Pool’s mint
function here, but know that it triggers the LPToken minting process).
Holding LPTokens:
Getting Your Tokens Back (Burning):
redeem
functions (e.g., redeemProportion
, redeemSingle
).(Again, the SPA Pool’s redeem
function triggers the LPToken burning process).
Transferring LPTokens:
LPToken.sol
contract uses a transferShares
function primarily, moving the underlying shares rather than a calculated token amount directly. Transferring shares effectively transfers the ownership slice of the pool.// --- 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.