-
Notifications
You must be signed in to change notification settings - Fork 292
/
burntax.go
61 lines (50 loc) · 1.91 KB
/
burntax.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package ante
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/types"
treasury "github.com/terra-money/core/x/treasury/types"
)
// TaxPowerUpgradeHeight is when taxes are allowed to go into effect
// This will still need a parameter change proposal, but can be activated
// anytime after this height
const TaxPowerUpgradeHeight = 9346889
// BurnTaxFeeDecorator will immediately burn the collected Tax
type BurnTaxFeeDecorator struct {
treasuryKeeper TreasuryKeeper
bankKeeper BankKeeper
}
// NewBurnTaxFeeDecorator returns new tax fee decorator instance
func NewBurnTaxFeeDecorator(treasuryKeeper TreasuryKeeper, bankKeeper BankKeeper) BurnTaxFeeDecorator {
return BurnTaxFeeDecorator{
treasuryKeeper: treasuryKeeper,
bankKeeper: bankKeeper,
}
}
// AnteHandle handles msg tax fee checking
func (btfd BurnTaxFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// Do not proceed if you are below this block height
currHeight := ctx.BlockHeight()
if currHeight < TaxPowerUpgradeHeight {
return next(ctx, tx, simulate)
}
feeTx, ok := tx.(sdk.FeeTx)
if !ok {
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx")
}
msgs := feeTx.GetMsgs()
// At this point we have already run the DeductFees AnteHandler and taken the fees from the sending account
// Now we remove the taxes from the gas reward and immediately burn it
if !simulate {
// Compute taxes again.
taxes := FilterMsgAndComputeTax(ctx, btfd.treasuryKeeper, msgs...)
// Record tax proceeds
if !taxes.IsZero() {
err = btfd.bankKeeper.SendCoinsFromModuleToModule(ctx, types.FeeCollectorName, treasury.BurnModuleName, taxes)
if err != nil {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
}
}
return next(ctx, tx, simulate)
}