From 73588394daa2fcca37e42711c8dbc3c19cc09228 Mon Sep 17 00:00:00 2001 From: Maximilian Breithecker <72022235+mbreithecker@users.noreply.github.com> Date: Fri, 3 May 2024 14:02:23 +0200 Subject: [PATCH] feat: support multiple denoms for delegation rewards (#176) --- app/upgrades/v1_5/upgrade.go | 2 + docs/static/openapi.yml | 86 ++++- .../kyve/delegation/v1beta1/delegation.proto | 15 +- proto/kyve/delegation/v1beta1/events.proto | 8 +- proto/kyve/query/v1beta1/account.proto | 8 +- proto/kyve/query/v1beta1/delegation.proto | 18 +- testutil/integration/checks.go | 28 +- testutil/integration/helpers.go | 14 + testutil/integration/integration.go | 25 +- .../keeper_suite_dropped_bundles_test.go | 4 +- .../keeper_suite_inflation_splitting_test.go | 25 +- .../keeper_suite_invalid_bundles_test.go | 30 +- .../keeper/keeper_suite_stakers_leave_test.go | 11 +- .../keeper/keeper_suite_valid_bundles_test.go | 31 +- .../keeper_suite_zero_delegation_test.go | 10 +- x/bundles/keeper/logic_bundles.go | 4 +- x/bundles/types/expected_keepers.go | 2 +- x/delegation/keeper/exported_functions.go | 14 +- .../keeper/getters_delegation_data.go | 4 +- x/delegation/keeper/keeper_suite_test.go | 12 +- x/delegation/keeper/logic_delegation.go | 21 +- x/delegation/keeper/logic_f1distribution.go | 67 ++-- .../keeper/msg_server_delegate_test.go | 34 +- .../keeper/msg_server_undelegate_test.go | 12 +- .../keeper/msg_server_update_params_test.go | 3 - .../keeper/msg_server_withdraw_rewards.go | 17 +- .../msg_server_withdraw_rewards_test.go | 302 +++++++++++++++++- x/delegation/spec/01_concepts.md | 2 +- x/delegation/spec/02_state.md | 18 +- x/delegation/spec/07_exported.md | 18 +- x/delegation/types/delegation.pb.go | 195 ++++++----- x/delegation/types/events.pb.go | 123 ++++--- x/query/keeper/grpc_account_assets.go | 2 +- x/query/keeper/grpc_delegation_delegator.go | 2 +- .../grpc_delegation_delegators_by_staker.go | 2 +- .../grpc_delegation_stakers_by_delegator.go | 2 +- x/query/types/account.pb.go | 173 ++++++---- x/query/types/delegation.pb.go | 256 +++++++++------ ...sg_server_claim_commission_rewards_test.go | 4 +- 39 files changed, 1110 insertions(+), 494 deletions(-) diff --git a/app/upgrades/v1_5/upgrade.go b/app/upgrades/v1_5/upgrade.go index 7c9c2a44..3553e1e3 100644 --- a/app/upgrades/v1_5/upgrade.go +++ b/app/upgrades/v1_5/upgrade.go @@ -34,6 +34,8 @@ func CreateUpgradeHandler(mm *module.Manager, configurator module.Configurator, // TODO: migrate gov params + // TODO: migrate delegation outstanding rewards + return mm.RunMigrations(ctx, configurator, fromVM) } } diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index 4f393572..d13ddcd1 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -267,8 +267,22 @@ paths: format: uint64 title: protocol_delegation_unbonding protocol_rewards: - type: string - format: uint64 + type: array + items: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the custom + method + + signatures required by gogoproto. description: protocol_rewards ... protocol_funding: type: string @@ -3184,10 +3198,24 @@ paths: delegator: type: string description: delegator ... - current_reward: - type: string - format: uint64 - description: current_reward ... + current_rewards: + type: array + items: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + description: current_rewards ... delegation_amount: type: string format: uint64 @@ -3424,10 +3452,25 @@ paths: delegator: type: string description: delegator ... - current_reward: - type: string - format: uint64 - description: current_reward ... + current_rewards: + type: array + items: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + description: current_rewards ... delegation_amount: type: string format: uint64 @@ -3977,10 +4020,25 @@ paths: It contains almost all needed information for a convenient usage - current_reward: - type: string - format: uint64 - description: current_reward ... + current_rewards: + type: array + items: + type: object + properties: + denom: + type: string + amount: + type: string + description: >- + Coin defines a token with a denomination and an + amount. + + + NOTE: The amount field is an Int which implements the + custom method + + signatures required by gogoproto. + description: current_rewards ... delegation_amount: type: string format: uint64 diff --git a/proto/kyve/delegation/v1beta1/delegation.proto b/proto/kyve/delegation/v1beta1/delegation.proto index 566e0084..3a8b93bf 100644 --- a/proto/kyve/delegation/v1beta1/delegation.proto +++ b/proto/kyve/delegation/v1beta1/delegation.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kyve.delegation.v1beta1; +import "amino/amino.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; option go_package = "github.com/KYVENetwork/chain/x/delegation/types"; @@ -31,9 +33,10 @@ message DelegationEntry { uint64 k_index = 2; // value is the quotient of collected rewards and total stake according to F1-distribution - string value = 3 [ - (gogoproto.customtype) = "cosmossdk.io/math.LegacyDec", - (gogoproto.nullable) = false + repeated cosmos.base.v1beta1.DecCoin value = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins" ]; } @@ -47,7 +50,11 @@ message DelegationData { // F1Distribution // current_rewards ... - uint64 current_rewards = 2; + repeated cosmos.base.v1beta1.Coin current_rewards = 2 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; // total_delegation ... uint64 total_delegation = 3; // latest_index_k ... diff --git a/proto/kyve/delegation/v1beta1/events.proto b/proto/kyve/delegation/v1beta1/events.proto index 8cdc5593..5177398b 100644 --- a/proto/kyve/delegation/v1beta1/events.proto +++ b/proto/kyve/delegation/v1beta1/events.proto @@ -2,6 +2,8 @@ syntax = "proto3"; package kyve.delegation.v1beta1; +import "amino/amino.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "kyve/delegation/v1beta1/delegation.proto"; import "kyve/delegation/v1beta1/params.proto"; @@ -78,7 +80,11 @@ message EventWithdrawRewards { // staker is the account address of the protocol node the users withdraws from. string staker = 2; // amount ... - uint64 amount = 3; + repeated cosmos.base.v1beta1.Coin amount = 3 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; } // EventSlash is an event emitted when a protocol node is slashed. diff --git a/proto/kyve/query/v1beta1/account.proto b/proto/kyve/query/v1beta1/account.proto index cb0dd48a..e57a2b12 100644 --- a/proto/kyve/query/v1beta1/account.proto +++ b/proto/kyve/query/v1beta1/account.proto @@ -2,7 +2,9 @@ syntax = "proto3"; package kyve.query.v1beta1; +import "amino/amino.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "kyve/query/v1beta1/query.proto"; @@ -55,7 +57,11 @@ message QueryAccountAssetsResponse { // protocol_delegation_unbonding uint64 protocol_delegation_unbonding = 5; // protocol_rewards ... - uint64 protocol_rewards = 6; + repeated cosmos.base.v1beta1.Coin protocol_rewards = 6 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; // protocol_funding ... uint64 protocol_funding = 7; } diff --git a/proto/kyve/query/v1beta1/delegation.proto b/proto/kyve/query/v1beta1/delegation.proto index b57a80e7..cd455a3c 100644 --- a/proto/kyve/query/v1beta1/delegation.proto +++ b/proto/kyve/query/v1beta1/delegation.proto @@ -2,7 +2,9 @@ syntax = "proto3"; package kyve.query.v1beta1; +import "amino/amino.proto"; import "cosmos/base/query/v1beta1/pagination.proto"; +import "cosmos/base/v1beta1/coin.proto"; import "gogoproto/gogo.proto"; import "google/api/annotations.proto"; import "kyve/query/v1beta1/query.proto"; @@ -51,8 +53,12 @@ message QueryDelegatorResponse { message StakerDelegatorResponse { // delegator ... string delegator = 1; - // current_reward ... - uint64 current_reward = 2; + // current_rewards ... + repeated cosmos.base.v1beta1.Coin current_rewards = 6 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; // delegation_amount ... uint64 delegation_amount = 3; // staker ... @@ -109,8 +115,12 @@ message QueryStakersByDelegatorResponse { message DelegationForStakerResponse { // staker ... FullStaker staker = 1; - // current_reward ... - uint64 current_reward = 2; + // current_rewards ... + repeated cosmos.base.v1beta1.Coin current_rewards = 6 [ + (gogoproto.nullable) = false, + (amino.dont_omitempty) = true, + (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ]; // delegation_amount ... uint64 delegation_amount = 3; } diff --git a/testutil/integration/checks.go b/testutil/integration/checks.go index b487b346..da8b40b1 100644 --- a/testutil/integration/checks.go +++ b/testutil/integration/checks.go @@ -4,6 +4,8 @@ import ( "fmt" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "cosmossdk.io/store" storeTypes "cosmossdk.io/store/types" @@ -328,7 +330,7 @@ func (suite *KeeperTestSuite) VerifyDelegationQueries() { Expect(resD.Delegator.Delegator).To(Equal(delegator.Delegator)) Expect(resD.Delegator.Staker).To(Equal(delegator.Staker)) Expect(resD.Delegator.DelegationAmount).To(Equal(suite.App().DelegationKeeper.GetDelegationAmountOfDelegator(suite.Ctx(), delegator.Staker, delegator.Delegator))) - Expect(resD.Delegator.CurrentReward).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator))) + Expect(resD.Delegator.CurrentRewards.String()).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator).String())) // Query: stakers_by_delegator/{delegator} resSbD, errSbD := suite.App().QueryKeeper.StakersByDelegator(suite.Ctx(), &querytypes.QueryStakersByDelegatorRequest{ @@ -339,7 +341,7 @@ func (suite *KeeperTestSuite) VerifyDelegationQueries() { Expect(resSbD.Delegator).To(Equal(delegator.Delegator)) for _, sRes := range resSbD.Stakers { Expect(sRes.DelegationAmount).To(Equal(suite.App().DelegationKeeper.GetDelegationAmountOfDelegator(suite.Ctx(), sRes.Staker.Address, delegator.Delegator))) - Expect(sRes.CurrentReward).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), sRes.Staker.Address, delegator.Delegator))) + Expect(sRes.CurrentRewards.String()).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), sRes.Staker.Address, delegator.Delegator).String())) suite.verifyFullStaker(*sRes.Staker, sRes.Staker.Address) } } @@ -367,28 +369,34 @@ func (suite *KeeperTestSuite) VerifyDelegationQueries() { for _, delegator := range resDbS.Delegators { Expect(stakersDelegators[delegator.Staker][delegator.Delegator]).ToNot(BeNil()) Expect(delegator.DelegationAmount).To(Equal(suite.App().DelegationKeeper.GetDelegationAmountOfDelegator(suite.Ctx(), delegator.Staker, delegator.Delegator))) - Expect(delegator.CurrentReward).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator))) + Expect(delegator.CurrentRewards.String()).To(Equal(suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator).String())) } } } func (suite *KeeperTestSuite) VerifyDelegationModuleIntegrity() { - expectedBalance := uint64(0) + expectedBalance := sdk.NewCoins() for _, delegator := range suite.App().DelegationKeeper.GetAllDelegators(suite.Ctx()) { - expectedBalance += suite.App().DelegationKeeper.GetDelegationAmountOfDelegator(suite.Ctx(), delegator.Staker, delegator.Delegator) - expectedBalance += suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator) + expectedBalance = expectedBalance.Add( + sdk.NewInt64Coin(globalTypes.Denom, + int64(suite.App().DelegationKeeper.GetDelegationAmountOfDelegator(suite.Ctx(), delegator.Staker, delegator.Delegator)), + )).Add( + suite.App().DelegationKeeper.GetOutstandingRewards(suite.Ctx(), delegator.Staker, delegator.Delegator)..., + ) } // Due to rounding errors the delegation module will get a very few nKYVE over the time. // As long as it is guaranteed that it's always the user who gets paid out less in case of // rounding, everything is fine. - difference := suite.GetBalanceFromModule(delegationtypes.ModuleName) - expectedBalance + difference := suite.GetCoinsFromModule(delegationtypes.ModuleName).Sub(expectedBalance...) //nolint:all - Expect(difference >= 0).To(BeTrue()) + Expect(difference.IsAnyNegative()).To(BeFalse()) - // 10 should be enough for testing - Expect(difference <= 10).To(BeTrue()) + // 10 should be enough for testing, these are left-over tokens due to rounding issues + for _, coin := range difference { + Expect(coin.Amount.Uint64() < 10).To(BeTrue()) + } } func (suite *KeeperTestSuite) VerifyDelegationGenesisImportExport() { diff --git a/testutil/integration/helpers.go b/testutil/integration/helpers.go index 418bc540..514aea52 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) GetCoinsFromAddress(address string) sdk.Coins { + accAddress, err := sdk.AccAddressFromBech32(address) + if err != nil { + return sdk.NewCoins() + } + + return suite.App().BankKeeper.GetAllBalances(suite.Ctx(), accAddress) +} + func (suite *KeeperTestSuite) GetBalanceFromPool(poolId uint64) uint64 { pool, found := suite.App().PoolKeeper.GetPool(suite.Ctx(), poolId) if !found { @@ -30,6 +39,11 @@ func (suite *KeeperTestSuite) GetBalanceFromModule(moduleName string) uint64 { return suite.App().BankKeeper.GetBalance(suite.Ctx(), moduleAcc, globalTypes.Denom).Amount.Uint64() } +func (suite *KeeperTestSuite) GetCoinsFromModule(moduleName string) sdk.Coins { + moduleAcc := suite.App().AccountKeeper.GetModuleAccount(suite.Ctx(), moduleName).GetAddress() + return suite.App().BankKeeper.GetAllBalances(suite.Ctx(), moduleAcc) +} + func (suite *KeeperTestSuite) GetNextUploader() (nextStaker string, nextValaddress string) { bundleProposal, _ := suite.App().BundlesKeeper.GetBundleProposal(suite.Ctx(), 0) diff --git a/testutil/integration/integration.go b/testutil/integration/integration.go index 5642399e..830b01bc 100644 --- a/testutil/integration/integration.go +++ b/testutil/integration/integration.go @@ -131,8 +131,8 @@ func (suite *KeeperTestSuite) initDummyAccounts() { } } -func (suite *KeeperTestSuite) Mint(address string, amount uint64) error { - coins := sdk.NewCoins(sdk.NewInt64Coin(KYVE_DENOM, int64(amount))) +func (suite *KeeperTestSuite) MintDenom(address string, amount uint64, denom string) error { + coins := sdk.NewCoins(sdk.NewInt64Coin(denom, int64(amount))) err := suite.app.BankKeeper.MintCoins(suite.ctx, mintTypes.ModuleName, coins) if err != nil { return err @@ -153,6 +153,27 @@ func (suite *KeeperTestSuite) Mint(address string, amount uint64) error { return nil } +func (suite *KeeperTestSuite) MintDenomToModule(moduleAddress string, amount uint64, denom string) error { + coins := sdk.NewCoins(sdk.NewInt64Coin(denom, int64(amount))) + err := suite.app.BankKeeper.MintCoins(suite.ctx, mintTypes.ModuleName, coins) + if err != nil { + return err + } + + suite.Commit() + + err = suite.app.BankKeeper.SendCoinsFromModuleToModule(suite.ctx, mintTypes.ModuleName, moduleAddress, coins) + if err != nil { + return err + } + + return nil +} + +func (suite *KeeperTestSuite) Mint(address string, amount uint64) error { + return suite.MintDenom(address, amount, KYVE_DENOM) +} + type KeeperTestSuite struct { suite.Suite diff --git a/x/bundles/keeper/keeper_suite_dropped_bundles_test.go b/x/bundles/keeper/keeper_suite_dropped_bundles_test.go index f695b523..034f43ef 100644 --- a/x/bundles/keeper/keeper_suite_dropped_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_dropped_bundles_test.go @@ -182,7 +182,7 @@ var _ = Describe("dropped bundles", Ordered, func() { balanceUploader := s.GetBalanceFromAddress(valaccountUploader.Staker) Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // check voter status valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -195,7 +195,7 @@ var _ = Describe("dropped bundles", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) // check pool funds pool, _ = s.App().PoolKeeper.GetPool(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go index bde9ad47..6d76cf62 100644 --- a/x/bundles/keeper/keeper_suite_inflation_splitting_test.go +++ b/x/bundles/keeper/keeper_suite_inflation_splitting_test.go @@ -5,6 +5,7 @@ import ( i "github.com/KYVENetwork/chain/testutil/integration" bundletypes "github.com/KYVENetwork/chain/x/bundles/types" funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" stakertypes "github.com/KYVENetwork/chain/x/stakers/types" . "github.com/onsi/ginkgo/v2" @@ -182,7 +183,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -275,7 +276,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -368,7 +369,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -474,7 +475,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -581,7 +582,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -688,7 +689,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -793,7 +794,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -900,7 +901,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1007,7 +1008,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1112,7 +1113,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1219,7 +1220,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1326,7 +1327,7 @@ var _ = Describe("inflation splitting", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go index 22f317b0..9ee64d18 100644 --- a/x/bundles/keeper/keeper_suite_invalid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_invalid_bundles_test.go @@ -223,7 +223,7 @@ var _ = Describe("invalid bundles", Ordered, func() { Expect(uploaderFound).To(BeTrue()) Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // calculate uploader slashes fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) @@ -242,7 +242,7 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) // check voter 2 status valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) @@ -254,7 +254,7 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeEmpty()) // check pool funds fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -391,7 +391,7 @@ var _ = Describe("invalid bundles", Ordered, func() { // 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(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // calculate uploader slashes fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) @@ -412,8 +412,8 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeEmpty()) // check voter 2 status valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -424,8 +424,8 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeEmpty()) // check pool funds fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -589,7 +589,7 @@ var _ = Describe("invalid bundles", Ordered, func() { // 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(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // calculate uploader slashes fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) @@ -618,8 +618,8 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter := s.GetBalanceFromAddress(i.STAKER_1) Expect(balanceVoter).To(Equal(initialBalanceStaker2)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeEmpty()) // check voter2 status valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_2) @@ -630,8 +630,8 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.STAKER_2)).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeEmpty()) // check voter3 status valaccountVoter, _ = s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_3) @@ -642,8 +642,8 @@ var _ = Describe("invalid bundles", Ordered, func() { balanceVoter = s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.STAKER_3)).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.DAVID)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.STAKER_3)).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_3, i.DAVID)).To(BeEmpty()) // check pool funds fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_stakers_leave_test.go b/x/bundles/keeper/keeper_suite_stakers_leave_test.go index b93f69e7..f740b897 100644 --- a/x/bundles/keeper/keeper_suite_stakers_leave_test.go +++ b/x/bundles/keeper/keeper_suite_stakers_leave_test.go @@ -5,6 +5,7 @@ import ( i "github.com/KYVENetwork/chain/testutil/integration" bundletypes "github.com/KYVENetwork/chain/x/bundles/types" funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" stakertypes "github.com/KYVENetwork/chain/x/stakers/types" . "github.com/onsi/ginkgo/v2" @@ -255,7 +256,7 @@ var _ = Describe("stakers leave", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) }) It("Staker leaves, although he was the uploader of the previous round and should get slashed", func() { @@ -354,7 +355,7 @@ var _ = Describe("stakers leave", Ordered, func() { // 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(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) }) It("Staker leaves, although he was a voter in the previous round and should get slashed", func() { @@ -455,7 +456,7 @@ var _ = Describe("stakers leave", Ordered, func() { // assert payout transfer Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) }) It("Staker leaves, although he was a voter in the previous round and should get a point", func() { @@ -548,7 +549,7 @@ var _ = Describe("stakers leave", Ordered, func() { // assert payout transfer Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) }) It("Staker leaves, although he was a voter who did not vote max points in a row should not get slashed", func() { @@ -644,6 +645,6 @@ var _ = Describe("stakers leave", Ordered, func() { // assert payout transfer Expect(balanceVoter).To(Equal(initialBalanceStaker1)) // assert uploader self delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) }) }) diff --git a/x/bundles/keeper/keeper_suite_valid_bundles_test.go b/x/bundles/keeper/keeper_suite_valid_bundles_test.go index 121fdd7c..e2d23c11 100644 --- a/x/bundles/keeper/keeper_suite_valid_bundles_test.go +++ b/x/bundles/keeper/keeper_suite_valid_bundles_test.go @@ -3,6 +3,7 @@ package keeper_test import ( "cosmossdk.io/math" fundersTypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -246,7 +247,7 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -395,19 +396,19 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) // assert delegator delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.BOB)).To(BeEmpty()) // assert payout transfer Expect(balanceUploader).To(Equal(initialBalanceStaker0)) // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -573,12 +574,12 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) // assert delegator delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -752,12 +753,12 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) // assert delegator delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -941,12 +942,12 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) // assert delegator delegation rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE)).To(Equal(delegatorDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(delegatorDelegationReward)) // check voter rewards - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_2, i.CHARLIE)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -1092,7 +1093,7 @@ var _ = Describe("valid bundles", Ordered, func() { // 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)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward)) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) diff --git a/x/bundles/keeper/keeper_suite_zero_delegation_test.go b/x/bundles/keeper/keeper_suite_zero_delegation_test.go index 5f4fc408..87c08c23 100644 --- a/x/bundles/keeper/keeper_suite_zero_delegation_test.go +++ b/x/bundles/keeper/keeper_suite_zero_delegation_test.go @@ -474,7 +474,7 @@ var _ = Describe("zero delegation", Ordered, func() { // assert commission rewards 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()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -627,7 +627,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(uploaderFound).To(BeTrue()) Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // calculate uploader slashes fraction := s.App().DelegationKeeper.GetUploadSlash(s.Ctx()) @@ -646,7 +646,7 @@ var _ = Describe("zero delegation", Ordered, func() { balanceVoter := s.GetBalanceFromAddress(valaccountVoter.Staker) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) @@ -891,7 +891,7 @@ var _ = Describe("zero delegation", Ordered, func() { balanceUploader := s.GetBalanceFromAddress(valaccountUploader.Staker) Expect(balanceUploader).To(Equal(initialBalanceStaker0)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0)).To(BeEmpty()) // check voter status valaccountVoter, _ := s.App().StakersKeeper.GetValaccount(s.Ctx(), 0, i.STAKER_1) @@ -904,7 +904,7 @@ var _ = Describe("zero delegation", Ordered, func() { Expect(balanceVoter).To(Equal(initialBalanceStaker1)) Expect(balanceVoter).To(Equal(initialBalanceStaker1)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_1, i.STAKER_1)).To(BeEmpty()) fundingState, _ := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index 74917b73..7488597c 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -3,6 +3,7 @@ package keeper import ( "cosmossdk.io/errors" "cosmossdk.io/math" + globalTypes "github.com/KYVENetwork/chain/x/global/types" poolTypes "github.com/KYVENetwork/chain/x/pool/types" delegationTypes "github.com/KYVENetwork/chain/x/delegation/types" @@ -550,7 +551,8 @@ func (k msgServer) tallyBundleProposal(ctx sdk.Context, bundleProposal types.Bun } // payout rewards to delegators through delegation rewards - if err := k.delegationKeeper.PayoutRewards(ctx, bundleProposal.Uploader, bundleReward.Delegation, poolTypes.ModuleName); err != nil { + bundleRewardCoins := sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(bundleReward.Delegation))) + if err := k.delegationKeeper.PayoutRewards(ctx, bundleProposal.Uploader, bundleRewardCoins, poolTypes.ModuleName); err != nil { return types.TallyResult{}, err } diff --git a/x/bundles/types/expected_keepers.go b/x/bundles/types/expected_keepers.go index a8a02f5e..896dcd84 100644 --- a/x/bundles/types/expected_keepers.go +++ b/x/bundles/types/expected_keepers.go @@ -43,7 +43,7 @@ type DelegationKeeper interface { GetDelegationAmount(ctx sdk.Context, staker string) uint64 GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 GetTotalAndHighestDelegationOfPool(ctx sdk.Context, poolId uint64) (uint64, uint64) - PayoutRewards(ctx sdk.Context, staker string, amount uint64, payerModuleName string) error + PayoutRewards(ctx sdk.Context, staker string, amount sdk.Coins, 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 16bd9bc1..98c8f5aa 100644 --- a/x/delegation/keeper/exported_functions.go +++ b/x/delegation/keeper/exported_functions.go @@ -58,14 +58,14 @@ func (k Keeper) GetTotalAndHighestDelegationOfPool(ctx sdk.Context, poolId uint6 return } -// PayoutRewards transfers `amount` $nKYVE from the `payerModuleName`-module to the delegation module. +// PayoutRewards transfers `amount` 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. -// 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 { +// If the staker has no delegators or the module to module transfer fails, the method fails and +// returns an error. +func (k Keeper) PayoutRewards(ctx sdk.Context, staker string, amount sdk.Coins, payerModuleName string) error { // Assert there is an amount - if amount == 0 { + if amount.Empty() { return nil } @@ -78,7 +78,7 @@ func (k Keeper) PayoutRewards(ctx sdk.Context, staker string, amount uint64, pay k.AddAmountToDelegationRewards(ctx, staker, amount) // Transfer tokens to the delegation module - if err := util.TransferFromModuleToModule(k.bankKeeper, ctx, payerModuleName, types.ModuleName, amount); err != nil { + if err := k.bankKeeper.SendCoinsFromModuleToModule(ctx, payerModuleName, types.ModuleName, amount); err != nil { return err } @@ -115,6 +115,6 @@ func (k Keeper) SlashDelegators(ctx sdk.Context, poolId uint64, staker string, s // GetOutstandingRewards calculates the current rewards a delegator has collected for // the given staker. -func (k Keeper) GetOutstandingRewards(ctx sdk.Context, staker string, delegator string) uint64 { +func (k Keeper) GetOutstandingRewards(ctx sdk.Context, staker string, delegator string) sdk.Coins { return k.f1GetOutstandingRewards(ctx, staker, delegator) } diff --git a/x/delegation/keeper/getters_delegation_data.go b/x/delegation/keeper/getters_delegation_data.go index 49cc92cf..358b7226 100644 --- a/x/delegation/keeper/getters_delegation_data.go +++ b/x/delegation/keeper/getters_delegation_data.go @@ -15,10 +15,10 @@ import ( // AddAmountToDelegationRewards adds the specified amount to the current delegationData object. // This is needed by the F1-algorithm to calculate to outstanding rewards -func (k Keeper) AddAmountToDelegationRewards(ctx sdk.Context, stakerAddress string, amount uint64) { +func (k Keeper) AddAmountToDelegationRewards(ctx sdk.Context, stakerAddress string, amount sdk.Coins) { delegationData, found := k.GetDelegationData(ctx, stakerAddress) if found { - delegationData.CurrentRewards += amount + delegationData.CurrentRewards = delegationData.CurrentRewards.Add(amount...) k.SetDelegationData(ctx, delegationData) } } diff --git a/x/delegation/keeper/keeper_suite_test.go b/x/delegation/keeper/keeper_suite_test.go index 392e2468..a9bf0ee9 100644 --- a/x/delegation/keeper/keeper_suite_test.go +++ b/x/delegation/keeper/keeper_suite_test.go @@ -4,6 +4,9 @@ import ( "fmt" "testing" + globalTypes "github.com/KYVENetwork/chain/x/global/types" + sdk "github.com/cosmos/cosmos-sdk/types" + funderstypes "github.com/KYVENetwork/chain/x/funders/types" i "github.com/KYVENetwork/chain/testutil/integration" @@ -19,22 +22,23 @@ func TestDelegationKeeper(t *testing.T) { RunSpecs(t, fmt.Sprintf("x/%s Keeper Test Suite", types.ModuleName)) } -func PayoutRewards(s *i.KeeperTestSuite, staker string, amount uint64) { +func PayoutRewards(s *i.KeeperTestSuite, staker string, coins sdk.Coins) { fundingState, found := s.App().FundersKeeper.GetFundingState(s.Ctx(), 0) Expect(found).To(BeTrue()) + // TODO support all denominations once the funding module supports it // divide amount by number of active fundings so that total payout is equal to amount activeFundings := s.App().FundersKeeper.GetActiveFundings(s.Ctx(), fundingState) for _, funding := range activeFundings { - funding.AmountPerBundle = amount / uint64(len(activeFundings)) + funding.AmountPerBundle = coins.AmountOf(globalTypes.Denom).Uint64() / uint64(len(activeFundings)) s.App().FundersKeeper.SetFunding(s.Ctx(), &funding) } payout, err := s.App().FundersKeeper.ChargeFundersOfPool(s.Ctx(), 0) Expect(err).To(BeNil()) - err = s.App().DelegationKeeper.PayoutRewards(s.Ctx(), staker, amount, pooltypes.ModuleName) + err = s.App().DelegationKeeper.PayoutRewards(s.Ctx(), staker, coins, pooltypes.ModuleName) Expect(err).NotTo(HaveOccurred()) - Expect(amount).To(Equal(payout)) + Expect(coins.AmountOf(globalTypes.Denom).Uint64()).To(Equal(payout)) } func CreateFundedPool(s *i.KeeperTestSuite) { diff --git a/x/delegation/keeper/logic_delegation.go b/x/delegation/keeper/logic_delegation.go index 2ce9331e..5b99fda4 100644 --- a/x/delegation/keeper/logic_delegation.go +++ b/x/delegation/keeper/logic_delegation.go @@ -16,7 +16,9 @@ func (k Keeper) performDelegation(ctx sdk.Context, stakerAddress string, delegat if k.DoesDelegatorExist(ctx, stakerAddress, delegatorAddress) { // If the sender is already a delegator, first perform an undelegation, before delegating. // "perform a withdrawal" - _ = k.performWithdrawal(ctx, stakerAddress, delegatorAddress) + if _, err := k.performWithdrawal(ctx, stakerAddress, delegatorAddress); err != nil { + util.PanicHalt(k.upgradeKeeper, ctx, "no money left in module") + } // Perform delegation by fully undelegating and then delegating the new amount unDelegateAmount := k.f1RemoveDelegator(ctx, stakerAddress, delegatorAddress) @@ -37,7 +39,9 @@ func (k Keeper) performUndelegation(ctx sdk.Context, stakerAddress string, deleg defer k.SetStakerIndex(ctx, stakerAddress) // Withdraw all outstanding rewards - k.performWithdrawal(ctx, stakerAddress, delegatorAddress) + if _, err := k.performWithdrawal(ctx, stakerAddress, delegatorAddress); err != nil { + util.PanicHalt(k.upgradeKeeper, ctx, "no money left in module") + } // Perform an internal re-delegation. undelegatedAmount := k.f1RemoveDelegator(ctx, stakerAddress, delegatorAddress) @@ -55,11 +59,14 @@ func (k Keeper) performUndelegation(ctx sdk.Context, stakerAddress string, deleg // performWithdrawal withdraws all pending rewards from a user and transfers it. // The amount is returned by the function. -func (k Keeper) performWithdrawal(ctx sdk.Context, stakerAddress, delegatorAddress string) uint64 { +func (k Keeper) performWithdrawal(ctx sdk.Context, stakerAddress, delegatorAddress string) (sdk.Coins, error) { reward := k.f1WithdrawRewards(ctx, stakerAddress, delegatorAddress) - err := util.TransferFromModuleToAddress(k.bankKeeper, ctx, types.ModuleName, delegatorAddress, reward) - if err != nil { - util.PanicHalt(k.upgradeKeeper, ctx, "no money left in module") + recipient, errAddress := sdk.AccAddressFromBech32(delegatorAddress) + if errAddress != nil { + return nil, errAddress + } + if err := k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, recipient, reward); err != nil { + return nil, err } // Emit withdraw event. @@ -69,5 +76,5 @@ func (k Keeper) performWithdrawal(ctx sdk.Context, stakerAddress, delegatorAddre Amount: reward, }) - return reward + return reward, nil } diff --git a/x/delegation/keeper/logic_f1distribution.go b/x/delegation/keeper/logic_f1distribution.go index e62ccb41..053b78eb 100644 --- a/x/delegation/keeper/logic_f1distribution.go +++ b/x/delegation/keeper/logic_f1distribution.go @@ -31,22 +31,22 @@ func (k Keeper) f1StartNewPeriod(ctx sdk.Context, staker string, delegationData // F1: corresponds to $Entry_{f-1}$ previousEntry, found := k.GetDelegationEntry(ctx, staker, delegationData.LatestIndexK) if !found { - previousEntry.Value = math.LegacyNewDec(0) + previousEntry.Value = sdk.NewDecCoins() } // Calculate quotient of current period // If totalDelegation is zero the quotient is also zero - currentPeriodValue := math.LegacyNewDec(0) + currentPeriodValue := sdk.NewDecCoins() if delegationData.TotalDelegation != 0 { - decCurrentRewards := math.LegacyNewDec(int64(delegationData.CurrentRewards)) + decCurrentRewards := sdk.NewDecCoinsFromCoins(delegationData.CurrentRewards...) decTotalDelegation := math.LegacyNewDec(int64(delegationData.TotalDelegation)) // F1: $T_f / n_f$ - currentPeriodValue = decCurrentRewards.Quo(decTotalDelegation) + currentPeriodValue = decCurrentRewards.QuoDec(decTotalDelegation) } // Add previous entry to current one - currentPeriodValue = currentPeriodValue.Add(previousEntry.Value) + currentPeriodValue = currentPeriodValue.Add(previousEntry.Value...) // Increment index for the next period indexF := delegationData.LatestIndexK + 1 @@ -60,7 +60,7 @@ func (k Keeper) f1StartNewPeriod(ctx sdk.Context, staker string, delegationData // Reset the rewards for the next period back to zero // and update to the new index - delegationData.CurrentRewards = 0 + delegationData.CurrentRewards = sdk.NewCoins() delegationData.LatestIndexK = indexF if delegationData.LatestIndexWasUndelegation { @@ -84,7 +84,8 @@ func (k Keeper) f1CreateDelegator(ctx sdk.Context, staker string, delegator stri // Init default data-set, if this is the first delegator if !found { delegationData = types.DelegationData{ - Staker: staker, + Staker: staker, + CurrentRewards: sdk.NewCoins(), } } @@ -177,10 +178,10 @@ func (k Keeper) f1Slash(ctx sdk.Context, stakerAddress string, fraction math.Leg // f1WithdrawRewards calculates all outstanding rewards and withdraws them from // the f1-logic. A new period starts. -func (k Keeper) f1WithdrawRewards(ctx sdk.Context, stakerAddress string, delegatorAddress string) (rewards uint64) { +func (k Keeper) f1WithdrawRewards(ctx sdk.Context, stakerAddress string, delegatorAddress string) sdk.Coins { delegator, found := k.GetDelegator(ctx, stakerAddress, delegatorAddress) if !found { - return 0 + return sdk.NewCoins() } // Fetch metadata @@ -197,15 +198,15 @@ func (k Keeper) f1WithdrawRewards(ctx sdk.Context, stakerAddress string, delegat // delegation amount for the period. // To incorporate slashing one needs to iterate all slashes and calculate the reward for every period // separately and then sum it. - reward := math.LegacyNewDec(0) + reward := sdk.NewDecCoins() k.f1IterateConstantDelegationPeriods(ctx, stakerAddress, delegatorAddress, delegator.KIndex, endIndex, func(startIndex uint64, endIndex uint64, delegation math.LegacyDec) { // entry difference difference := k.f1GetEntryDifference(ctx, stakerAddress, startIndex, endIndex) - periodReward := difference.Mul(delegation) + periodReward := safeMulDec(difference, delegation) - reward = reward.Add(periodReward) + reward = reward.Add(periodReward...) }) // Delete Delegator entry as he has no outstanding rewards anymore. @@ -216,7 +217,7 @@ func (k Keeper) f1WithdrawRewards(ctx sdk.Context, stakerAddress string, delegat delegator.InitialAmount = k.f1GetCurrentDelegation(ctx, delegator.Staker, delegator.Delegator) k.SetDelegator(ctx, delegator) - return reward.TruncateInt().Uint64() + return truncateDecCoins(reward) } // f1IterateConstantDelegationPeriods iterates all periods between minIndex and maxIndex (both inclusive) @@ -270,10 +271,10 @@ func (k Keeper) f1GetCurrentDelegation(ctx sdk.Context, stakerAddress string, de // f1GetOutstandingRewards calculates the current outstanding rewards without modifying the f1-state. // This method can be used for queries. -func (k Keeper) f1GetOutstandingRewards(ctx sdk.Context, stakerAddress string, delegatorAddress string) uint64 { +func (k Keeper) f1GetOutstandingRewards(ctx sdk.Context, stakerAddress string, delegatorAddress string) sdk.Coins { delegator, found := k.GetDelegator(ctx, stakerAddress, delegatorAddress) if !found { - return 0 + return sdk.NewCoins() } // Fetch metadata @@ -289,15 +290,15 @@ func (k Keeper) f1GetOutstandingRewards(ctx sdk.Context, stakerAddress string, d // delegation amount for the period. // To incorporate slashing one needs to iterate all slashes and calculate the reward for every period // separately and then sum it. - reward := math.LegacyNewDec(0) + reward := sdk.NewDecCoins() latestBalance := math.LegacyNewDec(int64(delegator.InitialAmount)) k.f1IterateConstantDelegationPeriods(ctx, stakerAddress, delegatorAddress, delegator.KIndex, endIndex, func(startIndex uint64, endIndex uint64, delegation math.LegacyDec) { difference := k.f1GetEntryDifference(ctx, stakerAddress, startIndex, endIndex) // Multiply with delegation for period - periodReward := difference.Mul(delegation) + periodReward := safeMulDec(difference, delegation) // Add to total rewards - reward = reward.Add(periodReward) + reward = reward.Add(periodReward...) // For calculating the last (ongoing) period latestBalance = delegation @@ -310,22 +311,22 @@ func (k Keeper) f1GetOutstandingRewards(ctx sdk.Context, stakerAddress string, d } _ = entry - currentPeriodValue := math.LegacyNewDec(0) + currentPeriodValue := sdk.NewDecCoins() if delegationData.TotalDelegation != 0 { - decCurrentRewards := math.LegacyNewDec(int64(delegationData.CurrentRewards)) + decCurrentRewards := sdk.NewDecCoinsFromCoins(delegationData.CurrentRewards...) decTotalDelegation := math.LegacyNewDec(int64(delegationData.TotalDelegation)) // F1: $T_f / n_f$ - currentPeriodValue = decCurrentRewards.Quo(decTotalDelegation) + currentPeriodValue = decCurrentRewards.QuoDec(decTotalDelegation) } - ongoingPeriodReward := currentPeriodValue.Mul(latestBalance) + ongoingPeriodReward := safeMulDec(currentPeriodValue, latestBalance) - reward = reward.Add(ongoingPeriodReward) - return reward.TruncateInt().Uint64() + reward = reward.Add(ongoingPeriodReward...) + return truncateDecCoins(reward) } -func (k Keeper) f1GetEntryDifference(ctx sdk.Context, stakerAddress string, lowIndex uint64, highIndex uint64) math.LegacyDec { +func (k Keeper) f1GetEntryDifference(ctx sdk.Context, stakerAddress string, lowIndex uint64, highIndex uint64) sdk.DecCoins { // entry difference firstEntry, found := k.GetDelegationEntry(ctx, stakerAddress, lowIndex) if !found { @@ -339,3 +340,19 @@ func (k Keeper) f1GetEntryDifference(ctx sdk.Context, stakerAddress string, lowI return secondEntry.Value.Sub(firstEntry.Value) } + +// truncateDecCoins converts sdm.DecCoins to sdk.Coins by truncating all values to integers. +func truncateDecCoins(decCoins sdk.DecCoins) sdk.Coins { + coins := sdk.NewCoins() + for _, coin := range decCoins { + coins = coins.Add(sdk.NewCoin(coin.Denom, coin.Amount.TruncateInt())) + } + return coins +} + +func safeMulDec(coins sdk.DecCoins, scalar math.LegacyDec) sdk.DecCoins { + if scalar.IsZero() { + return sdk.NewDecCoins() + } + return coins.MulDec(scalar) +} diff --git a/x/delegation/keeper/msg_server_delegate_test.go b/x/delegation/keeper/msg_server_delegate_test.go index c5880469..52954928 100644 --- a/x/delegation/keeper/msg_server_delegate_test.go +++ b/x/delegation/keeper/msg_server_delegate_test.go @@ -2,6 +2,8 @@ package keeper_test import ( funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -159,13 +161,13 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() { fundersModuleBalance := s.GetBalanceFromModule(funderstypes.ModuleName) Expect(fundersModuleBalance).To(Equal(100 * i.KYVE)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(BeEmpty()) s.PerformValidityChecks() // ACT - PayoutRewards(s, i.ALICE, 10*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE)))) // ASSERT @@ -173,18 +175,18 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() { // Alice: 100 100/(409) * 10 * 1e9 = 2.444.987.775 // Dummy0: 100 100/(409) * 10 * 1e9 = 2.444.987.775 // Dummy1: 209 209/(409) * 10 * 1e9 = 5.110.024.449 - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.ALICE)).To(Equal(uint64(2_444_987_775))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(2_444_987_775))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(5_110_024_449))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(2_444_987_775))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(2_444_987_775))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(5_110_024_449))) s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ Creator: i.DUMMY[0], Staker: i.ALICE, }) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.ALICE)).To(Equal(uint64(2_444_987_775))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(5_110_024_449))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.ALICE).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(2_444_987_775))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(0))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(5_110_024_449))) Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(900*i.KYVE + 2_444_987_775)) Expect(s.GetBalanceFromModule(funderstypes.ModuleName)).To(Equal(90 * i.KYVE)) @@ -209,19 +211,19 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() { Expect(fundersModuleBalance).To(Equal(100 * i.KYVE)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeZero()) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(BeZero()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(BeEmpty()) // ACT - PayoutRewards(s, i.ALICE, 10*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE)))) // ASSERT // Alice: 100 // Dummy0: 100 // Dummy1: 200 - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(2_500_000_000))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(5_000_000_000))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(2_500_000_000))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(5_000_000_000))) s.PerformValidityChecks() @@ -235,8 +237,8 @@ var _ = Describe("msg_server_delegate.go", Ordered, func() { Staker: i.ALICE, }) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(5_000_000_000))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(5_000_000_000))) Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(900*i.KYVE + 2_500_000_000)) Expect(s.GetBalanceFromModule(funderstypes.ModuleName)).To(Equal(90 * i.KYVE)) diff --git a/x/delegation/keeper/msg_server_undelegate_test.go b/x/delegation/keeper/msg_server_undelegate_test.go index 36349db1..ff4473fe 100644 --- a/x/delegation/keeper/msg_server_undelegate_test.go +++ b/x/delegation/keeper/msg_server_undelegate_test.go @@ -2,7 +2,9 @@ package keeper_test import ( "cosmossdk.io/math" + globalTypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -409,7 +411,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // Alice: 100 100/130 * 10 * 1e9 = 7_692_307_692 // Dummy0: 10 10/130 * 10 * 1e9 = 769_230_769 // Dummy1: 20 20/130 * 10 * 1e9 = 1_538_461_538 - PayoutRewards(s, i.ALICE, 10*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE)))) // Collect s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ @@ -493,11 +495,11 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // Alice: 50 50 / 75 * 10 * 1e9 = 6_666_666_666 // Dummy0: 5 5 / 75 * 10 * 1e9 = 666_666_666 // Dummy1: 20 20 / 75 * 10 * 1e9 = 2_666_666_666 - PayoutRewards(s, i.ALICE, 10*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE)))) // ASSERT - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(666_666_666))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(2_666_666_666))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(666_666_666))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(2_666_666_666))) // must be the same as before Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal((50 + 25) * i.KYVE)) @@ -576,7 +578,7 @@ var _ = Describe("msg_server_undelegate.go", Ordered, func() { // Alice: 25 25 / 32.5 * 1e10 = 7_692_307_692 // Dummy0: 2.5 2.5 / 32.5 * 1e10 = 769_230_769 // Dummy1: 5 5 / 32.5 * 1e10 = 1_538_461_538 - PayoutRewards(s, i.ALICE, 10*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE)))) s.CommitAfterSeconds(s.App().DelegationKeeper.GetUnbondingDelegationTime(s.Ctx()) + 1) s.CommitAfterSeconds(1) diff --git a/x/delegation/keeper/msg_server_update_params_test.go b/x/delegation/keeper/msg_server_update_params_test.go index 216c4b3e..3efaf9a9 100644 --- a/x/delegation/keeper/msg_server_update_params_test.go +++ b/x/delegation/keeper/msg_server_update_params_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "fmt" - "cosmossdk.io/math" i "github.com/KYVENetwork/chain/testutil/integration" @@ -518,7 +516,6 @@ var _ = Describe("msg_server_update_params.go", Ordered, func() { // ASSERT updatedParams := s.App().DelegationKeeper.GetParams(s.Ctx()) - fmt.Println(msg.ValidateBasic()) Expect(submitErr).To(HaveOccurred()) Expect(updatedParams.UnbondingDelegationTime).To(Equal(types.DefaultUnbondingDelegationTime)) diff --git a/x/delegation/keeper/msg_server_withdraw_rewards.go b/x/delegation/keeper/msg_server_withdraw_rewards.go index 44d550a0..f23a823b 100644 --- a/x/delegation/keeper/msg_server_withdraw_rewards.go +++ b/x/delegation/keeper/msg_server_withdraw_rewards.go @@ -3,8 +3,6 @@ package keeper import ( "context" - "github.com/KYVENetwork/chain/util" - sdkErrors "cosmossdk.io/errors" "github.com/KYVENetwork/chain/x/delegation/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -23,20 +21,11 @@ func (k msgServer) WithdrawRewards( return nil, sdkErrors.Wrapf(types.ErrNotADelegator, "%s does not delegate to %s", msg.Creator, msg.Staker) } - // Withdraw all rewards of the sender. - reward := k.f1WithdrawRewards(ctx, msg.Staker, msg.Creator) - - // Transfer reward $KYVE from this module to sender. - if err := util.TransferFromModuleToAddress(k.bankKeeper, ctx, types.ModuleName, msg.Creator, reward); err != nil { + // Withdraw all rewards of the sender and send them back + _, err := k.performWithdrawal(ctx, msg.Staker, msg.Creator) + if err != nil { return nil, err } - // Emit a delegation event. - _ = ctx.EventManager().EmitTypedEvent(&types.EventWithdrawRewards{ - Address: msg.Creator, - Staker: msg.Staker, - Amount: reward, - }) - return &types.MsgWithdrawRewardsResponse{}, nil } diff --git a/x/delegation/keeper/msg_server_withdraw_rewards_test.go b/x/delegation/keeper/msg_server_withdraw_rewards_test.go index 1d32e1fb..1f3f902e 100644 --- a/x/delegation/keeper/msg_server_withdraw_rewards_test.go +++ b/x/delegation/keeper/msg_server_withdraw_rewards_test.go @@ -2,14 +2,15 @@ package keeper_test import ( "cosmossdk.io/math" + i "github.com/KYVENetwork/chain/testutil/integration" + "github.com/KYVENetwork/chain/x/delegation/types" funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" stakerstypes "github.com/KYVENetwork/chain/x/stakers/types" + sdk "github.com/cosmos/cosmos-sdk/types" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" - - i "github.com/KYVENetwork/chain/testutil/integration" - "github.com/KYVENetwork/chain/x/delegation/types" ) /* @@ -21,6 +22,9 @@ TEST CASES - msg_server_withdraw_rewards.go * Test invalid payouts to delegators * Withdraw rewards which are zero * Withdraw rewards with multiple slashes +* Payout rewards with multiple denoms +* Payout mixed rewards multiple times and multiple delegation steps +* Withdraw multiple denoms, one after the other */ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { @@ -91,7 +95,7 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { // Alice: 100 // Dummy0: 10 // Dummy1: 0 - PayoutRewards(s, i.ALICE, 20*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(20*i.KYVE)))) // ASSERT delegationModuleBalanceAfter := s.GetBalanceFromModule(types.ModuleName) @@ -100,9 +104,9 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { Expect(delegationModuleBalanceAfter).To(Equal(delegationModuleBalanceBefore + 20*i.KYVE)) Expect(fundersModuleBalanceAfter).To(Equal(fundersModuleBalanceBefore - 20*i.KYVE)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(6666666666))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1])).To(Equal(uint64(6666666666))) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[2])).To(Equal(uint64(6666666666))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(6666666666))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(6666666666))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[2]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(6666666666))) s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ Creator: i.DUMMY[0], @@ -164,9 +168,9 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { // ACT // not enough balance in pool module - err1 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.ALICE, 20000*i.KYVE, pooltypes.ModuleName) + err1 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(20000*i.KYVE))), pooltypes.ModuleName) // staker does not exist - err2 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.DUMMY[20], 1*i.KYVE, pooltypes.ModuleName) + err2 := s.App().DelegationKeeper.PayoutRewards(s.Ctx(), i.DUMMY[20], sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(1*i.KYVE))), pooltypes.ModuleName) // ASSERT Expect(err1).To(HaveOccurred()) @@ -183,7 +187,7 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { startBalance := s.GetBalanceFromAddress(i.DUMMY[0]) // ACT - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ Creator: i.DUMMY[0], @@ -192,7 +196,7 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { // ASSERT Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(startBalance)) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) }) It("Withdraw rewards with multiple slashes", func() { @@ -211,22 +215,290 @@ var _ = Describe("msg_server_withdraw_rewards.go", Ordered, func() { // Slash 50% s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) - PayoutRewards(s, i.ALICE, 5*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(5*i.KYVE)))) // Slash 50% again s.App().DelegationKeeper.SlashDelegators(s.Ctx(), 0, i.ALICE, types.SLASH_TYPE_UPLOAD) - PayoutRewards(s, i.ALICE, 5*i.KYVE) + PayoutRewards(s, i.ALICE, sdk.NewCoins(sdk.NewInt64Coin(globalTypes.Denom, int64(5*i.KYVE)))) s.PerformValidityChecks() // ASSERT - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(10 * i.KYVE)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).AmountOf(globalTypes.Denom).Uint64()).To(Equal(10 * i.KYVE)) s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ Creator: i.DUMMY[0], Staker: i.ALICE, }) - Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(Equal(uint64(0))) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0])).To(BeEmpty()) Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(startBalance + 10*i.KYVE)) }) + + It("Payout rewards with multiple denoms", func() { + mintErr1 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "acoin") + Expect(mintErr1).To(BeNil()) + + mintErr2 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "bcoin") + Expect(mintErr2).To(BeNil()) + + // ARRANGE + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + Amount: 10 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[1], + Staker: i.ALICE, + Amount: 10 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + Amount: 10 * i.KYVE, + }) + + Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(990 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(990 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[2])).To(Equal(990 * i.KYVE)) + + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal(aliceSelfDelegation + 30*i.KYVE)) + + delegationModuleBalanceBefore := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceBefore := s.GetCoinsFromModule(pooltypes.ModuleName) + s.PerformValidityChecks() + + // ACT + payoutCoins := sdk.NewCoins( + sdk.NewCoin("acoin", math.NewInt(10*1_000_000)), + sdk.NewCoin("bcoin", math.NewInt(5*1_000_000)), + ) + PayoutRewards(s, i.ALICE, payoutCoins) + + // ASSERT + delegationModuleBalanceAfter := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceAfter := s.GetCoinsFromModule(pooltypes.ModuleName) + + Expect(delegationModuleBalanceAfter).To(Equal(delegationModuleBalanceBefore.Add(payoutCoins...))) + Expect(poolsModuleBalanceAfter).To(Equal(poolsModuleBalanceBefore.Sub(payoutCoins...))) + + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).String()).To(Equal("3333333acoin,1666666bcoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).String()).To(Equal("3333333acoin,1666666bcoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[2]).String()).To(Equal("3333333acoin,1666666bcoin")) + + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + }) + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[1], + Staker: i.ALICE, + }) + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + }) + + Expect(s.GetCoinsFromAddress(i.DUMMY[0]).String()).To(Equal("3333333acoin,1666666bcoin,990000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[1]).String()).To(Equal("3333333acoin,1666666bcoin,990000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[2]).String()).To(Equal("3333333acoin,1666666bcoin,990000000000tkyve")) + Expect(s.GetCoinsFromModule(types.ModuleName).String()).To(Equal("1acoin,2bcoin,30000000000tkyve")) + }) + + It("Payout mixed rewards multiple times and multiple delegation steps", func() { + mintErr1 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "acoin") + Expect(mintErr1).To(BeNil()) + + mintErr2 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "bcoin") + Expect(mintErr2).To(BeNil()) + + mintErr3 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "ccoin") + Expect(mintErr3).To(BeNil()) + + // ARRANGE + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + Amount: 20 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[1], + Staker: i.ALICE, + Amount: 5 * i.KYVE, + }) + + Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(980 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(995 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[2])).To(Equal(1000 * i.KYVE)) + + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal(aliceSelfDelegation + 25*i.KYVE)) + + delegationModuleBalanceBefore := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceBefore := s.GetCoinsFromModule(pooltypes.ModuleName) + s.PerformValidityChecks() + + // ACT + payoutCoins1 := sdk.NewCoins( + sdk.NewCoin("acoin", math.NewInt(10*1_000_000)), + sdk.NewCoin("bcoin", math.NewInt(5*1_000_000)), + ) + PayoutRewards(s, i.ALICE, payoutCoins1) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + Amount: 3 * i.KYVE, + }) + + payoutCoins2 := sdk.NewCoins( + sdk.NewCoin("bcoin", math.NewInt(8*1_000_000)), + sdk.NewCoin("ccoin", math.NewInt(7*1_000_000)), + ) + PayoutRewards(s, i.ALICE, payoutCoins2) + + // ASSERT + delegationModuleBalanceAfter := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceAfter := s.GetCoinsFromModule(pooltypes.ModuleName) + + Expect(delegationModuleBalanceAfter).To(Equal( + delegationModuleBalanceBefore.Add(payoutCoins1.Add(payoutCoins2...).Add(sdk.NewInt64Coin(globalTypes.Denom, int64(3*i.KYVE)))...)), + ) + Expect(poolsModuleBalanceAfter).To(Equal(poolsModuleBalanceBefore.Sub(payoutCoins1.Add(payoutCoins2...)...))) + + // Calculate outstanding rewards + // phase1: + // reward: 10_000_000 acoin, 5_000_000 bcoin + // delegation_shares: d0: 20, d1: 5 + // => d0: 20/25 * 10_000_000 = 8_000_000 acoin; 20/25 * 5_000_000 = 4_000_000 bcoin + // => d1: 5/25 * 10_000_000 = 2_000_000 acoin; 5/25 * 5_000_000 = 1_000_000 bcoin + // phase2: + // reward: 8_000_000 bcoin, 7_000_000 ccoin + // delegation_shares: d0: 20, d1: 5 d2: 3 + // => d0: 20/28 * 8_000_000 = 5_714_285 bcoin; 20/28 * 7_000_000 = 5_000_000 ccoin + // => d1: 5/28 * 8_000_000 = 1_428_571 bcoin; 5/28 * 7_000_000 = 1_250_000 ccoin + // => d2: 3/28 * 8_000_000 = 857_142 bcoin; 3/28 * 7_000_000 = 750_000 ccoin + // SUM: d0: 8_000_000 acoin, 9_714_285 bcoin, 5_000_000 ccoin, + // SUM: d1: 2_000_000 acoin, 2_428_571 bcoin, 1_250_000 ccoin + // SUM: d2: 0 acoin, 857_142 bcoin, 750_000 ccoin + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).String()).To(Equal("8000000acoin,9714285bcoin,5000000ccoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).String()).To(Equal("2000000acoin,2428571bcoin,1250000ccoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[2]).String()).To(Equal("857142bcoin,750000ccoin")) + + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + }) + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[1], + Staker: i.ALICE, + }) + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + }) + + Expect(s.GetCoinsFromAddress(i.DUMMY[0]).String()).To(Equal("8000000acoin,9714285bcoin,5000000ccoin,980000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[1]).String()).To(Equal("2000000acoin,2428571bcoin,1250000ccoin,995000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[2]).String()).To(Equal("857142bcoin,750000ccoin,997000000000tkyve")) + Expect(s.GetCoinsFromModule(types.ModuleName).String()).To(Equal("2bcoin,28000000000tkyve")) + }) + + It("Withdraw multiple denoms, one after the other", func() { + mintErr1 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "acoin") + Expect(mintErr1).To(BeNil()) + + mintErr2 := s.MintDenomToModule(pooltypes.ModuleName, 1000*1_000_000, "bcoin") + Expect(mintErr2).To(BeNil()) + + // ARRANGE + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + Amount: 20 * i.KYVE, + }) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[1], + Staker: i.ALICE, + Amount: 5 * i.KYVE, + }) + + Expect(s.GetBalanceFromAddress(i.DUMMY[0])).To(Equal(980 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[1])).To(Equal(995 * i.KYVE)) + Expect(s.GetBalanceFromAddress(i.DUMMY[2])).To(Equal(1000 * i.KYVE)) + + Expect(s.App().DelegationKeeper.GetDelegationAmount(s.Ctx(), i.ALICE)).To(Equal(aliceSelfDelegation + 25*i.KYVE)) + + delegationModuleBalanceBefore := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceBefore := s.GetCoinsFromModule(pooltypes.ModuleName) + s.PerformValidityChecks() + + // ACT + payoutCoins1 := sdk.NewCoins( + sdk.NewCoin("acoin", math.NewInt(10*1_000_000)), + ) + PayoutRewards(s, i.ALICE, payoutCoins1) + + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[0], + Staker: i.ALICE, + }) + + s.RunTxDelegatorSuccess(&types.MsgDelegate{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + Amount: 10 * i.KYVE, + }) + + payoutCoins2 := sdk.NewCoins( + sdk.NewCoin("bcoin", math.NewInt(8*1_000_000)), + ) + PayoutRewards(s, i.ALICE, payoutCoins2) + + s.RunTxDelegatorSuccess(&types.MsgWithdrawRewards{ + Creator: i.DUMMY[2], + Staker: i.ALICE, + }) + + // ASSERT + delegationModuleBalanceAfter := s.GetCoinsFromModule(types.ModuleName) + poolsModuleBalanceAfter := s.GetCoinsFromModule(pooltypes.ModuleName) + + compare := delegationModuleBalanceBefore.Add(payoutCoins1...) + compare = compare.Add(payoutCoins2...) + compare = compare.Add(sdk.NewInt64Coin(globalTypes.Denom, int64(10*i.KYVE))) + compare = compare.Sub(sdk.NewInt64Coin("acoin", 8_000_000)) + compare = compare.Sub(sdk.NewInt64Coin("bcoin", 2_285_714)) + Expect(delegationModuleBalanceAfter).To(Equal(compare)) + Expect(poolsModuleBalanceAfter).To(Equal(poolsModuleBalanceBefore.Sub(payoutCoins1.Add(payoutCoins2...)...))) + + // Calculate outstanding rewards + // phase1: + // reward: 10_000_000 acoin + // delegation_shares: d0: 20, d1: 5 + // => d0: 20/25 * 10_000_000 = 8_000_000 acoin + // => d1: 5/25 * 10_000_000 = 2_000_000 acoin + // d0: withdraw rewards (-8_000_000 acoin) + // phase2: + // reward: 8_000_000 bcoin + // delegation_shares: d0: 20, d1: 5 d2: 10 + // => d0: 20/35 * 8_000_000 = 4_571_428 bcoin + // => d1: 5/35 * 8_000_000 = 1_142_857 bcoin + // => d2: 10/35 * 8_000_000 = 2_285_714 bcoin + // d2: withdraw rewards (-2_285_714 bcoin) + // SUM: d0: 4_571_428 bcoin + // SUM: d1: 2_000_000 acoin, 1_142_857 bcoin + // SUM: d2: 0 + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[0]).String()).To(Equal("4571428bcoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[1]).String()).To(Equal("2000000acoin,1142857bcoin")) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.ALICE, i.DUMMY[2]).String()).To(Equal("")) + + Expect(s.GetCoinsFromAddress(i.DUMMY[0]).String()).To(Equal("8000000acoin,980000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[1]).String()).To(Equal("995000000000tkyve")) + Expect(s.GetCoinsFromAddress(i.DUMMY[2]).String()).To(Equal("2285714bcoin,990000000000tkyve")) + Expect(s.GetCoinsFromModule(types.ModuleName).String()).To(Equal("2000000acoin,5714286bcoin,35000000000tkyve")) + }) }) diff --git a/x/delegation/spec/01_concepts.md b/x/delegation/spec/01_concepts.md index 061e6caa..cfd351af 100644 --- a/x/delegation/spec/01_concepts.md +++ b/x/delegation/spec/01_concepts.md @@ -28,7 +28,7 @@ reward would cost an outrageous amount of gas. We have turned to the itself, payouts of rewards, and slashing events. The main idea is that if there is no change to delegation distribution (in -other words, no new delegations or undelegations), there is no need to payout +other words, no new delegations or undelegations), there is no need to pay out rewards. When users want to withdraw their rewards or update their delegation amount, their rewards are calculated and correctly distributed. diff --git a/x/delegation/spec/02_state.md b/x/delegation/spec/02_state.md index 0f2164d8..b7104420 100644 --- a/x/delegation/spec/02_state.md +++ b/x/delegation/spec/02_state.md @@ -20,15 +20,15 @@ of the f1-index. It exists as long as the staker has at least `1ukyve` delegatio ```go type DelegationData struct { - Staker string - // F1 - CurrentRewards uint64 - TotalDelegation uint64 - LatestIndexK uint64 - // delegator_count the amount of different addresses delegating to the staker - DelegatorCount uint64 - // latest_index_was_undelegation helps indicates when an entry can be deleted - LatestIndexWasUndelegation bool + // Every staker has one DelegationData + Staker string + CurrentRewards github_com_cosmos_cosmos_sdk_types.Coins + TotalDelegation uint64 + LatestIndexK uint64 + // delegator_count the amount of different addresses delegating to the staker + DelegatorCount uint64 + // latest_index_was_undelegation helps indicates when an entry can be deleted + LatestIndexWasUndelegation bool } ``` diff --git a/x/delegation/spec/07_exported.md b/x/delegation/spec/07_exported.md index 7ae0aa21..1cace730 100644 --- a/x/delegation/spec/07_exported.md +++ b/x/delegation/spec/07_exported.md @@ -5,8 +5,7 @@ order: 7 # Exported The `x/delegation` module exports the following functions, which can be used -outside the module. These functions will not return an error, as everything is -handled internally. +outside the module. ```go type DelegationKeeper interface { @@ -14,6 +13,7 @@ type DelegationKeeper interface { // GetDelegationAmount returns the sum of all delegations for a specific staker. // If the staker does not exist, it returns zero as the staker has zero delegations GetDelegationAmount(ctx sdk.Context, staker string) uint64 + // GetDelegationAmountOfDelegator returns the amount of how many $KYVE `delegatorAddress` // has delegated to `stakerAddress`. If one of the addresses does not exist, it returns zero. GetDelegationAmountOfDelegator(ctx sdk.Context, stakerAddress string, delegatorAddress string) uint64 @@ -22,12 +22,16 @@ type DelegationKeeper interface { // to stakers that are participating in the given pool GetDelegationOfPool(ctx sdk.Context, poolId uint64) uint64 - // PayoutRewards transfers `amount` $nKYVE from the `payerModuleName`-module to the delegation module. + // GetTotalAndHighestDelegationOfPool returns the total delegation amount of all validators in the given pool and + // the highest total delegation amount of a single validator in a pool + GetTotalAndHighestDelegationOfPool(ctx sdk.Context, poolId uint64) (totalDelegation, highestDelegation uint64) + + // PayoutRewards transfers `amount` 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. - // 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 + // If the staker has no delegators or the module to module transfer fails, the method fails and + // returns an error. + PayoutRewards(ctx sdk.Context, staker string, amount sdk.Coins, payerModuleName string) error // SlashDelegators reduces the delegation of all delegators of `staker` by fraction // and transfers the amount to the Treasury. @@ -35,7 +39,7 @@ type DelegationKeeper interface { // GetOutstandingRewards calculates the current rewards a delegator has collected for // the given staker. - GetOutstandingRewards(ctx sdk.Context, staker string, delegator string) uint64 + GetOutstandingRewards(ctx sdk.Context, staker string, delegator string) sdk.Coins } ``` diff --git a/x/delegation/types/delegation.pb.go b/x/delegation/types/delegation.pb.go index dd8ce378..ae6432e9 100644 --- a/x/delegation/types/delegation.pb.go +++ b/x/delegation/types/delegation.pb.go @@ -6,6 +6,9 @@ package types import ( cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -144,7 +147,7 @@ type DelegationEntry struct { // k_index is the of the period this entry ends KIndex uint64 `protobuf:"varint,2,opt,name=k_index,json=kIndex,proto3" json:"k_index,omitempty"` // value is the quotient of collected rewards and total stake according to F1-distribution - Value cosmossdk_io_math.LegacyDec `protobuf:"bytes,3,opt,name=value,proto3,customtype=cosmossdk.io/math.LegacyDec" json:"value"` + Value github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,3,rep,name=value,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"value"` } func (m *DelegationEntry) Reset() { *m = DelegationEntry{} } @@ -194,12 +197,19 @@ func (m *DelegationEntry) GetKIndex() uint64 { return 0 } +func (m *DelegationEntry) GetValue() github_com_cosmos_cosmos_sdk_types.DecCoins { + if m != nil { + return m.Value + } + return nil +} + // DelegationPoolData stores general delegation information for every staker type DelegationData struct { // Every staker has one DelegationData Staker string `protobuf:"bytes,1,opt,name=staker,proto3" json:"staker,omitempty"` // current_rewards ... - CurrentRewards uint64 `protobuf:"varint,2,opt,name=current_rewards,json=currentRewards,proto3" json:"current_rewards,omitempty"` + CurrentRewards github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,2,rep,name=current_rewards,json=currentRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"current_rewards"` // total_delegation ... TotalDelegation uint64 `protobuf:"varint,3,opt,name=total_delegation,json=totalDelegation,proto3" json:"total_delegation,omitempty"` // latest_index_k ... @@ -250,11 +260,11 @@ func (m *DelegationData) GetStaker() string { return "" } -func (m *DelegationData) GetCurrentRewards() uint64 { +func (m *DelegationData) GetCurrentRewards() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.CurrentRewards } - return 0 + return nil } func (m *DelegationData) GetTotalDelegation() uint64 { @@ -552,49 +562,55 @@ func init() { } var fileDescriptor_e07f10cb3da486ac = []byte{ - // 664 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0x4d, 0x4f, 0xdb, 0x40, - 0x10, 0x8d, 0x03, 0x04, 0x3c, 0x82, 0x24, 0xdd, 0xd2, 0x10, 0x85, 0x62, 0x90, 0x69, 0xd5, 0xb4, - 0x87, 0x58, 0xa8, 0xa7, 0x9e, 0xaa, 0x80, 0x5d, 0x11, 0x41, 0x81, 0xe6, 0x83, 0x8a, 0x5e, 0xac, - 0xc5, 0xde, 0x26, 0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, 0xd3, 0x8f, 0x77, 0xe6, 0xef, 0xe3, 0x2d, 0x41, 0x6e, 0xe2, 0x36, 0x93, 0x08, 0x6d, 0xc2, - 0x92, 0x15, 0x10, 0xce, 0x6c, 0x32, 0xa7, 0x4f, 0x12, 0xbb, 0x17, 0xef, 0xc0, 0xb6, 0xd3, 0x27, - 0xea, 0x2e, 0x00, 0x97, 0xd5, 0x62, 0x98, 0x11, 0xb4, 0x0a, 0xb2, 0x47, 0x07, 0xa6, 0x28, 0x6d, - 0xc1, 0xa3, 0x83, 0xd8, 0x8f, 0x35, 0x80, 0x9e, 0xd3, 0xed, 0x4d, 0x78, 0x25, 0x8f, 0x10, 0x9e, - 0x56, 0x3b, 0xb0, 0xdc, 0x24, 0xe3, 0x61, 0x77, 0x28, 0xf5, 0x6c, 0x3a, 0xf0, 0x51, 0x19, 0xe6, - 0xb1, 0x6d, 0x07, 0x24, 0x0c, 0x13, 0xe3, 0xef, 0xc2, 0x09, 0x81, 0x36, 0x66, 0x24, 0xe9, 0x99, - 0x0a, 0xd4, 0x31, 0x23, 0xcf, 0x3e, 0x80, 0xcc, 0xf7, 0xd7, 0x1e, 0x9e, 0x11, 0x54, 0x81, 0x52, - 0x6b, 0xbf, 0xde, 0xda, 0x35, 0xdb, 0x27, 0x47, 0x86, 0xd9, 0x39, 0x68, 0x1d, 0x19, 0x3b, 0x8d, - 0x57, 0x0d, 0x43, 0x2f, 0x66, 0x50, 0x09, 0x90, 0x90, 0x6b, 0x37, 0x5e, 0x1b, 0x87, 0x9d, 0x76, - 0x51, 0x42, 0xf7, 0xa1, 0x20, 0xe0, 0xc7, 0x87, 0x6d, 0xa3, 0x98, 0x45, 0x0f, 0xe0, 0x9e, 0xd8, - 0xe8, 0x68, 0xff, 0xb0, 0xae, 0x17, 0x67, 0x2a, 0xb3, 0x5f, 0x7e, 0x28, 0x99, 0xed, 0xc6, 0xe5, - 0x8d, 0x22, 0x5d, 0xdd, 0x28, 0xd2, 0xef, 0x1b, 0x45, 0xfa, 0x76, 0xab, 0x64, 0xae, 0x6e, 0x95, - 0xcc, 0xcf, 0x5b, 0x25, 0xf3, 0x4e, 0xeb, 0x3a, 0xac, 0x17, 0x9d, 0xd6, 0x2c, 0xda, 0xd7, 0xf6, - 0x4e, 0x8e, 0x8d, 0x03, 0xc2, 0x06, 0x34, 0x70, 0x35, 0xab, 0x87, 0x1d, 0x5f, 0xbb, 0x10, 0x9f, - 0x37, 0x36, 0x3c, 0x23, 0xe1, 0x69, 0x8e, 0xbf, 0x51, 0xcf, 0xff, 0x04, 0x00, 0x00, 0xff, 0xff, - 0x71, 0xb7, 0xbb, 0xf9, 0xfe, 0x04, 0x00, 0x00, + // 764 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x4f, 0xdb, 0x48, + 0x14, 0x8e, 0x13, 0x08, 0xe4, 0x2d, 0x24, 0x61, 0x96, 0x0d, 0xd9, 0x00, 0x26, 0x0a, 0xbb, 0xda, + 0x2c, 0xab, 0xb5, 0xc5, 0xae, 0x56, 0xda, 0x5b, 0x15, 0xe2, 0x54, 0x44, 0x50, 0xa0, 0xf9, 0x41, + 0x45, 0x2f, 0xd6, 0xc4, 0x9e, 0x26, 0x96, 0x1d, 0x0f, 0xb5, 0x27, 0x84, 0x1c, 0xab, 0x5e, 0x7a, + 0xec, 0xbf, 0x50, 0xf5, 0x52, 0xf5, 0xc4, 0x9f, 0xc1, 0x91, 0x63, 0xd5, 0x03, 0x45, 0x70, 0xe8, + 0xbf, 0x51, 0x65, 0xec, 0x24, 0x93, 0xaa, 0x48, 0xed, 0x25, 0xf1, 0xfb, 0xe6, 0xf9, 0x7d, 0xdf, + 0x7c, 0xef, 0x3d, 0x43, 0xd1, 0x1e, 0x9c, 0x11, 0xd5, 0x24, 0x0e, 0x69, 0x63, 0x66, 0x51, 0x57, + 0x3d, 0xdb, 0x6e, 0x11, 0x86, 0x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x30, 0xd2, 0x37, 0x6d, 0xc5, 0xa2, 0x6a, 0x17, 0xb3, 0x8e, 0xb2, 0x4f, 0xda, 0xd8, 0x18, 0x68, + 0xc4, 0xa8, 0x8d, 0x5f, 0x2a, 0xbc, 0x91, 0x20, 0x23, 0xca, 0x7a, 0xdc, 0x23, 0x3d, 0x12, 0x8c, + 0xe8, 0x32, 0xcc, 0x06, 0x94, 0x12, 0xa7, 0x0c, 0x02, 0x41, 0x62, 0xf4, 0xfe, 0x15, 0x8a, 0x7d, + 0xbd, 0x42, 0x19, 0x88, 0x4f, 0x6d, 0x48, 0x18, 0xa1, 0x4d, 0x58, 0x34, 0x3c, 0xc2, 0x99, 0x75, + 0x66, 0x75, 0x49, 0x68, 0xf7, 0xc2, 0x08, 0x6c, 0x58, 0x5d, 0x52, 0xd8, 0x05, 0xe0, 0xb2, 0xea, + 0x0c, 0x33, 0x82, 0x56, 0x21, 0xe1, 0xd0, 0xbe, 0x2e, 0x4a, 0x9b, 0x77, 0x68, 0x3f, 0xf0, 0x63, + 0x1d, 0xa0, 0x63, 0xb5, 0x3b, 0x53, 0x5e, 0x25, 0x86, 0x08, 0x3f, 0x2e, 0x34, 0x61, 0xb9, 0x46, + 0x26, 0x97, 0x2d, 0x53, 0xea, 0x98, 0xb4, 0xef, 0xa2, 0x2c, 0xcc, 0x61, 0xd3, 0xf4, 0x88, 0xef, + 0x87, 0xc6, 0x8f, 0xc2, 0x29, 0x81, 0x26, 0x66, 0x24, 0xac, 0x39, 0x16, 0xa8, 0x61, 0x46, 0xb6, + 0x9e, 0x43, 0x82, 0xf7, 0xaf, 0x31, 0x38, 0x25, 0x28, 0x07, 0x99, 0xfa, 0x7e, 0xa9, 0xbe, 0xab, + 0x37, 0x4e, 0x8e, 0x2a, 0x7a, 0xf3, 0xa0, 0x7e, 0x54, 0x29, 0x57, 0x1f, 0x56, 0x2b, 0x5a, 0x3a, + 0x82, 0x32, 0x80, 0x84, 0xb3, 0x46, 0xf5, 0x51, 0xe5, 0xb0, 0xd9, 0x48, 0x4b, 0xe8, 0x67, 0x48, + 0x09, 0xf8, 0xf1, 0x61, 0xa3, 0x92, 0x8e, 0xa2, 0x5f, 0x60, 0x49, 0x2c, 0x74, 0xb4, 0x7f, 0x58, + 0xd2, 0xd2, 0xb1, 0xdc, 0xcc, 0xab, 0xb7, 0x72, 0x64, 0xa7, 0x7a, 0x79, 0x2b, 0x4b, 0x57, 0xb7, + 0xb2, 0x74, 0x73, 0x2b, 0x4b, 0xaf, 0xef, 0xe4, 0xc8, 0xd5, 0x9d, 0x1c, 0xf9, 0x70, 0x27, 0x47, + 0x9e, 0xaa, 0xc2, 0x4e, 0xed, 0x9d, 0x1c, 0x57, 0x0e, 0x08, 0xeb, 0x53, 0xcf, 0x56, 0x8d, 0x0e, + 0xb6, 0x5c, 0xf5, 0x5c, 0xfc, 0x2e, 0xf3, 0x05, 0x6b, 0xc5, 0xf9, 0x97, 0xf2, 0xdf, 0x2f, 0x01, + 0x00, 0x00, 0xff, 0xff, 0x33, 0x14, 0xb7, 0x80, 0xb7, 0x05, 0x00, 0x00, } func (m *Delegator) Marshal() (dAtA []byte, err error) { @@ -664,16 +680,20 @@ func (m *DelegationEntry) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size := m.Value.Size() - i -= size - if _, err := m.Value.MarshalTo(dAtA[i:]); err != nil { - return 0, err + if len(m.Value) > 0 { + for iNdEx := len(m.Value) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Value[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a } - i = encodeVarintDelegation(dAtA, i, uint64(size)) } - i-- - dAtA[i] = 0x1a if m.KIndex != 0 { i = encodeVarintDelegation(dAtA, i, uint64(m.KIndex)) i-- @@ -734,10 +754,19 @@ func (m *DelegationData) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x18 } - if m.CurrentRewards != 0 { - i = encodeVarintDelegation(dAtA, i, uint64(m.CurrentRewards)) - i-- - dAtA[i] = 0x10 + if len(m.CurrentRewards) > 0 { + for iNdEx := len(m.CurrentRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CurrentRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } } if len(m.Staker) > 0 { i -= len(m.Staker) @@ -961,8 +990,12 @@ func (m *DelegationEntry) Size() (n int) { if m.KIndex != 0 { n += 1 + sovDelegation(uint64(m.KIndex)) } - l = m.Value.Size() - n += 1 + l + sovDelegation(uint64(l)) + if len(m.Value) > 0 { + for _, e := range m.Value { + l = e.Size() + n += 1 + l + sovDelegation(uint64(l)) + } + } return n } @@ -976,8 +1009,11 @@ func (m *DelegationData) Size() (n int) { if l > 0 { n += 1 + l + sovDelegation(uint64(l)) } - if m.CurrentRewards != 0 { - n += 1 + sovDelegation(uint64(m.CurrentRewards)) + if len(m.CurrentRewards) > 0 { + for _, e := range m.CurrentRewards { + l = e.Size() + n += 1 + l + sovDelegation(uint64(l)) + } } if m.TotalDelegation != 0 { n += 1 + sovDelegation(uint64(m.TotalDelegation)) @@ -1311,7 +1347,7 @@ func (m *DelegationEntry) Unmarshal(dAtA []byte) error { if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -1321,23 +1357,23 @@ func (m *DelegationEntry) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthDelegation } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthDelegation } if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Value.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + m.Value = append(m.Value, types.DecCoin{}) + if err := m.Value[len(m.Value)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex @@ -1424,10 +1460,10 @@ func (m *DelegationData) Unmarshal(dAtA []byte) error { m.Staker = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewards", wireType) } - m.CurrentRewards = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -1437,11 +1473,26 @@ func (m *DelegationData) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CurrentRewards |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthDelegation + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDelegation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentRewards = append(m.CurrentRewards, types.Coin{}) + if err := m.CurrentRewards[len(m.CurrentRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 3: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field TotalDelegation", wireType) diff --git a/x/delegation/types/events.pb.go b/x/delegation/types/events.pb.go index b2763a80..0d74c7fe 100644 --- a/x/delegation/types/events.pb.go +++ b/x/delegation/types/events.pb.go @@ -5,6 +5,9 @@ package types import ( fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" io "io" @@ -375,7 +378,7 @@ type EventWithdrawRewards struct { // staker is the account address of the protocol node the users withdraws from. Staker string `protobuf:"bytes,2,opt,name=staker,proto3" json:"staker,omitempty"` // amount ... - Amount uint64 `protobuf:"varint,3,opt,name=amount,proto3" json:"amount,omitempty"` + Amount github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,3,rep,name=amount,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"amount"` } func (m *EventWithdrawRewards) Reset() { *m = EventWithdrawRewards{} } @@ -425,11 +428,11 @@ func (m *EventWithdrawRewards) GetStaker() string { return "" } -func (m *EventWithdrawRewards) GetAmount() uint64 { +func (m *EventWithdrawRewards) GetAmount() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.Amount } - return 0 + return nil } // EventSlash is an event emitted when a protocol node is slashed. @@ -521,38 +524,43 @@ func init() { } var fileDescriptor_d01988a9108a2e89 = []byte{ - // 486 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x93, 0xc1, 0x6e, 0xd3, 0x40, - 0x14, 0x45, 0x33, 0x10, 0xa5, 0xf8, 0x55, 0x80, 0xb0, 0xaa, 0x36, 0xb4, 0x92, 0x53, 0x59, 0x2c, - 0xb2, 0xb2, 0xd5, 0xb2, 0x47, 0xa2, 0x4a, 0x17, 0x15, 0x12, 0x42, 0x0e, 0x05, 0x15, 0x16, 0x66, - 0xd2, 0x79, 0x24, 0x56, 0x6c, 0x8f, 0x65, 0xbf, 0xc4, 0x64, 0xc9, 0x1f, 0xb0, 0x64, 0xcd, 0x5f, - 0xf0, 0x07, 0x5d, 0x76, 0xc9, 0x0a, 0xa1, 0xe4, 0x47, 0xd0, 0xcc, 0xd8, 0x24, 0x45, 0x8a, 0xd4, - 0x4a, 0xd9, 0xcd, 0x9b, 0xb9, 0x3e, 0xf7, 0xda, 0xd7, 0x03, 0xcf, 0xc6, 0xb3, 0x29, 0xfa, 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0xfe, 0x97, 0xd5, 0x3b, - 0xaf, 0xec, 0x8b, 0x41, 0x4b, 0xdf, 0xf5, 0xe7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xab, 0xe2, - 0xab, 0xb6, 0x92, 0x04, 0x00, 0x00, + // 571 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x54, 0xc1, 0x6b, 0x13, 0x4f, + 0x14, 0xce, 0xfc, 0x1a, 0xd2, 0xdf, 0x4e, 0x50, 0x69, 0x28, 0x6d, 0xda, 0xc2, 0xa6, 0x04, 0x0f, + 0x41, 0x70, 0x87, 0x46, 0xbc, 0x0a, 0xc6, 0xf4, 0x50, 0x04, 0x91, 0x8d, 0x55, 0xaa, 0x87, 0x65, + 0x92, 0x19, 0x93, 0x25, 0xbb, 0xfb, 0x96, 0x9d, 0x49, 0xd6, 0x1c, 0xfd, 0x0f, 0x3c, 0x7a, 0xf6, + 0x24, 0x9e, 0xc4, 0x9b, 0xff, 0x41, 0x8f, 0x3d, 0x7a, 0x52, 0x49, 0x0e, 0xfe, 0x1b, 0x32, 0x33, + 0xbb, 0xc9, 0x56, 0x08, 0x58, 0xe9, 0x25, 0x99, 0x37, 0xef, 0xdb, 0xef, 0xfb, 0xde, 0xcc, 0x7b, + 0x83, 0x6f, 0x8f, 0x67, 0x53, 0x4e, 0x18, 0x0f, 0xf8, 0x90, 0x4a, 0x1f, 0x22, 0x32, 0x3d, 0xea, + 0x73, 0x49, 0x8f, 0x08, 0x9f, 0xf2, 0x48, 0x0a, 0x27, 0x4e, 0x40, 0x42, 0x6d, 0x57, 0xa1, 0x9c, + 0x15, 0xca, 0xc9, 0x50, 0xfb, 0x5b, 0x34, 0xf4, 0x23, 0x20, 0xfa, 0xd7, 0x60, 0xf7, 0xed, 0x01, + 0x88, 0x10, 0x04, 0xe9, 0x53, 0xc1, 0x97, 0x6c, 0x03, 0xf0, 0xa3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, 0x2d, 0xec, 0xd2, 0xc5, 0xc2, 0x2e, 0x7d, 0x5b, 0xd8, 0xa5, + 0x97, 0xa4, 0x50, 0xeb, 0xe3, 0xb3, 0xe7, 0xc7, 0x4f, 0xb8, 0x4c, 0x21, 0x19, 0x93, 0xc1, 0x88, + 0xfa, 0x11, 0x79, 0x53, 0x7c, 0x46, 0x74, 0xe1, 0xfd, 0x8a, 0x7e, 0x3e, 0xee, 0xfd, 0x0e, 0x00, + 0x00, 0xff, 0xff, 0x28, 0x77, 0xcc, 0xf2, 0x18, 0x05, 0x00, 0x00, } func (m *EventUpdateParams) Marshal() (dAtA []byte, err error) { @@ -805,10 +813,19 @@ func (m *EventWithdrawRewards) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Amount != 0 { - i = encodeVarintEvents(dAtA, i, uint64(m.Amount)) - i-- - dAtA[i] = 0x18 + if len(m.Amount) > 0 { + for iNdEx := len(m.Amount) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Amount[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvents(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } } if len(m.Staker) > 0 { i -= len(m.Staker) @@ -1001,8 +1018,11 @@ func (m *EventWithdrawRewards) Size() (n int) { if l > 0 { n += 1 + l + sovEvents(uint64(l)) } - if m.Amount != 0 { - n += 1 + sovEvents(uint64(m.Amount)) + if len(m.Amount) > 0 { + for _, e := range m.Amount { + l = e.Size() + n += 1 + l + sovEvents(uint64(l)) + } } return n } @@ -1860,10 +1880,10 @@ func (m *EventWithdrawRewards) Unmarshal(dAtA []byte) error { m.Staker = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 3: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Amount", wireType) } - m.Amount = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowEvents @@ -1873,11 +1893,26 @@ func (m *EventWithdrawRewards) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Amount |= uint64(b&0x7F) << shift + 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 + } + m.Amount = append(m.Amount, types.Coin{}) + if err := m.Amount[len(m.Amount)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipEvents(dAtA[iNdEx:]) diff --git a/x/query/keeper/grpc_account_assets.go b/x/query/keeper/grpc_account_assets.go index edf0b86c..84a47a9f 100644 --- a/x/query/keeper/grpc_account_assets.go +++ b/x/query/keeper/grpc_account_assets.go @@ -56,7 +56,7 @@ func (k Keeper) AccountAssets(goCtx context.Context, req *types.QueryAccountAsse staker := string(delegatorIterator.Key()[0:43]) response.ProtocolDelegation += k.delegationKeeper.GetDelegationAmountOfDelegator(ctx, staker, req.Address) - response.ProtocolRewards += k.delegationKeeper.GetOutstandingRewards(ctx, staker, req.Address) + response.ProtocolRewards.Add(k.delegationKeeper.GetOutstandingRewards(ctx, staker, req.Address)...) } // ====================================================== diff --git a/x/query/keeper/grpc_delegation_delegator.go b/x/query/keeper/grpc_delegation_delegator.go index 3af9f32a..47ddd2f0 100644 --- a/x/query/keeper/grpc_delegation_delegator.go +++ b/x/query/keeper/grpc_delegation_delegator.go @@ -22,7 +22,7 @@ func (k Keeper) Delegator(goCtx context.Context, req *types.QueryDelegatorReques response := types.QueryDelegatorResponse{} response.Delegator = &types.StakerDelegatorResponse{ Delegator: req.Delegator, - CurrentReward: k.delegationKeeper.GetOutstandingRewards(ctx, req.Staker, req.Delegator), + CurrentRewards: k.delegationKeeper.GetOutstandingRewards(ctx, req.Staker, req.Delegator), DelegationAmount: k.delegationKeeper.GetDelegationAmountOfDelegator(ctx, req.Staker, req.Delegator), Staker: req.Staker, } diff --git a/x/query/keeper/grpc_delegation_delegators_by_staker.go b/x/query/keeper/grpc_delegation_delegators_by_staker.go index faadf7c5..cee081cf 100644 --- a/x/query/keeper/grpc_delegation_delegators_by_staker.go +++ b/x/query/keeper/grpc_delegation_delegators_by_staker.go @@ -35,7 +35,7 @@ func (k Keeper) DelegatorsByStaker(goCtx context.Context, req *types.QueryDelega delegators = append(delegators, types.StakerDelegatorResponse{ Delegator: delegator.Delegator, - CurrentReward: k.delegationKeeper.GetOutstandingRewards(ctx, req.Staker, delegator.Delegator), + CurrentRewards: k.delegationKeeper.GetOutstandingRewards(ctx, req.Staker, delegator.Delegator), DelegationAmount: k.delegationKeeper.GetDelegationAmountOfDelegator(ctx, req.Staker, delegator.Delegator), Staker: req.Staker, }) diff --git a/x/query/keeper/grpc_delegation_stakers_by_delegator.go b/x/query/keeper/grpc_delegation_stakers_by_delegator.go index defd8774..ff91996c 100644 --- a/x/query/keeper/grpc_delegation_stakers_by_delegator.go +++ b/x/query/keeper/grpc_delegation_stakers_by_delegator.go @@ -32,7 +32,7 @@ func (k Keeper) StakersByDelegator(goCtx context.Context, req *types.QueryStaker stakers = append(stakers, types.DelegationForStakerResponse{ Staker: k.GetFullStaker(ctx, staker), - CurrentReward: k.delegationKeeper.GetOutstandingRewards(ctx, staker, req.Delegator), + CurrentRewards: k.delegationKeeper.GetOutstandingRewards(ctx, staker, req.Delegator), DelegationAmount: k.delegationKeeper.GetDelegationAmountOfDelegator(ctx, staker, req.Delegator), }) } diff --git a/x/query/types/account.pb.go b/x/query/types/account.pb.go index 89fcd5d2..7c589afe 100644 --- a/x/query/types/account.pb.go +++ b/x/query/types/account.pb.go @@ -6,7 +6,10 @@ package types import ( context "context" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -89,7 +92,7 @@ type QueryAccountAssetsResponse struct { // protocol_delegation_unbonding ProtocolDelegationUnbonding uint64 `protobuf:"varint,5,opt,name=protocol_delegation_unbonding,json=protocolDelegationUnbonding,proto3" json:"protocol_delegation_unbonding,omitempty"` // protocol_rewards ... - ProtocolRewards uint64 `protobuf:"varint,6,opt,name=protocol_rewards,json=protocolRewards,proto3" json:"protocol_rewards,omitempty"` + ProtocolRewards github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=protocol_rewards,json=protocolRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"protocol_rewards"` // protocol_funding ... ProtocolFunding uint64 `protobuf:"varint,7,opt,name=protocol_funding,json=protocolFunding,proto3" json:"protocol_funding,omitempty"` } @@ -162,11 +165,11 @@ func (m *QueryAccountAssetsResponse) GetProtocolDelegationUnbonding() uint64 { return 0 } -func (m *QueryAccountAssetsResponse) GetProtocolRewards() uint64 { +func (m *QueryAccountAssetsResponse) GetProtocolRewards() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { return m.ProtocolRewards } - return 0 + return nil } func (m *QueryAccountAssetsResponse) GetProtocolFunding() uint64 { @@ -674,63 +677,68 @@ func init() { func init() { proto.RegisterFile("kyve/query/v1beta1/account.proto", fileDescriptor_51ca316755261aec) } var fileDescriptor_51ca316755261aec = []byte{ - // 896 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0x41, 0x6f, 0x1b, 0x45, - 0x14, 0xce, 0x26, 0xc1, 0x15, 0x2f, 0x2d, 0xa5, 0x13, 0x54, 0x99, 0x0d, 0x5e, 0x47, 0x8b, 0xc0, - 0xa1, 0x82, 0x5d, 0xd9, 0x09, 0xa8, 0x25, 0x70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, - 0x98, 0xad, 0xcb, 0x40, 0x94, 0x82, 0x3b, 0x42, 0xc1, 0x2e, 0x6a, 0x2e, 0x52, 0x20, 0x87, 0xdd, - 0x4f, 0x62, 0xc6, 0x35, 0xde, 0x4f, 0x0c, 0xd8, 0x2c, 0x19, 0x32, 0xb4, 0xbb, 0x8c, 0x46, 0xc9, - 0x40, 0x9b, 0x7b, 0x97, 0x03, 0x29, 0xf6, 0xef, 0x0b, 0xf6, 0x7b, 0xa8, 0xb5, 0x88, 0xbd, 0x3e, - 0x97, 0x13, 0xfa, 0xed, 0x83, 0xa7, 0xe7, 0x96, 0xf1, 0xec, 0xdc, 0x32, 0xfe, 0x3e, 0xb7, 0x8c, - 0x9f, 0x2e, 0xac, 0x95, 0x67, 0x17, 0xd6, 0xca, 0x1f, 0x17, 0xd6, 0xca, 0xa3, 0x5b, 0x51, 0xcc, - 0x8f, 0x87, 0x5d, 0x27, 0xa0, 0x7d, 0xf7, 0xfe, 0xc3, 0x2f, 0x0f, 0x3f, 0x25, 0xfc, 0x8c, 0x66, - 0x27, 0x6e, 0x70, 0x8c, 0xe3, 0xd4, 0xfd, 0x4a, 0x6d, 0xc3, 0x47, 0x03, 0xc2, 0xba, 0x15, 0xf1, - 0x10, 0xef, 0xfe, 0x1b, 0x00, 0x00, 0xff, 0xff, 0xdd, 0x5b, 0x16, 0x72, 0xf8, 0x09, 0x00, 0x00, + // 962 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x55, 0xcd, 0x6f, 0x1b, 0x45, + 0x14, 0xcf, 0x26, 0xc1, 0x15, 0x2f, 0x2d, 0x25, 0x13, 0x54, 0xb9, 0x0e, 0xb1, 0xa3, 0x45, 0x90, + 0x10, 0xd1, 0x5d, 0xd9, 0x49, 0x51, 0x4b, 0xe0, 0x50, 0xe7, 0x83, 0x43, 0x01, 0x95, 0x0d, 0x20, + 0xb5, 0x17, 0x6b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7e, 0xa5, 0x98, 0x54, 0x86, 0x30, 0x05, + 0x37, 0x78, 0xf7, 0x00, 0x4a, 0xda, 0x3e, 0xb6, 0x2a, 0x75, 0x98, 0xef, 0x71, 0x9e, 0x98, 0x46, + 0xac, 0x14, 0x45, 0x6e, 0x62, 0x41, 0xc3, 0x7b, 0x9c, 0x27, 0x81, 0x82, 0xba, 0xdb, 0x50, 0xb3, + 0x09, 0x07, 0xe4, 0x62, 0x79, 0xa7, 0xab, 0x7d, 0xec, 0xc0, 0xea, 0x78, 0x6f, 0x23, 0x98, 0xc3, + 0x4a, 0x6a, 0xd9, 0x5b, 0x21, 0xe7, 0x49, 0xc4, 0x4f, 0x58, 0x8b, 0x30, 0x99, 0x52, 0x92, 0x4f, + 0xe1, 0xab, 0x45, 0x6c, 0xed, 0x80, 0x7b, 0x4c, 0xa6, 0xa7, 0xa6, 0x24, 0xcb, 0x76, 0xc4, 0x1d, + 0x13, 0x70, 0x4f, 0xc7, 0x43, 0x6b, 0x70, 0x15, 0x1f, 0x63, 0x9a, 0xe0, 0x76, 0x42, 0x5a, 0x22, + 0xe1, 0x52, 0x98, 0xe9, 0x78, 0x61, 0x60, 0x3e, 0xc8, 0xac, 0xee, 0x7d, 0x58, 0x1c, 0x49, 0x30, + 0x34, 0x59, 0x11, 0x96, 0xf9, 0x05, 0x3d, 0x98, 0xac, 0x5d, 0x2c, 0x09, 0xaa, 0xc1, 0x42, 0x87, + 0x32, 0x2a, 0x0e, 0x35, 0x44, 0x87, 0x07, 0x6d, 0xca, 0x00, 0x8d, 0xaf, 0x4a, 0x70, 0xd9, 0xae, + 0x0c, 0xfa, 0xd6, 0x81, 0x2b, 0x43, 0x6f, 0x01, 0xba, 0x51, 0x24, 0x78, 0xec, 0x5b, 0x53, 0xf1, + 0xfe, 0x2b, 0x5c, 0x97, 0xdd, 0xdd, 0xfa, 0xfc, 0xe7, 0xbf, 0xbe, 0x99, 0xf5, 0xd0, 0x1b, 0xfe, + 0xf8, 0xa7, 0xba, 0x85, 0x95, 0x8f, 0xff, 0xc8, 0x34, 0xf4, 0x33, 0xf4, 0x9b, 0x03, 0xcb, 0x13, + 0xee, 0x11, 0xb4, 0x3d, 0x8d, 0xc5, 0x84, 0xbb, 0xb0, 0xf2, 0xf6, 0xff, 0x73, 0x36, 0x82, 0x76, + 0x94, 0xa0, 0x77, 0xd0, 0xf6, 0x24, 0x41, 0x45, 0x4f, 0x8f, 0xad, 0xef, 0x47, 0x07, 0x16, 0x47, + 0x76, 0x13, 0xd5, 0xa7, 0x11, 0x1b, 0xb9, 0x02, 0x2a, 0x8d, 0x67, 0x71, 0x31, 0x0a, 0x6e, 0x2b, + 0x05, 0x9b, 0xa8, 0x3e, 0x49, 0x81, 0x5e, 0xf6, 0x56, 0x42, 0x85, 0xb4, 0x78, 0x3f, 0x76, 0x60, + 0xa9, 0x60, 0xc9, 0xd0, 0xe6, 0x34, 0x1a, 0x05, 0x0b, 0x5d, 0xd9, 0x7a, 0x36, 0x27, 0xc3, 0xfe, + 0x2d, 0xc5, 0x7e, 0x0b, 0x35, 0x26, 0xb1, 0xb7, 0xf7, 0xf2, 0x82, 0x7e, 0x73, 0xf7, 0xc9, 0x59, + 0xd5, 0x79, 0x7a, 0x56, 0x75, 0xfe, 0x3c, 0xab, 0x3a, 0x5f, 0x9f, 0x57, 0x67, 0x9e, 0x9e, 0x57, + 0x67, 0x7e, 0x39, 0xaf, 0xce, 0x3c, 0xd8, 0xb0, 0x9e, 0xed, 0xbb, 0xf7, 0x3f, 0xd9, 0xfb, 0x80, + 0xc8, 0x13, 0x9e, 0x1e, 0xf9, 0xe1, 0x21, 0xa6, 0xcc, 0xff, 0xd4, 0xa4, 0x51, 0xcf, 0x77, 0xbb, + 0xa4, 0x1e, 0xe2, 0xcd, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x1b, 0x46, 0x9a, 0x2c, 0x7d, 0x0a, + 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -984,10 +992,19 @@ func (m *QueryAccountAssetsResponse) MarshalToSizedBuffer(dAtA []byte) (int, err i-- dAtA[i] = 0x38 } - if m.ProtocolRewards != 0 { - i = encodeVarintAccount(dAtA, i, uint64(m.ProtocolRewards)) - i-- - dAtA[i] = 0x30 + if len(m.ProtocolRewards) > 0 { + for iNdEx := len(m.ProtocolRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.ProtocolRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintAccount(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } } if m.ProtocolDelegationUnbonding != 0 { i = encodeVarintAccount(dAtA, i, uint64(m.ProtocolDelegationUnbonding)) @@ -1410,8 +1427,11 @@ func (m *QueryAccountAssetsResponse) Size() (n int) { if m.ProtocolDelegationUnbonding != 0 { n += 1 + sovAccount(uint64(m.ProtocolDelegationUnbonding)) } - if m.ProtocolRewards != 0 { - n += 1 + sovAccount(uint64(m.ProtocolRewards)) + if len(m.ProtocolRewards) > 0 { + for _, e := range m.ProtocolRewards { + l = e.Size() + n += 1 + l + sovAccount(uint64(l)) + } } if m.ProtocolFunding != 0 { n += 1 + sovAccount(uint64(m.ProtocolFunding)) @@ -1777,10 +1797,10 @@ func (m *QueryAccountAssetsResponse) Unmarshal(dAtA []byte) error { } } case 6: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field ProtocolRewards", wireType) } - m.ProtocolRewards = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowAccount @@ -1790,11 +1810,26 @@ func (m *QueryAccountAssetsResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.ProtocolRewards |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthAccount + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthAccount + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ProtocolRewards = append(m.ProtocolRewards, types.Coin{}) + if err := m.ProtocolRewards[len(m.ProtocolRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex case 7: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field ProtocolFunding", wireType) diff --git a/x/query/types/delegation.pb.go b/x/query/types/delegation.pb.go index 0a35418a..841e6f3a 100644 --- a/x/query/types/delegation.pb.go +++ b/x/query/types/delegation.pb.go @@ -6,7 +6,10 @@ package types import ( context "context" fmt "fmt" + github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" + types "github.com/cosmos/cosmos-sdk/types" query "github.com/cosmos/cosmos-sdk/types/query" + _ "github.com/cosmos/cosmos-sdk/types/tx/amino" _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/cosmos/gogoproto/grpc" proto "github.com/cosmos/gogoproto/proto" @@ -135,8 +138,8 @@ func (m *QueryDelegatorResponse) GetDelegator() *StakerDelegatorResponse { type StakerDelegatorResponse struct { // delegator ... Delegator string `protobuf:"bytes,1,opt,name=delegator,proto3" json:"delegator,omitempty"` - // current_reward ... - CurrentReward uint64 `protobuf:"varint,2,opt,name=current_reward,json=currentReward,proto3" json:"current_reward,omitempty"` + // current_rewards ... + CurrentRewards github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=current_rewards,json=currentRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"current_rewards"` // delegation_amount ... DelegationAmount uint64 `protobuf:"varint,3,opt,name=delegation_amount,json=delegationAmount,proto3" json:"delegation_amount,omitempty"` // staker ... @@ -183,11 +186,11 @@ func (m *StakerDelegatorResponse) GetDelegator() string { return "" } -func (m *StakerDelegatorResponse) GetCurrentReward() uint64 { +func (m *StakerDelegatorResponse) GetCurrentRewards() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { - return m.CurrentReward + return m.CurrentRewards } - return 0 + return nil } func (m *StakerDelegatorResponse) GetDelegationAmount() uint64 { @@ -455,8 +458,8 @@ func (m *QueryStakersByDelegatorResponse) GetPagination() *query.PageResponse { type DelegationForStakerResponse struct { // staker ... Staker *FullStaker `protobuf:"bytes,1,opt,name=staker,proto3" json:"staker,omitempty"` - // current_reward ... - CurrentReward uint64 `protobuf:"varint,2,opt,name=current_reward,json=currentReward,proto3" json:"current_reward,omitempty"` + // current_rewards ... + CurrentRewards github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=current_rewards,json=currentRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"current_rewards"` // delegation_amount ... DelegationAmount uint64 `protobuf:"varint,3,opt,name=delegation_amount,json=delegationAmount,proto3" json:"delegation_amount,omitempty"` } @@ -501,11 +504,11 @@ func (m *DelegationForStakerResponse) GetStaker() *FullStaker { return nil } -func (m *DelegationForStakerResponse) GetCurrentReward() uint64 { +func (m *DelegationForStakerResponse) GetCurrentRewards() github_com_cosmos_cosmos_sdk_types.Coins { if m != nil { - return m.CurrentReward + return m.CurrentRewards } - return 0 + return nil } func (m *DelegationForStakerResponse) GetDelegationAmount() uint64 { @@ -531,51 +534,56 @@ func init() { } var fileDescriptor_5e1c28c162a0498a = []byte{ - // 699 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0x4f, 0x6b, 0x13, 0x4f, - 0x18, 0xc7, 0x33, 0x69, 0xe8, 0x8f, 0x4e, 0xf9, 0xd9, 0x3a, 0xda, 0x1a, 0x62, 0xd9, 0x96, 0x88, - 0x7f, 0xda, 0xc2, 0x0e, 0x4d, 0x4b, 0x41, 0xf1, 0x62, 0xac, 0x15, 0x11, 0xff, 0x34, 0x82, 0xa0, - 0x97, 0x30, 0xd9, 0x0e, 0xdb, 0xd0, 0x74, 0x27, 0x9d, 0x99, 0x6d, 0x0d, 0xa5, 0x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0x54, - 0xf1, 0xa6, 0x92, 0xbe, 0x8c, 0x96, 0xd2, 0xa4, 0xeb, 0x49, 0x08, 0x74, 0x1b, 0x0e, 0x44, 0xe0, - 0xcb, 0x2b, 0x07, 0x47, 0x16, 0x38, 0x3c, 0xb2, 0xc0, 0xcf, 0x23, 0x0b, 0xbc, 0x69, 0x5b, 0x99, - 0xc3, 0xb6, 0x95, 0xf9, 0xd6, 0xb6, 0x32, 0xcf, 0xe7, 0xdc, 0xba, 0xdc, 0xf0, 0x6b, 0xb6, 0xc3, - 0xb6, 0xf0, 0xfd, 0x67, 0x4f, 0xef, 0x3c, 0xa4, 0x72, 0x97, 0xf1, 0x4d, 0xec, 0x6c, 0x90, 0xba, - 0x87, 0x5f, 0xe8, 0x83, 0x64, 0xab, 0x49, 0x45, 0x6d, 0x58, 0x7d, 0x87, 0x17, 0x7f, 0x07, 0x00, - 0x00, 0xff, 0xff, 0x39, 0x97, 0xee, 0x37, 0x42, 0x08, 0x00, 0x00, + // 769 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x56, 0xcf, 0x6b, 0x13, 0x4d, + 0x18, 0xce, 0xa4, 0xa1, 0x1f, 0x9d, 0xc2, 0xd7, 0x76, 0xbe, 0xaf, 0x35, 0xc6, 0xb2, 0x2d, 0x11, + 0x34, 0x4d, 0x71, 0x87, 0x6e, 0x6b, 0x41, 0xf1, 0x62, 0x5a, 0x2b, 0x22, 0xfe, 0xe8, 0x0a, 0x82, + 0x5e, 0xc2, 0x66, 0x33, 0x6c, 0x97, 0x24, 0x3b, 0xe9, 0xce, 0xa6, 0x35, 0x94, 0x82, 0x78, 0xf0, + 0x2c, 0x78, 0x15, 0xcf, 0xa2, 0x17, 0x8f, 0x82, 0xff, 0x40, 0x8f, 0x05, 0x2f, 0x7a, 0x51, 0x69, + 0x05, 0xff, 0x04, 0x4f, 0x82, 0xec, 0xec, 0x6c, 0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a, 0x07, 0x20, 0xea, 0xdd, + 0x19, 0x48, 0x3b, 0x3a, 0x7d, 0xf7, 0x8e, 0xcb, 0x2d, 0x9e, 0xc8, 0x47, 0x60, 0xbf, 0xc4, 0xb1, + 0x2f, 0xa2, 0x85, 0x81, 0xd8, 0x59, 0xb9, 0xd2, 0x2e, 0x07, 0xf0, 0x3b, 0x65, 0xa0, 0xf7, 0x00, + 0xa2, 0xde, 0x31, 0x1a, 0x00, 0xbd, 0xef, 0xf0, 0x0f, 0x80, 0xde, 0x7f, 0x4e, 0xf3, 0x57, 0x38, + 0xf4, 0x65, 0xb4, 0x94, 0x04, 0x5d, 0x4c, 0x97, 0x8f, 0x5b, 0x52, 0x20, 0x22, 0xbe, 0xb4, 0xba, + 0x77, 0xa0, 0x80, 0xfd, 0x03, 0x05, 0x7c, 0x3d, 0x50, 0xc0, 0xb3, 0x43, 0x25, 0xb5, 0x7f, 0xa8, + 0xa4, 0x3e, 0x1e, 0x2a, 0xa9, 0x87, 0x45, 0xa9, 0x67, 0x6f, 0x3e, 0xb8, 0x7f, 0xed, 0x36, 0xf1, + 0xb6, 0xa9, 0x5b, 0xc3, 0xe6, 0x86, 0x61, 0x3b, 0xf8, 0x91, 0x48, 0xc4, 0x7b, 0xb7, 0x32, 0xcc, + 0xff, 0x2f, 0x2c, 0xfe, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x0e, 0x0e, 0x9f, 0xd2, 0x1d, 0x09, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -832,6 +840,20 @@ func (m *StakerDelegatorResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l + if len(m.CurrentRewards) > 0 { + for iNdEx := len(m.CurrentRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CurrentRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } if len(m.Staker) > 0 { i -= len(m.Staker) copy(dAtA[i:], m.Staker) @@ -844,11 +866,6 @@ func (m *StakerDelegatorResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) i-- dAtA[i] = 0x18 } - if m.CurrentReward != 0 { - i = encodeVarintDelegation(dAtA, i, uint64(m.CurrentReward)) - i-- - dAtA[i] = 0x10 - } if len(m.Delegator) > 0 { i -= len(m.Delegator) copy(dAtA[i:], m.Delegator) @@ -1078,16 +1095,25 @@ func (m *DelegationForStakerResponse) MarshalToSizedBuffer(dAtA []byte) (int, er _ = i var l int _ = l + if len(m.CurrentRewards) > 0 { + for iNdEx := len(m.CurrentRewards) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.CurrentRewards[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintDelegation(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x32 + } + } if m.DelegationAmount != 0 { i = encodeVarintDelegation(dAtA, i, uint64(m.DelegationAmount)) i-- dAtA[i] = 0x18 } - if m.CurrentReward != 0 { - i = encodeVarintDelegation(dAtA, i, uint64(m.CurrentReward)) - i-- - dAtA[i] = 0x10 - } if m.Staker != nil { { size, err := m.Staker.MarshalToSizedBuffer(dAtA[:i]) @@ -1154,9 +1180,6 @@ func (m *StakerDelegatorResponse) Size() (n int) { if l > 0 { n += 1 + l + sovDelegation(uint64(l)) } - if m.CurrentReward != 0 { - n += 1 + sovDelegation(uint64(m.CurrentReward)) - } if m.DelegationAmount != 0 { n += 1 + sovDelegation(uint64(m.DelegationAmount)) } @@ -1164,6 +1187,12 @@ func (m *StakerDelegatorResponse) Size() (n int) { if l > 0 { n += 1 + l + sovDelegation(uint64(l)) } + if len(m.CurrentRewards) > 0 { + for _, e := range m.CurrentRewards { + l = e.Size() + n += 1 + l + sovDelegation(uint64(l)) + } + } return n } @@ -1259,12 +1288,15 @@ func (m *DelegationForStakerResponse) Size() (n int) { l = m.Staker.Size() n += 1 + l + sovDelegation(uint64(l)) } - if m.CurrentReward != 0 { - n += 1 + sovDelegation(uint64(m.CurrentReward)) - } if m.DelegationAmount != 0 { n += 1 + sovDelegation(uint64(m.DelegationAmount)) } + if len(m.CurrentRewards) > 0 { + for _, e := range m.CurrentRewards { + l = e.Size() + n += 1 + l + sovDelegation(uint64(l)) + } + } return n } @@ -1535,11 +1567,11 @@ func (m *StakerDelegatorResponse) Unmarshal(dAtA []byte) error { } m.Delegator = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 2: + case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentReward", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DelegationAmount", wireType) } - m.CurrentReward = 0 + m.DelegationAmount = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -1549,16 +1581,16 @@ func (m *StakerDelegatorResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CurrentReward |= uint64(b&0x7F) << shift + m.DelegationAmount |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelegationAmount", wireType) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Staker", wireType) } - m.DelegationAmount = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -1568,16 +1600,29 @@ func (m *StakerDelegatorResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.DelegationAmount |= uint64(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 4: + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthDelegation + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthDelegation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Staker = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 6: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Staker", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewards", wireType) } - var stringLen uint64 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -1587,23 +1632,25 @@ func (m *StakerDelegatorResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - stringLen |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } - intStringLen := int(stringLen) - if intStringLen < 0 { + if msglen < 0 { return ErrInvalidLengthDelegation } - postIndex := iNdEx + intStringLen + postIndex := iNdEx + msglen if postIndex < 0 { return ErrInvalidLengthDelegation } if postIndex > l { return io.ErrUnexpectedEOF } - m.Staker = string(dAtA[iNdEx:postIndex]) + m.CurrentRewards = append(m.CurrentRewards, types.Coin{}) + if err := m.CurrentRewards[len(m.CurrentRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } iNdEx = postIndex default: iNdEx = preIndex @@ -2237,11 +2284,11 @@ func (m *DelegationForStakerResponse) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 2: + case 3: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field CurrentReward", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field DelegationAmount", wireType) } - m.CurrentReward = 0 + m.DelegationAmount = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -2251,16 +2298,16 @@ func (m *DelegationForStakerResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.CurrentReward |= uint64(b&0x7F) << shift + m.DelegationAmount |= uint64(b&0x7F) << shift if b < 0x80 { break } } - case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field DelegationAmount", wireType) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field CurrentRewards", wireType) } - m.DelegationAmount = 0 + var msglen int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowDelegation @@ -2270,11 +2317,26 @@ func (m *DelegationForStakerResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.DelegationAmount |= uint64(b&0x7F) << shift + msglen |= int(b&0x7F) << shift if b < 0x80 { break } } + if msglen < 0 { + return ErrInvalidLengthDelegation + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthDelegation + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.CurrentRewards = append(m.CurrentRewards, types.Coin{}) + if err := m.CurrentRewards[len(m.CurrentRewards)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipDelegation(dAtA[iNdEx:]) 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 f07d1669..53e43a6b 100644 --- a/x/stakers/keeper/msg_server_claim_commission_rewards_test.go +++ b/x/stakers/keeper/msg_server_claim_commission_rewards_test.go @@ -2,9 +2,11 @@ package keeper_test import ( "cosmossdk.io/math" + i "github.com/KYVENetwork/chain/testutil/integration" bundletypes "github.com/KYVENetwork/chain/x/bundles/types" funderstypes "github.com/KYVENetwork/chain/x/funders/types" + globalTypes "github.com/KYVENetwork/chain/x/global/types" pooltypes "github.com/KYVENetwork/chain/x/pool/types" stakertypes "github.com/KYVENetwork/chain/x/stakers/types" . "github.com/onsi/ginkgo/v2" @@ -173,7 +175,7 @@ var _ = Describe("msg_server_claim_commission_rewards.go", Ordered, func() { // 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(totalDelegationReward)) + Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(totalDelegationReward)) // assert commission rewards Expect(uploader.CommissionRewards).To(Equal(uploaderPayoutReward + storageReward))