Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operator): Add cli to query opt info #216

Merged
merged 22 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
643a0ea
detail the return error for operator info
TimmyExogenous Sep 5, 2024
50ed377
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 6, 2024
eb69bbd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 10, 2024
b75ee4d
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 10, 2024
ae24f6b
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 11, 2024
ff65b01
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 17, 2024
d5660be
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 19, 2024
063417a
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 20, 2024
7009f0c
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 20, 2024
dac10ab
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 23, 2024
3b58f4e
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
686a808
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
27fac4f
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 24, 2024
66bbf7e
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 25, 2024
7174462
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 26, 2024
02d2eb2
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Sep 29, 2024
b129fff
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 8, 2024
bdef6f0
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 10, 2024
34299cd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 12, 2024
e7c1d3f
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 14, 2024
39902dd
Merge remote-tracking branch 'upstream/develop' into develop
TimmyExogenous Oct 15, 2024
fceeed9
add a cli to query the opted info for specified operator and avs
TimmyExogenous Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
LOCAL_ADDRESS_HEX=0x$(exocored keys parse "$LOCAL_ADDRESS_EXO" --output json | jq -r .bytes | tr '[:upper:]' '[:lower:]')
CONSENSUS_KEY=$(exocored keys consensus-pubkey-to-bytes --keyring-backend "$KEYRING" --home "$HOMEDIR" --output json | jq -r .bytes32)

echo "the local operator address is $LOCAL_ADDRESS_EXO"
echo "the dogfood AVS address is $AVS_ADDRESS"

# Change parameter token denominations to hua
jq '.app_state["crisis"]["constant_fee"]["denom"]="hua"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="hua"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
Expand Down
39 changes: 29 additions & 10 deletions proto/exocore/operator/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
syntax = "proto3";

Check failure on line 1 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Previously present message "OperatorAVSAddressDetails" was deleted from file.
package exocore.operator.v1;

import "cosmos/base/query/v1beta1/pagination.proto";
Expand Down Expand Up @@ -31,24 +31,24 @@
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// OperatorAVSAddressDetails includes the address of operator and AVS
message OperatorAVSAddressDetails {
// OperatorAVSAddress includes the address of operator and AVS
message OperatorAVSAddress {
// operator_addr should be the string type of sdk.AccAddress
string operator_addr = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// avs_address is the address of the AVS - either an 0x address or a chainID.
string avs_address = 2 [(gogoproto.customname) = "AVSAddress"];
string avs_address = 2;
}

// QueryOperatorUSDValueRequest is the request to obtain the USD value for operator.
message QueryOperatorUSDValueRequest {
// details is the operator and AVS address
OperatorAVSAddressDetails details = 1;
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];;

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" with name "operator_and_avs" on message "QueryOperatorUSDValueRequest" changed option "json_name" from "details" to "operatorAndAvs".

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorUSDValueRequest" changed type from "exocore.operator.v1.OperatorAVSAddressDetails" to "exocore.operator.v1.OperatorAVSAddress".

Check failure on line 45 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorUSDValueRequest" changed name from "details" to "operator_and_avs".
}

// QueryOperatorUSDValueResponse is the response to obtain the USD value for operator.
message QueryOperatorUSDValueResponse {
// usd_info includes the self and total staking for the operator and AVS
OperatorOptedUSDValue usd_values = 1
OperatorOptedUSDValue usd_values = 1
[(gogoproto.customname) = "USDValues"];
}

Expand All @@ -62,8 +62,8 @@
// QueryOperatorSlashInfoRequest is the request to obtain the slash information for the specified
// operator and AVS
message QueryOperatorSlashInfoRequest {
// details is the operator and AVS address
OperatorAVSAddressDetails details = 1;
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" with name "operator_and_avs" on message "QueryOperatorSlashInfoRequest" changed option "json_name" from "details" to "operatorAndAvs".

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorSlashInfoRequest" changed type from "exocore.operator.v1.OperatorAVSAddressDetails" to "exocore.operator.v1.OperatorAVSAddress".

Check failure on line 66 in proto/exocore/operator/v1/query.proto

View workflow job for this annotation

GitHub Actions / break-check

Field "1" on message "QueryOperatorSlashInfoRequest" changed name from "details" to "operator_and_avs".
// pagination related options.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
Expand Down Expand Up @@ -213,6 +213,14 @@
// avs_list is a list of avs addresses .
repeated string avs_list = 1;
}

// QueryOptInfoRequest is the request to obtain the opted information of specified operator
// and AVS
message QueryOptInfoRequest {
// operator_and_avs is the operator and AVS address
OperatorAVSAddress operator_and_avs = 1 [(gogoproto.embed) = true];
}

