Skip to content

Commit

Permalink
Merge branch 'ExocoreNetwork:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
trestinlsd authored Oct 17, 2024
2 parents 3c8d1bd + bf6efa5 commit 2ab3e57
Show file tree
Hide file tree
Showing 6 changed files with 740 additions and 211 deletions.
3 changes: 3 additions & 0 deletions local_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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
Expand Up @@ -31,24 +31,24 @@ message QueryAllOperatorsResponse {
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];;
}

// 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 @@ message QueryAVSUSDValueRequest {
// 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];
// pagination related options.
cosmos.base.query.v1beta1.PageRequest pagination = 2;
}
Expand Down Expand Up @@ -213,6 +213,14 @@ message QueryAllAVSsByOperatorResponse {
// 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 @@ service Query {

// 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 @@ service Query {

// 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 @@ service Query {
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

0 comments on commit 2ab3e57

Please sign in to comment.