-
Notifications
You must be signed in to change notification settings - Fork 126
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
[TRA-70] Add state migrations for isolated markets #1155
Changes from 5 commits
a78c68b
7d63b0a
142696a
321628d
f7d05e3
19a71ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,7 +111,7 @@ func (k Keeper) CreatePerpetual( | |
} | ||
|
||
// Store the new perpetual. | ||
k.setPerpetual(ctx, perpetual) | ||
k.SetPerpetual(ctx, perpetual) | ||
|
||
k.SetEmptyPremiumSamples(ctx) | ||
k.SetEmptyPremiumVotes(ctx) | ||
|
@@ -165,7 +165,7 @@ func (k Keeper) ModifyPerpetual( | |
} | ||
|
||
// Store the modified perpetual. | ||
k.setPerpetual(ctx, perpetual) | ||
k.SetPerpetual(ctx, perpetual) | ||
|
||
// Emit indexer event. | ||
k.GetIndexerEventManager().AddTxnEvent( | ||
|
@@ -186,6 +186,40 @@ func (k Keeper) ModifyPerpetual( | |
return perpetual, nil | ||
} | ||
|
||
func (k Keeper) SetPerpetualMarketType( | ||
shrenujb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ctx sdk.Context, | ||
perpetualId uint32, | ||
marketType types.PerpetualMarketType, | ||
) (types.Perpetual, error) { | ||
if marketType == types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED { | ||
return types.Perpetual{}, errorsmod.Wrap( | ||
types.ErrInvalidMarketType, | ||
fmt.Sprintf("invalid market type %v for perpetual %d", marketType, perpetualId), | ||
) | ||
} | ||
|
||
// Get perpetual. | ||
perpetual, err := k.GetPerpetual(ctx, perpetualId) | ||
if err != nil { | ||
return perpetual, err | ||
} | ||
|
||
if perpetual.Params.MarketType != types.PerpetualMarketType_PERPETUAL_MARKET_TYPE_UNSPECIFIED { | ||
return types.Perpetual{}, errorsmod.Wrap( | ||
types.ErrInvalidMarketType, | ||
fmt.Sprintf("perpetual %d already has market type %v", perpetualId, perpetual.Params.MarketType), | ||
) | ||
} | ||
|
||
// Modify perpetual. | ||
perpetual.Params.MarketType = marketType | ||
|
||
// Store the modified perpetual. | ||
k.SetPerpetual(ctx, perpetual) | ||
|
||
return perpetual, nil | ||
} | ||
Comment on lines
+189
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The implementation of
Consider revisiting the implementation logic concerning the ability to update the market type of a perpetual, especially in light of the discussions and objectives outlined in the PR and previous comments. |
||
|
||
// GetPerpetual returns a perpetual from its id. | ||
func (k Keeper) GetPerpetual( | ||
ctx sdk.Context, | ||
|
@@ -1181,7 +1215,7 @@ func (k Keeper) ModifyFundingIndex( | |
bigFundingIndex.Add(bigFundingIndex, bigFundingIndexDelta) | ||
|
||
perpetual.FundingIndex = dtypes.NewIntFromBigInt(bigFundingIndex) | ||
k.setPerpetual(ctx, perpetual) | ||
k.SetPerpetual(ctx, perpetual) | ||
return nil | ||
} | ||
|
||
|
@@ -1207,7 +1241,7 @@ func (k Keeper) SetEmptyPremiumVotes( | |
) | ||
} | ||
|
||
func (k Keeper) setPerpetual( | ||
func (k Keeper) SetPerpetual( | ||
ctx sdk.Context, | ||
perpetual types.Perpetual, | ||
) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to
perpetualsUpgrade
withinCreateUpgradeHandler
does not handle potential errors. Consider capturing and handling any errors returned byperpetualsUpgrade
to ensure that the upgrade process can respond appropriately to failures.