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

v14 mainet upgrade handler #894

Merged
merged 2 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading