Pair.sol
Last updated
Last updated
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.
Adds liquidity to the pair.
Parameters
baseTokenAmount
uint256
The amount of base tokens to add.
fractionalTokenAmount
uint256
The amount of fractional tokens to add.
minLpTokenAmount
uint256
The minimum amount of LP tokens to mint.
minPrice
uint256
The minimum price that the pool should currently be at.
maxPrice
uint256
The maximum price that the pool should currently be at.
deadline
uint256
The deadline before the trade expires.
Returns
lpTokenAmount
uint256
The amount of LP tokens minted.
Removes liquidity from the pair.
Parameters
lpTokenAmount
uint256
The amount of LP tokens to burn.
minBaseTokenOutputAmount
uint256
The minimum amount of base tokens to receive.
minFractionalTokenOutputAmount
uint256
The minimum amount of fractional tokens to receive.
deadline
uint256
The deadline before the trade expires.
Returns
baseTokenOutputAmount
uint256
The amount of base tokens received.
fractionalTokenOutputAmount
uint256
The amount of fractional tokens received.
Buys fractional tokens from the pair.
Parameters
outputAmount
uint256
The amount of fractional tokens to buy.
maxInputAmount
uint256
The maximum amount of base tokens to spend.
deadline
uint256
The deadline before the trade expires.
Returns
inputAmount
uint256
The amount of base tokens spent.
Sells fractional tokens to the pair.
Parameters
inputAmount
uint256
The amount of fractional tokens to sell.
minOutputAmount
uint256
The minimum amount of base tokens to receive.
deadline
uint256
The deadline before the trade expires.
Returns
outputAmount
uint256
The amount of base tokens received.
Wraps NFTs into fractional tokens.
Parameters
tokenIds
uint256[]
The ids of the NFTs to wrap.
proofs
bytes32[][]
The merkle proofs for the NFTs proving that they can be used in the pair.
messages
Message.ReservoirOracle[]
Returns
fractionalTokenAmount
uint256
The amount of fractional tokens minted.
Unwraps fractional tokens into NFTs.
Parameters
tokenIds
uint256[]
The ids of the NFTs to unwrap.
withFee
bool
Whether to pay a fee for unwrapping or not.
Returns
fractionalTokenAmount
uint256
The amount of fractional tokens burned.
nftAdd Adds liquidity to the pair using NFTs.
Parameters
baseTokenAmount
uint256
The amount of base tokens to add.
tokenIds
uint256[]
The ids of the NFTs to add.
minLpTokenAmount
uint256
The minimum amount of lp tokens to receive.
minPrice
uint256
The minimum price of the pair.
maxPrice
uint256
The maximum price of the pair.
deadline
uint256
The deadline for the transaction.
proofs
bytes32[][]
The merkle proofs for the NFTs.
messages
Message.ReservoirOracle[]
Returns
lpTokenAmount
uint256
The amount of lp tokens minted.
Removes liquidity from the pair using NFTs.
Parameters
lpTokenAmount
uint256
The amount of lp tokens to remove.
minBaseTokenOutputAmount
uint256
The minimum amount of base tokens to receive.
deadline
uint256
The deadline before the trade expires.
tokenIds
uint256[]
The ids of the NFTs to remove.
withFee
bool
Whether to pay a fee for unwrapping or not.
Returns
baseTokenOutputAmount
uint256
The amount of base tokens received.
fractionalTokenOutputAmount
uint256
The amount of fractional tokens received.
Buys NFTs from the pair using base tokens.
Parameters
tokenIds
uint256[]
The ids of the NFTs to buy.
maxInputAmount
uint256
The maximum amount of base tokens to spend.
deadline
uint256
The deadline before the trade expires.
Returns
inputAmount
uint256
The amount of base tokens spent.
Sells NFTs to the pair for base tokens.
Parameters
tokenIds
uint256[]
The ids of the NFTs to sell.
minOutputAmount
uint256
The minimum amount of base tokens to receive.
deadline
uint256
The deadline before the trade expires.
proofs
bytes32[][]
The merkle proofs for the NFTs.
messages
Message.ReservoirOracle[]
Returns
outputAmount
uint256
The amount of base tokens received.
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.
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.
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
<none>
uint256
price The price of one fractional token in base tokens * 1e18.
The amount of base tokens required to buy a given amount of fractional tokens.
Calculated using the xyk invariant and a 30bps fee.
Parameters
outputAmount
uint256
The amount of fractional tokens to buy.
Returns
<none>
uint256
inputAmount The amount of base tokens required.
The amount of base tokens received for selling a given amount of fractional tokens.
Calculated using the xyk invariant and a 30bps fee.
Parameters
inputAmount
uint256
The amount of fractional tokens to sell.
Returns
<none>
uint256
outputAmount The amount of base tokens received.
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
baseTokenAmount
uint256
The amount of base tokens to add.
fractionalTokenAmount
uint256
The amount of fractional tokens to add.
lpTokenSupply
uint256
Returns
<none>
uint256
lpTokenAmount The amount of lp tokens received.
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
lpTokenAmount
uint256
The amount of lp tokens to burn.
Returns
<none>
uint256
baseTokenAmount The amount of base tokens received.
<none>
uint256
fractionalTokenAmount The amount of fractional tokens received.
Validates that the given tokenIds are valid for the contract's merkle root. Reverts if any of the tokenId proofs are invalid.
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.