Pair.sol
Inherits: ERC20, ERC721TokenReceiver
Author: out.eth (@outdoteth)
A pair of an NFT and a base token that can be used to create and trade fractionalized NFTs.
State Variables
CLOSE_GRACE_PERIOD
ONE
MINIMUM_LIQUIDITY
nft
baseToken
merkleRoot
lpToken
caviar
closeTimestamp
Functions
constructor
add
Adds liquidity to the pair.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of base tokens to add. |
|
| The amount of fractional tokens to add. |
|
| The minimum amount of LP tokens to mint. |
|
| The minimum price that the pool should currently be at. |
|
| The maximum price that the pool should currently be at. |
|
| The deadline before the trade expires. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of LP tokens minted. |
remove
Removes liquidity from the pair.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of LP tokens to burn. |
|
| The minimum amount of base tokens to receive. |
|
| The minimum amount of fractional tokens to receive. |
|
| The deadline before the trade expires. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens received. |
|
| The amount of fractional tokens received. |
buy
Buys fractional tokens from the pair.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens to buy. |
|
| The maximum amount of base tokens to spend. |
|
| The deadline before the trade expires. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens spent. |
sell
Sells fractional tokens to the pair.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens to sell. |
|
| The minimum amount of base tokens to receive. |
|
| The deadline before the trade expires. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens received. |
wrap
Wraps NFTs into fractional tokens.
Parameters
Name | Type | Description |
---|---|---|
|
| The ids of the NFTs to wrap. |
|
| The merkle proofs for the NFTs proving that they can be used in the pair. |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens minted. |
unwrap
Unwraps fractional tokens into NFTs.
Parameters
Name | Type | Description |
---|---|---|
|
| The ids of the NFTs to unwrap. |
|
| Whether to pay a fee for unwrapping or not. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens burned. |
nftAdd
nftAdd Adds liquidity to the pair using NFTs.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of base tokens to add. |
|
| The ids of the NFTs to add. |
|
| The minimum amount of lp tokens to receive. |
|
| The minimum price of the pair. |
|
| The maximum price of the pair. |
|
| The deadline for the transaction. |
|
| The merkle proofs for the NFTs. |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| The amount of lp tokens minted. |
nftRemove
Removes liquidity from the pair using NFTs.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of lp tokens to remove. |
|
| The minimum amount of base tokens to receive. |
|
| The deadline before the trade expires. |
|
| The ids of the NFTs to remove. |
|
| Whether to pay a fee for unwrapping or not. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens received. |
|
| The amount of fractional tokens received. |
nftBuy
Buys NFTs from the pair using base tokens.
Parameters
Name | Type | Description |
---|---|---|
|
| The ids of the NFTs to buy. |
|
| The maximum amount of base tokens to spend. |
|
| The deadline before the trade expires. |
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens spent. |
nftSell
Sells NFTs to the pair for base tokens.
Parameters
Name | Type | Description |
---|---|---|
|
| The ids of the NFTs to sell. |
|
| The minimum amount of base tokens to receive. |
|
| The deadline before the trade expires. |
|
| The merkle proofs for the NFTs. |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| The amount of base tokens received. |
close
Closes the pair to new wraps.
Can only be called by the caviar owner. This is used as an emergency exit in case the caviar owner suspects that the pair has been compromised.
withdraw
Withdraws a particular NFT from the pair.
Can only be called by the caviar owner after the close grace period has passed. This is used to auction off the NFTs in the pair in case NFTs get stuck due to liquidity imbalances. Proceeds from the auction should be distributed pro rata to fractional token holders. See documentation for more details.
baseTokenReserves
fractionalTokenReserves
price
The current price of one fractional token in base tokens with 18 decimals of precision.
Calculated by dividing the base token reserves by the fractional token reserves.
Returns
Name | Type | Description |
---|---|---|
|
| price The price of one fractional token in base tokens * 1e18. |
buyQuote
The amount of base tokens required to buy a given amount of fractional tokens.
Calculated using the xyk invariant and a 30bps fee.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens to buy. |
Returns
Name | Type | Description |
---|---|---|
|
| inputAmount The amount of base tokens required. |
sellQuote
The amount of base tokens received for selling a given amount of fractional tokens.
Calculated using the xyk invariant and a 30bps fee.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of fractional tokens to sell. |
Returns
Name | Type | Description |
---|---|---|
|
| outputAmount The amount of base tokens received. |
addQuote
The amount of lp tokens received for adding a given amount of base tokens and fractional tokens.
Calculated as a share of existing deposits. If there are no existing deposits, then initializes to sqrt(baseTokenAmount * fractionalTokenAmount).
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of base tokens to add. |
|
| The amount of fractional tokens to add. |
|
|
Returns
Name | Type | Description |
---|---|---|
|
| lpTokenAmount The amount of lp tokens received. |
removeQuote
The amount of base tokens and fractional tokens received for burning a given amount of lp tokens.
Calculated as a share of existing deposits.
Parameters
Name | Type | Description |
---|---|---|
|
| The amount of lp tokens to burn. |
Returns
Name | Type | Description |
---|---|---|
|
| baseTokenAmount The amount of base tokens received. |
|
| fractionalTokenAmount The amount of fractional tokens received. |
_transferFrom
_validateTokensAreNotStolen
_validateTokenIds
Validates that the given tokenIds are valid for the contract's merkle root. Reverts if any of the tokenId proofs are invalid.
_baseTokenReserves
Returns the current base token reserves. If the base token is ETH then it ignores the msg.value that is being sent in the current call context - this is to ensure the xyk math is correct in the buy() and add() functions.
Events
Add
Remove
Buy
Sell
Wrap
Unwrap
Close
Withdraw
Last updated