Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: make inflation share weight a decimal #190

Merged
merged 24 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a173d03
chore: make inflation-share-weight a LegacyDec
shifty11 May 22, 2024
8748d2c
fix: tests
shifty11 May 22, 2024
bd5d92f
fix: tests
shifty11 May 22, 2024
5df9f8a
fix: tests
shifty11 May 22, 2024
e8ecb42
fix: SplitInflation logic
shifty11 May 22, 2024
2b7e8d9
fix: tests
shifty11 May 22, 2024
6463063
feat: add migration for inflation-share-weight
shifty11 May 22, 2024
2cad9e6
refactor: rename v1.4 bundles types
shifty11 May 22, 2024
d3be301
fix: migration
shifty11 May 22, 2024
57cefb8
fix: test
shifty11 May 22, 2024
64bcc0b
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 May 23, 2024
deda791
chore: make totalInflationShareWeight a LegacyDec
shifty11 May 23, 2024
b901740
refactor: use only LegacyDec in keeper_suite_inflation_splitting_test.go
shifty11 May 23, 2024
3711a12
test: add more tests
shifty11 May 27, 2024
1102580
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 May 27, 2024
9678625
test: fix tests
shifty11 May 27, 2024
3e15eec
test: add second pool for some inflation-splitting tests
shifty11 May 29, 2024
09ef37b
test: check if inflation is correctly split across pools
mbreithecker May 31, 2024
c43f66d
chore: format
mbreithecker May 31, 2024
ea82ac0
chore: adjust migration + add event
mbreithecker May 31, 2024
c05d017
chore: update changelog
mbreithecker May 31, 2024
7359e08
Merge branch 'main' into rapha/make-inflation-share-weight-a-decimal
shifty11 Jun 3, 2024
e26b187
test: move resetting of team allocation to DeferCleanup
shifty11 Jun 3, 2024
5f514d9
chore: sync main
mbreithecker Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout
for each bundle reward
Expand Down Expand Up @@ -1127,7 +1126,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout for each
bundle reward
Expand Down Expand Up @@ -4028,7 +4026,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout
for each bundle reward
Expand Down Expand Up @@ -5051,7 +5048,6 @@ paths:
description: upload_interval ...
inflation_share_weight:
type: string
format: uint64
description: inflation_share_weight ...
min_delegation:
type: string
Expand Down Expand Up @@ -5639,7 +5635,6 @@ paths:
description: upload_interval ...
inflation_share_weight:
type: string
format: uint64
description: inflation_share_weight ...
min_delegation:
type: string
Expand Down Expand Up @@ -6400,7 +6395,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout for
each bundle reward
Expand Down Expand Up @@ -6858,7 +6852,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout for
each bundle reward
Expand Down Expand Up @@ -7427,7 +7420,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout
for each bundle reward
Expand Down Expand Up @@ -7929,7 +7921,6 @@ paths:
title: logo of the pool
inflation_share_weight:
type: string
format: uint64
title: >-
inflation_share_weight is the base payout for
each bundle reward
Expand Down
10 changes: 8 additions & 2 deletions proto/kyve/pool/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ message EventCreatePool {
uint64 upload_interval = 7;
// inflation_share_weight is the fixed cost which gets paid out
// to every successful uploader
uint64 inflation_share_weight = 8;
string inflation_share_weight = 8 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// min_delegation is the minimum amount of $KYVE the pool has
// to have in order to produce bundles
uint64 min_delegation = 9;
Expand Down Expand Up @@ -126,7 +129,10 @@ message EventPoolUpdated {
uint64 upload_interval = 7;
// inflation_share_weight is the fixed cost which gets paid out
// to every successful uploader
uint64 inflation_share_weight = 8;
string inflation_share_weight = 8 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// min_delegation is the minimum amount of $KYVE the pool has
// to have in order to produce bundles
uint64 min_delegation = 9;
Expand Down
5 changes: 4 additions & 1 deletion proto/kyve/pool/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ message Pool {
// upload_interval ...
uint64 upload_interval = 11;
// inflation_share_weight ...
uint64 inflation_share_weight = 12;
string inflation_share_weight = 12 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// min_delegation ...
uint64 min_delegation = 13;
// max_bundle_size ...
Expand Down
6 changes: 5 additions & 1 deletion proto/kyve/pool/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package kyve.pool.v1beta1;

import "cosmos/msg/v1/msg.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/KYVENetwork/chain/x/pool/types";

Expand Down Expand Up @@ -51,7 +52,10 @@ message MsgCreatePool {
// upload_interval ...
uint64 upload_interval = 7;
// inflation_share_weight ...
uint64 inflation_share_weight = 8;
string inflation_share_weight = 8 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];
// min_delegation ...
uint64 min_delegation = 9;
// max_bundle_size ...
Expand Down
5 changes: 4 additions & 1 deletion proto/kyve/query/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ message BasicPool {
string logo = 4;

// inflation_share_weight is the base payout for each bundle reward
uint64 inflation_share_weight = 5;
string inflation_share_weight = 5 [
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
(gogoproto.nullable) = false
];

// upload_interval is the interval bundles get created
uint64 upload_interval = 6;
Expand Down
4 changes: 2 additions & 2 deletions x/bundles/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func SplitInflation(ctx sdk.Context, k bundlesKeeper.Keeper, bk util.BankKeeper,
for _, pool := range pk.GetAllPools(ctx) {
// only include active pools
if err := k.AssertPoolCanRun(ctx, pool.Id); err == nil {
totalInflationShareWeight += pool.InflationShareWeight
totalInflationShareWeight += uint64(pool.InflationShareWeight.TruncateInt64())
troykessler marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand All @@ -59,7 +59,7 @@ func SplitInflation(ctx sdk.Context, k bundlesKeeper.Keeper, bk util.BankKeeper,
// only include active pools
if err := k.AssertPoolCanRun(ctx, pool.Id); err == nil {
// calculate pool share based of inflation share weight
amount := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).
amount := uint64(pool.InflationShareWeight.
Quo(math.LegacyNewDec(int64(totalInflationShareWeight))).
Mul(math.LegacyNewDec(protocolBlockProvision)).
TruncateInt64())
Expand Down
10 changes: 5 additions & 5 deletions x/bundles/keeper/abci_protocol_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ var _ = Describe("abci.go", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 1_000_000,
InflationShareWeight: math.LegacyNewDec(1_000_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down Expand Up @@ -124,7 +124,7 @@ var _ = Describe("abci.go", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 2_000_000,
InflationShareWeight: math.LegacyNewDec(2_000_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down Expand Up @@ -191,7 +191,7 @@ var _ = Describe("abci.go", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 0,
InflationShareWeight: math.LegacyZeroDec(),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down Expand Up @@ -240,7 +240,7 @@ var _ = Describe("abci.go", Ordered, func() {
It("every pool has zero inflation share weight", func() {
// ARRANGE
pool1, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0)
pool1.InflationShareWeight = 0
pool1.InflationShareWeight = math.LegacyZeroDec()
s.App().PoolKeeper.SetPool(s.Ctx(), pool1)

msg := &pooltypes.MsgCreatePool{
Expand All @@ -251,7 +251,7 @@ var _ = Describe("abci.go", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 0,
InflationShareWeight: math.LegacyZeroDec(),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down
3 changes: 2 additions & 1 deletion x/bundles/keeper/keeper_suite_dropped_bundles_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper_test

import (
"cosmossdk.io/math"
funderstypes "github.com/KYVENetwork/chain/x/funders/types"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -42,7 +43,7 @@ var _ = Describe("dropped bundles", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down
3 changes: 2 additions & 1 deletion x/bundles/keeper/keeper_suite_funding_bundles_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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"
Expand Down Expand Up @@ -50,7 +51,7 @@ var _ = Describe("funding bundles", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down
14 changes: 7 additions & 7 deletions x/bundles/keeper/keeper_suite_inflation_splitting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down Expand Up @@ -462,7 +462,7 @@ var _ = Describe("inflation splitting", Ordered, func() {

// the total payout is the inflation share weight because the funding is sufficient
// and there is no additional inflation
totalPayout := pool.InflationShareWeight
totalPayout := uint64(pool.InflationShareWeight.TruncateInt64())

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down Expand Up @@ -569,7 +569,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0)

// the total payout is the inflation share weight plus the inflation payout
totalPayout := pool.InflationShareWeight + payout
totalPayout := uint64(pool.InflationShareWeight.TruncateInt64()) + payout

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down Expand Up @@ -676,7 +676,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0)

// the total payout is the inflation share weight plus the inflation payout
totalPayout := pool.InflationShareWeight + payout
totalPayout := uint64(pool.InflationShareWeight.TruncateInt64()) + payout

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down Expand Up @@ -1100,7 +1100,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0)

// the total payout is the total funds
totalPayout := (pool.InflationShareWeight / 2) + 200
totalPayout := (uint64(pool.InflationShareWeight.TruncateInt64()) / 2) + 200

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down Expand Up @@ -1207,7 +1207,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0)

// the total payout is the inflation share weight plus the inflation payout
totalPayout := (pool.InflationShareWeight / 2) + 200 + payout
totalPayout := (uint64(pool.InflationShareWeight.TruncateInt64()) / 2) + 200 + payout

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down Expand Up @@ -1314,7 +1314,7 @@ var _ = Describe("inflation splitting", Ordered, func() {
uploader, _ := s.App().StakersKeeper.GetStaker(s.Ctx(), i.STAKER_0)

// the total payout is the inflation share weight plus the inflation payout
totalPayout := (pool.InflationShareWeight / 2) + 200 + payout
totalPayout := (uint64(pool.InflationShareWeight.TruncateInt64()) / 2) + 200 + payout

networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(totalPayout)).Mul(networkFee).TruncateInt64())
Expand Down
2 changes: 1 addition & 1 deletion x/bundles/keeper/keeper_suite_invalid_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("invalid bundles", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down
2 changes: 1 addition & 1 deletion x/bundles/keeper/keeper_suite_points_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var _ = Describe("points", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 100 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down
16 changes: 8 additions & 8 deletions x/bundles/keeper/keeper_suite_stakers_leave_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var _ = Describe("stakers leave", Ordered, func() {
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
UploadInterval: 60,
InflationShareWeight: 10_000,
InflationShareWeight: math.LegacyNewDec(10_000),
MinDelegation: 0 * i.KYVE,
MaxBundleSize: 100,
Version: "0.0.0",
Expand Down Expand Up @@ -244,19 +244,19 @@ var _ = Describe("stakers leave", Ordered, func() {

// calculate uploader rewards
networkFee := s.App().BundlesKeeper.GetNetworkFee(s.Ctx())
treasuryReward := uint64(math.LegacyNewDec(int64(pool.InflationShareWeight)).Mul(networkFee).TruncateInt64())
storageReward := uint64(s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100).TruncateInt64())
totalUploaderReward := pool.InflationShareWeight - treasuryReward - storageReward
treasuryReward := pool.InflationShareWeight.Mul(networkFee)
storageReward := s.App().BundlesKeeper.GetStorageCost(s.Ctx(), pool.CurrentStorageProviderId).MulInt64(100)
totalUploaderReward := pool.InflationShareWeight.Sub(treasuryReward).Sub(storageReward)

uploaderPayoutReward := uint64(math.LegacyNewDec(int64(totalUploaderReward)).Mul(uploader.Commission).TruncateInt64())
uploaderDelegationReward := totalUploaderReward - uploaderPayoutReward
uploaderPayoutReward := totalUploaderReward.Mul(uploader.Commission)
uploaderDelegationReward := totalUploaderReward.Sub(uploaderPayoutReward)

// assert payout transfer
Expect(balanceUploader).To(Equal(initialBalanceStaker0))
// assert commission rewards
Expect(uploader.CommissionRewards.AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderPayoutReward + storageReward))
Expect(uploader.CommissionRewards.AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(uploaderPayoutReward.Add(storageReward).TruncateInt64())))
// assert uploader self delegation rewards
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uploaderDelegationReward))
Expect(s.App().DelegationKeeper.GetOutstandingRewards(s.Ctx(), i.STAKER_0, i.STAKER_0).AmountOf(globalTypes.Denom).Uint64()).To(Equal(uint64(uploaderDelegationReward.TruncateInt64())))
})

It("Staker leaves, although he was the uploader of the previous round and should get slashed", func() {
Expand Down
Loading
Loading