Skip to content

Commit

Permalink
feat: inflation splitting (#98)
Browse files Browse the repository at this point in the history
Co-authored-by: John Letey <john@kyve.network>
  • Loading branch information
troykessler and johnletey authored Jul 11, 2023
1 parent cf4857f commit 5630a9f
Show file tree
Hide file tree
Showing 94 changed files with 5,521 additions and 983 deletions.
12 changes: 8 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func NewKYVEApp(
// ... other modules keepers
app.GlobalKeeper = *globalKeeper.NewKeeper(appCodec, keys[globalTypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.TeamKeeper = *teamKeeper.NewKeeper(appCodec, keys[teamTypes.StoreKey], app.AccountKeeper, app.BankKeeper)
app.TeamKeeper = *teamKeeper.NewKeeper(appCodec, keys[teamTypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.MintKeeper, app.UpgradeKeeper)

app.PoolKeeper = *poolKeeper.NewKeeper(
appCodec,
Expand All @@ -407,7 +407,9 @@ func NewKYVEApp(
app.AccountKeeper,
app.BankKeeper,
app.DistributionKeeper,
app.MintKeeper,
app.UpgradeKeeper,
app.TeamKeeper,
)

app.StakersKeeper = *stakersKeeper.NewKeeper(
Expand Down Expand Up @@ -632,10 +634,10 @@ func NewKYVEApp(
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),

// KYVE
bundles.NewAppModule(appCodec, app.BundlesKeeper, app.AccountKeeper, app.BankKeeper),
bundles.NewAppModule(appCodec, app.BundlesKeeper, app.AccountKeeper, app.BankKeeper, app.DistributionKeeper, app.MintKeeper, app.UpgradeKeeper, app.PoolKeeper, app.TeamKeeper),
delegation.NewAppModule(appCodec, app.DelegationKeeper, app.AccountKeeper, app.BankKeeper),
global.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.GlobalKeeper, app.UpgradeKeeper),
pool.NewAppModule(appCodec, app.PoolKeeper, app.AccountKeeper, app.BankKeeper),
pool.NewAppModule(appCodec, app.PoolKeeper, app.AccountKeeper, app.BankKeeper, app.UpgradeKeeper),
query.NewAppModule(appCodec, app.QueryKeeper, app.AccountKeeper, app.BankKeeper),
stakers.NewAppModule(appCodec, app.StakersKeeper, app.AccountKeeper, app.BankKeeper),
team.NewAppModule(appCodec, app.BankKeeper, app.MintKeeper, app.TeamKeeper, app.UpgradeKeeper),
Expand All @@ -652,6 +654,8 @@ func NewKYVEApp(
minttypes.ModuleName,
// NOTE: x/team must be run before x/distribution and after x/mint.
teamTypes.ModuleName,
// NOTE: x/bundles must be run before x/distribution and after x/team.
bundlesTypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
evidencetypes.ModuleName,
Expand All @@ -675,7 +679,6 @@ func NewKYVEApp(
poolTypes.ModuleName,
stakersTypes.ModuleName,
delegationTypes.ModuleName,
bundlesTypes.ModuleName,
queryTypes.ModuleName,
globalTypes.ModuleName,
)
Expand Down Expand Up @@ -803,6 +806,7 @@ func NewKYVEApp(
v1p3.CreateUpgradeHandler(
app.mm,
app.configurator,
app.PoolKeeper,
app.AccountKeeper,
app.BankKeeper,
app.StakingKeeper,
Expand Down
22 changes: 21 additions & 1 deletion app/upgrades/v1_3/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/tendermint/tendermint/libs/log"

// Pool
poolKeeper "github.com/KYVENetwork/chain/x/pool/keeper"
poolTypes "github.com/KYVENetwork/chain/x/pool/types"
// Upgrade
bankKeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"

// Auth
authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
vestingExported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
Expand All @@ -20,13 +25,16 @@ import (
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
poolKeeper poolKeeper.Keeper,
accountKeeper authKeeper.AccountKeeper,
bankKeeper bankKeeper.Keeper,
stakingKeeper stakingKeeper.Keeper,
) upgradeTypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradeTypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger().With("upgrade", UpgradeName)

CheckPoolAccounts(ctx, logger, poolKeeper)

if ctx.ChainID() == MainnetChainID {
for _, address := range InvestorAccounts {
TrackInvestorDelegation(ctx, logger, sdk.MustAccAddressFromBech32(address), accountKeeper, bankKeeper, stakingKeeper)
Expand Down Expand Up @@ -72,3 +80,15 @@ func TrackInvestorDelegation(ctx sdk.Context, logger log.Logger, address sdk.Acc
ak.SetAccount(ctx, account)
}
}

// CheckPoolAccounts ensures that each pool account exists post upgrade.
func CheckPoolAccounts(ctx sdk.Context, logger log.Logger, keeper poolKeeper.Keeper) {
pools := keeper.GetAllPools(ctx)

for _, pool := range pools {
keeper.EnsurePoolAccount(ctx, pool.Id)

name := fmt.Sprintf("%s/%d", poolTypes.ModuleName, pool.Id)
logger.Info("successfully initialised pool account", "name", name)
}
}
18 changes: 10 additions & 8 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,32 @@ genesis:
clawback: "1804978800"
commencement: "1647212400"
pool:
pool_count: "2"
params:
protocol_inflation_share: "0.04"
pool_count: "1"
pool_list:
- config: "ar://tMTrJ8E3QgBNLz0-lyn6QrxasEIX46d14QFVmBWshSI"
- config: "{\"network\":\"kyve-1\",\"rpc\":\"https://rpc-eu-1.kyve.network\"}"
current_compression_id: "1"
current_index: "0"
current_key: ""
current_storage_provider_id: "1"
current_summary: ""
funders: []
id: "0"
logo: "ar://E3jXAOeJ3El7HQgOf_NtSOwVE7Sd0M4g4bYqjCBH9CU"
logo: ""
max_bundle_size: "100"
min_delegation: "100000000000"
name: "Avalanche // C-Chain"
name: "KYVE // Mainnet"
operating_cost: "2500000000"
disabled: false
runtime: '@kyvejs/evm'
start_key: "0"
runtime: '@kyvejs/tendermint-bsync'
start_key: "1"
total_bundles: "0"
total_funds: "0"
upload_interval: "60"
protocol:
version: "1.0.0-beta.5"
binaries: "{\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Fevm%401.0.0-beta.5/kyve-macos-x64.zip\"}"
version: "1.0.0"
binaries: "{\"kyve-linux-arm64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-linux-arm64.zip\",\"kyve-linux-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-linux-x64.zip\",\"kyve-macos-x64\":\"https://github.com/KYVENetwork/kyvejs/releases/download/%40kyvejs%2Ftendermint-bsync%401.0.0/kyve-macos-x64.zip\"}"
last_upgrade: "0"
upgrade_plan:
version: ""
Expand Down
60 changes: 60 additions & 0 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,12 @@ paths:
commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE
earned through commission
title: >-
StakerMetadata contains static information for a
staker
Expand Down Expand Up @@ -3838,6 +3844,12 @@ paths:
commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE
earned through commission
title: >-
StakerMetadata contains static information for a
staker
Expand Down Expand Up @@ -4482,6 +4494,16 @@ paths:
type: string
format: uint64
description: commission_change_time ...
pool_params:
description: pool_params ...
type: object
properties:
protocol_inflation_share:
type: string
description: protocol_inflation_share ...
pool_inflation_payout_rate:
type: string
description: pool_inflation_payout_rate ...
description: QueryParamsResponse ...
default:
description: An unexpected error response.
Expand Down Expand Up @@ -4976,6 +4998,13 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
default: POOL_STATUS_UNSPECIFIED
account:
type: string
description: account ...
account_balance:
type: string
format: uint64
description: account_balance ...
description: >-
QueryPoolResponse is the response type for the Query/Pool RPC
method.
Expand Down Expand Up @@ -5485,6 +5514,13 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
default: POOL_STATUS_UNSPECIFIED
account:
type: string
description: account ...
account_balance:
type: string
format: uint64
description: account_balance ...
description: PoolResponse ...
description: pools ...
pagination:
Expand Down Expand Up @@ -5856,6 +5892,12 @@ paths:
title: |-
CommissionChangeEntry shows when the old commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE earned
through commission
title: StakerMetadata contains static information for a staker
self_delegation:
type: string
Expand Down Expand Up @@ -6279,6 +6321,12 @@ paths:
title: |-
CommissionChangeEntry shows when the old commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE earned
through commission
title: StakerMetadata contains static information for a staker
self_delegation:
type: string
Expand Down Expand Up @@ -6807,6 +6855,12 @@ paths:
commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE
earned through commission
title: >-
StakerMetadata contains static information for a
staker
Expand Down Expand Up @@ -7280,6 +7334,12 @@ paths:
title: |-
CommissionChangeEntry shows when the old commission
of a staker will change to the new commission
commission_rewards:
type: string
format: uint64
title: >-
commission_rewards are the rewards in $KYVE earned
through commission
title: StakerMetadata contains static information for a staker
self_delegation:
type: string
Expand Down
18 changes: 11 additions & 7 deletions proto/kyve/bundles/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,24 @@ message EventBundleFinalized {
uint64 total = 6;
// status of the finalized bundle
BundleStatus status = 7;
// amount which funders provided to the total bundle reward (in ukyve)
uint64 funders_payout = 8;
// amount which the inflation pool provided to the total reward (in ukyve)
uint64 inflation_payout = 9;
// rewards transferred to treasury (in ukyve)
uint64 reward_treasury = 8;
uint64 reward_treasury = 10;
// rewardUploader rewards directly transferred to uploader (in ukyve)
uint64 reward_uploader = 9;
uint64 reward_uploader = 11;
// rewardDelegation rewards distributed among all delegators (in ukyve)
uint64 reward_delegation = 10;
uint64 reward_delegation = 12;
// rewardTotal the total bundle reward
uint64 reward_total = 11;
uint64 reward_total = 13;
// finalized_at the block height where the bundle got finalized
uint64 finalized_at = 12;
uint64 finalized_at = 14;
// uploader the address of the uploader of this bundle
string uploader = 13;
string uploader = 15;
// next_uploader the address of the next uploader after this bundle
string next_uploader = 14;
string next_uploader = 16;
}

// EventClaimedUploaderRole is an event emitted when an uploader claims the uploader role
Expand Down
14 changes: 14 additions & 0 deletions proto/kyve/pool/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,22 @@ syntax = "proto3";

package kyve.pool.v1beta1;

import "gogoproto/gogo.proto";
import "kyve/pool/v1beta1/params.proto";

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

// EventUpdateParams is an event emitted when the module parameters are updated.
// emitted_by: MsgUpdateParams
message EventUpdateParams {
// old_params is the module's old parameters.
kyve.pool.v1beta1.Params old_params = 1 [(gogoproto.nullable) = false];
// new_params is the module's new parameters.
kyve.pool.v1beta1.Params new_params = 2 [(gogoproto.nullable) = false];
// payload is the parameter updates that were performed.
string payload = 3;
}

// EventCreatePool ...
// emitted_by: EndBlock(gov)
message EventCreatePool {
Expand Down
6 changes: 3 additions & 3 deletions proto/kyve/pool/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ syntax = "proto3";
package kyve.pool.v1beta1;

import "gogoproto/gogo.proto";
import "kyve/pool/v1beta1/params.proto";
import "kyve/pool/v1beta1/pool.proto";

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

// GenesisState defines the pool module's genesis state.
message GenesisState {
reserved 1;
reserved "params";

// params ...
Params params = 1 [(gogoproto.nullable) = false];
// pool_list ...
repeated kyve.pool.v1beta1.Pool pool_list = 2 [(gogoproto.nullable) = false];
// pool_count ...
Expand Down
22 changes: 22 additions & 0 deletions proto/kyve/pool/v1beta1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package kyve.pool.v1beta1;

import "gogoproto/gogo.proto";

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

// Params defines the pool module parameters.
message Params {
// protocol_inflation_share ...
string protocol_inflation_share = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// pool_inflation_payout_rate ...
string pool_inflation_payout_rate = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
26 changes: 26 additions & 0 deletions proto/kyve/pool/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
syntax = "proto3";

package kyve.pool.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "kyve/pool/v1beta1/params.proto";

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

// Query defines the gRPC querier service.
service Query {
// Parameters queries the parameters of the module.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/kyve/pool/v1beta1/params";
}
}

// QueryParamsRequest is request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is response type for the Query/Params RPC method.
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false];
}
Loading

0 comments on commit 5630a9f

Please sign in to comment.