-
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.
v0.2.2 hard fork to update clob pairs (#263)
* v0.2.2 hard fork to update clob pairs * remove from memclob * clear op queue * update numbers * update test * Add UpdateClobPair indexer event * recreate orderbook * missing args * clear untriggered conditional order struct * fix lint * fix multiple clob pair per perpetual issue * pass by value * disable trading until after upgrade * add unsafe reset memclob method * update subticks per tick and QCE to latest values * update pepe values --------- Co-authored-by: Teddy Ding <[email protected]>
- Loading branch information
Showing
17 changed files
with
214 additions
and
119 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
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
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,26 @@ | ||
package v0_2_2 | ||
|
||
import ( | ||
store "github.com/cosmos/cosmos-sdk/store/types" | ||
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades" | ||
) | ||
|
||
const ( | ||
UpgradeName = "v0.2.2" | ||
// Target upgrade time is Sept 15, 2023, 1pm EST, | ||
// estimated to occur on block 178500, assuming 1.5s block time. | ||
UpgradeHeight = 178500 | ||
) | ||
|
||
var ( | ||
Fork = upgrades.Fork{ | ||
UpgradeName: UpgradeName, | ||
UpgradeHeight: UpgradeHeight, | ||
UpgradeInfo: "", | ||
} | ||
|
||
Upgrade = upgrades.Upgrade{ | ||
UpgradeName: UpgradeName, | ||
StoreUpgrades: store.StoreUpgrades{}, | ||
} | ||
) |
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,64 @@ | ||
package v0_2_2 | ||
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/types/module" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" | ||
clobmodulekeeper "github.com/dydxprotocol/v4-chain/protocol/x/clob/keeper" | ||
clobtypes "github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
) | ||
|
||
func CreateUpgradeHandler( | ||
mm *module.Manager, | ||
configurator module.Configurator, | ||
clobKeeper *clobmodulekeeper.Keeper, | ||
) upgradetypes.UpgradeHandler { | ||
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { | ||
ctx.Logger().Info("Running v0.2.2 hard fork...") | ||
|
||
// Update clob pairs. | ||
clobPairs := clobKeeper.GetAllClobPairs(ctx) | ||
for _, clobPair := range clobPairs { | ||
switch clobPair.Id { | ||
case 0, 1: | ||
clobPair.SubticksPerTick = 1e5 | ||
clobPair.QuantumConversionExponent = -9 | ||
case 28: | ||
clobPair.SubticksPerTick = 1e6 | ||
clobPair.QuantumConversionExponent = -12 | ||
case 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, | ||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32: | ||
clobPair.SubticksPerTick = 1e6 | ||
clobPair.QuantumConversionExponent = -9 | ||
default: | ||
ctx.Logger().Error("Unknown clob pair id", "clobPairId", clobPair.Id) | ||
} | ||
clobKeeper.UnsafeSetClobPair( | ||
ctx, | ||
clobPair, | ||
) | ||
} | ||
|
||
// Delete all stateful ordes. | ||
placedStatefulOrders := clobKeeper.GetAllPlacedStatefulOrders(ctx) | ||
for _, order := range placedStatefulOrders { | ||
clobKeeper.MustRemoveStatefulOrder(ctx, order.OrderId) | ||
} | ||
|
||
untriggeredConditionalOrders := clobKeeper.GetAllUntriggeredConditionalOrders(ctx) | ||
for _, order := range untriggeredConditionalOrders { | ||
clobKeeper.MustRemoveStatefulOrder(ctx, order.OrderId) | ||
} | ||
clobKeeper.UntriggeredConditionalOrders = make( | ||
map[clobtypes.ClobPairId]*clobmodulekeeper.UntriggeredConditionalOrders, | ||
) | ||
|
||
// Update memclob. | ||
clobKeeper.MemClob.UnsafeResetMemclob(ctx) | ||
|
||
clobKeeper.PerpetualIdToClobPairId = make(map[uint32][]clobtypes.ClobPairId) | ||
clobKeeper.InitMemClobOrderbooks(ctx) | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
package app_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/app" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func TestDefaultUpgradesAndForks(t *testing.T) { | ||
require.Empty(t, app.Upgrades, "Expected empty upgrades list") | ||
require.Empty(t, app.Forks, "Expected empty forks list") | ||
require.Len(t, app.Upgrades, 1, "Expected 1 upgrade") | ||
require.Len(t, app.Forks, 1, "Expected 1 fork") | ||
} |
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,24 @@ | ||
package events | ||
|
||
import ( | ||
v1 "github.com/dydxprotocol/v4-chain/protocol/indexer/protocol/v1" | ||
"github.com/dydxprotocol/v4-chain/protocol/x/clob/types" | ||
) | ||
|
||
// NewUpdateClobPairEvent creates a UpdateClobPairEventV1 | ||
// representing update of a clob pair. | ||
func NewUpdateClobPairEvent( | ||
clobPairId uint32, | ||
status types.ClobPair_Status, | ||
quantumConversionExponent int32, | ||
subticksPerTick uint32, | ||
stepBaseQuantums uint64, | ||
) *UpdateClobPairEventV1 { | ||
return &UpdateClobPairEventV1{ | ||
ClobPairId: clobPairId, | ||
Status: v1.ConvertToClobPairStatus(status), | ||
QuantumConversionExponent: quantumConversionExponent, | ||
SubticksPerTick: subticksPerTick, | ||
StepBaseQuantums: stepBaseQuantums, | ||
} | ||
} |
Oops, something went wrong.