Skip to content

Commit

Permalink
ccv consumer module implementation (#997)
Browse files Browse the repository at this point in the history
* ccv consumer module implementation

* token economics implementation with ics

* Sending 25% of Stakers Dex revenue of provider chain

* fee corrections

* fixing test cases
  • Loading branch information
avkr003 authored Dec 4, 2024
1 parent 7ca556f commit b4e5292
Show file tree
Hide file tree
Showing 39 changed files with 2,370 additions and 453 deletions.
1,168 changes: 1,108 additions & 60 deletions api/elys/estaking/params.pulsar.go

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
ibcante "github.com/cosmos/ibc-go/v8/modules/core/ante"
consumerante "github.com/cosmos/interchain-security/v6/app/consumer/ante"
)

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand All @@ -28,7 +29,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "IBC keeper is required for AnteHandler")
}
if options.StakingKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrNotFound, "staking param store is required for AnteHandler")
return nil, errorsmod.Wrap(sdkerrors.ErrNotFound, "staking keeper is required for AnteHandler")
}

sigGasConsumer := options.SigGasConsumer
Expand All @@ -46,6 +47,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
NewMinCommissionDecorator(options.Cdc, options.StakingKeeper, options.BankKeeper, options.ParameterKeeper),
NewVestedAnteHandlerDecorator(options.AccountKeeper, options.BankKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
consumerante.NewDisabledModulesDecorator("/cosmos.evidence", "/cosmos.slashing"),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
ante.NewValidateMemoDecorator(options.AccountKeeper),
Expand Down
16 changes: 8 additions & 8 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package ante

import (
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
parameterkeeper "github.com/elys-network/elys/x/parameter/keeper"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/x/auth/ante"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibcconsumerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/consumer/keeper"
parameterkeeper "github.com/elys-network/elys/x/parameter/keeper"
)

// HandlerOptions extend the SDK's AnteHandler options by requiring the IBC
// channel keeper.
type HandlerOptions struct {
ante.HandlerOptions

Cdc codec.BinaryCodec
IBCKeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper

Cdc codec.BinaryCodec
IBCKeeper *ibckeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
ConsumerKeeper ibcconsumerkeeper.Keeper
BankKeeper bankkeeper.Keeper
ParameterKeeper parameterkeeper.Keeper
}
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import (
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsclient "github.com/cosmos/cosmos-sdk/x/params/client"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
ccvconsumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"
"github.com/elys-network/elys/app/ante"

// this line is used by starport scaffolding # stargate/app/moduleImport
Expand Down Expand Up @@ -281,6 +282,7 @@ func NewElysApp(
Cdc: appCodec,
IBCKeeper: app.IBCKeeper,
StakingKeeper: app.StakingKeeper,
ConsumerKeeper: app.ConsumerKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -388,7 +390,10 @@ func (app *ElysApp) ModuleAccountAddrs() map[string]bool {
func (app *ElysApp) BlockedModuleAccountAddrs() map[string]bool {
modAccAddrs := app.ModuleAccountAddrs()
delete(modAccAddrs, authtypes.NewModuleAddress(govtypes.ModuleName).String())

// Remove the fee-pool from the group of blocked recipient addresses in bank
// this is required for the consumer chain to be able to send tokens to
// the provider chain
delete(modAccAddrs, authtypes.NewModuleAddress(ccvconsumertypes.ConsumerToSendToProviderName).String())
return modAccAddrs
}

Expand Down
93 changes: 51 additions & 42 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ import (
porttypes "github.com/cosmos/ibc-go/v8/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"

//ccvconsumerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/consumer/keeper"
//ccvconsumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"
ccvconsumer "github.com/cosmos/interchain-security/v6/x/ccv/consumer"
ccvconsumerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/consumer/keeper"
ccvconsumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"
ccv "github.com/cosmos/interchain-security/v6/x/ccv/types"
accountedpoolmodulekeeper "github.com/elys-network/elys/x/accountedpool/keeper"
accountedpoolmoduletypes "github.com/elys-network/elys/x/accountedpool/types"
ammmodulekeeper "github.com/elys-network/elys/x/amm/keeper"
Expand Down Expand Up @@ -138,7 +139,8 @@ type AppKeepers struct {
IBCFeeKeeper ibcfeekeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper

//ConsumerKeeper ccvconsumerkeeper.Keeper
ConsumerKeeper ccvconsumerkeeper.Keeper
ConsumerModule ccvconsumer.AppModule // Have to declare this here for IBC router

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand All @@ -147,7 +149,7 @@ type AppKeepers struct {
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedIBCFeeKeeper capabilitykeeper.ScopedKeeper
ScopedOracleKeeper capabilitykeeper.ScopedKeeper
//ScopedCCVConsumerKeeper capabilitykeeper.ScopedKeeper
ScopedCCVConsumerKeeper capabilitykeeper.ScopedKeeper

EpochsKeeper *epochsmodulekeeper.Keeper
AssetprofileKeeper assetprofilemodulekeeper.Keeper
Expand Down Expand Up @@ -246,7 +248,7 @@ func NewAppKeeper(
app.ScopedICAControllerKeeper = app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
app.ScopedTransferKeeper = app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
app.ScopedOracleKeeper = app.CapabilityKeeper.ScopeToModule(oracletypes.ModuleName)
//app.ScopedCCVConsumerKeeper = app.CapabilityKeeper.ScopeToModule(ccvconsumertypes.ModuleName)
app.ScopedCCVConsumerKeeper = app.CapabilityKeeper.ScopeToModule(ccvconsumertypes.ModuleName)

// Add normal keepers
app.AccountKeeper = authkeeper.NewAccountKeeper(
Expand Down Expand Up @@ -341,7 +343,7 @@ func NewAppKeeper(
appCodec,
legacyAmino,
runtime.NewKVStoreService(app.keys[slashingtypes.StoreKey]),
app.EstakingKeeper,
&app.ConsumerKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand All @@ -368,18 +370,23 @@ func NewAppKeeper(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

//app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
// appCodec,
// app.keys[ccvconsumertypes.StoreKey],
// app.GetSubspace(ccvconsumertypes.ModuleName),
//)
// ... other modules keepers
// pre-initialize ConsumerKeeper to satisfy ibckeeper.NewKeeper
// which would panic on nil or zero keeper
// ConsumerKeeper implements StakingKeeper but all function calls result in no-ops so this is safe
// communication over IBC is not affected by these changes
app.ConsumerKeeper = ccvconsumerkeeper.NewNonZeroKeeper(
appCodec,
app.keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
)

// UpgradeKeeper must be created before IBCKeeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
app.keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
&app.ConsumerKeeper,
app.UpgradeKeeper,
app.ScopedIBCKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
Expand Down Expand Up @@ -437,14 +444,37 @@ func NewAppKeeper(
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(app.keys[evidencetypes.StoreKey]),
app.StakingKeeper,
&app.ConsumerKeeper,
app.SlashingKeeper,
app.AccountKeeper.AddressCodec(),
runtime.ProvideCometInfoService(),
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper

app.ConsumerKeeper = ccvconsumerkeeper.NewKeeper(
appCodec,
app.keys[ccvconsumertypes.StoreKey],
app.GetSubspace(ccvconsumertypes.ModuleName),
app.ScopedCCVConsumerKeeper,
app.IBCKeeper.ChannelKeeper,
app.IBCKeeper.PortKeeper,
app.IBCKeeper.ConnectionKeeper,
app.IBCKeeper.ClientKeeper,
app.SlashingKeeper,
app.BankKeeper,
app.AccountKeeper,
app.TransferKeeper,
app.IBCKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
address.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()),
address.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()),
)

app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks())
app.ConsumerModule = ccvconsumer.NewAppModule(app.ConsumerKeeper, app.GetSubspace(ccvconsumertypes.ModuleName))

app.OracleKeeper = *oraclekeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(app.keys[oracletypes.StoreKey]),
Expand Down Expand Up @@ -503,7 +533,7 @@ func NewAppKeeper(
app.AccountKeeper,
app.CommitmentKeeper,
app.EstakingKeeper,
authtypes.FeeCollectorName,
ccvconsumertypes.ConsumerRedistributeName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

Expand Down Expand Up @@ -548,30 +578,6 @@ func NewAppKeeper(
runtime.NewKVStoreService(app.keys[transferhooktypes.StoreKey]),
app.AmmKeeper)

//app.ConsumerKeeper = ccvconsumerkeeper.NewKeeper(
// appCodec,
// app.keys[ccvconsumertypes.StoreKey],
// app.GetSubspace(ccvconsumertypes.ModuleName),
// app.ScopedCCVConsumerKeeper,
// app.IBCKeeper.ChannelKeeper,
// app.IBCKeeper.PortKeeper,
// app.IBCKeeper.ConnectionKeeper,
// app.IBCKeeper.ClientKeeper,
// app.SlashingKeeper,
// app.BankKeeper,
// app.AccountKeeper,
// app.TransferKeeper,
// app.IBCKeeper,
// authtypes.FeeCollectorName,
// authtypes.NewModuleAddress(govtypes.ModuleName).String(),
// app.StakingKeeper.ValidatorAddressCodec(),
// app.StakingKeeper.ConsensusAddressCodec(),
//)
//app.ConsumerKeeper.SetStandaloneStakingKeeper(app.EstakingKeeper)
//
//// register slashing module StakingHooks to the consumer keeper
//app.ConsumerKeeper = *app.ConsumerKeeper.SetHooks(app.SlashingKeeper.Hooks())

// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
app.keys[ibchookstypes.StoreKey],
Expand All @@ -593,6 +599,7 @@ func NewAppKeeper(
runtime.NewKVStoreService(app.keys[govtypes.StoreKey]),
app.AccountKeeper,
app.BankKeeper,
// No need to send EstakingKeeper here as gov only does sk.IterateBondedValidatorsByPower, no need to give vp to Eden and EdenB
app.StakingKeeper,
app.DistrKeeper,
bApp.MsgServiceRouter(),
Expand Down Expand Up @@ -688,7 +695,8 @@ func NewAppKeeper(
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(ibctransfertypes.ModuleName, transferStack).
AddRoute(oracletypes.ModuleName, oracleIBCModule)
AddRoute(oracletypes.ModuleName, oracleIBCModule).
AddRoute(ccvconsumertypes.ModuleName, app.ConsumerModule)

app.IBCKeeper.SetRouter(ibcRouter)

Expand All @@ -709,7 +717,7 @@ func NewAppKeeper(
app.EstakingKeeper.SetHooks(
stakingtypes.NewMultiStakingHooks(
// insert staking hooks receivers here
app.SlashingKeeper.Hooks(),
// Do not use slashing keeper hooks when it's consumer chain
app.DistrKeeper.Hooks(),
app.EstakingKeeper.StakingHooks(),
app.TierKeeper.StakingHooks(),
Expand Down Expand Up @@ -739,6 +747,7 @@ func NewAppKeeper(
app.CommitmentKeeper.Hooks(),
app.BurnerKeeper.Hooks(),
app.PerpetualKeeper.EpochHooks(),
app.EstakingKeeper.EpochHooks(),
),
)

Expand Down Expand Up @@ -780,7 +789,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibctransfertypes.ModuleName).WithKeyTable(ibctransfertypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName).WithKeyTable(icacontrollertypes.ParamKeyTable())
paramsKeeper.Subspace(icahosttypes.SubModuleName).WithKeyTable(icahosttypes.ParamKeyTable())
//paramsKeeper.Subspace(ccvconsumertypes.ModuleName)
paramsKeeper.Subspace(ccvconsumertypes.ModuleName).WithKeyTable(ccv.ParamKeyTable())

// Can be removed as we are not using param subspace anymore anywhere
paramsKeeper.Subspace(assetprofilemoduletypes.ModuleName)
Expand Down
5 changes: 2 additions & 3 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
ibcfeetypes "github.com/cosmos/ibc-go/v8/modules/apps/29-fee/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
ccvconsumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"

//ccvconsumertypes "github.com/cosmos/interchain-security/v6/x/ccv/consumer/types"
accountedpoolmoduletypes "github.com/elys-network/elys/x/accountedpool/types"
ammmoduletypes "github.com/elys-network/elys/x/amm/types"
assetprofilemoduletypes "github.com/elys-network/elys/x/assetprofile/types"
Expand Down Expand Up @@ -67,8 +67,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
authz.ModuleName,
group.StoreKey,
consensusparamtypes.StoreKey,

//ccvconsumertypes.StoreKey,
ccvconsumertypes.StoreKey,

epochsmoduletypes.StoreKey,
assetprofilemoduletypes.StoreKey,
Expand Down
Loading

0 comments on commit b4e5292

Please sign in to comment.