diff --git a/x/commitment/keeper/commitments.go b/x/commitment/keeper/commitments.go index bb19eb45d..25b571e64 100644 --- a/x/commitment/keeper/commitments.go +++ b/x/commitment/keeper/commitments.go @@ -165,6 +165,7 @@ func (k Keeper) BurnEdenBoost(ctx sdk.Context, creator sdk.AccAddress, denom str amount = amount.Sub(claimedRemovalAmount) if amount.IsZero() { + k.SetCommitments(ctx, commitments) return nil } diff --git a/x/commitment/keeper/commitments_test.go b/x/commitment/keeper/commitments_test.go index af81f61f5..a893bb9bd 100644 --- a/x/commitment/keeper/commitments_test.go +++ b/x/commitment/keeper/commitments_test.go @@ -146,13 +146,13 @@ func TestKeeper_BurnEdenBoost(t *testing.T) { { name: "deduct amount is greater than claimed amount", claimedAmount: math.NewInt(100), - committedTokens: math.NewInt(100), - deductAmount: math.NewInt(200), + committedTokens: math.NewInt(0), + deductAmount: math.NewInt(100), expectedError: false, }, { name: "deduct amount is greater than claimed amount with no committed tokens", - claimedAmount: math.NewInt(100), + claimedAmount: math.NewInt(200), committedTokens: math.NewInt(0), deductAmount: math.NewInt(200), expectedError: false, @@ -193,8 +193,14 @@ func TestKeeper_BurnEdenBoost(t *testing.T) { commitments.AddCommittedTokens("denom", tt.committedTokens, 0) keeper.SetCommitments(ctx, commitments) + comm := keeper.GetCommitments(ctx, addr) + totalPrev := comm.Claimed.AmountOf("denom").Add(comm.GetCommittedAmountForDenom("denom")) + // Test BurnEdenBoost err := keeper.BurnEdenBoost(ctx, addr, "denom", tt.deductAmount) + comm = keeper.GetCommitments(ctx, addr) + total := comm.Claimed.AmountOf("denom").Add(comm.GetCommittedAmountForDenom("denom")) + assert.Equal(t, tt.deductAmount.String(), totalPrev.Sub(total).String()) if tt.expectedError { assert.Error(t, err) } else { diff --git a/x/estaking/keeper/hooks_staking.go b/x/estaking/keeper/hooks_staking.go index bb863bfff..9b0182c15 100644 --- a/x/estaking/keeper/hooks_staking.go +++ b/x/estaking/keeper/hooks_staking.go @@ -2,6 +2,7 @@ package keeper import ( "context" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -19,6 +20,7 @@ func (k Keeper) AfterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress, } func (k Keeper) BeforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress) error { + k.SetElysStakeChange(ctx, delAddr) return nil } diff --git a/x/estaking/keeper/keeper_burn_edenB.go b/x/estaking/keeper/keeper_burn_edenB.go index f587a395f..f2de81b17 100644 --- a/x/estaking/keeper/keeper_burn_edenB.go +++ b/x/estaking/keeper/keeper_burn_edenB.go @@ -48,10 +48,22 @@ func (k Keeper) BurnEdenBFromElysUnstaking(ctx sdk.Context, delegator sdk.AccAdd if edenCommittedAndElysStakedDec.GT(math.LegacyZeroDec()) { edenBToBurn = unstakedElysDec.Quo(edenCommittedAndElysStakedDec).MulInt(totalEdenB) } + if edenCommittedAndElysStakedDec.IsZero() { + edenBToBurn = math.LegacyNewDecFromInt(totalEdenB) + } if edenBToBurn.IsZero() { return nil } + // Add event for burning edenB + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeEvtBurnEdenB, + sdk.NewAttribute(types.AttributeDelegatorAddress, delegator.String()), + sdk.NewAttribute(types.AttributeAmount, edenBToBurn.String()), + ), + ) + // Burn EdenB in commitment module err = k.commKeeper.BurnEdenBoost(ctx, delegator, ptypes.EdenB, edenBToBurn.TruncateInt()) if err != nil { @@ -89,10 +101,23 @@ func (k Keeper) BurnEdenBFromEdenUncommitted(ctx sdk.Context, delegator sdk.AccA if edenCommittedAndElysStakedDec.GT(math.LegacyZeroDec()) { edenBToBurn = unclaimedAmtDec.Quo(edenCommittedAndElysStakedDec).MulInt(totalEdenB) } + if edenCommittedAndElysStakedDec.IsZero() { + edenBToBurn = math.LegacyNewDecFromInt(totalEdenB) + } + if edenBToBurn.IsZero() { return nil } + // Add event for burning edenB + ctx.EventManager().EmitEvent( + sdk.NewEvent( + types.TypeEvtBurnEdenB, + sdk.NewAttribute(types.AttributeDelegatorAddress, delegator.String()), + sdk.NewAttribute(types.AttributeAmount, edenBToBurn.String()), + ), + ) + // Burn EdenB in commitment module err = k.commKeeper.BurnEdenBoost(ctx, delegator, ptypes.EdenB, edenBToBurn.TruncateInt()) return err diff --git a/x/estaking/types/events.go b/x/estaking/types/events.go index ca8f8f185..3c5af7f96 100644 --- a/x/estaking/types/events.go +++ b/x/estaking/types/events.go @@ -2,6 +2,7 @@ package types const ( TypeEvtWithdrawReward = "withdraw_reward" + TypeEvtBurnEdenB = "burn_edenB" AttributeDelegatorAddress = "delegator_address" AttributeValidatorAddress = "validator_address"