Skip to content

Commit c782f51

Browse files
committed
fix: handle failed tokenDisabled call
1 parent 0292e73 commit c782f51

File tree

6 files changed

+144
-10
lines changed

6 files changed

+144
-10
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
inputs
12
__debug_bin
23
.DS_Store
34
.env
@@ -6,4 +7,4 @@ app
67
/.env.local
78
temp
89
dist
9-
test.go
10+
test.go

ds/execute_parse_len_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package ds
2+
3+
import (
4+
"encoding/hex"
5+
"strings"
6+
"testing"
7+
8+
"github.com/Gearbox-protocol/sdk-go/artifacts/multicall"
9+
"github.com/Gearbox-protocol/sdk-go/core/schemas"
10+
"github.com/Gearbox-protocol/sdk-go/utils"
11+
"github.com/ethereum/go-ethereum/common"
12+
)
13+
14+
type ExecuteParserLenTester struct {
15+
TxHash string `json:"txHash"`
16+
Calls []string `json:"calls"`
17+
Events []*schemas.AccountOperation `json:"events"`
18+
}
19+
20+
func (tester ExecuteParserLenTester) GetCalls(t *testing.T) FacadeCallNameWithMulticall {
21+
var multicalls []multicall.Multicall2Call
22+
for _, call := range tester.Calls {
23+
_s := strings.Split(call, "@")
24+
bytes, err := hex.DecodeString(_s[1])
25+
if err != nil {
26+
t.Fatal(err)
27+
}
28+
multicalls = append(multicalls, multicall.Multicall2Call{
29+
Target: common.HexToAddress(_s[0]),
30+
CallData: bytes,
31+
})
32+
}
33+
return FacadeCallNameWithMulticall{
34+
Name: "test",
35+
multiCalls: multicalls,
36+
}
37+
}
38+
39+
// checks failed tokeDisabled call
40+
func Test_Check1(t *testing.T) {
41+
data := ExecuteParserLenTester{}
42+
utils.ReadJsonAndSetInterface("execute_parser/check_failed_token_disabled.json", &data)
43+
44+
calls := data.GetCalls(t)
45+
if !calls.SameMulticallLenAsEvents(data.Events) {
46+
t.Fatalf("expected %d multicalls, but third-eye detected %d. Events: %s. Calls: %s. txhash: %s",
47+
calls.LenOfMulticalls(), len(data.Events),
48+
utils.ToJson(data.Events), calls.String(), data.TxHash)
49+
}
50+
}
51+
52+
// checks if the events len is zero, can func handle it?
53+
func Test_Check2(t *testing.T) {
54+
data := ExecuteParserLenTester{}
55+
utils.ReadJsonAndSetInterface("execute_parser/check_event_len_0.json", &data)
56+
57+
calls := data.GetCalls(t)
58+
if !calls.SameMulticallLenAsEvents(data.Events) {
59+
t.Fatalf("expected %d multicalls, but third-eye detected %d. Events: %s. Calls: %s. txhash: %s",
60+
calls.LenOfMulticalls(), len(data.Events),
61+
utils.ToJson(data.Events), calls.String(), data.TxHash)
62+
}
63+
}

ds/execute_parser.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@ func (f FacadeCallNameWithMulticall) LenOfMulticalls() int {
5656
return len(f.multiCalls)
5757
}
5858

