Skip to content

Commit

Permalink
final version of Tax2Gas
Browse files Browse the repository at this point in the history
  • Loading branch information
phamminh0811 committed Aug 2, 2024
1 parent eed10ea commit e584267
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion app/upgrades/v9/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ func CreateV9UpgradeHandler(
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// set default oracle split
keepers.TreasuryKeeper.SetTaxRate(ctx, sdk.ZeroDec())
keepers.Tax2gasKeeper.SetParams(ctx, tax2gastypes.DefaultParams())

tax2gasParams := tax2gastypes.DefaultParams()
tax2gasParams.GasPrices = sdk.NewDecCoins(
sdk.NewDecCoinFromDec("uluna", sdk.NewDecWithPrec(28325, 3)),
sdk.NewDecCoinFromDec("uusd", sdk.NewDecWithPrec(75, 2)),
)
tax2gasParams.MaxTotalBypassMinFeeMsgGasUsage = 200000
keepers.Tax2gasKeeper.SetParams(ctx, tax2gasParams)
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
8 changes: 4 additions & 4 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ func (s *IntegrationTestSuite) TestFeeTaxGrant() {

s.Require().Equal(balanceTest1, transferCoin1)
s.Require().Equal(newValidatorBalance, validatorBalance.Add(transferCoin1))
// addr2 lost 10uluna to pay for grant msg's gas, 100000000 * TaxRate + 1uluna to pay for bank send msg's tx fees,
s.Require().Equal(balanceTest2.Amount, transferAmount1.Sub(initialization.TaxRate.MulInt(transferAmount1).TruncateInt()).SubRaw(4))
// addr2 lost 2uluna to pay for grant msg's gas, 100000000 * TaxRate + 2uluna to pay for bank send msg's tx fees,
s.Require().Equal(balanceTest2.Amount, transferAmount1.Sub(initialization.TaxRate.MulInt(transferAmount1).TruncateInt()).SubRaw(12))

// Test 3: try bank send with no grant
transferAmount2 := sdkmath.NewInt(200000000)
Expand Down Expand Up @@ -292,7 +292,7 @@ func (s *IntegrationTestSuite) TestFeeTaxGrant() {
initialization.TaxRate.MulInt(transferAmount2). // tax amount in the form of terra denom
Mul(initialization.UsdGasPrice.Quo(initialization.TerraGasPrice)). // convert terra denom to usd denom base on gas price
TruncateInt(),
).SubRaw(5), // addr2 lost 2uusd to pay for revoke msg's gas, 2uusd to pay for grant msg's gas, 1uusd to pay for band send msg's gas
).SubRaw(21), // addr2 lost 10uusd to pay for revoke msg's gas, 10uusd to pay for grant msg's gas, 1uusd to pay for band send msg's gas
)
}

Expand Down Expand Up @@ -352,7 +352,7 @@ func (s *IntegrationTestSuite) TestFeeTaxNotSupport() {
transferAmount3 := sdkmath.NewInt(10000000)
transferCoin3 := sdk.NewCoin(initialization.TerraIBCDenom, transferAmount3)

nodeB.BankSend(transferCoin3.String(), test1AddrChainB, test2AddrChainB, []string{}, sdk.NewCoin(initialization.TerraDenom, sdkmath.NewInt(10)))
nodeB.BankSend(transferCoin3.String(), test1AddrChainB, test2AddrChainB, []string{}, sdk.NewCoin(initialization.TerraDenom, sdkmath.NewInt(2)))

newTerraIBCBalance, err := nodeB.QuerySpecificBalance(test1AddrChainB, initialization.TerraIBCDenom)
s.Require().NoError(err)
Expand Down
4 changes: 4 additions & 0 deletions x/tax2gas/post/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ func (tgd Tax2gasPostDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simulate
return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "fees are not enough to pay for gas, need to cover %s gas more, which equal to %q ", gasRemaining.String(), gasRemainingFees)
}
feePayerAccount := tgd.accountKeeper.GetAccount(ctx, feePayer)

if !simulate && taxes.IsZero() {
payableFees = feeCoins
}
err := tgd.bankKeeper.SendCoinsFromAccountToModule(ctx, feePayerAccount.GetAddress(), authtypes.FeeCollectorName, payableFees)
if err != nil {
return ctx, errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
Expand Down

0 comments on commit e584267

Please sign in to comment.