Skip to content

Commit

Permalink
Merge pull request #66 from KyberNetwork/feat/update-expiry-and-parse…
Browse files Browse the repository at this point in the history
…r-interface

feat: support parse expiry of bebop, oneinchv6, uniswapx and update p…
  • Loading branch information
vaigay authored Aug 28, 2024
2 parents 31e8a90 + 7d5efda commit 5b30ccb
Show file tree
Hide file tree
Showing 27 changed files with 321 additions and 171 deletions.
4 changes: 3 additions & 1 deletion pkg/decoder/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ func Decode(ABI *abi.ABI, input string) (*tradingTypes.ContractCall, error) {
if err != nil {
return nil, err
}

if len(input) < 10 {
return nil, fmt.Errorf("input data is too short")
}
bytes, err := hex.DecodeString(input[10:])
if err != nil {
return nil, err
Expand Down
7 changes: 2 additions & 5 deletions pkg/parser/bebop/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,12 @@ func (p *Parser) buildOrderByLog(log ethereumTypes.Log, blockTime uint64) (stora
return order, nil
}

func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
if callFrame == nil {
return storage.TradeLog{}, errors.New("missing call frame")
}
func (p *Parser) ParseWithCallFrame(callFrame types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
order, err := p.buildOrderByLog(log, blockTime)
if err != nil {
return storage.TradeLog{}, err
}
return p.searchTradeLog(order, types.ConvertCallFrame(callFrame))
return p.searchTradeLog(order, callFrame)
}

func (p *Parser) LogFromExchange(log ethereumTypes.Log) bool {
Expand Down
6 changes: 4 additions & 2 deletions pkg/parser/hashflow/hashflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package hashflow
import (
"context"
"encoding/json"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"math/big"
"strings"
"testing"
Expand All @@ -14,6 +13,9 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"

tradelogstype "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
)

const rpcURL = ""
Expand Down Expand Up @@ -84,7 +86,7 @@ func TestParseWithCallFrame(t *testing.T) {
continue
}

parse, err := p.ParseWithCallFrame(&callFrame, *eventLog, uint64(time.Now().Unix()))
parse, err := p.ParseWithCallFrame(tradelogstype.ConvertCallFrame(&callFrame), *eventLog, uint64(time.Now().Unix()))
require.NoError(t, err)
t.Log(parse)
}
Expand Down
27 changes: 8 additions & 19 deletions pkg/parser/hashflow/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"encoding/json"
"errors"
"github.com/KyberNetwork/tradelogs/pkg/decoder"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
ethereumTypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -79,10 +77,7 @@ func (p *Parser) Parse(log ethereumTypes.Log, blockTime uint64) (storage.TradeLo
return res, nil
}

func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
if callFrame == nil {
return storage.TradeLog{}, errors.New("missing call frame")
}
func (p *Parser) ParseWithCallFrame(callFrame types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
tradeLog, err := p.Parse(log, blockTime)
if err != nil {
return storage.TradeLog{}, err
Expand All @@ -103,19 +98,13 @@ func (p *Parser) UseTraceCall() bool {
return false
}

func (p *Parser) getRFQOrderParams(callFrame *tradingTypes.CallFrame) (*OrderRFQ, error) {
var (
err error
)
contractCall := callFrame.ContractCall
func (p *Parser) getRFQOrderParams(callFrame types.CallFrame) (*OrderRFQ, error) {
contractCall, err := decoder.Decode(p.abi, callFrame.Input)
if err != nil {
return nil, err
}
if contractCall == nil {
contractCall, err = decoder.Decode(p.abi, hexutil.Encode(callFrame.Input))
if err != nil {
return nil, err
}
if contractCall == nil {
return nil, errors.New("missing contract_call")
}
return nil, errors.New("missing contract_call")
}
for _, param := range contractCall.Params {
if param.Name != paramName {
Expand Down
3 changes: 2 additions & 1 deletion pkg/parser/hashflow_v3/hashflowv3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

tradelogstypes "github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -84,7 +85,7 @@ func TestParseWithCallFrame(t *testing.T) {
continue
}

parse, err := p.ParseWithCallFrame(&callFrame, *eventLog, uint64(time.Now().Unix()))
parse, err := p.ParseWithCallFrame(tradelogstypes.ConvertCallFrame(&callFrame), *eventLog, uint64(time.Now().Unix()))
require.NoError(t, err)
t.Log(parse)
}
Expand Down
28 changes: 9 additions & 19 deletions pkg/parser/hashflow_v3/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import (
"strings"

"github.com/KyberNetwork/tradelogs/pkg/decoder"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
ethereumTypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -87,10 +85,7 @@ func (p *Parser) UseTraceCall() bool {
return false
}

func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
if callFrame == nil {
return storage.TradeLog{}, errors.New("missing call frame")
}
func (p *Parser) ParseWithCallFrame(callFrame types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
tradeLog, err := p.Parse(log, blockTime)
if err != nil {
return storage.TradeLog{}, err
Expand All @@ -103,20 +98,15 @@ func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ether
return tradeLog, nil
}

func (p *Parser) getRFQOrderParams(callFrame *tradingTypes.CallFrame) (*OrderRFQ, error) {
var (
err error
)
contractCall := callFrame.ContractCall
func (p *Parser) getRFQOrderParams(callFrame types.CallFrame) (*OrderRFQ, error) {
contractCall, err := decoder.Decode(p.abi, callFrame.Input)
if err != nil {
return nil, err
}
if contractCall == nil {
contractCall, err = decoder.Decode(p.abi, hexutil.Encode(callFrame.Input))
if err != nil {
return nil, err
}
if contractCall == nil {
return nil, errors.New("missing contract_call")
}
return nil, errors.New("missing contract_call")
}

for _, param := range contractCall.Params {
if param.Name != paramName {
continue
Expand Down
5 changes: 2 additions & 3 deletions pkg/parser/kyberswap/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package kyberswap
import (
"strings"

tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"

ethereumTypes "github.com/ethereum/go-ethereum/core/types"

"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
)
Expand Down Expand Up @@ -81,7 +80,7 @@ func (p *Parser) UseTraceCall() bool {
return false
}

func (p *Parser) ParseWithCallFrame(_ *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
func (p *Parser) ParseWithCallFrame(_ types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
return p.Parse(log, blockTime)
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/parser/kyberswap_rfq/kyberswap_rfq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ package kyberswaprfq
import (
"context"
"encoding/json"
"strings"
"testing"

"github.com/KyberNetwork/tradelogs/pkg/storage"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"
"strings"
"testing"

tradelogstype "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
)

const rpcURL = ""
Expand Down Expand Up @@ -55,7 +58,7 @@ func TestParseWithCallFrame(t *testing.T) {
continue
}

parse, err := p.ParseWithCallFrame(&callFrame, *eventLog, 0)
parse, err := p.ParseWithCallFrame(tradelogstype.ConvertCallFrame(&callFrame), *eventLog, 0)
require.NoError(t, err)
t.Log(parse)
require.Equal(t, expectedTradelog, parse)
Expand Down
28 changes: 9 additions & 19 deletions pkg/parser/kyberswap_rfq/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
"strings"

"github.com/KyberNetwork/tradelogs/pkg/decoder"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/ethereum/go-ethereum/common/hexutil"

"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -89,10 +87,7 @@ func (p *Parser) UseTraceCall() bool {
return false
}

func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
if callFrame == nil {
return storage.TradeLog{}, errors.New("missing call frame")
}
func (p *Parser) ParseWithCallFrame(callFrame types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
tradeLog, err := p.Parse(log, blockTime)
if err != nil {
return storage.TradeLog{}, err
Expand All @@ -105,20 +100,15 @@ func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ether
return tradeLog, nil
}

func (p *Parser) getRFQOrderParams(callFrame *tradingTypes.CallFrame) (*OrderRFQ, error) {
var (
err error
)
contractCall := callFrame.ContractCall
func (p *Parser) getRFQOrderParams(callFrame types.CallFrame) (*OrderRFQ, error) {
contractCall, err := decoder.Decode(p.abi, callFrame.Input)
if err != nil {
return nil, err
}
if contractCall == nil {
contractCall, err = decoder.Decode(p.abi, hexutil.Encode(callFrame.Input))
if err != nil {
return nil, err
}
if contractCall == nil {
return nil, errors.New("missing contract_call")
}
return nil, errors.New("missing contract_call")
}

for _, param := range contractCall.Params {
if param.Name != paramName {
continue
Expand Down
5 changes: 2 additions & 3 deletions pkg/parser/native/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package native

import (
"errors"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"

"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"

Expand Down Expand Up @@ -84,6 +83,6 @@ func (p *Parser) UseTraceCall() bool {
return false
}

func (p *Parser) ParseWithCallFrame(_ *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
func (p *Parser) ParseWithCallFrame(_ types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
return p.Parse(log, blockTime)
}
4 changes: 2 additions & 2 deletions pkg/parser/okx/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"
"github.com/KyberNetwork/tradelogs/pkg/storage"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
ethereumTypes "github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -69,6 +69,6 @@ func (p *Parser) Parse(log ethereumTypes.Log, blockTime uint64) (storage.TradeLo
return res, nil
}

func (p *Parser) ParseWithCallFrame(_ *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
func (p *Parser) ParseWithCallFrame(_ types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
return p.Parse(log, blockTime)
}
13 changes: 7 additions & 6 deletions pkg/parser/oneinch/oneinch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ import (
"testing"
"time"

"github.com/KyberNetwork/tradelogs/pkg/storage"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"

"github.com/KyberNetwork/tradelogs/pkg/rpcnode"
"github.com/KyberNetwork/tradelogs/pkg/tracecall"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/stretchr/testify/require"

"github.com/KyberNetwork/tradelogs/pkg/rpcnode"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/tracecall"
tradelogstype "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
)

const rpcURL = ""
Expand Down Expand Up @@ -155,7 +156,7 @@ func TestParseWithCallFrame(t *testing.T) {
continue
}

parse, err := p.ParseWithCallFrame(&callFrame, *eventLog, 0)
parse, err := p.ParseWithCallFrame(tradelogstype.ConvertCallFrame(&callFrame), *eventLog, 0)
require.NoError(t, err)
require.Equal(t, expectedTradeLog, parse)
}
Expand Down
10 changes: 3 additions & 7 deletions pkg/parser/oneinch/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"math/big"
"strings"

Expand All @@ -14,6 +12,7 @@ import (
"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradelogs/pkg/tracecall"
"github.com/KyberNetwork/tradelogs/pkg/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
Expand Down Expand Up @@ -233,15 +232,12 @@ func (p *Parser) buildOrderByLog(log ethereumTypes.Log, blockTime uint64) (stora
return order, nil
}

func (p *Parser) ParseWithCallFrame(callFrame *tradingTypes.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
if callFrame == nil {
return storage.TradeLog{}, errors.New("missing call frame")
}
func (p *Parser) ParseWithCallFrame(callFrame types.CallFrame, log ethereumTypes.Log, blockTime uint64) (storage.TradeLog, error) {
tradeLog, err := p.buildOrderByLog(log, blockTime)
if err != nil {
return storage.TradeLog{}, err
}
tradeLog, err = p.recursiveDetectOneInchRFQTrades(tradeLog, types.ConvertCallFrame(callFrame))
tradeLog, err = p.recursiveDetectOneInchRFQTrades(tradeLog, callFrame)
if err != nil {
return tradeLog, err
}
Expand Down
Loading

0 comments on commit 5b30ccb

Please sign in to comment.