-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improved schema for finalized bundles query (#104)
(cherry picked from commit cf4857f) # Conflicts: # CHANGELOG.md # app/upgrades/v1_3/upgrade.go # proto/kyve/bundles/v1beta1/bundles.proto # x/bundles/types/bundles.pb.go # x/bundles/types/keys.go
- Loading branch information
1 parent
2f2bbdd
commit 1574c0d
Showing
16 changed files
with
3,249 additions
and
1,255 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package v1_3 | ||
|
||
import ( | ||
"fmt" | ||
|
||
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" | ||
|
||
// Auth | ||
authKeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" | ||
vestingExported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported" | ||
// Staking | ||
stakingKeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" | ||
// Upgrade | ||
upgradeTypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
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) | ||
|
||
if ctx.ChainID() == MainnetChainID { | ||
for _, address := range InvestorAccounts { | ||
TrackInvestorDelegation(ctx, logger, sdk.MustAccAddressFromBech32(address), accountKeeper, bankKeeper, stakingKeeper) | ||
} | ||
} | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} | ||
|
||
// TrackInvestorDelegation performs a correction of the delegation tracking inside the vesting account. | ||
// The correction is done by performing a full untracking and then tracking the actual total delegated amount | ||
// (including slashed amounts). | ||
func TrackInvestorDelegation(ctx sdk.Context, logger log.Logger, address sdk.AccAddress, ak authKeeper.AccountKeeper, bk bankKeeper.Keeper, sk stakingKeeper.Keeper) { | ||
denom := sk.BondDenom(ctx) | ||
account, _ := ak.GetAccount(ctx, address).(vestingExported.VestingAccount) | ||
|
||
// Obtain total delegation of address | ||
totalDelegation := sdk.NewInt(0) | ||
for _, delegation := range sk.GetAllDelegatorDelegations(ctx, address) { | ||
// We take the shares as the total delegation as this is the amount which is | ||
// tracked inside the vesting account. (slashes are ignored, which is correct) | ||
totalDelegation = totalDelegation.Add(delegation.GetShares().TruncateInt()) | ||
} | ||
|
||
// Fetch current balance. | ||
balanceCoin := bk.GetBalance(ctx, address, denom) | ||
|
||
// This is the balance a user would have if all tokens are unbonded (even the ones which got slashed). | ||
maxPossibleBalance := balanceCoin.Amount.Add(totalDelegation) | ||
maxPossibleBalanceCoins := sdk.NewCoins().Add(sdk.NewCoin(denom, maxPossibleBalance)) | ||
|
||
if totalDelegation.GT(sdk.ZeroInt()) { | ||
|
||
// Untrack entire vesting delegation using maximum amount. This will set both `delegated_free` | ||
// and `delegated_vesting` back to zero. | ||
account.TrackUndelegation(sdk.NewCoins(sdk.NewCoin("ukyve", maxPossibleBalance))) | ||
|
||
// Track the delegation using the total delegation | ||
account.TrackDelegation(ctx.BlockTime(), maxPossibleBalanceCoins, sdk.NewCoins(sdk.NewCoin("ukyve", totalDelegation))) | ||
|
||
logger.Info(fmt.Sprintf("tracked delegation of %s with %s", address.String(), totalDelegation.String())) | ||
ak.SetAccount(ctx, account) | ||
} | ||
} |
Oops, something went wrong.