Commit 45a138de authored by cartcrom's avatar cartcrom Committed by GitHub

fix: detect refunds on exact_out native swaps (#7227)

* fix: detect refunds on exact_out native swaps

* fix: correct comment
parent 26d2ab53
......@@ -159,10 +159,16 @@ function parseSwap(changes: TransactionChanges) {
}
// Some swaps may have more than 2 transfers, e.g. swaps with fees on tranfer
if (changes.TokenTransfer.length >= 2) {
const sent = changes.TokenTransfer.find((t) => t?.__typename === 'TokenTransfer' && t.direction === 'OUT')
const received = changes.TokenTransfer.find((t) => t?.__typename === 'TokenTransfer' && t.direction === 'IN')
const sent = changes.TokenTransfer.find((t) => t.direction === 'OUT')
// Any leftover native token is refunded on exact_out swaps where the input token is native
const refund = changes.TokenTransfer.find(
(t) => t.direction === 'IN' && t.asset.id === sent?.asset.id && t.asset.standard === 'NATIVE'
)
const received = changes.TokenTransfer.find((t) => t.direction === 'IN' && t !== refund)
if (sent && received) {
const inputAmount = formatNumberOrString(sent.quantity, NumberType.TokenNonTx)
const adjustedInput = parseFloat(sent.quantity) - parseFloat(refund?.quantity ?? '0')
const inputAmount = formatNumberOrString(adjustedInput, NumberType.TokenNonTx)
const outputAmount = formatNumberOrString(received.quantity, NumberType.TokenNonTx)
return {
title: getSwapTitle(sent, received),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment