-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: register epoch hook + delegate pending rewards (#334)
* register x/liquidstake epoch hooks * upgrade handler to delegate pending rewards * update upgrade test * register upgrade handler * update pstake version
- Loading branch information
Showing
7 changed files
with
81 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package v11_12_0_rc0 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
|
||
"github.com/persistenceOne/persistenceCore/v11/app/upgrades" | ||
) | ||
|
||
const ( | ||
// UpgradeName defines the on-chain upgrade name. | ||
UpgradeName = "v11.12.0-rc0" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
CreateUpgradeHandler: CreateUpgradeHandler, | ||
StoreUpgrades: store.StoreUpgrades{}, | ||
} |
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,53 @@ | ||
package v11_12_0_rc0 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
liquidstaketypes "github.com/persistenceOne/pstake-native/v2/x/liquidstake/types" | ||
|
||
"github.com/persistenceOne/persistenceCore/v11/app/keepers" | ||
"github.com/persistenceOne/persistenceCore/v11/app/upgrades" | ||
) | ||
|
||
func CreateUpgradeHandler(args upgrades.UpgradeHandlerArgs) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx.Logger().Info("running module migrations...") | ||
|
||
DelegateLiquidStakeRewards(ctx, args.Keepers) | ||
|
||
return args.ModuleManager.RunMigrations(ctx, args.Configurator, vm) | ||
} | ||
} | ||
|
||
func DelegateLiquidStakeRewards(ctx sdk.Context, k *keepers.AppKeepers) { | ||
proxyAccBalance := k.LiquidStakeKeeper.GetProxyAccBalance(ctx, liquidstaketypes.LiquidStakeProxyAcc) | ||
amountToDelegate := proxyAccBalance.Amount | ||
|
||
whitelistedValidators := k.LiquidStakeKeeper.GetParams(ctx).WhitelistedValidators | ||
whitelistedValsMap := liquidstaketypes.GetWhitelistedValsMap(whitelistedValidators) | ||
activeLiquidVals := k.LiquidStakeKeeper.GetActiveLiquidValidators(ctx, whitelistedValsMap) | ||
|
||
// currently auto compounding fee rate is zero, therefore fee logic is added here. | ||
|
||
err := k.LiquidStakeKeeper.LiquidDelegate(ctx, liquidstaketypes.LiquidStakeProxyAcc, activeLiquidVals, amountToDelegate, whitelistedValsMap) | ||
|
||
// if liquid delegate fails then try to delegate to any one active validator | ||
if err != nil { | ||
ctx.Logger().Info("failed to liquid delegate, trying to delegate to any one validator...", "error", err.Error()) | ||
|
||
for _, lv := range activeLiquidVals { | ||
val, _ := k.StakingKeeper.GetValidator(ctx, lv.GetOperator()) | ||
err2 := k.LiquidStakeKeeper.DelegateWithCap(ctx, liquidstaketypes.LiquidStakeProxyAcc, val, amountToDelegate) | ||
if err2 != nil { | ||
ctx.Logger().Info("failed to delegate", "validator", val.GetOperator(), "error", err2.Error()) | ||
// continue with next val | ||
} else { | ||
// successfully delegated, exit | ||
return | ||
} | ||
} | ||
|
||
ctx.Logger().Error("failed to delegate to any of active val set") | ||
} | ||
} |
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