diff --git a/apps/swap-service/src/swaps/__tests__/utils.test.ts b/apps/swap-service/src/swaps/__tests__/utils.test.ts index 1fa17a6..9d0d7c9 100644 --- a/apps/swap-service/src/swaps/__tests__/utils.test.ts +++ b/apps/swap-service/src/swaps/__tests__/utils.test.ts @@ -10,6 +10,7 @@ import { calculateFeeForSwap } from '../utils' const makeSwap = (overrides: Partial = {}): Swap => ({ swapId: 'test-swap', + isAffiliateVerified: true, sellAsset: { assetId: 'eip155:1/slip44:60', precision: 18 }, buyAsset: { assetId: 'eip155:1/erc20:0xusdc', precision: 6 }, sellAssetUsd: '2000', @@ -30,6 +31,14 @@ const makeSwap = (overrides: Partial = {}): Swap => describe('calculateFeeForSwap volume reconstruction', () => { afterEach(() => jest.restoreAllMocks()) + it('returns null without warning for a swap that is not affiliate-verified', () => { + const warn = jest.spyOn(Logger.prototype, 'warn').mockImplementation(() => undefined) + + // e.g. a failed / unverified swap surfaced by the partner swaps listing + expect(calculateFeeForSwap(makeSwap({ isAffiliateVerified: false, affiliateVerificationDetails: null }))).toBeNull() + expect(warn).not.toHaveBeenCalled() + }) + it('uses the sell-side USD as volume for a 0-bps swap when the sell price is present', () => { const result = calculateFeeForSwap(makeSwap()) diff --git a/apps/swap-service/src/swaps/swaps.service.ts b/apps/swap-service/src/swaps/swaps.service.ts index 79358fc..24c3ac4 100644 --- a/apps/swap-service/src/swaps/swaps.service.ts +++ b/apps/swap-service/src/swaps/swaps.service.ts @@ -399,7 +399,11 @@ export class SwapsService { return toSwap( await this.prisma.swap.update({ where: { swapId: swap.swapId }, - data: { verificationStatus: 'FAILED', isAffiliateVerified: false }, + data: { + verificationStatus: 'FAILED', + isAffiliateVerified: false, + affiliateVerificationDetails: Prisma.DbNull, + }, }), ) } diff --git a/apps/swap-service/src/swaps/utils.ts b/apps/swap-service/src/swaps/utils.ts index f23361b..77be2d0 100644 --- a/apps/swap-service/src/swaps/utils.ts +++ b/apps/swap-service/src/swaps/utils.ts @@ -168,6 +168,8 @@ export const calculateFeeForSwap = ( actualFeeUsd: number | null impliedFeeUsd: number | null } | null => { + if (!swap.isAffiliateVerified) return null + const verifiedBps = swap.affiliateVerificationDetails?.affiliateBps if (verifiedBps === undefined) { logger.warn(`Verified swap ${swap.swapId} missing affiliate bps in verification details, skipping`)