Skip to content

Commit

Permalink
feat(treasury): split the burn tax to the distribution module (#272)
Browse files Browse the repository at this point in the history
Co-authored-by: Inon Man <121477599+inon-man@users.noreply.github.com>
  • Loading branch information
alchemist-ti and inon-man authored Jul 21, 2023
1 parent a558deb commit 77547ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ Types of changes (Stanzas):
Ref: https://keepachangelog.com/en/1.0.0/
-->
# Changelog

## [Unreleased]

### State Machine Breaking

* (treasury) [#272](https://github.com/classic-terra/core/pull/272) Split the burn tax to the distribution module

## [v2.1.2](https://github.com/classic-terra/core/releases/tag/v2.1.2)

### Features
Expand Down
14 changes: 3 additions & 11 deletions custom/auth/ante/burntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,14 @@ func (btfd BurnTaxFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate
burnSplitRate := btfd.treasuryKeeper.GetBurnSplitRate(ctx)

if burnSplitRate.IsPositive() {
communityDeltaCoins := sdk.NewCoins()
distributionDeltaCoins := sdk.NewCoins()

for _, taxCoin := range taxes {
splitcoinAmount := burnSplitRate.MulInt(taxCoin.Amount).RoundInt()
communityDeltaCoins = communityDeltaCoins.Add(sdk.NewCoin(taxCoin.Denom, splitcoinAmount))
distributionDeltaCoins = distributionDeltaCoins.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())
}
taxes = taxes.Sub(distributionDeltaCoins)
}

if !taxes.IsZero() {
Expand Down
34 changes: 14 additions & 20 deletions custom/auth/ante/burntax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
tk := suite.app.TreasuryKeeper
bk := suite.app.BankKeeper
dk := suite.app.DistrKeeper
mfd := ante.NewBurnTaxFeeDecorator(suite.app.AccountKeeper, tk, bk, dk)
ak := suite.app.AccountKeeper
mfd := ante.NewBurnTaxFeeDecorator(ak, tk, bk, dk)
antehandler := sdk.ChainAnteDecorators(mfd)

// Set the blockheight past the burn tax height block
Expand Down Expand Up @@ -62,7 +63,7 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {

// Send taxes to fee collector to simulate DeductFeeDecorator antehandler
taxes := suite.DeductFees(sendAmount)
feeCollector := suite.app.AccountKeeper.GetModuleAccount(suite.ctx, types.FeeCollectorName)
feeCollector := ak.GetModuleAccount(suite.ctx, types.FeeCollectorName)

// expected: fee collector = taxes
amountFeeBefore := bk.GetAllBalances(suite.ctx, feeCollector.GetAddress())
Expand All @@ -71,32 +72,30 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
totalSupplyBefore, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{})
require.NoError(err)
fmt.Printf(
"Before: TotalSupply %v, Community %v, FeeCollector %v\n",
"Before: TotalSupply %v, FeeCollector %v\n",
totalSupplyBefore,
dk.GetFeePool(suite.ctx).CommunityPool,
amountFeeBefore,
)

// send tx to BurnTaxFeeDecorator antehandler
_, err = antehandler(suite.ctx, tx, false)
require.NoError(err)

communityPoolAfter := dk.GetFeePool(suite.ctx).CommunityPool
// burn the burn account
tk.BurnCoinsFromBurnAccount(suite.ctx)

feeCollectorAfter := sdk.NewDecCoinsFromCoins(bk.GetAllBalances(suite.ctx, ak.GetModuleAddress(types.FeeCollectorName))...)
burnTax := sdk.NewDecCoinsFromCoins(taxes...)

if burnSplitRate.IsPositive() {
splitTaxesDecCoins := burnTax.MulDec(burnSplitRate)
distributionDeltaCoins := burnTax.MulDec(burnSplitRate)

// expected: community pool 50%
require.Equal(communityPoolAfter, splitTaxesDecCoins)

fmt.Printf("BurnSplitRate %v, splitTaxes %v\n", burnSplitRate, splitTaxesDecCoins)
burnTax = burnTax.Sub(splitTaxesDecCoins)
fmt.Printf("BurnSplitRate %v, DistributionDeltaCoins %v\n", burnSplitRate, distributionDeltaCoins)
require.Equal(feeCollectorAfter, distributionDeltaCoins)
burnTax = burnTax.Sub(distributionDeltaCoins)
}

// burn the burn account
tk.BurnCoinsFromBurnAccount(suite.ctx)

totalSupplyAfter, _, err := bk.GetPaginatedTotalSupply(suite.ctx, &query.PageRequest{})
require.NoError(err)
if !burnTax.Empty() {
Expand All @@ -107,15 +106,10 @@ func (suite *AnteTestSuite) runSplitTaxTest(burnSplitRate sdk.Dec) {
)
}

amountFeeAfter := bk.GetAllBalances(suite.ctx, feeCollector.GetAddress())
// expected: fee collector = 0
require.True(amountFeeAfter.Empty())

fmt.Printf(
"After: TotalSupply %v, Community %v, FeeCollector %v\n",
"After: TotalSupply %v, FeeCollector %v\n",
totalSupplyAfter,
communityPoolAfter,
amountFeeAfter,
feeCollectorAfter,
)
}

Expand Down

0 comments on commit 77547ce

Please sign in to comment.