API Reference
Referral v2

Referral v2 API Routes

Codebase: /Desktop/referralv2/insiders-referral-v2
Service: Separate Express app — runs independently from the main Insiders backend

Referral v2 is a standalone service with its own database (Prisma/PostgreSQL). The frontend can cut over by swapping VITE_API_URL — the endpoint contract matches the legacy v1 API in the main backend.


Route prefixes

PrefixRouterAudience
/api/referralreferral.tsEnd users (authed)
/api/kolkol.tsKOL applicants + authed users
/api/schemescheme.tsPublic scheme info
/api/adminadmin.tsAdmin panel (SIWE-authed)
/api/admin/authadminAuth.tsAdmin SIWE auth
/api/internalinternal.tsService-to-service (internalAuth middleware)

User Referral · /api/referral

All routes require user JWT (authMiddleware).

MethodPathDescription
GET/chain5-level descendant tree (v2 native)
GET/balancePer-level earnings (?currency=pUSD|USDC)
GET/payoutsAuto-payout history
GET/tierLegacy tier snapshot + v2 depth-unlock
GET/codesUser's referral codes (pass-through from legacy)
POST/codes/:codeId/set-defaultSet a code as default
GET/codes/:codeId/refereesReferees under a code (enriched with level)
GET/codes/:codeId/schemeScheme assigned to a code
PATCH/codes/:codeId/schemeAssign scheme to a code
GET/platform-feeUser's effective platform fee %

GET /balance defaults to currency=pUSD (Phase D addendum 2026-05-27). Pass ?currency=USDC to read legacy USDC balances.


KOL · /api/kol

MethodPathAuthDescription
GET/leaderboardKOL leaderboard
POST/apply🔒Submit KOL application
GET/me🔒Current user's KOL status
POST/vanity-codes🔒Create vanity referral code
PATCH/landing-message🔒Update KOL landing message

Scheme · /api/scheme

MethodPathAuthDescription
GET/activeCurrently active default scheme
GET/publicAll public schemes

Admin · /api/admin

🚫

Requires admin SIWE authentication via /api/admin/auth. Do not expose to end users.

Scheme management

MethodPathDescription
POST/schemeCreate new scheme
GET/schemeGet default scheme
GET/scheme/allList all schemes
POST/scheme/assignAssign scheme to a code
POST/codes/:codeId/schemeAssign scheme directly to code

KOL management

MethodPathDescription
GET/kol/applications/queuePending KOL applications
POST/kol/applications/:id/rejectReject KOL application
POST/kol/approveApprove KOL
POST/kol/suspendSuspend KOL
POST/kol/terminateTerminate KOL

User management

MethodPathDescription
GET/users/by-tg/:tgIdLookup user by Telegram ID
GET/users/by-wallet/:addressLookup user by wallet address
GET/users/:userId/fullFull user profile
PATCH/users/:userId/rebate-tierOverride user's rebate tier
POST/users/:userId/platform-feeSet custom platform fee
GET/users/:userId/platform-feeGet user's platform fee

Platform fee analytics

MethodPathDescription
GET/platform-fee/summaryOverall fee collection summary
GET/platform-fee/dailyDaily fee breakdown
GET/platform-fee/top-sourcesTop fee-generating sources

Withdrawals

MethodPathDescription
GET/withdrawals/queuePending withdrawal queue
POST/withdrawals/:id/mark-dispatchedMark withdrawal dispatched
POST/withdrawals/batch-mark-dispatchedBatch mark dispatched
POST/withdrawals/:id/force-mark-dispatchedForce mark dispatched
POST/withdrawals/:id/cancelCancel withdrawal

Anti-abuse

MethodPathDescription
GET/anti-abuse/queueAnti-abuse review queue
POST/anti-abuse/resolveResolve anti-abuse flag

Leaderboard

MethodPathDescription
GET/leaderboard/top-referrersTop referrers leaderboard

Admin Auth · /api/admin/auth

SIWE (Sign-In with Ethereum) based admin authentication.

MethodPathDescription
GET/Get SIWE nonce
POST/Verify SIWE signature → admin session

Internal · /api/internal

🚫

Service-to-service only. Protected by internalAuth middleware (shared secret header). Not for frontend use.

MethodPathDescription
POST/shadow-tradeRecord a trade for shadow parity checking
POST/accrual (TBC)Trigger payout accrual for a trade

Cron jobs

JobScheduleDescription
dailyPayoutBatchDailyBatch-processes pending payout accruals
dailyParityReportDailyShadow parity divergence report (v1 vs v2 diff)