Skip to content

Commit

Permalink
wrap oracle client to feed timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Aug 2, 2024
1 parent febea5f commit 0931e72
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions app/slinky.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

0 comments on commit 0931e72

Please sign in to comment.