Skip to content

Commit

Permalink
Handle Batch Orders for Uniswapx and PancakeSwap (#91)
Browse files Browse the repository at this point in the history
* handle batch orders for uniswapx and pancakeswap

* add unit test
  • Loading branch information
linhnt3400 authored Oct 29, 2024
1 parent 1b4e334 commit 1fc0b78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/parser/pancakeswap/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *Parser) detectRfqTrade(order storage.TradeLog) (storage.TradeLog, error
}

func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.CallFrame) (storage.TradeLog, error) {
for _, l := range call.Logs {
for i, l := range call.Logs {
if len(l.Topics) < 2 {
continue
}
Expand All @@ -185,7 +185,7 @@ func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.Cal
if !ok || len(inputOrders) == 0 {
continue
}
inputOrder = inputOrders[0]
inputOrder = inputOrders[i]
}
parsedOrder, err := p.orderArguments.Unpack(inputOrder.Order)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/parser/uniswapx/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (p *Parser) detectRfqTrade(order storage.TradeLog) (storage.TradeLog, error
}

func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.CallFrame) (storage.TradeLog, error) {
for _, l := range call.Logs {
for i, l := range call.Logs {
if len(l.Topics) < 2 {
continue
}
Expand All @@ -204,7 +204,7 @@ func (p *Parser) recursiveDetectRFQTrades(order storage.TradeLog, call types.Cal
if !ok || len(inputOrders) == 0 {
continue
}
inputOrder = inputOrders[0]
inputOrder = inputOrders[i]
}

parsedOrder, err := p.orderArguments.Unpack(inputOrder.Order)
Expand Down
28 changes: 28 additions & 0 deletions pkg/parser/uniswapx/uniswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,31 @@ func TestParseEvent(t *testing.T) {
require.Equal(t, log.Expiry, uint64(0x66fd5e45))
t.Log(log)
}

func TestParseBatchEvent(t *testing.T) {
t.Skip("Need to add the rpc url that enables the trace call JSON-RPC")
eventRaw := `[{"address":"0x00000011f84b9aa48e5f8aa8b9897600006289be","topics":["0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66","0x1d62255d2fd90374be846f2114e2540a8b80242c4f849fd6dfb58a316479e9ca","0x00000000000000000000000043ee35d5542f5b826fa92832bd97caff153675a8","0x0000000000000000000000002d2e4848fa164911f935e713c58a3ce251f95ddf"],"data":"0x046832f5aa4b6a391a75b577e69c7409cf31d676a3983732f7cce4a8100f4001","blockNumber":"0x1414756","transactionHash":"0xe2530de46bf952c22a0c094586b6c2408a6b4900f07488f838a76874bde6cbf7","transactionIndex":"0x15","blockHash":"0x81279855a5a4d20e4369dc27928e08d8076ff342c4af02710862672c853659e4","logIndex":"0xa7","removed":false},{"address":"0x00000011f84b9aa48e5f8aa8b9897600006289be","topics":["0x78ad7ec0e9f89e74012afa58738b6b661c024cb0fd185ee2f616c0a28924bd66","0x7a70f8eb7d8a241a9016a9bee57b5166fa1aab9bdfe22bdf2a08d32b0ac4dd13","0x00000000000000000000000043ee35d5542f5b826fa92832bd97caff153675a8","0x00000000000000000000000085e3d047e92feb7879c302b92b689d7538b34691"],"data":"0x0468321cf5cd8349ef1d43cbdc795973c2c38a7392e7bc6e246e42051702840f","blockNumber":"0x1414756","transactionHash":"0xe2530de46bf952c22a0c094586b6c2408a6b4900f07488f838a76874bde6cbf7","transactionIndex":"0x15","blockHash":"0x81279855a5a4d20e4369dc27928e08d8076ff342c4af02710862672c853659e4","logIndex":"0xa8","removed":false}]`
var events []types.Log
err := json.Unmarshal([]byte(eventRaw), &events)
require.NoError(t, err)
ethClient, err := ethclient.Dial(rpcURL)
if err != nil {
panic(err)
}
block, err := ethClient.BlockByHash(context.Background(), events[0].BlockHash)
require.NoError(t, err)
traceCalls := tracecall.NewCache(rpcnode.NewClient(zap.S(), ethClient))
p := MustNewParser(traceCalls)
for _, e := range events {
log, err := p.Parse(e, block.Time())
require.NoError(t, err)
require.Equal(t, log.EventHash, p.eventHash)
t.Log("maker", log.Maker)
t.Log("maker_token", log.MakerToken)
t.Log("taker", log.Taker)
t.Log("taker_token", log.TakerToken)
t.Log("maker_amount", log.MakerTokenAmount)
t.Log("taker_amount", log.TakerTokenAmount)
t.Log("------------------------")
}
}

0 comments on commit 1fc0b78

Please sign in to comment.