Skip to content

Commit

Permalink
add trace call into error (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocthanh1389 authored Jun 17, 2024
1 parent 6dda023 commit 55bb32d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
21 changes: 17 additions & 4 deletions pkg/parser/bebop/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bebop
import (
"encoding/json"
"errors"
"fmt"
"math/big"
"strings"

Expand Down Expand Up @@ -145,7 +146,7 @@ func (p *Parser) parseTraceCall(order storage.TradeLog) (storage.TradeLog, error
}

func (p *Parser) searchTradeLog(order storage.TradeLog, traceCall types.CallFrame) (storage.TradeLog, error) {
if p.checkBebopTrade(traceCall) {
if p.checkBebopTrade(traceCall, order.OrderHash) {
return p.ParseFromInternalCall(order, traceCall)
}

Expand All @@ -155,17 +156,29 @@ func (p *Parser) searchTradeLog(order storage.TradeLog, traceCall types.CallFram
return tradeLog, nil
}
}
return order, ErrNotFoundLog
traceData, _ := json.Marshal(traceCall)
return order, fmt.Errorf("%w %s", ErrNotFoundLog, string(traceData))
}

func (p *Parser) checkBebopTrade(traceCall types.CallFrame) bool {
func (p *Parser) checkBebopTrade(traceCall types.CallFrame, orderHash string) bool {
for _, eventLog := range traceCall.Logs {
if len(eventLog.Topics) == 0 {
if len(eventLog.Topics) < 2 {
continue
}
if !strings.EqualFold(eventLog.Topics[0].String(), p.eventHash) {
continue
}
x, ok := big.NewInt(0).SetString(orderHash, 10)
if !ok {
continue
}
y, ok := big.NewInt(0).SetString(eventLog.Topics[1].String()[2:], 16)
if !ok {
continue
}
if x.Cmp(y) != 0 {
continue
}
return true
}
return false
Expand Down
4 changes: 3 additions & 1 deletion pkg/parser/oneinch/parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oneinch

import (
"encoding/json"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -159,7 +160,8 @@ func (p *Parser) recursiveDetectOneInchRFQTrades(tradeLog storage.TradeLog, trac
return tradeLog, nil
}
}
return tradeLog, ErrNotFoundLog
traceData, _ := json.Marshal(traceCall)
return tradeLog, fmt.Errorf("%w %s", ErrNotFoundLog, string(traceData))
}

func (p *Parser) isOneInchRFQTrades(makingAmountOrder string, orderHash string, traceCall types.CallFrame) bool {
Expand Down
4 changes: 3 additions & 1 deletion pkg/parser/oneinchv6/parser.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package oneinchv6

import (
"encoding/json"
"errors"
"fmt"
"math/big"
Expand Down Expand Up @@ -163,7 +164,8 @@ func (p *Parser) recursiveDetectOneInchRFQTrades(tradeLog storage.TradeLog, trac
}
}

return tradeLog, ErrNotFoundLog
traceData, _ := json.Marshal(traceCall)
return tradeLog, fmt.Errorf("%w %s", ErrNotFoundLog, string(traceData))
}

func (p *Parser) isOneInchRFQTrades(txHash, orderHash string, traceCall types.CallFrame, count *int) bool {
Expand Down
9 changes: 5 additions & 4 deletions pkg/parser/uniswapx/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type ResolvedOrder struct {

var (
ErrInvalidOneInchFilledTopic = errors.New("invalid uniswapx order filled topic")
ErrUpdateOrder = errors.New("can't update order")
ErrNotFoundLog = errors.New("not found log")
)

type Parser struct {
Expand Down Expand Up @@ -207,7 +207,7 @@ func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.Cal
if err != nil {
continue
}
finalOrder, err := p.updateOrder(call.From, order, parsedOrder)
finalOrder, err := p.updateOrder(order, parsedOrder)
if err != nil {
continue
}
Expand All @@ -220,10 +220,11 @@ func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.Cal
return order, nil
}
}
return order, ErrUpdateOrder
traceData, _ := json.Marshal(call)
return order, fmt.Errorf("%w %s", ErrNotFoundLog, string(traceData))
}

func (p *Parser) updateOrder(from string, internal storage.TradeLog, parsed []interface{}) (storage.TradeLog, error) {
func (p *Parser) updateOrder(internal storage.TradeLog, parsed []interface{}) (storage.TradeLog, error) {
data, err := json.Marshal(parsed)
if err != nil {
return storage.TradeLog{}, err
Expand Down

0 comments on commit 55bb32d

Please sign in to comment.