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
14 changes: 8 additions & 6 deletions apps/swap-service/src/utils/affiliateFeeAsset.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import type { AssetId } from '@shapeshiftoss/caip'
import { thorchainAssetId } from '@shapeshiftoss/caip'
import { SwapperName } from '@shapeshiftoss/swapper'
import type { Asset } from '@shapeshiftoss/types'

type FeeAssetStrategy = 'buy_asset' | 'sell_asset' | 'none'
type FeeAssetStrategy = 'buy_asset' | 'sell_asset' | AssetId | null

const SWAPPER_FEE_STRATEGY: Record<SwapperName, FeeAssetStrategy> = {
[SwapperName.Across]: 'buy_asset',
[SwapperName.ArbitrumBridge]: 'none',
[SwapperName.ArbitrumBridge]: null,
[SwapperName.Avnu]: 'sell_asset',
[SwapperName.Bebop]: 'buy_asset',
[SwapperName.ButterSwap]: 'buy_asset',
Expand All @@ -16,12 +18,12 @@ const SWAPPER_FEE_STRATEGY: Record<SwapperName, FeeAssetStrategy> = {
[SwapperName.Mayachain]: 'sell_asset',
[SwapperName.NearIntents]: 'sell_asset',
[SwapperName.Portals]: 'sell_asset',
[SwapperName.Relay]: 'none',
[SwapperName.Relay]: null,
[SwapperName.Stonfi]: 'sell_asset',
[SwapperName.Sunio]: 'buy_asset',
[SwapperName.Thorchain]: 'sell_asset',
[SwapperName.Thorchain]: thorchainAssetId,
[SwapperName.Zrx]: 'buy_asset',
[SwapperName.Test]: 'none',
[SwapperName.Test]: null,
}

export function resolveAffiliateFeeAssetId(swapperName: SwapperName, sellAsset: Asset, buyAsset: Asset): string | null {
Expand All @@ -34,6 +36,6 @@ export function resolveAffiliateFeeAssetId(swapperName: SwapperName, sellAsset:
case 'sell_asset':
return sellAsset.assetId
default:
return null
return strategy
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"actions": [
{
"date": "1778278960278752371",
"height": "26094014",
"in": [
{
"address": "0xa44c286ba83bb771cd0107b2c1df678435bd1535",
"coins": [
{
"amount": "300000",
"asset": "ETH.ETH"
}
],
"txID": "4A4CE957A047378C3F3AC57CA3CC3AB03E61814A7B415F493704D84A9E42D0EB"
}
],
"metadata": {
"swap": {
"affiliateAddress": "ss",
"affiliateFee": "60",
"inPriceUSD": "2316.00252129584",
"isStreamingSwap": true,
"liquidityFee": "2327555",
"memo": "=:ETH.USDC:0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535:660984846:ss:60",
"networkFees": [
{
"amount": "25005800",
"asset": "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"
}
],
"outPriceUSD": "0.9998584435447455",
"swapSlip": "20",
"swapTarget": "660984846",
"txType": "swap"
}
},
"out": [
{
"address": "thor1dl7un46w7l7f3ewrnrm6nq58nerjtp0dradjtd",
"affiliate": true,
"coins": [
{
"amount": "6944500",
"asset": "THOR.RUNE"
}
],
"height": "26094015",
"txID": ""
},
{
"address": "0xa44c286ba83bb771cd0107b2c1df678435bd1535",
"coins": [
{
"amount": "664373800",
"asset": "ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"
}
],
"height": "26094019",
"txID": "E6CECF7727DA23DDC52605D728775E7E022935987548FF5E9E922FDFBC55F9FC"
}
],
"pools": [
"ETH.ETH",
"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"
],
"status": "success",
"type": "swap"
}
],
"count": "1",
"meta": {
"nextPageToken": "260940149000000079",
"prevPageToken": "260940149000000079"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { SwapperName } from '@shapeshiftoss/swapper'

import type { Swap } from '../../../../swaps/types'

export default {
swapId: 'ca88e6ef-ca09-4848-98a6-1bd18e36fc81',
sellAsset: {
icon: 'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
name: 'Ethereum',
color: '#5C6BC0',
symbol: 'ETH',
assetId: 'eip155:1/slip44:60',
chainId: 'eip155:1',
explorer: 'https://etherscan.io',
precision: 18,
networkIcon:
'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
networkName: 'Ethereum',
networkColor: '#5C6BC0',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: 'eip155:1/slip44:60',
explorerAddressLink: 'https://etherscan.io/address/',
},
buyAsset: {
icon: 'https://assets.coingecko.com/coins/images/6319/large/USDC.png?1769615602',
name: 'USDC',
color: '#2373CB',
symbol: 'USDC',
assetId: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
chainId: 'eip155:1',
explorer: 'https://etherscan.io',
precision: 6,
networkIcon:
'https://rawcdn.githack.com/trustwallet/assets/32e51d582a890b3dd3135fe3ee7c20c2fd699a6d/blockchains/ethereum/info/logo.png',
networkName: 'Ethereum',
networkColor: '#5C6BC0',
explorerTxLink: 'https://etherscan.io/tx/',
relatedAssetKey: 'eip155:1/erc20:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
explorerAddressLink: 'https://etherscan.io/address/',
},
sellAmountCryptoBaseUnit: '3000000000000000',
expectedBuyAmountCryptoBaseUnit: '6643063.78',
actualBuyAmountCryptoBaseUnit: null,
status: 'SUCCESS',
source: 'THORChain',
swapperName: SwapperName.Thorchain,
sellAccountId: '3c70e97c6f86a5b5cfdf82dfd3380ac4ed3d8b89dabf86f631bdf739372926be',
buyAccountId: null,
receiveAddress: '0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535',
sellTxHash: '0x4a4ce957a047378c3f3ac57ca3cc3ab03e61814a7b415f493704d84a9e42d0eb',
buyTxHash: '0xE6CECF7727DA23DDC52605D728775E7E022935987548FF5E9E922FDFBC55F9FC',
txLink: null,
statusMessage: '',
isStreaming: false,
createdAt: new Date('2026-05-08T22:21:53.060Z'),
updatedAt: new Date('2026-05-08T22:23:25.138Z'),
metadata: {
quoteId: 'ca88e6ef-ca09-4848-98a6-1bd18e36fc81',
stepIndex: 0,
acrossTransactionMetadata: undefined,
chainflipSwapId: undefined,
debridgeTransactionMetadata: undefined,
relayerExplorerTxLink: undefined,
relayerTxHash: undefined,
relayTransactionMetadata: undefined,
streamingSwapMetadata: undefined,
},
userId: 'api',
referralCode: null,
sellAssetUsd: '2315.29',
buyAssetUsd: '0.999934',
affiliateAssetUsd: '2315.29',
isAffiliateVerified: null,
affiliateVerificationDetails: null,
affiliateAddress: '0xA44C286BA83Bb771cd0107B2c1Df678435Bd1535',
affiliateBps: 60,
origin: 'api',
affiliateFeeAssetId: 'eip155:1/slip44:60',
actualAffiliateFeeAmountCryptoBaseUnit: null,
shapeshiftBps: 10,
verificationStatus: 'PENDING',
} satisfies Swap
14 changes: 14 additions & 0 deletions apps/swap-service/src/verification/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Logger } from '@nestjs/common'
import type BigNumberJs from 'bignumber.js'

Logger.overrideLogger(false)

Expand All @@ -8,6 +9,7 @@ jest.mock('../../env', () => ({
VITE_CHAINFLIP_API_KEY: 'x',
VITE_NEAR_INTENTS_API_KEY: 'x',
VITE_THORCHAIN_NODE_URL: 'https://thornode.test',
VITE_THORCHAIN_MIDGARD_URL: 'https://midgard.test',
VITE_MAYACHAIN_NODE_URL: 'https://mayanode.test',
VITE_ACROSS_API_URL: 'https://across.test',
VITE_BEBOP_API_URL: 'https://bebop.test',
Expand All @@ -23,6 +25,18 @@ jest.mock('../../utils/pricing', () => ({
getAssetPriceUsd: jest.fn(),
}))

// chain-adapters transitively imports p-queue (ESM-only) which Jest's CJS loader can't parse.
// We only need bnOrZero in tests, so stub it via bignumber.js directly.
jest.mock('@shapeshiftoss/chain-adapters', () => {
const BigNumber = jest.requireActual<typeof BigNumberJs>('bignumber.js')
return {
bnOrZero: (x: unknown) => {
const bn = new BigNumber(x as BigNumberJs.Value)
return bn.isFinite() ? bn : new BigNumber(0)
},
}
})

jest.mock('@shapeshiftoss/swapper', () => ({
SwapperName: {
Thorchain: 'THORChain',
Expand Down
Loading
Loading