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 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
5387458
- add tax module
StrathCole Oct 11, 2024
254e6e2
- working version of reverse charge handling
StrathCole Oct 11, 2024
7a73828
add upgrade handler and linting
StrathCole Oct 11, 2024
553d870
- remove unnecessary context values
StrathCole Oct 11, 2024
79b8b25
- use upstream wasm message server
StrathCole Oct 11, 2024
579f5db
- fix in tax exemption
StrathCole Oct 12, 2024
6870149
- fix tax rate
StrathCole Oct 14, 2024
4dad6d3
- swagger
StrathCole Oct 14, 2024
92ec3f5
- gofump
StrathCole Oct 14, 2024
20630a1
- linting
StrathCole Oct 14, 2024
5411b6c
move tax payment to post handler
StrathCole Oct 14, 2024
2e22c9c
- add tax post
StrathCole Oct 14, 2024
ef8a0f6
- fix api urls
StrathCole Oct 14, 2024
094409a
- fix proto
StrathCole Oct 14, 2024
6a0e730
make tax query response backwards compatible
StrathCole Oct 14, 2024
80a0d2d
- proto fixes
StrathCole Oct 14, 2024
e322cd9
- refund tax on contract execution
StrathCole Oct 14, 2024
79c22a8
- fix for e2e
StrathCole Oct 14, 2024
624702f
- change hermes gas adjustment
StrathCole Oct 14, 2024
6fcd6e5
- set gas price in ic test setup
StrathCole Oct 17, 2024
6e3bb23
- fix ictest
StrathCole Oct 21, 2024
0f2fd74
- change v9 to v10 due to tax2gas conflict
StrathCole Nov 5, 2024
f286f6d
- fix subtraction leading to negative amount
StrathCole Nov 7, 2024
75951e1
- move minGasPrices inside the oracle check block
StrathCole Nov 13, 2024
6a03590
- remove dependency
StrathCole Nov 13, 2024
4ca2078
- remove commented code
StrathCole Nov 16, 2024
1de4dd8
- fix fee check
StrathCole Nov 21, 2024
5e06beb
registering statik namespace with "terrad" (#536)
kien6034 Nov 27, 2024
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
13 changes: 11 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ import (
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 had been used by tax2gas and has to be skipped
v10 "github.com/classic-terra/core/v3/app/upgrades/v10"

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

// Forks defines forks to be applied to the network
Expand Down Expand Up @@ -244,6 +248,7 @@ func NewTerraApp(
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
TaxKeeper: &app.TaxKeeper,
Cdc: app.appCodec,
},
)
Expand All @@ -253,7 +258,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 +411,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/v10/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v10

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 = "v10"

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

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 CreateV10UpgradeHandler(
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
StrathCole marked this conversation as resolved.
Show resolved Hide resolved

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