-
Notifications
You must be signed in to change notification settings - Fork 49
feat: add butterswap affiliate tracking #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 11437_relay_affiliate
Are you sure you want to change the base?
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the 📝 WalkthroughWalkthroughThis pull request adds two new affiliate revenue provider integrations (ButterSwap and Relay) and refactors existing providers to use centralized SLIP44 constants instead of hardcoded values. The index module now uses Promise.allSettled for independent provider error handling and tracks failed providers in the response. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Index as getAffiliateRevenue
participant Provider1 as Provider A (e.g., Butterswap)
participant Provider2 as Provider B (e.g., Relay)
participant ErrorHandler as Error Handler
Client->>Index: Call getAffiliateRevenue(start, end)
Index->>Provider1: Call getFees(start, end)
Index->>Provider2: Call getFees(start, end)
par Parallel Provider Execution
Provider1->>Provider1: Fetch & process data
Provider1-->>Index: Return Fees[] or Error
and
Provider2->>Provider2: Fetch & process data
Provider2-->>Index: Return Fees[] or Error
end
Index->>Index: Await Promise.allSettled()
alt Provider Success
Index->>Index: Accumulate fees by service
else Provider Failure
Index->>ErrorHandler: Log error with provider name
Index->>Index: Record provider in failedProviders
end
Index->>Index: Compute totalUsd & byService totals
Index-->>Client: Return AffiliateRevenueResponse with failedProviders
sequenceDiagram
participant API as ButterSwap API
participant Module as butterswap.ts
participant RPC as RPC Endpoint
participant Cache as Token Cache
Module->>Cache: Check token list cache
alt Cache Miss
Module->>API: Fetch token list
API-->>Module: Token list
Module->>Cache: Store tokens
else Cache Hit
Cache-->>Module: Cached tokens
end
Module->>Module: Calculate start/end block from timestamps
par Parallel Block Queries
Module->>RPC: eth_call (get total balance at start block)
RPC-->>Module: Balance response
and
Module->>RPC: eth_call (get total balance at end block)
RPC-->>Module: Balance response
end
Module->>Module: Compute net fees (end - start)
Module->>Module: Convert to USD using USDT decimals
Module-->>Module: Return Fees[] array
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
c9cfb16 to
76a8dc7
Compare
76a8dc7 to
0098b66
Compare
Summary
This adds butterswap to our affiliate revenue tracker. The implementation is a bit of a best effort hack until we get a proper API from butter. It just queries the approximate block at the start and end of your time period, looks at total affiliate fees and takes the diff.
Testing
If you want to properly test this locally:
Install dependencies (from repo root)
cd /home/sean/Repos/shapeshift-unchained
yarn install
Copy and configure env
cp node/proxy/sample.env node/proxy/.env
// Edit node/proxy/.env with real API keys (BEBOP_API_KEY, ZRX_API_KEY, etc.)
Start reverse proxy (from repo root)
docker-compose up -d reverse-proxy
Start proxy API
cd node/proxy
docker-compose up
Test endpoint (in another terminal)
curl "http://api.proxy.localhost/api/v1/affiliate/revenue?startTimestamp=1764547200&endTimestamp=1767225600"Screenshots
Summary by CodeRabbit
New Features
Chores
✏️ Tip: You can customize this high-level summary in your review settings.