-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #414 from ComposableFi/release/v6.4.x-epoch-staking
Release/v6.4.x with a epoch staking feature
- Loading branch information
Showing
37 changed files
with
4,122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package v6_4 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/notional-labs/composable/v6/app/upgrades" | ||
customstmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name for the composable upgrade. | ||
UpgradeName = "v6_4" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: store.StoreUpgrades{ | ||
Added: []string{customstmiddleware.StoreKey}, | ||
Deleted: []string{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package v6_4 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/notional-labs/composable/v6/app/keepers" | ||
"github.com/notional-labs/composable/v6/app/upgrades" | ||
customstmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/types" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
_ upgrades.BaseAppParamManager, | ||
_ codec.Codec, | ||
keepers *keepers.AppKeepers, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
// Add params for custom middleware | ||
custommiddlewareparams := customstmiddleware.Params{BlocksPerEpoch: 100, AllowUnbondAfterEpochProgressBlockNumber: 0} | ||
keepers.StakingMiddlewareKeeper.SetParams(ctx, custommiddlewareparams) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package bank | ||
|
||
import ( | ||
"time" | ||
|
||
abci "github.com/cometbft/cometbft/abci/types" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
// "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
customstakingkeeper "github.com/notional-labs/composable/v6/custom/staking/keeper" | ||
) | ||
|
||
// Called every block, update validator set | ||
func EndBlocker(ctx sdk.Context, k *customstakingkeeper.Keeper) []abci.ValidatorUpdate { | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) | ||
|
||
return k.BlockValidatorUpdates(ctx, ctx.BlockHeight()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package keeper | ||
|
||
import ( | ||
abcicometbft "github.com/cometbft/cometbft/abci/types" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
|
||
storetypes "github.com/cosmos/cosmos-sdk/store/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
stakingmiddleware "github.com/notional-labs/composable/v6/x/stakingmiddleware/keeper" | ||
) | ||
|
||
type Keeper struct { | ||
stakingkeeper.Keeper | ||
cdc codec.BinaryCodec | ||
Stakingmiddleware *stakingmiddleware.Keeper | ||
authority string | ||
} | ||
|
||
func (k Keeper) BlockValidatorUpdates(ctx sdk.Context, height int64) []abcicometbft.ValidatorUpdate { | ||
// Calculate validator set changes. | ||
// | ||
// NOTE: ApplyAndReturnValidatorSetUpdates has to come before | ||
// UnbondAllMatureValidatorQueue. | ||
// This fixes a bug when the unbonding period is instant (is the case in | ||
// some of the tests). The test expected the validator to be completely | ||
// unbonded after the Endblocker (go from Bonded -> Unbonding during | ||
// ApplyAndReturnValidatorSetUpdates and then Unbonding -> Unbonded during | ||
// UnbondAllMatureValidatorQueue). | ||
params := k.Stakingmiddleware.GetParams(ctx) | ||
shouldExecuteBatch := (height % int64(params.BlocksPerEpoch)) == 0 | ||
var validatorUpdates []abcicometbft.ValidatorUpdate | ||
if shouldExecuteBatch { | ||
k.Logger(ctx).Info("Should Execute ApplyAndReturnValidatorSetUpdates at height : ", height) | ||
v, err := k.ApplyAndReturnValidatorSetUpdates(ctx) | ||
if err != nil { | ||
panic(err) | ||
} | ||
validatorUpdates = v | ||
} | ||
|
||
// unbond all mature validators from the unbonding queue | ||
k.UnbondAllMatureValidators(ctx) | ||
|
||
// Remove all mature unbonding delegations from the ubd queue. | ||
matureUnbonds := k.DequeueAllMatureUBDQueue(ctx, ctx.BlockHeader().Time) | ||
for _, dvPair := range matureUnbonds { | ||
addr, err := sdk.ValAddressFromBech32(dvPair.ValidatorAddress) | ||
if err != nil { | ||
panic(err) | ||
} | ||
delegatorAddress := sdk.MustAccAddressFromBech32(dvPair.DelegatorAddress) | ||
|
||
balances, err := k.CompleteUnbonding(ctx, delegatorAddress, addr) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeCompleteUnbonding, | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), | ||
sdk.NewAttribute(types.AttributeKeyValidator, dvPair.ValidatorAddress), | ||
sdk.NewAttribute(types.AttributeKeyDelegator, dvPair.DelegatorAddress), | ||
), | ||
) | ||
} | ||
|
||
// Remove all mature redelegations from the red queue. | ||
matureRedelegations := k.DequeueAllMatureRedelegationQueue(ctx, ctx.BlockHeader().Time) | ||
for _, dvvTriplet := range matureRedelegations { | ||
valSrcAddr, err := sdk.ValAddressFromBech32(dvvTriplet.ValidatorSrcAddress) | ||
if err != nil { | ||
panic(err) | ||
} | ||
valDstAddr, err := sdk.ValAddressFromBech32(dvvTriplet.ValidatorDstAddress) | ||
if err != nil { | ||
panic(err) | ||
} | ||
delegatorAddress := sdk.MustAccAddressFromBech32(dvvTriplet.DelegatorAddress) | ||
|
||
balances, err := k.CompleteRedelegation( | ||
ctx, | ||
delegatorAddress, | ||
valSrcAddr, | ||
valDstAddr, | ||
) | ||
if err != nil { | ||
continue | ||
} | ||
|
||
ctx.EventManager().EmitEvent( | ||
sdk.NewEvent( | ||
types.EventTypeCompleteRedelegation, | ||
sdk.NewAttribute(sdk.AttributeKeyAmount, balances.String()), | ||
sdk.NewAttribute(types.AttributeKeyDelegator, dvvTriplet.DelegatorAddress), | ||
sdk.NewAttribute(types.AttributeKeySrcValidator, dvvTriplet.ValidatorSrcAddress), | ||
sdk.NewAttribute(types.AttributeKeyDstValidator, dvvTriplet.ValidatorDstAddress), | ||
), | ||
) | ||
} | ||
|
||
return validatorUpdates | ||
} | ||
|
||
func NewKeeper( | ||
cdc codec.BinaryCodec, | ||
key storetypes.StoreKey, | ||
ak types.AccountKeeper, | ||
bk types.BankKeeper, | ||
authority string, | ||
stakingmiddleware *stakingmiddleware.Keeper, | ||
) *Keeper { | ||
keeper := Keeper{ | ||
Keeper: *stakingkeeper.NewKeeper(cdc, key, ak, bk, authority), | ||
authority: authority, | ||
Stakingmiddleware: stakingmiddleware, | ||
cdc: cdc, | ||
} | ||
return &keeper | ||
} |
Oops, something went wrong.