Skip to content

Commit

Permalink
Merge branch 'main' into minh/tax2gas
Browse files Browse the repository at this point in the history
  • Loading branch information
expertdicer committed Jul 22, 2024
2 parents 75bd097 + 51a080f commit 693a641
Show file tree
Hide file tree
Showing 18 changed files with 244 additions and 81 deletions.
13 changes: 12 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,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, v8_1.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
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
12 changes: 3 additions & 9 deletions app/upgrades/v8_1/constants.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package v81
//nolint:revive
package v8_1

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

const UpgradeName = "v8_1"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV8_1UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
tax2gasTypes.StoreKey,
},
},
CreateUpgradeHandler: CreateV81UpgradeHandler,
}
10 changes: 7 additions & 3 deletions app/upgrades/v8_1/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
package v81
//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 CreateV8_1UpgradeHandler(
func CreateV81UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
_ *keepers.AppKeepers,
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.
3 changes: 3 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 @@ -36,6 +37,8 @@ type BankKeeper interface {
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ replace (
)

replace (
github.com/CosmWasm/wasmd => github.com/classic-terra/wasmd v0.45.1-0.20240716075902-ce9c9cb9b363
github.com/CosmWasm/wasmd => github.com/classic-terra/wasmd v0.45.0-terra.5
// use cometbft
github.com/cometbft/cometbft => github.com/classic-terra/cometbft v0.37.4-terra1
github.com/cometbft/cometbft-db => github.com/cometbft/cometbft-db v0.8.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ github.com/classic-terra/goleveldb v0.0.0-20230914223247-2b28f6655121 h1:fjpWDB0
github.com/classic-terra/goleveldb v0.0.0-20230914223247-2b28f6655121/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/classic-terra/ibc-go/v7 v7.4.0-terra h1:hawaq62XKlxyc8xLyIcc6IujDDEbqDBU+2U15SF+hj8=
github.com/classic-terra/ibc-go/v7 v7.4.0-terra/go.mod h1:s0lxNkjVIqsb8AVltL0qhzxeLgOKvWZrknPuvgjlEQ8=
github.com/classic-terra/wasmd v0.45.1-0.20240716075902-ce9c9cb9b363 h1:z6qheMvuS9Uongc5obQQbL0hmiJ7s5MKHfYgJl4BQeU=
github.com/classic-terra/wasmd v0.45.1-0.20240716075902-ce9c9cb9b363/go.mod h1:cdb31ecSxIQrq/ZmYf9KYNbsdqbHfFUUGiA2dHeYxsA=
github.com/classic-terra/wasmd v0.45.0-terra.5 h1:0fuc4lS1Z0Egci6hwK4DZqOwF2l9fGsZuPTZ1akObFY=
github.com/classic-terra/wasmd v0.45.0-terra.5/go.mod h1:r/AxjzSLyrQbrANEsV/d+qf/vmCDFiAoVwWenGs23ZY=
github.com/clbanning/x2j v0.0.0-20191024224557-825249438eec/go.mod h1:jMjuTZXRI4dUb/I5gc9Hdhagfvm9+RyrPryS/auMzxE=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/cloudflare-go v0.14.0/go.mod h1:EnwdgGMaFOruiPZRFSgn+TsQ3hQ7C/YWzIGLeu5c304=
Expand Down
6 changes: 6 additions & 0 deletions proto/terra/treasury/v1beta1/treasury.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ message Params {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
string oracle_split = 10 [
(cosmos_proto.scalar) = "cosmos.Dec",
(gogoproto.moretags) = "yaml:\"oracle_split\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// PolicyConstraints - defines policy constraints can be applied in tax & reward policies
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/configurer/chain/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (n *NodeConfig) InstantiateWasmContract(codeID, initMsg, amount, from strin
n.LogActionF("successfully initialized")
}

func (n *NodeConfig) Instantiate2WasmContract(codeID, initMsg, salt, amount, fee, from string) {
func (n *NodeConfig) Instantiate2WasmContract(codeID, initMsg, salt, amount, fee, gas, from string) {
n.LogActionF("instantiating wasm contract %s with %s", codeID, initMsg)
encodedSalt := make([]byte, hex.EncodedLen(len([]byte(salt))))
hex.Encode(encodedSalt, []byte(salt))
Expand All @@ -56,6 +56,9 @@ func (n *NodeConfig) Instantiate2WasmContract(codeID, initMsg, salt, amount, fee
if fee != "" {
cmd = append(cmd, fmt.Sprintf("--fees=%s", fee))
}
if gas != "" {
cmd = append(cmd, fmt.Sprintf("--gas=%s", gas))
}
n.LogActionF(strings.Join(cmd, " "))
_, _, err := n.containerManager.ExecTxCmd(n.t, n.chainID, n.Name, cmd)
require.NoError(n.t, err)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (s *IntegrationTestSuite) TestFeeTaxWasm() {
strconv.Itoa(chain.LatestCodeID),
`{"count": "0"}`, "salt",
transferCoin.String(),
fmt.Sprintf("%duluna", stabilityFee), "test")
fmt.Sprintf("%duluna", stabilityFee), "300000", "test")

contracts, err = node.QueryContractsFromID(chain.LatestCodeID)
s.Require().NoError(err)
Expand Down
65 changes: 60 additions & 5 deletions x/tax2gas/post/burntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/auth/types"

oracle "github.com/classic-terra/core/v3/x/oracle/types"
treasury "github.com/classic-terra/core/v3/x/treasury/types"
distributiontypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
)

// BurnTaxSplit splits
func (tdd Tax2gasPostDecorator) BurnTaxSplit(ctx sdk.Context, taxes sdk.Coins) (err error) {
burnSplitRate := tdd.treasuryKeeper.GetBurnSplitRate(ctx)
func (fd Tax2gasPostDecorator) BurnTaxSplit(ctx sdk.Context, taxes sdk.Coins) (err error) {
burnSplitRate := fd.treasuryKeeper.GetBurnSplitRate(ctx)
oracleSplitRate := fd.treasuryKeeper.GetOracleSplitRate(ctx)
communityTax := fd.distrKeeper.GetCommunityTax(ctx)
distributionDeltaCoins := sdk.NewCoins()
oracleSplitCoins := sdk.NewCoins()
communityTaxCoins := sdk.NewCoins()

if burnSplitRate.IsPositive() {
distributionDeltaCoins := sdk.NewCoins()

for _, taxCoin := range taxes {
splitcoinAmount := burnSplitRate.MulInt(taxCoin.Amount).RoundInt()
Expand All @@ -24,8 +30,57 @@ func (tdd Tax2gasPostDecorator) BurnTaxSplit(ctx sdk.Context, taxes sdk.Coins) (
taxes = taxes.Sub(distributionDeltaCoins...)
}

if communityTax.IsPositive() {

// we need to apply a reduced community tax here as the community tax is applied again during distribution
// in the distribution module and we don't want to calculate the tax twice
// the reduction depends on the oracle split rate as well as on the community tax itself
// the formula can be applied even with a zero oracle split rate
applyCommunityTax := communityTax.Mul(oracleSplitRate.Quo(communityTax.Mul(oracleSplitRate).Add(sdk.OneDec()).Sub(communityTax)))

for _, distrCoin := range distributionDeltaCoins {
communityTaxAmount := applyCommunityTax.MulInt(distrCoin.Amount).RoundInt()
communityTaxCoins = communityTaxCoins.Add(sdk.NewCoin(distrCoin.Denom, communityTaxAmount))
}

distributionDeltaCoins = distributionDeltaCoins.Sub(communityTaxCoins...)
}

if !communityTaxCoins.IsZero() {
if err = fd.bankKeeper.SendCoinsFromModuleToModule(
ctx,
types.FeeCollectorName,
distributiontypes.ModuleName,
communityTaxCoins,
); err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}

feePool := fd.distrKeeper.GetFeePool(ctx)
feePool.CommunityPool = feePool.CommunityPool.Add(sdk.NewDecCoinsFromCoins(communityTaxCoins...)...)
fd.distrKeeper.SetFeePool(ctx, feePool)
}

if oracleSplitRate.IsPositive() {
for _, distrCoin := range distributionDeltaCoins {
oracleCoinAmnt := oracleSplitRate.MulInt(distrCoin.Amount).RoundInt()
oracleSplitCoins = oracleSplitCoins.Add(sdk.NewCoin(distrCoin.Denom, oracleCoinAmnt))
}
}

if !oracleSplitCoins.IsZero() {
if err = fd.bankKeeper.SendCoinsFromModuleToModule(
ctx,
types.FeeCollectorName,
oracle.ModuleName,
oracleSplitCoins,
); err != nil {
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error())
}
}

if !taxes.IsZero() {
if err = tdd.bankKeeper.SendCoinsFromModuleToModule(
if err = fd.bankKeeper.SendCoinsFromModuleToModule(
ctx,
types.FeeCollectorName,
treasury.BurnModuleName,
Expand All @@ -36,6 +91,6 @@ func (tdd Tax2gasPostDecorator) BurnTaxSplit(ctx sdk.Context, taxes sdk.Coins) (
}

// Record tax proceeds
tdd.treasuryKeeper.RecordEpochTaxProceeds(ctx, taxes)
fd.treasuryKeeper.RecordEpochTaxProceeds(ctx, taxes)
return nil
}
9 changes: 9 additions & 0 deletions x/treasury/keeper/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ func (k Keeper) SetMinInitialDepositRatio(ctx sdk.Context, minInitialDepositRati
k.paramSpace.Set(ctx, types.KeyMinInitialDepositRatio, minInitialDepositRatio)
}

func (k Keeper) GetOracleSplitRate(ctx sdk.Context) (res sdk.Dec) {
k.paramSpace.Get(ctx, types.KeyOracleSplit, &res)
return
}

func (k Keeper) SetOracleSplitRate(ctx sdk.Context, oracleSplit sdk.Dec) {
k.paramSpace.Set(ctx, types.KeyOracleSplit, oracleSplit)
}

// GetParams returns the total set of treasury parameters.
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSetIfExists(ctx, &params)
Expand Down
29 changes: 29 additions & 0 deletions x/treasury/types/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
KeyWindowProbation = []byte("WindowProbation")
KeyBurnTaxSplit = []byte("BurnTaxSplit")
KeyMinInitialDepositRatio = []byte("MinInitialDepositRatio")
KeyOracleSplit = []byte("OracleSplit")
)

// Default parameter values
Expand All @@ -47,6 +48,7 @@ var (
DefaultRewardWeight = sdk.NewDecWithPrec(5, 2) // 5%
DefaultBurnTaxSplit = sdk.NewDecWithPrec(1, 1) // 10% goes to community pool, 90% burn
DefaultMinInitialDepositRatio = sdk.ZeroDec() // 0% min initial deposit
DefaultOracleSplit = sdk.OneDec() // 100% oracle, community tax (CP) is deducted before oracle split
)

var _ paramstypes.ParamSet = &Params{}
Expand All @@ -63,6 +65,7 @@ func DefaultParams() Params {
WindowProbation: DefaultWindowProbation,
BurnTaxSplit: DefaultBurnTaxSplit,
MinInitialDepositRatio: DefaultMinInitialDepositRatio,
OracleSplit: DefaultOracleSplit,
}
}

Expand Down Expand Up @@ -90,6 +93,7 @@ func (p *Params) ParamSetPairs() paramstypes.ParamSetPairs {
paramstypes.NewParamSetPair(KeyWindowProbation, &p.WindowProbation, validateWindowProbation),
paramstypes.NewParamSetPair(KeyBurnTaxSplit, &p.BurnTaxSplit, validateBurnTaxSplit),
paramstypes.NewParamSetPair(KeyMinInitialDepositRatio, &p.MinInitialDepositRatio, validateMinInitialDepositRatio),
paramstypes.NewParamSetPair(KeyOracleSplit, &p.OracleSplit, validateOraceSplit),
}
}

Expand Down Expand Up @@ -137,6 +141,14 @@ func (p Params) Validate() error {
return fmt.Errorf("treasury parameter WindowLong must be bigger than WindowShort: (%d, %d)", p.WindowLong, p.WindowShort)
}

if p.OracleSplit.IsNegative() {
return fmt.Errorf("treasury parameter OracleSplit must be positive: %s", p.OracleSplit)
}

if p.OracleSplit.GT(sdk.OneDec()) {
return fmt.Errorf("treasury parameter OracleSplit must be less than or equal to 1.0: %s", p.OracleSplit)
}

return nil
}

Expand Down Expand Up @@ -268,3 +280,20 @@ func validateMinInitialDepositRatio(i interface{}) error {

return nil
}

func validateOraceSplit(i interface{}) error {
v, ok := i.(sdk.Dec)
if !ok {
return fmt.Errorf("invalid paramater type: %T", i)
}

if v.IsNegative() {
return fmt.Errorf("oracle split must be positive: %s", v)
}

if v.GT(sdk.OneDec()) {
return fmt.Errorf("oracle split must be less than or equal to 1.0: %s", v)
}

return nil
}
Loading

0 comments on commit 693a641

Please sign in to comment.