Skip to content

Commit

Permalink
fix: x/gov ChargeDeposit delete deposits (#15033)
Browse files Browse the repository at this point in the history
  • Loading branch information
facundomedica authored Feb 14, 2023
1 parent 86eca4c commit dfb3271
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions x/gov/keeper/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,22 +174,22 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
rate := sdk.MustNewDecFromStr(proposalCancelRate)
var cancellationCharges sdk.Coins

for _, deposits := range keeper.GetDeposits(ctx, proposalID) {
depositerAddress := sdk.MustAccAddressFromBech32(deposits.Depositor)
for _, deposit := range keeper.GetDeposits(ctx, proposalID) {
depositerAddress := sdk.MustAccAddressFromBech32(deposit.Depositor)
var remainingAmount sdk.Coins

for _, deposit := range deposits.Amount {
burnAmount := sdk.NewDecFromInt(deposit.Amount).Mul(rate).TruncateInt()
for _, coins := range deposit.Amount {
burnAmount := sdk.NewDecFromInt(coins.Amount).Mul(rate).TruncateInt()
// remaining amount = deposits amount - burn amount
remainingAmount = remainingAmount.Add(
sdk.NewCoin(
deposit.Denom,
deposit.Amount.Sub(burnAmount),
coins.Denom,
coins.Amount.Sub(burnAmount),
),
)
cancellationCharges = cancellationCharges.Add(
sdk.NewCoin(
deposit.Denom,
coins.Denom,
burnAmount,
),
)
Expand All @@ -203,6 +203,8 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
return err
}
}

store.Delete(types.DepositKey(deposit.ProposalId, depositerAddress))
}

// burn the cancellation fee or sent the cancellation charges to destination address.
Expand Down Expand Up @@ -232,8 +234,6 @@ func (keeper Keeper) ChargeDeposit(ctx sdk.Context, proposalID uint64, destAddre
}
}

store.Delete(types.DepositsKey(proposalID))

return nil
}

Expand Down

0 comments on commit dfb3271

Please sign in to comment.