Skip to content

Conversation

@premiumjibles
Copy link

@premiumjibles premiumjibles commented Dec 18, 2025

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

  • Make sure unchained ain't dead

If you want to properly test this locally:

  1. Install dependencies (from repo root)
    cd /home/sean/Repos/shapeshift-unchained
    yarn install

  2. 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.)

  3. Start reverse proxy (from repo root)
    docker-compose up -d reverse-proxy

  4. Start proxy API
    cd node/proxy
    docker-compose up

  5. Test endpoint (in another terminal)

curl "http://api.proxy.localhost/api/v1/affiliate/revenue?startTimestamp=1764547200&endTimestamp=1767225600"

Screenshots

image

Summary by CodeRabbit

  • New Features

    • Integrated ButterSwap and Relay as affiliate revenue providers
    • Added support for additional blockchain networks (Bitcoin, Dogecoin, Zcash, Solana, TRON, Sui, THORChain, MayaChain, MAP)
    • Enhanced error handling with failed provider tracking in API responses
  • Chores

    • Updated API documentation to reflect expanded service availability

✏️ Tip: You can customize this high-level summary in your review settings.

@premiumjibles premiumjibles requested a review from a team as a code owner December 18, 2025 05:52
@coderabbitai
Copy link

coderabbitai bot commented Dec 18, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
New Provider Modules
node/proxy/api/src/affiliateRevenue/butterswap.ts, node/proxy/api/src/affiliateRevenue/relay.ts
Introduces two new affiliate revenue providers: ButterSwap (token list fetching with fallback, RPC-based balance queries with ABI encoding and block estimation) and Relay (paginated API integration with chain mapping and asset identifier construction). Both export getFees() methods returning Promise<Array<Fees>>.
Constant Refactoring
node/proxy/api/src/affiliateRevenue/bebop.ts, node/proxy/api/src/affiliateRevenue/mayachain.ts, node/proxy/api/src/affiliateRevenue/portals.ts, node/proxy/api/src/affiliateRevenue/thorchain.ts, node/proxy/api/src/affiliateRevenue/zrx.ts
Replaces hardcoded slip44 and chainId values with imported constants (SLIP44.ETHEREUM, SLIP44.MAYACHAIN, SLIP44.THORCHAIN, or MAYACHAIN_CHAIN_ID, THORCHAIN_CHAIN_ID) for consistent identifier generation.
Constants Definitions
node/proxy/api/src/affiliateRevenue/constants.ts
Adds SLIP44 coin type mapping object and chain ID constants for non-EVM chains (Bitcoin, Dogecoin, Zcash, Solana, Tron, Sui, Thorchain, Mayachain, MAP). Includes ButterSwap-specific constants (contract address, RPC URL, affiliate ID, USDT address).
Enhanced Provider Logic
node/proxy/api/src/affiliateRevenue/nearIntents.ts
Enhances asset parsing with NEAR_INTENTS_TO_CHAIN_ID and SLIP44_BY_NETWORK mappings; adds parseNearIntentsAsset() to derive chainId and assetId from origin asset formats; includes txHash extraction and warning logging for unparseable assets.
Error Handling & Response Refactoring
node/proxy/api/src/affiliateRevenue/index.ts
Replaces Promise.all with Promise.allSettled for independent provider error handling; adds failedProviders tracking; introduces axios-based error formatting; expands Fees type with assetId, chainId, service, timestamp, txHash fields.
API Schema Updates
node/proxy/api/src/models.ts, node/proxy/api/src/swagger.json
Adds failedProviders field (Service[]) to AffiliateRevenueResponse interface and schema; introduces new Service enum schema for type-safe service references; adds butterswap and relay to Record_Service.number_.

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
Loading
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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • butterswap.ts: RPC call logic with ABI encoding, block time estimation accuracy, token list fallback mechanism, and error recovery paths require careful verification
  • relay.ts: Pagination logic completeness, chain/asset mapping coverage for diverse networks, and asset ID construction consistency with other providers
  • index.ts: Promise.allSettled error handling semantics, failedProviders tracking correctness, and accumulation logic for per-service totals
  • Constants consolidation: Verify all SLIP44 values and new chain IDs are correct and consistently applied across all provider modules
  • Type changes: Expanded Fees type and new failedProviders field introduce breaking API changes requiring downstream impact assessment

Possibly related PRs

  • feat: affiliate revenue tracker and endpoint #1228: Introduces initial affiliateRevenue modules (bebop, mayachain, thorchain, zrx, portals, constants, index/models/swagger); this PR extends and refactors those modules by replacing hardcoded SLIP44 values and adding error handling patterns via Promise.allSettled.

Poem

🐰 Constants now reign where hardcodes once sprawled,
Two new providers answer the call,
ButterSwap balances dance through the RPC,
While Relay pages slip smooth and slick.
Errors settle, providers advance—
The affiliate ledger takes its stance! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title '11470 butter affiliate' is vague and does not clearly convey the purpose of the changes. While it references 'butter affiliate', it lacks specificity about what is being added or changed. Use a more descriptive title such as 'Add ButterSwap affiliate revenue tracking' or 'Implement ButterSwap integration to affiliate revenue module' to clearly communicate the main change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@premiumjibles premiumjibles changed the base branch from develop to 11437_relay_affiliate December 18, 2025 05:52
@premiumjibles premiumjibles marked this pull request as draft December 18, 2025 05:52
@premiumjibles premiumjibles marked this pull request as ready for review December 18, 2025 06:21
@premiumjibles premiumjibles changed the title 11470 butter affiliate feat: add butterswap affiliate tracking Dec 18, 2025
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.

2 participants