From f286f6df2f42be57095839064df42de0dd3015e5 Mon Sep 17 00:00:00 2001 From: StrathCole Date: Fri, 8 Nov 2024 00:32:19 +0100 Subject: [PATCH] - fix subtraction leading to negative amount --- custom/auth/ante/fee.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/custom/auth/ante/fee.go b/custom/auth/ante/fee.go index 6fd52fdd..40765cf9 100644 --- a/custom/auth/ante/fee.go +++ b/custom/auth/ante/fee.go @@ -179,13 +179,17 @@ func (fd FeeDecorator) checkDeductFee(ctx sdk.Context, feeTx sdk.FeeTx, taxes sd deductFees := feesOrTax.Sub(taxes...) // feesOrTax can never be lower than taxes if !nonTaxableTaxes.IsZero() { // if we have non-taxable taxes, we need to subtract them from the fees to be deducted - deductFees = deductFees.Sub(nonTaxableTaxes...) - - // add the non-taxable taxes to the events - events = append(events, sdk.NewEvent( - taxtypes.EventTypeTaxRefund, - sdk.NewAttribute(taxtypes.AttributeKeyTaxAmount, nonTaxableTaxes.String()), - )) + for _, coin := range nonTaxableTaxes { + if deductFees.AmountOf(coin.Denom).GTE(coin.Amount) { + deductFees = deductFees.Sub(coin) + + // add the non-taxable taxes to the events + events = append(events, sdk.NewEvent( + taxtypes.EventTypeTaxRefund, + sdk.NewAttribute(taxtypes.AttributeKeyTaxAmount, coin.String()), + )) + } + } } ctx = ctx.WithValue(taxtypes.ContextKeyTaxDue, taxes).WithValue(taxtypes.ContextKeyTaxPayer, deductFeesFrom.String())