diff --git a/app/app.go b/app/app.go index 8868d3392..1fa133918 100644 --- a/app/app.go +++ b/app/app.go @@ -10,48 +10,45 @@ import ( "path/filepath" "sort" + "github.com/ExocoreNetwork/exocore/x/operator" + operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper" + + exoslash "github.com/ExocoreNetwork/exocore/x/slash" + + slashKeeper "github.com/ExocoreNetwork/exocore/x/slash/keeper" + exoslashTypes "github.com/ExocoreNetwork/exocore/x/slash/types" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" ibctesting "github.com/cosmos/ibc-go/v7/testing" - // for EIP-1559 fee handling ethante "github.com/evmos/evmos/v14/app/ante/evm" - // for encoding and decoding of EIP-712 messages "github.com/evmos/evmos/v14/ethereum/eip712" "github.com/ExocoreNetwork/exocore/x/assets" assetsKeeper "github.com/ExocoreNetwork/exocore/x/assets/keeper" assetsTypes "github.com/ExocoreNetwork/exocore/x/assets/types" - "github.com/ExocoreNetwork/exocore/x/delegation" delegationKeeper "github.com/ExocoreNetwork/exocore/x/delegation/keeper" delegationTypes "github.com/ExocoreNetwork/exocore/x/delegation/types" - "github.com/ExocoreNetwork/exocore/x/deposit" depositKeeper "github.com/ExocoreNetwork/exocore/x/deposit/keeper" depositTypes "github.com/ExocoreNetwork/exocore/x/deposit/types" - - "github.com/ExocoreNetwork/exocore/x/operator" - operatorKeeper "github.com/ExocoreNetwork/exocore/x/operator/keeper" operatorTypes "github.com/ExocoreNetwork/exocore/x/operator/types" - "github.com/ExocoreNetwork/exocore/x/reward" rewardKeeper "github.com/ExocoreNetwork/exocore/x/reward/keeper" rewardTypes "github.com/ExocoreNetwork/exocore/x/reward/types" - - exoslash "github.com/ExocoreNetwork/exocore/x/slash" - slashKeeper "github.com/ExocoreNetwork/exocore/x/slash/keeper" - exoslashTypes "github.com/ExocoreNetwork/exocore/x/slash/types" - "github.com/ExocoreNetwork/exocore/x/withdraw" withdrawKeeper "github.com/ExocoreNetwork/exocore/x/withdraw/keeper" withdrawTypes "github.com/ExocoreNetwork/exocore/x/withdraw/types" - - // increases or decreases block gas limit based on usage "github.com/evmos/evmos/v14/x/feemarket" - feemarketkeeper "github.com/evmos/evmos/v14/x/feemarket/keeper" feemarkettypes "github.com/evmos/evmos/v14/x/feemarket/types" + "github.com/evmos/evmos/v14/x/incentives" + "github.com/evmos/evmos/v14/x/inflation" + "github.com/evmos/evmos/v14/x/recovery" + "github.com/evmos/evmos/v14/x/revenue/v1" + vestingtypes "github.com/evmos/evmos/v14/x/vesting/types" runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" @@ -74,14 +71,14 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" - + authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts" icahost "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host" - icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types" icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types" ibctestingtypes "github.com/cosmos/ibc-go/v7/testing/types" + // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens ibctransfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer" ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ibc "github.com/cosmos/ibc-go/v7/modules/core" @@ -92,12 +89,12 @@ import ( ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - - // this module allows the transfer of ERC20 tokens over IBC. for such transfers to occur, - // they must be enabled in the ERC20 keeper. + srvflags "github.com/evmos/evmos/v14/server/flags" transfer "github.com/evmos/evmos/v14/x/ibc/transfer" transferkeeper "github.com/evmos/evmos/v14/x/ibc/transfer/keeper" + incentivestypes "github.com/evmos/evmos/v14/x/incentives/types" + // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens "cosmossdk.io/simapp" simappparams "cosmossdk.io/simapp/params" servertypes "github.com/cosmos/cosmos-sdk/server/types" @@ -107,89 +104,85 @@ import ( "github.com/cosmos/cosmos-sdk/types/mempool" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/version" - srvflags "github.com/evmos/evmos/v14/server/flags" - "github.com/cosmos/cosmos-sdk/x/auth" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" "github.com/cosmos/cosmos-sdk/x/auth/posthandler" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/authz" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" - "github.com/cosmos/cosmos-sdk/x/bank" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - "github.com/cosmos/cosmos-sdk/x/capability" capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper" capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types" - "github.com/cosmos/cosmos-sdk/x/consensus" - consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - "github.com/cosmos/cosmos-sdk/x/crisis" crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper" crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - + distr "github.com/cosmos/cosmos-sdk/x/distribution" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - "github.com/cosmos/cosmos-sdk/x/feegrant" feegrantkeeper "github.com/cosmos/cosmos-sdk/x/feegrant/keeper" feegrantmodule "github.com/cosmos/cosmos-sdk/x/feegrant/module" - "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - "github.com/cosmos/cosmos-sdk/x/gov" govclient "github.com/cosmos/cosmos-sdk/x/gov/client" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" - "github.com/cosmos/cosmos-sdk/x/params" paramsclient "github.com/cosmos/cosmos-sdk/x/params/client" paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper" paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" paramproposal "github.com/cosmos/cosmos-sdk/x/params/types/proposal" - "github.com/cosmos/cosmos-sdk/x/slashing" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - "github.com/cosmos/cosmos-sdk/x/staking" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/cosmos/cosmos-sdk/x/upgrade" upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client" upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/ExocoreNetwork/exocore/x/evm" - evmkeeper "github.com/ExocoreNetwork/exocore/x/evm/keeper" - evmtypes "github.com/evmos/evmos/v14/x/evm/types" - + bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/evmos/evmos/v14/encoding" evmostypes "github.com/evmos/evmos/v14/types" + evmtypes "github.com/evmos/evmos/v14/x/evm/types" - // The recovery module is an IBC middleware for helping users recover funds that they sent - // to the Cosmos secp256k1 address instead of the Ethereum ethsecp256k1 address. It only - // works for authorized chains. - "github.com/evmos/evmos/v14/x/recovery" + evmkeeper "github.com/ExocoreNetwork/exocore/x/evm/keeper" + + consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + feemarketkeeper "github.com/evmos/evmos/v14/x/feemarket/keeper" + + icahostkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/keeper" + + incentiveskeeper "github.com/evmos/evmos/v14/x/incentives/keeper" + inflationkeeper "github.com/evmos/evmos/v14/x/inflation/keeper" + inflationtypes "github.com/evmos/evmos/v14/x/inflation/types" recoverykeeper "github.com/evmos/evmos/v14/x/recovery/keeper" recoverytypes "github.com/evmos/evmos/v14/x/recovery/types" - + revenuekeeper "github.com/evmos/evmos/v14/x/revenue/v1/keeper" + revenuetypes "github.com/evmos/evmos/v14/x/revenue/v1/types" + "github.com/evmos/evmos/v14/x/vesting" + vestingkeeper "github.com/evmos/evmos/v14/x/vesting/keeper" + + "github.com/evmos/evmos/v14/x/claims" + claimskeeper "github.com/evmos/evmos/v14/x/claims/keeper" + claimstypes "github.com/evmos/evmos/v14/x/claims/types" "github.com/evmos/evmos/v14/x/epochs" epochskeeper "github.com/evmos/evmos/v14/x/epochs/keeper" epochstypes "github.com/evmos/evmos/v14/x/epochs/types" - "github.com/evmos/evmos/v14/x/erc20" erc20keeper "github.com/evmos/evmos/v14/x/erc20/keeper" erc20types "github.com/evmos/evmos/v14/x/erc20/types" @@ -235,6 +228,7 @@ var ( bank.AppModuleBasic{}, capability.AppModuleBasic{}, staking.AppModuleBasic{}, + distr.AppModuleBasic{}, gov.NewAppModuleBasic( []govclient.ProposalHandler{ paramsclient.ProposalHandler, upgradeclient.LegacyProposalHandler, upgradeclient.LegacyCancelProposalHandler, @@ -253,12 +247,17 @@ var ( upgrade.AppModuleBasic{}, evidence.AppModuleBasic{}, transfer.AppModuleBasic{AppModuleBasic: &ibctransfer.AppModuleBasic{}}, + vesting.AppModuleBasic{}, evm.AppModuleBasic{}, feemarket.AppModuleBasic{}, // evmos modules + inflation.AppModuleBasic{}, erc20.AppModuleBasic{}, + incentives.AppModuleBasic{}, epochs.AppModuleBasic{}, + claims.AppModuleBasic{}, recovery.AppModuleBasic{}, + revenue.AppModuleBasic{}, consensus.AppModuleBasic{}, // Exocore modules assets.AppModuleBasic{}, @@ -273,20 +272,23 @@ var ( // module account permissions maccPerms = map[string][]string{ authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, govtypes.ModuleName: {authtypes.Burner}, ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, icatypes.ModuleName: nil, - evmtypes.ModuleName: { - authtypes.Minter, - authtypes.Burner, - }, // used for secure addition and subtraction of balance using module account - erc20types.ModuleName: {authtypes.Minter, authtypes.Burner}, + evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, // used for secure addition and subtraction of balance using module account + inflationtypes.ModuleName: {authtypes.Minter}, + erc20types.ModuleName: {authtypes.Minter, authtypes.Burner}, + claimstypes.ModuleName: nil, + incentivestypes.ModuleName: {authtypes.Minter, authtypes.Burner}, } // module accounts that are allowed to receive tokens - allowedReceivingModAcc = map[string]bool{} + allowedReceivingModAcc = map[string]bool{ + incentivestypes.ModuleName: true, + } ) var ( @@ -318,6 +320,7 @@ type ExocoreApp struct { CapabilityKeeper *capabilitykeeper.Keeper StakingKeeper stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper + DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper CrisisKeeper crisiskeeper.Keeper UpgradeKeeper upgradekeeper.Keeper @@ -339,9 +342,14 @@ type ExocoreApp struct { FeeMarketKeeper feemarketkeeper.Keeper // Evmos keepers - Erc20Keeper erc20keeper.Keeper - EpochsKeeper epochskeeper.Keeper - RecoveryKeeper *recoverykeeper.Keeper + InflationKeeper inflationkeeper.Keeper + ClaimsKeeper *claimskeeper.Keeper + Erc20Keeper erc20keeper.Keeper + IncentivesKeeper incentiveskeeper.Keeper + EpochsKeeper epochskeeper.Keeper + VestingKeeper vestingkeeper.Keeper + RecoveryKeeper *recoverykeeper.Keeper + RevenueKeeper revenuekeeper.Keeper // exocore assets module keepers AssetsKeeper assetsKeeper.Keeper @@ -396,8 +404,7 @@ func NewExocoreApp( app.SetPrepareProposal(handler.PrepareProposalHandler()) app.SetProcessProposal(handler.ProcessProposalHandler()) }) - // NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of - // sdk.StdTx + // NOTE we use custom transaction decoder that supports the sdk.Tx interface instead of sdk.StdTx bApp := baseapp.NewBaseApp( Name, logger, @@ -412,7 +419,7 @@ func NewExocoreApp( keys := sdk.NewKVStoreKeys( // SDK keys authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, - slashingtypes.StoreKey, + distrtypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, paramstypes.StoreKey, upgradetypes.StoreKey, evidencetypes.StoreKey, capabilitytypes.StoreKey, consensusparamtypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, crisistypes.StoreKey, @@ -423,9 +430,9 @@ func NewExocoreApp( // ethermint keys evmtypes.StoreKey, feemarkettypes.StoreKey, // evmos keys - erc20types.StoreKey, - epochstypes.StoreKey, - recoverytypes.StoreKey, + inflationtypes.StoreKey, erc20types.StoreKey, incentivestypes.StoreKey, + epochstypes.StoreKey, claimstypes.StoreKey, vestingtypes.StoreKey, + revenuetypes.StoreKey, recoverytypes.StoreKey, // exoCore module keys assetsTypes.StoreKey, delegationTypes.StoreKey, @@ -437,11 +444,7 @@ func NewExocoreApp( ) // Add the EVM transient store key - tkeys := sdk.NewTransientStoreKeys( - paramstypes.TStoreKey, - evmtypes.TransientKey, - feemarkettypes.TransientKey, - ) + tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey) memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey) // load state streaming if enabled @@ -462,37 +465,23 @@ func NewExocoreApp( } // init params keeper and subspaces - app.ParamsKeeper = initParamsKeeper( - appCodec, - cdc, - keys[paramstypes.StoreKey], - tkeys[paramstypes.TStoreKey], - ) + app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey]) // get authority address authAddr := authtypes.NewModuleAddress(govtypes.ModuleName).String() // set the BaseApp's parameter store - app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper( - appCodec, - keys[consensusparamtypes.StoreKey], - authAddr, - ) + app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[consensusparamtypes.StoreKey], authAddr) bApp.SetParamStore(&app.ConsensusParamsKeeper) // add capability keeper and ScopeToModule for ibc module - app.CapabilityKeeper = capabilitykeeper.NewKeeper( - appCodec, - keys[capabilitytypes.StoreKey], - memKeys[capabilitytypes.MemStoreKey], - ) + app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey]) scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName) scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName) scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName) - // Applications that wish to enforce statically created ScopedKeepers should call `Seal` - // after creating + // Applications that wish to enforce statically created ScopedKeepers should call `Seal` after creating // their scoped modules in `NewApp` with `ScopeToModule` app.CapabilityKeeper.Seal() // add account keepers @@ -515,6 +504,10 @@ func NewExocoreApp( appCodec, keys[stakingtypes.StoreKey], accountK, bankK, authAddr, ) app.StakingKeeper = *stakingKeeper + app.DistrKeeper = distrkeeper.NewKeeper( + appCodec, keys[distrtypes.StoreKey], accountK, bankK, + stakingKeeper, authtypes.FeeCollectorName, authAddr, + ) app.SlashingKeeper = slashingkeeper.NewKeeper( appCodec, app.LegacyAmino(), keys[slashingtypes.StoreKey], stakingKeeper, authAddr, ) @@ -524,12 +517,7 @@ func NewExocoreApp( app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], accountK) app.UpgradeKeeper = *upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authAddr) - app.AuthzKeeper = authzkeeper.NewKeeper( - keys[authzkeeper.StoreKey], - appCodec, - app.MsgServiceRouter(), - app.AccountKeeper, - ) + app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper) tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer)) @@ -542,28 +530,16 @@ func NewExocoreApp( ) evmKeeper := evmkeeper.NewKeeper( - appCodec, - keys[evmtypes.StoreKey], - tkeys[evmtypes.TransientKey], - authtypes.NewModuleAddress(govtypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - stakingKeeper, - app.FeeMarketKeeper, - tracer, - app.GetSubspace(evmtypes.ModuleName), + appCodec, keys[evmtypes.StoreKey], tkeys[evmtypes.TransientKey], authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, app.BankKeeper, stakingKeeper, app.FeeMarketKeeper, + tracer, app.GetSubspace(evmtypes.ModuleName), ) app.EvmKeeper = evmKeeper // Create IBC Keeper app.IBCKeeper = ibckeeper.NewKeeper( - appCodec, - keys[ibcexported.StoreKey], - app.GetSubspace(ibcexported.ModuleName), - stakingKeeper, - app.UpgradeKeeper, - scopedIBCKeeper, + appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), stakingKeeper, app.UpgradeKeeper, scopedIBCKeeper, ) // register the proposal types @@ -572,7 +548,10 @@ func NewExocoreApp( AddRoute(paramproposal.RouterKey, params.NewParamChangeProposalHandler(app.ParamsKeeper)). AddRoute(upgradetypes.RouterKey, upgrade.NewSoftwareUpgradeProposalHandler(&app.UpgradeKeeper)). AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.IBCKeeper.ClientKeeper)). - AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&app.Erc20Keeper)) + AddRoute(erc20types.RouterKey, erc20.NewErc20ProposalHandler(&app.Erc20Keeper)). + AddRoute(incentivestypes.RouterKey, incentives.NewIncentivesProposalHandler(&app.IncentivesKeeper)). + AddRoute(vestingtypes.RouterKey, vesting.NewVestingProposalHandler(&app.VestingKeeper)) + govConfig := govtypes.DefaultConfig() /* Example of setting gov params: @@ -586,36 +565,55 @@ func NewExocoreApp( // Set legacy router for backwards compatibility with gov v1beta1 govKeeper.SetLegacyRouter(govRouter) + // Evmos Keeper + app.InflationKeeper = inflationkeeper.NewKeeper( + keys[inflationtypes.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, app.BankKeeper, app.DistrKeeper, stakingKeeper, + authtypes.FeeCollectorName, + ) + + app.ClaimsKeeper = claimskeeper.NewKeeper( + appCodec, keys[claimstypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, app.BankKeeper, stakingKeeper, app.DistrKeeper, app.IBCKeeper.ChannelKeeper, + ) + // register the staking hooks // NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks - // NOTE: Slashing must be created before calling the Hooks method to avoid - // returning a Keeper without its table generated + // NOTE: Distr, Slashing and Claim must be created before calling the Hooks method to avoid returning a Keeper without its table generated stakingKeeper.SetHooks( stakingtypes.NewMultiStakingHooks( + app.DistrKeeper.Hooks(), app.SlashingKeeper.Hooks(), + app.ClaimsKeeper.Hooks(), ), ) app.StakingKeeper = *stakingKeeper - app.RecoveryKeeper = recoverykeeper.NewKeeper( - keys[recoverytypes.StoreKey], - appCodec, - authtypes.NewModuleAddress(govtypes.ModuleName), - app.AccountKeeper, - app.BankKeeper, - app.IBCKeeper.ChannelKeeper, - &app.TransferKeeper, + app.VestingKeeper = vestingkeeper.NewKeeper( + keys[vestingtypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName), appCodec, + app.AccountKeeper, app.BankKeeper, app.DistrKeeper, app.StakingKeeper, app.GovKeeper, ) app.Erc20Keeper = erc20keeper.NewKeeper( keys[erc20types.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName), - app.AccountKeeper, app.BankKeeper, app.EvmKeeper, app.StakingKeeper, app.RecoveryKeeper, + app.AccountKeeper, app.BankKeeper, app.EvmKeeper, app.StakingKeeper, app.ClaimsKeeper, + ) + + app.IncentivesKeeper = incentiveskeeper.NewKeeper( + keys[incentivestypes.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, app.BankKeeper, app.InflationKeeper, app.StakingKeeper, app.EvmKeeper, + ) + + app.RevenueKeeper = revenuekeeper.NewKeeper( + keys[revenuetypes.StoreKey], appCodec, authtypes.NewModuleAddress(govtypes.ModuleName), + app.BankKeeper, app.DistrKeeper, app.AccountKeeper, app.EvmKeeper, + authtypes.FeeCollectorName, ) app.TransferKeeper = transferkeeper.NewKeeper( appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName), - app.RecoveryKeeper, // ICS4 Wrapper: recovery IBC middleware + app.ClaimsKeeper, // ICS4 Wrapper: claims IBC middleware app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, scopedTransferKeeper, app.Erc20Keeper, // Add ERC20 Keeper for ERC20 transfers @@ -623,41 +621,21 @@ func NewExocoreApp( // set exoCore staking keepers app.AssetsKeeper = assetsKeeper.NewKeeper(keys[assetsTypes.StoreKey], appCodec) - app.DepositKeeper = depositKeeper.NewKeeper( - keys[depositTypes.StoreKey], - appCodec, - app.AssetsKeeper, - ) - app.OperatorKeeper = operatorKeeper.NewKeeper( - keys[operatorTypes.StoreKey], - appCodec, - app.AssetsKeeper, - operatorTypes.MockOracle{}, - operatorTypes.MockAvs{}, - delegationTypes.VirtualSlashKeeper{}, - ) - // todo: need to replace the virtual keepers with actual keepers after they have been - // implemented - app.DelegationKeeper = delegationKeeper.NewKeeper( - keys[depositTypes.StoreKey], - appCodec, - app.AssetsKeeper, - delegationTypes.VirtualSlashKeeper{}, - &app.OperatorKeeper, - ) + app.DepositKeeper = depositKeeper.NewKeeper(keys[depositTypes.StoreKey], appCodec, app.AssetsKeeper) + app.OperatorKeeper = operatorKeeper.NewKeeper(keys[operatorTypes.StoreKey], appCodec, app.AssetsKeeper, operatorTypes.MockOracle{}, operatorTypes.MockAvs{}, delegationTypes.VirtualSlashKeeper{}) + // todo: need to replace the virtual keepers with actual keepers after they have been implemented + app.DelegationKeeper = delegationKeeper.NewKeeper(keys[depositTypes.StoreKey], appCodec, app.AssetsKeeper, delegationTypes.VirtualSlashKeeper{}, &app.OperatorKeeper) app.OperatorKeeper.RegisterExpectDelegationInterface(&app.DelegationKeeper) app.WithdrawKeeper = *withdrawKeeper.NewKeeper(appCodec, keys[withdrawTypes.StoreKey], app.AssetsKeeper, app.DepositKeeper) app.RewardKeeper = *rewardKeeper.NewKeeper(appCodec, keys[rewardTypes.StoreKey], app.AssetsKeeper) - app.ExoSlashKeeper = slashKeeper.NewKeeper( - appCodec, - keys[exoslashTypes.StoreKey], - app.AssetsKeeper, - ) + app.ExoSlashKeeper = slashKeeper.NewKeeper(appCodec, keys[exoslashTypes.StoreKey], app.AssetsKeeper) // We call this after setting the hooks to ensure that the hooks are set on the keeper evmKeeper.WithPrecompiles( evmkeeper.AvailablePrecompiles( *stakingKeeper, + app.DistrKeeper, + app.VestingKeeper, app.AuthzKeeper, app.TransferKeeper, app.IBCKeeper.ChannelKeeper, @@ -672,24 +650,43 @@ func NewExocoreApp( epochsKeeper := epochskeeper.NewKeeper(appCodec, keys[epochstypes.StoreKey]) app.EpochsKeeper = *epochsKeeper.SetHooks( epochskeeper.NewMultiEpochHooks( - // insert epoch hooks receivers here + // insert epoch hooks receivers here + app.IncentivesKeeper.Hooks(), + app.InflationKeeper.Hooks(), ), ) app.GovKeeper = *govKeeper.SetHooks( - govtypes.NewMultiGovHooks(), + govtypes.NewMultiGovHooks( + app.ClaimsKeeper.Hooks(), + ), ) app.EvmKeeper = app.EvmKeeper.SetHooks( evmkeeper.NewMultiEvmHooks( app.Erc20Keeper.Hooks(), + app.IncentivesKeeper.Hooks(), + app.RevenueKeeper.Hooks(), + app.ClaimsKeeper.Hooks(), ), ) + app.RecoveryKeeper = recoverykeeper.NewKeeper( + keys[recoverytypes.StoreKey], + appCodec, + authtypes.NewModuleAddress(govtypes.ModuleName), + app.AccountKeeper, + app.BankKeeper, + app.IBCKeeper.ChannelKeeper, + app.TransferKeeper, + app.ClaimsKeeper, + ) + // NOTE: app.Erc20Keeper is already initialized elsewhere // Set the ICS4 wrappers for custom module middlewares app.RecoveryKeeper.SetICS4Wrapper(app.IBCKeeper.ChannelKeeper) + app.ClaimsKeeper.SetICS4Wrapper(app.RecoveryKeeper) // Override the ICS20 app module transferModule := transfer.NewAppModule(app.TransferKeeper) @@ -698,7 +695,7 @@ func NewExocoreApp( app.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, app.keys[icahosttypes.StoreKey], app.GetSubspace(icahosttypes.SubModuleName), - app.RecoveryKeeper, + app.ClaimsKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, @@ -715,19 +712,21 @@ func NewExocoreApp( transfer stack contains (from bottom to top): - ERC-20 Middleware - Recovery Middleware + - Airdrop Claims Middleware - IBC Transfer SendPacket, since it is originating from the application to core IBC: - transferKeeper.SendPacket -> recovery.SendPacket -> erc20.SendPacket -> channel.SendPacket + transferKeeper.SendPacket -> claim.SendPacket -> recovery.SendPacket -> erc20.SendPacket -> channel.SendPacket RecvPacket, message that originates from core IBC and goes down to app, the flow is the other way - channel.RecvPacket -> erc20.OnRecvPacket -> recovery.OnRecvPacket -> transfer.OnRecvPacket + channel.RecvPacket -> erc20.OnRecvPacket -> recovery.OnRecvPacket -> claim.OnRecvPacket -> transfer.OnRecvPacket */ // create IBC module from top to bottom of stack var transferStack porttypes.IBCModule transferStack = transfer.NewIBCModule(app.TransferKeeper) + transferStack = claims.NewIBCMiddleware(*app.ClaimsKeeper, transferStack) transferStack = recovery.NewIBCMiddleware(*app.RecoveryKeeper, transferStack) transferStack = erc20.NewIBCMiddleware(app.Erc20Keeper, transferStack) @@ -760,58 +759,19 @@ func NewExocoreApp( accountK, app.StakingKeeper, app.BaseApp.DeliverTx, encodingConfig.TxConfig, ), - auth.NewAppModule( - appCodec, - accountK, - authsims.RandomGenesisAccounts, - app.GetSubspace(authtypes.ModuleName), - ), + auth.NewAppModule(appCodec, accountK, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), bank.NewAppModule(appCodec, bankK, accountK, app.GetSubspace(banktypes.ModuleName)), capability.NewAppModule(appCodec, *app.CapabilityKeeper, false), - crisis.NewAppModule( - &app.CrisisKeeper, - skipGenesisInvariants, - app.GetSubspace(crisistypes.ModuleName), - ), - gov.NewAppModule( - appCodec, - govKeeper, - accountK, - bankK, - app.GetSubspace(govtypes.ModuleName), - ), - slashing.NewAppModule( - appCodec, - app.SlashingKeeper, - accountK, - bankK, - app.StakingKeeper, - app.GetSubspace(slashingtypes.ModuleName), - ), - staking.NewAppModule( - appCodec, - &app.StakingKeeper, - accountK, - bankK, - app.GetSubspace(stakingtypes.ModuleName), - ), + crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), + gov.NewAppModule(appCodec, govKeeper, accountK, bankK, app.GetSubspace(govtypes.ModuleName)), + slashing.NewAppModule(appCodec, app.SlashingKeeper, accountK, bankK, app.StakingKeeper, app.GetSubspace(slashingtypes.ModuleName)), + distr.NewAppModule(appCodec, app.DistrKeeper, accountK, bankK, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)), + staking.NewAppModule(appCodec, &app.StakingKeeper, accountK, bankK, app.GetSubspace(stakingtypes.ModuleName)), upgrade.NewAppModule(&app.UpgradeKeeper), evidence.NewAppModule(app.EvidenceKeeper), params.NewAppModule(app.ParamsKeeper), - feegrantmodule.NewAppModule( - appCodec, - accountK, - bankK, - app.FeeGrantKeeper, - app.interfaceRegistry, - ), - authzmodule.NewAppModule( - appCodec, - app.AuthzKeeper, - app.AccountKeeper, - app.BankKeeper, - app.interfaceRegistry, - ), + feegrantmodule.NewAppModule(appCodec, accountK, bankK, app.FeeGrantKeeper, app.interfaceRegistry), + authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper), // ibc modules @@ -819,18 +779,23 @@ func NewExocoreApp( ica.NewAppModule(nil, &app.ICAHostKeeper), transferModule, // Ethermint app modules - evm.NewAppModule( - app.EvmKeeper, - app.AccountKeeper, - app.GetSubspace(evmtypes.ModuleName), - ), + evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, app.GetSubspace(evmtypes.ModuleName)), feemarket.NewAppModule(app.FeeMarketKeeper, app.GetSubspace(feemarkettypes.ModuleName)), // Evmos app modules + inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, app.StakingKeeper, + app.GetSubspace(inflationtypes.ModuleName)), erc20.NewAppModule(app.Erc20Keeper, app.AccountKeeper, app.GetSubspace(erc20types.ModuleName)), + incentives.NewAppModule(app.IncentivesKeeper, app.AccountKeeper, + app.GetSubspace(incentivestypes.ModuleName)), epochs.NewAppModule(appCodec, app.EpochsKeeper), + claims.NewAppModule(appCodec, *app.ClaimsKeeper, + app.GetSubspace(claimstypes.ModuleName)), + vesting.NewAppModule(app.VestingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper), recovery.NewAppModule(*app.RecoveryKeeper, app.GetSubspace(recoverytypes.ModuleName)), + revenue.NewAppModule(app.RevenueKeeper, app.AccountKeeper, + app.GetSubspace(revenuetypes.ModuleName)), // exoCore app modules assets.NewAppModule(appCodec, app.AssetsKeeper), deposit.NewAppModule(appCodec, app.DepositKeeper), @@ -841,21 +806,20 @@ func NewExocoreApp( exoslash.NewAppModule(appCodec, app.ExoSlashKeeper), ) - // During begin block slashing happens after reward.BeginBlocker so that + // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, to keep the // CanWithdrawInvariant invariant. // NOTE: upgrade module must go first to handle software upgrades. // NOTE: staking module is required if HistoricalEntries param > 0. - // NOTE: capability module's beginblocker must come before any modules using capabilities - // (e.g. IBC) + // NOTE: capability module's beginblocker must come before any modules using capabilities (e.g. IBC) app.mm.SetOrderBeginBlockers( upgradetypes.ModuleName, capabilitytypes.ModuleName, - // Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at - // the beginning + // Note: epochs' begin should be "real" start of epochs, we keep epochs beginblock at the beginning epochstypes.ModuleName, feemarkettypes.ModuleName, evmtypes.ModuleName, + distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, stakingtypes.ModuleName, @@ -871,8 +835,13 @@ func NewExocoreApp( authz.ModuleName, feegrant.ModuleName, paramstypes.ModuleName, + vestingtypes.ModuleName, + inflationtypes.ModuleName, erc20types.ModuleName, + claimstypes.ModuleName, + incentivestypes.ModuleName, recoverytypes.ModuleName, + revenuetypes.ModuleName, consensusparamtypes.ModuleName, // ExoCore modules assetsTypes.ModuleName, @@ -891,9 +860,9 @@ func NewExocoreApp( stakingtypes.ModuleName, evmtypes.ModuleName, feemarkettypes.ModuleName, - // Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the - // end + // Note: epochs' endblock should be "real" end of epochs, we keep epochs endblock at the end epochstypes.ModuleName, + claimstypes.ModuleName, // no-op modules ibcexported.ModuleName, ibctransfertypes.ModuleName, @@ -901,6 +870,7 @@ func NewExocoreApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, + distrtypes.ModuleName, slashingtypes.ModuleName, genutiltypes.ModuleName, evidencetypes.ModuleName, @@ -909,8 +879,12 @@ func NewExocoreApp( paramstypes.ModuleName, upgradetypes.ModuleName, // Evmos modules + vestingtypes.ModuleName, + inflationtypes.ModuleName, erc20types.ModuleName, + incentivestypes.ModuleName, recoverytypes.ModuleName, + revenuetypes.ModuleName, consensusparamtypes.ModuleName, // ExoCore modules assetsTypes.ModuleName, @@ -932,11 +906,15 @@ func NewExocoreApp( capabilitytypes.ModuleName, authtypes.ModuleName, banktypes.ModuleName, + distrtypes.ModuleName, + // NOTE: staking requires the claiming hook + claimstypes.ModuleName, stakingtypes.ModuleName, slashingtypes.ModuleName, govtypes.ModuleName, ibcexported.ModuleName, // Ethermint modules + // evm module denomination is used by the revenue module, in AnteHandle evmtypes.ModuleName, // NOTE: feemarket module needs to be initialized before genutil module: // gentx transactions use MinGasPriceDecorator.AnteHandle @@ -958,44 +936,35 @@ func NewExocoreApp( rewardTypes.ModuleName, exoslashTypes.ModuleName, // Evmos modules + vestingtypes.ModuleName, + inflationtypes.ModuleName, erc20types.ModuleName, + incentivestypes.ModuleName, epochstypes.ModuleName, recoverytypes.ModuleName, + revenuetypes.ModuleName, // NOTE: crisis module must go at the end to check for invariants on each module crisistypes.ModuleName, consensusparamtypes.ModuleName, ) app.mm.RegisterInvariants(&app.CrisisKeeper) - app.configurator = module.NewConfigurator( - app.appCodec, - app.MsgServiceRouter(), - app.GRPCQueryRouter(), - ) + app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.mm.RegisterServices(app.configurator) // add test gRPC service for testing gRPC queries in isolation // testdata.RegisterTestServiceServer(app.GRPCQueryRouter(), testdata.TestServiceImpl{}) - // create the simulation manager and define the order of the modules for deterministic - // simulations + // create the simulation manager and define the order of the modules for deterministic simulations // // NOTE: this is not required apps that don't use the simulator for fuzz testing // transactions overrideModules := map[string]module.AppModuleSimulation{ - authtypes.ModuleName: auth.NewAppModule( - app.appCodec, - app.AccountKeeper, - authsims.RandomGenesisAccounts, - app.GetSubspace(authtypes.ModuleName), - ), + authtypes.ModuleName: auth.NewAppModule(app.appCodec, app.AccountKeeper, authsims.RandomGenesisAccounts, app.GetSubspace(authtypes.ModuleName)), } app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules) - autocliv1.RegisterQueryServer( - app.GRPCQueryRouter(), - runtimeservices.NewAutoCLIQueryService(app.mm.Modules), - ) + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules)) reflectionSvc, err := runtimeservices.NewReflectionService() if err != nil { @@ -1052,7 +1021,7 @@ func (app *ExocoreApp) setAnteHandler(txConfig client.TxConfig, maxGasWanted uin ExtensionOptionChecker: evmostypes.HasDynamicFeeExtensionOption, StakingKeeper: app.StakingKeeper, FeegrantKeeper: app.FeeGrantKeeper, - DistributionKeeper: app.RewardKeeper, + DistributionKeeper: app.DistrKeeper, IBCKeeper: app.IBCKeeper, SignModeHandler: txConfig.SignModeHandler(), SigGasConsumer: ante.SigVerificationGasConsumer, @@ -1080,24 +1049,17 @@ func (app *ExocoreApp) setPostHandler() { app.SetPostHandler(postHandler) } -// BeginBlocker runs the Tendermint ABCI BeginBlock logic. It executes state changes at the -// beginning of the new block for every registered module. If there is a registered fork at the -// current height, +// BeginBlocker runs the Tendermint ABCI BeginBlock logic. It executes state changes at the beginning +// of the new block for every registered module. If there is a registered fork at the current height, // BeginBlocker will schedule the upgrade plan and perform the state migration (if any). -func (app *ExocoreApp) BeginBlocker( - ctx sdk.Context, - req abci.RequestBeginBlock, -) abci.ResponseBeginBlock { +func (app *ExocoreApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock { // Perform any scheduled forks before executing the modules logic app.ScheduleForkUpgrade(ctx) return app.mm.BeginBlock(ctx, req) } // EndBlocker updates every end block -func (app *ExocoreApp) EndBlocker( - ctx sdk.Context, - req abci.RequestEndBlock, -) abci.ResponseEndBlock { +func (app *ExocoreApp) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.ResponseEndBlock { return app.mm.EndBlock(ctx, req) } @@ -1116,10 +1078,7 @@ func (app *ExocoreApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDe } // InitChainer updates at chain initialization -func (app *ExocoreApp) InitChainer( - ctx sdk.Context, - req abci.RequestInitChain, -) abci.ResponseInitChain { +func (app *ExocoreApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { var genesisState simapp.GenesisState if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil { panic(err) @@ -1224,12 +1183,7 @@ func (app *ExocoreApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.AP } func (app *ExocoreApp) RegisterTxService(clientCtx client.Context) { - authtx.RegisterTxService( - app.BaseApp.GRPCQueryRouter(), - clientCtx, - app.BaseApp.Simulate, - app.interfaceRegistry, - ) + authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry) } // RegisterTendermintService implements the Application.RegisterTendermintService method. @@ -1307,18 +1261,15 @@ func initParamsKeeper( paramsKeeper.Subspace(authtypes.ModuleName) paramsKeeper.Subspace(banktypes.ModuleName) paramsKeeper.Subspace(stakingtypes.ModuleName) + paramsKeeper.Subspace(distrtypes.ModuleName) paramsKeeper.Subspace(slashingtypes.ModuleName) - paramsKeeper.Subspace(govtypes.ModuleName). - // nolint: staticcheck - WithKeyTable(govv1.ParamKeyTable()) + paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govv1.ParamKeyTable()) //nolint: staticcheck paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(ibcexported.ModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) // ethermint subspaces - paramsKeeper.Subspace(evmtypes.ModuleName). - // nolint: staticcheck - WithKeyTable(evmtypes.ParamKeyTable()) + paramsKeeper.Subspace(evmtypes.ModuleName).WithKeyTable(evmtypes.ParamKeyTable()) //nolint: staticcheck return paramsKeeper } diff --git a/app/export.go b/app/export.go index b71e4fd1c..ed9e501c1 100644 --- a/app/export.go +++ b/app/export.go @@ -2,6 +2,7 @@ package app import ( "encoding/json" + "fmt" "cosmossdk.io/simapp" @@ -16,7 +17,9 @@ import ( slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + claimstypes "github.com/evmos/evmos/v14/x/claims/types" evmtypes "github.com/evmos/evmos/v14/x/evm/types" + inflationtypes "github.com/evmos/evmos/v14/x/inflation/types" "github.com/evmos/evmos/v14/encoding" ) @@ -54,12 +57,19 @@ func NewDefaultGenesisState(cdc codec.Codec) simapp.GenesisState { evmGenesis.Params.EvmDenom = utils.BaseDenom defaultGenesis[evmtypes.ModuleName] = cdc.MustMarshalJSON(&evmGenesis) + // inflation module + inflationGenesis := inflationtypes.GenesisState{} + rawGenesis = defaultGenesis[inflationtypes.ModuleName] + cdc.MustUnmarshalJSON(rawGenesis, &inflationGenesis) + inflationGenesis.Params.MintDenom = utils.BaseDenom + defaultGenesis[inflationtypes.ModuleName] = cdc.MustMarshalJSON(&inflationGenesis) + // claims module - // claimsGenesis := claimstypes.GenesisState{} - // rawGenesis = defaultGenesis[claimstypes.ModuleName] - // cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis) - // claimsGenesis.Params.ClaimsDenom = utils.BaseDenom - // defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis) + claimsGenesis := claimstypes.GenesisState{} + rawGenesis = defaultGenesis[claimstypes.ModuleName] + cdc.MustUnmarshalJSON(rawGenesis, &claimsGenesis) + claimsGenesis.Params.ClaimsDenom = utils.BaseDenom + defaultGenesis[claimstypes.ModuleName] = cdc.MustMarshalJSON(&claimsGenesis) return defaultGenesis } @@ -69,8 +79,7 @@ func NewDefaultGenesisState(cdc codec.Codec) simapp.GenesisState { func (app *ExocoreApp) ExportAppStateAndValidators( forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string, ) (servertypes.ExportedApp, error) { - // Creates context with current height and checks txs for ctx to be usable by start of next - // block + // Creates context with current height and checks txs for ctx to be usable by start of next block ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) // We export at last height + 1, because that's the height at which @@ -107,52 +116,141 @@ func (app *ExocoreApp) ExportAppStateAndValidators( // NOTE zero height genesis is a temporary feature which will be deprecated // // in favor of export at a block height -func (app *ExocoreApp) prepForZeroHeightGenesis( - ctx sdk.Context, - _ []string, -) error { - // allowedAddrsMap := make(map[string]bool) - - // for _, addr := range jailAllowedAddrs { - // _, err := sdk.ValAddressFromBech32(addr) - // if err != nil { - // return err - // } - // allowedAddrsMap[addr] = true - // } +func (app *ExocoreApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) error { + applyAllowedAddrs := false + + // check if there is a allowed address list + if len(jailAllowedAddrs) > 0 { + applyAllowedAddrs = true + } + + allowedAddrsMap := make(map[string]bool) + + for _, addr := range jailAllowedAddrs { + _, err := sdk.ValAddressFromBech32(addr) + if err != nil { + return err + } + allowedAddrsMap[addr] = true + } /* Just to be safe, assert the invariants on current state. */ app.CrisisKeeper.AssertInvariants(ctx) /* Handle fee distribution state. */ - // TODO(mm): replace with new reward distribution keeper. + // withdraw all validator commission + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) + return false + }) // withdraw all delegator rewards + dels := app.StakingKeeper.GetAllDelegations(ctx) + for _, delegation := range dels { + valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) + if err != nil { + return err + } + + delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) + if err != nil { + return err + } + _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) + } // clear validator slash events + app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) // clear validator historical rewards + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) // set context height to zero height := ctx.BlockHeight() ctx = ctx.WithBlockHeight(0) // reinitialize all validators + app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { + // donate any unwithdrawn outstanding reward fraction tokens to the community pool + scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) + feePool := app.DistrKeeper.GetFeePool(ctx) + feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) + app.DistrKeeper.SetFeePool(ctx, feePool) + + err := app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) + // this lets us stop in case there's an error + return err != nil + }) // reinitialize all delegations + for _, del := range dels { + valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) + if err != nil { + return err + } + delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress) + if err != nil { + return err + } + err = app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr) + if err != nil { + return err + } + err = app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) + if err != nil { + return err + } + } // reset context height ctx = ctx.WithBlockHeight(height) /* Handle staking state. */ - // not supported: iterate through redelegations, reset creation height + // iterate through redelegations, reset creation height + app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { + for i := range red.Entries { + red.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetRedelegation(ctx, red) + return false + }) // iterate through unbonding delegations, reset creation height + app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { + for i := range ubd.Entries { + ubd.Entries[i].CreationHeight = 0 + } + app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) + return false + }) // Iterate through validators by power descending, reset bond heights, and // update bond intra-tx counters. + store := ctx.KVStore(app.keys[stakingtypes.StoreKey]) + iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) + counter := int16(0) + + for ; iter.Valid(); iter.Next() { + addr := sdk.ValAddress(iter.Key()[1:]) + validator, found := app.StakingKeeper.GetValidator(ctx, addr) + if !found { + return fmt.Errorf("expected validator %s not found", addr) + } + + validator.UnbondingHeight = 0 + if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { + validator.Jailed = true + } + + app.StakingKeeper.SetValidator(ctx, validator) + counter++ + } + + if err := iter.Close(); err != nil { + return err + } if _, err := app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx); err != nil { return err diff --git a/go.mod b/go.mod index 54d9e0dc9..e11e6bcf5 100644 --- a/go.mod +++ b/go.mod @@ -215,12 +215,14 @@ replace ( github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // use Cosmos-SDK fork to enable Ledger functionality github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.4-evmos.2 + //github.com/cosmos/cosmos-sdk => ../cosmos-sdk //fix cosmos-sdk error github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10 // use Evmos geth fork github.com/ethereum/go-ethereum => github.com/evmos/go-ethereum v1.10.26-evmos-rc2 - // use exocore fork of evmos TODO - github.com/evmos/evmos/v14 => github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972 + // use exocore fork of evmos + github.com/evmos/evmos/v14 => github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4 + //github.com/evmos/evmos/v14 => ../ExocoreNetwork/evmos // Security Advisory https://github.com/advisories/GHSA-h395-qcrw-5vmq github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 // replace broken goleveldb diff --git a/go.sum b/go.sum index f4be6702e..05e975d6e 100644 --- a/go.sum +++ b/go.sum @@ -545,10 +545,10 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4 h1:55qBGHyCOvxxu4kxh+IY6T1pElfyQey5vRKTs25Gc6s= +github.com/ExocoreNetwork/evmos/v14 v14.1.1-0.20240205024453-5e8090e42ef4/go.mod h1:Hi3CAMxAE+H7Fs7sSHsHKb4DZIURk+trop+mMrjlZqw= github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= -github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972 h1:6oBb1Zhtar2hzju1Fv7cZ8mZVJoJ+K5DvbHt/nW0fyU= -github.com/MaxMustermann2/evmos/v14 v14.0.0-20240326155756-4f464426e972/go.mod h1:Hi3CAMxAE+H7Fs7sSHsHKb4DZIURk+trop+mMrjlZqw= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE= github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 h1:TngWCqHvy9oXAN6lEVMRuU21PR1EtLVZJmdB18Gu3Rw= diff --git a/precompiles/delegation/delegation_test.go b/precompiles/delegation/delegation_test.go index 84ba070d3..9a96bc840 100644 --- a/precompiles/delegation/delegation_test.go +++ b/precompiles/delegation/delegation_test.go @@ -17,6 +17,7 @@ import ( "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/evmos/evmos/v14/utils" "github.com/evmos/evmos/v14/x/evm/statedb" evmtypes "github.com/evmos/evmos/v14/x/evm/types" ) @@ -96,11 +97,11 @@ func (s *DelegationPrecompileSuite) TestRunDelegateToThroughClientChain() { } commonMalleate := func() (common.Address, []byte) { // prepare the call input for delegation test - // valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) - // s.Require().NoError(err) - // val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) - // coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) - // s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) + valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) + s.Require().NoError(err) + val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) + coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) + s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) input, err := s.precompile.Pack( delegation.MethodDelegateToThroughClientChain, uint16(clientChainLzID), @@ -338,11 +339,11 @@ func (s *DelegationPrecompileSuite) TestRunUnDelegateFromThroughClientChain() { } commonMalleate := func() (common.Address, []byte) { // prepare the call input for delegation test - // valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) - // s.Require().NoError(err) - // val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) - // coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) - // s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) + valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) + s.Require().NoError(err) + val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) + coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) + s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) input, err := s.precompile.Pack( delegation.MethodUndelegateFromThroughClientChain, uint16(clientChainLzID), diff --git a/precompiles/deposit/deposit_test.go b/precompiles/deposit/deposit_test.go index 7ee3b2470..30eb9e5f2 100644 --- a/precompiles/deposit/deposit_test.go +++ b/precompiles/deposit/deposit_test.go @@ -7,9 +7,11 @@ import ( "github.com/ExocoreNetwork/exocore/precompiles/deposit" assetstype "github.com/ExocoreNetwork/exocore/x/assets/types" deposittype "github.com/ExocoreNetwork/exocore/x/deposit/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/ethereum/go-ethereum/common" ethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" + "github.com/evmos/evmos/v14/utils" evmtypes "github.com/evmos/evmos/v14/x/evm/types" ) @@ -58,11 +60,11 @@ func (s *DepositPrecompileSuite) TestRunDepositTo() { opAmount := big.NewInt(100) assetAddr := usdtAddress commonMalleate := func() (common.Address, []byte) { - // valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) - // s.Require().NoError(err) - // val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) - // coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) - // s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) + valAddr, err := sdk.ValAddressFromBech32(s.Validators[0].OperatorAddress) + s.Require().NoError(err) + val, _ := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) + coins := sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, sdk.NewInt(1e18))) + s.App.DistrKeeper.AllocateTokensToValidator(s.Ctx, val, sdk.NewDecCoinsFromCoins(coins...)) input, err := s.precompile.Pack( deposit.MethodDepositTo, uint16(clientChainLzID), diff --git a/scripts/protocgen.sh b/scripts/protocgen.sh index 75f44a0a5..06456795b 100755 --- a/scripts/protocgen.sh +++ b/scripts/protocgen.sh @@ -11,13 +11,13 @@ proto_dirs=$(find ./proto -path -prune -o -name '*.proto' -print0 | xargs -0 -n1 #proto_dirs="proto/exocore/reward/v1beta1" #echo $proto_dirs for dir in $proto_dirs; do - proto_files=$(find "${dir}" -maxdepth 3 -name '*.proto') - for file in $proto_files; do - # Check if the go_package in the file is pointing to evmos - if grep -q "option go_package.*exocore" "$file"; then - buf generate --template proto/buf.gen.gogo.yaml "$file" - fi - done + proto_files=$(find "${dir}" -maxdepth 3 -name '*.proto') + for file in $proto_files; do + # Check if the go_package in the file is pointing to evmos + if grep -q "option go_package.*exocore" "$file"; then + buf generate --template proto/buf.gen.gogo.yaml "$file" + fi + done done # move proto files to the right places diff --git a/testutil/staking-rewards.go b/testutil/staking-rewards.go new file mode 100644 index 000000000..ac6cabefa --- /dev/null +++ b/testutil/staking-rewards.go @@ -0,0 +1,148 @@ +package testutil + +import ( + "fmt" + "testing" + + sdkmath "cosmossdk.io/math" + "github.com/ExocoreNetwork/exocore/app" + testutiltx "github.com/ExocoreNetwork/exocore/testutil/tx" + "github.com/ExocoreNetwork/exocore/utils" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/staking" + stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" + teststaking "github.com/cosmos/cosmos-sdk/x/staking/testutil" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/stretchr/testify/require" +) + +// CreateValidator creates a validator with the provided public key and stake amount +func CreateValidator(ctx sdk.Context, t *testing.T, pubKey cryptotypes.PubKey, sk stakingkeeper.Keeper, stakeAmt sdkmath.Int) { + zeroDec := sdk.ZeroDec() + stakingParams := sk.GetParams(ctx) + stakingParams.BondDenom = sk.BondDenom(ctx) + stakingParams.MinCommissionRate = zeroDec + err := sk.SetParams(ctx, stakingParams) + require.NoError(t, err) + + stakingHelper := teststaking.NewHelper(t, ctx, &sk) + stakingHelper.Commission = stakingtypes.NewCommissionRates(zeroDec, zeroDec, zeroDec) + stakingHelper.Denom = sk.BondDenom(ctx) + + valAddr := sdk.ValAddress(pubKey.Address()) + stakingHelper.CreateValidator(valAddr, pubKey, stakeAmt, true) +} + +// PrepareAccountsForDelegationRewards prepares the test suite for testing to withdraw delegation rewards. +// +// Balance is the amount of tokens that will be left in the account after the setup is done. +// For each defined reward, a validator is created and tokens are allocated to it using the distribution keeper, +// such that the given amount of tokens is outstanding as a staking reward for the account. +// +// The setup is done in the following way: +// - Fund the account with the given Address with the given balance. +// - If the given balance is zero, the account will be created with zero balance. +// +// For every reward defined in the rewards argument, the following steps are executed: +// - Set up a validator with zero commission and delegate to it -> the account delegation will be 50% of the total delegation. +// - Allocate rewards to the validator. +// +// The function returns the updated context along with a potential error. +func PrepareAccountsForDelegationRewards(t *testing.T, ctx sdk.Context, app *app.ExocoreApp, addr sdk.AccAddress, balance sdkmath.Int, rewards ...sdkmath.Int) (sdk.Context, error) { + // Calculate the necessary amount of tokens to fund the account in order for the desired residual balance to + // be left after creating Validators and delegating to them. + totalRewards := sdk.ZeroInt() + for _, reward := range rewards { + totalRewards = totalRewards.Add(reward) + } + totalNeededBalance := balance.Add(totalRewards) + + if totalNeededBalance.IsZero() { + app.AccountKeeper.SetAccount(ctx, app.AccountKeeper.NewAccountWithAddress(ctx, addr)) + } else { + // Fund account with enough tokens to stake them + err := FundAccountWithBaseDenom(ctx, app.BankKeeper, addr, totalNeededBalance.Int64()) + if err != nil { + return sdk.Context{}, fmt.Errorf("failed to fund account: %s", err.Error()) + } + } + + if totalRewards.IsZero() { + return ctx, nil + } + + // reset historical count in distribution keeper which is necessary + // for the delegation rewards to be calculated correctly + app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) + + // set distribution module account balance which pays out the rewards + distrAcc := app.DistrKeeper.GetDistributionAccount(ctx) + err := FundModuleAccount(ctx, app.BankKeeper, distrAcc.GetName(), sdk.NewCoins(sdk.NewCoin(utils.BaseDenom, totalRewards))) + if err != nil { + return sdk.Context{}, fmt.Errorf("failed to fund distribution module account: %s", err.Error()) + } + app.AccountKeeper.SetModuleAccount(ctx, distrAcc) + + for _, reward := range rewards { + if reward.IsZero() { + continue + } + + // Set up validator and delegate to it + privKey := ed25519.GenPrivKey() + addr2, _ := testutiltx.NewAccAddressAndKey() + err := FundAccountWithBaseDenom(ctx, app.BankKeeper, addr2, reward.Int64()) + if err != nil { + return sdk.Context{}, fmt.Errorf("failed to fund validator account: %s", err.Error()) + } + + zeroDec := sdk.ZeroDec() + stakingParams := app.StakingKeeper.GetParams(ctx) + stakingParams.BondDenom = utils.BaseDenom + stakingParams.MinCommissionRate = zeroDec + err = app.StakingKeeper.SetParams(ctx, stakingParams) + require.NoError(t, err) + + stakingHelper := teststaking.NewHelper(t, ctx, &app.StakingKeeper) + stakingHelper.Commission = stakingtypes.NewCommissionRates(zeroDec, zeroDec, zeroDec) + stakingHelper.Denom = utils.BaseDenom + + valAddr := sdk.ValAddress(addr2.Bytes()) + // self-delegate the same amount of tokens as the delegate Address also stakes + // this ensures, that the delegation rewards are 50% of the total rewards + stakingHelper.CreateValidator(valAddr, privKey.PubKey(), reward, true) + stakingHelper.Delegate(addr, valAddr, reward) + + // end block to bond validator and increase block height + // Not using Commit() here because code panics due to invalid block height + staking.EndBlocker(ctx, &app.StakingKeeper) + + // allocate rewards to validator (of these 50% will be paid out to the delegator) + validator := app.StakingKeeper.Validator(ctx, valAddr) + allocatedRewards := sdk.NewDecCoins(sdk.NewDecCoin(utils.BaseDenom, reward.Mul(sdk.NewInt(2)))) + app.DistrKeeper.AllocateTokensToValidator(ctx, validator, allocatedRewards) + } + + return ctx, nil +} + +// GetTotalDelegationRewards returns the total delegation rewards that are currently +// outstanding for the given Address. +func GetTotalDelegationRewards(ctx sdk.Context, distributionKeeper distributionkeeper.Keeper, addr sdk.AccAddress) (sdk.DecCoins, error) { + querier := distributionkeeper.NewQuerier(distributionKeeper) + resp, err := querier.DelegationTotalRewards( + ctx, + &distributiontypes.QueryDelegationTotalRewardsRequest{ + DelegatorAddress: addr.String(), + }, + ) + if err != nil { + return nil, err + } + + return resp.Total, nil +} diff --git a/x/dogfood/keeper/impl_sdk.go b/x/dogfood/keeper/impl_sdk.go index 7986c2950..5b342af5c 100644 --- a/x/dogfood/keeper/impl_sdk.go +++ b/x/dogfood/keeper/impl_sdk.go @@ -13,11 +13,7 @@ import ( // interface guards var ( - // the slashing module is responsible for downtime slashing. it tracks signing info and then - // asks the staking module (dogfood in our case) to slash the operator. _ slashingtypes.StakingKeeper = Keeper{} - // the evidence module is responsible for handling equivocation evidence. it validates the - // evidence and then asks the staking module (dogfood in our case) to slash the operator. _ evidencetypes.StakingKeeper = Keeper{} _ genutiltypes.StakingKeeper = Keeper{} _ clienttypes.StakingKeeper = Keeper{} // implemented in `validators.go` @@ -30,8 +26,11 @@ func (k Keeper) GetParams(sdk.Context) stakingtypes.Params { } // IterateValidators is an implementation of the staking interface expected by the SDK's -// slashing module. The slashing module uses it at genesis to store a mapping of pub key -// to cons address (which is done by our operator module), +// slashing module. The slashing module uses it for two purposes: once at genesis to +// store a mapping of pub key to cons address (which is done by our operator module), +// and then during the invariants check to ensure that the total delegated amount +// matches that of each validator. Ideally, this invariant should be implemented +// by the delegation and/or deposit module(s) instead. func (k Keeper) IterateValidators(sdk.Context, func(index int64, validator stakingtypes.ValidatorI) (stop bool), ) { diff --git a/x/evm/keeper/precompiles.go b/x/evm/keeper/precompiles.go index 1246457ea..a26d157bc 100644 --- a/x/evm/keeper/precompiles.go +++ b/x/evm/keeper/precompiles.go @@ -19,19 +19,25 @@ import ( withdrawPrecompile "github.com/ExocoreNetwork/exocore/precompiles/withdraw" exoslashKeeper "github.com/ExocoreNetwork/exocore/x/slash/keeper" authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper" + distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" channelkeeper "github.com/cosmos/ibc-go/v7/modules/core/04-channel/keeper" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/vm" + distprecompile "github.com/evmos/evmos/v14/precompiles/distribution" ics20precompile "github.com/evmos/evmos/v14/precompiles/ics20" stakingprecompile "github.com/evmos/evmos/v14/precompiles/staking" + vestingprecompile "github.com/evmos/evmos/v14/precompiles/vesting" transferkeeper "github.com/evmos/evmos/v14/x/ibc/transfer/keeper" + vestingkeeper "github.com/evmos/evmos/v14/x/vesting/keeper" ) // AvailablePrecompiles returns the list of all available precompiled contracts. // NOTE: this should only be used during initialization of the Keeper. func AvailablePrecompiles( stakingKeeper stakingkeeper.Keeper, + distributionKeeper distributionkeeper.Keeper, + vestingKeeper vestingkeeper.Keeper, authzKeeper authzkeeper.Keeper, transferKeeper transferkeeper.Keeper, channelKeeper channelkeeper.Keeper, @@ -50,53 +56,39 @@ func AvailablePrecompiles( panic(fmt.Errorf("failed to load staking precompile: %w", err)) } - ibcTransferPrecompile, err := ics20precompile.NewPrecompile( - transferKeeper, - channelKeeper, - authzKeeper, - ) + distributionPrecompile, err := distprecompile.NewPrecompile(distributionKeeper, authzKeeper) + if err != nil { + panic(fmt.Errorf("failed to load distribution precompile: %w", err)) + } + + ibcTransferPrecompile, err := ics20precompile.NewPrecompile(transferKeeper, channelKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load ICS20 precompile: %w", err)) } + vestingPrecompile, err := vestingprecompile.NewPrecompile(vestingKeeper, authzKeeper) + if err != nil { + panic(fmt.Errorf("failed to load vesting precompile: %w", err)) + } + // add exoCore chain preCompiles - depositPrecompile, err := depositprecompile.NewPrecompile( - stakingStateKeeper, - depositKeeper, - authzKeeper, - ) + depositPrecompile, err := depositprecompile.NewPrecompile(stakingStateKeeper, depositKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load deposit precompile: %w", err)) } - delegationPrecompile, err := delegationprecompile.NewPrecompile( - stakingStateKeeper, - delegationKeeper, - authzKeeper, - ) + delegationPrecompile, err := delegationprecompile.NewPrecompile(stakingStateKeeper, delegationKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load delegation precompile: %w", err)) } - withdrawPrecompile, err := withdrawPrecompile.NewPrecompile( - stakingStateKeeper, - withdrawKeeper, - authzKeeper, - ) + withdrawPrecompile, err := withdrawPrecompile.NewPrecompile(stakingStateKeeper, withdrawKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load withdraw precompile: %w", err)) } - slashPrecompile, err := slashPrecompile.NewPrecompile( - stakingStateKeeper, - slashKeeper, - authzKeeper, - ) + slashPrecompile, err := slashPrecompile.NewPrecompile(stakingStateKeeper, slashKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load slash precompile: %w", err)) } - rewardPrecompile, err := rewardPrecompile.NewPrecompile( - stakingStateKeeper, - rewardKeeper, - authzKeeper, - ) + rewardPrecompile, err := rewardPrecompile.NewPrecompile(stakingStateKeeper, rewardKeeper, authzKeeper) if err != nil { panic(fmt.Errorf("failed to load reward precompile: %w", err)) } @@ -107,14 +99,14 @@ func AvailablePrecompiles( precompiles[delegationPrecompile.Address()] = delegationPrecompile precompiles[stakingPrecompile.Address()] = stakingPrecompile + precompiles[distributionPrecompile.Address()] = distributionPrecompile + precompiles[vestingPrecompile.Address()] = vestingPrecompile precompiles[ibcTransferPrecompile.Address()] = ibcTransferPrecompile return precompiles } // WithPrecompiles sets the available precompiled contracts. -func (k *Keeper) WithPrecompiles( - precompiles map[common.Address]vm.PrecompiledContract, -) *Keeper { +func (k *Keeper) WithPrecompiles(precompiles map[common.Address]vm.PrecompiledContract) *Keeper { if k.precompiles != nil { panic("available precompiles map already set") } diff --git a/x/evm/types/params.go b/x/evm/types/params.go index 6349ee5ee..0dcacfceb 100644 --- a/x/evm/types/params.go +++ b/x/evm/types/params.go @@ -11,7 +11,9 @@ var ( DefaultEVMDenom = utils.BaseDenom ExocoreAvailableEVMExtensions = []string{ "0x0000000000000000000000000000000000000800", // Staking precompile + "0x0000000000000000000000000000000000000801", // Distribution precompile "0x0000000000000000000000000000000000000802", // ICS20 transfer precompile + "0x0000000000000000000000000000000000000803", // Vesting precompile "0x0000000000000000000000000000000000000804", // deposit precompile "0x0000000000000000000000000000000000000805", // delegation precompile "0x0000000000000000000000000000000000000806", // reward precompile @@ -22,6 +24,8 @@ var ( // ExocoreEvmDefaultParams returns default evm parameters // ExtraEIPs is empty to prevent overriding the latest hard fork instruction set +// ActivePrecompiles is empty to prevent overriding the default precompiles +// from the EVM configuration. func ExocoreEvmDefaultParams() evmtype.Params { return evmtype.Params{ EvmDenom: DefaultEVMDenom, diff --git a/x/reward/keeper/claim_reward.go b/x/reward/keeper/claim_reward.go index aa7af650e..182b074f8 100644 --- a/x/reward/keeper/claim_reward.go +++ b/x/reward/keeper/claim_reward.go @@ -149,13 +149,3 @@ func (k Keeper) RewardForWithdraw(ctx sdk.Context, event *RewardParams) error { } return nil } - -// WithdrawDelegationRewards is an implementation of a function in the distribution interface. -// Since this module acts as the distribution module for our network, this function is here. -// When implemented, this function should find the pending (native token) rewards for the -// specified delegator and validator address combination and send them to the delegator address. -func (Keeper) WithdrawDelegationRewards( - sdk.Context, sdk.AccAddress, sdk.ValAddress, -) (sdk.Coins, error) { - return nil, rtypes.ErrNotSupportYet -} diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go index 320b86b51..75688e4d1 100644 --- a/x/reward/types/errors.go +++ b/x/reward/types/errors.go @@ -14,5 +14,4 @@ var ( ErrNoParamsKey = errorsmod.Register(ModuleName, 2, "there is no stored key for params") ErrRewardAmountIsNegative = errorsmod.Register(ModuleName, 3, "the reward amount is negative") ErrRewardAssetNotExist = errorsmod.Register(ModuleName, 4, "the reward asset doesn't exist") - ErrNotSupportYet = errorsmod.Register(ModuleName, 5, "don't have supported it yet") )