From 0931e72ef8b2b579e1193d69b4e3cd22ec51218c Mon Sep 17 00:00:00 2001 From: beer-1 <147697694+beer-1@users.noreply.github.com> Date: Fri, 2 Aug 2024 14:08:58 +0900 Subject: [PATCH] wrap oracle client to feed timestamp --- app/slinky.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/app/slinky.go b/app/slinky.go index 315385a9..7ace344a 100644 --- a/app/slinky.go +++ b/app/slinky.go @@ -1,16 +1,15 @@ package app import ( + "context" + "strconv" "time" sdk "github.com/cosmos/cosmos-sdk/types" - - // this line is used by starport scaffolding # stargate/app/moduleImport + grpc "google.golang.org/grpc" stakingkeeper "github.com/initia-labs/initia/x/mstaking/keeper" - // block-sdk dependencies - // slinky oracle dependencies oraclepreblock "github.com/skip-mev/slinky/abci/preblock/oracle" oracleproposals "github.com/skip-mev/slinky/abci/proposals" @@ -22,9 +21,10 @@ import ( "github.com/skip-mev/slinky/pkg/math/voteweighted" oracleclient "github.com/skip-mev/slinky/service/clients/oracle" servicemetrics "github.com/skip-mev/slinky/service/metrics" + oracleservertypes "github.com/skip-mev/slinky/service/servers/oracle/types" - // unnamed import of statik for swagger UI support - _ "github.com/initia-labs/initia/client/docs/statik" + // OPinit dependencies + l2slinky "github.com/initia-labs/OPinit/x/opchild/l2slinky" ) func setupSlinky( @@ -58,6 +58,9 @@ func setupSlinky( return nil, nil, nil, nil, nil, nil, err } + // wrap oracle client to feed timestamp + oracleClient = withTimestamp(oracleClient) + oracleProposalHandler := oracleproposals.NewProposalHandler( app.Logger(), prepareProposalHandler, @@ -144,3 +147,24 @@ func setupSlinky( return oracleClient, prepareProposalHandler, processProposalHandler, preBlocker, extendedVoteHandler, verifyVoteExtensionHandler, nil } + +// oracleClientWithTimestamp is oracle client to feed timestamp +type oracleClientWithTimestamp struct { + oracleclient.OracleClient +} + +// wrap oracle client with timestamp feeder +func withTimestamp(oc oracleclient.OracleClient) oracleclient.OracleClient { + return oracleClientWithTimestamp{oc} +} + +// Prices defines a method for fetching the latest prices. +func (oc oracleClientWithTimestamp) Prices(ctx context.Context, req *oracleservertypes.QueryPricesRequest, opts ...grpc.CallOption) (*oracleservertypes.QueryPricesResponse, error) { + resp, err := oc.OracleClient.Prices(ctx, req, grpc.WaitForReady(true)) + if err != nil { + return nil, err + } + + resp.Prices[l2slinky.ReservedCPTimestamp] = strconv.FormatInt(resp.Timestamp.UTC().UnixNano(), 10) + return resp, err +}