-
Notifications
You must be signed in to change notification settings - Fork 39
/
burntax.go
92 lines (77 loc) · 2.85 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ante
import (
treasury "github.com/classic-terra/core/x/treasury/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
cosmosante "github.com/cosmos/cosmos-sdk/x/auth/ante"
"github.com/cosmos/cosmos-sdk/x/auth/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 {
accountKeeper cosmosante.AccountKeeper
treasuryKeeper TreasuryKeeper
bankKeeper BankKeeper
distrKeeper DistrKeeper
}
// NewBurnTaxFeeDecorator returns new tax fee decorator instance
func NewBurnTaxFeeDecorator(accountKeeper cosmosante.AccountKeeper, treasuryKeeper TreasuryKeeper, bankKeeper BankKeeper, distrKeeper DistrKeeper) BurnTaxFeeDecorator {
return BurnTaxFeeDecorator{
accountKeeper: accountKeeper,
treasuryKeeper: treasuryKeeper,
bankKeeper: bankKeeper,
distrKeeper: distrKeeper,
}
}
// 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() {
burnSplitRate := btfd.treasuryKeeper.GetBurnSplitRate(ctx)
if burnSplitRate.IsPositive() {
communityDeltaCoins := sdk.NewCoins()
for _, taxCoin := range taxes {
splitcoinAmount := burnSplitRate.MulInt(taxCoin.Amount).RoundInt()
communityDeltaCoins = communityDeltaCoins.Add(sdk.NewCoin(taxCoin.Denom, splitcoinAmount))
}
taxes = taxes.Sub(communityDeltaCoins)
if err = btfd.distrKeeper.FundCommunityPool(
ctx,
communityDeltaCoins,
btfd.accountKeeper.GetModuleAddress(types.FeeCollectorName),
); err != nil {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
}
if !taxes.IsZero() {
if err = btfd.bankKeeper.SendCoinsFromModuleToModule(
ctx,
types.FeeCollectorName,
treasury.BurnModuleName,
taxes,
); err != nil {
return ctx, sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
}
}
}
return next(ctx, tx, simulate)
}