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
24 changes: 5 additions & 19 deletions apps/swap-service/src/swaps/swaps.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,7 @@ import { getNextCursor, swapCursorArgs } from '../utils/pagination'
import { SwapVerificationService } from '../verification/swap-verification.service'

import { buildChainAdapterAsserts, getSwapperConfig } from './swapper-config'
import type {
AffiliateVerificationDetails,
AggregateFeesParams,
FeeTotals,
PaginatedSwaps,
Swap,
SwapReconciliation,
} from './types'
import type { AffiliateVerificationDetails, AggregateFeesParams, FeeTotals, PaginatedSwaps, Swap } from './types'
import { PaginationQueryDto } from './types'
import {
buildStatusNotification,
Expand Down Expand Up @@ -177,7 +170,6 @@ export class SwapsService {
buyTxHash: data.buyTxHash,
txLink: data.txLink,
statusMessage: data.statusMessage,
actualBuyAmountCryptoBaseUnit: data.actualBuyAmountCryptoBaseUnit,
},
}),
)
Expand Down Expand Up @@ -375,15 +367,13 @@ export class SwapsService {

const statusMessage = Array.isArray(message) ? message[0] : message

const { isAffiliateVerified, affiliateVerificationDetails } = await this.reconcileSwap(swap)
await this.reconcileSwap(swap)

return {
status: status === TxStatus.Confirmed ? 'SUCCESS' : status === TxStatus.Failed ? 'FAILED' : 'PENDING',
sellTxHash: swap.sellTxHash,
buyTxHash,
statusMessage: typeof statusMessage === 'string' ? statusMessage : '',
isAffiliateVerified,
affiliateVerificationDetails,
}
} catch (error) {
logger.error(`Failed to poll swap status for ${swapId}:`, error)
Expand All @@ -394,7 +384,7 @@ export class SwapsService {
}
}

private async reconcileSwap(swap: Swap): Promise<SwapReconciliation> {
private async reconcileSwap(swap: Swap): Promise<void> {
try {
const verificationResult = await this.swapVerificationService.verifySwap(swap)

Expand Down Expand Up @@ -424,16 +414,12 @@ export class SwapsService {
data: {
isAffiliateVerified,
affiliateVerificationDetails: isAffiliateVerified ? affiliateVerificationDetails : Prisma.DbNull,
actualBuyAmountCryptoBaseUnit: verificationResult.actualBuyAmountCryptoBaseUnit,
actualAffiliateFeeAmountCryptoBaseUnit: verificationResult.actualAffiliateFeeAmountCryptoBaseUnit,
},
})

return {
isAffiliateVerified,
affiliateVerificationDetails: isAffiliateVerified ? affiliateVerificationDetails : undefined,
}
} catch (error) {
logger.warn(`Failed to verify affiliate for swap ${swap.swapId}:`, error)
return {}
}
}
}
5 changes: 0 additions & 5 deletions apps/swap-service/src/swaps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ export type AffiliateVerificationDetails = {
hasAffiliate: boolean
}

export type SwapReconciliation = {
isAffiliateVerified?: boolean
affiliateVerificationDetails?: AffiliateVerificationDetails
}

export type UsdPrices = {
sellAmountUsd: string | null
buyAssetUsd: string | null
Expand Down
40 changes: 22 additions & 18 deletions apps/swap-service/src/utils/affiliateFeeAsset.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import { SwapperName } from '@shapeshiftoss/swapper'
import type { Asset } from '@shapeshiftoss/types'

type FeeAssetStrategy = 'buy_asset' | 'sell_asset' | 'fixed_base'
type FeeAssetStrategy = 'buy_asset' | 'sell_asset' | 'fixed_base' | 'none'

const SWAPPER_FEE_STRATEGY: Record<string, FeeAssetStrategy> = {
Across: 'buy_asset',
AVNU: 'sell_asset',
Bebop: 'buy_asset',
ButterSwap: 'buy_asset',
Cetus: 'buy_asset',
Chainflip: 'buy_asset',
'CoW Swap': 'sell_asset',
MAYAChain: 'sell_asset',
'NEAR Intents': 'sell_asset',
Portals: 'sell_asset',
Relay: 'fixed_base',
'STON.fi': 'sell_asset',
'Sun.io': 'buy_asset',
THORChain: 'sell_asset',
'0x': 'buy_asset',
const SWAPPER_FEE_STRATEGY: Record<SwapperName, FeeAssetStrategy> = {
[SwapperName.Across]: 'buy_asset',
[SwapperName.ArbitrumBridge]: 'none',
[SwapperName.Avnu]: 'sell_asset',
[SwapperName.Bebop]: 'buy_asset',
[SwapperName.ButterSwap]: 'buy_asset',
[SwapperName.Cetus]: 'buy_asset',
[SwapperName.Chainflip]: 'buy_asset',
[SwapperName.CowSwap]: 'sell_asset',
[SwapperName.Debridge]: 'sell_asset',
[SwapperName.Mayachain]: 'sell_asset',
[SwapperName.NearIntents]: 'sell_asset',
[SwapperName.Portals]: 'sell_asset',
[SwapperName.Relay]: 'fixed_base',
[SwapperName.Stonfi]: 'sell_asset',
[SwapperName.Sunio]: 'buy_asset',
[SwapperName.Thorchain]: 'sell_asset',
[SwapperName.Zrx]: 'buy_asset',
[SwapperName.Test]: 'none',
}

export function resolveAffiliateFeeAssetId(swapperName: string, sellAsset: Asset, buyAsset: Asset): string | null {
export function resolveAffiliateFeeAssetId(swapperName: SwapperName, sellAsset: Asset, buyAsset: Asset): string | null {
const strategy = SWAPPER_FEE_STRATEGY[swapperName]
if (!strategy) return null

Expand Down
Loading