From ef28ec129870297693c41b325564b0a1577a3561 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Thu, 3 Jul 2025 10:55:44 +0300 Subject: [PATCH] feat: add quoter updated handler --- cmd/service/router.go | 2 + internal/handler/quoter_updated.go | 66 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 internal/handler/quoter_updated.go diff --git a/cmd/service/router.go b/cmd/service/router.go index 200dacc..12c0c64 100644 --- a/cmd/service/router.go +++ b/cmd/service/router.go @@ -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 } diff --git a/internal/handler/quoter_updated.go b/internal/handler/quoter_updated.go new file mode 100644 index 0000000..195945e --- /dev/null +++ b/internal/handler/quoter_updated.go @@ -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) + } +}