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

Implement a Reverse Charge tax approach #525

Open
wants to merge 20 commits into
base: main
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
11 changes: 9 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import (
v8_1 "github.com/classic-terra/core/v3/app/upgrades/v8_1"
v8_2 "github.com/classic-terra/core/v3/app/upgrades/v8_2"
v8_3 "github.com/classic-terra/core/v3/app/upgrades/v8_3"
v9 "github.com/classic-terra/core/v3/app/upgrades/v9"

customante "github.com/classic-terra/core/v3/custom/auth/ante"
custompost "github.com/classic-terra/core/v3/custom/auth/post"
Expand Down Expand Up @@ -91,6 +92,7 @@ var (
v8_1.Upgrade,
v8_2.Upgrade,
v8_3.Upgrade,
v9.Upgrade,
}

// Forks defines forks to be applied to the network
Expand Down Expand Up @@ -244,6 +246,7 @@ func NewTerraApp(
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
TaxKeeper: &app.TaxKeeper,
Cdc: app.appCodec,
},
)
Expand All @@ -253,7 +256,11 @@ func NewTerraApp(

postHandler, err := custompost.NewPostHandler(
custompost.HandlerOptions{
DyncommKeeper: app.DyncommKeeper,
DyncommKeeper: app.DyncommKeeper,
TaxKeeper: app.TaxKeeper,
BankKeeper: app.BankKeeper,
AccountKeeper: app.AccountKeeper,
TreasuryKeeper: app.TreasuryKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -402,7 +409,7 @@ func (app *TerraApp) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIC
// RegisterTxService implements the Application.RegisterTxService method.
func (app *TerraApp) RegisterTxService(clientCtx client.Context) {
authtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.BaseApp.Simulate, app.interfaceRegistry)
customauthtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.TreasuryKeeper)
customauthtx.RegisterTxService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.TreasuryKeeper, app.TaxKeeper)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
Expand Down
15 changes: 15 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

taxkeeper "github.com/classic-terra/core/v3/x/tax/keeper"
taxtypes "github.com/classic-terra/core/v3/x/tax/types"
"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
Expand Down Expand Up @@ -103,6 +105,7 @@ type AppKeepers struct {
DyncommKeeper dyncommkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
TaxKeeper taxkeeper.Keeper

Ics20WasmHooks *ibchooks.WasmHooks
IBCHooksWrapper *ibchooks.ICS4Middleware
Expand Down Expand Up @@ -156,6 +159,7 @@ func NewAppKeepers(
treasurytypes.StoreKey,
wasmtypes.StoreKey,
dyncommtypes.StoreKey,
taxtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -390,6 +394,7 @@ func NewAppKeepers(
appKeepers.BankKeeper,
appKeepers.TreasuryKeeper,
appKeepers.AccountKeeper,
appKeepers.TaxKeeper,
appCodec,
appKeepers.TransferKeeper,
)
Expand Down Expand Up @@ -457,6 +462,15 @@ func NewAppKeepers(
),
)

appKeepers.TaxKeeper = taxkeeper.NewKeeper(
appCodec,
appKeepers.keys[taxtypes.StoreKey],
appKeepers.BankKeeper,
appKeepers.TreasuryKeeper,
appKeepers.DistrKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

appKeepers.DyncommKeeper = dyncommkeeper.NewKeeper(
appCodec,
appKeepers.keys[dyncommtypes.StoreKey],
Expand Down Expand Up @@ -504,6 +518,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(treasurytypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(dyncommtypes.ModuleName)
paramsKeeper.Subspace(taxtypes.ModuleName)

return paramsKeeper
}
Expand Down
16 changes: 13 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
markettypes "github.com/classic-terra/core/v3/x/market/types"
"github.com/classic-terra/core/v3/x/oracle"
oracletypes "github.com/classic-terra/core/v3/x/oracle/types"
taxmodule "github.com/classic-terra/core/v3/x/tax/module"
"github.com/classic-terra/core/v3/x/treasury"
treasuryclient "github.com/classic-terra/core/v3/x/treasury/client"
treasurytypes "github.com/classic-terra/core/v3/x/treasury/types"
Expand All @@ -34,7 +35,6 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/authz"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/capability"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
Expand Down Expand Up @@ -78,6 +78,10 @@ import (
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"

taxbank "github.com/classic-terra/core/v3/x/tax/modules/bank"
taxmarket "github.com/classic-terra/core/v3/x/tax/modules/market"
taxtypes "github.com/classic-terra/core/v3/x/tax/types"

// unnamed import of statik for swagger UI support
_ "github.com/classic-terra/core/v3/client/docs/statik"
)
Expand Down Expand Up @@ -125,6 +129,7 @@ var (
dyncomm.AppModuleBasic{},
ibchooks.AppModuleBasic{},
consensus.AppModuleBasic{},
taxmodule.AppModuleBasic{},
)
// module account permissions
maccPerms = map[string][]string{
Expand Down Expand Up @@ -163,7 +168,7 @@ func appModules(
encodingConfig.TxConfig,
),
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.GetSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
taxbank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.TreasuryKeeper, app.GetSubspace(banktypes.ModuleName), app.TaxKeeper),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
Expand All @@ -179,13 +184,14 @@ func appModules(
transfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
market.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
taxmarket.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.TreasuryKeeper, app.BankKeeper, app.OracleKeeper, app.TaxKeeper),
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, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
taxmodule.NewAppModule(appCodec, app.TaxKeeper),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
}
}
Expand Down Expand Up @@ -218,6 +224,7 @@ func simulationModules(
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
taxmodule.NewAppModule(appCodec, app.TaxKeeper),
}
}

Expand Down Expand Up @@ -250,6 +257,7 @@ func orderBeginBlockers() []string {
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down Expand Up @@ -284,6 +292,7 @@ func orderEndBlockers() []string {
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down Expand Up @@ -318,6 +327,7 @@ func orderInitGenesis() []string {
treasurytypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
taxtypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down
7 changes: 7 additions & 0 deletions app/testing/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v3/app"
appparams "github.com/classic-terra/core/v3/app/params"
core "github.com/classic-terra/core/v3/types"
dyncommtypes "github.com/classic-terra/core/v3/x/dyncomm/types"
markettypes "github.com/classic-terra/core/v3/x/market/types"
oracletypes "github.com/classic-terra/core/v3/x/oracle/types"
taxtypes "github.com/classic-terra/core/v3/x/tax/types"
treasurytypes "github.com/classic-terra/core/v3/x/treasury/types"
dbm "github.com/cometbft/cometbft-db"
abci "github.com/cometbft/cometbft/abci/types"
Expand Down Expand Up @@ -283,6 +285,11 @@ func genesisStateWithValSet(t *testing.T,
treasuryGensis := treasurytypes.DefaultGenesisState()
genesisState[treasurytypes.ModuleName] = app.AppCodec().MustMarshalJSON(treasuryGensis)

// update tax genesis state
taxGenesis := taxtypes.DefaultGenesisState()
taxGenesis.Params.GasPrices = sdk.NewDecCoins(sdk.NewDecCoin(core.MicroSDRDenom, sdk.ZeroInt())) // tests normally rely on zero gas price, so we are setting it here and fall back to the normal ctx.MinGasPrices
genesisState[taxtypes.ModuleName] = app.AppCodec().MustMarshalJSON(taxGenesis)

// update wasm genesis state
wasmGenesis := &wasmtypes.GenesisState{
Params: wasmtypes.DefaultParams(),
Expand Down
20 changes: 20 additions & 0 deletions app/upgrades/v9/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v9

import (
"github.com/classic-terra/core/v3/app/upgrades"
store "github.com/cosmos/cosmos-sdk/store/types"

tax2gastypes "github.com/classic-terra/core/v3/x/tax/types"
)

const UpgradeName = "v9"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV9UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
tax2gastypes.ModuleName,
},
},
}
26 changes: 26 additions & 0 deletions app/upgrades/v9/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package v9

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

func CreateV9UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// set default oracle split
keepers.TreasuryKeeper.SetTaxRate(ctx, sdk.ZeroDec())

tax2gasParams := taxtypes.DefaultParams()
keepers.TaxKeeper.SetParams(ctx, tax2gasParams)
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
2 changes: 1 addition & 1 deletion client/docs/statik/statik.go

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26570,6 +26570,45 @@ paths:
format: byte
tags:
- Query
/terra/tax/v1beta1/burn_tax_rate:
get:
summary: BurnTaxRate return the current tax rate
operationId: BurnTaxRate
responses:
'200':
description: A successful response.
schema:
type: object
properties:
tax_rate:
type: string
description: |-
QueryBurnTaxRateResponse is response type for the
Query/BurnTaxRate 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
/terra/dyncomm/v1beta1/params:
get:
summary: Params queries all parameters.
Expand Down
2 changes: 1 addition & 1 deletion contrib/updates/prepare_cosmovisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# These fields should be fetched automatically in the future
# Need to do more upgrade to see upgrade patterns
OLD_VERSION=v3.1.3
OLD_VERSION=v3.1.6
# this command will retrieve the folder with the largest number in format v<number>
SOFTWARE_UPGRADE_NAME=$(ls -d -- ./app/upgrades/v* | sort -Vr | head -n 1 | xargs basename)
BUILDDIR=$1
Expand Down
9 changes: 8 additions & 1 deletion custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"

taxkeeper "github.com/classic-terra/core/v3/x/tax/keeper"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
)
Expand All @@ -40,6 +42,7 @@ type HandlerOptions struct {
TXCounterStoreKey storetypes.StoreKey
DyncommKeeper dyncommkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
TaxKeeper *taxkeeper.Keeper
Cdc codec.BinaryCodec
}

Expand Down Expand Up @@ -75,6 +78,10 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tx counter key is required for ante builder")
}

if options.TaxKeeper == nil {
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "tax handler is required for ante builder")
}

