Skip to content

Commit

Permalink
feat: add to fund reward pool (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoowonYun committed Aug 22, 2024
1 parent f6b1bb1 commit 5238ddd
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 150 deletions.
20 changes: 10 additions & 10 deletions docs/proto/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
- [Query](#xpla.reward.v1beta1.Query)

- [xpla/reward/v1beta1/tx.proto](#xpla/reward/v1beta1/tx.proto)
- [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector)
- [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse)
- [MsgFundRewardPool](#xpla.reward.v1beta1.MsgFundRewardPool)
- [MsgFundRewardPoolResponse](#xpla.reward.v1beta1.MsgFundRewardPoolResponse)
- [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams)
- [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse)

Expand Down Expand Up @@ -200,11 +200,11 @@ Query defines the gRPC querier service for reward module.



<a name="xpla.reward.v1beta1.MsgFundFeeCollector"></a>
<a name="xpla.reward.v1beta1.MsgFundRewardPool"></a>

### MsgFundFeeCollector
MsgFundFeeCollector allows an account to directly
fund the fee collector.
### MsgFundRewardPool
MsgFundRewardPool allows an account to directly
fund the reward pool.


| Field | Type | Label | Description |
Expand All @@ -217,10 +217,10 @@ fund the fee collector.



<a name="xpla.reward.v1beta1.MsgFundFeeCollectorResponse"></a>
<a name="xpla.reward.v1beta1.MsgFundRewardPoolResponse"></a>

### MsgFundFeeCollectorResponse
MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type.
### MsgFundRewardPoolResponse
MsgFundRewardPoolResponse defines the Msg/FundRewardPool response type.



Expand Down Expand Up @@ -269,7 +269,7 @@ Msg defines the reawrd Msg service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `FundFeeCollector` | [MsgFundFeeCollector](#xpla.reward.v1beta1.MsgFundFeeCollector) | [MsgFundFeeCollectorResponse](#xpla.reward.v1beta1.MsgFundFeeCollectorResponse) | FundFeeCollector defines a method to allow an account to directly fund the fee collector. | |
| `FundRewardPool` | [MsgFundRewardPool](#xpla.reward.v1beta1.MsgFundRewardPool) | [MsgFundRewardPoolResponse](#xpla.reward.v1beta1.MsgFundRewardPoolResponse) | MsgFundRewardPool defines a method to allow an account to directly fund the reward pool. | |
| `UpdateParams` | [MsgUpdateParams](#xpla.reward.v1beta1.MsgUpdateParams) | [MsgUpdateParamsResponse](#xpla.reward.v1beta1.MsgUpdateParamsResponse) | UpdateParams defined a governance operation for updating the x/reward module parameters. The authority is hard-coded to the Cosmos SDK x/gov module account | |

<!-- end services -->
Expand Down
19 changes: 9 additions & 10 deletions proto/xpla/reward/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ import "amino/amino.proto";

// Msg defines the reawrd Msg service.
service Msg {
// FundFeeCollector defines a method to allow an account to directly
// fund the fee collector.
rpc FundFeeCollector(MsgFundFeeCollector)
returns (MsgFundFeeCollectorResponse);
// MsgFundRewardPool defines a method to allow an account to directly
// fund the reward pool.
rpc FundRewardPool(MsgFundRewardPool) returns (MsgFundRewardPoolResponse);

// UpdateParams defined a governance operation for updating the x/reward
// module parameters. The authority is hard-coded to the Cosmos SDK x/gov
// module account
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse);
}

// MsgFundFeeCollector allows an account to directly
// fund the fee collector.
message MsgFundFeeCollector {
option (amino.name) = "xpladev/MsgFundFeeCollector";
// MsgFundRewardPool allows an account to directly
// fund the reward pool.
message MsgFundRewardPool {
option (amino.name) = "xpladev/MsgFundRewardPool";
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

Expand All @@ -37,8 +36,8 @@ message MsgFundFeeCollector {
string depositor = 2;
}

// MsgFundFeeCollectorResponse defines the Msg/FundFeeCollector response type.
message MsgFundFeeCollectorResponse {}
// MsgFundRewardPoolResponse defines the Msg/FundRewardPool response type.
message MsgFundRewardPoolResponse {}

// MsgUpdateParams is the Msg/UpdateParams request type for reward parameters.
// Since: cosmos-sdk 0.47
Expand Down
14 changes: 7 additions & 7 deletions x/reward/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ func NewTxCmd() *cobra.Command {
}

distTxCmd.AddCommand(
NewFundFeeCollectorCmd(),
NewFundRewardPoolCmd(),
)

return distTxCmd
}

type newGenerateOrBroadcastFunc func(client.Context, *pflag.FlagSet, ...sdk.Msg) error

func NewFundFeeCollectorCmd() *cobra.Command {
func NewFundRewardPoolCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "fund-fee-collector [amount]",
Use: "fund-reward-pool [amount]",
Args: cobra.ExactArgs(1),
Short: "Funds the fee collector with the specified amount",
Short: "Funds the reward pool with the specified amount",
Long: strings.TrimSpace(
fmt.Sprintf(`Funds the fee collector with the specified amount
fmt.Sprintf(`Funds the reward pool with the specified amount
Example:
$ %s tx reward fund-fee-collector 100axpla --from mykey
$ %s tx reward fund-reward-pool 100axpla --from mykey
`,
version.AppName,
),
Expand All @@ -63,7 +63,7 @@ $ %s tx reward fund-fee-collector 100axpla --from mykey
return err
}

msg := types.NewMsgFundFeeCollector(amount, depositorAddr)
msg := types.NewMsgFundRewardPool(amount, depositorAddr)

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
Expand Down
9 changes: 4 additions & 5 deletions x/reward/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/xpladev/xpla/x/reward/types"
)
Expand Down Expand Up @@ -59,11 +58,11 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
return ctx.Logger().With("module", "x/"+types.ModuleName)
}

// FundFeeCollector allows an account to directly fund the fee collector fund.
// The amount is added to the fee collector account
// FundRewardPool allows an account to directly fund the reward pool fund.
// The amount is added to the reward pool account
// An error is returned if the amount cannot be sent to the module account.
func (k Keeper) FundFeeCollector(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error {
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, authtypes.FeeCollectorName, amount); err != nil {
func (k Keeper) FundRewardPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error {
if err := k.bankKeeper.SendCoinsFromAccountToModule(ctx, sender, types.ModuleName, amount); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions x/reward/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ func NewMsgServerImpl(keeper Keeper) types.MsgServer {

var _ types.MsgServer = msgServer{}

func (k msgServer) FundFeeCollector(goCtx context.Context, msg *types.MsgFundFeeCollector) (*types.MsgFundFeeCollectorResponse, error) {
func (k msgServer) FundRewardPool(goCtx context.Context, msg *types.MsgFundRewardPool) (*types.MsgFundRewardPoolResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

depositer, err := sdk.AccAddressFromBech32(msg.Depositor)
if err != nil {
return nil, err
}

err = k.Keeper.FundFeeCollector(ctx, msg.Amount, depositer)
err = k.Keeper.FundRewardPool(ctx, msg.Amount, depositer)
if err != nil {
return nil, err
}
Expand All @@ -42,7 +42,7 @@ func (k msgServer) FundFeeCollector(goCtx context.Context, msg *types.MsgFundFee
),
)

return &types.MsgFundFeeCollectorResponse{}, nil
return &types.MsgFundRewardPoolResponse{}, nil
}

// UpdateParams implements the gRPC MsgServer interface. After a successful governance vote
Expand Down
4 changes: 2 additions & 2 deletions x/reward/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
)

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgFundFeeCollector{}, "xpladev/MsgFundFeeCollector", nil)
cdc.RegisterConcrete(&MsgFundRewardPool{}, "xpladev/MsgFundRewardPool", nil)
cdc.RegisterConcrete(&MsgUpdateParams{}, "xpladev/reward/MsgUpdateParams", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgFundFeeCollector{},
&MsgFundRewardPool{},
&MsgUpdateParams{},
)

Expand Down
28 changes: 14 additions & 14 deletions x/reward/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,44 @@ import (
)

const (
TypeMsgFundFeeCollector = "fund_fee_collector"
TypeMsgUpdateParams = "update_params"
TypeMsgFundRewardPool = "fund_reward_pool"
TypeMsgUpdateParams = "update_params"
)

// NewMsgFundFeeCollector returns a new MsgFundFeeCollector with a sender and
// NewMsgFundRewardPool returns a new MsgFundRewardPool with a sender and
// a funding amount.
func NewMsgFundFeeCollector(amount sdk.Coins, depositor sdk.AccAddress) *MsgFundFeeCollector {
return &MsgFundFeeCollector{
func NewMsgFundRewardPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFundRewardPool {
return &MsgFundRewardPool{
Amount: amount,
Depositor: depositor.String(),
}
}

// Route returns the MsgFundFeeCollector message route.
func (msg MsgFundFeeCollector) Route() string { return ModuleName }
// Route returns the MsgFundRewardPool message route.
func (msg MsgFundRewardPool) Route() string { return ModuleName }

// Type returns the MsgFundFeeCollector message type.
func (msg MsgFundFeeCollector) Type() string { return TypeMsgFundFeeCollector }
// Type returns the MsgFundRewardPool message type.
func (msg MsgFundRewardPool) Type() string { return TypeMsgFundRewardPool }

// GetSigners returns the signer addresses that are expected to sign the result
// of GetSignBytes.
func (msg MsgFundFeeCollector) GetSigners() []sdk.AccAddress {
func (msg MsgFundRewardPool) GetSigners() []sdk.AccAddress {
depoAddr, err := sdk.AccAddressFromBech32(msg.Depositor)
if err != nil {
panic(err)
}
return []sdk.AccAddress{depoAddr}
}

// GetSignBytes returns the raw bytes for a MsgFundFeeCollector message that
// GetSignBytes returns the raw bytes for a MsgFundRewardPool message that
// the expected signer needs to sign.
func (msg MsgFundFeeCollector) GetSignBytes() []byte {
func (msg MsgFundRewardPool) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(&msg)
return sdk.MustSortJSON(bz)
}

// ValidateBasic performs basic MsgFundFeeCollector message validation.
func (msg MsgFundFeeCollector) ValidateBasic() error {
// ValidateBasic performs basic MsgFundRewardPool message validation.
func (msg MsgFundRewardPool) ValidateBasic() error {
if !msg.Amount.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, msg.Amount.String())
}
Expand Down
4 changes: 2 additions & 2 deletions x/reward/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/xpladev/xpla/x/reward/types"
)

func TestMsgFundFeeCollector(t *testing.T) {
func TestMsgFundRewardPool(t *testing.T) {
tests := []struct {
amount sdk.Coins
depositorAddr sdk.AccAddress
Expand All @@ -22,7 +22,7 @@ func TestMsgFundFeeCollector(t *testing.T) {
}

for i, tc := range tests {
msg := types.NewMsgFundFeeCollector(tc.amount, tc.depositorAddr)
msg := types.NewMsgFundRewardPool(tc.amount, tc.depositorAddr)
if tc.expectPass {
require.Nil(t, msg.ValidateBasic(), "test index: %v", i)
} else {
Expand Down
Loading

0 comments on commit 5238ddd

Please sign in to comment.