Skip to content
ubi.fun
Esc
navigateopen⌘Jpreview
On this page

Swaps and the referrer share

Quote and execute swaps against ubi.fun pools, and pass your address to earn 5% of the fee on volume you route.

Every ubi.fun coin trades in a Uniswap v4 pool whose cash side is USDC and whose hook is our PositionManager. You can route into these pools with any v4-capable router, but the supported path is our PoolSwap contract, because it forwards a referrer to the hook.

The referrer share, first

5% of every swap fee goes to whoever routed the swap. This is fixed in the fee split, not a partnership program: pass your address, and the hook assigns your share to the ReferralEscrow as it collects the fee. Claim whenever you like; TokensAssigned events tell you what you have accrued. If no referrer is passed, the share cascades down the split instead, so you are leaving money on the table by omitting it.

You can read the live distribution for any pool from the PositionManager:

function getPoolFeeDistribution(bytes32 poolId)
  view returns ((uint24 swapFee, uint24 referrer, uint24 protocol, bool active));

Pool key

Build the v4 pool key from the PoolCreated event: the two currencies are the memecoin and USDC, ordered per _currencyFlipped (false means USDC is currency0), with the PositionManager as the hooks address. The hook fixes fee to 0 (fees are taken by the hook, not the pool) and tickSpacing to 60; rather than assembling the key yourself, read it back exactly with PositionManager.poolKey(memecoin).

Quoting

Use the V4Quoter for exact-in and exact-out quotes off-chain. For the quote to match execution, the quoter call must carry the same referrer you will swap with, abi-encoded as the hook data:

import { encodeAbiParameters } from 'viem'

// '0x' means no referrer; otherwise a single abi-encoded address.
const hookData = referrer
  ? encodeAbiParameters([{ type: 'address' }], [referrer])
  : '0x'

Executing

PoolSwap’s entry point:

function swap(
  PoolKey calldata key,          // (currency0, currency1, fee, tickSpacing, hooks)
  SwapParams calldata params,    // (zeroForOne, amountSpecified, sqrtPriceLimitX96)
  address referrer               // your address; the router abi-encodes it into hookData
) payable returns (int256);
  • zeroForOne follows v4 semantics against the pool key ordering, so derive it from _currencyFlipped and the direction the user wants.
  • amountSpecified is negative for exact-in, positive for exact-out.
  • sqrtPriceLimitX96 is your slippage bound. Approve the input token to PoolSwap first: USDC for buys, the coin for sells.
  • Amounts are USDC 6 decimals on the cash side and 18 decimals on the coin side.

During a coin’s fair launch window, swaps fill at the fixed fair launch price first; the PoolSwap event’s three amount-pair legs show how a fill was sourced. Whitelisted launches route through WhitelistPoolSwap with a Merkle proof instead.

Fees on your volume, end to end

For a swap you route with your referrer address set: 5% of the fee accrues to you in ReferralEscrow, 24% funds the daily holder pool, 15% goes to the team, and 56% goes to the creator’s side of the split. Nothing about the user’s execution price changes based on whether a referrer is set. Full breakdown: Where every fee goes.

Was this page helpful?