Skip to content

Commit

Permalink
Merge pull request #4 from KyberNetwork/zxrfq
Browse files Browse the repository at this point in the history
zxrfq
  • Loading branch information
ductm54 authored Jan 11, 2023
2 parents dc9419e + 29ec64e commit 3a84bcb
Show file tree
Hide file tree
Showing 14 changed files with 1,086 additions and 2 deletions.
4 changes: 4 additions & 0 deletions cmd/tradelogs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import (
"github.com/KyberNetwork/tradelogs/internal/dbutil"
"github.com/KyberNetwork/tradelogs/internal/evmlistenerclient"
"github.com/KyberNetwork/tradelogs/internal/parser/kyberswap"
"github.com/KyberNetwork/tradelogs/internal/parser/tokenlon"
"github.com/KyberNetwork/tradelogs/internal/parser/zxotc"
"github.com/KyberNetwork/tradelogs/internal/parser/zxrfq"
"github.com/KyberNetwork/tradelogs/internal/server"
"github.com/KyberNetwork/tradelogs/internal/storage"
"github.com/KyberNetwork/tradelogs/internal/worker"
Expand Down Expand Up @@ -64,6 +66,8 @@ func run(c *cli.Context) error {
w, err := worker.New(l, s, listener,
kyberswap.MustNewParser(),
zxotc.MustNewParser(),
zxrfq.MustNewParser(),
tokenlon.MustNewParser(),
)
if err != nil {
l.Errorw("Error while init worker")
Expand Down
2 changes: 2 additions & 0 deletions internal/parser/kyberswap/kyberswap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

func TestFetchEvent(t *testing.T) {
t.Skip()
p := MustNewParser()
require.Equal(t, p.abi.Events[SwappedEvent].ID, common.HexToHash("0xd6d4f5681c246c9f42c203e287975af1601f8df8035a9251f79aab5c8f09e2f8"))
client, err := ethclient.Dial("https://mainnet.infura.io/v3/")
require.NoError(t, err)
logs, err := client.FilterLogs(context.Background(), ethereum.FilterQuery{
Expand Down
81 changes: 81 additions & 0 deletions internal/parser/tokenlon/abi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "source",
"type": "string"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "transactionHash",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "bytes32",
"name": "orderHash",
"type": "bytes32"
},
{
"indexed": true,
"internalType": "address",
"name": "userAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "takerAssetAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "takerAssetAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "makerAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "makerAssetAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "makerAssetAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "address",
"name": "receiverAddr",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "settleAmount",
"type": "uint256"
},
{
"indexed": false,
"internalType": "uint16",
"name": "feeFactor",
"type": "uint16"
}
],
"name": "FillOrder",
"type": "event"
}
]
1 change: 1 addition & 0 deletions internal/parser/tokenlon/gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
abigen --abi=abi.json --pkg=tokenlon --out=tokenlon.go -type FillOrder
73 changes: 73 additions & 0 deletions internal/parser/tokenlon/parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package tokenlon

import (
"errors"

"github.com/KyberNetwork/tradelogs/internal/storage"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

const (
FillOrderEvent = "FillOrder"
)

var ErrInvalidRFQTopic = errors.New("invalid RfqFilled topic")

type Parser struct {
abi *abi.ABI
ps *FillOrderFilterer
eventHash string
}

func MustNewParser() *Parser {
ps, err := NewFillOrderFilterer(common.Address{}, nil)
if err != nil {
panic(err)
}
ab, err := FillOrderMetaData.GetAbi()
if err != nil {
panic(err)
}
event, ok := ab.Events[FillOrderEvent]
if !ok {
panic("no such event: FillOrder")
}
return &Parser{
ps: ps,
abi: ab,
eventHash: event.ID.String(),
}
}

func (p *Parser) Topics() []string {
return []string{
p.eventHash,
}
}

func (p *Parser) Parse(log types.Log, blockTime uint64) (storage.TradeLog, error) {
if len(log.Topics) > 0 && log.Topics[0].Hex() != p.eventHash {
return storage.TradeLog{}, ErrInvalidRFQTopic
}
o, err := p.ps.ParseFillOrder(log)
if err != nil {
return storage.TradeLog{}, err
}
res := storage.TradeLog{
OrderHash: common.Hash(o.OrderHash).String(),
Maker: o.MakerAddr.Hex(),
Taker: o.ReceiverAddr.Hex(),
MakerToken: o.MakerAssetAddr.Hex(),
TakerToken: o.TakerAssetAddr.Hex(),
MakerTokenAmount: o.MakerAssetAmount.String(),
TakerTokenAmount: o.SettleAmount.String(),
ContractAddress: o.Raw.Address.String(),
BlockNumber: o.Raw.BlockNumber,
TxHash: o.Raw.TxHash.String(),
LogIndex: uint64(o.Raw.Index),
Timestamp: blockTime * 1000,
}
return res, nil
}
Loading

0 comments on commit 3a84bcb

Please sign in to comment.