Skip to content

Commit c12e34d

Browse files
committed
Include related rawTxs for thorchain
1 parent 6d40726 commit c12e34d

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

src/partners/thorchain.ts

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
143143
}
144144

145145
// See if the transaction exists already
146-
const matchTx = standardTxs.find(
146+
const previousTxIndex = standardTxs.findIndex(
147147
tx =>
148148
tx.orderId === standardTx.orderId &&
149149
tx.timestamp === standardTx.timestamp &&
@@ -152,10 +152,21 @@ const makeThorchainPlugin = (info: ThorchainInfo): PartnerPlugin => {
152152
tx.payoutAmount === standardTx.payoutAmount &&
153153
tx.depositAmount !== standardTx.depositAmount
154154
)
155-
if (matchTx == null) {
155+
if (previousTxIndex === -1) {
156156
standardTxs.push(standardTx)
157157
} else {
158-
matchTx.depositAmount += standardTx.depositAmount
158+
const previousTx = standardTxs[previousTxIndex]
159+
const previousRawTxs: unknown[] = Array.isArray(previousTx.rawTx)
160+
? previousTx.rawTx
161+
: [previousTx.rawTx]
162+
const updatedStandardTx = processThorchainTx(
163+
[...previousRawTxs, standardTx.rawTx],
164+
info,
165+
pluginParamsClean
166+
)
167+
if (updatedStandardTx != null) {
168+
standardTxs.splice(previousTxIndex, 1, updatedStandardTx)
169+
}
159170
}
160171
if (standardTx.isoDate > latestIsoDate) {
161172
latestIsoDate = standardTx.isoDate
@@ -209,7 +220,14 @@ export function processThorchainTx(
209220
): StandardTx | null {
210221
const { pluginId } = info
211222
const { affiliateAddress, thorchainAddress } = pluginParams.apiKeys
212-
const tx = asThorchainTx(rawTx)
223+
224+
const rawTxs: unknown[] = Array.isArray(rawTx) ? rawTx : [rawTx]
225+
const txs = asArray(asThorchainTx)(rawTxs)
226+
const tx = txs[0]
227+
228+
if (tx == null) {
229+
throw new Error(`${pluginId}: Missing rawTx`)
230+
}
213231

214232
const { swap } = tx.metadata
215233
if (swap?.affiliateAddress !== affiliateAddress) {
@@ -238,13 +256,15 @@ export function processThorchainTx(
238256
`${pluginId}: Unexpected ${txIn.coins.length} txIn.coins. Expected 1`
239257
)
240258
}
241-
const coin = txIn.coins[0]
242-
const srcAsset = coin.asset
243-
const depositAmount = Number(coin.amount) / THORCHAIN_MULTIPLIER
259+
const depositAmount = txs.reduce((sum, txInternal) => {
260+
const amount =
261+
Number(txInternal.in[0].coins[0].amount) / THORCHAIN_MULTIPLIER
262+
return sum + amount
263+
}, 0)
244264

245265
const srcDestMatch = tx.out.some(o => {
246266
const match = o.coins.some(
247-
c => c.asset === srcAsset && o.affiliate !== true
267+
c => c.asset === txIn.coins[0].asset && o.affiliate !== true
248268
)
249269
return match
250270
})
@@ -258,7 +278,7 @@ export function processThorchainTx(
258278
const timestampMs = div(tx.date, '1000000', 16)
259279
const { timestamp, isoDate } = smartIsoDateFromTimestamp(Number(timestampMs))
260280

261-
const [chainAsset] = srcAsset.split('-')
281+
const [chainAsset] = txIn.coins[0].asset.split('-')
262282
const [, asset] = chainAsset.split('.')
263283

264284
// Find the first output that does not match the affiliate address

0 commit comments

Comments
 (0)