Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destination of Slashed Funds in Basket Module Unclear #617

Open
kmlbgn opened this issue Dec 7, 2023 · 1 comment
Open

Destination of Slashed Funds in Basket Module Unclear #617

kmlbgn opened this issue Dec 7, 2023 · 1 comment
Assignees
Labels
Priority: Medium x/basket Basket module x/slashing Slashing module

Comments

@kmlbgn
Copy link
Collaborator

kmlbgn commented Dec 7, 2023

PR #610 (commit c4d2476) added new hooks to the basket module for handling validator slash events. However, it's not clear where the slashed funds go when the basket pool weight of a slashed validator is reduced.

func (k Keeper) AfterSlashStakingPool(ctx sdk.Context, valAddr sdk.ValAddress, pool multistakingtypes.StakingPool, slash sdk.Dec) {
rates := k.tk.GetAllTokenRates(ctx)
for _, rate := range rates {
if rate.StakeToken {
basket, err := k.GetBasketByDenom(ctx, fmt.Sprintf("sdb/%s", rate.Denom))
if err != nil {
continue
}
shareDenom := multistakingtypes.GetShareDenom(pool.Id, rate.Denom)
for i, token := range basket.Tokens {
if token.Denom == shareDenom {
basket.Tokens[i].Weight = token.Weight.Mul(sdk.OneDec().Sub(slash))
basket.Tokens[i].Deposits = true
basket.Tokens[i].Withdraws = true
basket.Tokens[i].Swaps = true
}
}
k.SetBasket(ctx, basket)
}
}
}

As per KIP :

The slashed tokens, including KIRA's native token KEX, are transferred to a governance-controlled community spending pool where a decision can be made regarding their final fate

@kmlbgn kmlbgn added x/basket Basket module x/slashing Slashing module Priority: Medium labels Dec 7, 2023
@kiragpg
Copy link
Contributor

kiragpg commented Mar 18, 2024

This is reducing the weight of an asset since that asset's value has been decreased from slashing underlying tokens. Therefore the slash handling should be actualy done in multistakingi module - not on basket module.
Here's where it handles slashed tokens

func (k Keeper) SlashStakingPool(ctx sdk.Context, validator string, slash sdk.Dec) {
	pool, found := k.GetStakingPoolByValidator(ctx, validator)
	if !found {
		return
	}
	pool.Slashed = slash
	pool.Enabled = false

	totalStakingTokens := sdk.Coins{}
	for _, stakingToken := range pool.TotalStakingTokens {
		totalStakingTokens = totalStakingTokens.Add(sdk.NewCoin(stakingToken.Denom, sdk.NewDecFromInt(stakingToken.Amount).Mul(sdk.OneDec().Sub(pool.Slashed)).RoundInt()))
	}
	totalSlashedTokens := sdk.Coins(pool.TotalStakingTokens).Sub(totalStakingTokens...)
	pool.TotalStakingTokens = totalStakingTokens

	defaultDenom := k.sk.DefaultDenom(ctx)
	defaultDenomAmount := totalSlashedTokens.AmountOf(defaultDenom)
	burnAmount := sdk.Coins{sdk.NewCoin(defaultDenom, defaultDenomAmount)}
	err := k.bankKeeper.BurnCoins(ctx, types.ModuleName, burnAmount)
	if err != nil {
		panic(err)
	}

	treasurySendAmount := totalSlashedTokens.Sub(burnAmount...)
	err = k.bankKeeper.SendCoinsFromModuleToModule(ctx, types.ModuleName, authtypes.FeeCollectorName, treasurySendAmount)
	if err != nil {
		panic(err)
	}
	feesTreasury := k.distrKeeper.GetFeesTreasury(ctx)
	feesTreasury = feesTreasury.Add(treasurySendAmount...)
	k.distrKeeper.SetFeesTreasury(ctx, feesTreasury)

For KEX tokens it's burnt. For non-KEX tokens, it's sent to fees treasury that can be controlled by governance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium x/basket Basket module x/slashing Slashing module
Projects
None yet
Development

No branches or pull requests

2 participants