Skip to content

Tokenize a pools.trade fee NFT

From /tokenize or a script: approve the fee NFT door factory, then tokenize with the fee NFT, its term and a market.

On this page

A pools.trade fee NFT goes into a revenue token in one call, and the token's income is the ETH the NFT is paid. The NFT is locked in a door of its own until a date or for good, and goes back to the wallet that added it at the end of its term.

Claim what is pending on pools.trade first: what is still pending when the fee NFT moves becomes the revenue token's income.

In the app

  1. Open /tokenize with the wallet that holds the fee NFT. Your wallet lists it with its pair: tick it, press Tokenize, set the terms and sign, as Tokenize a fee right you already hold shows.
  2. Or open By id and its pools.trade fee NFT card: type the vault and the fee NFT's id, press Read the fee NFT, set the terms, and press Approve and tokenize, or Tokenize the fee NFT when the approval is already in place.

Either way the app approves the NFT to the tokenizer's fee NFT door factory where it is not approved yet, then sends tokenize, and the token gets one fee NFT door.

The calls

  1. approve(feebAdapterFactory, tokenId) on the vault, unless getApproved(tokenId) already names it. feebAdapterFactory() on the tokenizer names the factory, and the vault must be one the tokenizer admits, as admittedVaults() lists them.
  2. predictToken(creator, t) gives the token's address before it exists, and defaultMarket(rules, token, quote, sqrtPriceX96, seed) the tokenizer's own terms for its market on rules, the core.
  3. tokenize(t, s, m) with the fee NFT in s.feebs and its term in s.unlockAt: at least 7 days from now, or the largest uint64 for good. In that one call the tokenizer deploys the token, makes the fee NFT door and moves the NFT into it, mints the whole supply, the market's seed included, and opens the market when m.open. The value sent is the launcher's launchFee() with a market and nothing without one.
  4. The receipt's Tokenized names the token, and its StreamAdded with kind 3 (FEEB) names the fee NFT door. A market adds two more streams: its family, locked for s.unlockBlock, and its Rules ledger.

In code

With client.ts and abis.ts:

import { createWalletClient, http, isAddressEqual, keccak256, parseEventLogs, parseUnits, toHex, zeroAddress, type Address } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { robinhood } from "viem/chains";
import { client, FOREVER, RULES, TOKENIZER } from "./client";
import { feeNftVaultAbi, launchFeeAbi, tokenizerAbi } from "./abis";

const creator = privateKeyToAccount(process.env.CREATOR_KEY as `0x${string}`);
const wallet = createWalletClient({ account: creator, chain: robinhood, transport: http() });
const VAULT: Address = "0x…"; // the pools.trade vault that holds the fee NFT
const FEE_NFT = 123456n; // your fee NFT's id

// 1. Let the tokenizer's fee NFT door factory move the fee NFT.
const factory = await client.readContract({ address: TOKENIZER, abi: tokenizerAbi, functionName: "feebAdapterFactory" });
const approved = await client.readContract({ address: VAULT, abi: feeNftVaultAbi, functionName: "getApproved", args: [FEE_NFT] });
if (!isAddressEqual(approved, factory)) {
  const hash = await wallet.writeContract({ address: VAULT, abi: feeNftVaultAbi, functionName: "approve", args: [factory, FEE_NFT] });
  await client.waitForTransactionReceipt({ hash });
}

// 2. The terms. Hookr's leg comes out of the stream's income at each sync, so the recipients share the whole supply
//    less the market's seed.
const supply = parseUnits("1000000000", 18);
const seed = parseUnits("5000000", 18); // the market's seed
const terms = {
  name: "Example Revenue",
  symbol: "rEXAMPLE",
  supply,
  streamSeconds: 86_400, // the release period: 1 day
  tipBps: 100, // the sync caller's tip: 1%
  assets: [], // a fee NFT pays ETH only
  recipients: [creator.address],
  amounts: [supply - seed],
  termsHash: keccak256(toHex("rEXAMPLE: 1,000,000,000 supply, 1-day release period, 1% tip")),
  streamManager: creator.address, // may add streams later; zero closes the list at the mint
  openStreams: false,
};
const token = await client.readContract({ address: TOKENIZER, abi: tokenizerAbi, functionName: "predictToken", args: [creator.address, terms] });

// 3. The market at mint against ETH, on the tokenizer's own terms. Against ETH the revenue token is currency1, so the
//    start price is revenue tokens per ETH as a sqrt price: here 1 ETH buys 1,000,000 revenue tokens.
const sqrt = (n: bigint) => {
  let x = n;
  let y = (x + 1n) / 2n;
  while (y < x) [x, y] = [y, (y + n / y) / 2n];
  return x;
};
const market = await client.readContract({ address: TOKENIZER, abi: tokenizerAbi, functionName: "defaultMarket", args: [RULES, token, zeroAddress, sqrt(1_000_000n << 192n), seed] });
const launcher = await client.readContract({ address: TOKENIZER, abi: tokenizerAbi, functionName: "launcher" });
const [launchFee] = await client.readContract({ address: launcher, abi: launchFeeAbi, functionName: "launchFee" });

// 4. Lock and mint in one call. The fee NFT and the market's family are locked for good.
const streams = {
  launchParams: "0x" as const,
  families: [],
  rules: [],
  feebs: [{ vault: VAULT, tokenId: FEE_NFT }],
  positionIds: [],
  positionPermits: [],
  v3PositionIds: [],
  v3Permits: [],
  revenueTokens: [],
  sources: [],
  unlockBlock: FOREVER, // the market's family
  unlockAt: FOREVER, // the fee NFT door
  listAssets: false,
};
const { request } = await client.simulateContract({
  account: creator,
  address: TOKENIZER,
  abi: tokenizerAbi,
  functionName: "tokenize",
  args: [terms, streams, market],
  value: launchFee,
});
const receipt = await client.waitForTransactionReceipt({ hash: await wallet.writeContract(request) });
const [minted] = parseEventLogs({ abi: tokenizerAbi, eventName: "Tokenized", logs: receipt.logs });
const added = parseEventLogs({ abi: tokenizerAbi, eventName: "StreamAdded", logs: receipt.logs });
console.log("revenue token", minted.args.token, added.map((s) => ({ kind: s.args.kind, door: s.args.door, legBps: s.args.legBps })));

A fee NFT pays ETH, so assets stays empty. Without a market, send { ...market, open: false } and no value: the tokenizer reads no other field of a closed market.

After the mint

The fee NFT's ETH reaches its vault only when collectFees runs on pools.trade's fee splitter. The fee NFT door has the splitter run it before each claim, so a plain sync() brings that income in. Once unlockAt has passed, anyone can call release() on the door: it collects and claims one last time and gives the NFT back to the wallet that added it.

Fee

A fee NFT pays Hookr nothing through the Hookr hook, so its door carries Hookr's leg of 5%: at each sync the token sends that share of what the door delivered to the leg collector, and the rest is the holders' income. StreamAdded gives the figure as legBps.