// Query defines the gRPC querier service.
service Query {
// QueryOperatorInfo queries the operator information.
Expand Down Expand Up @@ -257,7 +265,9 @@

// QueryOperatorUSDValue queries the opted-in USD value for the operator
rpc QueryOperatorUSDValue(QueryOperatorUSDValueRequest) returns(QueryOperatorUSDValueResponse){
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorUSDValue";
option (google.api.http).get =
"/exocore/operator/v1/QueryOperatorUSDValue/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAVSUSDValue queries the USD value for the AVS
Expand All @@ -267,7 +277,9 @@

// QueryOperatorSlashInfo queries the slash information for the specified operator and AVS
rpc QueryOperatorSlashInfo(QueryOperatorSlashInfoRequest) returns(QueryOperatorSlashInfoResponse){
option (google.api.http).get = "/exocore/operator/v1/QueryOperatorSlashInfo";
option (google.api.http).get =
"/exocore/operator/v1/QueryOperatorSlashInfo/{operator_and_avs.operator_addr}/"
"{operator_and_avs.avs_address}";
}

// QueryAllOperatorConsAddrsByChainID queries all operators and their consensus addresses
Expand All @@ -294,4 +306,11 @@
get: "/exocore/operator/v1/opt/avs_list/{operator}"
};
}

// QueryOptInfo queries specified opted information.
rpc QueryOptInfo(QueryOptInfoRequest) returns (OptedInfo) {
option (google.api.http) = {
get: "/exocore/operator/v1/opt_info/{operator_and_avs.operator_addr}/{operator_and_avs.avs_address}"
};
}
}
115 changes: 78 additions & 37 deletions x/operator/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cli

import (
"context"
"strings"

"github.com/ExocoreNetwork/exocore/x/avs/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -15,6 +16,30 @@ import (
"github.com/spf13/cobra"
)

type GenericQueryParams struct {
queryClient operatortypes.QueryClient
clientCtx client.Context
}