59-
// handles revertIflessthan case where event is not emitted.
60-
// also handles cases where number of execute order events emitted is less than execute calls
59+
// handles revertIflessthan case where event is not emitted. L1
60+
// handles failed tokenDisabled call. L2
61+
// also handles cases where number of execute order events emitted is less than execute calls // L3
62+
// event len can be zero in case of all failed calls, so no events.
6163
func (f *FacadeCallNameWithMulticall) SameMulticallLenAsEvents(events []*schemas.AccountOperation) bool {
6264
if f.TestLen != 0 {
6365
return f.TestLen == len(events)
@@ -101,15 +103,15 @@ func (f *FacadeCallNameWithMulticall) SameMulticallLenAsEvents(events []*schemas
101103
eventInd++
102104
callInd++
103105
case "23e27a64": // disable token
104-
if events[eventInd].Action != "TokenDisabled(address,address)" {
105-
return false
106+
if events[eventInd].Action == "TokenDisabled(address,address)" { // L2
107+
eventInd++
106108
}
107-
eventInd++
108-
callInd++
109-
case "81314b59": // revert if less than // ignore for event // revertIfReceivedLessThan
109+
callInd++ // disabled call can fail.
110+
case "81314b59": // revert if less than // ignore for event // revertIfReceivedLessThan // L1
110111
callInd++
111-
default: //execute order
112+
default: //execute order // L3
112113
// it might happen that some of the execution call are not executed so len of provided multicalls will be more than executed calls.
114+
// takes longest array of execute order events and calls, and compares their sizes. len events< len calls
113115
executeEvent := 0
114116
for eventInd < len(events) && events[eventInd].Action == "ExecuteOrder" {
115117
executeEvent++
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"calls": [
3+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@0000beef",
4+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@0000beef",
5+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@0000beef"
6+
],
7+
"events": [],
8+
"txhash": "0x"
9+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"calls": [
3+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@23e27a64",
4+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@23e27a64",
5+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@23e27a64",
6+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@c690908a",
7+
"0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541@c690908a"
8+
],
9+
"events": [
10+
{
11+
"MainAction": null,
12+
"action": "TokenDisabled(address,address)",
13+
"adapterCall": false,
14+
"args": {
15+
"token": "0xaF314b088B53835d5cF4e4CB81beABa5934a61fe"
16+
},
17+
"blockNum": 18630876,
18+
"borrower": "0xd1a3DcD7E6e81aE8D65B37016cF7Fa954B9dfD2B",
19+
"dapp": "0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541",
20+
"logId": 123,
21+
"multicalls": null,
22+
"sessionId": "0x8cDd4544B87B3AE1e04291E0468d3d0377ef0D54_15976867_133",
23+
"transfers": null,
24+
"txHash": "0x133eae4a6d131295b086f8c1c2635932ed717d79565f3592d2a95a5f376c4c0f"
25+
},
26+
{
27+
"MainAction": null,
28+
"action": "TokenEnabled(address,address)",
29+
"adapterCall": false,
30+
"args": {
31+
"token": "0x4e3FBD56CD56c3e72c1403e103b45Db9da5B9D2B"
32+
},
33+
"blockNum": 18630876,
34+
"borrower": "0xd1a3DcD7E6e81aE8D65B37016cF7Fa954B9dfD2B",
35+
"dapp": "0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541",
36+
"logId": 124,
37+
"multicalls": null,
38+
"sessionId": "0x8cDd4544B87B3AE1e04291E0468d3d0377ef0D54_15976867_133",
39+
"transfers": null,
40+
"txHash": "0x133eae4a6d131295b086f8c1c2635932ed717d79565f3592d2a95a5f376c4c0f"
41+
},
42+
{
43+
"MainAction": null,
44+
"action": "TokenEnabled(address,address)",
45+
"adapterCall": false,
46+
"args": {
47+
"token": "0xD533a949740bb3306d119CC777fa900bA034cd52"
48+
},
49+
"blockNum": 18630876,
50+
"borrower": "0xd1a3DcD7E6e81aE8D65B37016cF7Fa954B9dfD2B",
51+
"dapp": "0x34EE4eed88BCd2B5cDC3eF9A9DD0582EE538E541",
52+
"logId": 125,
53+
"multicalls": null,
54+
"sessionId": "0x8cDd4544B87B3AE1e04291E0468d3d0377ef0D54_15976867_133",
55+
"transfers": null,
56+
"txHash": "0x133eae4a6d131295b086f8c1c2635932ed717d79565f3592d2a95a5f376c4c0f"
57+
}
58+
],
59+
"txhash": "0x133eae4a6d131295b086f8c1c2635932ed717d79565f3592d2a95a5f376c4c0f"
60+
}

inputs/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)