return sdk.ChainAnteDecorators(
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
wasmkeeper.NewLimitSimulationGasDecorator(options.WasmConfig.SimulationGasLimit),
Expand All @@ -88,7 +95,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, options.DistributionKeeper),
NewFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper, options.DistributionKeeper, *options.TaxKeeper),
dyncommante.NewDyncommDecorator(options.Cdc, options.DyncommKeeper, options.StakingKeeper),

// Do not add any other decorators below this point unless explicitly explain.
Expand Down
4 changes: 4 additions & 0 deletions custom/auth/ante/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"

terraapp "github.com/classic-terra/core/v3/app"
taxtypes "github.com/classic-terra/core/v3/x/tax/types"
treasurytypes "github.com/classic-terra/core/v3/x/treasury/types"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
Expand Down Expand Up @@ -53,6 +54,9 @@ func createTestApp(isCheckTx bool, tempDir string) (*terraapp.TerraApp, sdk.Cont
app.DistrKeeper.SetParams(ctx, distributiontypes.DefaultParams())
app.DistrKeeper.SetFeePool(ctx, distributiontypes.InitialFeePool())

taxParams := taxtypes.DefaultParams()
taxParams.GasPrices = sdk.NewDecCoins() // tests normally rely on zero gas price, so we are setting it here and fall back to the normal ctx.MinGasPrices
app.TaxKeeper.SetParams(ctx, taxParams)
return app, ctx
}

Expand Down
4 changes: 4 additions & 0 deletions custom/auth/ante/expected_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ type DistrKeeper interface {
type GovKeeper interface {
GetDepositParams(ctx sdk.Context) govv1.DepositParams
}

type TaxKeeper interface {
GetBurnTaxRate(ctx sdk.Context) sdk.Dec
}
Loading
Loading