Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ttl33 committed Sep 25, 2024
1 parent 732d173 commit 51b0cf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
18 changes: 9 additions & 9 deletions protocol/x/subaccounts/keeper/subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,33 +770,33 @@ func (k Keeper) GetAllRelevantPerpetuals(
perptypes.PerpInfos,
error,
) {
subaccountIdsMap := make(map[types.SubaccountId]struct{})
perpIdsMap := make(map[uint32]struct{})
subaccountIdsSet := make(map[types.SubaccountId]struct{})
perpIdsSet := make(map[uint32]struct{})

// Add all relevant perpetuals in every update.
for _, update := range updates {
// If this subaccount has not been processed already, get all of its existing perpetuals.
if _, exists := subaccountIdsMap[update.SubaccountId]; !exists {
if _, exists := subaccountIdsSet[update.SubaccountId]; !exists {
sa := k.GetSubaccount(ctx, update.SubaccountId)
for _, postition := range sa.PerpetualPositions {
perpIdsMap[postition.PerpetualId] = struct{}{}
perpIdsSet[postition.PerpetualId] = struct{}{}
}
subaccountIdsMap[update.SubaccountId] = struct{}{}
subaccountIdsSet[update.SubaccountId] = struct{}{}
}

// Add all perpetuals in the update.
for _, perpUpdate := range update.PerpetualUpdates {
perpIdsMap[perpUpdate.GetId()] = struct{}{}
perpIdsSet[perpUpdate.GetId()] = struct{}{}
}
}

// Important: Sort the perpIds to ensure determinism!
perpIdsOrdered := lib.GetSortedKeys[lib.Sortable[uint32]](perpIdsMap)
sortedPerpIds := lib.GetSortedKeys[lib.Sortable[uint32]](perpIdsSet)

// Get all perpetual information from state.
ltCache := make(map[uint32]perptypes.LiquidityTier)
perpInfos := make(perptypes.PerpInfos, len(perpIdsOrdered))
for _, perpId := range perpIdsOrdered {
perpInfos := make(perptypes.PerpInfos, len(sortedPerpIds))
for _, perpId := range sortedPerpIds {
perpetual, price, err := k.perpetualsKeeper.GetPerpetualAndMarketPrice(ctx, perpId)
if err != nil {
return nil, err
Expand Down
6 changes: 0 additions & 6 deletions protocol/x/subaccounts/keeper/subaccount_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6033,12 +6033,6 @@ func TestGetAllRelevantPerpetuals_Deterministic(t *testing.T) {
// updates
assetUpdates []types.AssetUpdate
perpetualUpdates []types.PerpetualUpdate

// expectations
expectedNetCollateral *big.Int
expectedInitialMargin *big.Int
expectedMaintenanceMargin *big.Int
expectedErr error
}{
"Gas used is deterministic when erroring on gas usage": {
assetPositions: testutil.CreateUsdcAssetPositions(big.NewInt(10_000_000_001)), // $10,000.000001
Expand Down

0 comments on commit 51b0cf5

Please sign in to comment.