88 "github.com/0xsequence/ethkit/ethrpc"
99 "github.com/0xsequence/ethkit/go-ethereum/common"
1010 "github.com/0xsequence/go-sequence/receipts"
11- "github.com/davecgh/go-spew/spew"
1211 "github.com/stretchr/testify/require"
1312)
1413
@@ -31,6 +30,20 @@ func TestFetchReceiptTokenTransfers(t *testing.T) {
3130 require .Equal (t , common .HexToAddress ("0x1D17C0F90A0b3dFb5124C2FF56B33a0D2E202e1d" ), transfers [0 ].From )
3231 require .Equal (t , common .HexToAddress ("0x5646E2424A7b7d43740EF14bc5b4f1e00Bf9B6Ba" ), transfers [0 ].To )
3332 require .Equal (t , big .NewInt (184840 ), transfers [0 ].Value )
33+
34+ // Get the balance outputs from the transfer logs
35+ balances := transfers .ComputeBalanceOutputs ()
36+ require .NotNil (t , balances )
37+ require .Equal (t , len (balances ), 2 )
38+ // spew.Dump(balances)
39+
40+ require .Equal (t , common .HexToAddress ("0xaf88d065e77c8cC2239327C5EDb3A432268e5831" ), balances [0 ].Token ) // USDC
41+ require .Equal (t , common .HexToAddress ("0x1D17C0F90A0b3dFb5124C2FF56B33a0D2E202e1d" ), balances [0 ].Account )
42+ require .Equal (t , big .NewInt (- 184840 ), balances [0 ].Balance )
43+
44+ require .Equal (t , common .HexToAddress ("0xaf88d065e77c8cC2239327C5EDb3A432268e5831" ), balances [1 ].Token ) // USDC
45+ require .Equal (t , common .HexToAddress ("0x5646E2424A7b7d43740EF14bc5b4f1e00Bf9B6Ba" ), balances [1 ].Account )
46+ require .Equal (t , big .NewInt (184840 ), balances [1 ].Balance )
3447 })
3548
3649 // Case 2: a txn with a bunch of different erc20 transfers inside of it, ie. batch send
@@ -46,7 +59,7 @@ func TestFetchReceiptTokenTransfers(t *testing.T) {
4659 require .NotNil (t , receipt )
4760 require .Greater (t , len (transfers ), 0 )
4861
49- spew .Dump (transfers )
62+ // spew.Dump(transfers)
5063 require .Equal (t , 2 , len (transfers ))
5164
5265 // USDC
@@ -60,11 +73,33 @@ func TestFetchReceiptTokenTransfers(t *testing.T) {
6073 require .Equal (t , common .HexToAddress ("0x8e3E38fe7367dd3b52D1e281E4e8400447C8d8B9" ), transfers [1 ].From )
6174 require .Equal (t , common .HexToAddress ("0x9b1A542f3C455E8d6057C3478EB945B48D8e17fF" ), transfers [1 ].To )
6275 require .Equal (t , big .NewInt (200000000000000000 ), transfers [1 ].Value )
76+
77+ // Get the balance outputs from the transfer logs
78+ balances := transfers .ComputeBalanceOutputs ()
79+ require .NotNil (t , balances )
80+ require .Equal (t , len (balances ), 4 )
81+ // spew.Dump(balances)
82+
83+ require .Equal (t , common .HexToAddress ("0x539bdE0d7Dbd336b79148AA742883198BBF60342" ), balances [0 ].Token ) // MAGIC
84+ require .Equal (t , common .HexToAddress ("0x8e3E38fe7367dd3b52D1e281E4e8400447C8d8B9" ), balances [0 ].Account )
85+ require .Equal (t , big .NewInt (- 200000000000000000 ), balances [0 ].Balance )
86+
87+ require .Equal (t , common .HexToAddress ("0xaf88d065e77c8cC2239327C5EDb3A432268e5831" ), balances [1 ].Token ) // USDC
88+ require .Equal (t , common .HexToAddress ("0x8e3E38fe7367dd3b52D1e281E4e8400447C8d8B9" ), balances [1 ].Account )
89+ require .Equal (t , big .NewInt (- 100000 ), balances [1 ].Balance )
90+
91+ require .Equal (t , common .HexToAddress ("0xaf88d065e77c8cC2239327C5EDb3A432268e5831" ), balances [2 ].Token ) // USDC
92+ require .Equal (t , common .HexToAddress ("0x9b1A542f3C455E8d6057C3478EB945B48D8e17fF" ), balances [2 ].Account )
93+ require .Equal (t , big .NewInt (100000 ), balances [2 ].Balance )
94+
95+ require .Equal (t , common .HexToAddress ("0x539bdE0d7Dbd336b79148AA742883198BBF60342" ), balances [3 ].Token ) // MAGIC
96+ require .Equal (t , common .HexToAddress ("0x9b1A542f3C455E8d6057C3478EB945B48D8e17fF" ), balances [3 ].Account )
97+ require .Equal (t , big .NewInt (200000000000000000 ), balances [3 ].Balance )
6398 })
6499
65100 // Case 3: a trails intent call, with bunch of other actions inside of the txn, including erc20 transfers
66101 // https://arbiscan.io/tx/0xb88cc2fea7cd26c88e169f6244fea76f590fc0797ba4c424669d1b74643f1dc9
67- t .Run ("Case 3: .. " , func (t * testing.T ) {
102+ t .Run ("Case 3: Trails intent origin call " , func (t * testing.T ) {
68103 provider , err := ethrpc .NewProvider ("https://nodes.sequence.app/arbitrum" )
69104 require .NoError (t , err )
70105
@@ -103,7 +138,7 @@ func TestFetchReceiptTokenTransfers(t *testing.T) {
103138 require .Equal (t , collector , transfers [2 ].To )
104139 require .Equal (t , big .NewInt (9979 ), transfers [2 ].Value )
105140
106- // Get the delta / net effects
141+ // Get the balance outputs from the transfer logs
107142 balances := transfers .ComputeBalanceOutputs ()
108143 require .NotNil (t , balances )
109144 require .Equal (t , len (balances ), 3 )
@@ -125,23 +160,22 @@ func TestFetchReceiptTokenTransfers(t *testing.T) {
125160 // Case 4: a trails cross-chain swap where we use 0x + cctp to swap from MAGIC to USDC then bridge
126161 // over CCTP. This includes many calls with USDC and MAGIC.
127162 // https://arbiscan.io/tx/0xa5c17e51443c8a8ce60cdcbe84b89fd2570f073bbb3b9ec8cdc9361aa1ca984f
128- t .Run ("Case 4: .. " , func (t * testing.T ) {
163+ t .Run ("Case 4: Trails swap intent call " , func (t * testing.T ) {
129164 })
130165
131166 // Case 5: vault bridge USDC .. lets check the token transfer event, prob just erc20 too
132167 // https://katanascan.com/tx/0x7bcd0068a5c3352cf4e1d75c7c4f78d99f02b8b2f5f96b2c407972f43e724f52
133- t .Run ("Case 5: .. " , func (t * testing.T ) {
168+ t .Run ("Case 5: Vault bridge USDC transfer " , func (t * testing.T ) {
134169 })
135170
136171 // Case 6: polygon POL LogTransfer event
137172 // https://polygonscan.com/tx/0x252419983224542bfb07dab75808fa57186a7a269d0d267ae655eb7ef037fdd5
138- t .Run ("Case 6: .. " , func (t * testing.T ) {
173+ t .Run ("Case 6: POL with LogTransfer " , func (t * testing.T ) {
139174 })
140175
141176 // Case 7: bunch of logs for the same erc20 token, and we need to sum it up, ie. a big uniswap call
142- // and we have to do a delta/diff, and return the "result" maybe "TokenTransferResult" ?
143177 // https://etherscan.io/tx/0xb11ff491495e145b07a1d3cc304f7d04b235b80af51b50da9a54095a6882fca4
144- t .Run ("Case 7: .. " , func (t * testing.T ) {
178+ t .Run ("Case 7: Random txn with swap and many tokens " , func (t * testing.T ) {
145179 })
146180}
147181
0 commit comments