LP Tokens Contract

Overview

Native LP Token contract is a yield-bearing vault that represent the shares and positions for all liquidity providers in Native.

The contract also helps distribute yield from the funding interests, collected from private market makers, who utilise the liquidity to facilitate trading with Credit-Based swaps of the Native trading engine.

Mind 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

Name
Type
Description

amount

uint256

Amount of underlying tokens to deposit

Returns

Name
Type
Description

sharesToMint

uint256

Amount of shares to be minted

redeem

Redeem LP tokens for underlying tokens

Parameters

Name
Type
Description

sharesToBurn

uint256

Amount of shares to burn

Returns

Name
Type
Description

underlyingAmount

uint256

Amount of underlying tokens received

distributeYield

Distributes yield to LP token holders

Can only be called by the credit vault

Parameters

Name
Type
Description

yieldAmount

uint256

Amount of yield to distribute

balanceOf

Gets the underlying token balance of an account

Parameters

Name
Type
Description

account

address

The address to check the balance for

Returns

Name
Type
Description

<none>

uint256

The amount of underlying tokens the account effectively owns

totalSupply

Gets the total supply of underlying tokens in the pool

Returns

Name
Type
Description

<none>

uint256

The total amount of underlying tokens managed by this contract

sharesOf

Gets the number of shares owned by an account

Parameters

Name
Type
Description

account

address

The address to check shares for

Returns

Name
Type
Description

<none>

uint256

The number of shares owned by the account

getUnderlyingByShares

Calculates the underlying token amount for a given number of shares

Parameters

Name
Type
Description

sharesAmount

uint256

The number of shares to convert

Returns

Name
Type
Description

<none>

uint256

The corresponding amount of underlying tokens

getSharesByUnderlying

Calculates the number of shares for a given amount of underlying tokens

Parameters

Name
Type
Description

underlyingAmount

uint256

The amount of underlying tokens to convert

Returns

Name
Type
Description

<none>

uint256

The corresponding number of shares

exchangeRate

Gets the current exchange rate between shares and underlying tokens

Returns

Name
Type
Description

<none>

uint256

The exchange rate scaled by 1e18 (1:1 = 1e18)

decimals

Gets the number of decimals for this token

Returns

Name
Type
Description

<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

Name
Type
Description

_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

Name
Type
Description

_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

Name
Type
Description

_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

Name
Type
Description

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