mirror of
https://github.com/grassrootseconomics/eth-tracker.git
synced 2026-05-17 02:15:19 +02:00
release: v1.0.0
This commit is contained in:
112
internal/handler/faucet_give.go
Normal file
112
internal/handler/faucet_give.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/celoutils/v3"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type faucetGiveHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const faucetGiveEventName = "FAUCET_GIVE"
|
||||
|
||||
var (
|
||||
faucetGiveTopicHash = w3.H("0x26162814817e23ec5035d6a2edc6c422da2da2119e27cfca6be65cc2dc55ca4c")
|
||||
faucetGiveEvent = w3.MustNewEvent("Give(address indexed _recipient, address indexed _token, uint256 _amount)")
|
||||
faucetGiveToSig = w3.MustNewFunc("giveTo(address)", "uint256")
|
||||
faucetGimmeSig = w3.MustNewFunc("gimme()", "uint256")
|
||||
)
|
||||
|
||||
func NewFaucetGiveHandler(pub pub.Pub) *faucetGiveHandler {
|
||||
return &faucetGiveHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *faucetGiveHandler) Name() string {
|
||||
return faucetGiveEventName
|
||||
}
|
||||
|
||||
func (h *faucetGiveHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == faucetGiveTopicHash {
|
||||
var (
|
||||
recipient common.Address
|
||||
token common.Address
|
||||
amount big.Int
|
||||
)
|
||||
|
||||
if err := faucetGiveEvent.DecodeArgs(msg.Log, &recipient, &token, &amount); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
faucetGiveEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: faucetGiveEventName,
|
||||
Payload: map[string]any{
|
||||
"recipient": recipient.Hex(),
|
||||
"token": token.Hex(),
|
||||
"amount": amount.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, faucetGiveEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *faucetGiveHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
faucetGiveEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: faucetGiveEventName,
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "63e4bff4":
|
||||
var to common.Address
|
||||
|
||||
if err := faucetGiveToSig.DecodeArgs(w3.B(msg.InputData), &to); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
faucetGiveEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"recipient": to.Hex(),
|
||||
"token": celoutils.ZeroAddress,
|
||||
"amount": "0",
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, faucetGiveEvent)
|
||||
case "de82efb4":
|
||||
faucetGiveEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"recipient": celoutils.ZeroAddress,
|
||||
"token": celoutils.ZeroAddress,
|
||||
"amount": "0",
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, faucetGiveEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
50
internal/handler/handler.go
Normal file
50
internal/handler/handler.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/core/types"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
)
|
||||
|
||||
type (
|
||||
Handler interface {
|
||||
Name() string
|
||||
HandleLog(context.Context, LogMessage) error
|
||||
HandleRevert(context.Context, RevertMessage) error
|
||||
}
|
||||
|
||||
HandlerPipeline []Handler
|
||||
|
||||
LogMessage struct {
|
||||
Log *types.Log
|
||||
Timestamp uint64
|
||||
}
|
||||
|
||||
RevertMessage struct {
|
||||
From string
|
||||
RevertReason string
|
||||
InputData string
|
||||
Block uint64
|
||||
ContractAddress string
|
||||
Timestamp uint64
|
||||
TxHash string
|
||||
}
|
||||
)
|
||||
|
||||
func New(pub pub.Pub, cache cache.Cache) HandlerPipeline {
|
||||
return []Handler{
|
||||
NewTokenTransferHandler(pub),
|
||||
NewPoolSwapHandler(pub),
|
||||
NewFaucetGiveHandler(pub),
|
||||
NewPoolDepositHandler(pub),
|
||||
NewTokenMintHandler(pub),
|
||||
NewTokenBurnHandler(pub),
|
||||
NewQuoterPriceHandler(pub),
|
||||
NewOwnershipHandler(pub),
|
||||
NewSealHandler(pub),
|
||||
NewIndexAddHandler(pub, cache),
|
||||
NewIndexRemoveHandler(pub, cache),
|
||||
}
|
||||
}
|
||||
113
internal/handler/index_add.go
Normal file
113
internal/handler/index_add.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type indexAddHandler struct {
|
||||
pub pub.Pub
|
||||
cache cache.Cache
|
||||
}
|
||||
|
||||
const indexAddEventName = "INDEX_ADD"
|
||||
|
||||
var (
|
||||
indexAddTopicHash = w3.H("0xa226db3f664042183ee0281230bba26cbf7b5057e50aee7f25a175ff45ce4d7f")
|
||||
indexAddEvent = w3.MustNewEvent("AddressAdded(address _token)")
|
||||
indexAddSig = w3.MustNewFunc("add(address)", "bool")
|
||||
indexRegisterSig = w3.MustNewFunc("register(address)", "bool")
|
||||
)
|
||||
|
||||
func NewIndexAddHandler(pub pub.Pub, cache cache.Cache) *indexAddHandler {
|
||||
return &indexAddHandler{
|
||||
pub: pub,
|
||||
cache: cache,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *indexAddHandler) Name() string {
|
||||
return indexAddEventName
|
||||
}
|
||||
|
||||
func (h *indexAddHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == indexAddTopicHash {
|
||||
var address common.Address
|
||||
|
||||
if err := indexAddEvent.DecodeArgs(msg.Log, &address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
indexAddEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: indexAddEventName,
|
||||
Payload: map[string]any{
|
||||
"address": address.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
if h.cache.IsWatchableIndex(address.Hex()) {
|
||||
h.cache.Add(address.Hex(), false)
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, indexAddEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *indexAddHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
indexAddEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: indexAddEventName,
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "0a3b0a4f":
|
||||
var address common.Address
|
||||
|
||||
indexAddEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"address": address.Hex(),
|
||||
}
|
||||
|
||||
if err := indexAddSig.DecodeArgs(w3.B(msg.InputData), &address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, indexAddEvent)
|
||||
case "4420e486":
|
||||
var address common.Address
|
||||
|
||||
indexAddEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"address": address.Hex(),
|
||||
}
|
||||
|
||||
if err := indexRegisterSig.DecodeArgs(w3.B(msg.InputData), &address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, indexAddEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
98
internal/handler/index_remove.go
Normal file
98
internal/handler/index_remove.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/cache"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type indexRemoveHandler struct {
|
||||
pub pub.Pub
|
||||
cache cache.Cache
|
||||
}
|
||||
|
||||
const indexRemoveEventName = "INDEX_REMOVE"
|
||||
|
||||
var (
|
||||
indexRemoveTopicHash = w3.H("0x24a12366c02e13fe4a9e03d86a8952e85bb74a456c16e4a18b6d8295700b74bb")
|
||||
indexRemoveEvent = w3.MustNewEvent("AddressRemoved(address _token)")
|
||||
indexRemoveSig = w3.MustNewFunc("remove(address)", "bool")
|
||||
)
|
||||
|
||||
func NewIndexRemoveHandler(pub pub.Pub, cache cache.Cache) *indexRemoveHandler {
|
||||
return &indexRemoveHandler{
|
||||
pub: pub,
|
||||
cache: cache,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *indexRemoveHandler) Name() string {
|
||||
return indexRemoveEventName
|
||||
}
|
||||
|
||||
func (h *indexRemoveHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == indexRemoveTopicHash {
|
||||
var address common.Address
|
||||
|
||||
if err := indexRemoveEvent.DecodeArgs(msg.Log, &address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
indexRemoveEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: indexRemoveEventName,
|
||||
Payload: map[string]any{
|
||||
"address": address.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
if h.cache.IsWatchableIndex(address.Hex()) {
|
||||
h.cache.Remove(address.Hex())
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, indexRemoveEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *indexRemoveHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "29092d0e":
|
||||
var address common.Address
|
||||
|
||||
if err := indexRemoveSig.DecodeArgs(w3.B(msg.InputData), &address); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
indexRemoveEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: indexRemoveEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"address": address.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, indexRemoveEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
98
internal/handler/ownership.go
Normal file
98
internal/handler/ownership.go
Normal file
@@ -0,0 +1,98 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type ownershipHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const (
|
||||
ownershipEventName = "OWNERSHIP_TRANSFERRED"
|
||||
)
|
||||
|
||||
var (
|
||||
ownershipTopicHash = w3.H("0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0")
|
||||
ownershipEvent = w3.MustNewEvent("OwnershipTransferred(address indexed previousOwner, address indexed newOwner)")
|
||||
ownershipToSig = w3.MustNewFunc("transferOwnership(address)", "bool")
|
||||
)
|
||||
|
||||
func NewOwnershipHandler(pub pub.Pub) *ownershipHandler {
|
||||
return &ownershipHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *ownershipHandler) Name() string {
|
||||
return ownershipEventName
|
||||
}
|
||||
|
||||
func (h *ownershipHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == ownershipTopicHash {
|
||||
var (
|
||||
previousOwner common.Address
|
||||
newOwner common.Address
|
||||
)
|
||||
|
||||
if err := ownershipEvent.DecodeArgs(msg.Log, &previousOwner, &newOwner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ownershipEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: ownershipEventName,
|
||||
Payload: map[string]any{
|
||||
"previousOwner": previousOwner.Hex(),
|
||||
"newOwner": newOwner.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, ownershipEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *ownershipHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "f2fde38b":
|
||||
var newOwner common.Address
|
||||
|
||||
if err := ownershipToSig.DecodeArgs(w3.B(msg.InputData), &newOwner); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
ownershipEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: ownershipEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"previousOwner": msg.From,
|
||||
"newOwner": newOwner.Hex(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, ownershipEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
108
internal/handler/pool_deposit.go
Normal file
108
internal/handler/pool_deposit.go
Normal file
@@ -0,0 +1,108 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type poolDepositHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const poolDepositEventName = "POOL_DEPOSIT"
|
||||
|
||||
var (
|
||||
poolDepositTopicHash = w3.H("0x5548c837ab068cf56a2c2479df0882a4922fd203edb7517321831d95078c5f62")
|
||||
poolDepositEvent = w3.MustNewEvent("Deposit(address indexed initiator, address indexed tokenIn, uint256 amountIn)")
|
||||
poolDepositSig = w3.MustNewFunc("deposit(address, uint256)", "")
|
||||
)
|
||||
|
||||
func NewPoolDepositHandler(pub pub.Pub) *poolDepositHandler {
|
||||
return &poolDepositHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *poolDepositHandler) Name() string {
|
||||
return poolDepositEventName
|
||||
}
|
||||
|
||||
func (h *poolDepositHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == poolDepositTopicHash {
|
||||
var (
|
||||
initiator common.Address
|
||||
tokenIn common.Address
|
||||
amountIn big.Int
|
||||
)
|
||||
|
||||
if err := poolDepositEvent.DecodeArgs(
|
||||
msg.Log,
|
||||
&initiator,
|
||||
&tokenIn,
|
||||
&amountIn,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
poolDepositEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: poolDepositEventName,
|
||||
Payload: map[string]any{
|
||||
"initiator": initiator.Hex(),
|
||||
"tokenIn": tokenIn.Hex(),
|
||||
"amountIn": amountIn.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, poolDepositEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *poolDepositHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "47e7ef24":
|
||||
var (
|
||||
tokenIn common.Address
|
||||
amountIn big.Int
|
||||
)
|
||||
|
||||
if err := poolDepositSig.DecodeArgs(w3.B(msg.InputData), &tokenIn, &amountIn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
poolDepositEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: poolDepositEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"initiator": msg.From,
|
||||
"tokenIn": tokenIn.Hex(),
|
||||
"amountIn": amountIn.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, poolDepositEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
121
internal/handler/pool_swap.go
Normal file
121
internal/handler/pool_swap.go
Normal file
@@ -0,0 +1,121 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type poolSwapHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const poolSwapEventName = "POOL_SWAP"
|
||||
|
||||
var (
|
||||
poolSwapTopicHash = w3.H("0xd6d34547c69c5ee3d2667625c188acf1006abb93e0ee7cf03925c67cf7760413")
|
||||
poolSwapEvent = w3.MustNewEvent("Swap(address indexed initiator, address indexed tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut, uint256 fee)")
|
||||
poolSwapSig = w3.MustNewFunc("withdraw(address, address, uint256)", "")
|
||||
)
|
||||
|
||||
func NewPoolSwapHandler(pub pub.Pub) *poolSwapHandler {
|
||||
return &poolSwapHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *poolSwapHandler) Name() string {
|
||||
return poolSwapEventName
|
||||
}
|
||||
|
||||
func (h *poolSwapHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == poolSwapTopicHash {
|
||||
var (
|
||||
initiator common.Address
|
||||
tokenIn common.Address
|
||||
tokenOut common.Address
|
||||
amountIn big.Int
|
||||
amountOut big.Int
|
||||
fee big.Int
|
||||
)
|
||||
|
||||
if err := poolSwapEvent.DecodeArgs(
|
||||
msg.Log,
|
||||
&initiator,
|
||||
&tokenIn,
|
||||
&tokenOut,
|
||||
&amountIn,
|
||||
&amountOut,
|
||||
&fee,
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
poolSwapEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: poolSwapEventName,
|
||||
Payload: map[string]any{
|
||||
"initiator": initiator.Hex(),
|
||||
"tokenIn": tokenIn.Hex(),
|
||||
"tokenOut": tokenOut.Hex(),
|
||||
"amountIn": amountIn.String(),
|
||||
"amountOut": amountOut.String(),
|
||||
"fee": fee.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, poolSwapEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *poolSwapHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "d9caed12":
|
||||
var (
|
||||
tokenOut common.Address
|
||||
tokenIn common.Address
|
||||
amountIn big.Int
|
||||
)
|
||||
|
||||
if err := poolSwapSig.DecodeArgs(w3.B(msg.InputData), &tokenOut, &tokenIn, &amountIn); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
poolSwapEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: poolSwapEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"initiator": msg.From,
|
||||
"tokenIn": tokenIn.Hex(),
|
||||
"tokenOut": tokenOut.Hex(),
|
||||
"amountIn": amountIn.String(),
|
||||
"amountOut": "0",
|
||||
"fee": "0",
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, poolSwapEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
100
internal/handler/quoter_price.go
Normal file
100
internal/handler/quoter_price.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type quoterPriceHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const quoterPriceEventName = "QUOTER_PRICE_INDEX_UPDATED"
|
||||
|
||||
var (
|
||||
quoterPriceTopicHash = w3.H("0xdb9ce1a76955721ca61ac50cd1b87f9ab8620325c8619a62192c2dc7871d56b1")
|
||||
quoterPriceEvent = w3.MustNewEvent("PriceIndexUpdated(address _tokenAddress, uint256 _exchangeRate)")
|
||||
quoterPriceToSig = w3.MustNewFunc("setPriceIndexValue(address, uint256)", "uint256")
|
||||
)
|
||||
|
||||
func NewQuoterPriceHandler(pub pub.Pub) *quoterPriceHandler {
|
||||
return "erPriceHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *quoterPriceHandler) Name() string {
|
||||
return quoterPriceEventName
|
||||
}
|
||||
|
||||
func (h *quoterPriceHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == quoterPriceTopicHash {
|
||||
var (
|
||||
token common.Address
|
||||
exchangeRate big.Int
|
||||
)
|
||||
|
||||
if err := quoterPriceEvent.DecodeArgs(msg.Log, &token, &exchangeRate); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
quoterPriceEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: quoterPriceEventName,
|
||||
Payload: map[string]any{
|
||||
"token": token.Hex(),
|
||||
"exchangeRate": exchangeRate.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, quoterPriceEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *quoterPriceHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "ebc59dff":
|
||||
var (
|
||||
token common.Address
|
||||
exchangeRate big.Int
|
||||
)
|
||||
|
||||
if err := quoterPriceToSig.DecodeArgs(w3.B(msg.InputData), &token, &exchangeRate); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
quoterPriceEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: quoterPriceEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"token": token.Hex(),
|
||||
"exchangeRate": exchangeRate.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, quoterPriceEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
95
internal/handler/seal.go
Normal file
95
internal/handler/seal.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type sealHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const sealEventName = "SEAL_STATE_CHANGE"
|
||||
|
||||
var (
|
||||
sealTopicHash = w3.H("0x6b7e2e653f93b645d4ed7292d6429f96637084363e477c8aaea1a43ed13c284e")
|
||||
sealEvent = w3.MustNewEvent("SealStateChange(bool indexed _final, uint256 _sealState)")
|
||||
sealToSig = w3.MustNewFunc("seal(uint256)", "uint256")
|
||||
)
|
||||
|
||||
func NewSealHandler(pub pub.Pub) *sealHandler {
|
||||
return &sealHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *sealHandler) Name() string {
|
||||
return sealEventName
|
||||
}
|
||||
|
||||
func (h *sealHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == sealTopicHash {
|
||||
var (
|
||||
final bool
|
||||
sealState big.Int
|
||||
)
|
||||
|
||||
if err := sealEvent.DecodeArgs(msg.Log, &final, &sealState); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sealEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: sealEventName,
|
||||
Payload: map[string]any{
|
||||
"final": final,
|
||||
"sealState": sealState.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, sealEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *sealHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "86fe212d":
|
||||
var sealState big.Int
|
||||
|
||||
if err := sealToSig.DecodeArgs(w3.B(msg.InputData), &sealState); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sealEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: sealEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"sealState": sealState.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, sealEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
97
internal/handler/token_burn.go
Normal file
97
internal/handler/token_burn.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type tokenBurnHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const burnEventName = "TOKEN_BURN"
|
||||
|
||||
var (
|
||||
tokenBurnTopicHash = w3.H("0xcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca5")
|
||||
tokenBurnEvent = w3.MustNewEvent("tokenBurn(address indexed _tokenBurner, uint256 _value)")
|
||||
tokenBurnToSig = w3.MustNewFunc("tokenBurn(uint256)", "bool")
|
||||
)
|
||||
|
||||
func NewTokenBurnHandler(pub pub.Pub) *tokenBurnHandler {
|
||||
return &tokenBurnHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *tokenBurnHandler) Name() string {
|
||||
return burnEventName
|
||||
}
|
||||
|
||||
func (h *tokenBurnHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == tokenBurnTopicHash {
|
||||
var (
|
||||
tokenBurner common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenBurnEvent.DecodeArgs(msg.Log, &tokenBurner, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenBurnEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: burnEventName,
|
||||
Payload: map[string]any{
|
||||
"tokenBurner": tokenBurner.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenBurnEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *tokenBurnHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "42966c68":
|
||||
var value big.Int
|
||||
|
||||
if err := tokenBurnToSig.DecodeArgs(w3.B(msg.InputData), &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenBurnEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: burnEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"tokenBurner": msg.From,
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenBurnEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
103
internal/handler/token_mint.go
Normal file
103
internal/handler/token_mint.go
Normal file
@@ -0,0 +1,103 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type tokenMintHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const mintEventName = "TOKEN_MINT"
|
||||
|
||||
var (
|
||||
tokenMintTopicHash = w3.H("0xab8530f87dc9b59234c4623bf917212bb2536d647574c8e7e5da92c2ede0c9f8")
|
||||
tokenMintEvent = w3.MustNewEvent("Mint(address indexed _tokenMinter, address indexed _beneficiary, uint256 _value)")
|
||||
tokenMintToSig = w3.MustNewFunc("MintTo(address, uint256)", "bool")
|
||||
)
|
||||
|
||||
func NewTokenMintHandler(pub pub.Pub) *tokenMintHandler {
|
||||
return &tokenMintHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *tokenMintHandler) Name() string {
|
||||
return mintEventName
|
||||
}
|
||||
|
||||
func (h *tokenMintHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == tokenMintTopicHash {
|
||||
var (
|
||||
tokenMinter common.Address
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenMintEvent.DecodeArgs(msg.Log, &tokenMinter, &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenMintEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: mintEventName,
|
||||
Payload: map[string]any{
|
||||
"tokenMinter": tokenMinter.Hex(),
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenMintEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *tokenMintHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "449a52f8":
|
||||
var (
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenMintToSig.DecodeArgs(w3.B(msg.InputData), &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenMintEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: mintEventName,
|
||||
Payload: map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"tokenMinter": msg.From,
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenMintEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
124
internal/handler/token_transfer.go
Normal file
124
internal/handler/token_transfer.go
Normal file
@@ -0,0 +1,124 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/big"
|
||||
|
||||
"github.com/celo-org/celo-blockchain/common"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/event"
|
||||
"github.com/grassrootseconomics/celo-tracker/internal/pub"
|
||||
"github.com/grassrootseconomics/w3-celo"
|
||||
)
|
||||
|
||||
type tokenTransferHandler struct {
|
||||
pub pub.Pub
|
||||
}
|
||||
|
||||
const transferEventName = "TOKEN_TRANSFER"
|
||||
|
||||
var (
|
||||
tokenTransferTopicHash = w3.H("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
|
||||
tokenTransferEvent = w3.MustNewEvent("Transfer(address indexed _from, address indexed _to, uint256 _value)")
|
||||
tokenTransferSig = w3.MustNewFunc("transfer(address, uint256)", "bool")
|
||||
tokenTransferFromSig = w3.MustNewFunc("transferFrom(address, address, uint256)", "bool")
|
||||
)
|
||||
|
||||
func NewTokenTransferHandler(pub pub.Pub) *tokenTransferHandler {
|
||||
return &tokenTransferHandler{
|
||||
pub: pub,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *tokenTransferHandler) Name() string {
|
||||
return transferEventName
|
||||
}
|
||||
|
||||
func (h *tokenTransferHandler) HandleLog(ctx context.Context, msg LogMessage) error {
|
||||
if msg.Log.Topics[0] == tokenTransferTopicHash {
|
||||
var (
|
||||
from common.Address
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenTransferEvent.DecodeArgs(msg.Log, &from, &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenTransferEvent := event.Event{
|
||||
Index: msg.Log.Index,
|
||||
Block: msg.Log.BlockNumber,
|
||||
ContractAddress: msg.Log.Address.Hex(),
|
||||
Success: true,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.Log.TxHash.Hex(),
|
||||
TxType: transferEventName,
|
||||
Payload: map[string]any{
|
||||
"from": from.Hex(),
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
},
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenTransferEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (h *tokenTransferHandler) HandleRevert(ctx context.Context, msg RevertMessage) error {
|
||||
if len(msg.InputData) < 8 {
|
||||
return nil
|
||||
}
|
||||
|
||||
tokenTransferEvent := event.Event{
|
||||
Block: msg.Block,
|
||||
ContractAddress: msg.ContractAddress,
|
||||
Success: false,
|
||||
Timestamp: msg.Timestamp,
|
||||
TxHash: msg.TxHash,
|
||||
TxType: transferEventName,
|
||||
}
|
||||
|
||||
switch msg.InputData[:8] {
|
||||
case "a9059cbb":
|
||||
var (
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenTransferSig.DecodeArgs(w3.B(msg.InputData), &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenTransferEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"from": msg.From,
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenTransferEvent)
|
||||
case "23b872dd":
|
||||
var (
|
||||
from common.Address
|
||||
to common.Address
|
||||
value big.Int
|
||||
)
|
||||
|
||||
if err := tokenTransferFromSig.DecodeArgs(w3.B(msg.InputData), &from, &to, &value); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tokenTransferEvent.Payload = map[string]any{
|
||||
"revertReason": msg.RevertReason,
|
||||
"from": from.Hex(),
|
||||
"to": to.Hex(),
|
||||
"value": value.String(),
|
||||
}
|
||||
|
||||
return h.pub.Send(ctx, tokenTransferEvent)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user