Skip to content

Commit

Permalink
updated tax module to calculate taxes off new style gas fees
Browse files Browse the repository at this point in the history
  • Loading branch information
scottburch committed Jan 28, 2021
1 parent 9edc064 commit 9bdd459
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app/ante/NewDeductFeeDecorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ante

import (
"fmt"
"github.com/bluzelle/curium/app/ante/feeCalculator"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/exported"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
Expand Down Expand Up @@ -39,7 +40,7 @@ func NewDeductFeeDecorator(ak keeper.AccountKeeper, sk types.SupplyKeeper) Deduc
}

func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
gasFeeCoins := CalculateGasFee(tx, ctx)
gasFeeCoins := feeCalculator.CalculateGasFee(tx, ctx)

feeTx, ok := tx.(FeeTx)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ante
package feeCalculator

import (
"fmt"
Expand Down
24 changes: 7 additions & 17 deletions x/tax/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ante

import (
"github.com/bluzelle/curium/app/ante/feeCalculator"
"github.com/bluzelle/curium/x/tax"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -55,11 +56,11 @@ func (td TaxDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, nex
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", feePayer)
}

if err := collectTransactionTax(ctx, td, tx, feeTx.GetFee(), feePayer); err != nil {
if err := collectTransactionTax(ctx, td, tx, feeTx.GetFee(), feePayer); err != nil {
return ctx, err
}

if err := collectFeeTax(ctx, td.supplyKeeper, taxInfo.Collector, feeTx.GetFee(), taxInfo.FeeBp); err != nil {
if err := collectFeeTax(ctx, tx, td.supplyKeeper, taxInfo.Collector, taxInfo.FeeBp); err != nil {
return ctx, err
}
}
Expand Down Expand Up @@ -101,23 +102,12 @@ func collectTransactionTax(ctx sdk.Context, dfd TaxDecorator, tx sdk.Tx, fees sd
}


func collectFeeTax( ctx sdk.Context, supplyKeeper types.SupplyKeeper, taxCollectorAcc sdk.AccAddress, fees sdk.Coins, feebp int64) error {
func collectFeeTax( ctx sdk.Context, tx sdk.Tx, supplyKeeper types.SupplyKeeper, taxCollectorAcc sdk.AccAddress, feebp int64) error {

if !fees.IsValid() {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees)
}

taxFees := sdk.Coins{}
for _, fee := range fees {
feeAmt := fee.Amount.Int64() * feebp / 10000

if feeAmt > 0 {
taxFee := sdk.NewInt64Coin(fee.Denom, feeAmt)
taxFees = append(taxFees, taxFee)
}
}
gasFee := feeCalculator.CalculateGasFee(tx, ctx)
taxFees := sdk.NewCoins(sdk.NewInt64Coin("ubnt", gasFee.AmountOf("ubnt").Int64() * feebp / 10000))

if !taxFees.Empty() {
if !taxFees.IsZero() {
err := supplyKeeper.SendCoinsFromModuleToAccount(ctx, authtypes.FeeCollectorName, taxCollectorAcc, taxFees)
if err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
Expand Down

0 comments on commit 9bdd459

Please sign in to comment.