-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Shrenuj Bansal <shrenuj@dydx.exchange>
- Loading branch information
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package v5_0_0 | ||
|
||
import ( | ||
store "cosmossdk.io/store/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v5.0.0" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: store.StoreUpgrades{ | ||
Added: []string{}, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package v5_0_0 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
perptypes "github.com/dydxprotocol/v4-chain/protocol/x/perpetuals/types" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
) | ||
|
||
// Set all existing perpetuals to cross market type | ||
func perpetualsUpgrade( | ||
ctx sdk.Context, | ||
perpetualsKeeper perptypes.PerpetualsKeeper, | ||
) error { | ||
|
||
// Set all perpetuals to cross market type | ||
perpetuals, err := perpetualsKeeper.GetAllPerpetuals(ctx) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to get all perpetuals: %s", err)) | ||
} | ||
for _, p := range perpetuals { | ||
_, err = perpetualsKeeper.SetPerpetualMarketType(ctx, p.GetId(), | ||
perptypes.PerpetualMarketType_PERPETUAL_MARKET_TYPE_CROSS) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to set perpetual market type for perpetual %d: %s", p.GetId(), err)) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
perpetualsKeeper perptypes.PerpetualsKeeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx context.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
sdkCtx := lib.UnwrapSDKContext(ctx, "app/upgrades") | ||
sdkCtx.Logger().Info(fmt.Sprintf("Running %s Upgrade...", UpgradeName)) | ||
|
||
// Set all perpetuals to cross market type | ||
perpetualsUpgrade(sdkCtx, perpetualsKeeper) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters