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

store from custom staking module to other keeper #286

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 4 additions & 6 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ import (
ibc_hooks "github.com/notional-labs/composable/v6/x/ibc-hooks"
ibchookskeeper "github.com/notional-labs/composable/v6/x/ibc-hooks/keeper"
ibchookstypes "github.com/notional-labs/composable/v6/x/ibc-hooks/types"

customstakingtypes "github.com/notional-labs/composable/v6/custom/staking/types"
)

const (
Expand Down Expand Up @@ -187,15 +185,15 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.CustomStakingKeeper = customstaking.NewBaseKeeper2(
appCodec, appKeepers.keys[customstakingtypes.StoreKey], *appKeepers.StakingKeeper, appKeepers.AccountKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.MintKeeper = mintkeeper.NewKeeper(
appCodec, appKeepers.keys[minttypes.StoreKey], appKeepers.StakingKeeper,
appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.CustomStakingKeeper = customstaking.NewKeeper(
appCodec /*appKeepers.keys[stakingtypes.StoreKey],*/, *appKeepers.StakingKeeper, appKeepers.AccountKeeper, &appKeepers.MintKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.DistrKeeper = distrkeeper.NewKeeper(
appCodec, appKeepers.keys[distrtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper,
appKeepers.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down
5 changes: 2 additions & 3 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import (

"github.com/CosmWasm/wasmd/x/wasm"
wasm08types "github.com/cosmos/ibc-go/v7/modules/light-clients/08-wasm/types"

customstakingtypes "github.com/notional-labs/composable/v6/custom/staking/types"
// customstakingtypes "github.com/notional-labs/composable/v6/custom/staking/types"
)

// GenerateKeys generates new keys (KV Store, Transient store, and memory store).
Expand All @@ -54,7 +53,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, icqtypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, wasm08types.StoreKey,
crisistypes.StoreKey, routertypes.StoreKey, transfermiddlewaretypes.StoreKey, group.StoreKey, minttypes.StoreKey, wasm.StoreKey, ibchookstypes.StoreKey, icahosttypes.StoreKey, ratelimitmoduletypes.StoreKey, txBoundaryTypes.StoreKey,
authzkeeper.StoreKey, customstakingtypes.StoreKey,
authzkeeper.StoreKey, /*customstakingtypes.StoreKey,*/
)

// Define transient store keys
Expand Down
39 changes: 18 additions & 21 deletions custom/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,20 @@ package keeper

import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
accountkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"

customstakingtypes "github.com/notional-labs/composable/v6/custom/staking/types"
mintkeeper "github.com/notional-labs/composable/v6/x/mint/keeper"
)

type Keeper struct {
stakingkeeper.Keeper
cdc codec.BinaryCodec
storeKey storetypes.StoreKey
acck accountkeeper.AccountKeeper
authority string
cdc codec.BinaryCodec
acck accountkeeper.AccountKeeper
mintkeeper *mintkeeper.Keeper
authority string
}

var _ stakingkeeper.Keeper = stakingkeeper.Keeper{} //???

// func NewBaseKeeper(
// cdc codec.BinaryCodec,
// key storetypes.StoreKey,
Expand All @@ -36,17 +31,19 @@ var _ stakingkeeper.Keeper = stakingkeeper.Keeper{} //???
// return keeper
// }

func NewBaseKeeper2(
func NewKeeper(
cdc codec.BinaryCodec,
keys storetypes.StoreKey,
staking stakingkeeper.Keeper,
acck accountkeeper.AccountKeeper,
mintkeeper *mintkeeper.Keeper,
authority string,
) Keeper {
keeper := Keeper{
Keeper: staking,
acck: acck,
authority: authority,
Keeper: staking,
acck: acck,
authority: authority,
mintkeeper: mintkeeper,
cdc: cdc,
}
return keeper
}
Expand All @@ -55,10 +52,10 @@ func NewBaseKeeper2(
// k.acck = sk
// }

func (k Keeper) StoreDelegation(ctx sdk.Context, delegation types.Delegation) {
delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)
// func (k Keeper) StoreDelegation(ctx sdk.Context, delegation types.Delegation) {
// delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)

store := ctx.KVStore(k.storeKey)
b := types.MustMarshalDelegation(k.cdc, delegation)
store.Set(customstakingtypes.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr()), b)
}
// store := ctx.KVStore(k.storeKey)
// b := types.MustMarshalDelegation(k.cdc, delegation)
// store.Set(customstakingtypes.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr()), b)
// }
32 changes: 16 additions & 16 deletions custom/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import (
"context"

"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand All @@ -16,8 +16,8 @@

var _ types.MsgServer = msgServer{}

func NewMsgServerImpl(stakingKeeper stakingkeeper.Keeper) types.MsgServer {
return &msgServer{msgServer: stakingkeeper.NewMsgServerImpl(&stakingKeeper)}
func NewMsgServerImpl(stakingKeeper stakingkeeper.Keeper, customstakingkeeper Keeper) types.MsgServer {
return &msgServer{Keeper: customstakingkeeper, msgServer: stakingkeeper.NewMsgServerImpl(&stakingKeeper)}
}

func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateValidator) (*types.MsgCreateValidatorResponse, error) {
Expand All @@ -29,22 +29,22 @@
}

func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*types.MsgDelegateResponse, error) {

Check failure on line 32 in custom/staking/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
ctx := sdk.UnwrapSDKContext(goCtx)

bondDenom := k.BondDenom(ctx)
if msg.Amount.Denom != bondDenom {
return nil, sdkerrors.Wrapf(
sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom,
)
}

delegation := types.Delegation{
DelegatorAddress: msg.DelegatorAddress,
ValidatorAddress: msg.ValidatorAddress,
Shares: msg.Amount.Amount.ToLegacyDec(),
}
k.StoreDelegation(ctx, delegation)
// bondDenom := k.BondDenom(ctx)
// if msg.Amount.Denom != bondDenom {
// return nil, sdkerrors.Wrapf(
// sdkerrors.ErrInvalidRequest, "invalid coin denomination: got %s, expected %s", msg.Amount.Denom, bondDenom,
// )
// }

// delegation := types.Delegation{
// DelegatorAddress: msg.DelegatorAddress,
// ValidatorAddress: msg.ValidatorAddress,
// Shares: msg.Amount.Amount.ToLegacyDec(),
// }
k.mintkeeper.SetLastTotalPower(ctx, math.Int{})

return &types.MsgDelegateResponse{}, nil
// return nil, fmt.Errorf("My custom error: Nikita")
Expand Down
2 changes: 1 addition & 1 deletion custom/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"github.com/cosmos/cosmos-sdk/types/module"
stakingmodule "github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/exported"
"github.com/cosmos/cosmos-sdk/x/staking/keeper"

Check failure on line 10 in custom/staking/module.go

View workflow job for this annotation

GitHub Actions / lint

ST1019: package "github.com/cosmos/cosmos-sdk/x/staking/keeper" is being imported more than once (stylecheck)
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"

Check failure on line 11 in custom/staking/module.go

View workflow job for this annotation

GitHub Actions / lint

ST1019(related information): other import of "github.com/cosmos/cosmos-sdk/x/staking/keeper" (stylecheck)
"github.com/cosmos/cosmos-sdk/x/staking/types"

// custombankkeeper "github.com/notional-labs/composable/v6/custom/bank/keeper"
Expand Down Expand Up @@ -37,7 +37,7 @@
// when trying to force this custom keeper into a bankkeeper.BaseKeeper
func (am AppModule) RegisterServices(cfg module.Configurator) {
// types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper))
types.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper))
types.RegisterMsgServer(cfg.MsgServer(), customstakingkeeper.NewMsgServerImpl(am.keeper.Keeper, am.keeper))
querier := keeper.Querier{Keeper: &am.keeper.Keeper}
types.RegisterQueryServer(cfg.QueryServer(), querier)

Expand Down
10 changes: 10 additions & 0 deletions custom/staking/types/keeper_interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type MintKeeper interface {
SetLastTotalPower(ctx sdk.Context, power math.Int)
}
39 changes: 0 additions & 39 deletions custom/staking/types/keys.go

This file was deleted.

7 changes: 5 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ require (
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/zondax/hid v0.9.1 // indirect
github.com/zondax/ledger-go v0.14.1 // indirect
github.com/zondax/hid v0.9.2 // indirect
github.com/zondax/ledger-go v0.14.3 // indirect
go.etcd.io/bbolt v1.3.7 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect
Expand All @@ -331,6 +331,9 @@ replace (
// ibc-go with wasm client
github.com/cosmos/ibc-go/v7 => github.com/notional-labs/ibc-go/v7 v7.2.1-0.20231010040541-6cf43006971f

github.com/cosmos/ledger-cosmos-go => github.com/cosmos/ledger-cosmos-go v0.12.4

github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/terra-money/alliance => github.com/notional-labs/alliance v1.0.1-0.20231106184124-5cc1ff759647
github.com/zondax/ledger-go => github.com/zondax/ledger-go v0.14.3
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,8 @@ github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZD
github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA=
github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI=
github.com/cosmos/ledger-cosmos-go v0.12.4 h1:drvWt+GJP7Aiw550yeb3ON/zsrgW0jgh5saFCr7pDnw=
github.com/cosmos/ledger-cosmos-go v0.12.4/go.mod h1:fjfVWRf++Xkygt9wzCsjEBdjcf7wiiY35fv3ctT+k4M=
github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzUGSKFTcM=
github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4=
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
Expand Down Expand Up @@ -1257,10 +1257,10 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zondax/hid v0.9.1 h1:gQe66rtmyZ8VeGFcOpbuH3r7erYtNEAezCAYu8LdkJo=
github.com/zondax/hid v0.9.1/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/ledger-go v0.14.1 h1:Pip65OOl4iJ84WTpA4BKChvOufMhhbxED3BaihoZN4c=
github.com/zondax/ledger-go v0.14.1/go.mod h1:fZ3Dqg6qcdXWSOJFKMG8GCTnD7slO/RL2feOQv8K320=
github.com/zondax/hid v0.9.2 h1:WCJFnEDMiqGF64nlZz28E9qLVZ0KSJ7xpc5DLEyma2U=
github.com/zondax/hid v0.9.2/go.mod h1:l5wttcP0jwtdLjqjMMWFVEE7d1zO0jvSPA9OPZxWpEM=
github.com/zondax/ledger-go v0.14.3 h1:wEpJt2CEcBJ428md/5MgSLsXLBos98sBOyxNmCjfUCw=
github.com/zondax/ledger-go v0.14.3/go.mod h1:IKKaoxupuB43g4NxeQmbLXv7T9AlQyie1UpHb342ycI=
gitlab.com/bosi/decorder v0.2.3 h1:gX4/RgK16ijY8V+BRQHAySfQAb354T7/xQpDB2n10P0=
gitlab.com/bosi/decorder v0.2.3/go.mod h1:9K1RB5+VPNQYtXtTDAzd2OEftsZb1oV0IrJrzChSdGE=
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
Expand Down
Empty file modified proto/buf.gen.gogo.yaml
100644 → 100755
Empty file.
Empty file modified proto/buf.yaml
100644 → 100755
Empty file.
7 changes: 7 additions & 0 deletions proto/centauri/mint/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ message GenesisState {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coin",
(gogoproto.nullable) = false
];

// last_total_power tracks the total amounts of bonded tokens recorded during
// the previous end block.
bytes last_total_power = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
19 changes: 19 additions & 0 deletions x/mint/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"

"github.com/notional-labs/composable/v6/x/mint/types"
)
Expand Down Expand Up @@ -153,3 +154,21 @@ func (k Keeper) MintCoins(ctx sdk.Context, newCoins sdk.Coins) error {
func (k Keeper) AddCollectedFees(ctx sdk.Context, fees sdk.Coins) error {
return k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, k.feeCollectorName, fees)
}

func (k Keeper) StoreDelegation(ctx sdk.Context, delegation stakingtypes.Delegation) {
delegatorAddress := sdk.MustAccAddressFromBech32(delegation.DelegatorAddress)
log := k.Logger(ctx)
log.Info("StoreDelegation", "delegatorAddress", delegatorAddress, "validatorAddress", delegation.GetValidatorAddr())
store := ctx.KVStore(k.storeKey)
b := stakingtypes.MustMarshalDelegation(k.cdc, delegation)
kkk := types.GetDelegationKey(delegatorAddress, delegation.GetValidatorAddr())
// log.Info()
store.Set(kkk, b)
}

// SetLastTotalPower Set the last total validator power.
func (k Keeper) SetLastTotalPower(ctx sdk.Context, power math.Int) {
store := ctx.KVStore(k.storeKey)
bz := k.cdc.MustMarshal(&sdk.IntProto{Int: power})
store.Set(types.DelegationKey, bz)
}
4 changes: 4 additions & 0 deletions x/mint/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"context"

errorsmod "cosmossdk.io/errors"
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
Expand Down Expand Up @@ -42,8 +43,11 @@
func (ms msgServer) FundModuleAccount(goCtx context.Context, req *types.MsgFundModuleAccount) (*types.MsgFundModuleAccountResponse, error) {
// Unwrap context
ctx := sdk.UnwrapSDKContext(goCtx)

ms.SetLastTotalPower(ctx, math.Int{})
return nil, errorsmod.Wrapf(types.ErrInvalidAddress, "Custom error: nikita")
// Check sender address
sender, err := sdk.AccAddressFromBech32(req.FromAddress)

Check failure on line 50 in x/mint/keeper/msg_server.go

View workflow job for this annotation

GitHub Actions / lint

unreachable: unreachable code (govet)
if err != nil {
return nil, err
}
Expand Down
10 changes: 10 additions & 0 deletions x/mint/simulation/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/cosmos/cosmos-sdk/types/kv"

"github.com/notional-labs/composable/v6/x/mint/types"

stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
Expand All @@ -23,6 +25,14 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
cdc.MustUnmarshal(kvB.Value, &minterB)
return fmt.Sprintf("%v\n%v", minterA, minterB)

case bytes.Equal(kvA.Key[:1], types.DelegationKey):
var delegationA, delegationB stakingtypes.Delegation

cdc.MustUnmarshal(kvA.Value, &delegationA)
cdc.MustUnmarshal(kvB.Value, &delegationB)

return fmt.Sprintf("%v\n%v", delegationA, delegationB)

// case bytes.Equal(kvA.Key[:1], types.ParamsKey):
// var paramsA, paramsB types.Params
// cdc.MustUnmarshal(kvA.Value, &paramsA)
Expand Down
Loading
Loading