func ValidOperatorAVSAddr(cmd *cobra.Command, originalOperatorAddr, originalAVSAddr string) (*operatortypes.OperatorAVSAddress, *GenericQueryParams, error) {
_, err := sdk.AccAddressFromBech32(originalOperatorAddr)
if err != nil {
return nil, nil, xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
if !common.IsHexAddress(originalAVSAddr) {
return nil, nil, xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return nil, nil, err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
return &operatortypes.OperatorAVSAddress{
OperatorAddr: originalOperatorAddr,
AvsAddress: strings.ToLower(originalAVSAddr),
}, &GenericQueryParams{queryClient: queryClient, clientCtx: clientCtx}, nil
}

// GetQueryCmd returns the parent command for all incentives CLI query commands.
func GetQueryCmd() *cobra.Command {
cmd := &cobra.Command{
Expand All @@ -37,6 +62,7 @@ func GetQueryCmd() *cobra.Command {
QueryOperatorSlashInfo(),
QueryAllOperatorsWithOptInAVS(),
QueryAllAVSsByOperator(),
GetOptInfo(),
)
return cmd
}
Expand Down Expand Up @@ -251,31 +277,23 @@ func GetAllOperatorConsAddrs() *cobra.Command {
// QueryOperatorUSDValue queries the opted-in USD value for the operator
func QueryOperatorUSDValue() *cobra.Command {
cmd := &cobra.Command{
Use: "QueryOperatorUSDValue <operatorAddr> <avsAddr>",
Short: "Get the opted-in USD value for the operator",
Long: "Get the opted-in USD value for the operator",
Args: cobra.ExactArgs(2),
Use: "QueryOperatorUSDValue <operatorAddr> <avsAddr>",
Short: "Get the opted-in USD value",
Long: "Get the opted-in USD value for the operator",
Example: "exocored query operator QueryOperatorUSDValue exo1c5x7mxphvgavjhu0au9jjqnfqcyspevtyy27mz 0xaa089ba103f765fcea44808bd3d4073523254c57",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
_, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
clientCtx, err := client.GetClientQueryContext(cmd)
validOperatorAVSAddr, genericQueryParams, err := ValidOperatorAVSAddr(cmd, args[0], args[1])
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryOperatorUSDValueRequest{
Details: &operatortypes.OperatorAVSAddressDetails{
OperatorAddr: args[0],
AVSAddress: args[1],
},
}
res, err := queryClient.QueryOperatorUSDValue(context.Background(), req)
res, err := genericQueryParams.queryClient.QueryOperatorUSDValue(context.Background(), &operatortypes.QueryOperatorUSDValueRequest{
OperatorAVSAddress: validOperatorAVSAddr,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
return genericQueryParams.clientCtx.PrintProto(res)
},
}

Expand All @@ -291,13 +309,16 @@ func QueryAVSUSDValue() *cobra.Command {
Long: "Get the USD value for the avs",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if !common.IsHexAddress(args[0]) {
return xerrors.Errorf("invalid avs address,err:%s", types.ErrInvalidAddr)
}
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryAVSUSDValueRequest{
AVSAddress: args[0],
AVSAddress: strings.ToLower(args[0]),
}
res, err := queryClient.QueryAVSUSDValue(context.Background(), req)
if err != nil {
Expand All @@ -314,36 +335,29 @@ func QueryAVSUSDValue() *cobra.Command {
// QueryOperatorSlashInfo queries the slash information for the specified operator and AVS
func QueryOperatorSlashInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "QueryOperatorSlashInfo <operatorAddr> <avsAddr>",
Short: "Get the the slash information for the operator",
Long: "Get the the slash information for the operator",
Args: cobra.ExactArgs(2),
Use: "QueryOperatorSlashInfo <operatorAddr> <avsAddr>",
Short: "Get the the slash information for the operator",
Long: "Get the the slash information for the operator",
Example: "exocored query operator QueryOperatorSlashInfo exo1c5x7mxphvgavjhu0au9jjqnfqcyspevtyy27mz 0xaa089ba103f765fcea44808bd3d4073523254c57",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
_, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return xerrors.Errorf("invalid operator address,err:%s", err.Error())
}
clientCtx, err := client.GetClientQueryContext(cmd)
validOperatorAVSAddr, genericQueryParams, err := ValidOperatorAVSAddr(cmd, args[0], args[1])
if err != nil {
return err
}
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err
}
queryClient := operatortypes.NewQueryClient(clientCtx)
req := &operatortypes.QueryOperatorSlashInfoRequest{
Details: &operatortypes.OperatorAVSAddressDetails{
OperatorAddr: args[0],
AVSAddress: args[1],
},
Pagination: pageReq,
OperatorAVSAddress: validOperatorAVSAddr,
Pagination: pageReq,
}
res, err := queryClient.QueryOperatorSlashInfo(context.Background(), req)
res, err := genericQueryParams.queryClient.QueryOperatorSlashInfo(context.Background(), req)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
return genericQueryParams.clientCtx.PrintProto(res)
},
}

Expand All @@ -370,7 +384,7 @@ func QueryAllOperatorsWithOptInAVS() *cobra.Command {

queryClient := operatortypes.NewQueryClient(clientCtx)
req := operatortypes.QueryAllOperatorsByOptInAVSRequest{
Avs: args[0],
Avs: strings.ToLower(args[0]),
}
res, err := queryClient.QueryAllOperatorsWithOptInAVS(context.Background(), &req)
if err != nil {
Expand Down Expand Up @@ -415,3 +429,30 @@ func QueryAllAVSsByOperator() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetOptInfo queries opt info
func GetOptInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "GetOptInfo <operatorAddr> <avsAddr>",
Short: "Get opt info",
Long: "Get opt info of specified operator and AVS",
Example: "exocored query operator GetOptInfo exo1c5x7mxphvgavjhu0au9jjqnfqcyspevtyy27mz 0xaa089ba103f765fcea44808bd3d4073523254c57",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
validOperatorAVSAddr, genericQueryParams, err := ValidOperatorAVSAddr(cmd, args[0], args[1])
if err != nil {
return err
}
res, err := genericQueryParams.queryClient.QueryOptInfo(context.Background(), &operatortypes.QueryOptInfoRequest{
OperatorAVSAddress: validOperatorAVSAddr,
})
if err != nil {
return err
}
return genericQueryParams.clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
9 changes: 7 additions & 2 deletions x/operator/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (k Keeper) QueryAllOperatorConsAddrsByChainID(

func (k *Keeper) QueryOperatorUSDValue(ctx context.Context, req *types.QueryOperatorUSDValueRequest) (*types.QueryOperatorUSDValueResponse, error) {
c := sdk.UnwrapSDKContext(ctx)
optedUSDValues, err := k.GetOperatorOptedUSDValue(c, req.Details.AVSAddress, req.Details.OperatorAddr)
optedUSDValues, err := k.GetOperatorOptedUSDValue(c, req.AvsAddress, req.OperatorAddr)
if err != nil {
return nil, err
}
Expand All @@ -203,7 +203,7 @@ func (k *Keeper) QueryOperatorSlashInfo(goCtx context.Context, req *types.QueryO
ctx := sdk.UnwrapSDKContext(goCtx)
res := make([]*types.OperatorSlashInfoByID, 0)

slashPrefix := types.AppendMany(types.KeyPrefixOperatorSlashInfo, assetstype.GetJoinedStoreKeyForPrefix(req.Details.OperatorAddr, req.Details.AVSAddress))
slashPrefix := types.AppendMany(types.KeyPrefixOperatorSlashInfo, assetstype.GetJoinedStoreKeyForPrefix(req.OperatorAddr, req.AvsAddress))
store := prefix.NewStore(ctx.KVStore(k.storeKey), slashPrefix)
pageRes, err := query.Paginate(store, req.Pagination, func(key []byte, value []byte) error {
ret := &types.OperatorSlashInfo{}
Expand Down Expand Up @@ -248,3 +248,8 @@ func (k *Keeper) QueryAllAVSsByOperator(goCtx context.Context, req *types.QueryA
AvsList: avsList,
}, nil
}

func (k *Keeper) QueryOptInfo(goCtx context.Context, req *types.QueryOptInfoRequest) (*types.OptedInfo, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
return k.GetOptedInfo(ctx, req.OperatorAddr, req.AvsAddress)
}
Loading
Loading