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: tax2gas #500

Merged
merged 77 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
419ce91
Add tax2gas module and move all handle fees logic to tax2gas module
phamminh0811 Jun 24, 2024
7500c39
lint
phamminh0811 Jun 24, 2024
1599911
proto lint
phamminh0811 Jun 24, 2024
8fe545d
revert change in protocgen
phamminh0811 Jun 24, 2024
c40fa96
add tax2gas module and implementation
expertdicer Jul 8, 2024
22a7186
remove redundant files
expertdicer Jul 8, 2024
ef4264f
remove wasm file
expertdicer Jul 8, 2024
226de57
remove wasm file
expertdicer Jul 8, 2024
a2ae5c9
change proto
expertdicer Jul 8, 2024
4cd85c9
v8_1 upgrade handler
expertdicer Jul 8, 2024
cce285f
rename var and add comment
expertdicer Jul 9, 2024
af547c2
remove redundant check
expertdicer Jul 9, 2024
1203f0f
add comment and rename var
expertdicer Jul 9, 2024
b272150
correctly set ctx.Value
expertdicer Jul 9, 2024
c131733
remove tax2gas subspace and add authority
expertdicer Jul 11, 2024
bb99053
register msg service
expertdicer Jul 11, 2024
92ef82c
add msg update params
expertdicer Jul 11, 2024
c016cc6
register codec and unit tests
expertdicer Jul 11, 2024
e6d8242
proto update
expertdicer Jul 11, 2024
023cdfe
refactor tax2gas querier
expertdicer Jul 11, 2024
2fc2c60
refactor structure
expertdicer Jul 15, 2024
2d94166
adding unit tests
expertdicer Jul 16, 2024
a16d4df
deduct from tx origin
expertdicer Jul 16, 2024
ed0ad82
Allow to paid by multiple fees denom
phamminh0811 Jul 16, 2024
d57e4ce
consume tax gas in wasm plugin
expertdicer Jul 16, 2024
3c9b03a
Compute feeRequired base on gasPrice and gasRemaining
phamminh0811 Jul 16, 2024
0b55dd8
Handle fee grant in post handle
phamminh0811 Jul 17, 2024
ee60e0c
Handle fee grant in post handle
phamminh0811 Jul 17, 2024
9131a18
Add test scenario to tax2gas
phamminh0811 Jul 17, 2024
f615e83
Merge branch 'minh/tax2gas' of github-expertdicer:classic-terra/core …
expertdicer Jul 17, 2024
d83b8b3
add simulate condition
expertdicer Jul 17, 2024
052f7fb
update tests and checkTxFee
expertdicer Jul 17, 2024
e2b6dc1
lint
phamminh0811 Jul 17, 2024
2f779bf
lint
phamminh0811 Jul 17, 2024
8ecad7e
fix interchain test
phamminh0811 Jul 17, 2024
b7aa915
update tests and minor fix
expertdicer Jul 17, 2024
d66c1f4
Merge branch 'minh/tax2gas' of github-expertdicer:classic-terra/core …
expertdicer Jul 17, 2024
3e816ea
Move burn tax process to post handler
phamminh0811 Jul 18, 2024
af2336c
add bypass msg types and max gas, unit tests
expertdicer Jul 18, 2024
3f22cf0
Merge branch 'minh/tax2gas' of github-expertdicer:classic-terra/core …
expertdicer Jul 18, 2024
75bd097
update tests
expertdicer Jul 18, 2024
693a641
Merge branch 'main' into minh/tax2gas
expertdicer Jul 22, 2024
fb0344f
update post handler
expertdicer Jul 22, 2024
3deac13
Use taxGasMeter in sdk to handle tax2Gas logic (#499)
phamminh0811 Jul 23, 2024
56ea70b
fix e2e test
phamminh0811 Jul 23, 2024
1327e9d
fix test
expertdicer Jul 24, 2024
644d5f4
Merge branch 'minh/tax2gas' of github-expertdicer:classic-terra/core …
expertdicer Jul 24, 2024
29ac9ad
Add e2e tests to cover test scenario in tax2gas
phamminh0811 Jul 25, 2024
c98c617
lint
phamminh0811 Jul 25, 2024
4523ec5
fix ante test
phamminh0811 Jul 26, 2024
87437f1
lint
phamminh0811 Jul 26, 2024
9be68ba
fix e2e-test
phamminh0811 Jul 26, 2024
dd5eda3
fix tax2gas keeper test
phamminh0811 Jul 26, 2024
c21b748
fix msg server test
phamminh0811 Jul 26, 2024
d3f4005
fix sim test
expertdicer Jul 26, 2024
c1d0a11
lint
expertdicer Jul 26, 2024
da4d9d5
Add test for fee tax non value token denom
phamminh0811 Jul 27, 2024
240caaa
lint
phamminh0811 Jul 27, 2024
997910f
Change taxGas to sdkmath.Int
phamminh0811 Jul 27, 2024
1cb33dd
Fix tax exemption test
phamminh0811 Jul 29, 2024
b4e3896
Make gas auto work
phamminh0811 Jul 29, 2024
a2d402b
Move taxRate to tax2gas module params
phamminh0811 Jul 30, 2024
a1a12ac
Add upgrade handler
phamminh0811 Jul 30, 2024
56f61a5
fix exemption test
phamminh0811 Jul 30, 2024
c34c82d
combine all computeTax to one
phamminh0811 Jul 30, 2024
eb0097d
rename v8_2 to v9
phamminh0811 Jul 30, 2024
e355e02
lint
phamminh0811 Jul 30, 2024
d4eb832
Use more precise way to estimate gas and change e2e test for using ga…
phamminh0811 Jul 30, 2024
b4b813f
Deduct all fees and handle tx priority
phamminh0811 Aug 1, 2024
5abf3a9
lint
phamminh0811 Aug 1, 2024
7dcbf74
merge main
phamminh0811 Aug 1, 2024
bac6f8b
doc
phamminh0811 Aug 1, 2024
3c86903
fix wasmbinding test
phamminh0811 Aug 1, 2024
5f4d877
consume taxgas only on simulate
phamminh0811 Aug 1, 2024
b3d175d
revert logic to deduct correct amount needed for gas and tax
phamminh0811 Aug 1, 2024
eed10ea
lint
phamminh0811 Aug 1, 2024
e584267
final version of Tax2Gas
phamminh0811 Aug 2, 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 @@ -56,6 +56,7 @@ import (
v7_1 "github.com/classic-terra/core/v3/app/upgrades/v7_1"
v8 "github.com/classic-terra/core/v3/app/upgrades/v8"
v8_1 "github.com/classic-terra/core/v3/app/upgrades/v8_1"
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 @@ -87,6 +88,7 @@ var (
v7_1.Upgrade,
v8.Upgrade,
v8_1.Upgrade,
v9.Upgrade,
}

// Forks defines forks to be applied to the network
Expand Down Expand Up @@ -240,6 +242,7 @@ func NewTerraApp(
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
Tax2Gaskeeper: app.Tax2gasKeeper,
Cdc: app.appCodec,
},
)
Expand All @@ -249,7 +252,13 @@ func NewTerraApp(

postHandler, err := custompost.NewPostHandler(
custompost.HandlerOptions{
DyncommKeeper: app.DyncommKeeper,
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
DistrKeeper: app.DistrKeeper,
DyncommKeeper: app.DyncommKeeper,
TreasuryKeeper: app.TreasuryKeeper,
Tax2Gaskeeper: app.Tax2gasKeeper,
},
)
if err != nil {
Expand Down Expand Up @@ -398,7 +407,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.Tax2gasKeeper)
}

// RegisterTendermintService implements the Application.RegisterTendermintService method.
Expand Down
18 changes: 14 additions & 4 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import (
markettypes "github.com/classic-terra/core/v3/x/market/types"
oraclekeeper "github.com/classic-terra/core/v3/x/oracle/keeper"
oracletypes "github.com/classic-terra/core/v3/x/oracle/types"
tax2gasKeeper "github.com/classic-terra/core/v3/x/tax2gas/keeper"
tax2gasTypes "github.com/classic-terra/core/v3/x/tax2gas/types"
treasurykeeper "github.com/classic-terra/core/v3/x/treasury/keeper"
treasurytypes "github.com/classic-terra/core/v3/x/treasury/types"
)
Expand Down Expand Up @@ -103,10 +105,10 @@ type AppKeepers struct {
DyncommKeeper dyncommkeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper

Ics20WasmHooks *ibchooks.WasmHooks
IBCHooksWrapper *ibchooks.ICS4Middleware
TransferStack ibctransfer.IBCModule
Tax2gasKeeper tax2gasKeeper.Keeper
Ics20WasmHooks *ibchooks.WasmHooks
IBCHooksWrapper *ibchooks.ICS4Middleware
TransferStack ibctransfer.IBCModule

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -156,6 +158,7 @@ func NewAppKeepers(
treasurytypes.StoreKey,
wasmtypes.StoreKey,
dyncommtypes.StoreKey,
tax2gasTypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -276,6 +279,12 @@ func NewAppKeepers(
stakingtypes.NewMultiStakingHooks(appKeepers.DistrKeeper.Hooks(), appKeepers.SlashingKeeper.Hooks()),
)

appKeepers.Tax2gasKeeper = tax2gasKeeper.NewKeeper(
appCodec,
appKeepers.keys[tax2gasTypes.StoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Create IBC Keeper
appKeepers.IBCKeeper = ibckeeper.NewKeeper(
appCodec,
Expand Down Expand Up @@ -390,6 +399,7 @@ func NewAppKeepers(
appKeepers.BankKeeper,
appKeepers.TreasuryKeeper,
appKeepers.AccountKeeper,
appKeepers.Tax2gasKeeper,
appCodec,
appKeepers.TransferKeeper,
)
Expand Down
7 changes: 7 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ 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"
tax2gas "github.com/classic-terra/core/v3/x/tax2gas"
tax2gasTypes "github.com/classic-terra/core/v3/x/tax2gas/types"
"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 Down Expand Up @@ -123,6 +125,7 @@ var (
customwasm.AppModuleBasic{},
ibcfee.AppModuleBasic{},
dyncomm.AppModuleBasic{},
tax2gas.AppModuleBasic{},
ibchooks.AppModuleBasic{},
consensus.AppModuleBasic{},
)
Expand Down Expand Up @@ -184,6 +187,7 @@ func appModules(
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),
tax2gas.NewAppModule(appCodec, app.Tax2gasKeeper),
ibchooks.NewAppModule(app.AccountKeeper),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
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 @@ -250,6 +254,7 @@ func orderBeginBlockers() []string {
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
tax2gasTypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down Expand Up @@ -284,6 +289,7 @@ func orderEndBlockers() []string {
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
tax2gasTypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down Expand Up @@ -318,6 +324,7 @@ func orderInitGenesis() []string {
treasurytypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
tax2gasTypes.ModuleName,
// consensus module
consensusparamtypes.ModuleName,
}
Expand Down
24 changes: 22 additions & 2 deletions app/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
simcli "github.com/cosmos/cosmos-sdk/x/simulation/client/cli"

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

// SimAppChainID hardcoded chainID for simulation
Expand Down Expand Up @@ -142,16 +145,33 @@ func TestAppStateDeterminism(t *testing.T) {
simtestutil.EmptyAppOptions{}, emptyWasmOpts, interBlockCacheOpt(), fauxMerkleModeOpt(),
)

appGenState := app.DefaultGenesis()
tax2gasGenState := tax2gastypes.GenesisState{}
err := app.AppCodec().UnmarshalJSON(appGenState[tax2gastypes.ModuleName], &tax2gasGenState)
require.NoError(t, err)

tax2gasGenState.Params = tax2gastypes.Params{
Enabled: true,
GasPrices: sdk.DecCoins{
sdk.NewDecCoinFromDec("stake", sdk.NewDecWithPrec(0, 3)),
},
}
newGenState := tax2gasGenState
bz, err := app.AppCodec().MarshalJSON(&newGenState)
require.NoError(t, err)

appGenState[tax2gastypes.ModuleName] = bz

fmt.Printf(
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
config.Seed, i+1, numSeeds, j+1, numTimesToRunPerSeed,
)

_, _, err := simulation.SimulateFromSeed(
_, _, err = simulation.SimulateFromSeed(
t,
os.Stdout,
app.BaseApp,
AppStateFn(app.AppCodec(), app.SimulationManager(), app.DefaultGenesis()),
AppStateFn(app.AppCodec(), app.SimulationManager(), appGenState),
simtypes.RandomAccounts, // Replace with own random account function if using keys other than secp256k1
simtestutil.SimulationOperations(app, app.AppCodec(), config),
app.ModuleAccountAddrs(),
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/tax2gas/types"
)

const UpgradeName = "v9"

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

import (
"github.com/classic-terra/core/v3/app/keepers"
"github.com/classic-terra/core/v3/app/upgrades"
tax2gastypes "github.com/classic-terra/core/v3/x/tax2gas/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 := tax2gastypes.DefaultParams()
phamminh0811 marked this conversation as resolved.
Show resolved Hide resolved
tax2gasParams.GasPrices = sdk.NewDecCoins(
sdk.NewDecCoinFromDec("uluna", sdk.NewDecWithPrec(28325, 3)),
sdk.NewDecCoinFromDec("uusd", sdk.NewDecWithPrec(75, 2)),
)
tax2gasParams.MaxTotalBypassMinFeeMsgGasUsage = 200000
keepers.Tax2gasKeeper.SetParams(ctx, tax2gasParams)
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
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.0.3
OLD_VERSION=v3.1.3
# 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
8 changes: 6 additions & 2 deletions custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import (

dyncommante "github.com/classic-terra/core/v3/x/dyncomm/ante"
dyncommkeeper "github.com/classic-terra/core/v3/x/dyncomm/keeper"
tax2gasante "github.com/classic-terra/core/v3/x/tax2gas/ante"
tax2gaskeeper "github.com/classic-terra/core/v3/x/tax2gas/keeper"
tax2gastypes "github.com/classic-terra/core/v3/x/tax2gas/types"
"github.com/cosmos/cosmos-sdk/codec"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibcante "github.com/cosmos/ibc-go/v7/modules/core/ante"
Expand All @@ -26,7 +29,7 @@ type HandlerOptions struct {
AccountKeeper ante.AccountKeeper
BankKeeper BankKeeper
ExtensionOptionChecker ante.ExtensionOptionChecker
FeegrantKeeper ante.FeegrantKeeper
FeegrantKeeper tax2gastypes.FeegrantKeeper
OracleKeeper OracleKeeper
TreasuryKeeper TreasuryKeeper
SignModeHandler signing.SignModeHandler
Expand All @@ -40,6 +43,7 @@ type HandlerOptions struct {
TXCounterStoreKey storetypes.StoreKey
DyncommKeeper dyncommkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
Tax2Gaskeeper tax2gaskeeper.Keeper
Cdc codec.BinaryCodec
}

Expand Down Expand Up @@ -88,7 +92,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),
tax2gasante.NewFeeDecorator(options.AccountKeeper, options.BankKeeper, options.FeegrantKeeper, options.TreasuryKeeper, options.Tax2Gaskeeper),
dyncommante.NewDyncommDecorator(options.Cdc, options.DyncommKeeper, options.StakingKeeper),

// Do not add any other decorators below this point unless explicitly explain.
Expand Down
6 changes: 6 additions & 0 deletions custom/auth/ante/expected_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ type OracleKeeper interface {

// BankKeeper defines the contract needed for supply related APIs (noalias)
type BankKeeper interface {
GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin
IsSendEnabledCoins(ctx sdk.Context, coins ...sdk.Coin) error
SendCoins(ctx sdk.Context, from, to sdk.AccAddress, amt sdk.Coins) error
SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToModule(ctx sdk.Context, senderModule string, recipientModule string, amt sdk.Coins) error
SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
}

type DistrKeeper interface {
Expand All @@ -42,3 +44,7 @@ type DistrKeeper interface {
type GovKeeper interface {
GetDepositParams(ctx sdk.Context) govv1.DepositParams
}

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