Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apps/swap-service/src/swaps/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { calculateFeeForSwap } from '../utils'
const makeSwap = (overrides: Partial<Swap> = {}): Swap =>
({
swapId: 'test-swap',
isAffiliateVerified: true,
sellAsset: { assetId: 'eip155:1/slip44:60', precision: 18 },
buyAsset: { assetId: 'eip155:1/erc20:0xusdc', precision: 6 },
sellAssetUsd: '2000',
Expand All @@ -30,6 +31,14 @@ const makeSwap = (overrides: Partial<Swap> = {}): 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()
})
Comment thread
kaladinlight marked this conversation as resolved.

it('uses the sell-side USD as volume for a 0-bps swap when the sell price is present', () => {
const result = calculateFeeForSwap(makeSwap())

Expand Down
6 changes: 5 additions & 1 deletion apps/swap-service/src/swaps/swaps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}),
)
}
Expand Down
2 changes: 2 additions & 0 deletions apps/swap-service/src/swaps/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
Loading