Skip to main content

LPToken

LPToken.sol contains the implementation of APWine's AMM LP Tokens.

ERC1155 and ID encoding#

AMM LP tokens follow the ERC1155 standard. Only one LPToken.sol contract instance is deployed for all futures, periods, and pairs. We differentiate the LP Tokens in the ID of the token.

Token ID structure (256 bits):

  • [255 ... 192] (64 bits): AMM ID. The ID of the exchange for a specific future.
  • [191 ... 128] (64 bits): encode the period index
  • [128 ... 96] (32 bits): encode the pair ID. One bit would be necessary but some future pairs might be added later.
  • [95 ... 0] (96 bits): reserved for future use cases.

Methods#

ERC1155 standard#

All the standard EIP1155 methods are implemented. In particular, methods such as balanceOf, balanceOfBatch.

burnFrom#

function burnFrom(    address account,    uint256 id,    uint256 value)

Verifies that the sender is authorized (AMM pool or admin) or the the account to burn the token from, and butn the value of token with id id

mint#

function mint(    address to,    uint64 _ammId,    uint64 _periodIndex,    uint32 _pairId,    uint256 amount,    bytes memory data)

Verifies that the sender is an authorized minter and call the ERC115 mint method to mint the given amount of token with the corresponding id (constructed from _ammId, _periodIndex and _pairId).

getAMMId#

function getAMMId(uint256 _id)

Get the AMM ID corresponding to the token id _id. The AMM id is the identifier of the AMM for a given future (ex: the AMM for DAI-30D).

getPeriodIndex#

function getPeriodIndex(uint256 _id)

Get the [period] index corresponding to the LP token with id _id.

getPairId#

function getPairId(uint256 _id)

Get the pairID corresponding to the LP Token with id _id. The pairID precize if the pool is a PT/Underlying pool or PT/FYT pool.

Follow this link for more details about the AMM pool architecture.