Compare commits

...

6 Commits

6 changed files with 97 additions and 6 deletions

View File

@ -11,7 +11,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
handlerContainer := handler.New(cacheProvider)
router := router.New(pubCB)
router.RegisterContractCreationHandler(handler.HandleContractCreation())
router.RegisterContractCreationHandler(handler.HandleContractCreation(handlerContainer))
router.RegisterLogRoute(w3.H("0x26162814817e23ec5035d6a2edc6c422da2da2119e27cfca6be65cc2dc55ca4c"), handler.HandleFaucetGiveLog())
router.RegisterLogRoute(w3.H("0xa226db3f664042183ee0281230bba26cbf7b5057e50aee7f25a175ff45ce4d7f"), handler.HandleIndexAddLog(handlerContainer))
@ -27,6 +27,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
router.RegisterLogRoute(w3.H("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"), handler.HandleTokenTransferLog(handlerContainer))
router.RegisterLogRoute(w3.H("0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925"), handler.HandleTokenApproveLog(handlerContainer))
router.RegisterLogRoute(w3.H("0x5f7542858008eeb041631f30e6109ae94b83a58e9a58261dd2c42c508850f939"), handler.HandleTokenTransferFromLog(handlerContainer))
router.RegisterLogRoute(w3.H("0x06526a30af2ff868c2686df12e95844d8ae300416bbec5d5ccc2d2f4afdb17a0"), handler.HandleQuoterUpdatedLog())
router.RegisterInputDataRoute("63e4bff4", handler.HandleFaucetGiveInputData())
router.RegisterInputDataRoute("de82efb4", handler.HandleFaucetGiveInputData())
@ -44,6 +45,7 @@ func bootstrapEventRouter(cacheProvider cache.Cache, pubCB router.Callback) *rou
router.RegisterInputDataRoute("a9059cbb", handler.HandleTokenTransferInputData(handlerContainer))
router.RegisterInputDataRoute("23b872dd", handler.HandleTokenTransferInputData(handlerContainer))
router.RegisterInputDataRoute("095ea7b3", handler.HandleTokenApproveInputData(handlerContainer))
router.RegisterInputDataRoute("f912c64b", handler.HandleQuoterUpdatedInputData())
return router
}

View File

@ -10,6 +10,8 @@ db_type = "bolt"
# Tune max go routines that can process blocks
# Defaults to (nproc * 3)
pool_size = 0
batch_size = 100
[redis]
dsn = "127.0.0.1:6379"

View File

@ -22,8 +22,9 @@ func bootstrapCache(
lo *slog.Logger,
) error {
var (
tokenRegistryGetter = w3.MustNewFunc("tokenRegistry()", "address")
quoterGetter = w3.MustNewFunc("quoter()", "address")
tokenRegistryGetter = w3.MustNewFunc("tokenRegistry()", "address")
quoterGetter = w3.MustNewFunc("quoter()", "address")
systemAcccountGetter = w3.MustNewFunc("systemAccount()", "address")
)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
@ -46,6 +47,23 @@ func bootstrapCache(
}
}
if custodialRegistrationProxy := registryMap[ethutils.CustodialProxy]; custodialRegistrationProxy != ethutils.ZeroAddress {
var systemAccount common.Address
err := chain.Provider().Client.CallCtx(
ctx,
eth.CallFunc(custodialRegistrationProxy, systemAcccountGetter).Returns(&systemAccount),
)
if err != nil {
return err
}
if systemAccount != ethutils.ZeroAddress {
if err := cache.Add(ctx, systemAccount.Hex()); err != nil {
return err
}
lo.Debug("cached custodial system account", "address", systemAccount.Hex())
}
}
if accountIndex := registryMap[ethutils.AccountIndex]; accountIndex != ethutils.ZeroAddress {
if err := cache.Add(ctx, accountIndex.Hex()); err != nil {
return err
@ -103,7 +121,6 @@ func bootstrapCache(
if err := cache.Add(ctx, address.Hex()); err != nil {
return err
}
}
}
lo.Debug("cached token index batch", "batch_size", len(tokenIndexBatch))

View File

@ -9,7 +9,7 @@ import (
const contractCreationEventName = "CONTRACT_CREATION"
func HandleContractCreation() router.ContractCreationHandlerFunc {
func HandleContractCreation(hc *HandlerContainer) router.ContractCreationHandlerFunc {
return func(ctx context.Context, ccp router.ContractCreationPayload, c router.Callback) error {
contractCreationEvent := event.Event{
Block: ccp.Block,
@ -23,6 +23,10 @@ func HandleContractCreation() router.ContractCreationHandlerFunc {
},
}
if err := hc.cache.Add(ctx, ccp.ContractAddress); err != nil {
return err
}
return c(ctx, contractCreationEvent)
}
}

View File

@ -0,0 +1,66 @@
package handler
import (
"context"
"github.com/ethereum/go-ethereum/common"
"github.com/grassrootseconomics/eth-tracker/pkg/event"
"github.com/grassrootseconomics/eth-tracker/pkg/router"
"github.com/lmittmann/w3"
)
const quoterUpdatedEventName = "QUOTER_UPDATED"
var (
quoterUpdatedEvent = w3.MustNewEvent("QuoterUpdated(address indexed newQuoter)")
quoterUpdatedSig = w3.MustNewFunc("setQuoter(address)", "")
)
func HandleQuoterUpdatedLog() router.LogHandlerFunc {
return func(ctx context.Context, lp router.LogPayload, c router.Callback) error {
var newQuoter common.Address
if err := quoterUpdatedEvent.DecodeArgs(lp.Log, &newQuoter); err != nil {
return err
}
quoterUpdatedEvent := event.Event{
Index: lp.Log.Index,
Block: lp.Log.BlockNumber,
ContractAddress: lp.Log.Address.Hex(),
Success: true,
Timestamp: lp.Timestamp,
TxHash: lp.Log.TxHash.Hex(),
TxType: quoterUpdatedEventName,
Payload: map[string]any{
"newQuoter": newQuoter.Hex(),
},
}
return c(ctx, quoterUpdatedEvent)
}
}
func HandleQuoterUpdatedInputData() router.InputDataHandlerFunc {
return func(ctx context.Context, idp router.InputDataPayload, c router.Callback) error {
var newQuoter common.Address
if err := quoterUpdatedSig.DecodeArgs(w3.B(idp.InputData), &newQuoter); err != nil {
return err
}
quoterUpdatedEvent := event.Event{
Block: idp.Block,
ContractAddress: idp.ContractAddress,
Success: false,
Timestamp: idp.Timestamp,
TxHash: idp.TxHash,
TxType: quoterUpdatedEventName,
Payload: map[string]any{
"newQuoter": newQuoter.Hex(),
},
}
return c(ctx, quoterUpdatedEvent)
}
}

View File

@ -49,7 +49,7 @@ func NewJetStreamPub(o JetStreamOpts) (Pub, error) {
Subjects: streamSubjects,
MaxAge: o.PersistDuration,
Storage: jetstream.FileStorage,
Duplicates: time.Minute,
Duplicates: time.Minute * 20,
})
return &jetStreamPub{