Technical User Flows

Creating a Trading Pool

To create a trading pool, you need to provide the following parameters:

  • nft: The NFT contract of the collection the pool trades.

  • bondingCurve: The bonding curve for the pool to price NFTs; it must be whitelisted.

  • assetRecipient: The address that receives the assets traders give during trades. If set to address(0), assets will be sent to the pool address. Not available for TRADE pools.

  • receiver: The address that receives the LP token generated to represent ownership of the pool.

  • poolType: TOKEN, NFT, or TRADE.

  • delta: The delta value used by the bonding curve. The meaning of delta depends on the specific curve.

  • fee: The fee taken by the LP in each trade. Can only be non-zero if _poolType is TRADE.

  • spotPrice: The initial selling spot price.

  • props: A bytes variable for static variables, used by the bonding curve.

  • state: A bytes variable for stateful variables, used by the bonding curve.

  • royaltyNumerator: All trades result in royaltyNumerator * <trade amount> / 1e6 being sent to the account to which the traded NFT's royalties are awardable. Must be 0 if _nft is not IERC2981 and no recipient fallback is set.

  • royaltyRecipientFallback: An address that receives all royalties if not address(0) and ERC2981 is not supported or ERC2981 recipient is not set.

  • initialNFTIDs: The list of IDs of NFTs to transfer from the sender to the pool.

To define filter parameters, use the NFTFilterParams struct:

  • merkleRoot: The root of the Merkle tree of the allowed set of token IDs. Filters should accept at least one token ID. A pool that accepts no tokens is a dead pool.

  • encodedTokenIDs: The encoding of the token IDs, an efficient hexadecimal packing of the token IDs to minimize gas spent on emitting the event.

  • initialProof: The Merkle multiproof for initial NFT IDs. Together with initialProofFlags, it forms the Merkle proof for the initial set of NFT tokens put into the pool. Flags are used to indicate which proof is used for which token ID.

  • initialProofFlags: The Merkle multiproof flags for initial NFT IDs. Together with initialProof, it forms the Merkle proof for the initial set of NFT tokens put into the pool. Flags are used to indicate which proof is used for which token ID.

  • externalFilter: The address implementing IExternalFilter for external filtering.

Note on initialNFTIDs: The initial NFT IDs of the NFTs you wish to put into the pool. You must be the owner of these NFT IDs. Note that initial NFT IDs must be sorted using the filter_code library. This ensures consistency with initialProof and initialProofFlags. If it's not sorted, a "not accepted" error will be thrown. The sorted list of IDs is the leaves field of any Merkle proof you generate.

To generate filter parameters from the library:

  1. Call .root() for the Merkle root.

  2. Call .encode() for encoded Token IDs.

javascriptCopy code// tokenIDFilter is the main object of the library
// Example: accept [1, 2, 3, 4, 5]
// Pool starts with [1, 2, 3]

let tokenIDFilter = new tokenIDs([1n, 2n, 3n, 4n, 5n]);

// Merkle multiproof is order sensitive. Always pass proof.leaves to tokenId fields
// Required by the smart contract if a Merkle proof is needed
const unsortedIDs = [1n, 2n, 3n];
const initialNFTIDs = tokenIDFilter.sort([1n, 2n, 3n]);
const root = tokenIDFilter.root();
const encodedTokenIDs = tokenIDFilter.encode();
const {proof: initialProof, proofFlags: initialProofFlags, leaves: initialNFTIDs } = tokenIDFilter.proofOf(initialNFTIDs);

Last updated

Logo

© 2023 Collection. All rights reserved