Skip to content

Commit

Permalink
add uniswapx (#42)
Browse files Browse the repository at this point in the history
* add uniswapx

* update to uniswapx v2

* handle error create type
  • Loading branch information
ngocthanh1389 authored Apr 25, 2024
1 parent 2c2430a commit d20cda0
Show file tree
Hide file tree
Showing 21 changed files with 1,328 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/tradelogs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/parser/oneinch"
"github.com/KyberNetwork/tradelogs/pkg/parser/oneinchv6"
"github.com/KyberNetwork/tradelogs/pkg/parser/uniswapx"
"github.com/KyberNetwork/tradelogs/pkg/rpcnode"
"github.com/KyberNetwork/tradelogs/pkg/tracecall"

Expand Down Expand Up @@ -105,6 +106,7 @@ func run(c *cli.Context) error {
hashflowv3.MustNewParser(),
oneinch.MustNewParser(traceCalls),
oneinchv6.MustNewParser(traceCalls),
uniswapx.MustNewParser(traceCalls),
}

tradeLogChan := make(chan storage.TradeLog, 1000)
Expand Down
5 changes: 3 additions & 2 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ func New(l *zap.SugaredLogger, s *storage.Storage, listener *evmlistenerclient.C
}

func (w *Worker) Run(ctx context.Context) error {
retryTimer := time.NewTicker(evmlistenerclient.BlockTime)
retryTimer := time.NewTicker(evmlistenerclient.RetryTime)
defer retryTimer.Stop()
for {
select {
case <-retryTimer.C:
Expand Down Expand Up @@ -127,7 +128,7 @@ func (w *Worker) processMessages(m []evmlistenerclient.Message) error {

func (w *Worker) retryParseLog() error {
insertOrders := []storage.TradeLog{}
logs, err := w.s.GetErrorLogs()
logs, err := w.s.GetErrorLogsSince(time.Now().Add(-time.Hour * 24).Unix())
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/evmlistenerclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (

var (
BlockTime = 12 * time.Second
RetryTime = 2 * time.Second
)

type Config struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/parser/hashflow/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExHashflow
}

func (p *Parser) UseTraceCall() bool {
return false
}
4 changes: 4 additions & 0 deletions pkg/parser/hashflow_v3/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExHashflowV3
}

func (p *Parser) UseTraceCall() bool {
return false
}
4 changes: 4 additions & 0 deletions pkg/parser/kyberswap/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExKs
}

func (p *Parser) UseTraceCall() bool {
return false
}
4 changes: 4 additions & 0 deletions pkg/parser/kyberswap_rfq/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ func (p *Parser) Exchange() string {
return parser.ExKsRFQ
}

func (p *Parser) UseTraceCall() bool {
return false
}

4 changes: 4 additions & 0 deletions pkg/parser/native/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExNative
}

func (p *Parser) UseTraceCall() bool {
return false
}
4 changes: 4 additions & 0 deletions pkg/parser/oneinch/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,7 @@ func (p *Parser) decodeOutput(output string) (string, string, string, error) {
func (p *Parser) Exchange() string {
return parser.Ex1Inch
}

func (p *Parser) UseTraceCall() bool {
return true
}
4 changes: 4 additions & 0 deletions pkg/parser/oneinchv6/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,7 @@ func (p *Parser) decodeOutput(output string) (string, string, string, error) {
func (p *Parser) Exchange() string {
return parser.Ex1InchV6
}

func (p *Parser) UseTraceCall() bool {
return true
}
4 changes: 4 additions & 0 deletions pkg/parser/paraswap/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExParaswap
}

func (p *Parser) UseTraceCall() bool {
return false
}
1 change: 1 addition & 0 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ type Parser interface {
Parse(log types.Log, blockTime uint64) (storage.TradeLog, error)
Topics() []string
Exchange() string
UseTraceCall() bool
}
4 changes: 4 additions & 0 deletions pkg/parser/tokenlon/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error
func (p *Parser) Exchange() string {
return parser.ExTokenlon
}

func (p *Parser) UseTraceCall() bool {
return false
}
1 change: 1 addition & 0 deletions pkg/parser/uniswapx/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"contract IPermit2","name":"_permit2","type":"address"},{"internalType":"address","name":"_protocolFeeOwner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"DeadlineBeforeEndTime","type":"error"},{"inputs":[{"internalType":"address","name":"duplicateToken","type":"address"}],"name":"DuplicateFeeOutput","type":"error"},{"inputs":[],"name":"EndTimeBeforeStartTime","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"}],"name":"FeeTooLarge","type":"error"},{"inputs":[],"name":"IncorrectAmounts","type":"error"},{"inputs":[],"name":"InputAndOutputDecay","type":"error"},{"inputs":[],"name":"InsufficientEth","type":"error"},{"inputs":[],"name":"InvalidCosignature","type":"error"},{"inputs":[],"name":"InvalidCosignerInput","type":"error"},{"inputs":[],"name":"InvalidCosignerOutput","type":"error"},{"inputs":[{"internalType":"address","name":"feeToken","type":"address"}],"name":"InvalidFeeToken","type":"error"},{"inputs":[],"name":"InvalidReactor","type":"error"},{"inputs":[],"name":"NativeTransferFailed","type":"error"},{"inputs":[],"name":"NoExclusiveOverride","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"indexed":true,"internalType":"address","name":"filler","type":"address"},{"indexed":true,"internalType":"address","name":"swapper","type":"address"},{"indexed":false,"internalType":"uint256","name":"nonce","type":"uint256"}],"name":"Fill","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldFeeController","type":"address"},{"indexed":false,"internalType":"address","name":"newFeeController","type":"address"}],"name":"ProtocolFeeControllerSet","type":"event"},{"inputs":[{"components":[{"internalType":"bytes","name":"order","type":"bytes"},{"internalType":"bytes","name":"sig","type":"bytes"}],"internalType":"struct SignedOrder","name":"order","type":"tuple"}],"name":"execute","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"order","type":"bytes"},{"internalType":"bytes","name":"sig","type":"bytes"}],"internalType":"struct SignedOrder[]","name":"orders","type":"tuple[]"}],"name":"executeBatch","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"order","type":"bytes"},{"internalType":"bytes","name":"sig","type":"bytes"}],"internalType":"struct SignedOrder[]","name":"orders","type":"tuple[]"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"name":"executeBatchWithCallback","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"components":[{"internalType":"bytes","name":"order","type":"bytes"},{"internalType":"bytes","name":"sig","type":"bytes"}],"internalType":"struct SignedOrder","name":"order","type":"tuple"},{"internalType":"bytes","name":"callbackData","type":"bytes"}],"name":"executeWithCallback","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"feeController","outputs":[{"internalType":"contract IProtocolFeeController","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"permit2","outputs":[{"internalType":"contract IPermit2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newFeeController","type":"address"}],"name":"setProtocolFeeController","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
1 change: 1 addition & 0 deletions pkg/parser/uniswapx/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abigen --abi=abi.json --pkg=uniswapx --out=uniswapx.go
Loading

0 comments on commit d20cda0

Please sign in to comment.