LP Tokens Contract
Overview
The Native LP Token contract is a yield-bearing vault that represents the shares and positions for all liquidity providers in Native.
The contract also helps distribute yield from the funding interest collected from private market makers, who utilise the liquidity to facilitate trading with Credit-Based swaps on the Native trading engine.
Note that the balance of the token directly represents the amount of underlying tokens in users' addresses, as well as the totalSupply number. To get shares, use shares and totalShares.
Inherits
ERC20, Ownable, ReentrancyGuardTransient, Pausable
State Variables
underlying
The underlying token that this LP token represents
IERC20Metadata public underlying;creditVault
The address of the credit vault contract
address public creditVault;_decimals
The number of decimals for this token, matching the underlying token's decimals
earlyWithdrawFeeBips
Early withdrawal fee in basis points (1 bip = 0.01%)
Applied to prevent front-running by users who deposit right before yield distribution and immediately redeem after
totalUnderlying
Total amount of underlying assets deposited by LPs
totalShares
Total number of shares issued
minRedeemInterval
Minimum time interval between deposit and redeem (in seconds)
minDeposit
Minimum amount required for deposits
shares
Mapping of user addresses to their share balances
lastDepositTimestamp
Mapping of user addresses to their last deposit timestamp
Functions
constructor
deposit
Deposit underlying tokens to mint LP tokens
Parameters
amount
uint256
Amount of underlying tokens to deposit
Returns
sharesToMint
uint256
Amount of shares to be minted
redeem
Redeem LP tokens for underlying tokens
Parameters
sharesToBurn
uint256
Amount of shares to burn
Returns
underlyingAmount
uint256
Amount of underlying tokens received
distributeYield
Distributes yield to LP token holders
Can only be called by the credit vault
Parameters
yieldAmount
uint256
Amount of yield to distribute
balanceOf
Gets the underlying token balance of an account
Parameters
account
address
The address to check the balance for
Returns
<none>
uint256
The amount of underlying tokens the account effectively owns
totalSupply
Gets the total supply of underlying tokens in the pool
Returns
<none>
uint256
The total amount of underlying tokens managed by this contract
sharesOf
Gets the number of shares owned by an account
Parameters
account
address
The address to check shares for
Returns
<none>
uint256
The number of shares owned by the account
getUnderlyingByShares
Calculates the underlying token amount for a given number of shares
Parameters
sharesAmount
uint256
The number of shares to convert
Returns
<none>
uint256
The corresponding amount of underlying tokens
getSharesByUnderlying
Calculates the number of shares for a given amount of underlying tokens
Parameters
underlyingAmount
uint256
The amount of underlying tokens to convert
Returns
<none>
uint256
The corresponding number of shares
exchangeRate
Gets the current exchange rate between shares and underlying tokens
Returns
<none>
uint256
The exchange rate scaled by 1e18 (1:1 = 1e18)
decimals
Gets the number of decimals for this token
Returns
<none>
uint8
The number of decimals, matching the underlying token
pause
Pauses all deposit and redeem operations
Can only be called by the owner
unpause
Unpauses all deposit and redeem operations
Can only be called by the owner
setMinDeposit
Sets the minimum deposit amount
Can only be called by the owner
Parameters
_minDeposit
uint256
New minimum deposit amount
setMinRedeemInterval
Sets the minimum time interval required between deposit and redeem
Can only be called by the owner
Parameters
_interval
uint256
New minimum interval in seconds
setEarlyWithdrawFeeBips
Sets the early withdrawal fee in basis points (BIPs)
Can only be called by the owner
Parameters
_earlyWithdrawFeeBips
uint256
New early withdrawal fee in BIPs
_mintShares
_burnShares
_transferShares
_transfer
Override ERC20's _transfer to handle yield-bearing LP token transfers
Since this is a yield-bearing token, the actual transfer is done by transferring shares rather than token amounts directly. The shares represent the user's proportion of the total underlying assets including yield.
Parameters
from
address
The address to transfer from
to
address
The address to transfer to
amount
uint256
The underlying token amount to transfer
Events
YieldDistributed
Event emitted when yield is distributed to LP holders
MinRedeemIntervalUpdated
Event emitted when minimum redeem interval is updated
TransferShares
Event emitted when shares are transferred between addresses
SharesMinted
Event emitted when new shares are minted
SharesBurned
Event emitted when shares are burned
MinDepositUpdated
Event emitted when minimum deposit amount is updated
EarlyWithdrawFeeBipsUpdated
Event emitted when early withdraw fee is updated
Last updated