Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
inon-man committed Jun 22, 2023
1 parent ba605e0 commit 78cadb5
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 41 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/auth) [ebba05](https://github.com/classic-terra/core/commit/ebba0521fec4fc5655d90c0b3fdb2dbb2ec8d11f) Added Z's fix for the feeutils.go
* (x/auth) [7fe446](https://github.com/classic-terra/core/commit/7fe4468fab7a767b8779e093d671a69f26b19781) allow uluna to be taxed

## [v1.0.4](https://github.com/terra-money/classic-core/releases/tag/v0.5.23) - 2022-12-07
## [v0.5.23](https://github.com/terra-money/classic-core/releases/tag/v0.5.23) - 2022-12-07

### State Machine Breaking
* [#800](https://github.com/terra-money/classic-core/pull/800) Tax and Burn
Expand Down
23 changes: 13 additions & 10 deletions app/upgrades/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ that each upgrade implements. These then get included in the application
app.go to run the upgrade.

## Upgrade History
* Initial release (v1)
* (soft-fork) v0.5.20 - Disable swap and IBC
* (soft-fork) v1.0.4 - Enable IBC
* (soft-fork) v1.0.5 - Set module version map for enabling software upgrades
* Upgrade: v2
* (treasury) Tax exemption list, burn tax split
* Upgrade: v3
* (treasury) Minimum initial deposit
* Upgrade: v4
* (staking) Minimum commision rate
### v1
__NOTE__: initial version without upgrade handler
* (soft-fork) v0.5.20 - Disable swap and IBC [#760](https://github.com/terra-money/classic-core/pull/760)
* (soft-fork) v0.5.21 - Burn Tax and allow Luna to be taxed
* (soft-fork) v0.5.22 - Limit validator power to 20% [cosmos-sdk/pull/104](https://github.com/terra-money/cosmos-sdk/pull/104)
* (soft-fork) v0.5.23 - Enable IBC
* (soft-fork) v1.0.5 - Set module version map for enabling software upgrades
### v2
* (treasury) Tax exemption list, burn tax split
### v3
* (treasury) Minimum initial deposit
### v4
* (staking) Minimum commision rate

## Upgrade types

Expand Down
2 changes: 1 addition & 1 deletion app/upgrades/v1/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var DisableSwapFork = upgrades.Fork{
}

var IbcEnableFork = upgrades.Fork{
UpgradeName: "v1.0.4",
UpgradeName: "v0.5.23",
UpgradeHeight: fork.IbcEnableHeight,
BeginForkLogic: runForkLogicIbcEnable,
}
Expand Down
5 changes: 2 additions & 3 deletions custom/auth/ante/burntax.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ func NewBurnTaxFeeDecorator(accountKeeper cosmosante.AccountKeeper, treasuryKeep

// AnteHandle handles msg tax fee checking
func (btfd BurnTaxFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
// Do not proceed if you are below this block height
// ChainID check is required to test burn tax in the testnet
if fork.IsBeforeTaxPowerUpgradeHeight(ctx) {
// Do not proceed if you are below BurnTaxUpgradeHeight block height
if fork.IsBeforeBurnTaxUpgradeHeight(ctx) {
return next(ctx, tx, simulate)
}

Expand Down
2 changes: 1 addition & 1 deletion custom/auth/ante/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (suite *AnteTestSuite) TestIntegrationTaxExemption() {
)
suite.Require().NoError(err)

suite.ctx = suite.ctx.WithBlockHeight(fork.TaxPowerUpgradeHeight)
suite.ctx = suite.ctx.WithBlockHeight(fork.BurnTaxUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

tk.AddBurnTaxExemptionAddress(suite.ctx, addrs[0].String())
Expand Down
4 changes: 2 additions & 2 deletions custom/auth/ante/tax.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ func computeTax(ctx sdk.Context, tk TreasuryKeeper, principal sdk.Coins) sdk.Coi
taxes := sdk.Coins{}

for _, coin := range principal {
// Originally only a stability tax on UST. Changed to tax Luna as well after TaxPowerUpgradeHeight
if (coin.Denom == types.MicroLunaDenom || coin.Denom == sdk.DefaultBondDenom) && fork.IsBeforeTaxPowerUpgradeHeight(ctx) {
// Originally only a stability tax on UST. Changed to tax Luna as well after BurnTaxUpgradeHeight
if (coin.Denom == types.MicroLunaDenom || coin.Denom == sdk.DefaultBondDenom) && fork.IsBeforeBurnTaxUpgradeHeight(ctx) {
continue
}
if coin.Denom == sdk.DefaultBondDenom {
Expand Down
2 changes: 1 addition & 1 deletion custom/auth/ante/tax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ func (suite *AnteTestSuite) TestTaxExemption() {
tk.SetBurnSplitRate(suite.ctx, sdk.NewDecWithPrec(5, 1))

fmt.Printf("CASE = %s \n", c.name)
suite.ctx = suite.ctx.WithBlockHeight(fork.TaxPowerUpgradeHeight)
suite.ctx = suite.ctx.WithBlockHeight(fork.BurnTaxUpgradeHeight)
suite.txBuilder = suite.clientCtx.TxConfig.NewTxBuilder()

tk.AddBurnTaxExemptionAddress(suite.ctx, addrs[0].String())
Expand Down
38 changes: 28 additions & 10 deletions types/fork/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@ import (
)

const (
ColumbusLunaSwapFeeHeight = int64(5_100_000)
BombayLunaSwapFeeHeight = int64(6_200_000)
ColumbusOracleFixHeight = int64(5_701_000)
BombayOracleFixHeight = int64(7_000_000)
// v0.5.20
// SwapDisableHeight - make min spread to 100% to disable swap
SwapDisableHeight = 7_607_790
// TaxPowerUpgradeHeight is when taxes are allowed to go into effect
SwapDisableHeight = int64(7_607_790)
// v0.5.21
// BurnTaxUpgradeHeight is when taxes are allowed to go into effect
// This will still need a parameter change proposal, but can be activated
// anytime after this height
TaxPowerUpgradeHeight = 9_346_889
BurnTaxUpgradeHeight = int64(9_346_889)
// v0.5.23
// IbcEnableHeight - renable IBC only, block height is approximately December 5th, 2022
IbcEnableHeight = 10_542_500
IbcEnableHeight = int64(10_542_500)
// v1.0.5
// VersionMapEnableHeight - set the version map to enable software upgrades, approximately February 14, 2023
VersionMapEnableHeight = 11_543_150
VersionMapEnableHeight = int64(11_543_150)
)

func IsBeforeTaxPowerUpgradeHeight(ctx sdk.Context) bool {
func IsBeforeLunaSwapFeeHeight(ctx sdk.Context) bool {
return (ctx.ChainID() == types.ColumbusChainID && ctx.BlockHeight() < ColumbusLunaSwapFeeHeight) ||
(ctx.ChainID() == types.BombayChainID && ctx.BlockHeight() < BombayLunaSwapFeeHeight)
}

func IsBeforeOracleFixHeight(ctx sdk.Context) bool {
return (ctx.ChainID() == types.ColumbusChainID && ctx.BlockHeight() < ColumbusOracleFixHeight) ||
(ctx.ChainID() == types.BombayChainID && ctx.BlockHeight() < BombayOracleFixHeight)
}

func IsBeforeBurnTaxUpgradeHeight(ctx sdk.Context) bool {
currHeight := ctx.BlockHeight()
// TODO: There's no columbus check condition because of test failures
return currHeight < TaxPowerUpgradeHeight
// TODO: There's no ChainID check condition because of test failures
return currHeight < BurnTaxUpgradeHeight
}

func IsAfterPowerUpgradeHeight(ctx sdk.Context) bool {
func IsAfterBurnTaxUpgradeHeight(ctx sdk.Context) bool {
currHeight := ctx.BlockHeight()
return ctx.ChainID() == types.ColumbusChainID && currHeight >= TaxPowerUpgradeHeight
return ctx.ChainID() == types.ColumbusChainID && currHeight >= BurnTaxUpgradeHeight
}
2 changes: 1 addition & 1 deletion wasmbinding/test/tax_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (s *WasmTestSuite) TestTax() {
toAddress := s.TestAccs[1]
// fund an account
s.FundAcc(payer, sdk.NewCoins(sdk.NewInt64Coin("uluna", 1000000000)))
s.Ctx = s.Ctx.WithBlockHeight(fork.TaxPowerUpgradeHeight + 1)
s.Ctx = s.Ctx.WithBlockHeight(fork.BurnTaxUpgradeHeight + 1)

// instantiate reflect contract
contractAddr := s.InstantiateContract(payer, TerraBindingsPath)
Expand Down
3 changes: 2 additions & 1 deletion x/market/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"

core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
"github.com/classic-terra/core/v2/x/market/keeper"
"github.com/classic-terra/core/v2/x/market/types"
)
Expand All @@ -35,7 +36,7 @@ func TestSwapMsg_FailZeroReturn(t *testing.T) {
params.MinStabilitySpread = sdk.OneDec()
input.MarketKeeper.SetParams(input.Ctx, params)

input.Ctx = input.Ctx.WithChainID(core.ColumbusChainID).WithBlockHeight(core.SwapDisableHeight)
input.Ctx = input.Ctx.WithChainID(core.ColumbusChainID).WithBlockHeight(fork.SwapDisableHeight)

amt := sdk.NewInt(10)
offerCoin := sdk.NewCoin(core.MicroLunaDenom, amt)
Expand Down
7 changes: 3 additions & 4 deletions x/oracle/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"time"

core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
"github.com/classic-terra/core/v2/x/oracle/keeper"
"github.com/classic-terra/core/v2/x/oracle/types"

Expand Down Expand Up @@ -65,8 +66,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
var exchangeRateRT sdk.Dec

// softfork
if (ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() < int64(5_701_000)) ||
(ctx.ChainID() == core.BombayChainID && ctx.BlockHeight() < int64(7_000_000)) {
if fork.IsBeforeOracleFixHeight(ctx) {
exchangeRateRT = ballotRT.WeightedMedian()
} else {
exchangeRateRT = ballotRT.WeightedMedianWithAssertion()
Expand All @@ -78,8 +78,7 @@ func EndBlocker(ctx sdk.Context, k keeper.Keeper) {
// Convert ballot to cross exchange rates
if denom != referenceTerra {
// softfork
if (ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() < int64(5_701_000)) ||
(ctx.ChainID() == core.BombayChainID && ctx.BlockHeight() < int64(7_000_000)) {
if fork.IsBeforeOracleFixHeight(ctx) {
ballot = ballot.ToCrossRate(voteMapRT)
} else {
ballot = ballot.ToCrossRateWithSort(voteMapRT)
Expand Down
5 changes: 3 additions & 2 deletions x/oracle/keeper/reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"

core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
"github.com/classic-terra/core/v2/x/oracle/types"
)

Expand All @@ -21,12 +22,12 @@ func (k Keeper) RewardBallotWinners(
ballotWinners map[string]types.Claim,
) {
// softfork for reward distribution
if (ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() < int64(5_100_000)) ||
(ctx.ChainID() == core.BombayChainID && ctx.BlockHeight() < int64(6_200_000)) {
if fork.IsBeforeLunaSwapFeeHeight(ctx) {
k.RewardBallotWinnersLegacy(ctx, votePeriod, rewardDistributionWindow, ballotWinners)
return
}

// Add Luna explicitly for oracle account balance coming from the market swap fee
rewardDenoms := make([]string, len(voteTargets)+1)
rewardDenoms[0] = core.MicroLunaDenom

Expand Down
5 changes: 2 additions & 3 deletions x/oracle/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package oracle
import (
sdk "github.com/cosmos/cosmos-sdk/types"

core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/types/fork"
"github.com/classic-terra/core/v2/x/oracle/keeper"
"github.com/classic-terra/core/v2/x/oracle/types"
)
Expand All @@ -13,8 +13,7 @@ import (
// CONTRACT: pb must be sorted
func Tally(ctx sdk.Context, pb types.ExchangeRateBallot, rewardBand sdk.Dec, validatorClaimMap map[string]types.Claim) (weightedMedian sdk.Dec) {
// softfork
if (ctx.ChainID() == core.ColumbusChainID && ctx.BlockHeight() < int64(5_701_000)) ||
(ctx.ChainID() == core.BombayChainID && ctx.BlockHeight() < int64(7_000_000)) {
if fork.IsBeforeOracleFixHeight(ctx) {
weightedMedian = pb.WeightedMedian()
} else {
weightedMedian = pb.WeightedMedianWithAssertion()
Expand Down
2 changes: 1 addition & 1 deletion x/treasury/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (k Keeper) SetTaxCap(ctx sdk.Context, denom string, cap sdk.Int) {
// GetTaxCap gets the tax cap denominated in integer units of the reference {denom}
func (k Keeper) GetTaxCap(ctx sdk.Context, denom string) sdk.Int {
// Allow tax cap for uluna
if denom == core.MicroLunaDenom && fork.IsAfterPowerUpgradeHeight(ctx) {
if denom == core.MicroLunaDenom && fork.IsAfterBurnTaxUpgradeHeight(ctx) {
return sdk.ZeroInt()
}

Expand Down

0 comments on commit 78cadb5

Please sign in to comment.