diff --git a/src/lib/swapper/swappers/ThorchainSwapper/endpoints.ts b/src/lib/swapper/swappers/ThorchainSwapper/endpoints.ts index b4a5e59a43c..0b28ff61e62 100644 --- a/src/lib/swapper/swappers/ThorchainSwapper/endpoints.ts +++ b/src/lib/swapper/swappers/ThorchainSwapper/endpoints.ts @@ -35,7 +35,7 @@ import { isNativeEvmAsset } from '../utils/helpers/helpers' import { THORCHAIN_OUTBOUND_FEE_RUNE_THOR_UNIT } from './constants' import type { ThorEvmTradeQuote } from './getThorTradeQuote/getTradeQuote' import { getThorTradeQuote } from './getThorTradeQuote/getTradeQuote' -import { type MidgardActionsResponse, type ThornodeStatusResponse } from './types' +import type { ThornodeStatusResponse } from './types' import { checkOutboundTxConfirmations } from './utils/checkOutputTxConfirmations' import { getLatestThorTxStatusMessage } from './utils/getLatestThorTxStatusMessage' import { TradeType } from './utils/longTailHelpers' @@ -334,16 +334,11 @@ export const thorchainApi: SwapperApi = { const thorTxHash = txHash.replace(/^0x/, '') // not using monadic axios, this is intentional for simplicity in this non-monadic context - const [{ data: thorTxData }, { data: thorActionsData }] = await Promise.all([ - axios.get( - `${getConfig().REACT_APP_THORCHAIN_NODE_URL}/lcd/thorchain/tx/status/${thorTxHash}`, - ), - axios.get( - `${getConfig().REACT_APP_MIDGARD_URL}/actions?txid=${thorTxHash}`, - ), - ]) - - if ('error' in thorTxData) { + const { data } = await axios.get( + `${getConfig().REACT_APP_THORCHAIN_NODE_URL}/lcd/thorchain/tx/status/${thorTxHash}`, + ) + + if ('error' in data) { return { buyTxHash: undefined, status: TxStatus.Unknown, @@ -351,14 +346,14 @@ export const thorchainApi: SwapperApi = { } } - const outCoinAsset: string | undefined = thorActionsData.actions[0]?.out[0]?.coins[0]?.asset - const hasOutboundTx = outCoinAsset !== 'THOR.RUNE' + const latestOutTx = data.out_txs?.[data.out_txs.length - 1] + const hasOutboundTx = latestOutTx?.chain !== 'THOR' - const buyTxHash = parseThorBuyTxHash(txHash, thorActionsData) + const buyTxHash = parseThorBuyTxHash(txHash, data) - // if we have a buyTxHash, check if it's been confirmed on-chain + // if we have an outbound transaction (non rune) and associated buyTxHash, check if it's been confirmed on-chain if (hasOutboundTx && buyTxHash) { - const outboundTxConfirmations = await checkOutboundTxConfirmations(thorTxData, buyTxHash) + const outboundTxConfirmations = await checkOutboundTxConfirmations(data, buyTxHash) if (outboundTxConfirmations !== undefined && outboundTxConfirmations > 0) { return { @@ -369,7 +364,7 @@ export const thorchainApi: SwapperApi = { } } - const { message, status } = getLatestThorTxStatusMessage(thorTxData, hasOutboundTx) + const { message, status } = getLatestThorTxStatusMessage(data, hasOutboundTx) return { buyTxHash, diff --git a/src/lib/swapper/swappers/ThorchainSwapper/utils/parseThorBuyTxHash.ts b/src/lib/swapper/swappers/ThorchainSwapper/utils/parseThorBuyTxHash.ts index cfd9993b6ef..e107f8f72c7 100644 --- a/src/lib/swapper/swappers/ThorchainSwapper/utils/parseThorBuyTxHash.ts +++ b/src/lib/swapper/swappers/ThorchainSwapper/utils/parseThorBuyTxHash.ts @@ -1,22 +1,19 @@ -import type { MidgardActionsResponse } from '../types' +import type { ThorNodeStatusResponseSuccess } from '../types' const THORCHAIN_EVM_CHAINS = ['ETH', 'AVAX', 'BSC'] as const export const parseThorBuyTxHash = ( sellTxId: string, - thorActionsData: MidgardActionsResponse, + response: ThorNodeStatusResponseSuccess, ): string | undefined => { - const inCoinAsset: string | undefined = thorActionsData.actions[0]?.in[0]?.coins[0]?.asset - const outCoinAsset: string | undefined = thorActionsData.actions[0]?.out[0]?.coins[0]?.asset - const isDoubleSwap = outCoinAsset !== 'THOR.RUNE' && inCoinAsset !== 'THOR.RUNE' + const latestOutTx = response.out_txs?.[response.out_txs.length - 1] - // swaps into rune aren't double swaps so don't have a second tx (buy tx) - if (!isDoubleSwap) return sellTxId + if (!latestOutTx) return - const isEvmCoinAsset = THORCHAIN_EVM_CHAINS.some( - thorEvmChain => outCoinAsset?.startsWith(thorEvmChain), - ) + // outbound rune transactions do not have a txid as they are processed internally, use sell txid + if (latestOutTx.chain === 'THOR') return sellTxId - const buyTxId = thorActionsData.actions[0]?.out[0]?.txID - return isEvmCoinAsset && buyTxId ? `0x${buyTxId}` : buyTxId + const isEvmCoinAsset = THORCHAIN_EVM_CHAINS.some(chain => chain === latestOutTx.chain) + + return isEvmCoinAsset ? `0x${latestOutTx.id}` : latestOutTx.id }