Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TimmyExogenous committed Oct 15, 2024
2 parents e7c1d3f + 2b7a55c commit 39902dd
Show file tree
Hide file tree
Showing 12 changed files with 870 additions and 143 deletions.
4 changes: 4 additions & 0 deletions cmd/exocored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
evmoskr "github.com/evmos/evmos/v16/crypto/keyring"

pricefeeder "github.com/ExocoreNetwork/price-feeder/external"
feedertypes "github.com/ExocoreNetwork/price-feeder/types"
)

const (
Expand Down Expand Up @@ -154,6 +155,9 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
defer func() {
if err := recover(); err != nil {
fmt.Println("price-feeder failed", err)
if e, ok := err.(error); ok && errors.Is(e, feedertypes.ErrInitFail) {
panic(e)
}
}
}()
mnemonic, _ := cmd.Flags().GetString(flagMnemonic)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
cosmossdk.io/math v1.2.0
cosmossdk.io/simapp v0.0.0-20230608160436-666c345ad23d
cosmossdk.io/tools/rosetta v0.2.1
github.com/ExocoreNetwork/price-feeder v0.1.9
github.com/ExocoreNetwork/price-feeder v0.0.0-20241009094357-40e58e6f1694
github.com/agiledragon/gomonkey/v2 v2.11.0
github.com/armon/go-metrics v0.4.1
github.com/cometbft/cometbft v0.37.4
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ github.com/ChainSafe/go-schnorrkel v1.0.0/go.mod h1:dpzHYVxLZcp8pjlV+O+UR8K0Hp/z
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/ExocoreNetwork/evmos/v16 v16.0.3-0.20240828081344-d5cfcd34a812 h1:4P/4GZ89DOy9uNPDlEwebPytKltbimq8wn9XiuX96vw=
github.com/ExocoreNetwork/evmos/v16 v16.0.3-0.20240828081344-d5cfcd34a812/go.mod h1:w0vtRYI4I0/O8eihq6ZuDvlca4ZiYCKN6vpakG9zHcc=
github.com/ExocoreNetwork/price-feeder v0.1.9 h1:1keqcZoYdW2XE+TQBYyStfUyLpNAbjgsw1grshdfPlQ=
github.com/ExocoreNetwork/price-feeder v0.1.9/go.mod h1:/6yLPrHdUdKyZaKeQ0MNpYq2cBlT58ZokPHlh8ARZ9g=
github.com/ExocoreNetwork/price-feeder v0.0.0-20241009094357-40e58e6f1694 h1:Qkm7hiwvp1WusBlOGZhPsRlzy1Yb6tXEeEZXo8W11JE=
github.com/ExocoreNetwork/price-feeder v0.0.0-20241009094357-40e58e6f1694/go.mod h1:CgVrnt5K1Yp8/y7Dz/UFU0g3B86Hx9DjJHHiQz2z0rY=
github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand Down
52 changes: 37 additions & 15 deletions proto/exocore/oracle/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,39 @@ option go_package = "github.com/ExocoreNetwork/exocore/x/oracle/types";

// Query defines the gRPC querier service.
service Query {
// stakerList shows all stakers related to the specified asset under native-restaking context
// TokenIndexes shows the map tells token and its index for further usage
rpc TokenIndexes(QueryTokenIndexesRequest) returns (QueryTokenIndexesResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/token_indexes";
}

// StakerList shows all stakers related to the specified asset under native-restaking context
rpc StakerList (QueryStakerListRequest) returns (QueryStakerListResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/staker_list";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/staker_list";
}

// StakerInfos shows the details for all stakers of the specified assets under native-restaking context
rpc StakerInfos (QueryStakerInfosRequest) returns (QueryStakerInfosResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/staker_infos/{asset_id}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/staker_infos/{asset_id}";
}

// StakerInfo shows the details for one staker required by input parsms of the specified asset
rpc StakerInfo (QueryStakerInfoRequest) returns (QueryStakerInfoResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/staker_info/{asset_id}/{staker_addr}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/staker_info/{asset_id}/{staker_addr}";
}


// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/params";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/params";
}

// Queries a list of Prices items.
rpc Prices(QueryGetPricesRequest) returns (QueryGetPricesResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/prices/{token_id}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/prices/{token_id}";
}

// Queries the latest price of a specific token
rpc LatestPrice(QueryGetLatestPriceRequest) returns (QueryGetLatestPriceResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/latest_price/{token_id}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/latest_price/{token_id}";
}

// rpc PricesAll (QueryAllPricesRequest) returns (QueryAllPricesResponse) {
Expand All @@ -57,40 +61,58 @@ service Query {

// Queries a ValidatorUpdateBlock by index.
rpc ValidatorUpdateBlock(QueryGetValidatorUpdateBlockRequest) returns (QueryGetValidatorUpdateBlockResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/validator_update_block";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/validator_update_block";
}

// Queries a IndexRecentParams by index.
rpc IndexRecentParams(QueryGetIndexRecentParamsRequest) returns (QueryGetIndexRecentParamsResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/index_recent_params";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/index_recent_params";
}

// Queries a IndexRecentMsg by index.
rpc IndexRecentMsg(QueryGetIndexRecentMsgRequest) returns (QueryGetIndexRecentMsgResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/index_recent_msg";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/index_recent_msg";
}

// Queries a list of RecentMsg items.
rpc RecentMsg(QueryGetRecentMsgRequest) returns (QueryGetRecentMsgResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/recent_msg/{block}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/recent_msg/{block}";
}

// RecentMsgAll all RecentMsg items.
rpc RecentMsgAll(QueryAllRecentMsgRequest) returns (QueryAllRecentMsgResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/recent_msg";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/recent_msg";
}

// Queries a list of RecentParams items.
rpc RecentParams(QueryGetRecentParamsRequest) returns (QueryGetRecentParamsResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/recent_params/{block}";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/recent_params/{block}";
}

// RecentParamsAll query all RecentParams.
rpc RecentParamsAll(QueryAllRecentParamsRequest) returns (QueryAllRecentParamsResponse) {
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/recent_params";
option (google.api.http).get = "/ExocoreNetwork/exocore/oracle/v1/recent_params";
}
}

// TokenIndex is the pair of tokenName and its index defined in params
message TokenIndex {
// token name
string token = 1;
// the index registered in params.Token
uint64 index = 2;
}

// QueryTokenIndexsRequest is request type for Query/TokenIndexes RPC method
message QueryTokenIndexesRequest {}


// QueryTokenIndexesResponse is response type for Query/TokenIndexes RPC method
message QueryTokenIndexesResponse {
//token_indexes includes all the token-index mapping
repeated TokenIndex token_indexes = 1;
}

// QueryStakerListRequest is request type for Query/StakerList RPC method
message QueryStakerListRequest {
// id of assets for the staker list request for
Expand Down
1 change: 1 addition & 0 deletions x/oracle/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func GetQueryCmd(_ string) *cobra.Command {
cmd.AddCommand(CmdQueryStakerInfo())
cmd.AddCommand(CmdQueryStakerInfos())
cmd.AddCommand(CmdQueryStakerList())
cmd.AddCommand(CmdQueryTokenIndexes())
// this line is used by starport scaffolding # 1

return cmd
Expand Down
29 changes: 29 additions & 0 deletions x/oracle/client/cli/query_tokens.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cli

import (
"github.com/ExocoreNetwork/exocore/x/oracle/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/spf13/cobra"
)

func CmdQueryTokenIndexes() *cobra.Command {
cmd := &cobra.Command{
Use: "show-tokens",
Short: "shows the list of token-index mapping",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) (err error) {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.TokenIndexes(cmd.Context(), &types.QueryTokenIndexesRequest{})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
return cmd
}
4 changes: 4 additions & 0 deletions x/oracle/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (k Keeper) RegisterNewTokenAndSetTokenFeeder(ctx sdk.Context, oInfo *types.
if t.Name == oInfo.Token.Name && t.ChainID == chainID {
t.AssetID = strings.Join([]string{t.AssetID, oInfo.AssetID}, ",")
k.SetParams(ctx, p)
if !ctx.IsCheckTx() {
_ = GetAggregatorContext(ctx, k)
cs.AddCache(cache.ItemP(p))
}
// there should have been existing tokenFeeder running(currently we register tokens from assets-module and with infinite endBlock)
return nil
}
Expand Down
22 changes: 22 additions & 0 deletions x/oracle/keeper/query_tokens.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package keeper

import (
"context"

"github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (k Keeper) TokenIndexes(goCtx context.Context, req *types.QueryTokenIndexesRequest) (*types.QueryTokenIndexesResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
ret := k.GetTokens(ctx)
return &types.QueryTokenIndexesResponse{
TokenIndexes: ret,
}, nil
}
6 changes: 6 additions & 0 deletions x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext
if updated := c.GetCache(&pRet); !updated {
c.AddCache(cache.ItemP(*p))
}
// TODO: these 4 lines are mainly used for hot fix
// since the latest params stored in KV for recache should be the same with the latest params, so these lines are just duplicated actions if everything is fine.
*p = k.GetParams(ctx)
agc.SetParams(p)
setCommonParams(p)
c.AddCache(cache.ItemP(*p))

return true
}
Expand Down
19 changes: 19 additions & 0 deletions x/oracle/keeper/tokens.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package keeper

import (
"github.com/ExocoreNetwork/exocore/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// GetTokens returns a list of token-index mapping registered in params
func (k Keeper) GetTokens(ctx sdk.Context) []*types.TokenIndex {
params := k.GetParams(ctx)
ret := make([]*types.TokenIndex, 0, len(params.Tokens))
for idx, token := range params.Tokens {
ret = append(ret, &types.TokenIndex{
Token: token.Name,
Index: uint64(idx),
})
}
return ret
}
Loading

0 comments on commit 39902dd

Please sign in to comment.