Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(2.11): burn fees #232

Open
wants to merge 3 commits into
base: release/v2.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ import (
"github.com/terra-money/alliance/x/alliance"
allianceclient "github.com/terra-money/alliance/x/alliance/client"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
"github.com/terra-money/core/v2/x/feeburn"
feeshare "github.com/terra-money/core/v2/x/feeshare"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

Expand Down Expand Up @@ -273,6 +274,7 @@ func NewTerraApp(
postHandler := post.NewPostHandler(
post.HandlerOptions{
FeeShareKeeper: app.Keepers.FeeShareKeeper,
FeeBurnKeeper: app.Keepers.FeeBurnKeeper,
BankKeeper: app.Keepers.BankKeeper,
WasmKeeper: app.Keepers.WasmKeeper,
},
Expand Down Expand Up @@ -540,6 +542,7 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
customwasmodule.NewAppModule(appCodec, &app.Keepers.WasmKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.BaseApp.MsgServiceRouter(), app.Keepers.GetSubspace(wasmtypes.ModuleName)),
alliance.NewAppModule(appCodec, app.Keepers.AllianceKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry, app.Keepers.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.Keepers.FeeShareKeeper, app.Keepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
feeburn.NewAppModule(app.Keepers.FeeBurnKeeper),
)

sm.RegisterStoreDecoders()
Expand Down
8 changes: 8 additions & 0 deletions app/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/stretchr/testify/suite"
"github.com/terra-money/alliance/x/alliance"
"github.com/terra-money/core/v2/app"
"github.com/terra-money/core/v2/x/feeburn"
"github.com/terra-money/core/v2/x/feeshare"
"github.com/terra-money/core/v2/x/tokenfactory"

Expand Down Expand Up @@ -205,6 +206,7 @@ func (s *AppGenesisTestSuite) TestMigration() {
"crisis": crisis.AppModule{}.ConsensusVersion(),
"distribution": distribution.AppModule{}.ConsensusVersion(),
"evidence": evidence.AppModule{}.ConsensusVersion(),
"feeburn": feeburn.AppModule{}.ConsensusVersion(),
"feegrant": feegrantmodule.AppModule{}.ConsensusVersion(),
"feeshare": feeshare.AppModule{}.ConsensusVersion(),
"feeibc": ibcfee.AppModule{}.ConsensusVersion(),
Expand Down Expand Up @@ -237,6 +239,7 @@ func (s *AppGenesisTestSuite) TestMigration() {
"crisis": 2,
"distribution": 3,
"evidence": 1,
"feeburn": 1,
"feegrant": 2,
"feeshare": 2,
"feeibc": 1,
Expand Down Expand Up @@ -340,6 +343,11 @@ func (s *AppGenesisTestSuite) TestGenesis() {
"evidence": {
"evidence": []
},
"feeburn": {
"params": {
"enable_fee_burn": true
}
},
"feegrant": {
"allowances": []
},
Expand Down
12 changes: 11 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ import (
alliancekeeper "github.com/terra-money/alliance/x/alliance/keeper"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
custombankkeeper "github.com/terra-money/core/v2/x/bank/keeper"
feeburnkeeper "github.com/terra-money/core/v2/x/feeburn/keeper"
feeburntypes "github.com/terra-money/core/v2/x/feeburn/types"
feesharekeeper "github.com/terra-money/core/v2/x/feeshare/keeper"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

Expand All @@ -109,7 +111,7 @@ var wasmCapabilities = "iterator,staking,stargate,token_factory,cosmwasm_1_1,cos

// module account permissions
var maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
authtypes.FeeCollectorName: {authtypes.Burner},
distrtypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
Expand Down Expand Up @@ -156,6 +158,7 @@ type TerraAppKeepers struct {
TokenFactoryKeeper tokenfactorykeeper.Keeper
AllianceKeeper alliancekeeper.Keeper
FeeShareKeeper feesharekeeper.Keeper
FeeBurnKeeper feeburnkeeper.Keeper
ICQKeeper icqkeeper.Keeper

// IBC hooks
Expand Down Expand Up @@ -509,6 +512,12 @@ func NewTerraAppKeepers(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

keepers.FeeBurnKeeper = feeburnkeeper.NewKeeper(
keys[feeburntypes.StoreKey],
appCodec,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

keepers.FeeShareKeeper = feesharekeeper.NewKeeper(
appCodec,
keys[feesharetypes.StoreKey],
Expand Down Expand Up @@ -571,6 +580,7 @@ func (app *TerraAppKeepers) initParamsKeeper(appCodec codec.BinaryCodec, legacyA
paramsKeeper.Subspace(tokenfactorytypes.ModuleName).WithKeyTable(tokenfactorytypes.ParamKeyTable())
paramsKeeper.Subspace(feesharetypes.ModuleName).WithKeyTable(feesharetypes.ParamKeyTable())
paramsKeeper.Subspace(alliancetypes.ModuleName).WithKeyTable(alliancetypes.ParamKeyTable())
paramsKeeper.Subspace(feeburntypes.ModuleName)

return paramsKeeper
}
Expand Down
3 changes: 2 additions & 1 deletion app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

alliancetypes "github.com/terra-money/alliance/x/alliance/types"
feeburntypes "github.com/terra-money/core/v2/x/feeburn/types"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"

// unnamed import of statik for swagger UI support
Expand All @@ -60,7 +61,7 @@ func (keepers *TerraAppKeepers) GenerateKeys() {
icahosttypes.StoreKey, icacontrollertypes.StoreKey, routertypes.StoreKey,
consensusparamtypes.StoreKey, tokenfactorytypes.StoreKey, wasmtypes.StoreKey,
ibcfeetypes.StoreKey, ibchookstypes.StoreKey, crisistypes.StoreKey,
alliancetypes.StoreKey, feesharetypes.StoreKey, icqtypes.StoreKey,
alliancetypes.StoreKey, feesharetypes.StoreKey, icqtypes.StoreKey, feeburntypes.StoreKey,
)

keepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
ibc "github.com/cosmos/ibc-go/v7/modules/core"
alliancetypes "github.com/terra-money/alliance/x/alliance/types"
"github.com/terra-money/core/v2/x/feeburn"
feeburntypes "github.com/terra-money/core/v2/x/feeburn/types"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

Expand Down Expand Up @@ -116,6 +118,7 @@ var ModuleBasics = module.NewBasicManager(
consensus.AppModuleBasic{},
alliance.AppModuleBasic{},
feeshare.AppModuleBasic{},
feeburn.AppModuleBasic{},
icq.AppModuleBasic{},
)

Expand Down Expand Up @@ -154,6 +157,7 @@ func appModules(app *TerraApp, encodingConfig terrappsparams.EncodingConfig, ski
alliance.NewAppModule(app.appCodec, app.Keepers.AllianceKeeper, app.Keepers.StakingKeeper, app.Keepers.AccountKeeper, app.Keepers.BankKeeper, app.interfaceRegistry, app.GetSubspace(alliancetypes.ModuleName)),
feeshare.NewAppModule(app.Keepers.FeeShareKeeper, app.Keepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
icq.NewAppModule(app.Keepers.ICQKeeper),
feeburn.NewAppModule(app.Keepers.FeeBurnKeeper),
}
}

Expand Down Expand Up @@ -191,6 +195,7 @@ var initGenesisOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
feeburntypes.ModuleName,
}

var beginBlockersOrder = []string{
Expand Down Expand Up @@ -223,6 +228,7 @@ var beginBlockersOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
feeburntypes.ModuleName,
}

var endBlockerOrder = []string{
Expand Down Expand Up @@ -255,4 +261,5 @@ var endBlockerOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
feeburntypes.ModuleName,
}
6 changes: 6 additions & 0 deletions app/post/post.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package post

import (
feeburnpost "github.com/terra-money/core/v2/x/feeburn/post"
feesharepost "github.com/terra-money/core/v2/x/feeshare/post"
customwasmkeeper "github.com/terra-money/core/v2/x/wasm/keeper"
wasmpost "github.com/terra-money/core/v2/x/wasm/post"
Expand All @@ -12,13 +13,18 @@ type HandlerOptions struct {
FeeShareKeeper feesharepost.FeeShareKeeper
BankKeeper feesharepost.BankKeeper
WasmKeeper customwasmkeeper.Keeper
FeeBurnKeeper feeburnpost.FeeBurnKeeper
}

func NewPostHandler(options HandlerOptions) sdk.PostHandler {

// NOTE: feesharepost handler MUST always run before the wasmpost handler because
// feeshare will distribute the fees between the contracts enabled with feeshare
// and then wasmpost will clean the list of executed contracts in the block.
postDecorators := []sdk.PostDecorator{
feesharepost.NewFeeSharePayoutDecorator(options.FeeShareKeeper, options.BankKeeper, options.WasmKeeper),
wasmpost.NewWasmdDecorator(options.WasmKeeper),
feeburnpost.NewFeeBurnDecorator(options.FeeBurnKeeper, options.BankKeeper),
}

return sdk.ChainPostDecorators(postDecorators...)
Expand Down
4 changes: 4 additions & 0 deletions app/test_helpers/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/suite"
terra_app "github.com/terra-money/core/v2/app"
appparams "github.com/terra-money/core/v2/app/params"
feeburntypes "github.com/terra-money/core/v2/x/feeburn/types"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

Expand Down Expand Up @@ -75,6 +76,9 @@ func (s *AppTestSuite) Setup() {
err = s.App.Keepers.TokenFactoryKeeper.SetParams(s.Ctx, tokenfactorytypes.DefaultParams())
s.Require().NoError(err)

err = s.App.Keepers.FeeBurnKeeper.SetParams(s.Ctx, feeburntypes.DefaultParams())
s.Require().NoError(err)

err = s.FundModule(authtypes.FeeCollectorName, sdk.NewCoins(sdk.NewCoin("uluna", sdk.NewInt(1000)), sdk.NewCoin("utoken", sdk.NewInt(500))))
s.Require().NoError(err)

Expand Down
8 changes: 8 additions & 0 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
v2_7 "github.com/terra-money/core/v2/app/upgrades/v2.7"
v2_8 "github.com/terra-money/core/v2/app/upgrades/v2.8"
v2_9 "github.com/terra-money/core/v2/app/upgrades/v2.9"
feeburntypes "github.com/terra-money/core/v2/x/feeburn/types"
feesharetypes "github.com/terra-money/core/v2/x/feeshare/types"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

Expand Down Expand Up @@ -123,5 +124,12 @@
} else if upgradeInfo.Name == terraappconfig.Upgrade2_9 && !app.Keepers.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{Deleted: []string{"builder"}}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
} else if upgradeInfo.Name == terraappconfig.Upgrade2_9 && !app.Keepers.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
feeburntypes.StoreKey,
},

Check warning on line 131 in app/upgrade_handler.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade_handler.go#L128-L131

Added lines #L128 - L131 were not covered by tests
}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))

Check warning on line 133 in app/upgrade_handler.go

View check run for this annotation

Codecov / codecov/patch

app/upgrade_handler.go#L133

Added line #L133 was not covered by tests
}
}
8 changes: 4 additions & 4 deletions integration-tests/src/helpers/lcd.connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ export function getLCDClient() {
"test-1": {
lcd: "http://localhost:1316",
chainID: "test-1",
gasPrices: "0.15uluna",
gasAdjustment: 1.5,
gasPrices: "0.015uluna",
gasAdjustment: 1.75,
prefix: "terra"
}
}),
chain2: new LCDClient({
"test-2": {
lcd: "http://localhost:1317",
chainID: "test-2",
gasPrices: "0.15uluna",
gasAdjustment: 1.5,
gasPrices: "0.015uluna",
gasAdjustment: 1.75,
prefix: "terra"
}
})
Expand Down
9 changes: 5 additions & 4 deletions integration-tests/src/modules/disabled.pob/pob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe("Proposer Builder Module (https://github.com/skip-mev/pob) ", () => {
chainID: "test-1",
accountNumber: accInfo.getAccountNumber(),
sequence: accInfo.getSequenceNumber() + 1,
fee: new Fee(100000, new Coins({ uluna: 100000 })),
fee: new Fee(100000, new Coins({ uluna: 5000 })),
timeoutHeight: parseInt(blockHeight) + 20,
});

Expand All @@ -71,7 +71,7 @@ describe("Proposer Builder Module (https://github.com/skip-mev/pob) ", () => {
chainID: "test-1",
accountNumber: accInfo.getAccountNumber(),
sequence: accInfo.getSequenceNumber(),
fee: new Fee(100000, new Coins({ uluna: 100000 })),
fee: new Fee(100000, new Coins({ uluna: 5000 })),
timeoutHeight: parseInt(blockHeight) + 20,
});

Expand All @@ -83,18 +83,19 @@ describe("Proposer Builder Module (https://github.com/skip-mev/pob) ", () => {
let buildTx = await wallet11.createAndSignTx({
msgs: [MsgAuctionBid.fromData({
"@type": "/pob.builder.v1.MsgAuctionBid",
bid: { amount: "100000", denom: "uluna" },
bid: { amount: "120000", denom: "uluna" },
bidder: accounts.pobMnemonic1.accAddress("terra"),
transactions: [secondSignedSendTx.toBytes(), firstSignedSendTx.toBytes()]
})],
memo: "Build block",
chainID: "test-1",
fee: new Fee(100000, new Coins({ uluna: 100000 })),
fee: new Fee(125000, new Coins({ uluna: 10000 })),
timeoutHeight: parseInt(blockHeight) + 20,
});
const result = await LCD.chain1.tx.broadcastSync(buildTx, "test-1");
await blockInclusion();
const txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1");
console.log(JSON.stringify(txResult))
expect(txResult.logs).toBeDefined();
// Recover the transactions hashes from the bundled transactions
// to query the respective transaction data and check there are two
Expand Down
51 changes: 51 additions & 0 deletions integration-tests/src/modules/feeburn/feeburn.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Coins, Fee, MnemonicKey, MsgSend } from "@terra-money/feather.js";
import { getMnemonics, getLCDClient, blockInclusion } from "../../helpers";

describe("FeeBurn Module (https://github.com/terra-money/core/tree/release/v2.9/x/feeburn) ", () => {
// Prepare environment clients, accounts and wallets
const LCD = getLCDClient();
const accounts = getMnemonics();
const wallet = LCD.chain1.wallet(accounts.mnemonic2);
const randomAddress = new MnemonicKey().accAddress("terra");

test('Must burn unused TX Fees', async () => {
const sendTx = await wallet.createAndSignTx({
msgs: [new MsgSend(
wallet.key.accAddress("terra"),
randomAddress,
new Coins({ uluna: 1 }),
)],
chainID: "test-1",
fee: new Fee(200_000, new Coins({ uluna: 3_000 })),
});

const result = await LCD.chain1.tx.broadcastSync(sendTx, "test-1");
await blockInclusion();
const txResult = await LCD.chain1.tx.txInfo(result.txhash, "test-1");
const eventsLength = txResult.events.length;
expect([txResult.events[eventsLength - 2], txResult.events[eventsLength - 1]])
.toStrictEqual([{
"type": "burn",
"attributes": [{
"key": "burner",
"value": "terra17xpfvakm2amg962yls6f84z3kell8c5lkaeqfa",
"index": true
}, {
"key": "amount",
"value": "1768uluna",
"index": true
}]
}, {
"type": "terra.feeburn.v1.FeeBurnEvent",
"attributes": [{
"key": "burn_rate",
"value": "\"0.589615000000000000\"",
"index": true
}, {
"key": "fees_burn",
"value": "[{\"denom\":\"uluna\",\"amount\":\"1768\"}]",
"index": true
}]
}]);
});
});
14 changes: 4 additions & 10 deletions integration-tests/src/teardown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { execSync } from 'child_process';
import path from 'path';

module.exports = async () => {
try {
const pathToDataDir = path.join(__dirname, "/test-data");
execSync("pkill relayer")
execSync("pkill terrad")
execSync("pkill terrad")
execSync(`rm -r ${pathToDataDir}`)
}
catch (e) {
console.log(e)
}
const pathToDataDir = path.join(__dirname, "/test-data");
execSync("pkill relayer")
execSync("pkill terrad")
execSync(`rm -r ${pathToDataDir}`)
}
19 changes: 19 additions & 0 deletions proto/terra/feeburn/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
syntax = "proto3";
package terra.feeburn.v1;

import "cosmos/base/v1beta1/coin.proto";
import "gogoproto/gogo.proto";

option go_package = "github.com/terra-money/core/v2/x/feeburn/types";

// Event fired when fees are burned with the amount of fees burned
message FeeBurnEvent {
// Amount of the payout
repeated cosmos.base.v1beta1.Coin fees_burn = 1 [(gogoproto.nullable) = false];

// Calculated % of the fees burned before truncating the decimal
string burn_rate = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
Loading
Loading