feat(swap-service): add affiliate address tracking alongside referral codes#19
Draft
feat(swap-service): add affiliate address tracking alongside referral codes#19
Conversation
… codes - Add affiliateAddress field to Swap model (nullable, indexed) - Update CreateSwapDto to accept affiliateAddress - Calculate and store sellAmountUsd at swap creation time - Add calculateAffiliateFees method querying by affiliateAddress - Add GET /swaps/affiliate-fees/:affiliateAddress endpoint - Existing referralCode system unchanged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds B2B affiliate address tracking to swap-service, running alongside the existing referralCode system. Enables tracking swap volumes and fees by Arbitrum address for B2B integrators.
Epic: ss-aff — B2B Affiliate Tracking System (bead 4)
Changes
Prisma Schema (
apps/swap-service/prisma/schema.prisma)affiliateAddress String?field to Swap model@@index([affiliateAddress])for query performanceMigration
20260223000000_add_affiliate_address—ALTER TABLE "Swap" ADD COLUMN "affiliateAddress" TEXT+ indexSwap Service (
apps/swap-service/src/swaps/swaps.service.ts)createSwap()now accepts and storesaffiliateAddresssellAmountUsdcalculated and snapshot at creation time usinggetAssetPriceUsd()calculateAffiliateFees()method — queries byaffiliateAddress(parallel tocalculateReferralFeesbyreferralCode)sellAmountUsdsnapshot, falls back to live pricing for older swapsSwap Controller (
apps/swap-service/src/swaps/swaps.controller.ts)GET /swaps/affiliate-fees/:affiliateAddressendpoint/swaps/referral-fees/:referralCodepatternShared Types (
packages/shared-types/src/index.ts)affiliateAddress?: stringtoCreateSwapDtoDesign Decisions
referralCode(user-to-user) andaffiliateAddress(B2B) — both can be set on the same swapsellAmountUsdcaptured at creation time to ensure consistent fee calculations{ affiliateAddress, swapCount, totalSwapVolumeUsd, totalFeesCollectedUsd, referrerCommissionUsd }Testing
Related PRs
swap-trackingbranch (separate PR with public-api endpoints, widget fix, web app attribution, dashboard)Out of Scope