Skip to content

Commit

Permalink
Wasmbinding fixes (#485)
Browse files Browse the repository at this point in the history
* potential wasmbinding fix for rewards query decCoins nil

* resolve internal audit findings in masterchef+estaking

* Add MsgUpdateTotalBlocksPerYear message on parameter module

* Add APR field in external incentive

---------

Co-authored-by: Cosmic Vagabond <[email protected]>
  • Loading branch information
jelysn and cosmic-vagabond authored May 13, 2024
1 parent b692dbd commit 8835af1
Show file tree
Hide file tree
Showing 50 changed files with 970 additions and 540 deletions.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ func NewElysApp(
appCodec,
keys[estakingmoduletypes.StoreKey],
keys[estakingmoduletypes.MemStoreKey],
app.ParameterKeeper,
app.StakingKeeper,
&app.CommitmentKeeper,
&app.DistrKeeper,
Expand Down Expand Up @@ -816,6 +817,7 @@ func NewElysApp(
keys[masterchefmoduletypes.StoreKey],
keys[masterchefmoduletypes.MemStoreKey],
app.GetSubspace(masterchefmoduletypes.ModuleName),
app.ParameterKeeper,
app.CommitmentKeeper,
app.AmmKeeper,
app.OracleKeeper,
Expand All @@ -838,6 +840,7 @@ func NewElysApp(
appCodec,
keys[incentivemoduletypes.StoreKey],
keys[incentivemoduletypes.MemStoreKey],
app.ParameterKeeper,
commitmentKeeper,
app.StakingKeeper,
app.AccountKeeper,
Expand Down
17 changes: 17 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41865,6 +41865,8 @@ paths:
format: uint64
amount_per_block:
type: string
apr:
type: string
description: ExternalIncentive defines the external incentives.
default:
description: An unexpected error response.
Expand Down Expand Up @@ -42994,6 +42996,9 @@ paths:
type: string
broker_address:
type: string
total_blocks_per_year:
type: string
format: int64
description: >-
QueryParamsResponse is response type for the Query/Params RPC
method.
Expand Down Expand Up @@ -86919,6 +86924,8 @@ definitions:
format: uint64
amount_per_block:
type: string
apr:
type: string
description: ExternalIncentive defines the external incentives.
elys.masterchef.IncentiveInfo:
type: object
Expand Down Expand Up @@ -87095,6 +87102,8 @@ definitions:
format: uint64
amount_per_block:
type: string
apr:
type: string
description: ExternalIncentive defines the external incentives.
elys.masterchef.QueryParamsResponse:
type: object
Expand Down Expand Up @@ -87706,6 +87715,8 @@ definitions:
type: object
elys.parameter.MsgUpdateMinSelfDelegationResponse:
type: object
elys.parameter.MsgUpdateTotalBlocksPerYearResponse:
type: object
elys.parameter.Params:
type: object
properties:
Expand All @@ -87717,6 +87728,9 @@ definitions:
type: string
broker_address:
type: string
total_blocks_per_year:
type: string
format: int64
description: Params defines the parameters for the module.
elys.parameter.QueryParamsResponse:
type: object
Expand All @@ -87733,6 +87747,9 @@ definitions:
type: string
broker_address:
type: string
total_blocks_per_year:
type: string
format: int64
description: QueryParamsResponse is response type for the Query/Params RPC method.
elys.perpetual.IsWhitelistedResponse:
type: object
Expand Down
2 changes: 2 additions & 0 deletions proto/elys/masterchef/external_incentive.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ message ExternalIncentive {
uint64 to_block = 5;
string amount_per_block = 6
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
string apr = 7
[ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
}
7 changes: 4 additions & 3 deletions proto/elys/masterchef/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ option go_package = "github.com/elys-network/elys/x/masterchef/types";
message GenesisState {
Params params = 1 [(gogoproto.nullable) = false];
repeated ExternalIncentive external_incentives = 2 [(gogoproto.nullable) = false];
repeated PoolInfo pool_infos = 3 [(gogoproto.nullable) = false];
repeated PoolRewardInfo pool_reward_infos = 4 [(gogoproto.nullable) = false];
repeated UserRewardInfo user_reward_infos = 5 [(gogoproto.nullable) = false];
uint64 external_incentive_index = 3;
repeated PoolInfo pool_infos = 4 [(gogoproto.nullable) = false];
repeated PoolRewardInfo pool_reward_infos = 5 [(gogoproto.nullable) = false];
repeated UserRewardInfo user_reward_infos = 6 [(gogoproto.nullable) = false];
}
1 change: 1 addition & 0 deletions proto/elys/parameter/params.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ message Params {
(gogoproto.nullable) = false
];
string broker_address = 4;
int64 total_blocks_per_year = 5;
}
15 changes: 11 additions & 4 deletions proto/elys/parameter/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ service Msg {
rpc UpdateMaxVotingPower(MsgUpdateMaxVotingPower) returns (MsgUpdateMaxVotingPowerResponse);
rpc UpdateMinSelfDelegation(MsgUpdateMinSelfDelegation) returns (MsgUpdateMinSelfDelegationResponse);
rpc UpdateBrokerAddress(MsgUpdateBrokerAddress) returns (MsgUpdateBrokerAddressResponse);
rpc UpdateTotalBlocksPerYear(MsgUpdateTotalBlocksPerYear) returns (MsgUpdateTotalBlocksPerYearResponse);
}

message MsgUpdateMinCommission {
Expand All @@ -19,18 +20,24 @@ message MsgUpdateMinCommissionResponse {}

message MsgUpdateMaxVotingPower {
string creator = 1;
string max_voting_power = 3;
string max_voting_power = 2;
}
message MsgUpdateMaxVotingPowerResponse {}

message MsgUpdateMinSelfDelegation {
string creator = 1;
string min_self_delegation = 3;
string min_self_delegation = 2;
}
message MsgUpdateMinSelfDelegationResponse {}

message MsgUpdateBrokerAddress {
string creator = 1;
string broker_address = 3;
string broker_address = 2;
}
message MsgUpdateBrokerAddressResponse {}
message MsgUpdateBrokerAddressResponse {}

message MsgUpdateTotalBlocksPerYear {
string creator = 1;
int64 total_blocks_per_year = 2;
}
message MsgUpdateTotalBlocksPerYearResponse {}
3 changes: 2 additions & 1 deletion scripts/examples/estaking/estaking.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ elysd tx commitment commit-claimed-rewards 1678547 uedenb --from=treasury --keyr
# Pay 10000 uusdc as gas fees
elysd tx staking delegate $VALIDATOR 1000uelys --fees=10000uusdc --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000

elysd query estaking rewards $TREASURY
elysd query estaking rewards $TREASURY
elysd tx estaking withdraw-all-rewards --from=validator --chain-id=elystestnet-1
1 change: 1 addition & 0 deletions testutil/keeper/estaking.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func EstakingKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
"",
)

Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/incentive.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func IncentiveKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
"",
govAddress.String(),
)
Expand Down
1 change: 1 addition & 0 deletions testutil/keeper/masterchef.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func MasterchefKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
nil,
nil,
nil,
nil,
"",
)

Expand Down
59 changes: 57 additions & 2 deletions x/estaking/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package cli

import (
"fmt"
// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/flags"

// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/elys-network/elys/x/estaking/types"
Expand All @@ -32,3 +32,58 @@ func GetQueryCmd(queryRoute string) *cobra.Command {

return cmd
}

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(cmd.Context(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

func CmdQueryRewards() *cobra.Command {
cmd := &cobra.Command{
Use: "rewards [address]",
Short: "shows the rewards of an account",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Rewards(cmd.Context(), &types.QueryRewardsRequest{
Address: args[0],
})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
64 changes: 0 additions & 64 deletions x/estaking/client/cli/query_params.go

This file was deleted.

4 changes: 2 additions & 2 deletions x/estaking/client/wasm/msg_withdraw_elys_staking_rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func (m *Messenger) msgWithdrawElysStakingRewards(ctx sdk.Context, contractAddr

res, err = performMsgWithdrawElysStakingRewards(m.keeper, ctx, contractAddr, msgWithdrawElysStakingRewards)
if err != nil {
return nil, nil, errorsmod.Wrap(err, "perform elys claim rewards")
return nil, nil, errorsmod.Wrap(err, "perform msgWithdrawElysStakingRewards")
}

responseBytes, err := json.Marshal(*res)
if err != nil {
return nil, nil, errorsmod.Wrap(err, "failed to serialize stake")
return nil, nil, errorsmod.Wrap(err, "failed to serialize msgWithdrawElysStakingRewards response")
}

resp := [][]byte{responseBytes}
Expand Down
4 changes: 2 additions & 2 deletions x/estaking/client/wasm/msg_withdraw_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func (m *Messenger) msgWithdrawReward(ctx sdk.Context, contractAddr sdk.AccAddre

res, err = performMsgWithdrawReward(m.keeper, ctx, contractAddr, msgWithdrawReward)
if err != nil {
return nil, nil, errorsmod.Wrap(err, "perform elys claim rewards")
return nil, nil, errorsmod.Wrap(err, "perform msgWithdrawReward")
}

responseBytes, err := json.Marshal(*res)
if err != nil {
return nil, nil, errorsmod.Wrap(err, "failed to serialize stake")
return nil, nil, errorsmod.Wrap(err, "failed to serialize msgWithdrawReward response")
}

resp := [][]byte{responseBytes}
Expand Down
Loading

0 comments on commit 8835af1

Please sign in to comment.