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(x/rewards): Add fee burn #422

Merged
merged 6 commits into from
Jul 27, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Contains all the PRs that improved the code without changing the behaviours.

### Added

- [#422](https://github.com/archway-network/archway/pull/422/) - Add fee burning of tx fees not distributed to contracts.
- [#419](https://github.com/archway-network/archway/pull/419) - Easily run localnet via make
- [#421](https://github.com/archway-network/archway/pull/421) - Add archwayd darwin binaries

Expand Down
7 changes: 4 additions & 3 deletions app/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import (
type HandlerOptions struct {
ante.HandlerOptions

IBCKeeper *ibckeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
IBCKeeper *ibckeeper.Keeper
WasmConfig *wasmTypes.WasmConfig
RewardsAnteBankKeeper rewardsAnte.BankKeeper

TXCounterStoreKey sdk.StoreKey

Expand Down Expand Up @@ -76,7 +77,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
// Custom Archway interceptor to track new transactions
trackingAnte.NewTxGasTrackingDecorator(options.TrackingKeeper),
// Custom Archway fee deduction, which splits fees between x/rewards and x/auth fee collector
rewardsAnte.NewDeductFeeDecorator(options.Codec, options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.RewardsKeeper),
rewardsAnte.NewDeductFeeDecorator(options.Codec, options.AccountKeeper, options.RewardsAnteBankKeeper, options.FeegrantKeeper, options.RewardsKeeper),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
13 changes: 7 additions & 6 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ var (
// module account permissions
maccPerms = map[string][]string{
rewardsTypes.ContractRewardCollector: nil,
authtypes.FeeCollectorName: nil,
authtypes.FeeCollectorName: {authtypes.Burner},
distrtypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter},
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
Expand Down Expand Up @@ -799,11 +799,12 @@ func NewArchwayApp(
SignModeHandler: encodingConfig.TxConfig.SignModeHandler(),
SigGasConsumer: ante.DefaultSigVerificationGasConsumer,
},
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: keys[wasm.StoreKey],
TrackingKeeper: app.TrackingKeeper,
RewardsKeeper: app.RewardsKeeper,
IBCKeeper: app.IBCKeeper,
WasmConfig: &wasmConfig,
RewardsAnteBankKeeper: app.BankKeeper,
TXCounterStoreKey: keys[wasm.StoreKey],
TrackingKeeper: app.TrackingKeeper,
RewardsKeeper: app.RewardsKeeper,
},
)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions docs/adr/ADR-007-fee-burning.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# ADR-007 – Introduction of fee burning

Date: 2023-07-27

## Status

Implemented

## Context

To better accommodate inflationary rewards increases within the Archway protocol, we are introducing transaction (TX)
fee burning. This strategy permits us to offer more inflationary rewards to contracts safely, while simultaneously
incinerating the TX fees which were previously distributed to validators and stakers.

## Decision

We plan to modify the Fee Deduction ante handler to burn the fees formerly allocated to validators and stakers. This
change involves extending the behavior of the FeeDeduction ante handler. Currently, the FeeDeduction ante handler
dispatches the TX fees (which are not dedicated to contracts) to the fee collector module address.
This address then becomes a rewards pool for staking rewards, managed by the Distribution module. Our new approach is to
burn these funds as soon as the FeeDeduction handler sends them to the fee collector.

## Consequences

### Positive
a) This change enables a safe increase of inflationary rewards for contracts, mitigating the risk of potential spam attacks and economic imbalances.
b) It establishes a transparent performance metric for Archway. The more fees burnt, the more value is generated for the protocol.

### Negative

a) Validators and stakers will experience a decrease in their rewards.
b) TX consume slightly more gas (12000gas more approximately), as they will need to pay for the gas used to burn the fees.
2 changes: 1 addition & 1 deletion e2e/txfees_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// Test configures a chain based on the Archway mainnet parameters.
func (s *E2ETestSuite) TestTxFees() {
const (
txGasLimit = 201_000
txGasLimit = 212_000
txFeeAmtIncrement = 1000
)

Expand Down
13 changes: 11 additions & 2 deletions x/rewards/ante/fee_deduction.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@ import (

var _ sdk.AnteDecorator = DeductFeeDecorator{}

type BankKeeper interface {
authTypes.BankKeeper
BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) error
}

// DeductFeeDecorator deducts fees from the first signer of the tx.
// If the first signer does not have the funds to pay for the fees, return with InsufficientFunds error.
// Call next AnteHandler if fees successfully deducted.
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator.
type DeductFeeDecorator struct {
codec codec.BinaryCodec
ak ante.AccountKeeper
bankKeeper authTypes.BankKeeper
bankKeeper BankKeeper
feegrantKeeper ante.FeegrantKeeper
rewardsKeeper RewardsKeeperExpected
}

// NewDeductFeeDecorator returns a new DeductFeeDecorator instance.
func NewDeductFeeDecorator(codec codec.BinaryCodec, ak ante.AccountKeeper, bk authTypes.BankKeeper, fk ante.FeegrantKeeper, rk RewardsKeeperExpected) DeductFeeDecorator {
func NewDeductFeeDecorator(codec codec.BinaryCodec, ak ante.AccountKeeper, bk BankKeeper, fk ante.FeegrantKeeper, rk RewardsKeeperExpected) DeductFeeDecorator {
return DeductFeeDecorator{
codec: codec,
ak: ak,
Expand Down Expand Up @@ -138,6 +143,10 @@ func (dfd DeductFeeDecorator) deductFees(ctx sdk.Context, tx sdk.Tx, acc authTyp
if err := dfd.bankKeeper.SendCoinsFromAccountToModule(ctx, acc.GetAddress(), authTypes.FeeCollectorName, authFees); err != nil {
return sdkErrors.Wrapf(sdkErrors.ErrInsufficientFunds, err.Error())
}
// burn the auth fees.
if err := dfd.bankKeeper.BurnCoins(ctx, authTypes.FeeCollectorName, authFees); err != nil {
return sdkErrors.Wrapf(sdkErrors.ErrInsufficientFunds, err.Error())
}
}

if !rewardsFees.Empty() {
Expand Down
4 changes: 2 additions & 2 deletions x/rewards/ante/fee_deduction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRewardsFeeDeductionAnteHandler(t *testing.T) {
mockWasmExecuteMsg,
},
rewardRecordExpected: true,
feeCollectorBalanceDiffExpected: "500stake",
feeCollectorBalanceDiffExpected: "0stake", // fees are burnt
rewardsBalanceDiffExpected: "500stake",
},
{
Expand All @@ -66,7 +66,7 @@ func TestRewardsFeeDeductionAnteHandler(t *testing.T) {
mockWasmExecuteMsg,
},
rewardRecordExpected: true,
feeCollectorBalanceDiffExpected: "900stake,450uarch",
feeCollectorBalanceDiffExpected: "0stake,0uarch", // fees are burnt
rewardsBalanceDiffExpected: "100stake,50uarch",
},
{
Expand Down
Loading