Skip to content

Commit

Permalink
v14 mainet upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Jun 20, 2024
1 parent 2f57d14 commit 02aaabb
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 10 deletions.
8 changes: 4 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ import (
cwasm "github.com/comdex-official/comdex/app/wasm"

mv13 "github.com/comdex-official/comdex/app/upgrades/mainnet/v13"
tv14 "github.com/comdex-official/comdex/app/upgrades/testnet/v14"
mv14 "github.com/comdex-official/comdex/app/upgrades/mainnet/v14"
)

const (
Expand Down Expand Up @@ -1544,8 +1544,8 @@ func (a *App) ModuleAccountsPermissions() map[string][]string {

func (a *App) registerUpgradeHandlers() {
a.UpgradeKeeper.SetUpgradeHandler(
tv14.UpgradeName,
tv14.CreateUpgradeHandlerV14(a.mm, a.configurator, a.AuctionKeeperSkip, a.LendKeeper, a.WasmKeeper, *a.StakingKeeper, a.MintKeeper, a.SlashingKeeper, a.BandoracleKeeper),
mv14.UpgradeName,
mv14.CreateUpgradeHandlerV14(a.mm, a.configurator, a.AuctionKeeperSkip, a.LendKeeper),
)
// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
Expand Down Expand Up @@ -1579,7 +1579,7 @@ func upgradeHandlers(upgradeInfo upgradetypes.Plan, a *App, storeUpgrades *store
ibcfeetypes.StoreKey,
},
}
case upgradeInfo.Name == tv14.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
case upgradeInfo.Name == mv14.UpgradeName && !a.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height):
storeUpgrades = &storetypes.StoreUpgrades{
Added: []string{
auctionmoduleskiptypes.StoreKey,
Expand Down
15 changes: 15 additions & 0 deletions app/upgrades/mainnet/v14/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package v14

const (
UpgradeName = "v14.1.0"
UpgradeHeight = ""
UpgradeInfo = `'{
"binaries": {
"darwin/arm64":"",
"darwin/x86_64":"",
"linux/arm64":"",
"linux/x86_64":"",
"windows/x86_64":""
}
}'`
)
39 changes: 39 additions & 0 deletions app/upgrades/mainnet/v14/upgrade_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package v14_test

import (
"github.com/comdex-official/comdex/app"
v14 "github.com/comdex-official/comdex/app/upgrades/mainnet/v14"
"github.com/stretchr/testify/suite"
"testing"
)

type UpgradeTestSuite struct {
app.KeeperTestHelper
}

func (s *UpgradeTestSuite) SetupTest() {
s.Setup()
}

func TestKeeperTestSuite(t *testing.T) {
suite.Run(t, new(UpgradeTestSuite))
}

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()

preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v14.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
}

func postUpgradeChecks(s *UpgradeTestSuite) {

}
68 changes: 68 additions & 0 deletions app/upgrades/mainnet/v14/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package v14

import (
lendkeeper "github.com/comdex-official/comdex/x/lend/keeper"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
auctionkeeperskip "github.com/skip-mev/block-sdk/x/auction/keeper"
auctionmoduleskiptypes "github.com/skip-mev/block-sdk/x/auction/types"
"strings"
)

func CreateUpgradeHandlerV14(
mm *module.Manager,
configurator module.Configurator,
auctionkeeperskip auctionkeeperskip.Keeper,
lendKeeper lendkeeper.Keeper,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {

ctx.Logger().Info("Applying main net upgrade - v14.1.0")
vm, err := mm.RunMigrations(ctx, configurator, fromVM)
if err != nil {
return vm, err
}

ctx.Logger().Info("setting default params for MEV module (x/auction)")
if err = setDefaultMEVParams(ctx, auctionkeeperskip); err != nil {
return nil, err
}

ctx.Logger().Info("updating lend params")
UpdateLendParams(ctx, lendKeeper)
return vm, err
}
}

func setDefaultMEVParams(ctx sdk.Context, auctionkeeperskip auctionkeeperskip.Keeper) error {
nativeDenom := getChainBondDenom(ctx.ChainID())

// Skip MEV (x/auction)
return auctionkeeperskip.SetParams(ctx, auctionmoduleskiptypes.Params{
MaxBundleSize: auctionmoduleskiptypes.DefaultMaxBundleSize,
EscrowAccountAddress: authtypes.NewModuleAddress(auctionmoduleskiptypes.ModuleName), // TODO: revisit
ReserveFee: sdk.NewCoin(nativeDenom, sdk.NewInt(10)),
MinBidIncrement: sdk.NewCoin(nativeDenom, sdk.NewInt(5)),
FrontRunningProtection: auctionmoduleskiptypes.DefaultFrontRunningProtection,
ProposerFee: auctionmoduleskiptypes.DefaultProposerFee,
})
}

// getChainBondDenom returns expected bond denom based on chainID.
func getChainBondDenom(chainID string) string {
if strings.HasPrefix(chainID, "comdex-") {
return "ucmdx"
}
return "stake"
}

func UpdateLendParams(
ctx sdk.Context,
lendKeeper lendkeeper.Keeper,
) {
assetRatesParamsStAtom, _ := lendKeeper.GetAssetRatesParams(ctx, 14)
assetRatesParamsStAtom.CAssetID = 23
lendKeeper.SetAssetRatesParams(ctx, assetRatesParamsStAtom)
}
12 changes: 6 additions & 6 deletions app/upgrades/testnet/v14/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package v14_test
import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/comdex-official/comdex/app"
v14 "github.com/comdex-official/comdex/app/upgrades/testnet/v14"
// v14 "github.com/comdex-official/comdex/app/upgrades/testnet/v14"
"github.com/stretchr/testify/suite"
"testing"
)
Expand All @@ -22,14 +22,14 @@ func TestKeeperTestSuite(t *testing.T) {

// Ensures the test does not error out.
func (s *UpgradeTestSuite) TestUpgrade() {
s.Setup()
// s.Setup()

preUpgradeChecks(s)
// preUpgradeChecks(s)

upgradeHeight := int64(5)
s.ConfirmUpgradeSucceeded(v14.UpgradeName, upgradeHeight)
// upgradeHeight := int64(5)
// s.ConfirmUpgradeSucceeded(v14.UpgradeName, upgradeHeight)

postUpgradeChecks(s)
// postUpgradeChecks(s)
}

func preUpgradeChecks(s *UpgradeTestSuite) {
Expand Down

0 comments on commit 02aaabb

Please sign in to comment.