-
Notifications
You must be signed in to change notification settings - Fork 115
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
[CT-619] deprecate pessimistic add-to-book collateralization check #1107
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
844eea0
[CT-619] deprecate pessimistic add-to-book collateralization check
jayy04 69c9879
fix lint
jayy04 28be1b0
fix e2e test
jayy04 7cb7ad3
fix test
jayy04 6ac1ae7
Update protocol/x/clob/keeper/orders_test.go
jayy04 b733c1a
Update protocol/x/clob/keeper/orders_test.go
jayy04 1473914
remove comments
jayy04 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/dydxprotocol/v4-chain/protocol/dtypes" | ||
indexerevents "github.com/dydxprotocol/v4-chain/protocol/indexer/events" | ||
|
||
cmt "github.com/cometbft/cometbft/types" | ||
|
@@ -515,12 +516,10 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
clobs: []types.ClobPair{ | ||
constants.ClobPair_Btc, | ||
}, | ||
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price5subticks_GTB10, | ||
expectedOrderStatus: types.Undercollateralized, | ||
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price5subticks_GTB10, | ||
expectedErr: types.ErrOrderWouldExceedMaxOpenOrdersEquityTierLimit, | ||
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. this and the test below now fails because of equity tier limit and not collat check |
||
}, | ||
`Subaccount cannot place maker sell order for 1 BTC at 500,000 with 0 collateral`: { | ||
perpetuals: []perptypes.Perpetual{ | ||
|
@@ -530,20 +529,18 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
clobs: []types.ClobPair{ | ||
constants.ClobPair_Btc, | ||
}, | ||
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Sell1BTC_Price500000_GTB10, | ||
expectedOrderStatus: types.Undercollateralized, | ||
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Sell1BTC_Price500000_GTB10, | ||
expectedErr: types.ErrOrderWouldExceedMaxOpenOrdersEquityTierLimit, | ||
}, | ||
// <grouped tests: pessimistic value collateralization check -- BUY> | ||
// The following 3 tests are a group to test the pessimistic value used for the collateralization check. | ||
// 1. The first should have a lower asset value in its subaccount. (undercollateralized) | ||
// <grouped tests: deprecating pessimistic value collateralization check -- BUY> | ||
// The following 3 tests are a group to test the deprecation of pessimistic collateralization check. | ||
// 1. The first should have a buy price well below the oracle price of 50,000. (success) | ||
// 2. The second should have a buy price above the oracle price of 50,000. (undercollateralized) | ||
// 3. The third should have the order in common with #1 and the subaccount in common with #2 and should succeed. | ||
`Subaccount cannot place buy order due to a failed collateralization check with the oracle price but would | ||
pass if using the maker price`: { | ||
`Subaccount can now place buy order that would have failed the | ||
deprecated pessimistic collateralization check with the oracle price`: { | ||
perpetuals: []perptypes.Perpetual{ | ||
constants.BtcUsd_50PercentInitial_40PercentMaintenance, | ||
}, | ||
|
@@ -554,7 +551,7 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Buy1BTC_Price5subticks_GTB10, | ||
expectedOrderStatus: types.Undercollateralized, | ||
expectedOrderStatus: types.Success, | ||
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
}, | ||
|
@@ -574,7 +571,7 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
}, | ||
`Subaccount placed buy order passes collateralization check when using the oracle price`: { | ||
`Subaccount placed buy order passes collateralization check when using the maker price`: { | ||
perpetuals: []perptypes.Perpetual{ | ||
constants.BtcUsd_50PercentInitial_40PercentMaintenance, | ||
}, | ||
|
@@ -590,13 +587,13 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
expectedMultiStoreWrites: []string{}, | ||
}, | ||
// <end of grouped tests: pessimistic value collateralization check -- BUY> | ||
// <grouped tests: pessimistic value collateralization check -- SELL> | ||
// The following 3 tests are a group to test the pessimistic value used for the collateralization check. | ||
// 1. The first should have a lower asset value in its subaccount. (undercollateralized) | ||
// <grouped tests: deprecating pessimistic value collateralization check -- SELL> | ||
// The following 3 tests are a group to test the deprecation of pessimistic collateralization check. | ||
// 1. The first should have a sell price well above the oracle price of 50,000. (success) | ||
// 2. The second should have a sell price below the oracle price of 50,000 subticks. (undercollateralized) | ||
// 3. The third should have the order in common with #1 and the subaccount in common with #2 and should succeed. | ||
`Subaccount cannot place sell order due to a failed collateralization check with the oracle price but would | ||
pass if using the maker price`: { | ||
`Subaccount can now place sell order that would have failed the | ||
deprecated pessimistic collateralization check with the oracle price`: { | ||
perpetuals: []perptypes.Perpetual{ | ||
constants.BtcUsd_50PercentInitial_40PercentMaintenance, | ||
}, | ||
|
@@ -607,7 +604,7 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
existingOrders: []types.Order{}, | ||
feeParams: constants.PerpetualFeeParamsNoFee, | ||
order: constants.Order_Carl_Num0_Id0_Clob0_Sell1BTC_Price500000_GTB10, | ||
expectedOrderStatus: types.Undercollateralized, | ||
expectedOrderStatus: types.Success, | ||
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
}, | ||
|
@@ -627,7 +624,7 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
expectedFilledSize: 0, | ||
expectedMultiStoreWrites: []string{}, | ||
}, | ||
`Subaccount placed sell order passes collateralization check when using the oracle price`: { | ||
`Subaccount placed sell order passes collateralization check when using the maker price`: { | ||
perpetuals: []perptypes.Perpetual{ | ||
constants.BtcUsd_50PercentInitial_40PercentMaintenance, | ||
}, | ||
|
@@ -705,6 +702,25 @@ func TestPlaceShortTermOrder(t *testing.T) { | |
require.NoError(t, err) | ||
} | ||
|
||
err = ks.ClobKeeper.InitializeEquityTierLimit( | ||
ctx, | ||
types.EquityTierLimitConfiguration{ | ||
ShortTermOrderEquityTiers: []types.EquityTierLimit{ | ||
{ | ||
UsdTncRequired: dtypes.NewInt(20_000_000), | ||
Limit: 5, | ||
}, | ||
}, | ||
StatefulOrderEquityTiers: []types.EquityTierLimit{ | ||
{ | ||
UsdTncRequired: dtypes.NewInt(20_000_000), | ||
Limit: 5, | ||
}, | ||
}, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
// Create all existing orders. | ||
for _, order := range tc.existingOrders { | ||
_, _, err := ks.ClobKeeper.PlaceShortTermOrder(ctx, &types.MsgPlaceOrder{Order: order}) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
give alice some money so that she fails b/c collat check and not equity tier