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: parse buy txid from midgard actions #6813

Merged
merged 4 commits into from
May 6, 2024
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ export const parseThorBuyTxHash = (
sellTxId: string,
thorActionsData: MidgardActionsResponse,
): 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 outTxs = thorActionsData.actions[0]?.out

// swaps into rune aren't double swaps so don't have a second tx (buy tx)
if (!isDoubleSwap) return sellTxId
if (!outTxs?.length) return

const latestOutTx = outTxs[outTxs.length - 1]
const latestTxId = latestOutTx.txID

// outbound rune transactions do not have a txid as they are processed internally
if (!latestTxId) return sellTxId
kaladinlight marked this conversation as resolved.
Show resolved Hide resolved

const isEvmCoinAsset = THORCHAIN_EVM_CHAINS.some(
thorEvmChain => outCoinAsset?.startsWith(thorEvmChain),
thorEvmChain => latestOutTx.coins[0].asset?.startsWith(thorEvmChain),
)

const buyTxId = thorActionsData.actions[0]?.out[0]?.txID
return isEvmCoinAsset && buyTxId ? `0x${buyTxId}` : buyTxId
return isEvmCoinAsset ? `0x${latestTxId}` : latestTxId
}
Loading