Skip to content

Comments

feat(swap-service): add affiliate address tracking alongside referral codes#19

Draft
NeOMakinG wants to merge 1 commit intodevelopfrom
feat/swap-service-affiliate-address-tracking
Draft

feat(swap-service): add affiliate address tracking alongside referral codes#19
NeOMakinG wants to merge 1 commit intodevelopfrom
feat/swap-service-affiliate-address-tracking

Conversation

@NeOMakinG
Copy link
Collaborator

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)

  • Added affiliateAddress String? field to Swap model
  • Added @@index([affiliateAddress]) for query performance

Migration

  • 20260223000000_add_affiliate_addressALTER TABLE "Swap" ADD COLUMN "affiliateAddress" TEXT + index

Swap Service (apps/swap-service/src/swaps/swaps.service.ts)

  • createSwap() now accepts and stores affiliateAddress
  • sellAmountUsd calculated and snapshot at creation time using getAssetPriceUsd()
  • New calculateAffiliateFees() method — queries by affiliateAddress (parallel to calculateReferralFees by referralCode)
  • Prefers stored sellAmountUsd snapshot, falls back to live pricing for older swaps

Swap Controller (apps/swap-service/src/swaps/swaps.controller.ts)

  • New GET /swaps/affiliate-fees/:affiliateAddress endpoint
  • Mirrors existing /swaps/referral-fees/:referralCode pattern

Shared Types (packages/shared-types/src/index.ts)

  • Added affiliateAddress?: string to CreateSwapDto

Design Decisions

  • Two systems coexist: referralCode (user-to-user) and affiliateAddress (B2B) — both can be set on the same swap
  • Snapshot pricing: sellAmountUsd captured at creation time to ensure consistent fee calculations
  • Same response shape: { affiliateAddress, swapCount, totalSwapVolumeUsd, totalFeesCollectedUsd, referrerCommissionUsd }
  • No changes to existing system: referralCode flow completely untouched

Testing

  • Existing referral system unaffected
  • New affiliate-fees endpoint returns expected data structure
  • Migration applies cleanly

Related PRs

  • Web: shapeshift/web — swap-tracking branch (separate PR with public-api endpoints, widget fix, web app attribution, dashboard)

Out of Scope

  • Fee distribution/payouts
  • Custom fee rates per affiliate
  • Multi-chain affiliate addresses

… 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant