Skip to content

Commit

Permalink
feat(v2.9): burn fees
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Dec 14, 2023
1 parent 93b2cd0 commit 60068e6
Show file tree
Hide file tree
Showing 37 changed files with 3,049 additions and 32 deletions.
3 changes: 3 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 @@ -285,6 +286,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 @@ -570,6 +572,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
15 changes: 12 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ import (
tokenfactorykeeper "github.com/terra-money/core/v2/x/tokenfactory/keeper"
tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

pobkeeper "github.com/skip-mev/pob/x/builder/keeper"
pobtype "github.com/skip-mev/pob/x/builder/types"
"github.com/terra-money/alliance/x/alliance"
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"

pobkeeper "github.com/skip-mev/pob/x/builder/keeper"

terraappconfig "github.com/terra-money/core/v2/app/config"
// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
Expand All @@ -112,7 +113,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 @@ -160,6 +161,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 @@ -516,6 +518,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 @@ -588,6 +596,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
6 changes: 3 additions & 3 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ import (

tokenfactorytypes "github.com/terra-money/core/v2/x/tokenfactory/types"

pobtype "github.com/skip-mev/pob/x/builder/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"

pobtype "github.com/skip-mev/pob/x/builder/types"

// unnamed import of statik for swagger UI support
_ "github.com/terra-money/core/v2/client/docs/statik"
)
Expand All @@ -62,7 +62,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, pobtype.StoreKey, icqtypes.StoreKey,
alliancetypes.StoreKey, feesharetypes.StoreKey, feeburntypes.StoreKey, pobtype.StoreKey, icqtypes.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 @@ -119,6 +121,7 @@ var ModuleBasics = module.NewBasicManager(
consensus.AppModuleBasic{},
alliance.AppModuleBasic{},
feeshare.AppModuleBasic{},
feeburn.AppModuleBasic{},
pob.AppModuleBasic{},
icq.AppModuleBasic{},
)
Expand Down Expand Up @@ -159,6 +162,7 @@ func appModules(app *TerraApp, encodingConfig terrappsparams.EncodingConfig, ski
feeshare.NewAppModule(app.Keepers.FeeShareKeeper, app.Keepers.AccountKeeper, app.GetSubspace(feesharetypes.ModuleName)),
pob.NewAppModule(app.appCodec, app.Keepers.BuilderKeeper),
icq.NewAppModule(app.Keepers.ICQKeeper),
feeburn.NewAppModule(app.Keepers.FeeBurnKeeper),
}
}

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

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

Expand Down Expand Up @@ -262,5 +268,6 @@ var endBlockerOrder = []string{
feesharetypes.ModuleName,
consensusparamtypes.ModuleName,
icqtypes.ModuleName,
feeburntypes.ModuleName,
pobtype.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
8 changes: 8 additions & 0 deletions app/upgrade_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
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 @@ -143,5 +144,12 @@ func (app *TerraApp) RegisterUpgradeStores() {
},
}
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,
},
}
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
14 changes: 7 additions & 7 deletions integration-tests/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"typescript": "^5.2.2"
},
"dependencies": {
"@terra-money/feather.js": "^2.0.0-beta.14",
"@terra-money/feather.js": "^2.0.0-beta.15",
"moment": "^2.29.4"
}
}
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/pob/pob.test.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
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}`)
}
15 changes: 15 additions & 0 deletions proto/terra/feeburn/v1/events.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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
];
}
13 changes: 13 additions & 0 deletions proto/terra/feeburn/v1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
syntax = "proto3";
package terra.feeburn.v1;

import "terra/feeburn/v1/params.proto";
import "gogoproto/gogo.proto";

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

// GenesisState defines the feeburn module's genesis state.
message GenesisState {
// params defines the paramaters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}
11 changes: 11 additions & 0 deletions proto/terra/feeburn/v1/params.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";
package terra.feeburn.v1;

import "cosmos_proto/cosmos.proto";

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

// Params defines the parameters for the feeburn module
message Params {
bool enable_fee_burn = 1;
}
25 changes: 25 additions & 0 deletions proto/terra/feeburn/v1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
syntax = "proto3";
package terra.feeburn.v1;

import "terra/feeburn/v1/params.proto";
import "google/api/annotations.proto";
import "gogoproto/gogo.proto";

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

// Query defines the gRPC querier service.
service Query {
// Params retrieves the FeeShare module params
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/terra/feeburn/v1/params";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params is the returned FeeShare parameter
Params params = 1 [ (gogoproto.nullable) = false ];
}
Loading

0 comments on commit 60068e6

Please sign in to comment.