-
Notifications
You must be signed in to change notification settings - Fork 79
/
liquidatable_subaccount_ids.go
39 lines (33 loc) · 1.28 KB
/
liquidatable_subaccount_ids.go
1
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
28
29
30
31
32
33
34
35
36
37
38
39
package types
import (
"sync"
satypes "github.com/dydxprotocol/v4-chain/protocol/x/subaccounts/types"
)
// LiquidatableSubaccountIds maintains the list of subaccount ids to be liquidated
// in the next block. Methods are goroutine safe.
type LiquidatableSubaccountIds struct {
sync.Mutex // lock
subaccountIds []satypes.SubaccountId // liquidatable subaccount ids
}
// NewLiquidatableSubaccountIds creates a new `LiquidatableSubaccountIds` struct.
func NewLiquidatableSubaccountIds() *LiquidatableSubaccountIds {
return &LiquidatableSubaccountIds{
subaccountIds: make([]satypes.SubaccountId, 0),
}
}
// UpdateSubaccountIds updates the struct with the given a list of potentially liquidatable subaccount ids.
func (ls *LiquidatableSubaccountIds) UpdateSubaccountIds(updates []satypes.SubaccountId) {
ls.Lock()
defer ls.Unlock()
ls.subaccountIds = make([]satypes.SubaccountId, len(updates))
copy(ls.subaccountIds, updates)
}
// GetSubaccountIds returns the list of potentially liquidatable subaccount ids
// reported by the liquidation daemon.
func (ls *LiquidatableSubaccountIds) GetSubaccountIds() []satypes.SubaccountId {
ls.Lock()
defer ls.Unlock()
results := make([]satypes.SubaccountId, len(ls.subaccountIds))
copy(results, ls.subaccountIds)
return results
}