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

Merge duplicate token transaction data from evmscan #832

Merged
merged 1 commit into from
Sep 12, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- fixed: (EVM) Merge duplicate token transaction data from evmscan fixing incorrect transaction native amounts

## 4.24.1 (2024-09-10)

- fixed: (ADA) Correctly parse txid after broadcasting a transaction
Expand Down
26 changes: 21 additions & 5 deletions src/ethereum/networkAdapters/EvmScanAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class EvmScanAdapter extends NetworkAdapter<EvmScanAdapterConfig> {
const address = this.ethEngine.walletLocalData.publicKey
let page = 1

const allTransactions: EdgeTransaction[] = []
let allTransactions: EdgeTransaction[] = []
let server: string | undefined
while (true) {
const offset = NUM_TRANSACTIONS_TO_QUERY
Expand Down Expand Up @@ -339,7 +339,7 @@ export class EvmScanAdapter extends NetworkAdapter<EvmScanAdapterConfig> {
cleanedTx,
l1RollupFee
)
allTransactions.push(tx)
allTransactions = mergeEdgeTransactions([...allTransactions, tx])
} catch (e: any) {
this.ethEngine.error(
`getAllTxsEthscan ${cleanerFunc.name}\n${safeErrorMessage(
Expand Down Expand Up @@ -533,7 +533,11 @@ export function mergeEdgeTransactions(
}

// Parent network is expected to always match for token transactions:
if (existingTransaction.parentNetworkFee !== transaction.parentNetworkFee) {
if (
existingTransaction.parentNetworkFee != null &&
transaction.parentNetworkFee != null &&
existingTransaction.parentNetworkFee !== transaction.parentNetworkFee
) {
throw new Error(
`Failed to merge transaction '${uniqueKey}': Mismatch parentNetworkFee`
)
Expand All @@ -547,12 +551,19 @@ export function mergeEdgeTransactions(
transaction.networkFee
)

// We can safely assume that the parentNetworkFees for each transaction
// are either the same or one or both are undefined. So, we can take the
// first non-undefined parentNetworkFee to get the merged parentNetworkFee:
const mergedParentNetworkFee =
existingTransaction.parentNetworkFee ?? transaction.parentNetworkFee

// Update the existing transaction:
const nativeAmount = add(
existingTransaction.nativeAmount,
transaction.nativeAmount
)
txidToTransaction.set(uniqueKey, {

const mergedTx = {
...existingTransaction,
isSend: nativeAmount.startsWith('-'),
nativeAmount,
Expand All @@ -561,7 +572,12 @@ export function mergeEdgeTransactions(
...existingTransaction.ourReceiveAddresses,
...transaction.ourReceiveAddresses
]
})
}
if (mergedParentNetworkFee != null) {
mergedTx.parentNetworkFee = mergedParentNetworkFee
}

txidToTransaction.set(uniqueKey, mergedTx)
}

return Array.from(txidToTransaction.values())
Expand Down
Loading