> For the complete documentation index, see [llms.txt](https://docs.trover.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.trover.tech/engineering/verify-2026-09-13-fees-round-2-referrals.md).

# Verify 2026-09-13: fee ledger, NFT marketplace fee, referral links, referral league (round 2)

Migration status: **one new migration**, `20260913120000_platform_fees_and_referrals` (additive: two nullable columns on `trading_profiles`, tables `platform_fees`, `referral_codes`, `referral_epochs`, `referral_rewards`, three enums; no rewrite). Plan: `PLAN-2026-09-13-fees-and-referrals.md`.

## What changed

* `platform_fees`: every fee from every source in one ledger (rate paid, referral discount, referrer share, status, tx). Token trades through the executor write it in the same transaction as `trade_fees`.
* NFT marketplace fee: after a buy, sweep or mint confirms, the worker sums the native value the purchase transactions spent, applies `NFT_PLATFORM_FEE_BPS` (default 100, referral discount applied), and sends it from the delegated wallet to `PLATFORM_FEE_WALLET` as a second transfer; waived (recorded, not sent) for non-delegated wallets or zero native spend; retried when the wallet cannot cover the fee.
* Referrals: `GET /v1/referrals/me` (code, link, stats, payouts), `POST /v1/referrals/code`, `POST /v1/referrals/attach` (fresh profiles only), `GET /v1/referrals/leaderboard` (today live + last settled day). `trover.tech/r/<code>` sets a 30-day cookie; the web app attaches it once after login. Referred profiles pay `PLATFORM_FEE_BPS` less `REFERRAL_DISCOUNT_PCT` (20%) for `REFERRAL_DISCOUNT_DAYS` (90); referrers earn `REFERRAL_SHARE_BPS` (25%) of every fee their referrals pay, forever.
* Referral league: `settle_referral_epoch` at 00:10 UTC closes the previous day, ranks referrers by share, pays each in ETH from the fee wallet (`REFERRAL_MIN_PAYOUT_USD`, default $1), records tx hashes. Off until `REFERRAL_LEAGUE_ENABLED=true`.
* Web: account → Referrals tab (link, copy, custom code, stats, payouts); public `/referrals` league page (today's standings, last settled day); header link. Privy modal logo now `/privy-logo-2x1.png` (`https://trover.tech/privy-logo-2x1.png`, plus `-light` and `-transparent` variants).

## Checks run

`tsc` api, worker, web; `prisma validate` + generate.

## Deploy

```
ssh trevor-server
cd ~/trover && git pull --ff-only origin main
nohup bash -c 'set -x; docker compose -f docker-compose.yml -f docker-compose.production.yml build migrate api worker && docker compose -f docker-compose.yml -f docker-compose.production.yml run --rm migrate && docker compose -f docker-compose.yml -f docker-compose.production.yml up -d --no-deps api worker; echo DEPLOY_EXIT=$?' > deploy-$(date +%Y%m%d-%H%M).log 2>&1 < /dev/null &
```

Then in the server `.env` when ready: `REFERRAL_LEAGUE_ENABLED=true` (fee wallet must hold ETH for payouts), and after the mainnet executor deploy `AUTO_INVEST_FEE_EXECUTOR_ADDRESS` + `PLATFORM_FEE_BPS=100`.

## Checks for you

1. Account → Referrals: your link; open it in a private window, sign up, trade once: the new profile's `trade_fees.feeBps` is 80, the ledger row carries your id as referrer and 25% as your share.
2. `/referrals` shows the running day; after 00:10 UTC with the league enabled, the settled day and tx hashes.
3. Buy an NFT with a delegated wallet: a second transfer of 1% of the spend reaches the fee wallet within a minute (`platform_fees` row confirmed).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.trover.tech/engineering/verify-2026-09-13-fees-round-2-referrals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
