diff --git a/src/utils/three-route.ts b/src/utils/three-route.ts index 19c2615..e89fcc7 100644 --- a/src/utils/three-route.ts +++ b/src/utils/three-route.ts @@ -31,6 +31,13 @@ export interface ThreeRouteSwapResponse { chains: ThreeRouteChain[]; } +export interface ThreeRouteSirsSwapResponse { + input: number; + output: number; + tzbtcChain: ThreeRouteSwapResponse; + xtzChain: ThreeRouteSwapResponse; +} + interface ThreeRouteTokenCommon { id: number; symbol: string; @@ -90,7 +97,13 @@ export interface ThreeRouteDex { } type ThreeRouteQueryParams = object | SwapQueryParams; -type ThreeRouteQueryResponse = ThreeRouteSwapResponse | ThreeRouteDex[] | ThreeRouteToken[]; +type ThreeRouteQueryResponse = + | ThreeRouteSwapResponse + | ThreeRouteSirsSwapResponse + | ThreeRouteDex[] + | ThreeRouteToken[]; + +export const THREE_ROUTE_SIRS_SYMBOL = 'SIRS'; const threeRouteBuildQueryFn = makeBuildQueryFn( THREE_ROUTE_API_URL, @@ -98,11 +111,18 @@ const threeRouteBuildQueryFn = makeBuildQueryFn( - ({ inputTokenSymbol, outputTokenSymbol, realAmount }) => - `/swap/${inputTokenSymbol}/${outputTokenSymbol}/${realAmount}` -); +export const getThreeRouteSwap = threeRouteBuildQueryFn< + SwapQueryParams, + ThreeRouteSwapResponse | ThreeRouteSirsSwapResponse +>(({ inputTokenSymbol, outputTokenSymbol, realAmount }) => { + const isSirsSwap = inputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL || outputTokenSymbol === THREE_ROUTE_SIRS_SYMBOL; + + return `/${isSirsSwap ? 'swap-sirs' : 'swap'}/${inputTokenSymbol}/${outputTokenSymbol}/${realAmount}`; +}); export const getThreeRouteDexes = threeRouteBuildQueryFn('/dexes', []); export const getThreeRouteTokens = threeRouteBuildQueryFn('/tokens', []); + +export const getChains = (response: ThreeRouteSwapResponse | ThreeRouteSirsSwapResponse) => + 'chains' in response ? response.chains : [...response.xtzChain.chains, ...response.tzbtcChain.chains]; diff --git a/src/utils/tokens.ts b/src/utils/tokens.ts index f061532..70a6a53 100644 --- a/src/utils/tokens.ts +++ b/src/utils/tokens.ts @@ -16,7 +16,9 @@ import { getThreeRouteTokens, ThreeRouteStandardEnum, ThreeRouteFa12Token, - ThreeRouteFa2Token + ThreeRouteFa2Token, + getChains, + THREE_ROUTE_SIRS_SYMBOL } from './three-route'; import { BcdTokenData, mapTzktTokenDataToBcdTokenData, tokensMetadataProvider } from './tzkt'; @@ -184,6 +186,11 @@ blockFinder(EMPTY_BLOCK, async block => return false; } + if (token.symbol === THREE_ROUTE_SIRS_SYMBOL) { + // Swap output for SIRS should be updated each block because of baking subsidy + return true; + } + try { await probeSwapsProvider.subscribe(token.symbol); const { data: probeSwaps, error: swapError } = await Promise.race([ @@ -196,8 +203,10 @@ blockFinder(EMPTY_BLOCK, async block => } const { directSwap, invertedSwap } = probeSwaps; - const dexesAddresses = directSwap.chains - .concat(invertedSwap.chains) + const directSwapChains = getChains(directSwap); + const invertedSwapChains = getChains(invertedSwap); + const dexesAddresses = directSwapChains + .concat(invertedSwapChains) .map(chain => chain.hops.map(hop => dexes.find(dex => dex.id === hop.dex)?.contract).filter(isDefined)) .flat();