Skip to content

Commit

Permalink
feat: tax2gas (#500)
Browse files Browse the repository at this point in the history
Co-authored-by: expertdicer <[email protected]>
  • Loading branch information
phamminh0811 and expertdicer authored Aug 13, 2024
1 parent c8c04d9 commit d28ff8c
Show file tree
Hide file tree
Showing 63 changed files with 5,617 additions and 1,842 deletions.
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()
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

0 comments on commit d28ff8c

Please sign in to comment.