Skip to content
Merged
24 changes: 17 additions & 7 deletions packages/chain-adapters/src/tron/TronChainAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,8 +605,10 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.TronMainnet> {

const parsedTx = this.parse(tx, pubkey)

const txInitiator = tx.raw_data?.contract?.[0]?.parameter?.value?.owner_address

const trc20Transfers = this.parseTRC20Transfers(tx, pubkey)
const internalTrxTransfers = this.parseInternalTrxTransfers(tx, pubkey)
const internalTrxTransfers = this.parseInternalTrxTransfers(tx, pubkey, txInitiator)

return {
...parsedTx,
Expand Down Expand Up @@ -695,6 +697,7 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.TronMainnet> {
private parseInternalTrxTransfers(
tx: unchained.tron.TronTx,
pubkey: string,
txInitiator?: string,
): {
assetId: AssetId
from: string[]
Expand Down Expand Up @@ -733,22 +736,29 @@ export class ChainAdapter implements IChainAdapter<KnownChainIds.TronMainnet> {

const value = String(callInfo.callValue)

const isSend = caller_address === pubkey
const isReceive = transferTo_address === pubkey

if (!isSend && !isReceive) continue
const isDirectSend = caller_address === pubkey
const isDirectReceive = transferTo_address === pubkey
const isInitiatedByUser = txInitiator === pubkey && caller_address !== pubkey

if (isSend) {
if (isDirectSend) {
transfers.push({
assetId: this.assetId,
from: [caller_address],
to: [transferTo_address],
type: TransferType.Send,
value,
})
} else if (isInitiatedByUser) {
transfers.push({
assetId: this.assetId,
from: [txInitiator],
to: [transferTo_address],
type: TransferType.Send,
value,
})
}

if (isReceive) {
if (isDirectReceive) {
transfers.push({
assetId: this.assetId,
from: [caller_address],
Expand Down