@exodus/ethereum-api 5.0.9 → 5.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-api",
3
- "version": "5.0.9",
3
+ "version": "5.0.10",
4
4
  "description": "Ethereum Api",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -36,5 +36,5 @@
36
36
  "devDependencies": {
37
37
  "@exodus/models": "^8.10.4"
38
38
  },
39
- "gitHead": "894830a79d49d9673b40143b4893234bc01a7cbc"
39
+ "gitHead": "ac047264960da5f5c08140def57f62e0eef80b39"
40
40
  }
@@ -23,6 +23,32 @@ async function getAssetSymbolFromContract(contractAddress) {
23
23
  return assetSymbol
24
24
  }
25
25
 
26
+ // Sometimes ERC20 transfers happen with a proxy contract and Blocknative Preview API duplicates them.
27
+ // We consider transfers having the same type (ERC20), symbol, decimals number and the delta number (transfer amount)
28
+ // as duplicates and remove them.
29
+ export function maybeRemoveDuplicates(balanceChanges) {
30
+ // We didn't encounter duplicates in other cases so doing this check to limit the function impact.
31
+ if (balanceChanges.length !== 2) return balanceChanges
32
+
33
+ const uniqueBalanceChanges = []
34
+ const existingBalanceChangesSet = new Set()
35
+ for (const balanceChange of balanceChanges) {
36
+ const { asset: assetData, delta } = balanceChange
37
+ if (assetData.type !== 'erc20') {
38
+ uniqueBalanceChanges.push(balanceChange)
39
+ continue
40
+ }
41
+
42
+ const key = `${assetData.type}:${assetData.symbol}:${assetData.decimal}:${delta}`
43
+ if (existingBalanceChangesSet.has(key)) continue
44
+
45
+ existingBalanceChangesSet.add(key)
46
+ uniqueBalanceChanges.push(balanceChange)
47
+ }
48
+
49
+ return uniqueBalanceChanges
50
+ }
51
+
26
52
  async function prepareBalanceChanges(
27
53
  internalTransactions,
28
54
  balanceChanges,
@@ -102,7 +128,7 @@ async function prepareBalanceChanges(
102
128
  }
103
129
  }
104
130
 
105
- return preparedBalanceChanges
131
+ return maybeRemoveDuplicates(preparedBalanceChanges)
106
132
  }
107
133
 
108
134
  async function tryToDecodeApprovalTransaction(transaction) {