diff --git a/app/app.go b/app/app.go index 0932d390..1335c020 100644 --- a/app/app.go +++ b/app/app.go @@ -395,7 +395,7 @@ func NewKYVEApp( // ... other modules keepers app.GlobalKeeper = *globalKeeper.NewKeeper(appCodec, keys[globalTypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String()) - app.TeamKeeper = *teamKeeper.NewKeeper(appCodec, keys[teamTypes.StoreKey], app.AccountKeeper, app.BankKeeper) + app.TeamKeeper = *teamKeeper.NewKeeper(appCodec, keys[teamTypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.UpgradeKeeper) app.PoolKeeper = *poolKeeper.NewKeeper( appCodec, @@ -407,7 +407,9 @@ func NewKYVEApp( app.AccountKeeper, app.BankKeeper, app.DistributionKeeper, + app.MintKeeper, app.UpgradeKeeper, + app.TeamKeeper, ) app.StakersKeeper = *stakersKeeper.NewKeeper( @@ -632,10 +634,10 @@ func NewKYVEApp( ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper), // KYVE - bundles.NewAppModule(appCodec, app.BundlesKeeper, app.AccountKeeper, app.BankKeeper), + bundles.NewAppModule(appCodec, app.BundlesKeeper, app.AccountKeeper, app.BankKeeper, app.DistributionKeeper, app.MintKeeper, app.UpgradeKeeper, app.PoolKeeper, app.TeamKeeper), delegation.NewAppModule(appCodec, app.DelegationKeeper, app.AccountKeeper, app.BankKeeper), global.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.GlobalKeeper, app.UpgradeKeeper), - pool.NewAppModule(appCodec, app.PoolKeeper, app.AccountKeeper, app.BankKeeper), + pool.NewAppModule(appCodec, app.PoolKeeper, app.AccountKeeper, app.BankKeeper, app.UpgradeKeeper), query.NewAppModule(appCodec, app.QueryKeeper, app.AccountKeeper, app.BankKeeper), stakers.NewAppModule(appCodec, app.StakersKeeper, app.AccountKeeper, app.BankKeeper), team.NewAppModule(appCodec, app.BankKeeper, app.MintKeeper, app.TeamKeeper, app.UpgradeKeeper), @@ -652,6 +654,8 @@ func NewKYVEApp( minttypes.ModuleName, // NOTE: x/team must be run before x/distribution and after x/mint. teamTypes.ModuleName, + // NOTE: x/bundles must be run before x/distribution and after x/team. + bundlesTypes.ModuleName, distrtypes.ModuleName, slashingtypes.ModuleName, evidencetypes.ModuleName, @@ -675,7 +679,6 @@ func NewKYVEApp( poolTypes.ModuleName, stakersTypes.ModuleName, delegationTypes.ModuleName, - bundlesTypes.ModuleName, queryTypes.ModuleName, globalTypes.ModuleName, ) @@ -803,6 +806,7 @@ func NewKYVEApp( v1p3.CreateUpgradeHandler( app.mm, app.configurator, + app.PoolKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, diff --git a/app/upgrades/v1_3/upgrade.go b/app/upgrades/v1_3/upgrade.go index 3a33f26a..b8664693 100644 --- a/app/upgrades/v1_3/upgrade.go +++ b/app/upgrades/v1_3/upgrade.go @@ -5,9 +5,14 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" - bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/tendermint/tendermint/libs/log" + // Pool + poolKeeper "github.com/KYVENetwork/chain/x/pool/keeper" + poolTypes "github.com/KYVENetwork/chain/x/pool/types" + // Upgrade + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + // Auth authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" vestingExported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" @@ -20,6 +25,7 @@ import ( func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, + poolKeeper poolKeeper.Keeper, accountKeeper authKeeper.AccountKeeper, bankKeeper bankKeeper.Keeper, stakingKeeper stakingKeeper.Keeper, @@ -27,6 +33,8 @@ func CreateUpgradeHandler( return func(ctx sdk.Context, _ upgradeTypes.Plan, vm module.VersionMap) (module.VersionMap, error) { logger := ctx.Logger().With("upgrade", UpgradeName) + CheckPoolAccounts(ctx, logger, poolKeeper) + if ctx.ChainID() == MainnetChainID { for _, address := range InvestorAccounts { TrackInvestorDelegation(ctx, logger, sdk.MustAccAddressFromBech32(address), accountKeeper, bankKeeper, stakingKeeper) @@ -72,3 +80,15 @@ func TrackInvestorDelegation(ctx sdk.Context, logger log.Logger, address sdk.Acc ak.SetAccount(ctx, account) } } + +// CheckPoolAccounts ensures that each pool account exists post upgrade. +func CheckPoolAccounts(ctx sdk.Context, logger log.Logger, keeper poolKeeper.Keeper) { + pools := keeper.GetAllPools(ctx) + + for _, pool := range pools { + keeper.EnsurePoolAccount(ctx, pool.Id) + + name := fmt.Sprintf("%s/%d", poolTypes.ModuleName, pool.Id) + logger.Info("successfully initialised pool account", "name", name) + } +} diff --git a/config.yml b/config.yml index 35b2c1ee..a2ef69a8 100644 --- a/config.yml +++ b/config.yml @@ -128,9 +128,11 @@ genesis: clawback: "1804978800" commencement: "1647212400" pool: - pool_count: "2" + params: + protocol_inflation_share: "0.04" + pool_count: "1" pool_list: - - config: "ar://tMTrJ8E3QgBNLz0-lyn6QrxasEIX46d14QFVmBWshSI" + - config: "{\"network\":\"kyve-1\",\"rpc\":\"https://rpc-eu-1.kyve.network\"}" current_compression_id: "1" current_index: "0" current_key: "" @@ -138,20 +140,20 @@ genesis: current_summary: "" funders: [] id: "0" - logo: "ar://E3jXAOeJ3El7HQgOf_NtSOwVE7Sd0M4g4bYqjCBH9CU" + logo: "" max_bundle_size: "100" min_delegation: "100000000000" - name: "Avalanche // C-Chain" + name: "KYVE // Mainnet" operating_cost: "2500000000" disabled: false - runtime: '@kyvejs/evm' - start_key: "0" + runtime: '@kyvejs/tendermint-bsync' + start_key: "1" total_bundles: "0" total_funds: "0" upload_interval: "60" protocol: - version: "1.0.0-beta.5" - binaries: "{\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Fevm%401.0.0-beta.5/kyve-macos-x64.zip\"}" + version: "1.0.0" + binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-macos-x64.zip\"}" last_upgrade: "0" upgrade_plan: version: "" diff --git a/docs/swagger.yml b/docs/swagger.yml index 2e1beef1..73cef6ff 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -578,6 +578,12 @@ paths: commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE + earned through commission title: >- StakerMetadata contains static information for a staker @@ -3838,6 +3844,12 @@ paths: commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE + earned through commission title: >- StakerMetadata contains static information for a staker @@ -4482,6 +4494,16 @@ paths: type: string format: uint64 description: commission_change_time ... + pool_params: + description: pool_params ... + type: object + properties: + protocol_inflation_share: + type: string + description: protocol_inflation_share ... + pool_inflation_payout_rate: + type: string + description: pool_inflation_payout_rate ... description: QueryParamsResponse ... default: description: An unexpected error response. @@ -4976,6 +4998,13 @@ paths: - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING default: POOL_STATUS_UNSPECIFIED + account: + type: string + description: account ... + account_balance: + type: string + format: uint64 + description: account_balance ... description: >- QueryPoolResponse is the response type for the Query/Pool RPC method. @@ -5485,6 +5514,13 @@ paths: - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING default: POOL_STATUS_UNSPECIFIED + account: + type: string + description: account ... + account_balance: + type: string + format: uint64 + description: account_balance ... description: PoolResponse ... description: pools ... pagination: @@ -5856,6 +5892,12 @@ paths: title: |- CommissionChangeEntry shows when the old commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE earned + through commission title: StakerMetadata contains static information for a staker self_delegation: type: string @@ -6279,6 +6321,12 @@ paths: title: |- CommissionChangeEntry shows when the old commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE earned + through commission title: StakerMetadata contains static information for a staker self_delegation: type: string @@ -6807,6 +6855,12 @@ paths: commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE + earned through commission title: >- StakerMetadata contains static information for a staker @@ -7280,6 +7334,12 @@ paths: title: |- CommissionChangeEntry shows when the old commission of a staker will change to the new commission + commission_rewards: + type: string + format: uint64 + title: >- + commission_rewards are the rewards in $KYVE earned + through commission title: StakerMetadata contains static information for a staker self_delegation: type: string diff --git a/proto/kyve/bundles/v1beta1/events.proto b/proto/kyve/bundles/v1beta1/events.proto index f82143f0..749c9e97 100644 --- a/proto/kyve/bundles/v1beta1/events.proto +++ b/proto/kyve/bundles/v1beta1/events.proto @@ -87,20 +87,24 @@ message EventBundleFinalized { uint64 total = 6; // status of the finalized bundle BundleStatus status = 7; + // amount which funders provided to the total bundle reward (in ukyve) + uint64 funders_payout = 8; + // amount which the inflation pool provided to the total reward (in ukyve) + uint64 inflation_payout = 9; // rewards transferred to treasury (in ukyve) - uint64 reward_treasury = 8; + uint64 reward_treasury = 10; // rewardUploader rewards directly transferred to uploader (in ukyve) - uint64 reward_uploader = 9; + uint64 reward_uploader = 11; // rewardDelegation rewards distributed among all delegators (in ukyve) - uint64 reward_delegation = 10; + uint64 reward_delegation = 12; // rewardTotal the total bundle reward - uint64 reward_total = 11; + uint64 reward_total = 13; // finalized_at the block height where the bundle got finalized - uint64 finalized_at = 12; + uint64 finalized_at = 14; // uploader the address of the uploader of this bundle - string uploader = 13; + string uploader = 15; // next_uploader the address of the next uploader after this bundle - string next_uploader = 14; + string next_uploader = 16; } // EventClaimedUploaderRole is an event emitted when an uploader claims the uploader role diff --git a/proto/kyve/pool/v1beta1/events.proto b/proto/kyve/pool/v1beta1/events.proto index 47c59386..2e23ad92 100644 --- a/proto/kyve/pool/v1beta1/events.proto +++ b/proto/kyve/pool/v1beta1/events.proto @@ -2,8 +2,22 @@ syntax = "proto3"; package kyve.pool.v1beta1; +import "gogoproto/gogo.proto"; +import "kyve/pool/v1beta1/params.proto"; + option go_package = "github.com/KYVENetwork/chain/x/pool/types"; +// EventUpdateParams is an event emitted when the module parameters are updated. +// emitted_by: MsgUpdateParams +message EventUpdateParams { + // old_params is the module's old parameters. + kyve.pool.v1beta1.Params old_params = 1 [(gogoproto.nullable) = false]; + // new_params is the module's new parameters. + kyve.pool.v1beta1.Params new_params = 2 [(gogoproto.nullable) = false]; + // payload is the parameter updates that were performed. + string payload = 3; +} + // EventCreatePool ... // emitted_by: EndBlock(gov) message EventCreatePool { diff --git a/proto/kyve/pool/v1beta1/genesis.proto b/proto/kyve/pool/v1beta1/genesis.proto index 0051e4ac..ca5286ab 100644 --- a/proto/kyve/pool/v1beta1/genesis.proto +++ b/proto/kyve/pool/v1beta1/genesis.proto @@ -3,15 +3,15 @@ syntax = "proto3"; package kyve.pool.v1beta1; import "gogoproto/gogo.proto"; +import "kyve/pool/v1beta1/params.proto"; import "kyve/pool/v1beta1/pool.proto"; option go_package = "github.com/KYVENetwork/chain/x/pool/types"; // GenesisState defines the pool module's genesis state. message GenesisState { - reserved 1; - reserved "params"; - + // params ... + Params params = 1 [(gogoproto.nullable) = false]; // pool_list ... repeated kyve.pool.v1beta1.Pool pool_list = 2 [(gogoproto.nullable) = false]; // pool_count ... diff --git a/proto/kyve/pool/v1beta1/params.proto b/proto/kyve/pool/v1beta1/params.proto new file mode 100644 index 00000000..331307a5 --- /dev/null +++ b/proto/kyve/pool/v1beta1/params.proto @@ -0,0 +1,22 @@ +syntax = "proto3"; + +package kyve.pool.v1beta1; + +import "gogoproto/gogo.proto"; + +option go_package = "github.com/KYVENetwork/chain/x/pool/types"; + +// Params defines the pool module parameters. +message Params { + // protocol_inflation_share ... + string protocol_inflation_share = 1 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; + + // pool_inflation_payout_rate ... + string pool_inflation_payout_rate = 2 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; +} diff --git a/proto/kyve/pool/v1beta1/query.proto b/proto/kyve/pool/v1beta1/query.proto new file mode 100644 index 00000000..8589b372 --- /dev/null +++ b/proto/kyve/pool/v1beta1/query.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; + +package kyve.pool.v1beta1; + +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "kyve/pool/v1beta1/params.proto"; + +option go_package = "github.com/KYVENetwork/chain/x/pool/types"; + +// Query defines the gRPC querier service. +service Query { + // Parameters queries the parameters of the module. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/kyve/pool/v1beta1/params"; + } +} + +// QueryParamsRequest is request type for the Query/Params RPC method. +message QueryParamsRequest {} + +// QueryParamsResponse is response type for the Query/Params RPC method. +message QueryParamsResponse { + // params holds all the parameters of this module. + Params params = 1 [(gogoproto.nullable) = false]; +} diff --git a/proto/kyve/pool/v1beta1/tx.proto b/proto/kyve/pool/v1beta1/tx.proto index 4ca6223d..c7efa075 100644 --- a/proto/kyve/pool/v1beta1/tx.proto +++ b/proto/kyve/pool/v1beta1/tx.proto @@ -31,6 +31,9 @@ service Msg { // CancelRuntimeUpgrade defines a governance operation for cancelling a runtime upgrade. // The authority is hard-coded to the x/gov module account. rpc CancelRuntimeUpgrade(MsgCancelRuntimeUpgrade) returns (MsgCancelRuntimeUpgradeResponse); + // UpdateParams defines a governance operation for updating the x/pool module + // parameters. The authority is hard-coded to the x/gov module account. + rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); } // MsgFundPool defines a SDK message for funding a pool. @@ -158,3 +161,15 @@ message MsgCancelRuntimeUpgrade { // MsgCancelRuntimeUpgradeResponse defines the Msg/CancelRuntimeUpgrade response type. message MsgCancelRuntimeUpgradeResponse {} + +// MsgUpdateParams defines a SDK message for updating the module parameters. +message MsgUpdateParams { + // authority is the address of the governance account. + string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; + + // payload defines the x/stakers parameters to update. + string payload = 2; +} + +// MsgUpdateParamsResponse defines the Msg/UpdateParams response type. +message MsgUpdateParamsResponse {} diff --git a/proto/kyve/query/v1beta1/params.proto b/proto/kyve/query/v1beta1/params.proto index 69a0133d..923d569e 100644 --- a/proto/kyve/query/v1beta1/params.proto +++ b/proto/kyve/query/v1beta1/params.proto @@ -7,6 +7,7 @@ import "google/api/annotations.proto"; import "kyve/bundles/v1beta1/params.proto"; import "kyve/delegation/v1beta1/params.proto"; import "kyve/global/v1beta1/global.proto"; +import "kyve/pool/v1beta1/params.proto"; import "kyve/stakers/v1beta1/params.proto"; option go_package = "github.com/KYVENetwork/chain/x/query/types"; @@ -38,4 +39,6 @@ message QueryParamsResponse { cosmos.gov.v1.QueryParamsResponse gov_params = 4; // stakers_params ... kyve.stakers.v1beta1.Params stakers_params = 5; + // pool_params ... + kyve.pool.v1beta1.Params pool_params = 6; } diff --git a/proto/kyve/query/v1beta1/pools.proto b/proto/kyve/query/v1beta1/pools.proto index 1bee7e2d..a1ef4b0c 100644 --- a/proto/kyve/query/v1beta1/pools.proto +++ b/proto/kyve/query/v1beta1/pools.proto @@ -65,6 +65,10 @@ message PoolResponse { uint64 total_delegation = 6; // status ... kyve.pool.v1beta1.PoolStatus status = 7; + // account ... + string account = 8; + // account_balance ... + uint64 account_balance = 9; } // ========= diff --git a/proto/kyve/query/v1beta1/query.proto b/proto/kyve/query/v1beta1/query.proto index 87ddc414..b8033a71 100644 --- a/proto/kyve/query/v1beta1/query.proto +++ b/proto/kyve/query/v1beta1/query.proto @@ -122,6 +122,9 @@ message StakerMetadata { // the commission is applied. Users have time to redelegate // if they not agree with the new commission. CommissionChangeEntry pending_commission_change = 7; + + // commission_rewards are the rewards in $KYVE earned through commission + uint64 commission_rewards = 8; } // CommissionChangeEntry shows when the old commission diff --git a/testutil/integration/helpers.go b/testutil/integration/helpers.go index d202237a..8c691815 100644 --- a/testutil/integration/helpers.go +++ b/testutil/integration/helpers.go @@ -16,6 +16,15 @@ func (suite *KeeperTestSuite) GetBalanceFromAddress(address string) uint64 { return uint64(balance.Amount.Int64()) } +func (suite *KeeperTestSuite) GetBalanceFromPool(poolId uint64) uint64 { + pool, found := suite.App().PoolKeeper.GetPool(suite.Ctx(), poolId) + if !found { + return 0 + } + + return uint64(suite.App().BankKeeper.GetBalance(suite.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) +} + func (suite *KeeperTestSuite) GetBalanceFromModule(moduleName string) uint64 { moduleAcc := suite.App().AccountKeeper.GetModuleAccount(suite.Ctx(), moduleName).GetAddress() return suite.App().BankKeeper.GetBalance(suite.Ctx(), moduleAcc, globalTypes.Denom).Amount.Uint64() diff --git a/testutil/integration/integration.go b/testutil/integration/integration.go index ecc92509..1ee553e5 100644 --- a/testutil/integration/integration.go +++ b/testutil/integration/integration.go @@ -81,15 +81,13 @@ func (suite *KeeperTestSuite) initDummyAccounts() { _ = suite.Mint(STAKER_2, 1000*KYVE) _ = suite.Mint(VALADDRESS_2, 1000*KYVE) - mrand.New(mrand.NewSource(1)) - DUMMY = make([]string, 50) for i := 0; i < 50; i++ { byteAddr := make([]byte, 20) for k := 0; k < 20; k++ { - mrand.New(mrand.NewSource(int64(i + k))) - byteAddr[k] = byte(mrand.Int()) + randomSource := mrand.New(mrand.NewSource(int64(i + k))) + byteAddr[k] = byte(randomSource.Int()) } dummy, _ := sdk.Bech32ifyAddressBytes("kyve", byteAddr) DUMMY[i] = dummy @@ -100,8 +98,8 @@ func (suite *KeeperTestSuite) initDummyAccounts() { for i := 0; i < 50; i++ { byteAddr := make([]byte, 20) for k := 0; k < 20; k++ { - mrand.New(mrand.NewSource(int64(i + k + 100))) - byteAddr[k] = byte(mrand.Int()) + randomSource := mrand.New(mrand.NewSource(int64(i + k + 100))) + byteAddr[k] = byte(randomSource.Int()) } dummy, _ := sdk.Bech32ifyAddressBytes("kyve", byteAddr) VALDUMMY[i] = dummy diff --git a/x/bundles/abci.go b/x/bundles/abci.go new file mode 100644 index 00000000..245607a1 --- /dev/null +++ b/x/bundles/abci.go @@ -0,0 +1,90 @@ +package bundles + +import ( + "github.com/KYVENetwork/chain/util" + bundlesKeeper "github.com/KYVENetwork/chain/x/bundles/keeper" + sdk "github.com/cosmos/cosmos-sdk/types" + + // Auth + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + // Bank + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + // Mint + mintKeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + // Pool + "github.com/KYVENetwork/chain/x/pool/keeper" + // Team + teamKeeper "github.com/KYVENetwork/chain/x/team/keeper" + // Upgrade + upgradeKeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" +) + +func SplitInflation(ctx sdk.Context, k bundlesKeeper.Keeper, bk bankKeeper.Keeper, mk mintKeeper.Keeper, pk keeper.Keeper, tk teamKeeper.Keeper, uk upgradeKeeper.Keeper) { + minter := mk.GetMinter(ctx) + params := mk.GetParams(ctx) + + // get total inflation rewards for current block + blockProvision := minter.BlockProvision(params).Amount.Int64() + + // calculate the remaining block provision for chain and protocol after x/team took its share + remainingBlockProvision := blockProvision - tk.GetTeamBlockProvision(ctx) + + // calculate block provision for protocol based on protocol inflation share + protocolBlockProvision := sdk.NewDec(remainingBlockProvision).Mul(pk.GetProtocolInflationShare(ctx)).TruncateInt64() + + if protocolBlockProvision == 0 { + return + } + + // track actual distributed block provision for protocol + distributed := uint64(0) + + // calculate total operating cost of pools to get each pool's reward share + totalOperatingCost := uint64(0) + + for _, pool := range pk.GetAllPools(ctx) { + // only include active pools + if err := k.AssertPoolCanRun(ctx, pool.Id); err == nil { + totalOperatingCost += pool.OperatingCost + } + } + + // if the total operating cost is zero all rewards go the chain + if totalOperatingCost == 0 { + return + } + + for _, pool := range pk.GetAllPools(ctx) { + // only include active pools + if err := k.AssertPoolCanRun(ctx, pool.Id); err == nil { + // calculate pool share based of operating cost + amount := uint64(sdk.NewDec(int64(pool.OperatingCost)).Quo(sdk.NewDec(int64(totalOperatingCost))).Mul(sdk.NewDec(protocolBlockProvision)).TruncateInt64()) + + // transfer funds to pool account + if err := util.TransferFromModuleToAddress(bk, ctx, authTypes.FeeCollectorName, pool.GetPoolAccount().String(), amount); err != nil { + util.PanicHalt(uk, ctx, err.Error()) + } + + // track transferred $KYVE to protocol + distributed += amount + } + } + + // calculate if a remainder is left + remainder := uint64(protocolBlockProvision) - distributed + + if remainder > 0 { + // find an active pool + for _, pool := range pk.GetAllPools(ctx) { + if err := k.AssertPoolCanRun(ctx, pool.Id); err != nil { + // add remainder to first active pool we find + if err := util.TransferFromModuleToAddress(bk, ctx, authTypes.FeeCollectorName, pool.GetPoolAccount().String(), remainder); err != nil { + util.PanicHalt(uk, ctx, err.Error()) + } + } + } + } + + // rest gets transferred to chain + pk.Logger(ctx).Info("split portion of minted coins to protocol", "amount", protocolBlockProvision) +} diff --git a/x/bundles/keeper/abci_protocol_split_test.go b/x/bundles/keeper/abci_protocol_split_test.go new file mode 100644 index 00000000..bfcf0ad1 --- /dev/null +++ b/x/bundles/keeper/abci_protocol_split_test.go @@ -0,0 +1,238 @@ +package keeper_test + +import ( + i "github.com/KYVENetwork/chain/testutil/integration" + globalTypes "github.com/KYVENetwork/chain/x/global/types" + poolTypes "github.com/KYVENetwork/chain/x/pool/types" + stakertypes "github.com/KYVENetwork/chain/x/stakers/types" + sdk "github.com/cosmos/cosmos-sdk/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +/* + +TEST CASES - abci.go + +* inactive pool should not receive inflation funds +* active pool should receive inflation funds +* pool should split inflation funds depending on operating cost +* pools with zero operating cost should receive nothing +* every pool has zero operating cost + +*/ + +var _ = Describe("abci.go", Ordered, func() { + s := i.NewCleanChain() + + BeforeEach(func() { + s = i.NewCleanChain() + + s.App().PoolKeeper.SetParams(s.Ctx(), poolTypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + s.App().PoolKeeper.AppendPool(s.Ctx(), poolTypes.Pool{ + Name: "PoolTest", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + MinDelegation: 100 * i.KYVE, + OperatingCost: 1_000_000, + Protocol: &poolTypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &poolTypes.UpgradePlan{}, + }) + }) + + AfterEach(func() { + s.PerformValidityChecks() + }) + + It("inactive pool should not receive inflation funds", func() { + // ARRANGE + b1, b2 := uint64(0), uint64(0) + + for t := 0; t < 100; t++ { + // ACT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + b1 = uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + s.Commit() + b2 = uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + // ASSERT + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + } + }) + + It("active pool should receive inflation funds", func() { + // ARRANGE + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0, + }) + + b1, b2 := uint64(0), uint64(0) + + for t := 0; t < 100; t++ { + // ACT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + b1 = uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + s.Commit() + b2 = uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + // ASSERT + Expect(b1).To(BeNumerically("<", b2)) + } + }) + + It("pool should split inflation funds depending on operating cost", func() { + // ARRANGE + s.App().PoolKeeper.AppendPool(s.Ctx(), poolTypes.Pool{ + Name: "PoolTest2", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + MinDelegation: 100 * i.KYVE, + OperatingCost: 2_000_000, + Protocol: &poolTypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &poolTypes.UpgradePlan{}, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_1, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_1, + PoolId: 1, + Valaddress: i.VALADDRESS_1, + }) + + // ACT + s.Commit() + + pool1, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + b1 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool1.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + pool2, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 1) + b2 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool2.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + // ASSERT + Expect(b1 * 2).To(BeNumerically("~", b2, 1)) + }) + + It("pools with zero operating cost should receive nothing", func() { + // ARRANGE + s.App().PoolKeeper.AppendPool(s.Ctx(), poolTypes.Pool{ + Name: "PoolTest2", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + MinDelegation: 100 * i.KYVE, + OperatingCost: 0, + Protocol: &poolTypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &poolTypes.UpgradePlan{}, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0, + }) + + // ACT + s.Commit() + + pool1, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + b1 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool1.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + pool2, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 1) + b2 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool2.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + // ASSERT + Expect(b1).To(BeNumerically(">", b2)) + Expect(b2).To(BeZero()) + }) + + It("every pool has zero operating cost", func() { + // ARRANGE + s.App().PoolKeeper.SetPool(s.Ctx(), poolTypes.Pool{ + Id: 0, + Name: "PoolTest", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + OperatingCost: 0, + Protocol: &poolTypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &poolTypes.UpgradePlan{}, + }) + + s.App().PoolKeeper.AppendPool(s.Ctx(), poolTypes.Pool{ + Name: "PoolTest2", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + OperatingCost: 0, + Protocol: &poolTypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &poolTypes.UpgradePlan{}, + }) + + // ACT + s.Commit() + + pool1, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + b1 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool1.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + pool2, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 1) + b2 := uint64(s.App().BankKeeper.GetBalance(s.Ctx(), pool2.GetPoolAccount(), globalTypes.Denom).Amount.Int64()) + + // ASSERT + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + }) +}) diff --git a/x/bundles/keeper/keeper_suite_funding_bundles_test.go b/x/bundles/keeper/keeper_suite_funding_bundles_test.go index dbf2a30e..36f10c8a 100644 --- a/x/bundles/keeper/keeper_suite_funding_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_funding_bundles_test.go @@ -18,9 +18,10 @@ TEST CASES - funding bundles * Produce a valid bundle with multiple funders and same funding amounts * Produce a valid bundle with multiple funders and different funding amounts * Produce a valid bundle with multiple funders and different funding amounts where not everyone can afford the funds -* Produce a dropped bundle because the only funder can not pay for the bundle reward -* Produce a dropped bundle because multiple funders with same amount can not pay for the bundle reward -* Produce a dropped bundle because multiple funders with different amount can not pay for the bundle reward +* Produce a valid bundle although the only funder can not pay for the bundle reward +* Produce a valid bundle although multiple funders with same amount can not pay for the bundle reward +* Produce a valid bundle although multiple funders with different amount can not pay for the bundle reward +* Produce a valid bundle although there are no funders at all */ @@ -115,9 +116,11 @@ var _ = Describe("funding bundles", Ordered, func() { // ASSERT pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + totalReward := pool.OperatingCost // assert total pool funds Expect(pool.TotalFunds).To(Equal(100*i.KYVE - totalReward)) @@ -187,9 +190,11 @@ var _ = Describe("funding bundles", Ordered, func() { // ASSERT pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + totalReward := pool.OperatingCost // assert total pool funds Expect(pool.TotalFunds).To(Equal(200*i.KYVE - totalReward)) @@ -266,9 +271,11 @@ var _ = Describe("funding bundles", Ordered, func() { // ASSERT pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + totalReward := pool.OperatingCost // assert total pool funds Expect(pool.TotalFunds).To(Equal(200*i.KYVE - totalReward)) @@ -345,18 +352,17 @@ var _ = Describe("funding bundles", Ordered, func() { // ASSERT pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + totalReward := pool.OperatingCost // assert total pool funds - Expect(pool.TotalFunds).To(Equal(100*i.KYVE - totalReward)) + Expect(pool.TotalFunds).To(Equal(100*i.KYVE - (totalReward / 2))) Expect(pool.Funders).To(HaveLen(1)) - // assert individual funds - fundersCharge := uint64(sdk.NewDec(int64(totalReward)).TruncateInt64()) - - Expect(pool.GetFunderAmount(i.BOB)).To(Equal(100*i.KYVE - fundersCharge)) + Expect(pool.GetFunderAmount(i.BOB)).To(Equal(100*i.KYVE - (totalReward / 2))) // assert individual balances balanceAlice := s.GetBalanceFromAddress(i.ALICE) @@ -366,7 +372,7 @@ var _ = Describe("funding bundles", Ordered, func() { Expect(balanceBob).To(Equal(initialBalanceBob - 100*i.KYVE)) }) - It("Produce a dropped bundle because the only funder can not pay for the bundle reward", func() { + It("Produce a valid bundle although the only funder can not pay for the bundle reward", func() { // ARRANGE s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ Creator: i.ALICE, @@ -414,44 +420,11 @@ var _ = Describe("funding bundles", Ordered, func() { }) // ASSERT - // check if bundle got not finalized on pool - pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - Expect(poolFound).To(BeTrue()) - - Expect(pool.CurrentKey).To(Equal("")) - Expect(pool.CurrentSummary).To(BeEmpty()) - Expect(pool.CurrentIndex).To(BeZero()) - Expect(pool.TotalBundles).To(BeZero()) - - // check if finalized bundle exists - _, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) - Expect(finalizedBundleFound).To(BeFalse()) - - // check if bundle proposal got dropped - bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposalFound).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("0")) - Expect(bundleProposal.ToKey).To(Equal("99")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // check uploader status - valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) - Expect(valaccountUploader.Points).To(BeZero()) - - // check pool funds - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) // assert total pool funds Expect(pool.TotalFunds).To(BeZero()) @@ -462,7 +435,7 @@ var _ = Describe("funding bundles", Ordered, func() { Expect(balanceAlice).To(Equal(initialBalanceAlice - 10)) }) - It("Produce a dropped bundle because multiple funders with same amount can not pay for the bundle reward", func() { + It("Produce a valid bundle although multiple funders with same amount can not pay for the bundle reward", func() { // ARRANGE s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ Creator: i.ALICE, @@ -516,44 +489,11 @@ var _ = Describe("funding bundles", Ordered, func() { }) // ASSERT - // check if bundle got not finalized on pool - pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - Expect(poolFound).To(BeTrue()) - - Expect(pool.CurrentKey).To(Equal("")) - Expect(pool.CurrentSummary).To(BeEmpty()) - Expect(pool.CurrentIndex).To(BeZero()) - Expect(pool.TotalBundles).To(BeZero()) - - // check if finalized bundle exists - _, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) - Expect(finalizedBundleFound).To(BeFalse()) - - // check if bundle proposal got dropped - bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposalFound).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("0")) - Expect(bundleProposal.ToKey).To(Equal("99")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // check uploader status - valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) - Expect(valaccountUploader.Points).To(BeZero()) - - // check pool funds - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) // assert total pool funds Expect(pool.TotalFunds).To(BeZero()) @@ -621,44 +561,11 @@ var _ = Describe("funding bundles", Ordered, func() { }) // ASSERT - // check if bundle got not finalized on pool - pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - Expect(poolFound).To(BeTrue()) - - Expect(pool.CurrentKey).To(Equal("")) - Expect(pool.CurrentSummary).To(BeEmpty()) - Expect(pool.CurrentIndex).To(BeZero()) - Expect(pool.TotalBundles).To(BeZero()) - - // check if finalized bundle exists - _, finalizedBundleFound := s.App().BundlesKeeper.GetFinalizedBundle(s.Ctx(), 0, 0) - Expect(finalizedBundleFound).To(BeFalse()) - - // check if bundle proposal got dropped - bundleProposal, bundleProposalFound := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposalFound).To(BeTrue()) - - Expect(bundleProposal.PoolId).To(Equal(uint64(0))) - Expect(bundleProposal.StorageId).To(Equal("y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI")) - Expect(bundleProposal.Uploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) - Expect(bundleProposal.DataSize).To(Equal(uint64(100))) - Expect(bundleProposal.DataHash).To(Equal("test_hash")) - Expect(bundleProposal.BundleSize).To(Equal(uint64(100))) - Expect(bundleProposal.FromKey).To(Equal("0")) - Expect(bundleProposal.ToKey).To(Equal("99")) - Expect(bundleProposal.BundleSummary).To(Equal("test_value")) - Expect(bundleProposal.UpdatedAt).NotTo(BeZero()) - Expect(bundleProposal.VotersValid).To(ContainElement(i.STAKER_0)) - Expect(bundleProposal.VotersInvalid).To(BeEmpty()) - Expect(bundleProposal.VotersAbstain).To(BeEmpty()) - - // check uploader status - valaccountUploader, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_0) - Expect(valaccountUploader.Points).To(BeZero()) - - // check pool funds - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) // assert total pool funds Expect(pool.TotalFunds).To(BeZero()) @@ -671,4 +578,63 @@ var _ = Describe("funding bundles", Ordered, func() { balanceBob := s.GetBalanceFromAddress(i.BOB) Expect(balanceBob).To(Equal(initialBalanceBob - 20)) }) + + It("Produce a valid bundle although there are no funders at all", func() { + // ARRANGE + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + }) + + s.CommitAfterSeconds(60) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + + s.CommitAfterSeconds(60) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) }) diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go new file mode 100644 index 00000000..500aa90a --- /dev/null +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -0,0 +1,1166 @@ +package keeper_test + +import ( + i "github.com/KYVENetwork/chain/testutil/integration" + bundletypes "github.com/KYVENetwork/chain/x/bundles/types" + pooltypes "github.com/KYVENetwork/chain/x/pool/types" + stakertypes "github.com/KYVENetwork/chain/x/stakers/types" + sdk "github.com/cosmos/cosmos-sdk/types" + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" +) + +/* + +TEST CASES - inflation splitting + +* Produce a valid bundle with no funders and 0% inflation splitting +* Produce a valid bundle with no funders and 10% inflation splitting +* Produce a valid bundle with no funders and 100% inflation splitting + +* Produce a valid bundle with sufficient funders and 0% inflation splitting +* Produce a valid bundle with sufficient funders and 10% inflation splitting +* Produce a valid bundle with sufficient funders and 100% inflation splitting + +* Produce a valid bundle with insufficient funders and 0% inflation splitting +* Produce a valid bundle with insufficient funders and 10% inflation splitting +* Produce a valid bundle with insufficient funders and 100% inflation splitting + +* Produce a valid bundle with some insufficient funders and 0% inflation splitting +* Produce a valid bundle with some insufficient funders and 10% inflation splitting +* Produce a valid bundle with some insufficient funders and 100% inflation splitting + +*/ + +var _ = Describe("inflation splitting", Ordered, func() { + s := i.NewCleanChain() + + BeforeEach(func() { + // init new clean chain + s = i.NewCleanChain() + + // create clean pool for every test case + s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ + Name: "PoolTest", + MaxBundleSize: 100, + StartKey: "0", + UploadInterval: 60, + OperatingCost: 10_000, + Protocol: &pooltypes.Protocol{ + Version: "0.0.0", + Binaries: "{}", + LastUpgrade: uint64(s.Ctx().BlockTime().Unix()), + }, + UpgradePlan: &pooltypes.UpgradePlan{}, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ + Creator: i.STAKER_0, + Amount: 100 * i.KYVE, + }) + + s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ + Creator: i.STAKER_0, + PoolId: 0, + Valaddress: i.VALADDRESS_0, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + }) + + s.CommitAfterSeconds(60) + }) + + AfterEach(func() { + s.PerformValidityChecks() + }) + + It("Produce a valid bundle with no funders and 0% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // assert commission rewards + Expect(uploader.CommissionRewards).To(BeZero()) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with no funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is here just the inflation payout + totalPayout := payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with no funders and 100% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.2"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is here just the inflation payout + totalPayout := payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with sufficient funders and 0% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost because the funding is sufficient + // and there is no additional inflation + totalPayout := pool.OperatingCost + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(200*i.KYVE - totalPayout)) + Expect(pool.Funders).To(HaveLen(2)) + }) + + It("Produce a valid bundle with sufficient funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.3"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := pool.OperatingCost + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(200*i.KYVE - pool.OperatingCost)) + Expect(pool.Funders).To(HaveLen(2)) + }) + + It("Produce a valid bundle with sufficient funders and 100% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := pool.OperatingCost + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(200*i.KYVE - pool.OperatingCost)) + Expect(pool.Funders).To(HaveLen(2)) + }) + + It("Produce a valid bundle with insufficient funders and 0% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the total funds + totalPayout := uint64(300) + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with insufficient funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.3"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := 300 + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with insufficient funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := 300 + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(BeZero()) + Expect(pool.Funders).To(BeEmpty()) + }) + + It("Produce a valid bundle with some insufficient funders and 0% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeZero()) + Expect(b2).To(BeZero()) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the total funds + totalPayout := (pool.OperatingCost / 2) + 200 + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(100*i.KYVE - (pool.OperatingCost / 2))) + Expect(pool.Funders).To(HaveLen(1)) + }) + + It("Produce a valid bundle with some insufficient funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.3"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := (pool.OperatingCost / 2) + 200 + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(100*i.KYVE - (pool.OperatingCost / 2))) + Expect(pool.Funders).To(HaveLen(1)) + }) + + It("Produce a valid bundle with some insufficient funders and 10% inflation splitting", func() { + // ARRANGE + s.App().PoolKeeper.SetParams(s.Ctx(), pooltypes.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.1"), + }) + + // mine some blocks + for i := 1; i < 100; i++ { + s.Commit() + } + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.BOB, + Id: 0, + Amount: 200, + }) + + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "y62A3tfbSNcNYDGoL-eXwzyV-Zc9Q0OVtDvR1biJmNI", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 0, + BundleSize: 100, + FromKey: "0", + ToKey: "99", + BundleSummary: "test_value", + }) + + s.CommitAfterSeconds(60) + + b1 := s.GetBalanceFromPool(0) + + // ACT + s.RunTxBundlesSuccess(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + StorageId: "P9edn0bjEfMU_lecFDIPLvGO2v2ltpFNUMWp5kgPddg", + DataSize: 100, + DataHash: "test_hash2", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value2", + }) + + // ASSERT + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + // assert if bundle go finalized + Expect(pool.TotalBundles).To(Equal(uint64(1))) + Expect(pool.CurrentKey).To(Equal("99")) + + // assert pool balance + b2 := s.GetBalanceFromPool(0) + Expect(b1).To(BeNumerically(">", b2)) + + payout := uint64(sdk.NewDec(int64(b1)).Mul(s.App().PoolKeeper.GetPoolInflationPayoutRate(s.Ctx())).TruncateInt64()) + Expect(b1 - b2).To(Equal(payout)) + + // assert bundle reward + uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) + + // the total payout is the operating cost plus the inflation payout + totalPayout := (pool.OperatingCost / 2) + 200 + payout + + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := totalPayout - treasuryReward - storageReward + + uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + + // assert commission rewards + Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) + // assert uploader self delegation rewards + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + + // assert total pool funds + Expect(pool.TotalFunds).To(Equal(100*i.KYVE - (pool.OperatingCost / 2))) + Expect(pool.Funders).To(HaveLen(1)) + }) +}) diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index 5791f928..6250d77f 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -217,12 +217,11 @@ var _ = Describe("stakers leave", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index 72683919..32cd8d4e 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -178,12 +178,10 @@ var _ = Describe("valid bundles", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -199,7 +197,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with one validator and foreign delegations", func() { @@ -296,12 +294,10 @@ var _ = Describe("valid bundles", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), valaccountUploader.Staker) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -323,7 +319,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with multiple validators and no foreign delegations", func() { @@ -447,12 +443,11 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -468,7 +463,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with one validator and foreign delegations", func() { @@ -604,12 +599,10 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -641,7 +634,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with multiple validators and foreign delegation although some did not vote at all", func() { @@ -768,12 +761,11 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -798,7 +790,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with multiple validators and foreign delegation although some voted abstain", func() { @@ -933,12 +925,11 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -963,7 +954,7 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Produce a valid bundle with multiple validators and foreign delegation although some voted invalid", func() { @@ -1108,12 +1099,11 @@ var _ = Describe("valid bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + // calculate uploader rewards networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) totalDelegationReward := totalUploaderReward - uploaderPayoutReward @@ -1138,6 +1128,6 @@ var _ = Describe("valid bundles", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) }) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index d1b45f83..79504765 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -384,18 +384,17 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // calculate uploader rewards - totalReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + pool.OperatingCost networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(totalReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := totalReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) // assert payout transfer Expect(balanceUploader).To(Equal(initialBalanceStaker0)) // assert commission rewards - Expect(uploader.CommissionRewards).To(Equal(totalUploaderReward)) + Expect(uploader.CommissionRewards).To(Equal(totalUploaderReward + storageReward)) // assert uploader self delegation rewards Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) @@ -403,7 +402,7 @@ var _ = Describe("zero delegation", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - totalReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Staker receives upload slash with zero delegation", func() { diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index 7597dcfc..4b3925d1 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -28,11 +28,6 @@ func (k Keeper) AssertPoolCanRun(ctx sdk.Context, poolId uint64) error { return types.ErrPoolDisabled } - // Error if the pool has no funds. - if len(pool.Funders) == 0 { - return types.ErrPoolOutOfFunds - } - // Error if min delegation is not reached if k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) < pool.MinDelegation { return types.ErrMinDelegationNotReached @@ -217,46 +212,54 @@ func (k Keeper) handleNonVoters(ctx sdk.Context, poolId uint64) { } } -// calculatePayouts deducts the network fee from the rewards and splits the remaining amount -// between the staker and its delegators. If there are no delegators, the entire amount is -// awarded to the staker. -func (k Keeper) calculatePayouts(ctx sdk.Context, poolId uint64) (bundleReward types.BundleReward) { - pool, _ := k.poolKeeper.GetPoolWithError(ctx, poolId) +// calculatePayouts calculates the different payouts to treasury, uploader and delegators from the total payout +// the pool module provides for this bundle round +func (k Keeper) calculatePayouts(ctx sdk.Context, poolId uint64, totalPayout uint64) (bundleReward types.BundleReward) { + // This method first subtracts the network fee from it + // After that the uploader receives the storage rewards. If the total payout does not cover the + // storage rewards we pay out the remains, the commission and delegation rewards will be empty + // in this case. After the payout of the storage rewards the remains are divided between uploader + // and its delegators based on the commission. bundleProposal, _ := k.GetBundleProposal(ctx, poolId) - // Should not happen, if so move everything to the treasury + // Should not happen, if so make no payouts if !k.stakerKeeper.DoesStakerExist(ctx, bundleProposal.Uploader) { - bundleReward.Treasury = bundleReward.Total - return } - operatingReward := pool.OperatingCost - storageReward := uint64(k.GetStorageCost(ctx).MulInt64(int64(bundleProposal.DataSize)).TruncateInt64()) + bundleReward.Total = totalPayout - // formula for calculating the rewards - bundleReward.Total = operatingReward + storageReward + // calculate share of treasury from total payout + bundleReward.Treasury = uint64(sdk.NewDec(int64(totalPayout)).Mul(k.GetNetworkFee(ctx)).TruncateInt64()) - // Add fee to treasury - bundleReward.Treasury = uint64(sdk.NewDec(int64(operatingReward)).Mul(k.GetNetworkFee(ctx)).TruncateInt64()) + // calculate wanted storage reward the uploader should receive + storageReward := uint64(k.GetStorageCost(ctx).MulInt64(int64(bundleProposal.DataSize)).TruncateInt64()) - // Remaining rewards to be split between staker and its delegators - totalNodeReward := operatingReward - bundleReward.Treasury + // if not even the full storage reward can not be paid out we pay out the remains. + // in this case the uploader will not earn the commission rewards and delegators not + // their delegation rewards because total payout is not high enough + if totalPayout-bundleReward.Treasury < storageReward { + bundleReward.Uploader = totalPayout - bundleReward.Treasury + return + } else { + bundleReward.Uploader = storageReward + } - // Payout delegators + // remaining rewards to be split between uploader and its delegators + totalNodeReward := totalPayout - bundleReward.Treasury - bundleReward.Uploader + + // payout delegators if k.delegationKeeper.GetDelegationAmount(ctx, bundleProposal.Uploader) > 0 { commission := k.stakerKeeper.GetCommission(ctx, bundleProposal.Uploader) + commissionRewards := uint64(sdk.NewDec(int64(totalNodeReward)).Mul(commission).TruncateInt64()) - bundleReward.Uploader = uint64(sdk.NewDec(int64(totalNodeReward)).Mul(commission).TruncateInt64()) - bundleReward.Delegation = totalNodeReward - bundleReward.Uploader + bundleReward.Uploader += commissionRewards + bundleReward.Delegation = totalNodeReward - commissionRewards } else { - bundleReward.Uploader = totalNodeReward + bundleReward.Uploader += totalNodeReward bundleReward.Delegation = 0 } - // the uploader always receives the full storage reward since the uploader paid for storage - bundleReward.Uploader += storageReward - return } @@ -314,7 +317,7 @@ func (k Keeper) registerBundleProposalFromUploader(ctx sdk.Context, msg *types.M // finalizeCurrentBundleProposal takes the data of the current evaluated proposal // and stores it as a finalized proposal. This only happens if the network // reached quorum on the proposal's validity. -func (k Keeper) finalizeCurrentBundleProposal(ctx sdk.Context, poolId uint64, voteDistribution types.VoteDistribution, bundleReward types.BundleReward, nextUploader string) { +func (k Keeper) finalizeCurrentBundleProposal(ctx sdk.Context, poolId uint64, voteDistribution types.VoteDistribution, fundersPayout uint64, inflationPayout uint64, bundleReward types.BundleReward, nextUploader string) { pool, _ := k.poolKeeper.GetPool(ctx, poolId) bundleProposal, _ := k.GetBundleProposal(ctx, poolId) @@ -349,6 +352,8 @@ func (k Keeper) finalizeCurrentBundleProposal(ctx sdk.Context, poolId uint64, vo Abstain: voteDistribution.Abstain, Total: voteDistribution.Total, Status: voteDistribution.Status, + FundersPayout: fundersPayout, + InflationPayout: inflationPayout, RewardTreasury: bundleReward.Treasury, RewardUploader: bundleReward.Uploader, RewardDelegation: bundleReward.Delegation, diff --git a/x/bundles/keeper/logic_bundles_test.go b/x/bundles/keeper/logic_bundles_test.go index 5cfa9b49..a4c4a98a 100644 --- a/x/bundles/keeper/logic_bundles_test.go +++ b/x/bundles/keeper/logic_bundles_test.go @@ -15,9 +15,9 @@ TEST CASES - logic_bundles.go * Assert pool can run while pool is upgrading * Assert pool can run while pool is disabled -* Assert pool can run while pool has no funds * Assert pool can run while min delegation is not reached * Assert pool can run +* Assert pool can run while pool has no funds * Assert can vote if sender is no staker * Assert can vote if bundle is dropped @@ -129,7 +129,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { Expect(err).To(HaveOccurred()) }) - It("Assert pool can run while pool has no funds", func() { + It("Assert pool can run while min delegation is not reached", func() { // ASSERT s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ Name: "PoolTest", @@ -145,9 +145,15 @@ var _ = Describe("logic_bundles.go", Ordered, func() { UpgradePlan: &pooltypes.UpgradePlan{}, }) + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_0, - Amount: 100 * i.KYVE, + Amount: 99 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ @@ -164,7 +170,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { Expect(err).To(HaveOccurred()) }) - It("Assert pool can run while min delegation is not reached", func() { + It("Assert pool can run", func() { // ASSERT s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ Name: "PoolTest", @@ -188,7 +194,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() { s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_0, - Amount: 99 * i.KYVE, + Amount: 100 * i.KYVE, }) s.RunTxStakersSuccess(&stakertypes.MsgJoinPool{ @@ -202,10 +208,10 @@ var _ = Describe("logic_bundles.go", Ordered, func() { err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) }) - It("Assert pool can run", func() { + It("Assert pool can run while pool has no funds", func() { // ASSERT s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ Name: "PoolTest", @@ -221,12 +227,6 @@ var _ = Describe("logic_bundles.go", Ordered, func() { UpgradePlan: &pooltypes.UpgradePlan{}, }) - s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ - Creator: i.ALICE, - Id: 0, - Amount: 100 * i.KYVE, - }) - s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{ Creator: i.STAKER_0, Amount: 100 * i.KYVE, diff --git a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go index db7104eb..d78ce528 100644 --- a/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go +++ b/x/bundles/keeper/logic_end_block_handle_upload_timeout_test.go @@ -15,10 +15,10 @@ import ( TEST CASES - logic_end_block_handle_upload_timeout.go +* Next uploader can stay although pool ran out of funds * First staker who joins gets automatically chosen as next uploader * Next uploader gets removed due to pool upgrading * Next uploader gets removed due to pool being disabled -* Next uploader gets removed due to pool having no funds * Next uploader gets removed due to pool not reaching min stake * Staker is next uploader of genesis bundle and upload interval and timeout does not pass * Staker is next uploader of genesis bundle and upload timeout does not pass but upload interval passes @@ -81,7 +81,20 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { s.PerformValidityChecks() }) - It("First staker who joins gets automatically chosen as next uploader", func() { + It("Next uploader can stay although pool ran out of funds", func() { + // ARRANGE + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ + Creator: i.VALADDRESS_0, + Staker: i.STAKER_0, + PoolId: 0, + }) + + s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + // ACT s.CommitAfterSeconds(1) @@ -98,31 +111,13 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) }) - It("Next uploader gets removed due to pool upgrading", func() { - // ARRANGE - s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ - Creator: i.VALADDRESS_0, - Staker: i.STAKER_0, - PoolId: 0, - }) - - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - - pool.UpgradePlan = &pooltypes.UpgradePlan{ - Version: "1.0.0", - Binaries: "{}", - ScheduledAt: uint64(s.Ctx().BlockTime().Unix()), - Duration: 3600, - } - - s.App().PoolKeeper.SetPool(s.Ctx(), pool) - + It("First staker who joins gets automatically chosen as next uploader", func() { // ACT s.CommitAfterSeconds(1) // ASSERT bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(bundleProposal.NextUploader).To(BeEmpty()) + Expect(bundleProposal.NextUploader).To(Equal(i.STAKER_0)) Expect(bundleProposal.StorageId).To(BeEmpty()) poolStakers := s.App().StakersKeeper.GetAllStakerAddressesOfPool(s.Ctx(), 0) @@ -133,7 +128,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) }) - It("Next uploader gets removed due to pool being disabled", func() { + It("Next uploader gets removed due to pool upgrading", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0, @@ -143,7 +138,12 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - pool.Disabled = true + pool.UpgradePlan = &pooltypes.UpgradePlan{ + Version: "1.0.0", + Binaries: "{}", + ScheduledAt: uint64(s.Ctx().BlockTime().Unix()), + Duration: 3600, + } s.App().PoolKeeper.SetPool(s.Ctx(), pool) @@ -163,7 +163,7 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.STAKER_0)).To(Equal(100 * i.KYVE)) }) - It("Next uploader gets removed due to pool having no funds", func() { + It("Next uploader gets removed due to pool being disabled", func() { // ARRANGE s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0, @@ -171,11 +171,11 @@ var _ = Describe("logic_end_block_handle_upload_timeout.go", Ordered, func() { PoolId: 0, }) - s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ - Creator: i.ALICE, - Id: 0, - Amount: 100 * i.KYVE, - }) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + pool.Disabled = true + + s.App().PoolKeeper.SetPool(s.Ctx(), pool) // ACT s.CommitAfterSeconds(1) diff --git a/x/bundles/keeper/logic_round_robin_test.go b/x/bundles/keeper/logic_round_robin_test.go index ed2cefe0..8e9f95a6 100644 --- a/x/bundles/keeper/logic_round_robin_test.go +++ b/x/bundles/keeper/logic_round_robin_test.go @@ -67,7 +67,7 @@ var _ = Describe("logic_round_robin.go", Ordered, func() { Name: "PoolTest", UploadInterval: 60, OperatingCost: 2 * i.KYVE, - MinDelegation: 100 * i.KYVE, + MinDelegation: 1_000_000 * i.KYVE, MaxBundleSize: 100, Protocol: &pooltypes.Protocol{ Version: "0.0.0", diff --git a/x/bundles/keeper/msg_server_claim_uploader_role_test.go b/x/bundles/keeper/msg_server_claim_uploader_role_test.go index a2c96a92..eec9c553 100644 --- a/x/bundles/keeper/msg_server_claim_uploader_role_test.go +++ b/x/bundles/keeper/msg_server_claim_uploader_role_test.go @@ -59,7 +59,7 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { }) // ACT - s.RunTxBundlesError(&bundletypes.MsgClaimUploaderRole{ + s.RunTxBundlesSuccess(&bundletypes.MsgClaimUploaderRole{ Creator: i.VALADDRESS_0, Staker: i.STAKER_0, PoolId: 0, @@ -67,7 +67,7 @@ var _ = Describe("msg_server_claim_uploader_role.go", Ordered, func() { // ASSERT _, found := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) - Expect(found).To(BeFalse()) + Expect(found).To(BeTrue()) }) It("Try to claim uploader role without being a staker", func() { diff --git a/x/bundles/keeper/msg_server_submit_bundle_proposal.go b/x/bundles/keeper/msg_server_submit_bundle_proposal.go index 1f64fc5a..4d95de09 100644 --- a/x/bundles/keeper/msg_server_submit_bundle_proposal.go +++ b/x/bundles/keeper/msg_server_submit_bundle_proposal.go @@ -11,8 +11,6 @@ import ( delegationTypes "github.com/KYVENetwork/chain/x/delegation/types" // Pool poolTypes "github.com/KYVENetwork/chain/x/pool/types" - // Stakers - stakersTypes "github.com/KYVENetwork/chain/x/stakers/types" ) // SubmitBundleProposal handles the logic of an SDK message that allows protocol nodes to submit a new bundle proposal. @@ -57,7 +55,8 @@ func (k msgServer) SubmitBundleProposal(goCtx context.Context, msg *types.MsgSub case types.BUNDLE_STATUS_VALID: // If a bundle is valid the following things happen: - // 1. A reward is paid out to the uploader, its delegators and the treasury + // 1. Funders and Inflation Pool are charged. The total payout is divided + // between the uploader, its delegators and the treasury. // The appropriate funds are deducted from the total pool funds // 2. The next uploader is randomly selected based on everybody who // voted valid on this bundle. @@ -65,44 +64,35 @@ func (k msgServer) SubmitBundleProposal(goCtx context.Context, msg *types.MsgSub // 4. The sender immediately starts the next round by registering // his new bundle proposal. - // Calculate the total reward for the bundle, and individual payouts. - bundleReward := k.calculatePayouts(ctx, msg.PoolId) - - if err := k.poolKeeper.ChargeFundersOfPool(ctx, msg.PoolId, bundleReward.Total); err != nil { - // update the latest time on bundle to indicate that the bundle is still active - // protocol nodes use this to determine the upload timeout - bundleProposal.UpdatedAt = uint64(ctx.BlockTime().Unix()) - k.SetBundleProposal(ctx, bundleProposal) - - // emit event which indicates that pool has run out of funds - _ = ctx.EventManager().EmitTypedEvent(&poolTypes.EventPoolOutOfFunds{ - PoolId: msg.PoolId, - }) + pool, _ := k.poolKeeper.GetPool(ctx, msg.PoolId) - return &types.MsgSubmitBundleProposalResponse{}, nil + // charge the operating cost from funders + fundersPayout, err := k.poolKeeper.ChargeFundersOfPool(ctx, msg.PoolId, pool.OperatingCost) + if err != nil { + return &types.MsgSubmitBundleProposalResponse{}, err } - pool, _ := k.poolKeeper.GetPool(ctx, msg.PoolId) - bundleProposal, _ := k.GetBundleProposal(ctx, msg.PoolId) + // charge the inflation pool + inflationPayout, err := k.poolKeeper.ChargeInflationPool(ctx, msg.PoolId) + if err != nil { + return &types.MsgSubmitBundleProposalResponse{}, err + } - uploaderPayout := bundleReward.Uploader + // calculate payouts to the different stakeholders like treasury, uploader and delegators + bundleReward := k.calculatePayouts(ctx, msg.PoolId, fundersPayout+inflationPayout) - delegationPayoutSuccessful := k.delegationKeeper.PayoutRewards(ctx, bundleProposal.Uploader, bundleReward.Delegation, poolTypes.ModuleName) - // If staker has no delegators add all delegation rewards to the staker rewards - if !delegationPayoutSuccessful { - uploaderPayout += bundleReward.Delegation + // payout rewards to treasury + if err := util.TransferFromModuleToTreasury(k.accountKeeper, k.distrkeeper, ctx, poolTypes.ModuleName, bundleReward.Treasury); err != nil { + return nil, err } - // transfer funds from pool to stakers module - if err := util.TransferFromModuleToModule(k.bankKeeper, ctx, poolTypes.ModuleName, stakersTypes.ModuleName, uploaderPayout); err != nil { + // payout rewards to uploader through commission rewards + if err := k.stakerKeeper.IncreaseStakerCommissionRewards(ctx, bundleProposal.Uploader, bundleReward.Uploader); err != nil { return nil, err } - // increase commission rewards of uploader - k.stakerKeeper.IncreaseStakerCommissionRewards(ctx, bundleProposal.Uploader, uploaderPayout) - - // send network fee to treasury - if err := util.TransferFromModuleToTreasury(k.accountKeeper, k.distrkeeper, ctx, poolTypes.ModuleName, bundleReward.Treasury); err != nil { + // payout rewards to delegators through delegation rewards + if err := k.delegationKeeper.PayoutRewards(ctx, bundleProposal.Uploader, bundleReward.Delegation, poolTypes.ModuleName); err != nil { return nil, err } @@ -116,13 +106,12 @@ func (k msgServer) SubmitBundleProposal(goCtx context.Context, msg *types.MsgSub // Get next uploader from stakers who voted `valid` nextUploader := k.chooseNextUploaderFromList(ctx, msg.PoolId, bundleProposal.VotersValid) - k.finalizeCurrentBundleProposal(ctx, pool.Id, voteDistribution, bundleReward, nextUploader) + k.finalizeCurrentBundleProposal(ctx, pool.Id, voteDistribution, fundersPayout, inflationPayout, bundleReward, nextUploader) // Register the provided bundle as a new proposal for the next round k.registerBundleProposalFromUploader(ctx, msg, nextUploader) return &types.MsgSubmitBundleProposalResponse{}, nil - case types.BUNDLE_STATUS_INVALID: // If the bundles is invalid, everybody who voted incorrectly gets slashed. // The bundle provided by the message-sender is of no mean, because the previous bundle diff --git a/x/bundles/module.go b/x/bundles/module.go index c27f0c28..85d6e1be 100644 --- a/x/bundles/module.go +++ b/x/bundles/module.go @@ -4,6 +4,14 @@ import ( "context" "encoding/json" "fmt" + + poolKeeper "github.com/KYVENetwork/chain/x/pool/keeper" + teamKeeper "github.com/KYVENetwork/chain/x/team/keeper" + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + distributionKeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + mintKeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + upgradeKeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + // this line is used by starport scaffolding # 1 "github.com/grpc-ecosystem/grpc-gateway/runtime" @@ -91,22 +99,37 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper types.AccountKeeper - bankKeeper types.BankKeeper + keeper keeper.Keeper + accountKeeper types.AccountKeeper + bankKeeper bankKeeper.Keeper + distributionKeeper distributionKeeper.Keeper + mintKeeper mintKeeper.Keeper + upgradeKeeper upgradeKeeper.Keeper + poolKeeper poolKeeper.Keeper + teamKeeper teamKeeper.Keeper } func NewAppModule( cdc codec.Codec, keeper keeper.Keeper, accountKeeper types.AccountKeeper, - bankKeeper types.BankKeeper, + bankKeeper bankKeeper.Keeper, + distributionKeeper distributionKeeper.Keeper, + mintKeeper mintKeeper.Keeper, + upgradeKeeper upgradeKeeper.Keeper, + poolKeeper poolKeeper.Keeper, + teamKeeper teamKeeper.Keeper, ) AppModule { return AppModule{ - AppModuleBasic: NewAppModuleBasic(cdc), - keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, + AppModuleBasic: NewAppModuleBasic(cdc), + keeper: keeper, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + distributionKeeper: distributionKeeper, + mintKeeper: mintKeeper, + upgradeKeeper: upgradeKeeper, + poolKeeper: poolKeeper, + teamKeeper: teamKeeper, } } @@ -153,6 +176,7 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { am.keeper.InitMemStore(ctx) + SplitInflation(ctx, am.keeper, am.bankKeeper, am.mintKeeper, am.poolKeeper, am.teamKeeper, am.upgradeKeeper) } // EndBlock contains the logic that is automatically triggered at the end of each block diff --git a/x/bundles/spec/04_begin_block.md b/x/bundles/spec/04_begin_block.md new file mode 100644 index 00000000..cb7d4c17 --- /dev/null +++ b/x/bundles/spec/04_begin_block.md @@ -0,0 +1,9 @@ + + +# BeginBlock + +BeginBlock is used to distribute the inflation split to the pools. +All active pools are eligible for the inflation split. The distribution +between the pools are determined by the operating cost of each pool. diff --git a/x/bundles/spec/04_end_block.md b/x/bundles/spec/05_end_block.md similarity index 98% rename from x/bundles/spec/04_end_block.md rename to x/bundles/spec/05_end_block.md index aedb2a34..3ef944bf 100644 --- a/x/bundles/spec/04_end_block.md +++ b/x/bundles/spec/05_end_block.md @@ -1,5 +1,5 @@ # EndBlock diff --git a/x/bundles/spec/06_events.md b/x/bundles/spec/06_events.md index a79557d4..fbf6b526 100644 --- a/x/bundles/spec/06_events.md +++ b/x/bundles/spec/06_events.md @@ -92,22 +92,26 @@ message EventBundleFinalized { uint64 abstain = 5; // total voting power of the pool uint64 total = 6; - // vestingStatus of the finalized bundle - BundleStatus vestingStatus = 7; + // status of the finalized bundle + BundleStatus status = 7; + // amount which funders provided to the total bundle reward (in ukyve) + uint64 funders_payout = 8; + // amount which the inflation pool provided to the total reward (in ukyve) + uint64 inflation_payout = 9; // rewards transferred to treasury (in ukyve) - uint64 reward_treasury = 8; + uint64 reward_treasury = 10; // rewardUploader rewards directly transferred to uploader (in ukyve) - uint64 reward_uploader = 9; + uint64 reward_uploader = 11; // rewardDelegation rewards distributed among all delegators (in ukyve) - uint64 reward_delegation = 10; + uint64 reward_delegation = 12; // rewardTotal the total bundle reward - uint64 reward_total = 11; + uint64 reward_total = 13; // finalized_at the block height where the bundle got finalized - uint64 finalized_at = 12; + uint64 finalized_at = 14; // uploader the address of the uploader of this bundle - string uploader = 13; + string uploader = 15; // next_uploader the address of the next uploader after this bundle - string next_uploader = 14; + string next_uploader = 16; } ``` diff --git a/x/bundles/spec/05_params.md b/x/bundles/spec/08_params.md similarity index 97% rename from x/bundles/spec/05_params.md rename to x/bundles/spec/08_params.md index 00257271..c14aa4ce 100644 --- a/x/bundles/spec/05_params.md +++ b/x/bundles/spec/08_params.md @@ -1,5 +1,5 @@ # Parameters diff --git a/x/bundles/types/events.pb.go b/x/bundles/types/events.pb.go index a154c821..689b44e5 100644 --- a/x/bundles/types/events.pb.go +++ b/x/bundles/types/events.pb.go @@ -347,20 +347,24 @@ type EventBundleFinalized struct { Total uint64 `protobuf:"varint,6,opt,name=total,proto3" json:"total,omitempty"` // status of the finalized bundle Status BundleStatus `protobuf:"varint,7,opt,name=status,proto3,enum=kyve.bundles.v1beta1.BundleStatus" json:"status,omitempty"` + // amount which funders provided to the total bundle reward (in ukyve) + FundersPayout uint64 `protobuf:"varint,8,opt,name=funders_payout,json=fundersPayout,proto3" json:"funders_payout,omitempty"` + // amount which the inflation pool provided to the total reward (in ukyve) + InflationPayout uint64 `protobuf:"varint,9,opt,name=inflation_payout,json=inflationPayout,proto3" json:"inflation_payout,omitempty"` // rewards transferred to treasury (in ukyve) - RewardTreasury uint64 `protobuf:"varint,8,opt,name=reward_treasury,json=rewardTreasury,proto3" json:"reward_treasury,omitempty"` + RewardTreasury uint64 `protobuf:"varint,10,opt,name=reward_treasury,json=rewardTreasury,proto3" json:"reward_treasury,omitempty"` // rewardUploader rewards directly transferred to uploader (in ukyve) - RewardUploader uint64 `protobuf:"varint,9,opt,name=reward_uploader,json=rewardUploader,proto3" json:"reward_uploader,omitempty"` + RewardUploader uint64 `protobuf:"varint,11,opt,name=reward_uploader,json=rewardUploader,proto3" json:"reward_uploader,omitempty"` // rewardDelegation rewards distributed among all delegators (in ukyve) - RewardDelegation uint64 `protobuf:"varint,10,opt,name=reward_delegation,json=rewardDelegation,proto3" json:"reward_delegation,omitempty"` + RewardDelegation uint64 `protobuf:"varint,12,opt,name=reward_delegation,json=rewardDelegation,proto3" json:"reward_delegation,omitempty"` // rewardTotal the total bundle reward - RewardTotal uint64 `protobuf:"varint,11,opt,name=reward_total,json=rewardTotal,proto3" json:"reward_total,omitempty"` + RewardTotal uint64 `protobuf:"varint,13,opt,name=reward_total,json=rewardTotal,proto3" json:"reward_total,omitempty"` // finalized_at the block height where the bundle got finalized - FinalizedAt uint64 `protobuf:"varint,12,opt,name=finalized_at,json=finalizedAt,proto3" json:"finalized_at,omitempty"` + FinalizedAt uint64 `protobuf:"varint,14,opt,name=finalized_at,json=finalizedAt,proto3" json:"finalized_at,omitempty"` // uploader the address of the uploader of this bundle - Uploader string `protobuf:"bytes,13,opt,name=uploader,proto3" json:"uploader,omitempty"` + Uploader string `protobuf:"bytes,15,opt,name=uploader,proto3" json:"uploader,omitempty"` // next_uploader the address of the next uploader after this bundle - NextUploader string `protobuf:"bytes,14,opt,name=next_uploader,json=nextUploader,proto3" json:"next_uploader,omitempty"` + NextUploader string `protobuf:"bytes,16,opt,name=next_uploader,json=nextUploader,proto3" json:"next_uploader,omitempty"` } func (m *EventBundleFinalized) Reset() { *m = EventBundleFinalized{} } @@ -445,6 +449,20 @@ func (m *EventBundleFinalized) GetStatus() BundleStatus { return BUNDLE_STATUS_UNSPECIFIED } +func (m *EventBundleFinalized) GetFundersPayout() uint64 { + if m != nil { + return m.FundersPayout + } + return 0 +} + +func (m *EventBundleFinalized) GetInflationPayout() uint64 { + if m != nil { + return m.InflationPayout + } + return 0 +} + func (m *EventBundleFinalized) GetRewardTreasury() uint64 { if m != nil { return m.RewardTreasury @@ -769,61 +787,63 @@ func init() { func init() { proto.RegisterFile("kyve/bundles/v1beta1/events.proto", fileDescriptor_a02f505e55d81e92) } var fileDescriptor_a02f505e55d81e92 = []byte{ - // 858 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0xce, 0x26, 0x1b, 0x27, 0x7b, 0xfc, 0xd3, 0x64, 0x1b, 0x60, 0x09, 0xd4, 0x4d, 0x8c, 0x10, - 0x91, 0x8a, 0x6c, 0x35, 0xdc, 0x71, 0x97, 0x94, 0x56, 0x58, 0x95, 0x50, 0xb4, 0x69, 0x2b, 0xc1, - 0x8d, 0x35, 0xce, 0x9c, 0xd8, 0x23, 0xaf, 0x77, 0x46, 0x33, 0x63, 0x3b, 0xce, 0x53, 0x20, 0x21, - 0x9e, 0x84, 0x57, 0xe0, 0xa2, 0x97, 0xbd, 0xe4, 0x0a, 0x41, 0xf2, 0x22, 0x68, 0x7e, 0x76, 0x6d, -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 0x97, 0x03, 0xa6, 0x87, 0x93, 0x7e, 0xfb, 0x82, 0x8f, 0x3b, - 0xcf, 0xbf, 0x7f, 0xf5, 0xf4, 0x3b, 0xd4, 0x33, 0x2e, 0x47, 0x9d, 0x8b, 0x21, 0x61, 0x79, 0xe7, - 0xaa, 0xfc, 0xf7, 0xd3, 0x73, 0x81, 0xaa, 0x5f, 0xb1, 0xff, 0x7c, 0x5f, 0xfd, 0x15, 0x00, 0x00, - 0xff, 0xff, 0x37, 0x28, 0x51, 0xd0, 0xb0, 0x07, 0x00, 0x00, + // 895 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xdf, 0x6e, 0x1b, 0xc5, + 0x17, 0xce, 0xa6, 0x1b, 0x27, 0x7b, 0xfc, 0x27, 0xce, 0x36, 0xbf, 0x1f, 0x4b, 0xa0, 0x6e, 0x62, + 0x84, 0x08, 0x2a, 0xb2, 0xd5, 0x70, 0xc7, 0x5d, 0x52, 0x5a, 0x61, 0x55, 0x42, 0xd6, 0xa6, 0xad, + 0x04, 0x37, 0xd6, 0x38, 0x73, 0x6c, 0x8f, 0xbc, 0xde, 0x59, 0xcd, 0xcc, 0xda, 0x71, 0x9e, 0x02, + 0x09, 0xf1, 0x24, 0x7d, 0x05, 0x2e, 0x7a, 0xd9, 0x4b, 0xae, 0x10, 0x4a, 0x5e, 0x04, 0xcd, 0x9f, + 0xdd, 0x98, 0xe0, 0x42, 0xcb, 0x9d, 0xcf, 0x77, 0xbe, 0xf9, 0xce, 0xb7, 0xe7, 0x9c, 0x19, 0xc3, + 0xd1, 0x74, 0x39, 0xc7, 0xee, 0x30, 0x4f, 0x69, 0x82, 0xb2, 0x3b, 0x7f, 0x3c, 0x44, 0x45, 0x1e, + 0x77, 0x71, 0x8e, 0xa9, 0x92, 0x9d, 0x4c, 0x70, 0xc5, 0xc3, 0x7d, 0x4d, 0xe9, 0x38, 0x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f, 0x78, 0xf5, 0xf4, 0x7b, 0x54, 0x0b, 0x2e, 0xa6, 0xdd, + 0x8b, 0x09, 0x61, 0x69, 0xf7, 0xb2, 0xfc, 0x3f, 0x55, 0xcb, 0x0c, 0xe5, 0xb0, 0x62, 0xfe, 0x4b, + 0xbf, 0xfe, 0x33, 0x00, 0x00, 0xff, 0xff, 0x0d, 0xeb, 0x71, 0xdc, 0x02, 0x08, 0x00, 0x00, } func (m *EventUpdateParams) Marshal() (dAtA []byte, err error) { @@ -1053,38 +1073,50 @@ func (m *EventBundleFinalized) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.NextUploader) i = encodeVarintEvents(dAtA, i, uint64(len(m.NextUploader))) i-- - dAtA[i] = 0x72 + dAtA[i] = 0x1 + i-- + dAtA[i] = 0x82 } if len(m.Uploader) > 0 { i -= len(m.Uploader) copy(dAtA[i:], m.Uploader) i = encodeVarintEvents(dAtA, i, uint64(len(m.Uploader))) i-- - dAtA[i] = 0x6a + dAtA[i] = 0x7a } if m.FinalizedAt != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.FinalizedAt)) i-- - dAtA[i] = 0x60 + dAtA[i] = 0x70 } if m.RewardTotal != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.RewardTotal)) i-- - dAtA[i] = 0x58 + dAtA[i] = 0x68 } if m.RewardDelegation != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.RewardDelegation)) i-- - dAtA[i] = 0x50 + dAtA[i] = 0x60 } if m.RewardUploader != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.RewardUploader)) i-- - dAtA[i] = 0x48 + dAtA[i] = 0x58 } if m.RewardTreasury != 0 { i = encodeVarintEvents(dAtA, i, uint64(m.RewardTreasury)) i-- + dAtA[i] = 0x50 + } + if m.InflationPayout != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.InflationPayout)) + i-- + dAtA[i] = 0x48 + } + if m.FundersPayout != 0 { + i = encodeVarintEvents(dAtA, i, uint64(m.FundersPayout)) + i-- dAtA[i] = 0x40 } if m.Status != 0 { @@ -1422,6 +1454,12 @@ func (m *EventBundleFinalized) Size() (n int) { if m.Status != 0 { n += 1 + sovEvents(uint64(m.Status)) } + if m.FundersPayout != 0 { + n += 1 + sovEvents(uint64(m.FundersPayout)) + } + if m.InflationPayout != 0 { + n += 1 + sovEvents(uint64(m.InflationPayout)) + } if m.RewardTreasury != 0 { n += 1 + sovEvents(uint64(m.RewardTreasury)) } @@ -1443,7 +1481,7 @@ func (m *EventBundleFinalized) Size() (n int) { } l = len(m.NextUploader) if l > 0 { - n += 1 + l + sovEvents(uint64(l)) + n += 2 + l + sovEvents(uint64(l)) } return n } @@ -2388,6 +2426,44 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { } } case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field FundersPayout", wireType) + } + m.FundersPayout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.FundersPayout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field InflationPayout", wireType) + } + m.InflationPayout = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.InflationPayout |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 10: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field RewardTreasury", wireType) } @@ -2406,7 +2482,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { break } } - case 9: + case 11: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field RewardUploader", wireType) } @@ -2425,7 +2501,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { break } } - case 10: + case 12: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field RewardDelegation", wireType) } @@ -2444,7 +2520,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { break } } - case 11: + case 13: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field RewardTotal", wireType) } @@ -2463,7 +2539,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { break } } - case 12: + case 14: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field FinalizedAt", wireType) } @@ -2482,7 +2558,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { break } } - case 13: + case 15: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Uploader", wireType) } @@ -2514,7 +2590,7 @@ func (m *EventBundleFinalized) Unmarshal(dAtA []byte) error { } m.Uploader = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 14: + case 16: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field NextUploader", wireType) } diff --git a/x/bundles/types/expected_keepers.go b/x/bundles/types/expected_keepers.go index b30db737..cec3a1c1 100644 --- a/x/bundles/types/expected_keepers.go +++ b/x/bundles/types/expected_keepers.go @@ -36,13 +36,14 @@ type PoolKeeper interface { IncrementBundleInformation(ctx sdk.Context, poolId uint64, currentHeight uint64, currentKey string, currentValue string) GetAllPools(ctx sdk.Context) (list []pooltypes.Pool) - ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) error + ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) (payout uint64, err error) + ChargeInflationPool(ctx sdk.Context, poolId uint64) (payout uint64, err error) } type StakerKeeper interface { GetAllStakerAddressesOfPool(ctx sdk.Context, poolId uint64) (stakers []string) GetCommission(ctx sdk.Context, stakerAddress string) sdk.Dec - IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) + IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) error AssertValaccountAuthorized(ctx sdk.Context, poolId uint64, stakerAddress string, valaddress string) error DoesStakerExist(ctx sdk.Context, staker string) bool @@ -57,6 +58,6 @@ type StakerKeeper interface { type DelegationKeeper interface { GetDelegationAmount(ctx sdk.Context, staker string) uint64 GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 - PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) (success bool) + PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) error SlashDelegators(ctx sdk.Context, poolId uint64, staker string, slashType delegationTypes.SlashType) } diff --git a/x/delegation/keeper/exported_functions.go b/x/delegation/keeper/exported_functions.go index a43e304d..aa87037a 100644 --- a/x/delegation/keeper/exported_functions.go +++ b/x/delegation/keeper/exported_functions.go @@ -1,9 +1,11 @@ package keeper import ( + "cosmossdk.io/errors" "github.com/KYVENetwork/chain/util" "github.com/KYVENetwork/chain/x/delegation/types" sdk "github.com/cosmos/cosmos-sdk/types" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" ) // These functions are meant to be called from external modules @@ -43,24 +45,28 @@ func (k Keeper) GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 { // PayoutRewards transfers `amount` $nKYVE from the `payerModuleName`-module to the delegation module. // It then awards these tokens internally to all delegators of staker `staker`. // Delegators can then receive these rewards if they call the `withdraw`-transaction. -// This method returns false if the payout fails. This happens usually if there are no -// delegators for that staker. If this happens one should do something else with the rewards. -func (k Keeper) PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) (success bool) { +// If the staker has no delegators or the module to module transfer fails the method fails and +// returns the error. +func (k Keeper) PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) error { + // Assert there is an amount + if amount == 0 { + return nil + } + // Assert there are delegators - if k.DoesDelegationDataExist(ctx, staker) { + if !k.DoesDelegationDataExist(ctx, staker) { + return errors.Wrapf(sdkErrors.ErrLogic, "Staker has no delegators which can be paid out.") + } - // Add amount to the rewards pool - k.AddAmountToDelegationRewards(ctx, staker, amount) + // Add amount to the rewards pool + k.AddAmountToDelegationRewards(ctx, staker, amount) - // Transfer tokens to the delegation module - err := util.TransferFromModuleToModule(k.bankKeeper, ctx, payerModuleName, types.ModuleName, amount) - if err != nil { - util.PanicHalt(k.upgradeKeeper, ctx, "Not enough tokens in module") - return false - } - return true + // Transfer tokens to the delegation module + if err := util.TransferFromModuleToModule(k.bankKeeper, ctx, payerModuleName, types.ModuleName, amount); err != nil { + return err } - return false + + return nil } // SlashDelegators reduces the delegation of all delegators of `staker` by fraction diff --git a/x/delegation/keeper/keeper_suite_test.go b/x/delegation/keeper/keeper_suite_test.go index 37185cbb..160587f1 100644 --- a/x/delegation/keeper/keeper_suite_test.go +++ b/x/delegation/keeper/keeper_suite_test.go @@ -18,15 +18,16 @@ func TestDelegationKeeper(t *testing.T) { } func PayoutRewards(s *i.KeeperTestSuite, staker string, amount uint64) { - err := s.App().PoolKeeper.ChargeFundersOfPool(s.Ctx(), 0, amount) + payout, err := s.App().PoolKeeper.ChargeFundersOfPool(s.Ctx(), 0, amount) Expect(err).To(BeNil()) - success := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), staker, amount, pooltypes.ModuleName) - Expect(success).To(BeTrue()) + err = s.App().DelegationKeeper.PayoutRewards(s.Ctx(), staker, amount, pooltypes.ModuleName) + Expect(err).NotTo(HaveOccurred()) + Expect(amount).To(Equal(payout)) } func CreateFundedPool(s *i.KeeperTestSuite) { s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/delegation/keeper/msg_server_redelegate_test.go b/x/delegation/keeper/msg_server_redelegate_test.go index b56b7f0c..43dc8361 100644 --- a/x/delegation/keeper/msg_server_redelegate_test.go +++ b/x/delegation/keeper/msg_server_redelegate_test.go @@ -35,7 +35,8 @@ var _ = Describe("Delegation - Redelegation", Ordered, func() { CreateFundedPool(s) s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "EnabledPool", + Name: "EnabledPool", + MinDelegation: 1_000 * i.KYVE, Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/delegation/keeper/msg_server_withdraw_rewards_test.go b/x/delegation/keeper/msg_server_withdraw_rewards_test.go index fc062d4a..331eaadb 100644 --- a/x/delegation/keeper/msg_server_withdraw_rewards_test.go +++ b/x/delegation/keeper/msg_server_withdraw_rewards_test.go @@ -153,14 +153,22 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { It("Test invalid payouts to delegators", func() { // ARRANGE - forkedCtx, _ := s.Ctx().CacheContext() + + // fund pool module + s.RunTxPoolSuccess(&pooltypes.MsgFundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) // ACT - success1 := s.App().DelegationKeeper.PayoutRewards(forkedCtx, i.ALICE, 20000*i.KYVE, pooltypes.ModuleName) - success2 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.DUMMY[20], 0*i.KYVE, pooltypes.ModuleName) + // not enough balance in pool module + err1 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.ALICE, 20000*i.KYVE, pooltypes.ModuleName) + // staker does not exist + err2 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.DUMMY[20], 1*i.KYVE, pooltypes.ModuleName) // ASSERT - Expect(success1).To(BeFalse()) - Expect(success2).To(BeFalse()) + Expect(err1).To(HaveOccurred()) + Expect(err2).To(HaveOccurred()) }) }) diff --git a/x/delegation/spec/07_exported.md b/x/delegation/spec/07_exported.md index 9772bfc9..7ae0aa21 100644 --- a/x/delegation/spec/07_exported.md +++ b/x/delegation/spec/07_exported.md @@ -25,9 +25,9 @@ type DelegationKeeper interface { // PayoutRewards transfers `amount` $nKYVE from the `payerModuleName`-module to the delegation module. // It then awards these tokens internally to all delegators of staker `staker`. // Delegators can then receive these rewards if they call the `withdraw`-transaction. - // This method returns false if the payout fails. This happens usually if there are no - // delegators for that staker. If this happens one should do something else with the rewards. - PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) (success bool) + // If the staker has no delegators or the module to module transfer fails the method fails and + // returns the error. + PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) error // SlashDelegators reduces the delegation of all delegators of `staker` by fraction // and transfers the amount to the Treasury. diff --git a/x/pool/client/cli/query.go b/x/pool/client/cli/query.go new file mode 100644 index 00000000..37080a34 --- /dev/null +++ b/x/pool/client/cli/query.go @@ -0,0 +1,23 @@ +package cli + +import ( + "fmt" + + "github.com/KYVENetwork/chain/x/pool/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/spf13/cobra" +) + +func GetQueryCmd() *cobra.Command { + cmd := &cobra.Command{ + Use: types.ModuleName, + Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName), + DisableFlagParsing: true, + SuggestionsMinimumDistance: 2, + RunE: client.ValidateCmd, + } + + cmd.AddCommand(CmdQueryParams()) + + return cmd +} diff --git a/x/pool/client/cli/query_params.go b/x/pool/client/cli/query_params.go new file mode 100644 index 00000000..26f58d78 --- /dev/null +++ b/x/pool/client/cli/query_params.go @@ -0,0 +1,34 @@ +package cli + +import ( + "context" + + "github.com/KYVENetwork/chain/x/pool/types" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/spf13/cobra" +) + +func CmdQueryParams() *cobra.Command { + cmd := &cobra.Command{ + Use: "params", + Short: "shows the parameters of the module", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{}) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) + }, + } + + flags.AddQueryFlagsToCmd(cmd) + + return cmd +} diff --git a/x/pool/genesis.go b/x/pool/genesis.go index 33d12006..23b30394 100644 --- a/x/pool/genesis.go +++ b/x/pool/genesis.go @@ -8,6 +8,8 @@ import ( // InitGenesis initializes the pool module's state from a provided genesis state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { + k.SetParams(ctx, genState.Params) + for _, elem := range genState.PoolList { k.SetPool(ctx, elem) } @@ -19,6 +21,7 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { genesis := types.DefaultGenesis() + genesis.Params = k.GetParams(ctx) genesis.PoolList = k.GetAllPools(ctx) genesis.PoolCount = k.GetPoolCount(ctx) diff --git a/x/pool/keeper/getters_params.go b/x/pool/keeper/getters_params.go new file mode 100644 index 00000000..bf311ec9 --- /dev/null +++ b/x/pool/keeper/getters_params.go @@ -0,0 +1,32 @@ +package keeper + +import ( + "github.com/KYVENetwork/chain/x/pool/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// GetParams returns the x/pool params from state. +func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { + bz := ctx.KVStore(k.storeKey).Get(types.ParamsKey) + if bz != nil { + k.cdc.MustUnmarshal(bz, ¶ms) + } + + return +} + +// GetProtocolInflationShare returns the ProtocolInflationShare param. +func (k Keeper) GetProtocolInflationShare(ctx sdk.Context) (res sdk.Dec) { + return k.GetParams(ctx).ProtocolInflationShare +} + +// GetPoolInflationPayoutRate returns the GetPoolInflationPayoutRate param +func (k Keeper) GetPoolInflationPayoutRate(ctx sdk.Context) (res sdk.Dec) { + return k.GetParams(ctx).PoolInflationPayoutRate +} + +// SetParams stores the x/pool params in state. +func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { + bz := k.cdc.MustMarshal(¶ms) + ctx.KVStore(k.storeKey).Set(types.ParamsKey, bz) +} diff --git a/x/pool/keeper/grpc_query.go b/x/pool/keeper/grpc_query.go new file mode 100644 index 00000000..2b92ddf8 --- /dev/null +++ b/x/pool/keeper/grpc_query.go @@ -0,0 +1,21 @@ +package keeper + +import ( + "context" + + "github.com/KYVENetwork/chain/x/pool/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +var _ types.QueryServer = Keeper{} + +func (k Keeper) Params(c context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) { + if req == nil { + return nil, status.Error(codes.InvalidArgument, "invalid request") + } + ctx := sdk.UnwrapSDKContext(c) + + return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil +} diff --git a/x/pool/keeper/keeper.go b/x/pool/keeper/keeper.go index cd9a4dc3..1b3e9c51 100644 --- a/x/pool/keeper/keeper.go +++ b/x/pool/keeper/keeper.go @@ -3,45 +3,57 @@ package keeper import ( "fmt" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - + "github.com/cosmos/cosmos-sdk/codec" + storeTypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/tendermint/tendermint/libs/log" + // Auth + authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" + // Bank + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + // Distribution + distributionKeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + // Mint + mintKeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + // Pool "github.com/KYVENetwork/chain/x/pool/types" - "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" + // Team + teamKeeper "github.com/KYVENetwork/chain/x/team/keeper" ) type ( Keeper struct { cdc codec.BinaryCodec - storeKey storetypes.StoreKey - memKey storetypes.StoreKey + storeKey storeTypes.StoreKey + memKey storeTypes.StoreKey authority string stakersKeeper types.StakersKeeper - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper - distrkeeper distrkeeper.Keeper + accountKeeper authKeeper.AccountKeeper + bankKeeper bankKeeper.Keeper + distrkeeper distributionKeeper.Keeper + mintKeeper mintKeeper.Keeper upgradeKeeper types.UpgradeKeeper + teamKeeper teamKeeper.Keeper } ) func NewKeeper( cdc codec.BinaryCodec, - storeKey storetypes.StoreKey, - memKey storetypes.StoreKey, + storeKey storeTypes.StoreKey, + memKey storeTypes.StoreKey, authority string, - accountKeeper authkeeper.AccountKeeper, - bankKeeper bankkeeper.Keeper, - distrKeeper distrkeeper.Keeper, + accountKeeper authKeeper.AccountKeeper, + bankKeeper bankKeeper.Keeper, + distrKeeper distributionKeeper.Keeper, + mintKeeper mintKeeper.Keeper, upgradeKeeper types.UpgradeKeeper, + teamKeeper teamKeeper.Keeper, ) *Keeper { return &Keeper{ cdc: cdc, @@ -53,8 +65,29 @@ func NewKeeper( accountKeeper: accountKeeper, bankKeeper: bankKeeper, distrkeeper: distrKeeper, + mintKeeper: mintKeeper, upgradeKeeper: upgradeKeeper, + teamKeeper: teamKeeper, + } +} + +func (k Keeper) EnsurePoolAccount(ctx sdk.Context, id uint64) { + name := fmt.Sprintf("%s/%d", types.ModuleName, id) + + address := authTypes.NewModuleAddress(name) + account := k.accountKeeper.GetAccount(ctx, address) + + if account == nil { + // account doesn't exist, initialise a new module account. + account = authTypes.NewEmptyModuleAccount(name) + } else { + // account exists, adjust it to a module account. + baseAccount := authTypes.NewBaseAccount(address, nil, account.GetAccountNumber(), 0) + + account = authTypes.NewModuleAccount(baseAccount, name) } + + k.accountKeeper.SetAccount(ctx, account) } func SetStakersKeeper(k *Keeper, stakersKeeper types.StakersKeeper) { @@ -65,6 +98,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", fmt.Sprintf("x/%s", types.ModuleName)) } -func (k Keeper) StoreKey() storetypes.StoreKey { +func (k Keeper) StoreKey() storeTypes.StoreKey { return k.storeKey } diff --git a/x/pool/keeper/logic_end_block_handle_pool_upgrades_test.go b/x/pool/keeper/logic_end_block_handle_pool_upgrades_test.go index e0e0d633..416361ce 100644 --- a/x/pool/keeper/logic_end_block_handle_pool_upgrades_test.go +++ b/x/pool/keeper/logic_end_block_handle_pool_upgrades_test.go @@ -29,7 +29,7 @@ var _ = Describe("logic_end_block_handle_pool_upgrades.go", Ordered, func() { // create clean pool for every test case s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", MaxBundleSize: 100, StartKey: "0", MinDelegation: 100 * i.KYVE, diff --git a/x/pool/keeper/logic_funders.go b/x/pool/keeper/logic_funders.go index f72c2972..d5ad55d1 100644 --- a/x/pool/keeper/logic_funders.go +++ b/x/pool/keeper/logic_funders.go @@ -1,8 +1,7 @@ package keeper import ( - "github.com/KYVENetwork/chain/util" - pooltypes "github.com/KYVENetwork/chain/x/pool/types" + poolTypes "github.com/KYVENetwork/chain/x/pool/types" sdk "github.com/cosmos/cosmos-sdk/types" ) @@ -10,69 +9,56 @@ import ( // the appropriate amount from each funder. // All funders who can't afford the amount, are kicked out. // Their remaining amount is transferred to the Treasury. -// The function throws an error if pool ran out of funds. // This method does not transfer any funds. The bundles-module // is responsible for transferring the rewards out of the module. -func (k Keeper) ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) error { +func (k Keeper) ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) (payout uint64, err error) { pool, poolErr := k.GetPoolWithError(ctx, poolId) if poolErr != nil { - return poolErr + return 0, poolErr + } + + // if pool has no funders we immediately return + if len(pool.Funders) == 0 { + return payout, err } // This is the amount every funder will be charged - var amountPerFunder uint64 + amountPerFunder := amount / uint64(len(pool.Funders)) // Due to discrete division there will be a reminder which can not be split // equally among all funders. This amount is charged to the lowest funder - var amountRemainder uint64 - - // When a funder is not able to pay, all the remaining funds will be moved - // to the treasury. - var slashedFunds uint64 - - // Remove all funders who can not afford amountPerFunder - for len(pool.Funders) > 0 { - amountPerFunder = amount / uint64(len(pool.Funders)) - amountRemainder = amount - amountPerFunder*uint64(len(pool.Funders)) + amountRemainder := amount - amountPerFunder*uint64(len(pool.Funders)) - lowestFunder := pool.GetLowestFunder() + funders := pool.Funders - if amountRemainder+amountPerFunder > lowestFunder.Amount { - pool.RemoveFunder(lowestFunder.Address) - - _ = ctx.EventManager().EmitTypedEvent(&pooltypes.EventPoolFundsSlashed{ - PoolId: poolId, - Address: lowestFunder.Address, - Amount: lowestFunder.Amount, - }) - - slashedFunds += lowestFunder.Amount + for _, funder := range funders { + if funder.Amount < amountPerFunder { + pool.RemoveFunder(funder.Address) + payout += funder.Amount } else { - break + pool.SubtractAmountFromFunder(funder.Address, amountPerFunder) + payout += amountPerFunder } } - if slashedFunds > 0 { - // send slash to treasury - if err := util.TransferFromModuleToTreasury(k.accountKeeper, k.distrkeeper, ctx, pooltypes.ModuleName, slashedFunds); err != nil { - util.PanicHalt(k.upgradeKeeper, ctx, "pool module out of funds") + lowestFunder := pool.GetLowestFunder() + + if lowestFunder.Address != "" { + if lowestFunder.Amount < amountRemainder { + pool.RemoveFunder(lowestFunder.Address) + payout += lowestFunder.Amount + } else { + pool.SubtractAmountFromFunder(lowestFunder.Address, amountRemainder) + payout += amountRemainder } } if len(pool.Funders) == 0 { - k.SetPool(ctx, pool) - return pooltypes.ErrFundsTooLow - } - - // Remove amount from funders - for _, funder := range pool.Funders { - pool.SubtractAmountFromFunder(funder.Address, amountPerFunder) + _ = ctx.EventManager().EmitTypedEvent(&poolTypes.EventPoolOutOfFunds{ + PoolId: pool.Id, + }) } - lowestFunder := pool.GetLowestFunder() - pool.SubtractAmountFromFunder(lowestFunder.Address, amountRemainder) - k.SetPool(ctx, pool) - - return nil + return payout, nil } diff --git a/x/pool/keeper/logic_funders_test.go b/x/pool/keeper/logic_funders_test.go index ecff4204..ebb83291 100644 --- a/x/pool/keeper/logic_funders_test.go +++ b/x/pool/keeper/logic_funders_test.go @@ -10,7 +10,7 @@ import ( /* -TEST CASES - logic_funders_test.go +TEST CASES - logic_funders.go * Add funders; check total sum * Add multiple funders; check total sum @@ -20,16 +20,22 @@ TEST CASES - logic_funders_test.go * Charge Funders test remainder * Charge exactly the lowest funder amount * Kick out multiple lowest funders -* Kick out all funders +* Charge more than pool has funds +* Charge pool which has no funds at all */ -func chargeFunders(s *i.KeeperTestSuite, amount uint64) error { - err := s.App().PoolKeeper.ChargeFundersOfPool(s.Ctx(), 0, amount) - if err == nil { - return util.TransferFromModuleToAddress(s.App().BankKeeper, s.Ctx(), pooltypes.ModuleName, i.BURNER, amount) +func chargeFunders(s *i.KeeperTestSuite, amount uint64) (payout uint64, err error) { + payout, err = s.App().PoolKeeper.ChargeFundersOfPool(s.Ctx(), 0, amount) + if err != nil { + return 0, err } - return err + + if err := util.TransferFromModuleToAddress(s.App().BankKeeper, s.Ctx(), pooltypes.ModuleName, i.BURNER, payout); err != nil { + return 0, err + } + + return payout, err } func fundersCheck(pool *pooltypes.Pool) { @@ -43,14 +49,14 @@ func fundersCheck(pool *pooltypes.Pool) { Expect(pool.TotalFunds).To(Equal(poolFunds)) } -var _ = Describe("logic_funders_test.go", Ordered, func() { +var _ = Describe("logic_funders.go", Ordered, func() { s := i.NewCleanChain() var pool *pooltypes.Pool BeforeEach(func() { s = i.NewCleanChain() pool = &pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", MaxBundleSize: 100, StartKey: "0", MinDelegation: 100 * i.KYVE, @@ -147,10 +153,11 @@ var _ = Describe("logic_funders_test.go", Ordered, func() { Expect(pool.TotalFunds).To(Equal(50 * 100 * i.KYVE)) // ACT - err := chargeFunders(s, 50*10*i.KYVE) + payout, err := chargeFunders(s, 50*10*i.KYVE) // ASSERT Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(Equal(50 * 10 * i.KYVE)) pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.TotalFunds).To(Equal(50 * 90 * i.KYVE)) @@ -176,10 +183,11 @@ var _ = Describe("logic_funders_test.go", Ordered, func() { // ACT // Charge 10 $KYVE + 49tkyve // the 49 tkyve will be charged to the lowest funder - err := chargeFunders(s, 50*10*i.KYVE+49) + payout, err := chargeFunders(s, 50*10*i.KYVE+49) // ASSERT Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(Equal(50*10*i.KYVE + 49)) pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) @@ -213,10 +221,11 @@ var _ = Describe("logic_funders_test.go", Ordered, func() { Expect(pool.TotalFunds).To(Equal((100*40 + 200*10) * i.KYVE)) // ACT - err := chargeFunders(s, 50*100*i.KYVE) + payout, err := chargeFunders(s, 50*100*i.KYVE) // ASSERT Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(Equal(50 * 100 * i.KYVE)) pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(10)) @@ -247,16 +256,17 @@ var _ = Describe("logic_funders_test.go", Ordered, func() { // Charge 5000 // Act - err := chargeFunders(s, 5000*i.KYVE) + payout, err := chargeFunders(s, 5000*i.KYVE) // Assert Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(Equal(3000 * i.KYVE)) pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(10)) for _, funder := range pool.Funders { - Expect(funder.Amount).To(Equal(500 * i.KYVE)) + Expect(funder.Amount).To(Equal(900 * i.KYVE)) } }) @@ -274,12 +284,31 @@ var _ = Describe("logic_funders_test.go", Ordered, func() { Expect(pool.TotalFunds).To(Equal((50 * 50) * i.KYVE)) // ACT - err := chargeFunders(s, 5000*i.KYVE) + payout, err := chargeFunders(s, 5000*i.KYVE) // ASSERT - Expect(err).To(HaveOccurred()) + Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(Equal(2500 * i.KYVE)) + + pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + Expect(pool.Funders).To(HaveLen(0)) + }) + + It("Charge pool which has no funds at all", func() { + // ARRANGE + pool, poolFound := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + Expect(poolFound).To(BeTrue()) + Expect(pool.TotalFunds).To(BeZero()) + + // ACT + payout, err := chargeFunders(s, 5000*i.KYVE) + + // ASSERT + Expect(err).NotTo(HaveOccurred()) + Expect(payout).To(BeZero()) pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(0)) + Expect(pool.TotalFunds).To(BeZero()) }) }) diff --git a/x/pool/keeper/logic_pool.go b/x/pool/keeper/logic_pool.go index b6348365..6bbc4855 100644 --- a/x/pool/keeper/logic_pool.go +++ b/x/pool/keeper/logic_pool.go @@ -2,6 +2,8 @@ package keeper import ( "cosmossdk.io/errors" + "github.com/KYVENetwork/chain/util" + globalTypes "github.com/KYVENetwork/chain/x/global/types" "github.com/KYVENetwork/chain/x/pool/types" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" @@ -27,6 +29,28 @@ func (k Keeper) AssertPoolExists(ctx sdk.Context, poolId uint64) error { return errors.Wrapf(errorsTypes.ErrNotFound, types.ErrPoolNotFound.Error(), poolId) } +// ChargeInflationPool charges the inflation pool and transfers the funds to the pool module +// so the payout can be performed +func (k Keeper) ChargeInflationPool(ctx sdk.Context, poolId uint64) (payout uint64, err error) { + pool, found := k.GetPool(ctx, poolId) + if !found { + return payout, errors.Wrapf(errorsTypes.ErrNotFound, types.ErrPoolNotFound.Error(), poolId) + } + + account := pool.GetPoolAccount() + balance := k.bankKeeper.GetBalance(ctx, account, globalTypes.Denom).Amount.Int64() + + // charge X percent from current pool balance and use it as payout + payout = uint64(sdk.NewDec(balance).Mul(k.GetPoolInflationPayoutRate(ctx)).TruncateInt64()) + + // transfer funds to pool module account so bundle reward can be paid out from there + if err := util.TransferFromAddressToModule(k.bankKeeper, ctx, account.String(), types.ModuleName, payout); err != nil { + util.PanicHalt(k.upgradeKeeper, ctx, err.Error()) + } + + return payout, nil +} + // IncrementBundleInformation updates the latest finalized bundle of a pool func (k Keeper) IncrementBundleInformation( ctx sdk.Context, diff --git a/x/pool/keeper/msg_server_create_pool.go b/x/pool/keeper/msg_server_create_pool.go index 1b19972d..f69d29c8 100644 --- a/x/pool/keeper/msg_server_create_pool.go +++ b/x/pool/keeper/msg_server_create_pool.go @@ -26,7 +26,7 @@ func (k msgServer) CreatePool(goCtx context.Context, req *types.MsgCreatePool) ( ctx := sdk.UnwrapSDKContext(goCtx) - k.AppendPool(ctx, types.Pool{ + id := k.AppendPool(ctx, types.Pool{ Name: req.Name, Runtime: req.Runtime, Logo: req.Logo, @@ -46,6 +46,8 @@ func (k msgServer) CreatePool(goCtx context.Context, req *types.MsgCreatePool) ( CurrentCompressionId: req.CompressionId, }) + k.EnsurePoolAccount(ctx, id) + _ = ctx.EventManager().EmitTypedEvent(&types.EventCreatePool{ Id: k.GetPoolCount(ctx) - 1, Name: req.Name, diff --git a/x/pool/keeper/msg_server_defund_pool_test.go b/x/pool/keeper/msg_server_defund_pool_test.go index 324e49f9..e5b3aff8 100644 --- a/x/pool/keeper/msg_server_defund_pool_test.go +++ b/x/pool/keeper/msg_server_defund_pool_test.go @@ -30,7 +30,7 @@ var _ = Describe("msg_server_defund_pool.go", Ordered, func() { // create clean pool for every test case s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/pool/keeper/msg_server_disable_pool.go b/x/pool/keeper/msg_server_disable_pool.go index 6e2d98b4..fd34663c 100644 --- a/x/pool/keeper/msg_server_disable_pool.go +++ b/x/pool/keeper/msg_server_disable_pool.go @@ -3,6 +3,9 @@ package keeper import ( "context" + "github.com/KYVENetwork/chain/util" + globalTypes "github.com/KYVENetwork/chain/x/global/types" + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -41,6 +44,13 @@ func (k msgServer) DisablePool( k.stakersKeeper.LeavePool(ctx, staker, pool.Id) } + // send remaining pool assets to treasury + if balance := k.bankKeeper.GetBalance(ctx, pool.GetPoolAccount(), globalTypes.Denom).Amount.Uint64(); balance > 0 { + if err := util.TransferFromAddressToTreasury(k.distrkeeper, ctx, pool.GetPoolAccount().String(), balance); err != nil { + return nil, err + } + } + _ = ctx.EventManager().EmitTypedEvent(&types.EventPoolDisabled{Id: req.Id}) return &types.MsgDisablePoolResponse{}, nil diff --git a/x/pool/keeper/msg_server_disable_pool_test.go b/x/pool/keeper/msg_server_disable_pool_test.go index 13fdde32..c2215bc8 100644 --- a/x/pool/keeper/msg_server_disable_pool_test.go +++ b/x/pool/keeper/msg_server_disable_pool_test.go @@ -3,6 +3,7 @@ package keeper_test import ( i "github.com/KYVENetwork/chain/testutil/integration" bundletypes "github.com/KYVENetwork/chain/x/bundles/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" stakertypes "github.com/KYVENetwork/chain/x/stakers/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,6 +24,7 @@ TEST CASES - msg_server_disabled_pool.go * Invalid authority (proposal) * Disable a non-existing pool * Disable pool which is active +* Disable pool which is active and has a balance * Disable pool which is already disabled * Disable multiple pools * Kick out all stakers from pool @@ -153,6 +155,88 @@ var _ = Describe("msg_server_disable_pool.go", Ordered, func() { Expect(proposal.Status).To(Equal(govV1Types.StatusFailed)) }) + It("Disable pool which is active", func() { + // ARRANGE + msg := &types.MsgDisablePool{ + Authority: gov, + Id: 0, + } + + p, v := BuildGovernanceTxs(s, []sdk.Msg{msg}) + + // ACT + _, submitErr := s.RunTx(&p) + _, voteErr := s.RunTx(&v) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + proposal, _ := s.App().GovKeeper.GetProposal(s.Ctx(), 1) + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + Expect(submitErr).To(Not(HaveOccurred())) + Expect(voteErr).To(Not(HaveOccurred())) + + Expect(proposal.Status).To(Equal(govV1Types.StatusPassed)) + Expect(pool.Disabled).To(BeTrue()) + + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + Expect(bundleProposal.StorageId).To(BeEmpty()) + + // assert empty pool balance + b := s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Uint64() + Expect(b).To(BeZero()) + }) + + It("Disable pool which is active and has a balance", func() { + // ARRANGE + pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + s.App().PoolKeeper.SetParams(s.Ctx(), types.Params{ + ProtocolInflationShare: sdk.MustNewDecFromStr("0.1"), + PoolInflationPayoutRate: sdk.MustNewDecFromStr("0.05"), + }) + + for i := 0; i < 100; i++ { + s.Commit() + } + + b := s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Uint64() + Expect(b).To(BeNumerically(">", uint64(0))) + + msg := &types.MsgDisablePool{ + Authority: gov, + Id: 0, + } + + p, v := BuildGovernanceTxs(s, []sdk.Msg{msg}) + + // ACT + _, submitErr := s.RunTx(&p) + _, voteErr := s.RunTx(&v) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + proposal, _ := s.App().GovKeeper.GetProposal(s.Ctx(), 1) + pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) + + Expect(submitErr).To(Not(HaveOccurred())) + Expect(voteErr).To(Not(HaveOccurred())) + + Expect(proposal.Status).To(Equal(govV1Types.StatusPassed)) + Expect(pool.Disabled).To(BeTrue()) + + bundleProposal, _ := s.App().BundlesKeeper.GetBundleProposal(s.Ctx(), 0) + Expect(bundleProposal.StorageId).To(BeEmpty()) + + // assert empty pool balance + b = s.App().BankKeeper.GetBalance(s.Ctx(), pool.GetPoolAccount(), globalTypes.Denom).Amount.Uint64() + Expect(b).To(BeZero()) + }) + It("Disable pool which is active", func() { // ARRANGE msg := &types.MsgDisablePool{ diff --git a/x/pool/keeper/msg_server_fund_pool_test.go b/x/pool/keeper/msg_server_fund_pool_test.go index 6cc6fb8f..8dc9c6ba 100644 --- a/x/pool/keeper/msg_server_fund_pool_test.go +++ b/x/pool/keeper/msg_server_fund_pool_test.go @@ -33,7 +33,7 @@ var _ = Describe("msg_server_fund_pool.go", Ordered, func() { // create clean pool for every test case s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/pool/keeper/msg_server_update_params.go b/x/pool/keeper/msg_server_update_params.go new file mode 100644 index 00000000..9209b960 --- /dev/null +++ b/x/pool/keeper/msg_server_update_params.go @@ -0,0 +1,35 @@ +package keeper + +import ( + "context" + "encoding/json" + + "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" + + // Gov + govTypes "github.com/cosmos/cosmos-sdk/x/gov/types" + // Pool + "github.com/KYVENetwork/chain/x/pool/types" +) + +func (k msgServer) UpdateParams(goCtx context.Context, msg *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.authority != msg.Authority { + return nil, errors.Wrapf(govTypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, msg.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + oldParams := k.GetParams(ctx) + + newParams := oldParams + _ = json.Unmarshal([]byte(msg.Payload), &newParams) + k.SetParams(ctx, newParams) + + _ = ctx.EventManager().EmitTypedEvent(&types.EventUpdateParams{ + OldParams: oldParams, + NewParams: newParams, + Payload: msg.Payload, + }) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/pool/keeper/msg_server_update_params_test.go b/x/pool/keeper/msg_server_update_params_test.go new file mode 100644 index 00000000..b7f90d6a --- /dev/null +++ b/x/pool/keeper/msg_server_update_params_test.go @@ -0,0 +1,329 @@ +package keeper_test + +import ( + i "github.com/KYVENetwork/chain/testutil/integration" + sdk "github.com/cosmos/cosmos-sdk/types" + + . "github.com/onsi/ginkgo/v2" + . "github.com/onsi/gomega" + + // Pool + "github.com/KYVENetwork/chain/x/pool/types" + // Gov + govV1Types "github.com/cosmos/cosmos-sdk/x/gov/types/v1" +) + +/* + +TEST CASES - msg_server_update_params.go + +* Check default params +* Invalid authority (transaction) +* Invalid authority (proposal) +* Update every param at once +* Update no param +* Update with invalid formatted payload + +* Update protocol inflation share +* Update protocol inflation share with invalid value + +* Update pool inflation payout rate +* Update pool inflation payout rate with invalid value + +*/ + +var _ = Describe("msg_server_update_params.go", Ordered, func() { + s := i.NewCleanChain() + + gov := s.App().GovKeeper.GetGovernanceAccount(s.Ctx()).GetAddress().String() + + minDeposit := s.App().GovKeeper.GetDepositParams(s.Ctx()).MinDeposit + votingPeriod := s.App().GovKeeper.GetVotingParams(s.Ctx()).VotingPeriod + + delegations := s.App().StakingKeeper.GetAllDelegations(s.Ctx()) + voter := sdk.MustAccAddressFromBech32(delegations[0].DelegatorAddress) + + BeforeEach(func() { + s = i.NewCleanChain() + + delegations := s.App().StakingKeeper.GetAllDelegations(s.Ctx()) + voter = sdk.MustAccAddressFromBech32(delegations[0].DelegatorAddress) + }) + + AfterEach(func() { + s.PerformValidityChecks() + }) + + It("Check default params", func() { + // ASSERT + params := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(params.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(params.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) + + It("Invalid authority (transaction)", func() { + // ARRANGE + msg := &types.MsgUpdateParams{ + Authority: i.DUMMY[0], + Payload: "{}", + } + + // ACT + _, err := s.RunTx(msg) + + // ASSERT + Expect(err).To(HaveOccurred()) + }) + + It("Invalid authority (proposal)", func() { + // ARRANGE + msg := &types.MsgUpdateParams{ + Authority: i.DUMMY[0], + Payload: "{}", + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + // ACT + _, err := s.RunTx(proposal) + + // ASSERT + Expect(err).To(HaveOccurred()) + }) + + It("Update every param at once", func() { + // ARRANGE + payload := `{ + "protocol_inflation_share": "0.2", + "pool_inflation_payout_rate": "0.05" + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + vote := govV1Types.NewMsgVote( + voter, 1, govV1Types.VoteOption_VOTE_OPTION_YES, "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + _, voteErr := s.RunTx(vote) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).NotTo(HaveOccurred()) + Expect(voteErr).NotTo(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(sdk.MustNewDecFromStr("0.2"))) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(sdk.MustNewDecFromStr("0.05"))) + }) + + It("Update no params", func() { + // ARRANGE + payload := `{}` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + vote := govV1Types.NewMsgVote( + voter, 1, govV1Types.VoteOption_VOTE_OPTION_YES, "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + _, voteErr := s.RunTx(vote) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).NotTo(HaveOccurred()) + Expect(voteErr).NotTo(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) + + It("Update with invalid formatted payload", func() { + // ARRANGE + payload := `{ + "protocol_inflation_share: 20 + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).To(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) + + It("Update protocol inflation share", func() { + // ARRANGE + payload := `{ + "protocol_inflation_share": "0.07" + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + vote := govV1Types.NewMsgVote( + voter, 1, govV1Types.VoteOption_VOTE_OPTION_YES, "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + _, voteErr := s.RunTx(vote) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).NotTo(HaveOccurred()) + Expect(voteErr).NotTo(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(sdk.MustNewDecFromStr("0.07"))) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) + + It("Update protocol inflation share with invalid value", func() { + // ARRANGE + payload := `{ + "protocol_inflation_share": "invalid" + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).To(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) + + It("Update pool inflation payout rate", func() { + // ARRANGE + payload := `{ + "pool_inflation_payout_rate": "0.2" + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + vote := govV1Types.NewMsgVote( + voter, 1, govV1Types.VoteOption_VOTE_OPTION_YES, "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + _, voteErr := s.RunTx(vote) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).NotTo(HaveOccurred()) + Expect(voteErr).NotTo(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(sdk.MustNewDecFromStr("0.2"))) + }) + + It("Update pool inflation payout rate with invalid value", func() { + // ARRANGE + payload := `{ + "pool_inflation_payout_rate": "1.2" + }` + + msg := &types.MsgUpdateParams{ + Authority: gov, + Payload: payload, + } + + proposal, _ := govV1Types.NewMsgSubmitProposal( + []sdk.Msg{msg}, minDeposit, i.DUMMY[0], "", + ) + + // ACT + _, submitErr := s.RunTx(proposal) + + s.CommitAfter(*votingPeriod) + s.Commit() + + // ASSERT + updatedParams := s.App().PoolKeeper.GetParams(s.Ctx()) + + Expect(submitErr).To(HaveOccurred()) + + Expect(updatedParams.ProtocolInflationShare).To(Equal(types.DefaultProtocolInflationShare)) + Expect(updatedParams.PoolInflationPayoutRate).To(Equal(types.DefaultPoolInflationPayoutRate)) + }) +}) diff --git a/x/pool/module.go b/x/pool/module.go index 32d9e222..49443c59 100644 --- a/x/pool/module.go +++ b/x/pool/module.go @@ -1,24 +1,29 @@ package pool import ( + "context" "encoding/json" "fmt" - // this line is used by starport scaffolding # 1 + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + cdctypes "github.com/cosmos/cosmos-sdk/codec/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" "github.com/grpc-ecosystem/grpc-gateway/runtime" "github.com/spf13/cobra" - abci "github.com/tendermint/tendermint/abci/types" + // Bank + bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + + // Pool "github.com/KYVENetwork/chain/x/pool/client/cli" "github.com/KYVENetwork/chain/x/pool/keeper" "github.com/KYVENetwork/chain/x/pool/types" - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/codec" - cdctypes "github.com/cosmos/cosmos-sdk/codec/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" + + // Upgrade + upgradeKeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" ) var ( @@ -69,7 +74,9 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, _ client.TxEncodingCo } // RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for the module -func (AppModuleBasic) RegisterGRPCGatewayRoutes(_ client.Context, _ *runtime.ServeMux) {} +func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) { + _ = types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)) +} // GetTxCmd returns the root Tx command for the module. The subcommands of this root command are used by end-users to generate new transactions containing messages defined in the module func (a AppModuleBasic) GetTxCmd() *cobra.Command { @@ -78,7 +85,7 @@ func (a AppModuleBasic) GetTxCmd() *cobra.Command { // GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users to generate new queries to the subset of the state defined by the module func (AppModuleBasic) GetQueryCmd() *cobra.Command { - return nil + return cli.GetQueryCmd() } // ---------------------------------------------------------------------------- @@ -92,6 +99,7 @@ type AppModule struct { keeper keeper.Keeper accountKeeper types.AccountKeeper bankKeeper bankKeeper.Keeper + upgradeKeeper upgradeKeeper.Keeper } func NewAppModule( @@ -99,12 +107,14 @@ func NewAppModule( keeper keeper.Keeper, accountKeeper types.AccountKeeper, bankKeeper bankKeeper.Keeper, + upgradeKeeper upgradeKeeper.Keeper, ) AppModule { return AppModule{ AppModuleBasic: NewAppModuleBasic(cdc), keeper: keeper, accountKeeper: accountKeeper, bankKeeper: bankKeeper, + upgradeKeeper: upgradeKeeper, } } @@ -122,6 +132,7 @@ func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier { // RegisterServices registers a gRPC query service to respond to the module-specific gRPC queries func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), am.keeper) } // RegisterInvariants registers the invariants of the module. If an invariant deviates from its predicted value, the InvariantRegistry triggers appropriate logic (most often the chain will be halted) diff --git a/x/pool/spec/01_concepts.md b/x/pool/spec/01_concepts.md index 0c7dd605..ba23eb0a 100644 --- a/x/pool/spec/01_concepts.md +++ b/x/pool/spec/01_concepts.md @@ -26,3 +26,9 @@ stakeholders of the data that is being archived and therefore have a strong inte in further archiving the data. Once a valid bundle is produced and the reward is paid out the pool module takes care of correctly deducting the funds equally from each funder in order to guarantee a steady pool economy. + +## Inflation Splitting + +In order to support funders inflation splitting was introduced where a part of the block inflation +goes to the protocol and is paid out with the funds from the funders. This relieves the burden of the +funders to keep a pool alive and allows a pool to even run without any funds. diff --git a/x/pool/spec/02_state.md b/x/pool/spec/02_state.md index 2925d314..17c51672 100644 --- a/x/pool/spec/02_state.md +++ b/x/pool/spec/02_state.md @@ -8,12 +8,16 @@ The module is mainly responsible for holding the pools state and keeping track of pool funders. ## Pools + The pool object is rather large and holds multiple sub-objects grouped by functionality. ### Pool + Pool is the main type and holds everything a pool needs to know including some -sub-objects which are listed below. +sub-objects which are listed below. Each pool has their own module account, storing +the funds from the inflation split in order to pay those out with the funders to the +pool participants. The pool account is defined by the following: `pool/$ID` - Pool: `0x01 | PoolId -> ProtocolBuffer(pool)` diff --git a/x/pool/spec/05_params.md b/x/pool/spec/05_params.md index 563fc3ab..0ecb4a1a 100644 --- a/x/pool/spec/05_params.md +++ b/x/pool/spec/05_params.md @@ -4,4 +4,9 @@ order: 5 # Parameters -The pool module has no params +The pool module contains the following parameters: + +| Key | Type | Example | +|-------------------------|-------------------------|---------| +| ProtocolInflationShare | sdk.Dec (%) | 0.05 | +| PoolInflationPayoutRate | sdk.Dec (%) | 0.1 | diff --git a/x/pool/spec/07_exported.md b/x/pool/spec/07_exported.md index bc3b75d9..cdf6c302 100644 --- a/x/pool/spec/07_exported.md +++ b/x/pool/spec/07_exported.md @@ -28,10 +28,7 @@ type PoolKeeper interface { // ChargeFundersOfPool equally splits the amount between all funders and removes // the appropriate amount from each funder. // All funders who can't afford the amount, are kicked out. - // Their remaining amount is transferred to the Treasury. - // The function throws an error if pool ran out of funds. - // This method does not transfer any funds. The bundles-module - // is responsible for transferring the rewards out of the module. - ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) error + // The method returns the payout amount the pool was able to charge from the funders. + ChargeFundersOfPool(ctx sdk.Context, poolId uint64, amount uint64) (payout uint64, err error) } ``` diff --git a/x/pool/types/codec.go b/x/pool/types/codec.go index 394956cf..b6f742a4 100644 --- a/x/pool/types/codec.go +++ b/x/pool/types/codec.go @@ -22,6 +22,7 @@ func RegisterInterfaces(registry codecTypes.InterfaceRegistry) { registry.RegisterImplementations((*sdk.Msg)(nil), &MsgEnablePool{}) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgScheduleRuntimeUpgrade{}) registry.RegisterImplementations((*sdk.Msg)(nil), &MsgCancelRuntimeUpgrade{}) + registry.RegisterImplementations((*sdk.Msg)(nil), &MsgUpdateParams{}) } var ( diff --git a/x/pool/types/events.pb.go b/x/pool/types/events.pb.go index 6a5908c1..e0938306 100644 --- a/x/pool/types/events.pb.go +++ b/x/pool/types/events.pb.go @@ -5,6 +5,7 @@ package types import ( fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/gogo/protobuf/proto" io "io" math "math" @@ -22,6 +23,71 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// EventUpdateParams is an event emitted when the module parameters are updated. +// emitted_by: MsgUpdateParams +type EventUpdateParams struct { + // old_params is the module's old parameters. + OldParams Params `protobuf:"bytes,1,opt,name=old_params,json=oldParams,proto3" json:"old_params"` + // new_params is the module's new parameters. + NewParams Params `protobuf:"bytes,2,opt,name=new_params,json=newParams,proto3" json:"new_params"` + // payload is the parameter updates that were performed. + Payload string `protobuf:"bytes,3,opt,name=payload,proto3" json:"payload,omitempty"` +} + +func (m *EventUpdateParams) Reset() { *m = EventUpdateParams{} } +func (m *EventUpdateParams) String() string { return proto.CompactTextString(m) } +func (*EventUpdateParams) ProtoMessage() {} +func (*EventUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_c1828a100d789238, []int{0} +} +func (m *EventUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *EventUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_EventUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *EventUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_EventUpdateParams.Merge(m, src) +} +func (m *EventUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *EventUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_EventUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_EventUpdateParams proto.InternalMessageInfo + +func (m *EventUpdateParams) GetOldParams() Params { + if m != nil { + return m.OldParams + } + return Params{} +} + +func (m *EventUpdateParams) GetNewParams() Params { + if m != nil { + return m.NewParams + } + return Params{} +} + +func (m *EventUpdateParams) GetPayload() string { + if m != nil { + return m.Payload + } + return "" +} + // EventCreatePool ... // emitted_by: EndBlock(gov) type EventCreatePool struct { @@ -67,7 +133,7 @@ func (m *EventCreatePool) Reset() { *m = EventCreatePool{} } func (m *EventCreatePool) String() string { return proto.CompactTextString(m) } func (*EventCreatePool) ProtoMessage() {} func (*EventCreatePool) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{0} + return fileDescriptor_c1828a100d789238, []int{1} } func (m *EventCreatePool) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -205,7 +271,7 @@ func (m *EventPoolEnabled) Reset() { *m = EventPoolEnabled{} } func (m *EventPoolEnabled) String() string { return proto.CompactTextString(m) } func (*EventPoolEnabled) ProtoMessage() {} func (*EventPoolEnabled) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{1} + return fileDescriptor_c1828a100d789238, []int{2} } func (m *EventPoolEnabled) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -252,7 +318,7 @@ func (m *EventPoolDisabled) Reset() { *m = EventPoolDisabled{} } func (m *EventPoolDisabled) String() string { return proto.CompactTextString(m) } func (*EventPoolDisabled) ProtoMessage() {} func (*EventPoolDisabled) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{2} + return fileDescriptor_c1828a100d789238, []int{3} } func (m *EventPoolDisabled) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -311,7 +377,7 @@ func (m *EventRuntimeUpgradeScheduled) Reset() { *m = EventRuntimeUpgrad func (m *EventRuntimeUpgradeScheduled) String() string { return proto.CompactTextString(m) } func (*EventRuntimeUpgradeScheduled) ProtoMessage() {} func (*EventRuntimeUpgradeScheduled) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{3} + return fileDescriptor_c1828a100d789238, []int{4} } func (m *EventRuntimeUpgradeScheduled) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -396,7 +462,7 @@ func (m *EventRuntimeUpgradeCancelled) Reset() { *m = EventRuntimeUpgrad func (m *EventRuntimeUpgradeCancelled) String() string { return proto.CompactTextString(m) } func (*EventRuntimeUpgradeCancelled) ProtoMessage() {} func (*EventRuntimeUpgradeCancelled) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{4} + return fileDescriptor_c1828a100d789238, []int{5} } func (m *EventRuntimeUpgradeCancelled) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -479,7 +545,7 @@ func (m *EventPoolUpdated) Reset() { *m = EventPoolUpdated{} } func (m *EventPoolUpdated) String() string { return proto.CompactTextString(m) } func (*EventPoolUpdated) ProtoMessage() {} func (*EventPoolUpdated) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{5} + return fileDescriptor_c1828a100d789238, []int{6} } func (m *EventPoolUpdated) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -607,7 +673,7 @@ func (m *EventFundPool) Reset() { *m = EventFundPool{} } func (m *EventFundPool) String() string { return proto.CompactTextString(m) } func (*EventFundPool) ProtoMessage() {} func (*EventFundPool) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{6} + return fileDescriptor_c1828a100d789238, []int{7} } func (m *EventFundPool) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -672,7 +738,7 @@ func (m *EventDefundPool) Reset() { *m = EventDefundPool{} } func (m *EventDefundPool) String() string { return proto.CompactTextString(m) } func (*EventDefundPool) ProtoMessage() {} func (*EventDefundPool) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{7} + return fileDescriptor_c1828a100d789238, []int{8} } func (m *EventDefundPool) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -737,7 +803,7 @@ func (m *EventPoolFundsSlashed) Reset() { *m = EventPoolFundsSlashed{} } func (m *EventPoolFundsSlashed) String() string { return proto.CompactTextString(m) } func (*EventPoolFundsSlashed) ProtoMessage() {} func (*EventPoolFundsSlashed) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{8} + return fileDescriptor_c1828a100d789238, []int{9} } func (m *EventPoolFundsSlashed) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -798,7 +864,7 @@ func (m *EventPoolOutOfFunds) Reset() { *m = EventPoolOutOfFunds{} } func (m *EventPoolOutOfFunds) String() string { return proto.CompactTextString(m) } func (*EventPoolOutOfFunds) ProtoMessage() {} func (*EventPoolOutOfFunds) Descriptor() ([]byte, []int) { - return fileDescriptor_c1828a100d789238, []int{9} + return fileDescriptor_c1828a100d789238, []int{10} } func (m *EventPoolOutOfFunds) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -835,6 +901,7 @@ func (m *EventPoolOutOfFunds) GetPoolId() uint64 { } func init() { + proto.RegisterType((*EventUpdateParams)(nil), "kyve.pool.v1beta1.EventUpdateParams") proto.RegisterType((*EventCreatePool)(nil), "kyve.pool.v1beta1.EventCreatePool") proto.RegisterType((*EventPoolEnabled)(nil), "kyve.pool.v1beta1.EventPoolEnabled") proto.RegisterType((*EventPoolDisabled)(nil), "kyve.pool.v1beta1.EventPoolDisabled") @@ -850,52 +917,107 @@ func init() { func init() { proto.RegisterFile("kyve/pool/v1beta1/events.proto", fileDescriptor_c1828a100d789238) } var fileDescriptor_c1828a100d789238 = []byte{ - // 706 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0xc1, 0x4e, 0x1b, 0x3b, - 0x14, 0x65, 0x92, 0x10, 0xc0, 0x90, 0xe4, 0x65, 0xd0, 0x7b, 0x6f, 0xf4, 0x5e, 0x15, 0xa5, 0xa9, - 0x68, 0x69, 0x17, 0x89, 0x50, 0xbf, 0xa0, 0x04, 0x2a, 0x45, 0x48, 0x05, 0x25, 0xa2, 0x52, 0x51, - 0x25, 0xcb, 0x19, 0xdf, 0x4c, 0x2c, 0x66, 0xec, 0x91, 0xed, 0x09, 0x84, 0xaf, 0xe8, 0x17, 0xf4, - 0x6b, 0xba, 0xe8, 0x92, 0x45, 0x17, 0x5d, 0x56, 0xf0, 0x23, 0x95, 0x3d, 0x93, 0x51, 0x02, 0xa1, - 0xea, 0xa2, 0x95, 0xba, 0x9b, 0x7b, 0xee, 0xb1, 0xaf, 0x7d, 0xce, 0xbd, 0x63, 0xd4, 0x38, 0x9f, - 0x4e, 0xa0, 0x13, 0x0b, 0x11, 0x76, 0x26, 0x7b, 0x43, 0xd0, 0x64, 0xaf, 0x03, 0x13, 0xe0, 0x5a, - 0xb5, 0x63, 0x29, 0xb4, 0x70, 0xeb, 0x26, 0xdf, 0x36, 0xf9, 0x76, 0x96, 0x6f, 0x7d, 0x2a, 0xa2, - 0xda, 0xa1, 0xe1, 0x74, 0x25, 0x10, 0x0d, 0x27, 0x42, 0x84, 0x6e, 0x15, 0x15, 0x18, 0xf5, 0x9c, - 0xa6, 0xb3, 0x5b, 0xea, 0x17, 0x18, 0x75, 0x5d, 0x54, 0xe2, 0x24, 0x02, 0xaf, 0xd0, 0x74, 0x76, - 0x37, 0xfa, 0xf6, 0xdb, 0xf5, 0xd0, 0x9a, 0x4c, 0xb8, 0x66, 0x11, 0x78, 0x45, 0x0b, 0xcf, 0x42, - 0xc3, 0x0e, 0x45, 0x20, 0xbc, 0x52, 0xca, 0x36, 0xdf, 0xee, 0x3f, 0xa8, 0xec, 0x0b, 0x3e, 0x62, - 0x81, 0xb7, 0x6a, 0xd1, 0x2c, 0x72, 0xff, 0x47, 0x1b, 0x4a, 0x13, 0xa9, 0xf1, 0x39, 0x4c, 0xbd, - 0xb2, 0x4d, 0xad, 0x5b, 0xe0, 0x08, 0xa6, 0xee, 0x33, 0x54, 0x4b, 0xe2, 0x50, 0x10, 0x8a, 0x19, - 0xd7, 0x20, 0x27, 0x24, 0xf4, 0xd6, 0xec, 0x99, 0xaa, 0x29, 0xdc, 0xcb, 0x50, 0x77, 0x07, 0x55, - 0x45, 0x0c, 0x92, 0x68, 0xc6, 0x03, 0xec, 0x0b, 0xa5, 0xbd, 0x75, 0xcb, 0xab, 0xe4, 0x68, 0x57, - 0x28, 0x6d, 0x68, 0x11, 0xe3, 0x98, 0x42, 0x08, 0x01, 0xd1, 0x4c, 0x70, 0x6f, 0x23, 0xa5, 0x45, - 0x8c, 0x1f, 0xe4, 0xa0, 0xfb, 0x14, 0xd5, 0x22, 0x72, 0x89, 0x87, 0x09, 0xa7, 0x21, 0x60, 0xc5, - 0xae, 0xc0, 0x43, 0x19, 0x8f, 0x5c, 0xee, 0x5b, 0x74, 0xc0, 0xae, 0xac, 0x02, 0x13, 0x90, 0xca, - 0xec, 0xb3, 0x99, 0x2a, 0x90, 0x85, 0xee, 0x7f, 0x68, 0x7d, 0xc8, 0x38, 0x91, 0x0c, 0x94, 0xb7, - 0x95, 0x5e, 0x6a, 0x16, 0xbb, 0x6d, 0xb4, 0xad, 0xb4, 0x90, 0x24, 0x00, 0x1c, 0x4b, 0x31, 0x61, - 0x14, 0x24, 0x66, 0xd4, 0xab, 0x34, 0x9d, 0xdd, 0x4a, 0xbf, 0x9e, 0xa5, 0x4e, 0xb2, 0x4c, 0x8f, - 0x9a, 0x43, 0xfb, 0x22, 0x8a, 0x25, 0x28, 0xb3, 0xb5, 0xa1, 0x56, 0x2d, 0xb5, 0x32, 0x87, 0xf6, - 0x68, 0xab, 0x85, 0xfe, 0xb2, 0x2e, 0x1a, 0xff, 0x0e, 0x39, 0x19, 0x86, 0x40, 0xef, 0xda, 0xd8, - 0x7a, 0x82, 0xea, 0x39, 0xe7, 0x80, 0xa9, 0xe5, 0xa4, 0x2f, 0x0e, 0x7a, 0x64, 0x59, 0xfd, 0xd4, - 0xce, 0xd3, 0x38, 0x90, 0x84, 0xc2, 0xc0, 0x1f, 0x03, 0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0xd4, - 0x7a, 0x9f, 0xfd, 0x43, 0x0f, 0x60, 0xf4, 0x1b, 0x76, 0x1f, 0xa2, 0xbf, 0xf3, 0xce, 0x32, 0xa7, - 0x57, 0x83, 0x90, 0xa8, 0x31, 0xd0, 0x5f, 0x59, 0xa3, 0x8d, 0xb6, 0xf3, 0x1a, 0xc7, 0x89, 0x3e, - 0x1e, 0xd9, 0x42, 0x0f, 0x56, 0xd8, 0xef, 0x7e, 0xbe, 0x69, 0x38, 0xd7, 0x37, 0x0d, 0xe7, 0xdb, - 0x4d, 0xc3, 0xf9, 0x70, 0xdb, 0x58, 0xb9, 0xbe, 0x6d, 0xac, 0x7c, 0xbd, 0x6d, 0xac, 0x9c, 0x3d, - 0x0f, 0x98, 0x1e, 0x27, 0xc3, 0xb6, 0x2f, 0xa2, 0xce, 0xd1, 0xbb, 0xb7, 0x87, 0x6f, 0x40, 0x5f, - 0x08, 0x79, 0xde, 0xf1, 0xc7, 0x84, 0xf1, 0xce, 0x65, 0xfa, 0x3a, 0xe9, 0x69, 0x0c, 0x6a, 0x58, - 0xb6, 0xaf, 0xd2, 0xcb, 0xef, 0x01, 0x00, 0x00, 0xff, 0xff, 0x13, 0xf3, 0x39, 0x99, 0xb7, 0x06, - 0x00, 0x00, + // 792 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x55, 0xcd, 0x6e, 0xeb, 0x44, + 0x14, 0x8e, 0x93, 0x34, 0x6d, 0x26, 0x4d, 0x42, 0x7c, 0xf9, 0x31, 0x05, 0x85, 0x10, 0x74, 0xa1, + 0xb0, 0x70, 0x74, 0x61, 0x8f, 0x44, 0xd3, 0x22, 0x45, 0x57, 0xe2, 0x5e, 0x25, 0xba, 0x48, 0x54, + 0x48, 0xd6, 0xc4, 0x73, 0xe2, 0x8c, 0x6a, 0xcf, 0x58, 0x33, 0xe3, 0xa4, 0xe9, 0x53, 0xf0, 0x04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, 0x07, 0x00, 0x00, +} + +func (m *EventUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *EventUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *EventUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Payload) > 0 { + i -= len(m.Payload) + copy(dAtA[i:], m.Payload) + i = encodeVarintEvents(dAtA, i, uint64(len(m.Payload))) + i-- + dAtA[i] = 0x1a + } + { + size, err := m.NewParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size, err := m.OldParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil } func (m *EventCreatePool) Marshal() (dAtA []byte, err error) { @@ -1082,20 +1204,20 @@ func (m *EventRuntimeUpgradeScheduled) MarshalToSizedBuffer(dAtA []byte) (int, e var l int _ = l if len(m.AffectedPools) > 0 { - dAtA2 := make([]byte, len(m.AffectedPools)*10) - var j1 int + dAtA4 := make([]byte, len(m.AffectedPools)*10) + var j3 int for _, num := range m.AffectedPools { for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) + dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j1++ + j3++ } - dAtA2[j1] = uint8(num) - j1++ + dAtA4[j3] = uint8(num) + j3++ } - i -= j1 - copy(dAtA[i:], dAtA2[:j1]) - i = encodeVarintEvents(dAtA, i, uint64(j1)) + i -= j3 + copy(dAtA[i:], dAtA4[:j3]) + i = encodeVarintEvents(dAtA, i, uint64(j3)) i-- dAtA[i] = 0x32 } @@ -1154,20 +1276,20 @@ func (m *EventRuntimeUpgradeCancelled) MarshalToSizedBuffer(dAtA []byte) (int, e var l int _ = l if len(m.AffectedPools) > 0 { - dAtA4 := make([]byte, len(m.AffectedPools)*10) - var j3 int + dAtA6 := make([]byte, len(m.AffectedPools)*10) + var j5 int for _, num := range m.AffectedPools { for num >= 1<<7 { - dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) + dAtA6[j5] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j3++ + j5++ } - dAtA4[j3] = uint8(num) - j3++ + dAtA6[j5] = uint8(num) + j5++ } - i -= j3 - copy(dAtA[i:], dAtA4[:j3]) - i = encodeVarintEvents(dAtA, i, uint64(j3)) + i -= j5 + copy(dAtA[i:], dAtA6[:j5]) + i = encodeVarintEvents(dAtA, i, uint64(j5)) i-- dAtA[i] = 0x12 } @@ -1433,6 +1555,23 @@ func encodeVarintEvents(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } +func (m *EventUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.OldParams.Size() + n += 1 + l + sovEvents(uint64(l)) + l = m.NewParams.Size() + n += 1 + l + sovEvents(uint64(l)) + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovEvents(uint64(l)) + } + return n +} + func (m *EventCreatePool) Size() (n int) { if m == nil { return 0 @@ -1694,6 +1833,154 @@ func sovEvents(x uint64) (n int) { func sozEvents(x uint64) (n int) { return sovEvents(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } +func (m *EventUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: EventUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: EventUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field OldParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.OldParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NewParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.NewParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowEvents + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthEvents + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthEvents + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipEvents(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthEvents + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func (m *EventCreatePool) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/pool/types/genesis.go b/x/pool/types/genesis.go index d30ce883..dff80bf7 100644 --- a/x/pool/types/genesis.go +++ b/x/pool/types/genesis.go @@ -4,7 +4,10 @@ import "fmt" // DefaultGenesis returns the default Capability genesis state func DefaultGenesis() *GenesisState { - return &GenesisState{} + return &GenesisState{ + // this line is used by starport scaffolding # genesis/types/default + Params: DefaultParams(), + } } // Validate performs basic genesis state validation returning an error upon any failure. @@ -26,5 +29,5 @@ func (gs GenesisState) Validate() error { } } - return nil + return gs.Params.Validate() } diff --git a/x/pool/types/genesis.pb.go b/x/pool/types/genesis.pb.go index 74c70044..509edd76 100644 --- a/x/pool/types/genesis.pb.go +++ b/x/pool/types/genesis.pb.go @@ -25,6 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the pool module's genesis state. type GenesisState struct { + // params ... + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // pool_list ... PoolList []Pool `protobuf:"bytes,2,rep,name=pool_list,json=poolList,proto3" json:"pool_list"` // pool_count ... @@ -64,6 +66,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func (m *GenesisState) GetPoolList() []Pool { if m != nil { return m.PoolList @@ -85,23 +94,24 @@ func init() { func init() { proto.RegisterFile("kyve/pool/v1beta1/genesis.proto", fileDescriptor_ba827ab14a3de899) } var fileDescriptor_ba827ab14a3de899 = []byte{ - // 250 bytes of a gzipped FileDescriptorProto + // 271 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcf, 0xae, 0x2c, 0x4b, 0xd5, 0x2f, 0xc8, 0xcf, 0xcf, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x04, 0x29, 0xd0, 0x03, 0x29, 0xd0, 0x83, 0x2a, 0x90, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0xcb, 0xea, 0x83, 0x58, - 0x10, 0x85, 0x52, 0x32, 0x98, 0x26, 0x81, 0x75, 0x81, 0x65, 0x95, 0xca, 0xb9, 0x78, 0xdc, 0x21, - 0xe6, 0x06, 0x97, 0x24, 0x96, 0xa4, 0x0a, 0x59, 0x71, 0x71, 0x82, 0x64, 0xe3, 0x73, 0x32, 0x8b, - 0x4b, 0x24, 0x98, 0x14, 0x98, 0x35, 0xb8, 0x8d, 0xc4, 0xf5, 0x30, 0xac, 0xd2, 0x0b, 0xc8, 0xcf, - 0xcf, 0x71, 0x62, 0x39, 0x71, 0x4f, 0x9e, 0x21, 0x88, 0x03, 0x24, 0xe1, 0x93, 0x59, 0x5c, 0x22, - 0x24, 0xcb, 0xc5, 0x05, 0xd6, 0x9b, 0x9c, 0x5f, 0x9a, 0x57, 0x22, 0xc1, 0xac, 0xc0, 0xa8, 0xc1, - 0x12, 0x04, 0x36, 0xcd, 0x19, 0x24, 0xe0, 0xc5, 0xc2, 0xc1, 0x28, 0xc0, 0x14, 0xc4, 0x56, 0x90, - 0x58, 0x94, 0x98, 0x5b, 0xec, 0xe4, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, - 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, - 0x51, 0x9a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0xde, 0x91, 0x61, - 0xae, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0xfa, 0xc9, 0x19, 0x89, 0x99, 0x79, 0xfa, 0x15, - 0x10, 0xaf, 0x94, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x3d, 0x61, 0x0c, 0x08, 0x00, 0x00, - 0xff, 0xff, 0x22, 0xa0, 0x4e, 0x17, 0x2e, 0x01, 0x00, 0x00, + 0x10, 0x85, 0x52, 0x72, 0x98, 0x26, 0x15, 0x24, 0x16, 0x25, 0xe6, 0x42, 0x0d, 0x92, 0x92, 0xc1, + 0x22, 0x0f, 0x32, 0x15, 0x2c, 0xab, 0xb4, 0x88, 0x91, 0x8b, 0xc7, 0x1d, 0x62, 0x71, 0x70, 0x49, + 0x62, 0x49, 0xaa, 0x90, 0x39, 0x17, 0x1b, 0x44, 0xbb, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0xb7, 0x91, + 0xa4, 0x1e, 0x86, 0x43, 0xf4, 0x02, 0xc0, 0x0a, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, + 0x2a, 0x17, 0xb2, 0xe2, 0xe2, 0x04, 0x29, 0x8a, 0xcf, 0xc9, 0x2c, 0x2e, 0x91, 0x60, 0x52, 0x60, + 0xd6, 0xe0, 0x36, 0x12, 0xc7, 0xa6, 0x37, 0x3f, 0x3f, 0x07, 0xaa, 0x93, 0x03, 0x24, 0xe1, 0x93, + 0x59, 0x5c, 0x22, 0x24, 0xcb, 0xc5, 0x05, 0xd6, 0x9b, 0x9c, 0x5f, 0x9a, 0x57, 0x22, 0xc1, 0xac, + 0xc0, 0xa8, 0xc1, 0x12, 0x04, 0x36, 0xcd, 0x19, 0x24, 0xe0, 0xe4, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, + 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, + 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x9a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, + 0xb9, 0xfa, 0xde, 0x91, 0x61, 0xae, 0x7e, 0xa9, 0x25, 0xe5, 0xf9, 0x45, 0xd9, 0xfa, 0xc9, 0x19, + 0x89, 0x99, 0x79, 0xfa, 0x15, 0x10, 0x6f, 0x97, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x3d, + 0x6c, 0x0c, 0x08, 0x00, 0x00, 0xff, 0xff, 0xc6, 0x79, 0x5b, 0xc5, 0x7a, 0x01, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -143,6 +153,16 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x12 } } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -163,6 +183,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) if len(m.PoolList) > 0 { for _, e := range m.PoolList { l = e.Size() @@ -210,6 +232,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return fmt.Errorf("proto: GenesisState: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field PoolList", wireType) diff --git a/x/pool/types/keys.go b/x/pool/types/keys.go index 39013aa0..715bf985 100644 --- a/x/pool/types/keys.go +++ b/x/pool/types/keys.go @@ -23,7 +23,13 @@ const ( ) var ( - PoolKey = []byte{1} + // ParamsKey is the prefix for all module params defined in params.proto + ParamsKey = []byte{0} + + // PoolKey is the prefix for all pools defined in pool.proto + PoolKey = []byte{1} + + // PoolCountKey is the prefix for the pool counter defined in pool.proto PoolCountKey = []byte{2} ) diff --git a/x/pool/types/msgs.go b/x/pool/types/msgs.go index fa8d7830..7d6072aa 100644 --- a/x/pool/types/msgs.go +++ b/x/pool/types/msgs.go @@ -17,6 +17,7 @@ var ( _ sdk.Msg = &MsgEnablePool{} _ sdk.Msg = &MsgScheduleRuntimeUpgrade{} _ sdk.Msg = &MsgCancelRuntimeUpgrade{} + _ sdk.Msg = &MsgUpdateParams{} ) // GetSigners returns the expected signers for a MsgCreatePool message. @@ -167,3 +168,27 @@ func (msg *MsgCancelRuntimeUpgrade) ValidateBasic() error { return nil } + +// GetSigners returns the expected signers for a MsgCancelRuntimeUpgrade message. +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) + return []sdk.AccAddress{addr} +} + +// ValidateBasic does a sanity check on the provided data. +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errors.Wrap(err, "invalid authority address") + } + + params := DefaultParams() + if err := json.Unmarshal([]byte(msg.Payload), ¶ms); err != nil { + return err + } + + if err := params.Validate(); err != nil { + return err + } + + return nil +} diff --git a/x/pool/types/params.go b/x/pool/types/params.go new file mode 100644 index 00000000..d61e3d09 --- /dev/null +++ b/x/pool/types/params.go @@ -0,0 +1,44 @@ +package types + +import ( + "github.com/KYVENetwork/chain/util" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// DefaultProtocolInflationShare ... +var DefaultProtocolInflationShare = sdk.ZeroDec() + +// DefaultPoolInflationPayoutRate ... +var DefaultPoolInflationPayoutRate = sdk.MustNewDecFromStr("0.05") + +// NewParams creates a new Params instance +func NewParams( + protocolInflationShare sdk.Dec, + poolInflationPayoutRate sdk.Dec, +) Params { + return Params{ + ProtocolInflationShare: protocolInflationShare, + PoolInflationPayoutRate: poolInflationPayoutRate, + } +} + +// DefaultParams returns a default set of parameters +func DefaultParams() Params { + return NewParams( + DefaultProtocolInflationShare, + DefaultPoolInflationPayoutRate, + ) +} + +// Validate validates the set of params +func (p Params) Validate() error { + if err := util.ValidatePercentage(p.ProtocolInflationShare); err != nil { + return err + } + + if err := util.ValidatePercentage(p.PoolInflationPayoutRate); err != nil { + return err + } + + return nil +} diff --git a/x/pool/types/params.pb.go b/x/pool/types/params.pb.go new file mode 100644 index 00000000..bce3587c --- /dev/null +++ b/x/pool/types/params.pb.go @@ -0,0 +1,369 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: kyve/pool/v1beta1/params.proto + +package types + +import ( + fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/gogoproto/gogoproto" + proto "github.com/gogo/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// Params defines the pool module parameters. +type Params struct { + // protocol_inflation_share ... + ProtocolInflationShare github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=protocol_inflation_share,json=protocolInflationShare,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"protocol_inflation_share"` + // pool_inflation_payout_rate ... + PoolInflationPayoutRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=pool_inflation_payout_rate,json=poolInflationPayoutRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"pool_inflation_payout_rate"` +} + +func (m *Params) Reset() { *m = Params{} } +func (m *Params) String() string { return proto.CompactTextString(m) } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_7d8646dfa6da3b4d, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func init() { + proto.RegisterType((*Params)(nil), "kyve.pool.v1beta1.Params") +} + +func init() { proto.RegisterFile("kyve/pool/v1beta1/params.proto", fileDescriptor_7d8646dfa6da3b4d) } + +var fileDescriptor_7d8646dfa6da3b4d = []byte{ + // 268 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcb, 0xae, 0x2c, 0x4b, + 0xd5, 0x2f, 0xc8, 0xcf, 0xcf, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x48, + 0x2c, 0x4a, 0xcc, 0x2d, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x04, 0xc9, 0xeb, 0x81, + 0xe4, 0xf5, 0xa0, 0xf2, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x59, 0x7d, 0x10, 0x0b, 0xa2, + 0x50, 0xe9, 0x3e, 0x23, 0x17, 0x5b, 0x00, 0x58, 0xa7, 0x50, 0x06, 0x97, 0x04, 0x58, 0x2c, 0x39, + 0x3f, 0x27, 0x3e, 0x33, 0x2f, 0x2d, 0x27, 0xb1, 0x24, 0x33, 0x3f, 0x2f, 0xbe, 0x38, 0x23, 0xb1, + 0x28, 0x55, 0x82, 0x51, 0x81, 0x51, 0x83, 0xd3, 0x49, 0xef, 0xc4, 0x3d, 0x79, 0x86, 0x5b, 0xf7, + 0xe4, 0xd5, 0xd2, 0x33, 0x4b, 0x32, 0x4a, 0x93, 0xf4, 0x92, 0xf3, 0x73, 0xf5, 0x93, 0xf3, 0x8b, + 0x73, 0xf3, 0x8b, 0xa1, 0x94, 0x6e, 0x71, 0x4a, 0xb6, 0x7e, 0x49, 0x65, 0x41, 0x6a, 0xb1, 0x9e, + 0x4b, 0x6a, 0x72, 0x90, 0x18, 0xcc, 0x3c, 0x4f, 0x98, 0x71, 0xc1, 0x20, 0xd3, 0x84, 0xb2, 0xb9, + 0xa4, 0x40, 0x4e, 0x43, 0xb2, 0xa5, 0x20, 0xb1, 0x32, 0xbf, 0xb4, 0x24, 0xbe, 0x28, 0xb1, 0x24, + 0x55, 0x82, 0x89, 0x2c, 0xbb, 0xc4, 0x41, 0x26, 0xc2, 0xed, 0x09, 0x00, 0x9b, 0x17, 0x94, 0x58, + 0x92, 0xea, 0xe4, 0x7c, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f, 0x1e, 0xc9, 0x31, + 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c, 0x51, 0x9a, 0x48, + 0x46, 0x7b, 0x47, 0x86, 0xb9, 0xfa, 0xa5, 0x96, 0x94, 0xe7, 0x17, 0x65, 0xeb, 0x27, 0x67, 0x24, + 0x66, 0xe6, 0xe9, 0x57, 0x40, 0x82, 0x17, 0x6c, 0x43, 0x12, 0x1b, 0xd8, 0x27, 0xc6, 0x80, 0x00, + 0x00, 0x00, 0xff, 0xff, 0xd3, 0x1a, 0xf2, 0x59, 0x78, 0x01, 0x00, 0x00, +} + +func (m *Params) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size := m.PoolInflationPayoutRate.Size() + i -= size + if _, err := m.PoolInflationPayoutRate.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + { + size := m.ProtocolInflationShare.Size() + i -= size + if _, err := m.ProtocolInflationShare.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintParams(dAtA []byte, offset int, v uint64) int { + offset -= sovParams(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.ProtocolInflationShare.Size() + n += 1 + l + sovParams(uint64(l)) + l = m.PoolInflationPayoutRate.Size() + n += 1 + l + sovParams(uint64(l)) + return n +} + +func sovParams(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozParams(x uint64) (n int) { + return sovParams(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ProtocolInflationShare", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.ProtocolInflationShare.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolInflationPayoutRate", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.PoolInflationPayoutRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipParams(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthParams + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipParams(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowParams + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthParams + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupParams + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthParams + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthParams = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowParams = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupParams = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/pool/types/pool.go b/x/pool/types/pool.go index ee7209f1..b9e46dbe 100644 --- a/x/pool/types/pool.go +++ b/x/pool/types/pool.go @@ -1,6 +1,12 @@ package types -import "math" +import ( + "fmt" + "math" + + sdk "github.com/cosmos/cosmos-sdk/types" + authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) // Handles the funders of a pool. Functions safely add and remove funds to funders. // If amount drops to zero the funder is automatically removed from the list. @@ -58,6 +64,12 @@ func (m *Pool) GetFunderAmount(address string) uint64 { return 0 } +func (m *Pool) GetPoolAccount() sdk.AccAddress { + name := fmt.Sprintf("%s/%d", ModuleName, m.Id) + + return authTypes.NewModuleAddress(name) +} + func (m *Pool) GetLowestFunder() Funder { if len(m.Funders) == 0 { return Funder{} diff --git a/x/pool/types/query.pb.go b/x/pool/types/query.pb.go new file mode 100644 index 00000000..ccc9afc6 --- /dev/null +++ b/x/pool/types/query.pb.go @@ -0,0 +1,535 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: kyve/pool/v1beta1/query.proto + +package types + +import ( + context "context" + fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" + grpc1 "github.com/gogo/protobuf/grpc" + proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" + math "math" + math_bits "math/bits" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package + +// QueryParamsRequest is request type for the Query/Params RPC method. +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_9c2f559babbc8665, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo + +// QueryParamsResponse is response type for the Query/Params RPC method. +type QueryParamsResponse struct { + // params holds all the parameters of this module. + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_9c2f559babbc8665, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "kyve.pool.v1beta1.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "kyve.pool.v1beta1.QueryParamsResponse") +} + +func init() { proto.RegisterFile("kyve/pool/v1beta1/query.proto", fileDescriptor_9c2f559babbc8665) } + +var fileDescriptor_9c2f559babbc8665 = []byte{ + // 284 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0xcd, 0xae, 0x2c, 0x4b, + 0xd5, 0x2f, 0xc8, 0xcf, 0xcf, 0xd1, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0x2f, 0x2c, + 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x12, 0x04, 0x49, 0xeb, 0x81, 0xa4, + 0xf5, 0xa0, 0xd2, 0x52, 0x22, 0xe9, 0xf9, 0xe9, 0xf9, 0x60, 0x59, 0x7d, 0x10, 0x0b, 0xa2, 0x50, + 0x4a, 0x26, 0x3d, 0x3f, 0x3f, 0x3d, 0x27, 0x55, 0x3f, 0xb1, 0x20, 0x53, 0x3f, 0x31, 0x2f, 0x2f, + 0xbf, 0x24, 0xb1, 0x24, 0x33, 0x3f, 0xaf, 0x18, 0x2a, 0x2b, 0x87, 0x69, 0x4b, 0x41, 0x62, 0x51, + 0x62, 0x2e, 0x54, 0x5e, 0x49, 0x84, 0x4b, 0x28, 0x10, 0x64, 0x6b, 0x00, 0x58, 0x30, 0x28, 0xb5, + 0xb0, 0x34, 0xb5, 0xb8, 0x44, 0xc9, 0x8f, 0x4b, 0x18, 0x45, 0xb4, 0xb8, 0x20, 0x3f, 0xaf, 0x38, + 0x55, 0xc8, 0x9c, 0x8b, 0x0d, 0xa2, 0x59, 0x82, 0x51, 0x81, 0x51, 0x83, 0xdb, 0x48, 0x52, 0x0f, + 0xc3, 0x91, 0x7a, 0x10, 0x2d, 0x4e, 0x2c, 0x27, 0xee, 0xc9, 0x33, 0x04, 0x41, 0x95, 0x1b, 0x35, + 0x33, 0x72, 0xb1, 0x82, 0x0d, 0x14, 0xaa, 0xe2, 0x62, 0x83, 0xa8, 0x10, 0x52, 0xc5, 0xa2, 0x19, + 0xd3, 0x29, 0x52, 0x6a, 0x84, 0x94, 0x41, 0xdc, 0xa6, 0xa4, 0xd8, 0x74, 0xf9, 0xc9, 0x64, 0x26, + 0x69, 0x21, 0x49, 0x7d, 0x5c, 0x3e, 0x76, 0x72, 0x3e, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, + 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, + 0x39, 0x86, 0x28, 0xcd, 0xf4, 0xcc, 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0x7d, 0xef, + 0xc8, 0x30, 0x57, 0xbf, 0xd4, 0x92, 0xf2, 0xfc, 0xa2, 0x6c, 0xfd, 0xe4, 0x8c, 0xc4, 0xcc, 0x3c, + 0xfd, 0x0a, 0x88, 0x69, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0xe0, 0x70, 0x33, 0x06, 0x04, + 0x00, 0x00, 0xff, 0xff, 0x09, 0x81, 0xd4, 0xe5, 0xbf, 0x01, 0x00, 0x00, +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// QueryClient is the client API for Query service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type QueryClient interface { + // Parameters queries the parameters of the module. + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) +} + +type queryClient struct { + cc grpc1.ClientConn +} + +func NewQueryClient(cc grpc1.ClientConn) QueryClient { + return &queryClient{cc} +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/kyve.pool.v1beta1.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// QueryServer is the server API for Query service. +type QueryServer interface { + // Parameters queries the parameters of the module. + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) +} + +// UnimplementedQueryServer can be embedded to have forward compatible implementations. +type UnimplementedQueryServer struct { +} + +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + +func RegisterQueryServer(s grpc1.Server, srv QueryServer) { + s.RegisterService(&_Query_serviceDesc, srv) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kyve.pool.v1beta1.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _Query_serviceDesc = grpc.ServiceDesc{ + ServiceName: "kyve.pool.v1beta1.Query", + HandlerType: (*QueryServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "kyve/pool/v1beta1/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/pool/types/query.pb.gw.go b/x/pool/types/query.pb.gw.go new file mode 100644 index 00000000..000d5948 --- /dev/null +++ b/x/pool/types/query.pb.gw.go @@ -0,0 +1,153 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: kyve/pool/v1beta1/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kyve", "pool", "v1beta1", "params"}, "", runtime.AssumeColonVerbOpt(true))) +) + +var ( + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/pool/types/tx.pb.go b/x/pool/types/tx.pb.go index 161f9336..32d1573d 100644 --- a/x/pool/types/tx.pb.go +++ b/x/pool/types/tx.pb.go @@ -935,6 +935,98 @@ func (m *MsgCancelRuntimeUpgradeResponse) XXX_DiscardUnknown() { var xxx_messageInfo_MsgCancelRuntimeUpgradeResponse proto.InternalMessageInfo +// MsgUpdateParams defines a SDK message for updating the module parameters. +type MsgUpdateParams struct { + // authority is the address of the governance account. + Authority string `protobuf:"bytes,1,opt,name=authority,proto3" json:"authority,omitempty"` + // payload defines the x/stakers parameters to update. + Payload string `protobuf:"bytes,2,opt,name=payload,proto3" json:"payload,omitempty"` +} + +func (m *MsgUpdateParams) Reset() { *m = MsgUpdateParams{} } +func (m *MsgUpdateParams) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParams) ProtoMessage() {} +func (*MsgUpdateParams) Descriptor() ([]byte, []int) { + return fileDescriptor_20ddefdf83388ddc, []int{16} +} +func (m *MsgUpdateParams) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParams.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParams) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParams.Merge(m, src) +} +func (m *MsgUpdateParams) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParams) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParams.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParams proto.InternalMessageInfo + +func (m *MsgUpdateParams) GetAuthority() string { + if m != nil { + return m.Authority + } + return "" +} + +func (m *MsgUpdateParams) GetPayload() string { + if m != nil { + return m.Payload + } + return "" +} + +// MsgUpdateParamsResponse defines the Msg/UpdateParams response type. +type MsgUpdateParamsResponse struct { +} + +func (m *MsgUpdateParamsResponse) Reset() { *m = MsgUpdateParamsResponse{} } +func (m *MsgUpdateParamsResponse) String() string { return proto.CompactTextString(m) } +func (*MsgUpdateParamsResponse) ProtoMessage() {} +func (*MsgUpdateParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_20ddefdf83388ddc, []int{17} +} +func (m *MsgUpdateParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *MsgUpdateParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_MsgUpdateParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *MsgUpdateParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_MsgUpdateParamsResponse.Merge(m, src) +} +func (m *MsgUpdateParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *MsgUpdateParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_MsgUpdateParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_MsgUpdateParamsResponse proto.InternalMessageInfo + func init() { proto.RegisterType((*MsgFundPool)(nil), "kyve.pool.v1beta1.MsgFundPool") proto.RegisterType((*MsgFundPoolResponse)(nil), "kyve.pool.v1beta1.MsgFundPoolResponse") @@ -952,65 +1044,70 @@ func init() { proto.RegisterType((*MsgScheduleRuntimeUpgradeResponse)(nil), "kyve.pool.v1beta1.MsgScheduleRuntimeUpgradeResponse") proto.RegisterType((*MsgCancelRuntimeUpgrade)(nil), "kyve.pool.v1beta1.MsgCancelRuntimeUpgrade") proto.RegisterType((*MsgCancelRuntimeUpgradeResponse)(nil), "kyve.pool.v1beta1.MsgCancelRuntimeUpgradeResponse") + proto.RegisterType((*MsgUpdateParams)(nil), "kyve.pool.v1beta1.MsgUpdateParams") + proto.RegisterType((*MsgUpdateParamsResponse)(nil), "kyve.pool.v1beta1.MsgUpdateParamsResponse") } func init() { proto.RegisterFile("kyve/pool/v1beta1/tx.proto", fileDescriptor_20ddefdf83388ddc) } var fileDescriptor_20ddefdf83388ddc = []byte{ - // 841 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xdd, 0x6e, 0x1b, 0x45, - 0x14, 0x8e, 0x93, 0xd4, 0x89, 0x4f, 0x6a, 0x57, 0x9d, 0xb6, 0xe9, 0x74, 0x91, 0x4c, 0x62, 0x44, - 0x49, 0x11, 0xd8, 0x6a, 0x41, 0xdc, 0x37, 0x69, 0x91, 0xa2, 0x2a, 0x50, 0x36, 0x2a, 0x14, 0xb8, - 0x58, 0x8d, 0x77, 0xa6, 0x9b, 0x51, 0x76, 0x67, 0x96, 0x99, 0x59, 0x13, 0x57, 0x3c, 0x04, 0x17, - 0x3c, 0x0a, 0x0f, 0xc1, 0x65, 0xc5, 0x15, 0x97, 0x28, 0xb9, 0xe3, 0x29, 0xd0, 0xcc, 0xae, 0x77, - 0xd7, 0xd8, 0x4b, 0xf9, 0x49, 0xef, 0x7c, 0xce, 0xf9, 0xf2, 0x9d, 0x6f, 0x66, 0xbe, 0x73, 0xb2, - 0xe0, 0x9d, 0x4e, 0x27, 0x6c, 0x94, 0x4a, 0x19, 0x8f, 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 0xfe, 0x0c, 0x00, 0x00, 0xff, - 0xff, 0x47, 0x15, 0xd0, 0xc0, 0x94, 0x09, 0x00, 0x00, + // 881 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xd1, 0x6e, 0x1b, 0x45, + 0x14, 0x8d, 0x9d, 0xd4, 0x89, 0x6f, 0x62, 0x47, 0xdd, 0xb6, 0xe9, 0x64, 0x91, 0x4c, 0x62, 0x44, + 0x49, 0x2b, 0xb0, 0xd5, 0x82, 0x78, 0x6f, 0xd2, 0x22, 0x45, 0x55, 0xa0, 0x6c, 0x54, 0x28, 0x20, + 0xb1, 0x1a, 0xef, 0x4c, 0x37, 0xa3, 0xec, 0xce, 0x2c, 0x33, 0xb3, 0x26, 0xae, 0xf8, 0x08, 0x3e, + 0x86, 0x8f, 0xe0, 0xb1, 0xe2, 0x89, 0x47, 0x94, 0xbc, 0xf1, 0xcc, 0x07, 0xa0, 0x99, 0x5d, 0xef, + 0xae, 0xb1, 0xb7, 0x01, 0x9a, 0xbe, 0xf9, 0xde, 0x7b, 0x7c, 0xce, 0x9d, 0x99, 0x33, 0x77, 0x16, + 0xdc, 0xd3, 0xc9, 0x98, 0x0e, 0x13, 0x21, 0xa2, 0xe1, 0xf8, 0xfe, 0x88, 0x6a, 0x7c, 0x7f, 0xa8, + 0xcf, 0x06, 0x89, 0x14, 0x5a, 0x38, 0xd7, 0x4d, 0x6d, 0x60, 0x6a, 0x83, 0xbc, 0xe6, 0x6e, 0x07, + 0x42, 0xc5, 0x42, 0xf9, 0x16, 0x30, 0xcc, 0x82, 0x0c, 0xdd, 0xff, 0x02, 0xd6, 0x8f, 0x54, 0xf8, + 0x59, 0xca, 0xc9, 0x53, 0x21, 0x22, 0x07, 0xc1, 0x6a, 0x20, 0x29, 0xd6, 0x42, 0xa2, 0xc6, 0x4e, + 0x63, 0xaf, 0xed, 0x4d, 0x43, 0xa7,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x97, 0x88, 0x3a, 0xe6, 0xf9, + 0x49, 0xe3, 0x7c, 0x07, 0xeb, 0xd5, 0x31, 0xb3, 0x5b, 0xb3, 0xd8, 0x12, 0xe2, 0xde, 0xbd, 0x14, + 0x52, 0x6d, 0xbb, 0x32, 0x4f, 0x6a, 0xda, 0x2e, 0x11, 0x75, 0x6d, 0xcf, 0x8f, 0x0e, 0xe7, 0x27, + 0xd8, 0xaa, 0x19, 0x1b, 0x1f, 0x2e, 0xe6, 0x58, 0x8c, 0x76, 0x3f, 0xf9, 0x2f, 0xe8, 0x42, 0x7d, + 0x0c, 0x37, 0x17, 0xde, 0xd5, 0x7b, 0x35, 0x07, 0xba, 0x00, 0xeb, 0x3e, 0xf8, 0xf7, 0xd8, 0x42, + 0xf7, 0x7b, 0xd8, 0x98, 0xb9, 0x93, 0xfd, 0xd7, 0x1e, 0xb3, 0xc5, 0xb8, 0xf7, 0x2e, 0xc7, 0x4c, + 0xf9, 0xf7, 0x0f, 0x7e, 0x3d, 0xef, 0x35, 0x5e, 0x9d, 0xf7, 0x1a, 0x7f, 0x9c, 0xf7, 0x1a, 0x3f, + 0x5f, 0xf4, 0x96, 0x5e, 0x5d, 0xf4, 0x96, 0x7e, 0xbf, 0xe8, 0x2d, 0x7d, 0x7b, 0x37, 0x64, 0xfa, + 0x24, 0x1d, 0x0d, 0x02, 0x11, 0x0f, 0x9f, 0x7c, 0xf3, 0xd5, 0xe3, 0xcf, 0xa9, 0xfe, 0x51, 0xc8, + 0xd3, 0x61, 0x70, 0x82, 0x19, 0x1f, 0x9e, 0x65, 0x9f, 0x96, 0x7a, 0x92, 0x50, 0x35, 0x6a, 0xd9, + 0x0f, 0xc5, 0x8f, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x68, 0x62, 0xc8, 0xb4, 0x74, 0x0a, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1047,6 +1144,9 @@ type MsgClient interface { // CancelRuntimeUpgrade defines a governance operation for cancelling a runtime upgrade. // The authority is hard-coded to the x/gov module account. CancelRuntimeUpgrade(ctx context.Context, in *MsgCancelRuntimeUpgrade, opts ...grpc.CallOption) (*MsgCancelRuntimeUpgradeResponse, error) + // UpdateParams defines a governance operation for updating the x/pool module + // parameters. The authority is hard-coded to the x/gov module account. + UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) } type msgClient struct { @@ -1129,6 +1229,15 @@ func (c *msgClient) CancelRuntimeUpgrade(ctx context.Context, in *MsgCancelRunti return out, nil } +func (c *msgClient) UpdateParams(ctx context.Context, in *MsgUpdateParams, opts ...grpc.CallOption) (*MsgUpdateParamsResponse, error) { + out := new(MsgUpdateParamsResponse) + err := c.cc.Invoke(ctx, "/kyve.pool.v1beta1.Msg/UpdateParams", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // MsgServer is the server API for Msg service. type MsgServer interface { // FundPool ... @@ -1153,6 +1262,9 @@ type MsgServer interface { // CancelRuntimeUpgrade defines a governance operation for cancelling a runtime upgrade. // The authority is hard-coded to the x/gov module account. CancelRuntimeUpgrade(context.Context, *MsgCancelRuntimeUpgrade) (*MsgCancelRuntimeUpgradeResponse, error) + // UpdateParams defines a governance operation for updating the x/pool module + // parameters. The authority is hard-coded to the x/gov module account. + UpdateParams(context.Context, *MsgUpdateParams) (*MsgUpdateParamsResponse, error) } // UnimplementedMsgServer can be embedded to have forward compatible implementations. @@ -1183,6 +1295,9 @@ func (*UnimplementedMsgServer) ScheduleRuntimeUpgrade(ctx context.Context, req * func (*UnimplementedMsgServer) CancelRuntimeUpgrade(ctx context.Context, req *MsgCancelRuntimeUpgrade) (*MsgCancelRuntimeUpgradeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method CancelRuntimeUpgrade not implemented") } +func (*UnimplementedMsgServer) UpdateParams(ctx context.Context, req *MsgUpdateParams) (*MsgUpdateParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateParams not implemented") +} func RegisterMsgServer(s grpc1.Server, srv MsgServer) { s.RegisterService(&_Msg_serviceDesc, srv) @@ -1332,6 +1447,24 @@ func _Msg_CancelRuntimeUpgrade_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Msg_UpdateParams_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MsgUpdateParams) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(MsgServer).UpdateParams(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/kyve.pool.v1beta1.Msg/UpdateParams", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(MsgServer).UpdateParams(ctx, req.(*MsgUpdateParams)) + } + return interceptor(ctx, in, info, handler) +} + var _Msg_serviceDesc = grpc.ServiceDesc{ ServiceName: "kyve.pool.v1beta1.Msg", HandlerType: (*MsgServer)(nil), @@ -1368,6 +1501,10 @@ var _Msg_serviceDesc = grpc.ServiceDesc{ MethodName: "CancelRuntimeUpgrade", Handler: _Msg_CancelRuntimeUpgrade_Handler, }, + { + MethodName: "UpdateParams", + Handler: _Msg_UpdateParams_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "kyve/pool/v1beta1/tx.proto", @@ -1956,6 +2093,66 @@ func (m *MsgCancelRuntimeUpgradeResponse) MarshalToSizedBuffer(dAtA []byte) (int return len(dAtA) - i, nil } +func (m *MsgUpdateParams) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParams) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParams) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Payload) > 0 { + i -= len(m.Payload) + copy(dAtA[i:], m.Payload) + i = encodeVarintTx(dAtA, i, uint64(len(m.Payload))) + i-- + dAtA[i] = 0x12 + } + if len(m.Authority) > 0 { + i -= len(m.Authority) + copy(dAtA[i:], m.Authority) + i = encodeVarintTx(dAtA, i, uint64(len(m.Authority))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *MsgUpdateParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *MsgUpdateParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *MsgUpdateParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + func encodeVarintTx(dAtA []byte, offset int, v uint64) int { offset -= sovTx(v) base := offset @@ -2236,6 +2433,32 @@ func (m *MsgCancelRuntimeUpgradeResponse) Size() (n int) { return n } +func (m *MsgUpdateParams) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Authority) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + l = len(m.Payload) + if l > 0 { + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *MsgUpdateParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + func sovTx(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -3967,6 +4190,170 @@ func (m *MsgCancelRuntimeUpgradeResponse) Unmarshal(dAtA []byte) error { } return nil } +func (m *MsgUpdateParams) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParams: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParams: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Authority", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Authority = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Payload", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Payload = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *MsgUpdateParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: MsgUpdateParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} func skipTx(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/query/keeper/grpc_account_redelegation_test.go b/x/query/keeper/grpc_account_redelegation_test.go index adf0a9fe..1e8f1d9c 100644 --- a/x/query/keeper/grpc_account_redelegation_test.go +++ b/x/query/keeper/grpc_account_redelegation_test.go @@ -29,7 +29,7 @@ var _ = Describe("grpc_account_redelegation.go", Ordered, func() { s = i.NewCleanChain() s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "T", MinDelegation: 200 * i.KYVE, UploadInterval: 60, MaxBundleSize: 100, diff --git a/x/query/keeper/grpc_params.go b/x/query/keeper/grpc_params.go index cec84da6..d857d43a 100644 --- a/x/query/keeper/grpc_params.go +++ b/x/query/keeper/grpc_params.go @@ -24,6 +24,7 @@ func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*t globalParams := k.globalKeeper.GetParams(ctx) govParams := govTypes.QueryParamsResponse{} sp := k.stakerKeeper.GetParams(ctx) + pp := k.poolKeeper.GetParams(ctx) govVotingParams := k.govKeeper.GetVotingParams(ctx) govParams.VotingParams = &govVotingParams @@ -32,5 +33,5 @@ func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*t govTallyParams := k.govKeeper.GetTallyParams(ctx) govParams.TallyParams = &govTallyParams - return &types.QueryParamsResponse{BundlesParams: &bp, DelegationParams: &dp, GlobalParams: &globalParams, GovParams: &govParams, StakersParams: &sp}, nil + return &types.QueryParamsResponse{BundlesParams: &bp, DelegationParams: &dp, GlobalParams: &globalParams, GovParams: &govParams, StakersParams: &sp, PoolParams: &pp}, nil } diff --git a/x/query/keeper/grpc_query_can_propose_test.go b/x/query/keeper/grpc_query_can_propose_test.go index f9455053..963a1983 100644 --- a/x/query/keeper/grpc_query_can_propose_test.go +++ b/x/query/keeper/grpc_query_can_propose_test.go @@ -28,6 +28,7 @@ TEST CASES - grpc_query_can_propose.go * Call can propose before the upload interval passed * Call can propose with an invalid from height * Call can propose on an active pool as the next uploader with valid args +* Call can propose on an active pool without funds as the next uploader with valid args */ @@ -38,7 +39,7 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { s = i.NewCleanChain() s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", MinDelegation: 200 * i.KYVE, UploadInterval: 60, MaxBundleSize: 100, @@ -229,46 +230,6 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(txErr.Error()).To(Equal(canPropose.Reason)) }) - It("Call can propose if pool is out of funds", func() { - // ARRANGE - s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ - Creator: i.ALICE, - Id: 0, - Amount: 100 * i.KYVE, - }) - - // ACT - canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ - PoolId: 0, - Staker: i.STAKER_1, - Proposer: i.VALADDRESS_1, - FromIndex: 100, - }) - - // ASSERT - Expect(err).To(BeNil()) - - Expect(canPropose.Possible).To(BeFalse()) - Expect(canPropose.Reason).To(Equal(bundletypes.ErrPoolOutOfFunds.Error())) - - _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, - PoolId: 0, - StorageId: "test_storage_id", - DataSize: 100, - DataHash: "test_hash", - FromIndex: 100, - BundleSize: 100, - FromKey: "100", - ToKey: "199", - BundleSummary: "test_value", - }) - - Expect(txErr).NotTo(BeNil()) - Expect(txErr.Error()).To(Equal(canPropose.Reason)) - }) - It("Call can propose if pool has not reached the minimum stake", func() { // ARRANGE s.RunTxDelegatorSuccess(&delegationtypes.MsgUndelegate{ @@ -554,4 +515,43 @@ var _ = Describe("grpc_query_can_propose.go", Ordered, func() { Expect(txErr).To(BeNil()) }) + + It("Call can propose on an active pool without funds as the next uploader with valid args", func() { + // ARRANGE + s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + // ACT + canPropose, err := s.App().QueryKeeper.CanPropose(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanProposeRequest{ + PoolId: 0, + Staker: i.STAKER_1, + Proposer: i.VALADDRESS_1, + FromIndex: 100, + }) + + // ASSERT + Expect(err).To(BeNil()) + + Expect(canPropose.Possible).To(BeTrue()) + Expect(canPropose.Reason).To(BeEmpty()) + + _, txErr := s.RunTx(&bundletypes.MsgSubmitBundleProposal{ + Creator: i.VALADDRESS_1, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "test_storage_id", + DataSize: 100, + DataHash: "test_hash", + FromIndex: 100, + BundleSize: 100, + FromKey: "100", + ToKey: "199", + BundleSummary: "test_value", + }) + + Expect(txErr).To(BeNil()) + }) }) diff --git a/x/query/keeper/grpc_query_can_validate_test.go b/x/query/keeper/grpc_query_can_validate_test.go index 7324994a..89a49c41 100644 --- a/x/query/keeper/grpc_query_can_validate_test.go +++ b/x/query/keeper/grpc_query_can_validate_test.go @@ -30,7 +30,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { s = i.NewCleanChain() s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", MinDelegation: 200 * i.KYVE, UploadInterval: 60, MaxBundleSize: 100, @@ -51,7 +51,7 @@ var _ = Describe("grpc_query_can_validate.go", Ordered, func() { }) s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest2", + Name: "Test Pool2", MinDelegation: 200 * i.KYVE, UploadInterval: 60, MaxBundleSize: 100, diff --git a/x/query/keeper/grpc_query_can_vote_test.go b/x/query/keeper/grpc_query_can_vote_test.go index 83c09dfa..1b18563b 100644 --- a/x/query/keeper/grpc_query_can_vote_test.go +++ b/x/query/keeper/grpc_query_can_vote_test.go @@ -21,7 +21,6 @@ TEST CASES - grpc_query_can_vote.go * Call can vote if pool does not exist * Call can vote if pool is currently upgrading * Call can vote if pool is disabled -* Call can vote if pool is out of funds * Call can vote if pool has not reached the minimum stake * Call can vote with a valaccount which does not exist * Call can vote if current bundle was dropped @@ -30,6 +29,7 @@ TEST CASES - grpc_query_can_vote.go * Call can vote if voter has already voted invalid * Call can vote if voter has already voted abstain * Call can vote on an active pool with a data bundle with valid args +* Call can vote on an active pool with no funds and a data bundle with valid args */ @@ -40,7 +40,7 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { s = i.NewCleanChain() s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", MinDelegation: 200 * i.KYVE, UploadInterval: 60, MaxBundleSize: 100, @@ -202,40 +202,6 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(txErr.Error()).To(Equal(canVote.Reason)) }) - It("Call can vote if pool is out of funds", func() { - // ARRANGE - s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ - Creator: i.ALICE, - Id: 0, - Amount: 100 * i.KYVE, - }) - - // ACT - canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ - PoolId: 0, - Staker: i.STAKER_1, - Voter: i.VALADDRESS_1, - StorageId: "test_storage_id", - }) - - // ASSERT - Expect(err).To(BeNil()) - - Expect(canVote.Possible).To(BeFalse()) - Expect(canVote.Reason).To(Equal(bundletypes.ErrPoolOutOfFunds.Error())) - - _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ - Creator: i.VALADDRESS_1, - Staker: i.STAKER_1, - PoolId: 0, - StorageId: "test_storage_id", - Vote: bundletypes.VOTE_TYPE_VALID, - }) - - Expect(txErr).NotTo(BeNil()) - Expect(txErr.Error()).To(Equal(canVote.Reason)) - }) - It("Call can vote if pool has not reached the minimum stake", func() { // ARRANGE s.RunTxDelegatorSuccess(&delegationtypes.MsgUndelegate{ @@ -498,4 +464,37 @@ var _ = Describe("grpc_query_can_vote.go", Ordered, func() { Expect(txErr).To(BeNil()) }) + + It("Call can vote on an active pool with no funds and a data bundle with valid args", func() { + // ARRANGE + s.RunTxPoolSuccess(&pooltypes.MsgDefundPool{ + Creator: i.ALICE, + Id: 0, + Amount: 100 * i.KYVE, + }) + + // ACT + canVote, err := s.App().QueryKeeper.CanVote(sdk.WrapSDKContext(s.Ctx()), &querytypes.QueryCanVoteRequest{ + PoolId: 0, + Staker: i.STAKER_1, + Voter: i.VALADDRESS_1, + StorageId: "test_storage_id", + }) + + // ASSERT + Expect(err).To(BeNil()) + + Expect(canVote.Possible).To(BeTrue()) + Expect(canVote.Reason).To(BeEmpty()) + + _, txErr := s.RunTx(&bundletypes.MsgVoteBundleProposal{ + Creator: i.VALADDRESS_1, + Staker: i.STAKER_1, + PoolId: 0, + StorageId: "test_storage_id", + Vote: bundletypes.VOTE_TYPE_VALID, + }) + + Expect(txErr).To(BeNil()) + }) }) diff --git a/x/query/keeper/grpc_query_pool.go b/x/query/keeper/grpc_query_pool.go index b321c2f6..71c692c1 100644 --- a/x/query/keeper/grpc_query_pool.go +++ b/x/query/keeper/grpc_query_pool.go @@ -3,12 +3,17 @@ package keeper import ( "context" - pooltypes "github.com/KYVENetwork/chain/x/pool/types" - "github.com/KYVENetwork/chain/x/query/types" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsTypes "github.com/cosmos/cosmos-sdk/types/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + + // Global + globalTypes "github.com/KYVENetwork/chain/x/global/types" + // Pool + poolTypes "github.com/KYVENetwork/chain/x/pool/types" + // Query + "github.com/KYVENetwork/chain/x/query/types" ) func (k Keeper) Pools(c context.Context, req *types.QueryPoolsRequest) (*types.QueryPoolsResponse, error) { @@ -38,13 +43,13 @@ func (k Keeper) Pool(c context.Context, req *types.QueryPoolRequest) (*types.Que pool, found := k.poolKeeper.GetPool(ctx, req.Id) if !found { - return nil, sdkerrors.ErrKeyNotFound + return nil, errorsTypes.ErrKeyNotFound } return &types.QueryPoolResponse{Pool: k.parsePoolResponse(ctx, &pool)}, nil } -func (k Keeper) parsePoolResponse(ctx sdk.Context, pool *pooltypes.Pool) types.PoolResponse { +func (k Keeper) parsePoolResponse(ctx sdk.Context, pool *poolTypes.Pool) types.PoolResponse { bundleProposal, _ := k.bundleKeeper.GetBundleProposal(ctx, pool.Id) stakers := k.stakerKeeper.GetAllStakerAddressesOfPool(ctx, pool.Id) @@ -55,6 +60,9 @@ func (k Keeper) parsePoolResponse(ctx sdk.Context, pool *pooltypes.Pool) types.P totalDelegation := k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) + poolAccount := pool.GetPoolAccount() + poolBalance := k.bankKeeper.GetBalance(ctx, poolAccount, globalTypes.Denom).Amount.Uint64() + return types.PoolResponse{ Id: pool.Id, Data: pool, @@ -63,5 +71,7 @@ func (k Keeper) parsePoolResponse(ctx sdk.Context, pool *pooltypes.Pool) types.P TotalSelfDelegation: totalSelfDelegation, TotalDelegation: totalDelegation, Status: k.GetPoolStatus(ctx, pool), + Account: poolAccount.String(), + AccountBalance: poolBalance, } } diff --git a/x/query/keeper/helper.go b/x/query/keeper/helper.go index 83ecb35b..0536becd 100644 --- a/x/query/keeper/helper.go +++ b/x/query/keeper/helper.go @@ -27,6 +27,7 @@ func (k Keeper) GetFullStaker(ctx sdk.Context, stakerAddress string) *types.Full SecurityContact: staker.SecurityContact, Details: staker.Details, PendingCommissionChange: commissionChangeEntry, + CommissionRewards: staker.CommissionRewards, } delegationData, _ := k.delegationKeeper.GetDelegationData(ctx, staker.Address) diff --git a/x/query/types/params.pb.go b/x/query/types/params.pb.go index 875a8a42..62befeff 100644 --- a/x/query/types/params.pb.go +++ b/x/query/types/params.pb.go @@ -9,6 +9,7 @@ import ( types "github.com/KYVENetwork/chain/x/bundles/types" types1 "github.com/KYVENetwork/chain/x/delegation/types" types2 "github.com/KYVENetwork/chain/x/global/types" + types4 "github.com/KYVENetwork/chain/x/pool/types" types3 "github.com/KYVENetwork/chain/x/stakers/types" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" grpc1 "github.com/gogo/protobuf/grpc" @@ -82,6 +83,8 @@ type QueryParamsResponse struct { GovParams *v1.QueryParamsResponse `protobuf:"bytes,4,opt,name=gov_params,json=govParams,proto3" json:"gov_params,omitempty"` // stakers_params ... StakersParams *types3.Params `protobuf:"bytes,5,opt,name=stakers_params,json=stakersParams,proto3" json:"stakers_params,omitempty"` + // pool_params ... + PoolParams *types4.Params `protobuf:"bytes,6,opt,name=pool_params,json=poolParams,proto3" json:"pool_params,omitempty"` } func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } @@ -152,6 +155,13 @@ func (m *QueryParamsResponse) GetStakersParams() *types3.Params { return nil } +func (m *QueryParamsResponse) GetPoolParams() *types4.Params { + if m != nil { + return m.PoolParams + } + return nil +} + func init() { proto.RegisterType((*QueryParamsRequest)(nil), "kyve.query.v1beta1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "kyve.query.v1beta1.QueryParamsResponse") @@ -160,34 +170,36 @@ func init() { func init() { proto.RegisterFile("kyve/query/v1beta1/params.proto", fileDescriptor_b5269c0a69f1d3d4) } var fileDescriptor_b5269c0a69f1d3d4 = []byte{ - // 427 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x92, 0xbf, 0x8e, 0xd3, 0x40, - 0x10, 0xc6, 0xe3, 0x00, 0x91, 0xd8, 0x90, 0x08, 0x0c, 0x05, 0x98, 0xc8, 0x09, 0x16, 0x02, 0x44, - 0xb1, 0x2b, 0x87, 0x17, 0x00, 0x02, 0x15, 0x08, 0x41, 0x0a, 0x24, 0x68, 0xd0, 0x3a, 0x59, 0x6d, - 0xac, 0x38, 0x1e, 0xc7, 0xbb, 0x5e, 0x48, 0x41, 0x43, 0x4d, 0x81, 0xc4, 0x4b, 0x51, 0x46, 0xa2, - 0xa1, 0x44, 0xc9, 0x3d, 0xc1, 0x3d, 0xc1, 0x29, 0xbb, 0xeb, 0xcb, 0x3f, 0x9f, 0xae, 0xf3, 0xcc, - 0x7c, 0xf3, 0x9b, 0xf1, 0xb7, 0x83, 0xba, 0xd3, 0x85, 0x62, 0x64, 0x5e, 0xb0, 0x7c, 0x41, 0x54, - 0x18, 0x31, 0x49, 0x43, 0x92, 0xd1, 0x9c, 0xce, 0x04, 0xce, 0x72, 0x90, 0xe0, 0xba, 0x1b, 0x01, - 0xd6, 0x02, 0x6c, 0x05, 0xde, 0xbd, 0x11, 0x88, 0x19, 0x08, 0xc2, 0x41, 0x11, 0x15, 0x9a, 0x6e, - 0x23, 0xf7, 0x3a, 0x1c, 0x80, 0x27, 0x8c, 0xd0, 0x2c, 0x26, 0x34, 0x4d, 0x41, 0x52,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c, 0xef, 0xa8, 0x61, 0xbf, 0x1e, 0xe1, 0xe3, 0x03, 0xc4, 0xc7, 0xcf, 0xe6, - 0x3d, 0xbe, 0x54, 0x67, 0x56, 0x0f, 0x82, 0x1f, 0x7f, 0x4f, 0x7e, 0xd7, 0x3b, 0xae, 0x47, 0x2e, - 0x3c, 0xfd, 0x97, 0xaf, 0xfe, 0xac, 0x7c, 0x67, 0xb9, 0xf2, 0x9d, 0xff, 0x2b, 0xdf, 0xf9, 0xb5, - 0xf6, 0x6b, 0xcb, 0xb5, 0x5f, 0xfb, 0xb7, 0xf6, 0x6b, 0x9f, 0x9f, 0xf2, 0x58, 0x4e, 0x8a, 0x08, - 0x8f, 0x60, 0x46, 0xde, 0x7c, 0xfa, 0xf8, 0xfa, 0x1d, 0x93, 0x5f, 0x21, 0x9f, 0x92, 0xd1, 0x84, - 0xc6, 0x29, 0xf9, 0x66, 0x71, 0x72, 0x91, 0x31, 0x11, 0x35, 0xf4, 0x99, 0x3d, 0x3b, 0x0b, 0x00, - 0x00, 0xff, 0xff, 0x49, 0x98, 0xf2, 0x4c, 0x64, 0x03, 0x00, 0x00, + // 455 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x93, 0x31, 0x8f, 0xd3, 0x30, + 0x14, 0xc7, 0x9b, 0x3b, 0xa8, 0x84, 0xcb, 0x9d, 0x20, 0x30, 0x70, 0xa1, 0xca, 0x1d, 0x11, 0x02, + 0xc4, 0x60, 0x2b, 0xc7, 0xc6, 0x04, 0x1c, 0x4c, 0x20, 0x04, 0x1d, 0x90, 0x60, 0x41, 0x4e, 0x6b, + 0xb9, 0x51, 0xd3, 0xbc, 0x34, 0x76, 0x0c, 0x1d, 0x58, 0x98, 0x19, 0x90, 0xf8, 0x1e, 0x7c, 0x0e, + 0xc6, 0x4a, 0x2c, 0x8c, 0xa8, 0xe5, 0x83, 0xa0, 0xd8, 0x2f, 0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0xfb, 0x44, 0xef, 0xfd, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xc8, + 0x33, 0x96, 0x09, 0xc0, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -315,6 +327,18 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.PoolParams != nil { + { + size, err := m.PoolParams.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintParams(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } if m.StakersParams != nil { { size, err := m.StakersParams.MarshalToSizedBuffer(dAtA[:i]) @@ -424,6 +448,10 @@ func (m *QueryParamsResponse) Size() (n int) { l = m.StakersParams.Size() n += 1 + l + sovParams(uint64(l)) } + if m.PoolParams != nil { + l = m.PoolParams.Size() + n += 1 + l + sovParams(uint64(l)) + } return n } @@ -692,6 +720,42 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PoolParams", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowParams + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthParams + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthParams + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PoolParams == nil { + m.PoolParams = &types4.Params{} + } + if err := m.PoolParams.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipParams(dAtA[iNdEx:]) diff --git a/x/query/types/pools.pb.go b/x/query/types/pools.pb.go index 636be4ad..53a336b2 100644 --- a/x/query/types/pools.pb.go +++ b/x/query/types/pools.pb.go @@ -185,6 +185,10 @@ type PoolResponse struct { TotalDelegation uint64 `protobuf:"varint,6,opt,name=total_delegation,json=totalDelegation,proto3" json:"total_delegation,omitempty"` // status ... Status types.PoolStatus `protobuf:"varint,7,opt,name=status,proto3,enum=kyve.pool.v1beta1.PoolStatus" json:"status,omitempty"` + // account ... + Account string `protobuf:"bytes,8,opt,name=account,proto3" json:"account,omitempty"` + // account_balance ... + AccountBalance uint64 `protobuf:"varint,9,opt,name=account_balance,json=accountBalance,proto3" json:"account_balance,omitempty"` } func (m *PoolResponse) Reset() { *m = PoolResponse{} } @@ -269,6 +273,20 @@ func (m *PoolResponse) GetStatus() types.PoolStatus { return types.POOL_STATUS_UNSPECIFIED } +func (m *PoolResponse) GetAccount() string { + if m != nil { + return m.Account + } + return "" +} + +func (m *PoolResponse) GetAccountBalance() uint64 { + if m != nil { + return m.AccountBalance + } + return 0 +} + // QueryPoolRequest is the request type for the Query/Pool RPC method. type QueryPoolRequest struct { // id defines the unique ID of the pool. @@ -372,49 +390,51 @@ func init() { func init() { proto.RegisterFile("kyve/query/v1beta1/pools.proto", fileDescriptor_b627739c2d7723dc) } var fileDescriptor_b627739c2d7723dc = []byte{ - // 659 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcf, 0x4f, 0xd4, 0x40, - 0x14, 0xde, 0x96, 0xee, 0x02, 0x83, 0xf2, 0x63, 0xf0, 0x47, 0x5d, 0xa5, 0xd4, 0x06, 0x70, 0xc5, - 0xa4, 0x13, 0xd6, 0x78, 0x31, 0x9e, 0x08, 0x6a, 0x8c, 0x51, 0xd7, 0x92, 0x98, 0xe8, 0x65, 0x33, - 0xdd, 0x0e, 0x65, 0x42, 0xe9, 0x94, 0xce, 0x2c, 0xba, 0x1a, 0x2f, 0xfc, 0x05, 0x26, 0x1e, 0xfd, - 0x87, 0x88, 0x27, 0x12, 0x2f, 0x7a, 0x31, 0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0x98, 0x4c, 0x14, - 0x21, 0x6c, 0x82, 0x89, 0x80, 0x72, 0xec, 0x47, 0x24, 0x30, 0x0d, 0x5b, 0x6b, 0x4d, 0x78, 0x65, - 0x0c, 0x5d, 0x30, 0xcf, 0x05, 0x4b, 0x71, 0x48, 0xba, 0x49, 0xca, 0xf6, 0x69, 0x40, 0xd2, 0x2e, - 0x0d, 0xcc, 0xba, 0xad, 0xb5, 0xce, 0x7b, 0x73, 0x2a, 0xd5, 0x51, 0x99, 0x47, 0x81, 0xf3, 0x49, - 0x03, 0xb0, 0x3a, 0x1b, 0x4f, 0x58, 0xcc, 0x09, 0xbc, 0x07, 0xea, 0x72, 0x6f, 0xa6, 0x66, 0x8f, - 0xb5, 0xa6, 0xda, 0xb6, 0x7b, 0x7a, 0x71, 0x6e, 0xc6, 0x28, 0x08, 0xeb, 0xc6, 0xe1, 0xf7, 0xc5, - 0x9a, 0x97, 0x93, 0xe0, 0xc3, 0x21, 0x6b, 0x74, 0x69, 0xcd, 0x8d, 0x91, 0xd6, 0xe4, 0x95, 0xaa, - 0xde, 0x38, 0x9f, 0x75, 0x70, 0xae, 0xda, 0x06, 0x4e, 0x03, 0x9d, 0x06, 0xd2, 0x6c, 0xc3, 0xd3, - 0x69, 0x00, 0x6f, 0x01, 0x23, 0xc0, 0x02, 0xab, 0x1e, 0x97, 0x73, 0x99, 0x72, 0x75, 0x43, 0x2a, - 0x25, 0x08, 0x3e, 0x01, 0x33, 0xf9, 0xda, 0x33, 0x6b, 0x12, 0xc6, 0x71, 0x24, 0x9d, 0x9d, 0x6a, - 0x2f, 0xe5, 0xbc, 0xe2, 0x26, 0x0a, 0xea, 0xba, 0x8c, 0x3b, 0x0a, 0xeb, 0x4d, 0xfb, 0x43, 0x71, - 0xb6, 0x20, 0x2e, 0xf0, 0x0e, 0x49, 0xb9, 0x69, 0xd8, 0x63, 0xd9, 0x82, 0x54, 0x08, 0xdb, 0xe0, - 0xa2, 0x60, 0x02, 0x47, 0x5d, 0x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, 0x1e, 0xbf, 0x7c, 0x71, 0xff, 0x29, - 0x11, 0xaf, 0x59, 0xba, 0x83, 0x7a, 0xdb, 0x98, 0xc6, 0xe8, 0x8d, 0xaa, 0x28, 0x06, 0x09, 0xe1, - 0x7e, 0x43, 0xfe, 0x8d, 0x6e, 0xff, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x47, 0xf1, 0xcf, 0x38, 0x65, - 0x05, 0x00, 0x00, + // 693 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x4f, 0xd4, 0x4e, + 0x18, 0xde, 0xee, 0x76, 0x17, 0x18, 0x7e, 0xbf, 0x05, 0x06, 0x3f, 0xea, 0x2a, 0xa5, 0x36, 0x7c, + 0xac, 0x98, 0xb4, 0x61, 0x8d, 0x17, 0xe3, 0x69, 0x83, 0x1a, 0x63, 0xd4, 0xb5, 0x24, 0x26, 0x7a, + 0xd9, 0x4c, 0xdb, 0xa1, 0x34, 0x94, 0x4e, 0xe9, 0x4c, 0xd1, 0xd5, 0x78, 0xe1, 0x6e, 0x62, 0xe2, + 0xd1, 0x7f, 0x88, 0x23, 0x89, 0x17, 0xbd, 0x18, 0x03, 0xfe, 0x21, 0xa6, 0x33, 0xd3, 0xda, 0x15, + 0x11, 0x6f, 0xf3, 0xce, 0xfb, 0x3c, 0xef, 0xfb, 0xbc, 0x1f, 0x33, 0x40, 0xdf, 0x19, 0xed, 0x63, + 0x7b, 0x2f, 0xc3, 0xe9, 0xc8, 0xde, 0x5f, 0x77, 0x31, 0x43, 0xeb, 0x76, 0x42, 0x48, 0x44, 0xad, + 0x24, 0x25, 0x8c, 0x40, 0x98, 0xfb, 0x2d, 0xee, 0xb7, 0xa4, 0xbf, 0xb3, 0xe6, 0x11, 0xba, 0x4b, + 0xa8, 0xed, 0x22, 0x7a, 0x8a, 0x8a, 0x82, 0x30, 0x46, 0x2c, 0x24, 0x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e8, 0x4e, 0xf7, 0x0c, 0xeb, 0xf4, 0xe0, 0xac, 0x9c, 0x51, 0x10, 0xfa, 0xea, 0xe1, 0xb7, + 0xc5, 0x9a, 0x23, 0x48, 0xf0, 0xc1, 0x58, 0x6b, 0xea, 0xbc, 0x35, 0xab, 0xe7, 0xb6, 0x46, 0x44, + 0xaa, 0xf6, 0xc6, 0x7c, 0xdf, 0x00, 0xff, 0x55, 0xd3, 0xc0, 0x36, 0xa8, 0x87, 0x3e, 0x6f, 0xb6, + 0xea, 0xd4, 0x43, 0x1f, 0xde, 0x04, 0xaa, 0x8f, 0x18, 0x92, 0x39, 0x2e, 0x0b, 0x99, 0x7c, 0x74, + 0x63, 0x2a, 0x39, 0x08, 0x3e, 0x06, 0x33, 0x62, 0xec, 0x79, 0x6b, 0x12, 0x42, 0x51, 0xc4, 0x3b, + 0x3b, 0xdd, 0x5b, 0x12, 0xbc, 0x62, 0x27, 0x0a, 0x6a, 0x9f, 0xdb, 0x03, 0x89, 0x75, 0xda, 0xee, + 0x98, 0x9d, 0x0f, 0x88, 0x32, 0xb4, 0x83, 0x53, 0xaa, 0xa9, 0x46, 0x23, 0x1f, 0x90, 0x34, 0x61, + 0x0f, 0x5c, 0x64, 0x84, 0xa1, 0x68, 0x48, 0x71, 0xb4, 0x35, 0xf4, 0x71, 0x84, 0x03, 0xd1, 0x8a, + 0x26, 0x17, 0x3e, 0xcf, 0x9d, 0x9b, 0x38, 0xda, 0xda, 0x28, 0x5d, 0xf0, 0x06, 0x98, 0x15, 0x9c, + 0x0a, 0xbc, 0xc5, 0xe1, 0x33, 0xfc, 0xbe, 0x02, 0xbd, 0x0d, 0x5a, 0x94, 0x21, 0x96, 0x51, 0x6d, + 0xc2, 0x50, 0xba, 0xed, 0xde, 0xc2, 0x19, 0x65, 0x6f, 0x72, 0x90, 0x23, 0xc1, 0xb9, 0x5e, 0xe4, + 0x79, 0x24, 0x8b, 0x99, 0x36, 0x29, 0x16, 0x4a, 0x9a, 0x70, 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0xb9, 0xa8, 0x05, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -670,6 +690,18 @@ func (m *PoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.AccountBalance != 0 { + i = encodeVarintPools(dAtA, i, uint64(m.AccountBalance)) + i-- + dAtA[i] = 0x48 + } + if len(m.Account) > 0 { + i -= len(m.Account) + copy(dAtA[i:], m.Account) + i = encodeVarintPools(dAtA, i, uint64(len(m.Account))) + i-- + dAtA[i] = 0x42 + } if m.Status != 0 { i = encodeVarintPools(dAtA, i, uint64(m.Status)) i-- @@ -876,6 +908,13 @@ func (m *PoolResponse) Size() (n int) { if m.Status != 0 { n += 1 + sovPools(uint64(m.Status)) } + l = len(m.Account) + if l > 0 { + n += 1 + l + sovPools(uint64(l)) + } + if m.AccountBalance != 0 { + n += 1 + sovPools(uint64(m.AccountBalance)) + } return n } @@ -1426,6 +1465,57 @@ func (m *PoolResponse) Unmarshal(dAtA []byte) error { break } } + case 8: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Account", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPools + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthPools + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthPools + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Account = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 9: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field AccountBalance", wireType) + } + m.AccountBalance = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPools + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.AccountBalance |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipPools(dAtA[iNdEx:]) diff --git a/x/query/types/query.pb.go b/x/query/types/query.pb.go index 67a036dd..d88244e5 100644 --- a/x/query/types/query.pb.go +++ b/x/query/types/query.pb.go @@ -280,6 +280,8 @@ type StakerMetadata struct { // the commission is applied. Users have time to redelegate // if they not agree with the new commission. PendingCommissionChange *CommissionChangeEntry `protobuf:"bytes,7,opt,name=pending_commission_change,json=pendingCommissionChange,proto3" json:"pending_commission_change,omitempty"` + // commission_rewards are the rewards in $KYVE earned through commission + CommissionRewards uint64 `protobuf:"varint,8,opt,name=commission_rewards,json=commissionRewards,proto3" json:"commission_rewards,omitempty"` } func (m *StakerMetadata) Reset() { *m = StakerMetadata{} } @@ -357,6 +359,13 @@ func (m *StakerMetadata) GetPendingCommissionChange() *CommissionChangeEntry { return nil } +func (m *StakerMetadata) GetCommissionRewards() uint64 { + if m != nil { + return m.CommissionRewards + } + return 0 +} + // CommissionChangeEntry shows when the old commission // of a staker will change to the new commission type CommissionChangeEntry struct { @@ -511,55 +520,56 @@ func init() { func init() { proto.RegisterFile("kyve/query/v1beta1/query.proto", fileDescriptor_6b41255feae93a15) } var fileDescriptor_6b41255feae93a15 = []byte{ - // 765 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x41, 0x6f, 0xe3, 0x44, - 0x14, 0xc7, 0xe3, 0x24, 0x4d, 0x93, 0x17, 0x9a, 0xa0, 0x11, 0x50, 0xb7, 0xa2, 0x6e, 0x15, 0x04, - 0x6d, 0x91, 0x70, 0xd4, 0x22, 0x24, 0xc4, 0x81, 0x43, 0x93, 0x56, 0x42, 0xd0, 0x0a, 0x19, 0x81, - 0x04, 0x17, 0x6b, 0x62, 0x4f, 0x9d, 0x51, 0xec, 0x19, 0xe3, 0x19, 0xa7, 0xe4, 0x3b, 0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0x99, 0x90, 0x4c, 0x4c, - 0x69, 0xea, 0x99, 0x05, 0x83, 0x57, 0x75, 0xe8, 0xad, 0xf2, 0x40, 0x57, 0x00, 0x01, 0x4f, 0x12, - 0x2a, 0x84, 0xda, 0x9a, 0x46, 0x7c, 0xe6, 0xde, 0xde, 0xef, 0xd7, 0x5e, 0xde, 0xef, 0x7f, 0x15, - 0x51, 0x39, 0xcd, 0x27, 0x6e, 0xc0, 0x93, 0x61, 0xc0, 0x45, 0xc2, 0x45, 0xf1, 0xf3, 0x8d, 0x08, - 0x67, 0x43, 0xb9, 0x48, 0x89, 0x70, 0xc7, 0x24, 0xf0, 0x96, 0x2a, 0xa8, 0x7e, 0x25, 0x9c, 0xd1, - 0x19, 0xc9, 0x8a, 0xb1, 0x2e, 0x43, 0x95, 0xb9, 0x21, 0x13, 0x41, 0x65, 0x35, 0xd9, 0x45, 0x88, - 0x76, 0xa1, 0x4d, 0x43, 0xc2, 0x24, 0x95, 0x8b, 0x62, 0xba, 0xab, 0x58, 0x01, 0x14, 0x24, 0xc8, - 0x33, 0x2a, 0x17, 0x7e, 0xc0, 0x99, 0xc4, 0x81, 0x99, 0xf1, 0x8e, 0xd7, 0x2f, 0xf5, 0x91, 0x91, - 0xd5, 0x1f, 0x84, 0x44, 0x62, 0x1a, 0x0b, 0x0d, 0xae, 0xe3, 0x95, 0x21, 0x22, 0xb0, 0x93, 0x12, - 0xdd, 0x10, 0xff, 0xed, 0x56, 0xfd, 0x60, 0x8a, 0x59, 0x44, 0xf4, 0x90, 0x77, 0x4f, 0x8f, 0xd7, - 0x51, 0x1c, 0x55, 0xe6, 0x91, 0xf6, 0x9e, 0x33, 0x99, 0x2d, 0xbc, 0xed, 0xa2, 0xd6, 0xd3, 0xec, - 0xe0, 0x5f, 0x0b, 0x3e, 0x5d, 0xbb, 0xe4, 0x83, 0x53, 0xfe, 0x02, 0xb6, 0x82, 0x8c, 0x98, 0x59, - 0x0c, 0xb1, 0x34, 0x4f, 0x48, 0xc3, 0xfb, 0xa8, 0x14, 0xc7, 0x58, 0x92, 0xc1, 0x33, 0x0b, 0x7a, - 0xab, 0x73, 0x80, 0x4e, 0xa0, 0xa9, 0x26, 0x41, 0xef, 0xa0, 0x5b, 0xde, 0xc8, 0xd5, 0x33, 0x57, - 0xcf, 0x95, 0xa7, 0xad, 0xe8, 0x33, 0x68, 0xa5, 0x9c, 0x32, 0x29, 0xf4, 0x7f, 0x34, 0xbd, 0x22, - 0x42, 0x7b, 0x00, 0x54, 0xf8, 0x31, 0xc1, 0x73, 0x75, 0x0d, 0x54, 0x47, 0xdb, 0x5e, 0x87, 0x8a, - 0x5f, 0x8c, 0x80, 0x1c, 0x80, 0x39, 0x8e, 0xcb, 0xab, 0x6b, 0xba, 0xba, 0xa4, 0xa8, 0x66, 0x4d, - 0x70, 0x8c, 0x59, 0x40, 0x8a, 0xfb, 0x50, 0x86, 0x67, 0xe3, 0xdb, 0x07, 0xc7, 0xba, 0x7b, 0x70, - 0xac, 0xd7, 0x0f, 0x8e, 0xf5, 0xdf, 0xa3, 0x53, 0xbb, 0x7b, 0x74, 0x6a, 0xcf, 0x1f, 0x9d, 0xda, - 0x5f, 0x5f, 0x2f, 0x91, 0xfa, 0xf9, 0xcf, 0x3f, 0xce, 0xaf, 0x88, 0xbc, 0xe1, 0xd9, 0x6c, 0x18, - 0x4c, 0x31, 0x65, 0xc3, 0x7f, 0x8a, 0xf7, 0x5c, 0x13, 0x9b, 0xb4, 0xf4, 0x03, 0xfc, 0xed, 0x9b, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xb3, 0xdc, 0x12, 0x0e, 0xea, 0x05, 0x00, 0x00, + // 782 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x94, 0x41, 0x8f, 0xe3, 0x34, + 0x14, 0xc7, 0x9b, 0xb6, 0xd3, 0x6d, 0x5f, 0xd9, 0x16, 0x2c, 0x60, 0xb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61, 0x7c, 0xfa, 0x53, 0x75, 0xfd, 0x5b, 0x62, 0x8b, 0x9e, 0xbd, 0xaf, 0x3f, + 0xfe, 0x27, 0x00, 0x00, 0xff, 0xff, 0x50, 0x8f, 0x9d, 0x37, 0x19, 0x06, 0x00, 0x00, } func (m *BasicPool) Marshal() (dAtA []byte, err error) { @@ -732,6 +742,11 @@ func (m *StakerMetadata) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.CommissionRewards != 0 { + i = encodeVarintQuery(dAtA, i, uint64(m.CommissionRewards)) + i-- + dAtA[i] = 0x40 + } if m.PendingCommissionChange != nil { { size, err := m.PendingCommissionChange.MarshalToSizedBuffer(dAtA[:i]) @@ -1009,6 +1024,9 @@ func (m *StakerMetadata) Size() (n int) { l = m.PendingCommissionChange.Size() n += 1 + l + sovQuery(uint64(l)) } + if m.CommissionRewards != 0 { + n += 1 + sovQuery(uint64(m.CommissionRewards)) + } return n } @@ -1805,6 +1823,25 @@ func (m *StakerMetadata) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field CommissionRewards", wireType) + } + m.CommissionRewards = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.CommissionRewards |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/stakers/keeper/getters_staker.go b/x/stakers/keeper/getters_staker.go index e5922652..c803a042 100644 --- a/x/stakers/keeper/getters_staker.go +++ b/x/stakers/keeper/getters_staker.go @@ -33,20 +33,20 @@ func (k Keeper) UpdateStakerMetadata( } } -// UpdateStakerCommission ... -func (k Keeper) UpdateStakerCommission(ctx sdk.Context, address string, commission sdk.Dec) { +// updateStakerCommissionRewards ... +func (k Keeper) updateStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) { staker, found := k.GetStaker(ctx, address) if found { - staker.Commission = commission + staker.CommissionRewards += amount k.setStaker(ctx, staker) } } -// IncreaseStakerCommissionRewards ... -func (k Keeper) IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) { +// UpdateStakerCommission ... +func (k Keeper) UpdateStakerCommission(ctx sdk.Context, address string, commission sdk.Dec) { staker, found := k.GetStaker(ctx, address) if found { - staker.CommissionRewards += amount + staker.Commission = commission k.setStaker(ctx, staker) } } diff --git a/x/stakers/keeper/logic_stakers.go b/x/stakers/keeper/logic_stakers.go index ab8dffab..32f6f649 100644 --- a/x/stakers/keeper/logic_stakers.go +++ b/x/stakers/keeper/logic_stakers.go @@ -3,12 +3,38 @@ package keeper import ( "math" - "cosmossdk.io/errors" + "github.com/KYVENetwork/chain/util" + poolTypes "github.com/KYVENetwork/chain/x/pool/types" "github.com/KYVENetwork/chain/x/stakers/types" + + "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" errorsTypes "github.com/cosmos/cosmos-sdk/types/errors" + sdkErrors "github.com/cosmos/cosmos-sdk/types/errors" ) +// IncreaseStakerCommissionRewards sets the uploader's commission rewards and transfers the funds from +// the pool module to the stakers module, so the funds can be later claimed and transferred from here +func (k Keeper) IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) error { + // Assert there is an amount + if amount == 0 { + return nil + } + + // Assert the staker exists + if _, found := k.GetStaker(ctx, address); !found { + return errors.Wrapf(sdkErrors.ErrNotFound, "Staker does not exist.") + } + + // transfer funds from pool to stakers module + if err := util.TransferFromModuleToModule(k.bankKeeper, ctx, poolTypes.ModuleName, types.ModuleName, amount); err != nil { + return err + } + + k.updateStakerCommissionRewards(ctx, address, amount) + return nil +} + // getLowestStaker returns the staker with the lowest total stake // (self-delegation + delegation) of a given pool. // If all pool slots are taken, this is the staker who then diff --git a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go index df7d28bf..8c9b578b 100644 --- a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go +++ b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go @@ -14,7 +14,7 @@ import ( TEST CASES - msg_server_claim_commission_rewards.go -* Produce a valid bundle and check commission rewards // TODO: move to bundles module tests +* Produce a valid bundle and check commission rewards * Claim with non-staker account * Claim more rewards than available * Claim zero rewards @@ -127,20 +127,18 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) balanceUploader := s.GetBalanceFromAddress(i.STAKER_0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) - - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) - uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward + totalDelegationReward := totalUploaderReward - uploaderPayoutReward // assert payout transfer Expect(balanceUploader).To(Equal(initialBalanceStaker0)) // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(uploaderDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(Equal(totalDelegationReward)) // assert commission rewards Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) @@ -149,7 +147,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) Expect(pool.Funders).To(HaveLen(1)) - Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - operatingReward - storageReward)) + Expect(pool.GetFunderAmount(i.ALICE)).To(Equal(100*i.KYVE - pool.OperatingCost)) }) It("Claim with non-staker account", func() { @@ -164,14 +162,13 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) @@ -193,14 +190,13 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) @@ -218,14 +214,13 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward)) @@ -245,14 +240,13 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward - 100)) @@ -272,14 +266,13 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward := pool.OperatingCost - storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward := uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward := pool.OperatingCost - treasuryReward - storageReward - treasuryReward := uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward := operatingReward - treasuryReward uploaderPayoutReward := uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward - 100)) @@ -314,17 +307,16 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // assert commission rewards uploader, _ = s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0) - pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) - operatingReward = pool.OperatingCost - storageReward = 2 * uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + networkFee = s.App().BundlesKeeper.GetNetworkFee(s.Ctx()) + treasuryReward = uint64(sdk.NewDec(int64(pool.OperatingCost)).Mul(networkFee).TruncateInt64()) + storageReward = uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx()).MulInt64(100).TruncateInt64()) + totalUploaderReward = pool.OperatingCost - treasuryReward - storageReward - treasuryReward = uint64(sdk.NewDec(int64(operatingReward)).Mul(networkFee).TruncateInt64()) - totalUploaderReward = operatingReward - treasuryReward - uploaderPayoutReward = 2 * uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) + uploaderPayoutReward = uint64(sdk.NewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64()) - Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward - 300)) + Expect(uploader.CommissionRewards).To(Equal(2*(uploaderPayoutReward+storageReward) - 300)) Expect(s.GetBalanceFromAddress(i.STAKER_0)).To(Equal(initialBalanceStaker0 + 300)) }) diff --git a/x/stakers/keeper/msg_server_join_pool_test.go b/x/stakers/keeper/msg_server_join_pool_test.go index 1691545f..841327b5 100644 --- a/x/stakers/keeper/msg_server_join_pool_test.go +++ b/x/stakers/keeper/msg_server_join_pool_test.go @@ -52,7 +52,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { // create pool s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", @@ -393,7 +393,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { }) s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest2", + Name: "Test Pool2", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", @@ -418,7 +418,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { It("Try to join pool with a valaddress that is already used by another staker", func() { // ARRANGE s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest2", + Name: "Test Pool2", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", @@ -489,7 +489,7 @@ var _ = Describe("msg_server_join_pool.go", Ordered, func() { }) s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest2", + Name: "Test Pool2", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/stakers/keeper/msg_server_leave_pool_test.go b/x/stakers/keeper/msg_server_leave_pool_test.go index 6d2f755f..bc05b851 100644 --- a/x/stakers/keeper/msg_server_leave_pool_test.go +++ b/x/stakers/keeper/msg_server_leave_pool_test.go @@ -30,7 +30,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { // create pool s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", @@ -209,7 +209,7 @@ var _ = Describe("msg_server_leave_pool.go", Ordered, func() { It("Leave one of multiple pools a staker has previously joined", func() { // ARRANGE s.App().PoolKeeper.AppendPool(s.Ctx(), pooltypes.Pool{ - Name: "Moontest", + Name: "PoolTest", Protocol: &pooltypes.Protocol{ Version: "0.0.0", Binaries: "{}", diff --git a/x/stakers/spec/07_exported.md b/x/stakers/spec/07_exported.md index eae8a6d5..0a6700de 100644 --- a/x/stakers/spec/07_exported.md +++ b/x/stakers/spec/07_exported.md @@ -65,6 +65,6 @@ type StakersKeeper interface { // IncreaseStakerCommissionRewards increases the commission rewards of a // staker by a specific amount. It can not be decreased, only the // MsgClaimCommissionRewards message can decrease this value. - IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) + IncreaseStakerCommissionRewards(ctx sdk.Context, address string, amount uint64) error } ``` diff --git a/x/team/abci.go b/x/team/abci.go index 0772f18c..5a90a279 100644 --- a/x/team/abci.go +++ b/x/team/abci.go @@ -10,8 +10,7 @@ import ( authTypes "github.com/cosmos/cosmos-sdk/x/auth/types" // Bank bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - // Mint - mintKeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + // Team "github.com/KYVENetwork/chain/x/team/keeper" "github.com/KYVENetwork/chain/x/team/types" @@ -19,31 +18,9 @@ import ( upgradeKeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" ) -func DistributeTeamInflation(ctx sdk.Context, bk bankKeeper.Keeper, mk mintKeeper.Keeper, tk keeper.Keeper, uk upgradeKeeper.Keeper) { - // Compute team allocation of minted coins. - minter := mk.GetMinter(ctx) - params := mk.GetParams(ctx) - - // get total inflation rewards for current block - blockProvision := minter.BlockProvision(params) - - // calculate theoretical team balance. We don't use team module balance because a third party could skew - // the team inflation rewards by simply transferring funds to the team module account - teamBalance := tk.GetTeamInfo(ctx).RequiredModuleBalance - - // calculate total inflation rewards for team module. - // We subtract current inflation because it was already applied to the total supply because BeginBlocker - // x/mint runs before this method - totalSupply := bk.GetSupply(ctx, blockProvision.Denom).Amount.Int64() - blockProvision.Amount.Int64() - teamModuleRewardsShare := sdk.NewDec(int64(teamBalance)).Quo(sdk.NewDec(totalSupply)) - - // if team module balance is greater than total supply panic - if teamModuleRewardsShare.GT(sdk.NewDec(int64(1))) { - util.PanicHalt(uk, ctx, fmt.Sprintf("team module balance %v is higher than total supply %v", teamBalance, totalSupply)) - } - - // calculate the total reward in $KYVE the entire team module receives this block - teamModuleRewards := uint64(teamModuleRewardsShare.Mul(sdk.NewDec(blockProvision.Amount.Int64())).TruncateInt64()) +func DistributeTeamInflation(ctx sdk.Context, bk bankKeeper.Keeper, tk keeper.Keeper, uk upgradeKeeper.Keeper) { + // get the total team reward the module is eligible for in this block + teamModuleRewards := tk.GetTeamBlockProvision(ctx) // count total account rewards totalAccountRewards := uint64(0) @@ -55,7 +32,7 @@ func DistributeTeamInflation(ctx sdk.Context, bk bankKeeper.Keeper, mk mintKeepe // calculate reward share of account accountShare := sdk.NewDec(int64(status.TotalVestedAmount - account.UnlockedClaimed)).Quo(sdk.NewDec(int64(types.TEAM_ALLOCATION))) // calculate total inflation rewards for account for this block - accountRewards := uint64(sdk.NewDec(int64(teamModuleRewards)).Mul(accountShare).TruncateInt64()) + accountRewards := uint64(sdk.NewDec(teamModuleRewards).Mul(accountShare).TruncateInt64()) // save inflation rewards to account account.TotalRewards += accountRewards @@ -66,17 +43,17 @@ func DistributeTeamInflation(ctx sdk.Context, bk bankKeeper.Keeper, mk mintKeepe } // panic if total account rewards are higher than team module rewards - if totalAccountRewards > teamModuleRewards { + if totalAccountRewards > uint64(teamModuleRewards) { util.PanicHalt(uk, ctx, fmt.Sprintf("account rewards %v are higher than entire team module rewards %v", totalAccountRewards, teamModuleRewards)) } // track total authority inflation rewards authority := tk.GetAuthority(ctx) - authority.TotalRewards += teamModuleRewards - totalAccountRewards + authority.TotalRewards += uint64(teamModuleRewards) - totalAccountRewards tk.SetAuthority(ctx, authority) // distribute part of block provision to team module - if err := util.TransferFromModuleToModule(bk, ctx, authTypes.FeeCollectorName, types.ModuleName, teamModuleRewards); err != nil { + if err := util.TransferFromModuleToModule(bk, ctx, authTypes.FeeCollectorName, types.ModuleName, uint64(teamModuleRewards)); err != nil { util.PanicHalt(uk, ctx, err.Error()) } diff --git a/x/team/keeper/keeper.go b/x/team/keeper/keeper.go index 86bf8874..d454901a 100644 --- a/x/team/keeper/keeper.go +++ b/x/team/keeper/keeper.go @@ -3,6 +3,9 @@ package keeper import ( "fmt" + mintKeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" + upgradeKeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper" + "github.com/cosmos/cosmos-sdk/codec" storeTypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,6 +26,8 @@ type ( accountKeeper authKeeper.AccountKeeper bankKeeper bankKeeper.Keeper + mintKeeper mintKeeper.Keeper + upgradeKeeper upgradeKeeper.Keeper } ) @@ -31,6 +36,8 @@ func NewKeeper( storeKey storeTypes.StoreKey, accountKeeper authKeeper.AccountKeeper, bankKeeper bankKeeper.Keeper, + mintKeeper mintKeeper.Keeper, + upgradeKeeper upgradeKeeper.Keeper, ) *Keeper { return &Keeper{ cdc: cdc, @@ -38,6 +45,8 @@ func NewKeeper( accountKeeper: accountKeeper, bankKeeper: bankKeeper, + mintKeeper: mintKeeper, + upgradeKeeper: upgradeKeeper, } } diff --git a/x/team/keeper/logic_team.go b/x/team/keeper/logic_team.go index 299b43b4..c9b6b470 100644 --- a/x/team/keeper/logic_team.go +++ b/x/team/keeper/logic_team.go @@ -1,12 +1,43 @@ package keeper import ( + "fmt" + "github.com/KYVENetwork/chain/util" globalTypes "github.com/KYVENetwork/chain/x/global/types" "github.com/KYVENetwork/chain/x/team/types" sdk "github.com/cosmos/cosmos-sdk/types" ) +// GetTeamBlockProvision gets the total reward amount for the team module +// for the current block +func (k Keeper) GetTeamBlockProvision(ctx sdk.Context) int64 { + // Compute team allocation of minted coins. + minter := k.mintKeeper.GetMinter(ctx) + params := k.mintKeeper.GetParams(ctx) + + // get total inflation rewards for current block + blockProvision := minter.BlockProvision(params) + + // calculate theoretical team balance. We don't use team module balance because a third party could skew + // the team inflation rewards by simply transferring funds to the team module account + teamBalance := k.GetTeamInfo(ctx).RequiredModuleBalance + + // calculate total inflation rewards for team module. + // We subtract current inflation because it was already applied to the total supply because BeginBlocker + // x/mint runs before this method + totalSupply := k.bankKeeper.GetSupply(ctx, blockProvision.Denom).Amount.Int64() - blockProvision.Amount.Int64() + teamModuleRewardsShare := sdk.NewDec(int64(teamBalance)).Quo(sdk.NewDec(totalSupply)) + + // if team module balance is greater than total supply panic + if teamModuleRewardsShare.GT(sdk.NewDec(int64(1))) { + util.PanicHalt(k.upgradeKeeper, ctx, fmt.Sprintf("team module balance %v is higher than total supply %v", teamBalance, totalSupply)) + } + + // calculate the total reward in $KYVE the entire team module receives this block + return teamModuleRewardsShare.Mul(sdk.NewDec(blockProvision.Amount.Int64())).TruncateInt64() +} + // GetVestingStatus returns all computed values which are dependent on the time // for the given account func GetVestingStatus(account types.TeamVestingAccount, time uint64) *types.VestingStatus { diff --git a/x/team/module.go b/x/team/module.go index 2edd5a53..c0988157 100644 --- a/x/team/module.go +++ b/x/team/module.go @@ -160,7 +160,7 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { - DistributeTeamInflation(ctx, am.bk, am.mk, am.keeper, am.uk) + DistributeTeamInflation(ctx, am.bk, am.keeper, am.uk) } // EndBlock contains the logic that is automatically triggered at the end of each block