-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Tian Qin <[email protected]>
- Loading branch information
1 parent
a1af1f5
commit 181aad3
Showing
4 changed files
with
81 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package v_5_2_0 | ||
|
||
import ( | ||
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v5.2.0" | ||
) | ||
|
||
var Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
} |
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,61 @@ | ||
package v_5_2_0 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
upgradetypes "cosmossdk.io/x/upgrade/types" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/dydxprotocol/v4-chain/protocol/lib" | ||
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
vaultkeeper "github.com/dydxprotocol/v4-chain/protocol/x/vault/keeper" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
clobKeeper clobtypes.ClobKeeper, | ||
vaultKeeper vaultkeeper.Keeper, | ||
) 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)) | ||
|
||
// Migrate x/clob. | ||
clobKeeper.UnsafeMigrateOrderExpirationState(sdkCtx) | ||
|
||
// Migrate x/vault. | ||
setVaultOrderExpirationSecondsToSixty(sdkCtx, vaultKeeper) | ||
addAllVaultsToVaultAddressStore(sdkCtx, vaultKeeper) | ||
|
||
return mm.RunMigrations(ctx, configurator, vm) | ||
} | ||
} | ||
|
||
// addAllVaultsToVaultAddressStore adds all existing vaults to Vault Address store. | ||
func addAllVaultsToVaultAddressStore( | ||
ctx sdk.Context, | ||
vaultKeeper vaultkeeper.Keeper, | ||
) { | ||
allVaults := vaultKeeper.GetAllVaults(ctx) | ||
for _, vault := range allVaults { | ||
vaultKeeper.AddVaultToAddressStore(ctx, *vault.VaultId) | ||
} | ||
} | ||
|
||
// setVaultOrderExpirationSecondsToSixty sets vault module param `OrderExpirationSeconds` to 60. | ||
func setVaultOrderExpirationSecondsToSixty( | ||
ctx sdk.Context, | ||
vaultKeeper vaultkeeper.Keeper, | ||
) { | ||
params := vaultKeeper.GetParams(ctx) | ||
params.OrderExpirationSeconds = 60 | ||
err := vaultKeeper.SetParams( | ||
ctx, | ||
params, | ||
) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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