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

Rework of tax to be included in gas #383

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6df1ba0
- initial commit of classic tax module
StrathCole Oct 31, 2023
b5330f8
- upgrade handlers
StrathCole Oct 31, 2023
bbd2516
-
StrathCole Oct 31, 2023
f578b49
- added genesis proto
StrathCole Oct 31, 2023
7ef20c9
- changed proto
StrathCole Oct 31, 2023
51c78ed
- fixed types and init genesis order
StrathCole Oct 31, 2023
540903c
different adjustments and added debug logging
StrathCole Nov 1, 2023
f7c478c
- several fixes
StrathCole Nov 1, 2023
f45cf38
- handle deducting fees
StrathCole Nov 2, 2023
c19bb12
- several fixes
StrathCole Nov 2, 2023
2fe80e6
- fix
StrathCole Nov 2, 2023
bbee581
- handle tax in wasm and deduct tax from coins sent instead of contra…
StrathCole Nov 2, 2023
4776ba5
- smaller fixes
StrathCole Nov 3, 2023
4b323b2
- fixed old tax tests
StrathCole Nov 3, 2023
a78df27
- fixed further tests
StrathCole Nov 3, 2023
1af9865
- add further test and move suite
StrathCole Nov 3, 2023
bfffded
- remove fees on height 0 (genesis transactions)
StrathCole Nov 4, 2023
d41cc6d
Merge remote-tracking branch 'upstream/main' into classictax
StrathCole Nov 5, 2023
b75f526
- added missing grpc registering
StrathCole Nov 8, 2023
edf5723
- added swagger for classictax module
StrathCole Nov 8, 2023
729a011
Merge remote-tracking branch 'upstream/main' into classictax
StrathCole Nov 10, 2023
3cdf8bb
- change exchange rate calculation to gas prices
StrathCole Nov 13, 2023
d18338b
- add burned event to emitted events
StrathCole Nov 19, 2023
26236ab
- linting
StrathCole Nov 20, 2023
a31827b
- gofumpted
StrathCole Nov 20, 2023
0d800ff
- don't use reflection package
StrathCole Nov 20, 2023
720d07d
- gofumpt
StrathCole Nov 21, 2023
7ba7096
- fix upgrade name
StrathCole Nov 21, 2023
c26a79c
- fixed tests
StrathCole Nov 21, 2023
70d2833
Merge remote-tracking branch 'upstream/main' into classictax
StrathCole Nov 29, 2023
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ client/lcd/keys/*
client/docs/statik/statik.go
remote/ansible/testnets
mytestnet
proto/google

# Testing
coverage.txt
Expand Down
7 changes: 6 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ func NewTerraApp(
GovKeeper: app.GovKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: app.GetKey(wasm.StoreKey),
ClassicTaxKeeper: app.ClassicTaxKeeper,
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
},
Expand All @@ -222,7 +223,11 @@ func NewTerraApp(

postHandler, err := custompost.NewPostHandler(
custompost.HandlerOptions{
DyncommKeeper: app.DyncommKeeper,
TreasuryKeeper: app.TreasuryKeeper,
BankKeeper: app.BankKeeper,
OracleKeeper: app.OracleKeeper,
ClassicTaxKeeper: app.ClassicTaxKeeper,
DyncommKeeper: app.DyncommKeeper,
},
)
if err != nil {
Expand Down
18 changes: 18 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import (
customwasmkeeper "github.com/classic-terra/core/v2/custom/wasm/keeper"
terrawasm "github.com/classic-terra/core/v2/wasmbinding"

classictaxkeeper "github.com/classic-terra/core/v2/x/classictax/keeper"
classictaxtypes "github.com/classic-terra/core/v2/x/classictax/types"
dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
marketkeeper "github.com/classic-terra/core/v2/x/market/keeper"
Expand Down Expand Up @@ -94,6 +96,7 @@ type AppKeepers struct {
MarketKeeper marketkeeper.Keeper
TreasuryKeeper treasurykeeper.Keeper
WasmKeeper wasmkeeper.Keeper
ClassicTaxKeeper classictaxkeeper.Keeper
DyncommKeeper dyncommkeeper.Keeper

// make scoped keepers public for test purposes
Expand Down Expand Up @@ -140,6 +143,7 @@ func NewAppKeepers(
markettypes.StoreKey,
treasurytypes.StoreKey,
wasmtypes.StoreKey,
classictaxtypes.StoreKey,
dyncommtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -341,6 +345,18 @@ func NewAppKeepers(
&appKeepers.WasmKeeper, distrtypes.ModuleName,
)

// register the classictax keeper, needs to be before wasmkeeper
appKeepers.ClassicTaxKeeper = classictaxkeeper.NewKeeper(
appCodec,
appKeepers.keys[classictaxtypes.StoreKey],
appKeepers.GetSubspace(classictaxtypes.ModuleName),
appKeepers.OracleKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.TreasuryKeeper,
appKeepers.FeeGrantKeeper,
)

wasmConfig, err := wasm.ReadWasmConfig(appOpts)
if err != nil {
panic("error while reading wasm config: " + err.Error())
Expand All @@ -356,6 +372,7 @@ func NewAppKeepers(
appKeepers.AccountKeeper,
appCodec,
appKeepers.TransferKeeper,
appKeepers.ClassicTaxKeeper,
)
// the first slice will replace all default msh handler with custom one
wasmOpts = append([]wasmkeeper.Option{wasmkeeper.WithMessageHandler(wasmMsgHandler)}, wasmOpts...)
Expand Down Expand Up @@ -453,6 +470,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(treasurytypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(classictaxtypes.ModuleName)
paramsKeeper.Subspace(dyncommtypes.ModuleName)

return paramsKeeper
Expand Down
9 changes: 9 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v2/x/classictax"
classictaxtypes "github.com/classic-terra/core/v2/x/classictax/types"
"github.com/classic-terra/core/v2/x/dyncomm"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
"github.com/classic-terra/core/v2/x/market"
Expand Down Expand Up @@ -123,6 +125,7 @@ var (
treasury.AppModuleBasic{},
customwasm.AppModuleBasic{},
ibcfee.AppModuleBasic{},
classictax.AppModuleBasic{},
dyncomm.AppModuleBasic{},
)

Expand Down Expand Up @@ -185,6 +188,7 @@ func appModules(
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
classictax.NewAppModule(appCodec, app.ClassicTaxKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
}
}
Expand Down Expand Up @@ -217,6 +221,7 @@ func simulationModules(
market.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
classictax.NewAppModule(appCodec, app.ClassicTaxKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
}
}
Expand Down Expand Up @@ -248,6 +253,7 @@ func orderBeginBlockers() []string {
treasurytypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
classictaxtypes.ModuleName,
dyncommtypes.ModuleName,
}
}
Expand Down Expand Up @@ -279,6 +285,7 @@ func orderEndBlockers() []string {
treasurytypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
classictaxtypes.ModuleName,
dyncommtypes.ModuleName,
}
}
Expand All @@ -294,6 +301,8 @@ func orderInitGenesis() []string {
govtypes.ModuleName,
minttypes.ModuleName,
crisistypes.ModuleName,
// needs to be before any genesis init that makes txs
classictaxtypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
authz.ModuleName,
Expand Down
3 changes: 3 additions & 0 deletions app/upgrades/v6/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func CreateV6UpgradeHandler(
_ *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// as the stability tax rate is no longer used for the burn tax,
// we set it to 0 to allow dApps/clients to run without changes and
// without being double-taxed
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
19 changes: 19 additions & 0 deletions app/upgrades/v7/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v6

import (
"github.com/classic-terra/core/v2/app/upgrades"
classictaxtypes "github.com/classic-terra/core/v2/x/classictax/types"
store "github.com/cosmos/cosmos-sdk/store/types"
)

const UpgradeName = "v6"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV6UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
classictaxtypes.StoreKey,
},
},
}
24 changes: 24 additions & 0 deletions app/upgrades/v7/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v6

import (
"github.com/classic-terra/core/v2/app/keepers"
"github.com/classic-terra/core/v2/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateV6UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
k *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// as the stability tax rate is no longer used for the burn tax,
// we set it to 0 to allow dApps/clients to run without changes and
// without being double-taxed
k.TreasuryKeeper.SetTaxRate(ctx, sdk.NewDec(0))
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
8 changes: 8 additions & 0 deletions client/docs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@
}
}
},
{
"url": "./tmp-swagger-gen/terra/classictax/v1beta1/query.swagger.json",
"operationIds": {
"rename": {
"Params": "ClassicTaxParams"
}
}
},
{
"url": "./tmp-swagger-gen/cosmwasm/wasm/v1/query.swagger.json",
"operationIds": {
Expand Down
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26665,6 +26665,57 @@ paths:
type: string
tags:
- Query
/terra/classictax/v1beta1/params:
get:
summary: Params queries all parameters.
operationId: ClassicTaxParams
responses:
'200':
description: A successful response.
schema:
type: object
properties:
params:
description: params defines the parameters of the module.
type: object
properties:
burn_tax:
type: string
gas_prices:
type: array
items:
type: string
taxable_msg_types:
type: array
items:
type: string
description: >-
QueryParamsResponse is the response type for the Query/Params RPC
method.
default:
description: An unexpected error response.
schema:
type: object
properties:
error:
type: string
code:
type: integer
format: int32
message:
type: string
details:
type: array
items:
type: object
properties:
type_url:
type: string
value:
type: string
format: byte
tags:
- Query
/cosmwasm/wasm/v1/code:
get:
summary: Codes gets the metadata for all stored wasm codes
Expand Down Expand Up @@ -61069,6 +61120,38 @@ definitions:
target:
type: string
description: QueryRateResponse is the response type for the Query/Rate RPC method.
terra.classictax.v1beta1.Params:
type: object
properties:
burn_tax:
type: string
gas_prices:
type: array
items:
type: string
taxable_msg_types:
type: array
items:
type: string
description: Params defines the parameters for the classictax module.
terra.classictax.v1beta1.QueryParamsResponse:
type: object
properties:
params:
description: params defines the parameters of the module.
type: object
properties:
burn_tax:
type: string
gas_prices:
type: array
items:
type: string
taxable_msg_types:
type: array
items:
type: string
description: QueryParamsResponse is the response type for the Query/Params RPC method.
cosmwasm.wasm.v1.AbsoluteTxPosition:
type: object
properties:
Expand Down
14 changes: 10 additions & 4 deletions custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
expectedkeeper "github.com/classic-terra/core/v2/custom/auth/keeper"
classictax "github.com/classic-terra/core/v2/x/classictax/ante"
classictaxkeeper "github.com/classic-terra/core/v2/x/classictax/keeper"
oraclekeeper "github.com/classic-terra/core/v2/x/oracle/keeper"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand All @@ -21,11 +25,11 @@ import (
// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
AccountKeeper ante.AccountKeeper
BankKeeper BankKeeper
BankKeeper expectedkeeper.BankKeeper
ExtensionOptionChecker ante.ExtensionOptionChecker
FeegrantKeeper ante.FeegrantKeeper
OracleKeeper OracleKeeper
TreasuryKeeper TreasuryKeeper
OracleKeeper expectedkeeper.OracleKeeper
TreasuryKeeper expectedkeeper.TreasuryKeeper
SignModeHandler signing.SignModeHandler
SigGasConsumer ante.SignatureVerificationGasConsumer
TxFeeChecker ante.TxFeeChecker
Expand All @@ -34,6 +38,8 @@ type HandlerOptions struct {
GovKeeper govkeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
DefaultOracleKeeper oraclekeeper.Keeper
ClassicTaxKeeper classictaxkeeper.Keeper
DyncommKeeper dyncommkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
}
Expand Down Expand Up @@ -83,7 +89,7 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
// MinInitialDepositDecorator prevents submitting governance proposal low initial deposit
NewMinInitialDepositDecorator(options.GovKeeper, options.TreasuryKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
NewFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper),
classictax.NewClassicTaxFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper, options.DefaultOracleKeeper, options.ClassicTaxKeeper),
ante.NewSetPubKeyDecorator(options.AccountKeeper), // SetPubKeyDecorator must be called before all signature verification decorators
ante.NewValidateSigCountDecorator(options.AccountKeeper),
ante.NewSigGasConsumeDecorator(options.AccountKeeper, options.SigGasConsumer),
Expand Down
Loading
Loading