Skip to content

Commit

Permalink
feat: implemented new pool status which halts if voting power is too …
Browse files Browse the repository at this point in the history
…high
  • Loading branch information
troykessler committed Oct 26, 2023
1 parent c9c105b commit 5bf771a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 55 deletions.
9 changes: 9 additions & 0 deletions docs/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -1083,6 +1084,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
title: >-
BasicPool contains the necessary properties need for a
Expand Down Expand Up @@ -3949,6 +3951,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -4999,6 +5002,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
account:
type: string
Expand Down Expand Up @@ -5515,6 +5519,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
account:
type: string
Expand Down Expand Up @@ -5992,6 +5997,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -6421,6 +6427,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -6962,6 +6969,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -7434,6 +7442,7 @@ paths:
- POOL_STATUS_NO_FUNDS
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VP_TOO_HIGH
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down
2 changes: 2 additions & 0 deletions proto/kyve/pool/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ enum PoolStatus {
POOL_STATUS_NOT_ENOUGH_DELEGATION = 4;
// POOL_STATUS_UPGRADING ...
POOL_STATUS_UPGRADING = 5;
// POOL_STATUS_VP_TOO_HIGH ...
POOL_STATUS_VP_TOO_HIGH = 6;
}

// Protocol holds all info about the current pool version and the
Expand Down
20 changes: 19 additions & 1 deletion x/bundles/keeper/logic_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,29 @@ func (k Keeper) AssertPoolCanRun(ctx sdk.Context, poolId uint64) error {
return types.ErrPoolDisabled
}

totalDelegation := uint64(0)
maxDelegation := uint64(0)

// Get the total delegation and the highest delegation of a staker in the pool
for _, address := range k.stakerKeeper.GetAllStakerAddressesOfPool(ctx, poolId) {
delegation := k.delegationKeeper.GetDelegationAmount(ctx, address)
totalDelegation += delegation

if delegation > maxDelegation {
maxDelegation = delegation
}
}

// Error if min delegation is not reached
if k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) < pool.MinDelegation {
if totalDelegation < pool.MinDelegation {
return types.ErrMinDelegationNotReached
}

// Error if the top staker has more than 50%
if maxDelegation*2 > totalDelegation {
return types.ErrVPTooHigh
}

return nil
}

Expand Down
1 change: 1 addition & 0 deletions x/bundles/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ var (
ErrAlreadyVotedValid = errors.Register(ModuleName, 1204, "already voted valid on bundle proposal")
ErrAlreadyVotedInvalid = errors.Register(ModuleName, 1205, "already voted invalid on bundle proposal")
ErrAlreadyVotedAbstain = errors.Register(ModuleName, 1206, "already voted abstain on bundle proposal")
ErrVPTooHigh = errors.Register(ModuleName, 1207, "staker in pool has more than 50% voting power")
)
110 changes: 57 additions & 53 deletions x/pool/types/pool.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion x/query/keeper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,18 @@ func (k Keeper) GetFullStaker(ctx sdk.Context, stakerAddress string) *types.Full
}

func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.PoolStatus {
totalDelegation := k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id)
totalDelegation := uint64(0)
maxDelegation := uint64(0)

// Get the total delegation and the highest delegation of a staker in the pool
for _, address := range k.stakerKeeper.GetAllStakerAddressesOfPool(ctx, pool.Id) {
delegation := k.delegationKeeper.GetDelegationAmount(ctx, address)
totalDelegation += delegation

if delegation > maxDelegation {
maxDelegation = delegation
}
}

var poolStatus pooltypes.PoolStatus

Expand All @@ -92,6 +103,8 @@ func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.P
poolStatus = pooltypes.POOL_STATUS_DISABLED
} else if totalDelegation < pool.MinDelegation {
poolStatus = pooltypes.POOL_STATUS_NOT_ENOUGH_DELEGATION
} else if maxDelegation*2 > totalDelegation {
poolStatus = pooltypes.POOL_STATUS_VP_TOO_HIGH
} else if pool.TotalFunds == 0 {
poolStatus = pooltypes.POOL_STATUS_NO_FUNDS
} else {
Expand Down

0 comments on commit 5bf771a

Please sign in to comment.