Skip to content

Commit

Permalink
nits
Browse files Browse the repository at this point in the history
  • Loading branch information
teddyding committed Mar 20, 2024
1 parent 3164b81 commit ccfca2d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
15 changes: 14 additions & 1 deletion protocol/x/subaccounts/keeper/oimf.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ func GetDeltaOpenInterestFromPerpMatchUpdates(
)
}

if settledUpdates[0].PerpetualUpdates[0].PerpetualId != settledUpdates[1].PerpetualUpdates[0].PerpetualId {
perpUpdate0 := settledUpdates[0].PerpetualUpdates[0]
perpUpdate1 := settledUpdates[1].PerpetualUpdates[0]

if perpUpdate0.PerpetualId != perpUpdate1.PerpetualId {
panic(
fmt.Sprintf(
types.ErrMatchUpdatesMustBeSamePerpId,
Expand All @@ -79,6 +82,16 @@ func GetDeltaOpenInterestFromPerpMatchUpdates(
updatedPerpId = settledUpdates[0].PerpetualUpdates[0].PerpetualId
}

if (perpUpdate0.BigQuantumsDelta.Sign()*perpUpdate0.BigQuantumsDelta.Sign() < 0) ||
perpUpdate0.BigQuantumsDelta.CmpAbs(perpUpdate1.BigQuantumsDelta) != 0 {
panic(
fmt.Sprintf(
types.ErrMatchUpdatesInvalidSize,
settledUpdates,
),
)
}

deltaOpenInterest = big.NewInt(0)
for _, u := range settledUpdates {
deltaLong := getDeltaLongFromSettledUpdate(u, updatedPerpId)
Expand Down
25 changes: 5 additions & 20 deletions protocol/x/subaccounts/keeper/subaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3247,10 +3247,7 @@ func TestCanUpdateSubaccounts(t *testing.T) {
},
additionalTestSubaccounts: []types.Subaccount{
{
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Id: &constants.Bob_Num0,
AssetPositions: []*types.AssetPosition{
{
AssetId: uint32(0),
Expand Down Expand Up @@ -3314,10 +3311,7 @@ func TestCanUpdateSubaccounts(t *testing.T) {
},
additionalTestSubaccounts: []types.Subaccount{
{
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Id: &constants.Bob_Num0,
AssetPositions: []*types.AssetPosition{
{
AssetId: uint32(0),
Expand Down Expand Up @@ -3388,10 +3382,7 @@ func TestCanUpdateSubaccounts(t *testing.T) {
},
additionalTestSubaccounts: []types.Subaccount{
{
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Id: &constants.Bob_Num0,
AssetPositions: []*types.AssetPosition{
{
AssetId: uint32(0),
Expand Down Expand Up @@ -3464,10 +3455,7 @@ func TestCanUpdateSubaccounts(t *testing.T) {
},
additionalTestSubaccounts: []types.Subaccount{
{
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Id: &constants.Bob_Num0,
AssetPositions: []*types.AssetPosition{
{
AssetId: uint32(0),
Expand Down Expand Up @@ -3539,10 +3527,7 @@ func TestCanUpdateSubaccounts(t *testing.T) {
},
additionalTestSubaccounts: []types.Subaccount{
{
Id: &types.SubaccountId{
Owner: "Bob",
Number: 0,
},
Id: &constants.Bob_Num0,
AssetPositions: []*types.AssetPosition{
{
AssetId: uint32(0),
Expand Down
4 changes: 3 additions & 1 deletion protocol/x/subaccounts/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ const (
"exactly 2 updates, got settledUpdates: %+v"
ErrMatchUpdatesMustUpdateOnePerp = "internalCanUpdateSubaccounts: MATCH subaccount updates must each have " +
"exactly 1 PerpetualUpdate, got settledUpdates: %+v"
ErrMatchUpdatesMustBeSamePerpId = "internalCanUpdateSubaccounts: MATCH subaccount updates must consists two " +
ErrMatchUpdatesMustBeSamePerpId = "internalCanUpdateSubaccounts: MATCH subaccount updates must consists of two " +
"updates on same perpetual Id, got settledUpdates: %+v"
ErrMatchUpdatesInvalidSize = "internalCanUpdateSubaccounts: MATCH subaccount updates must consists of two " +
"updates of equal absolute base quantums and opposite sign: %+v"
)

// x/subaccounts module sentinel errors
Expand Down

0 comments on commit ccfca2d

Please sign in to comment.