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

Add tax2gas module and move all handle fees logic to tax2gas module #491

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
2db4512
feat: oracle split as per governance (#495)
fragwuerdig Jul 10, 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
829a7d2
fix: wrong interface cast
fragwuerdig Jul 11, 2024
01932fe
Adjust oracle split logic (#496)
StrathCole Jul 14, 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
51a080f
fix: use wasmvm v1.5.2 to prevent memory leak (#497)
phamminh0811 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
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
22 changes: 20 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import (
v7 "github.com/classic-terra/core/v3/app/upgrades/v7"
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"

customante "github.com/classic-terra/core/v3/custom/auth/ante"
custompost "github.com/classic-terra/core/v3/custom/auth/post"
Expand All @@ -75,7 +76,18 @@ var (
DefaultNodeHome string

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade, v6_1.Upgrade, v7.Upgrade, v7_1.Upgrade, v8.Upgrade}
Upgrades = []upgrades.Upgrade{
v2.Upgrade,
v3.Upgrade,
v4.Upgrade,
v5.Upgrade,
v6.Upgrade,
v6_1.Upgrade,
v7.Upgrade,
v7_1.Upgrade,
v8.Upgrade,
v8_1.Upgrade,
}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{}
Expand Down Expand Up @@ -228,6 +240,7 @@ func NewTerraApp(
TXCounterStoreKey: app.GetKey(wasmtypes.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
Tax2Gaskeeper: app.Tax2gasKeeper,
Cdc: app.appCodec,
},
)
Expand All @@ -237,7 +250,12 @@ func NewTerraApp(

postHandler, err := custompost.NewPostHandler(
custompost.HandlerOptions{
DyncommKeeper: app.DyncommKeeper,
AccountKeeper: app.AccountKeeper,
BankKeeper: app.BankKeeper,
FeegrantKeeper: app.FeeGrantKeeper,
DyncommKeeper: app.DyncommKeeper,
TreasuryKeeper: app.TreasuryKeeper,
Tax2Gaskeeper: app.Tax2gasKeeper,
},
)
if err != nil {
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
2 changes: 0 additions & 2 deletions app/legacy/pubkey_replacement.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func loadKeydataFromFile(clientCtx client.Context, replacementrJSON string, genD
var replacementKeys replacementConfigs

err = json.Unmarshal(jsonReplacementBlob, &replacementKeys)

if err != nil {
log.Fatal(errors.Wrap(err, "Could not unmarshal replacement keys "))
}
Expand Down Expand Up @@ -112,7 +111,6 @@ func loadKeydataFromFile(clientCtx client.Context, replacementrJSON string, genD
state[slashing.ModuleName] = clientCtx.Codec.MustMarshalJSON(&slashingGenesis)

genDoc.AppState, err = json.Marshal(state)

if err != nil {
log.Fatal("Could not marshal App State")
}
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
13 changes: 13 additions & 0 deletions app/upgrades/v8_1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//nolint:revive
package v8_1

import (
"github.com/classic-terra/core/v3/app/upgrades"
)

const UpgradeName = "v8_1"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV81UpgradeHandler,
}
24 changes: 24 additions & 0 deletions app/upgrades/v8_1/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//nolint:revive
package v8_1

import (
"github.com/classic-terra/core/v3/app/keepers"
"github.com/classic-terra/core/v3/app/upgrades"
treasurytypes "github.com/classic-terra/core/v3/x/treasury/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 CreateV81UpgradeHandler(
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.SetOracleSplitRate(ctx, treasurytypes.DefaultOracleSplit)
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
4 changes: 2 additions & 2 deletions contrib/updates/Dockerfile.old
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

# Cosmwasm - Download correct libwasmvm version and verify checksum
RUN set -eux &&\
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 5) && \
WASMVM_DOWNLOADS="https://github.com/classic-terra/wasmvm/releases/download/${WASMVM_VERSION}"; \
WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) && \
WASMVM_DOWNLOADS="https://github.com/CosmWasm/wasmvm/releases/download/${WASMVM_VERSION}"; \
wget ${WASMVM_DOWNLOADS}/checksums.txt -O /tmp/checksums.txt; \
if [ ${BUILDPLATFORM} = "linux/amd64" ]; then \
WASMVM_URL="${WASMVM_DOWNLOADS}/libwasmvm_muslc.x86_64.a"; \
Expand Down
2 changes: 1 addition & 1 deletion contrib/updates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ networks:
driver: default
config:
-
subnet: 192.168.10.0/16
subnet: 192.168.10.0/24
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=v2.4.2
OLD_VERSION=v3.0.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
Empty file modified contrib/updates/upgrade-test.sh
100644 → 100755
Empty file.
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),
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
5 changes: 5 additions & 0 deletions custom/auth/ante/expected_keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type TreasuryKeeper interface {
HasBurnTaxExemptionAddress(ctx sdk.Context, addresses ...string) bool
HasBurnTaxExemptionContract(ctx sdk.Context, address string) bool
GetMinInitialDepositRatio(ctx sdk.Context) sdk.Dec
GetOracleSplitRate(ctx sdk.Context) sdk.Dec
}

// OracleKeeper for feeder validation
Expand All @@ -25,15 +26,19 @@ 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 {
FundCommunityPool(ctx sdk.Context, amount sdk.Coins, sender sdk.AccAddress) error
GetFeePool(ctx sdk.Context) distributiontypes.FeePool
GetCommunityTax(ctx sdk.Context) math.LegacyDec
SetFeePool(ctx sdk.Context, feePool distributiontypes.FeePool)
}

type GovKeeper interface {
Expand Down
Loading
Loading