Skip to content

Commit

Permalink
remove add-revenue tx
Browse files Browse the repository at this point in the history
  • Loading branch information
kkast committed Jan 29, 2024
1 parent aa035a4 commit 78dba9f
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 572 deletions.
3 changes: 1 addition & 2 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.AccountKeeper,
)

appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String())
appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())

appKeepers.StakingKeeper = customstaking.NewKeeper(
appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), &appKeepers.StakingMiddlewareKeeper,
Expand Down Expand Up @@ -238,7 +238,6 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
)

appKeepers.BankKeeper.RegisterKeepers(appKeepers.AllianceKeeper, appKeepers.StakingKeeper)
appKeepers.StakingMiddlewareKeeper.RegisterKeepers(appKeepers.StakingKeeper)
// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
appKeepers.StakingKeeper.SetHooks(
Expand Down
15 changes: 0 additions & 15 deletions proto/composable/stakingmiddleware/v1beta1/tx.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
syntax = "proto3";
package composable.stakingmiddleware.v1beta1;

import "cosmos/base/v1beta1/coin.proto";
import "cosmos/msg/v1/msg.proto";
import "amino/amino.proto";
import "gogoproto/gogo.proto";
Expand All @@ -15,7 +14,6 @@ service Msg {
option (cosmos.msg.v1.service) = true;

rpc UpdateEpochParams(MsgUpdateEpochParams) returns (MsgUpdateParamsEpochResponse);
rpc AddRevenueFundsToStaking(MsgAddRevenueFundsToStakingParams) returns (MsgAddRevenueFundsToStakingResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand All @@ -41,16 +39,3 @@ message MsgUpdateEpochParams {
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsEpochResponse {}

message MsgAddRevenueFundsToStakingParams {
option (cosmos.msg.v1.signer) = "from_address";

string from_address = 1 [ (cosmos_proto.scalar) = "cosmos.AddressString" ];
repeated cosmos.base.v1beta1.Coin amount = 3 [
(gogoproto.nullable) = false,
(amino.dont_omitempty) = true,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

message MsgAddRevenueFundsToStakingResponse {}
35 changes: 1 addition & 34 deletions x/stakingmiddleware/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package cli

import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/notional-labs/composable/v6/x/stakingmiddleware/types"
"github.com/spf13/cobra"
)
Expand All @@ -19,37 +16,7 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

txCmd.AddCommand(
GetCmdAddRevenueFundsToStaking(),
)
txCmd.AddCommand()

return txCmd
}

func GetCmdAddRevenueFundsToStaking() *cobra.Command {
cmd := &cobra.Command{
Use: "add-revenue [amount]",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

coins, err := sdk.ParseCoinsNormalized(args[0])
if err != nil {
return err
}

msg := &types.MsgAddRevenueFundsToStakingParams{
FromAddress: clientCtx.GetFromAddress().String(),
Amount: coins,
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}
29 changes: 5 additions & 24 deletions x/stakingmiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,12 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
banktypes "github.com/notional-labs/composable/v6/custom/bank/types"
)

// Keeper of the staking middleware store
type Keeper struct {
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
accountKeeper types.AccountKeeper
bankKeeper types.BankKeeper
stakingKeeper banktypes.StakingKeeper
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string
Expand All @@ -29,24 +24,15 @@ type Keeper struct {
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
ak types.AccountKeeper,
bk types.BankKeeper,
authority string,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: key,
accountKeeper: ak,
bankKeeper: bk,
stakingKeeper: stakingkeeper.Keeper{},
authority: authority,
cdc: cdc,
storeKey: key,
authority: authority,
}
}

func (k *Keeper) RegisterKeepers(sk banktypes.StakingKeeper) {
k.stakingKeeper = sk
}

// GetAuthority returns the x/stakingmiddleware module's authority.
func (k Keeper) GetAuthority() string {
return k.authority
Expand Down Expand Up @@ -88,8 +74,3 @@ func (k Keeper) GetParams(ctx sdk.Context) (p types.Params) {
k.cdc.MustUnmarshal(bz, &p)
return p
}

func (k Keeper) GetModuleAccountAccAddress(ctx sdk.Context) sdk.AccAddress {
moduleAccount := k.accountKeeper.GetModuleAccount(ctx, types.RewardModuleName)
return moduleAccount.GetAddress()
}
28 changes: 0 additions & 28 deletions x/stakingmiddleware/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,3 @@ func (ms msgServer) UpdateEpochParams(goCtx context.Context, req *types.MsgUpdat

return &types.MsgUpdateParamsEpochResponse{}, nil
}

// UpdateParams updates the params.
func (ms msgServer) AddRevenueFundsToStaking(goCtx context.Context, req *types.MsgAddRevenueFundsToStakingParams) (*types.MsgAddRevenueFundsToStakingResponse, error) {
// Unwrap context
ctx := sdk.UnwrapSDKContext(goCtx)

// Check sender address
sender, err := sdk.AccAddressFromBech32(req.FromAddress)
if err != nil {
return nil, err
}

rewardDenom := ms.Keeper.stakingKeeper.BondDenom(ctx)

// Check that reward is 1 coin rewardDenom
if len(req.Amount.Denoms()) != 1 || req.Amount[0].Denom != rewardDenom {
return nil, errorsmod.Wrapf(types.ErrInvalidCoin, "Invalid coin")
}

// Send Fund to account module
moduleAccountAccAddress := ms.GetModuleAccountAccAddress(ctx)
err = ms.bankKeeper.SendCoins(ctx, sender, moduleAccountAccAddress, req.Amount)
if err != nil {
return nil, err
}

return &types.MsgAddRevenueFundsToStakingResponse{}, nil
}
7 changes: 0 additions & 7 deletions x/stakingmiddleware/types/errors.go

This file was deleted.

17 changes: 0 additions & 17 deletions x/stakingmiddleware/types/expected_keepers.go

This file was deleted.

3 changes: 1 addition & 2 deletions x/stakingmiddleware/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ var (

const (
// module name
ModuleName = "stakingmiddleware"
RewardModuleName = "fee_collector"
ModuleName = "stakingmiddleware"

// StoreKey is the default store key for stakingmiddleware module that store params when apply validator set changes and when allow to unbond/redelegate

Expand Down
20 changes: 0 additions & 20 deletions x/stakingmiddleware/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,3 @@ func (m *MsgUpdateEpochParams) ValidateBasic() error {

return nil
}

// GetSignBytes implements the LegacyMsg interface.
func (m MsgAddRevenueFundsToStakingParams) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m))
}

// GetSigners returns the expected signers for a MsgUpdateParams message.
func (m *MsgAddRevenueFundsToStakingParams) GetSigners() []sdk.AccAddress {
addr, _ := sdk.AccAddressFromBech32(m.FromAddress)
return []sdk.AccAddress{addr}
}

// ValidateBasic does a sanity check on the provided data.
func (m *MsgAddRevenueFundsToStakingParams) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(m.FromAddress); err != nil {
return errorsmod.Wrapf(err, "invalid address")
}

return nil
}
Loading

0 comments on commit 78dba9f

Please sign in to comment.