LP Token Mechanism
Overview
LP (Liquidity Provider) tokens are credentials that represent a provider's share in a specific trading pair within JAMM DEX. Each trading pair has a corresponding LP token, implemented based on the JAMMERC20 contract. It not only complies with the ERC-20 standard but also supports the EIP-2612 permit function, providing a better user experience.
JAMMERC20 Contract Implementation
Basic Information
// from JAMMERC20.sol
contract JAMMERC20 is IJAMMERC20 {
string public constant name = "JAMM LPs";
string public constant symbol = "JAMM-LP";
uint8 public constant decimals = 18;
uint public totalSupply;
mapping(address => uint) public balanceOf;
mapping(address => mapping(address => uint)) public allowance;
// ...
}LP Token Characteristics:
Uniform Name: All LP tokens for all pairs are named "JAMM LPs".
Uniform Symbol: "JAMM-LP".
Precision: 18 decimals.
Uniqueness: Each trading pair is a separate instance of the LP token contract.
EIP-2612 Permit Support
JAMM DEX's LP tokens support the EIP-2612 standard, allowing users to grant approvals via a signature, eliminating the need for a separate approve transaction.
LP Token Lifecycle
Minting
When a user adds liquidity to a pool, corresponding LP tokens are minted. This logic is implemented in JAMMPair.sol:
Burning
When a user removes liquidity, the corresponding LP tokens are burned:
Minimum Liquidity Mechanism
Permanent Lock
Purpose:
To prevent the liquidity pool from being completely drained, which would break price calculations.
To prevent certain types of malicious manipulation attacks.
permit Function Explained
permit Function ExplainedAdvantage of Signature Approval
Traditional ERC-20 approvals require two transactions: approve and transferFrom. The permit function allows users to complete the approval and the action in a single on-chain transaction, preceded by an offline signature. This saves gas and improves user experience.
Application in the Router
The JAMMRouter contract provides a function for removing liquidity using permit:
Usage Example
Querying LP Token Information
Removing Liquidity with permit
permitSummary
The LP token mechanism in JAMM DEX has the following features:
Standard Compliance: Fully compliant with the ERC-20 standard.
Permit Support: Offers a better user experience and gas efficiency through EIP-2612.
Secure Design: Multiple security mechanisms, including re-entrancy guards, overflow protection, and signature verification.
Flexible Use: Transferable and tradable liquidity credentials.
Transparent Value: The value corresponds directly to the share of assets in the pool.
LP tokens are a vital part of the JAMM DEX ecosystem, providing liquidity providers with a flexible way to manage their assets.