Skip to content

Commit

Permalink
feat: support parse expiry of bebop, oneinchv6, uniswapx and update p…
Browse files Browse the repository at this point in the history
…arse with call frame
  • Loading branch information
vaigay committed Aug 27, 2024
1 parent 31e8a90 commit 8939bb9
Show file tree
Hide file tree
Showing 26 changed files with 300 additions and 157 deletions.
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
3 changes: 2 additions & 1 deletion pkg/parser/hashflow/hashflow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package hashflow
import (
"context"
"encoding/json"
tradelogs_type "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"math/big"
"strings"
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(tradelogs_type.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"

tradelogs_types "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(tradelogs_types.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 @@ -3,12 +3,10 @@ package hashflowv3
import (
"encoding/json"
"errors"
"github.com/KyberNetwork/tradelogs/pkg/types"
"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/ethereum/go-ethereum/accounts/abi"
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
@@ -1,10 +1,9 @@
package kyberswap

import (
"github.com/KyberNetwork/tradelogs/pkg/types"
"strings"

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

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

"github.com/KyberNetwork/tradelogs/pkg/parser"
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
3 changes: 2 additions & 1 deletion pkg/parser/kyberswap_rfq/kyberswap_rfq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"github.com/KyberNetwork/tradelogs/pkg/storage"
tradelogs_type "github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestParseWithCallFrame(t *testing.T) {
continue
}

parse, err := p.ParseWithCallFrame(&callFrame, *eventLog, 0)
parse, err := p.ParseWithCallFrame(tradelogs_type.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 @@ -4,12 +4,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/KyberNetwork/tradelogs/pkg/types"
"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/ethereum/go-ethereum/accounts/abi"
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)
}
3 changes: 2 additions & 1 deletion pkg/parser/oneinch/oneinch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package oneinch
import (
"context"
"encoding/json"
tradelogs_type "github.com/KyberNetwork/tradelogs/pkg/types"
"math/big"
"strings"
"testing"
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(tradelogs_type.ConvertCallFrame(&callFrame), *eventLog, 0)
require.NoError(t, err)
require.Equal(t, expectedTradeLog, parse)
}
Expand Down
8 changes: 2 additions & 6 deletions pkg/parser/oneinch/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/KyberNetwork/tradelogs/pkg/types"
tradingTypes "github.com/KyberNetwork/tradinglib/pkg/types"
"math/big"
"strings"

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 8939bb9

Please sign in to comment.