Provides three implementations of NFT liquidity pools, allowing users to trade NFTs for fungible tokens and vice versa. Each implementation uses a different token standard (Coin, Legacy Token V1, Fungible Asset) to demonstrate the evolution of Aptos token standards.
Advanced
- NFT liquidity: Converting NFTs to fungible tokens and back
- Random selection: Pseudorandom NFT selection when claiming from the pool
- Three token standards compared:
liquid_coin.move-- Uses Coin + Token Objects (V2)liquid_coin_legacy.move-- Uses Coin + Legacy Tokens (V1)liquid_fungible_asset.move-- Uses Fungible Assets + Token Objects (V2)
- SmartVector: Efficient pool storage for locked NFTs
- Friend modules: Shared
common.moveutilities viapublic(friend) - Sticky objects: Non-deletable objects required for fungible asset metadata
| Module | File | Token Standard | Fungible Standard |
|---|---|---|---|
common |
common.move |
-- | -- |
liquid_coin |
liquid_coin.move |
Token Objects (V2) | Coin |
liquid_coin_legacy |
liquid_coin_legacy.move |
Legacy Tokens (V1) | Coin |
liquid_fungible_asset |
liquid_fungible_asset.move |
Token Objects (V2) | Fungible Asset |
- Creator creates a liquid token for a fixed-supply collection
- Total fungible supply = collection size * 10^decimals
- User deposits NFT (
liquify): NFT goes to pool, user gets fungible tokens - User claims NFT (
claim): User pays fungible tokens, gets a random NFT from pool
| Function | Visibility | Description |
|---|---|---|
create_liquid_token |
entry |
Creates the liquidity pool for a collection |
liquify |
entry |
Deposits NFTs into the pool, receives fungible tokens |
claim |
entry |
Pays fungible tokens, receives random NFTs from pool |
// Uses AUID (globally unique) + timestamp to generate unpredictable index
let auid = transaction_context::generate_auid_address();
let bytes = bcs::to_bytes(&auid);
bytes.append(bcs::to_bytes(×tamp::now_microseconds()));
let hash = hash::sha3_256(bytes);
let val = from_bcs::to_u256(hash) % (pool_size as u256);Note: For production use, consider the Aptos on-chain randomness API instead.
| Package | snippets/liquid-nfts |
| Named address | fraction_addr |
aptos move publish --named-addresses fraction_addr=default --package-dir snippets/liquid-nftsaptos move test --dev --package-dir snippets/liquid-nfts- Fractional Token -- Single-NFT fractionalization (vs pool-based)
- Lootbox / Mystery Box -- Another randomness-based distribution pattern
- Composable NFTs -- Dynamic NFT composition