Skip to content

Commit

Permalink
Merge pull request #787 from cybercongress/v5-hardfork
Browse files Browse the repository at this point in the history
V5 hardfork
  • Loading branch information
cyborgshead authored Oct 20, 2024
2 parents 4f9d452 + fe9a35f commit 078928f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ var (
Bech32Prefix = "bostrom"

Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade}
Forks = []upgrades.Fork{v5.Fork}
)

// These constants are derived from the above variables.
Expand Down Expand Up @@ -339,6 +340,7 @@ func (app *App) Name() string {

// BeginBlocker application updates every begin block
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
BeginBlockForks(ctx, app)
return app.ModuleManager.BeginBlock(ctx, req)
}

Expand Down
15 changes: 15 additions & 0 deletions app/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package app

import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// BeginBlockForks is intended to be ran in a chain upgrade.
func BeginBlockForks(ctx sdk.Context, app *App) {
for _, fork := range Forks {
if ctx.BlockHeight() == fork.UpgradeHeight {
fork.BeginForkLogic(ctx, &app.AppKeepers)
return
}
}
}
15 changes: 15 additions & 0 deletions app/upgrades/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,18 @@ type Upgrade struct {
// Store upgrades, should be used for any new modules introduced, new modules deleted, or store names renamed.
StoreUpgrades store.StoreUpgrades
}

// Fork defines a struct containing the requisite fields for a non-software upgrade proposal
// Hard Fork at a given height to implement.
// There is one time code that can be added for the start of the Fork, in `BeginForkLogic`.
// Any other change in the code should be height-gated, if the goal is to have old and new binaries
// to be compatible prior to the upgrade height.
type Fork struct {
// Upgrade version name, for the upgrade handler, e.g. `v7`
UpgradeName string
// height the upgrade occurs at
UpgradeHeight int64

// Function that runs some custom state transition code at the beginning of a fork.
BeginForkLogic func(ctx sdk.Context, keepers *keepers.AppKeepers)
}
17 changes: 17 additions & 0 deletions app/upgrades/v5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package v5

import (
"github.com/cybercongress/go-cyber/v5/app/upgrades"
)

const (
UpgradeName = "v5"

UpgradeHeight = 15_700_842
)

var Fork = upgrades.Fork{
UpgradeName: UpgradeName,
UpgradeHeight: UpgradeHeight,
BeginForkLogic: RunForkLogic,
}
25 changes: 25 additions & 0 deletions app/upgrades/v5/forks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package v5

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cybercongress/go-cyber/v5/app/keepers"
)

func RunForkLogic(ctx sdk.Context, keepers *keepers.AppKeepers) {
logger := ctx.Logger().With("upgrade", UpgradeName)

logger.Info("Applying emergency hard fork for v5")

liquidityParams := keepers.LiquidityKeeper.GetParams(ctx)
liquidityParams.CircuitBreakerEnabled = true
err := keepers.LiquidityKeeper.SetParams(ctx, liquidityParams)
if err != nil {
panic(err)
}
logger.Info("set liquidity circuit breaker enabled, disable dex")

keepers.BankKeeper.SetSendEnabled(ctx, "millivolt", false)
keepers.BankKeeper.SetSendEnabled(ctx, "milliampere", false)

logger.Info("set bank send disabled for millivolt and amperes")
}
7 changes: 3 additions & 4 deletions x/resources/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,10 @@ func (k Keeper) CalculateInvestmint(ctx sdk.Context, amt sdk.Coin, resource stri
case ctypes.VOLT:
cycles := sdk.NewDec(int64(length)).QuoInt64(int64(params.BaseInvestmintPeriodVolt))
base := sdk.NewDec(amt.Amount.Int64()).QuoInt64(params.BaseInvestmintAmountVolt.Amount.Int64())

// TODO double check when third halving will be applied?
// NOTE out of parametrization custom code is applied here in order to shift the FIRST HALVING 6M BLOCKS LATER but keep base halving parameter same

// NOTE out of parametrization, custom code is applied here in order to shift the HALVINGS START 6M BLOCKS LATER but keep base halving parameter same
if ctx.BlockHeight() > 15000000 {
halving = sdk.NewDecWithPrec(int64(math.Pow(0.5, float64((ctx.BlockHeight()-600000)/int64(params.HalvingPeriodVoltBlocks)))*10000), 4)
halving = sdk.NewDecWithPrec(int64(math.Pow(0.5, float64((ctx.BlockHeight()-6000000)/int64(params.HalvingPeriodVoltBlocks)))*10000), 4)
} else {
halving = sdk.OneDec()
}
Expand Down

0 comments on commit 078928f

Please sign in to comment.