@@ -2,6 +2,7 @@ import { formatUnits } from 'ethers/lib/utils'
2
2
import { constants } from 'ethers'
3
3
import networks from 'consts/networks'
4
4
import humanizers from './humanizers'
5
+ import { isZeroAddress } from 'ethereumjs-util'
5
6
6
7
// address (lowercase) => name
7
8
let knownAliases = { }
@@ -10,6 +11,93 @@ const knownTokens = {}
10
11
// address (lowercase) => name
11
12
const knownAddressNames = { }
12
13
14
+ function parseActions ( actions ) {
15
+ const result = [ ]
16
+ for ( let i = 0 ; i < actions . length ; i ++ ) {
17
+
18
+ const notLast = i < actions . length - 1
19
+ if ( ! notLast ) {
20
+ result . push ( actions [ i ] )
21
+ continue
22
+ }
23
+
24
+ if (
25
+ // are valid [obj]
26
+ actions [ i ] . length >= 4 &&
27
+ actions [ i + 1 ] . length >= 2 &&
28
+ Array . isArray ( actions [ i ] ) &&
29
+ Array . isArray ( actions [ i + 1 ] ) &&
30
+ // are actual swap and unwrap
31
+ typeof actions [ i ] [ 0 ] === 'string' &&
32
+ actions [ i ] [ 0 ] . startsWith ( 'Swap' ) &&
33
+ actions [ i ] [ 3 ] . type === 'token' &&
34
+ // isWrappedAsset(actions[i][3].address) &&
35
+ typeof actions [ i + 1 ] [ 3 ] === 'string' &&
36
+ actions [ i + 1 ] [ 0 ] . startsWith ( 'Unwrap' ) &&
37
+ actions [ i + 1 ] [ 1 ] . type === 'token' &&
38
+ // have proper values and addresses
39
+ actions [ i ] [ 3 ] . amount === actions [ i + 1 ] [ 1 ] . amount &&
40
+ isZeroAddress ( actions [ i + 1 ] [ 1 ] . address )
41
+ ) {
42
+ // swap x for at least y
43
+ result . push ( [ "Swap" , actions [ i ] [ 1 ] , actions [ i ] [ 2 ] , actions [ i + 1 ] [ 1 ] ] )
44
+ // skip next ccall, since two were merged
45
+ i ++
46
+ continue
47
+ }
48
+
49
+ if (
50
+ // are valid [obj]
51
+ actions [ i ] . length >= 2 &&
52
+ actions [ i + 1 ] . length >= 4 &&
53
+ Array . isArray ( actions [ i ] ) &&
54
+ Array . isArray ( actions [ i + 1 ] ) &&
55
+ // are actual Wrap and Swap
56
+ typeof actions [ i ] [ 0 ] === 'string' &&
57
+ actions [ i ] [ 0 ] . startsWith ( 'Wrap' ) &&
58
+ actions [ i ] [ 1 ] . type === 'token' &&
59
+ typeof actions [ i + 1 ] [ 0 ] === 'string' &&
60
+ actions [ i + 1 ] [ 0 ] . startsWith ( 'Swap' ) &&
61
+ actions [ i + 1 ] [ 3 ] . type === 'token' &&
62
+ // have proper values and addresses
63
+ actions [ i + 1 ] [ 1 ] . amount === actions [ i ] [ 1 ] . amount &&
64
+ isZeroAddress ( actions [ i ] [ 1 ] . address )
65
+ ) {
66
+ // swap x for at least y
67
+ result . push ( [ "Swap" , actions [ i ] [ 1 ] , actions [ i + 1 ] [ 2 ] , actions [ i + 1 ] [ 3 ] ] )
68
+ // skip next ccall, since two were merged
69
+ i ++
70
+ continue
71
+ }
72
+
73
+
74
+
75
+ if (
76
+ // are valid [obj]
77
+ actions [ i ] . length == 2 &&
78
+ actions [ i + 1 ] . length == 2 &&
79
+ Array . isArray ( actions [ i ] ) &&
80
+ Array . isArray ( actions [ i + 1 ] ) &&
81
+ // are actual Unwrap and Sweep
82
+ typeof actions [ i ] [ 0 ] === 'string' &&
83
+ actions [ i ] [ 0 ] . startsWith ( 'Unwrap' ) &&
84
+ actions [ i ] [ 1 ] . type === 'token' &&
85
+ typeof actions [ i + 1 ] [ 0 ] === 'string' &&
86
+ actions [ i + 1 ] [ 0 ] . startsWith ( 'Sweep' ) &&
87
+ actions [ i + 1 ] [ 1 ] . type === 'token'
88
+ ) {
89
+ result . push ( [ "Remove liquidity and withdraw" , actions [ i ] [ 1 ] , "and" , actions [ i + 1 ] [ 1 ] ] )
90
+ // skip next ccall, since two were merged
91
+ i ++
92
+ continue
93
+ }
94
+
95
+ result . push ( actions [ i ] )
96
+ continue
97
+ }
98
+ return result
99
+ }
100
+
13
101
export const formatNativeTokenAddress = ( address ) =>
14
102
address . toLowerCase ( ) === `0x${ 'e' . repeat ( 40 ) } ` ? `0x${ '0' . repeat ( 40 ) } ` : address . toLowerCase ( )
15
103
@@ -82,7 +170,8 @@ export function getTransactionSummary(
82
170
83
171
if ( humanizer ) {
84
172
try {
85
- const actions = humanizer ( { to, value, data, from : accountAddr } , network , opts )
173
+ let actions = humanizer ( { to, value, data, from : accountAddr } , network , opts )
174
+ actions = parseActions ( actions )
86
175
return opts . extended === true ? actions : actions . join ( ', ' )
87
176
} catch ( e ) {
88
177
callSummary = opts . extended
0 commit comments