Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use latest out tx for all checks #6853

Merged
merged 1 commit into from
May 8, 2024
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
4 changes: 2 additions & 2 deletions src/lib/swapper/swappers/ThorchainSwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,11 @@ export const thorchainApi: SwapperApi = {
const latestOutTx = data.out_txs?.[data.out_txs.length - 1]
const hasOutboundTx = latestOutTx?.chain !== 'THOR'

const buyTxHash = parseThorBuyTxHash(txHash, data)
const buyTxHash = parseThorBuyTxHash(txHash, latestOutTx)

// 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(data, buyTxHash)
const outboundTxConfirmations = await checkOutboundTxConfirmations(buyTxHash, latestOutTx)

if (outboundTxConfirmations !== undefined && outboundTxConfirmations > 0) {
return {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/swapper/swappers/ThorchainSwapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ type ThorNodeCoinSchema = {
decimals?: number
}

type ThorNodeTxSchema = {
export type ThorNodeTxSchema = {
id: string
chain: ThorchainChain
from_address: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ import axios from 'axios'
import { getConfig } from 'config'
import { assertUnreachable } from 'lib/utils'

import type { ThorNodeStatusResponseSuccess } from '../types'
import type { ThorNodeTxSchema } from '../types'
import { ThorchainChain } from '../types'

export const checkOutboundTxConfirmations = async (
thorTxData: ThorNodeStatusResponseSuccess,
buyTxHash: string,
latestOutTx: ThorNodeTxSchema | undefined,
) => {
const outCoinChain: ThorchainChain | undefined = thorTxData.out_txs?.[0]?.chain

if (!outCoinChain) return
if (!latestOutTx) return

const apiUrl = (() => {
switch (outCoinChain) {
switch (latestOutTx.chain) {
case ThorchainChain.BTC: {
return getConfig().REACT_APP_UNCHAINED_BITCOIN_HTTP_URL
}
Expand Down Expand Up @@ -44,9 +42,9 @@ export const checkOutboundTxConfirmations = async (
return getConfig().REACT_APP_UNCHAINED_COSMOS_HTTP_URL
}
case ThorchainChain.BSC:
throw Error(`${outCoinChain} not supported`)
throw Error(`${latestOutTx.chain} not supported`)
default:
assertUnreachable(outCoinChain)
assertUnreachable(latestOutTx.chain)
}
})()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { ThorNodeStatusResponseSuccess } from '../types'
import type { ThorNodeTxSchema } from '../types'

const THORCHAIN_EVM_CHAINS = ['ETH', 'AVAX', 'BSC'] as const

export const parseThorBuyTxHash = (
sellTxId: string,
response: ThorNodeStatusResponseSuccess,
latestOutTx: ThorNodeTxSchema | undefined,
): string | undefined => {
const latestOutTx = response.out_txs?.[response.out_txs.length - 1]

if (!latestOutTx) return

// outbound rune transactions do not have a txid as they are processed internally, use sell txid
Expand Down
Loading