-
Notifications
You must be signed in to change notification settings - Fork 0
/
liquidity_tier.go
62 lines (52 loc) · 1.78 KB
/
liquidity_tier.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package liquidity_tier
import (
perptypes "github.com/jinxprotocol/v4-chain/protocol/x/perpetuals/types"
)
type LtModifierOption func(cp *perptypes.LiquidityTier)
func WithId(id uint32) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.Id = id
}
}
func WithName(name string) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.Name = name
}
}
func WithInitialMarginPpm(initialMarginPpm uint32) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.InitialMarginPpm = initialMarginPpm
}
}
func WithMaintenanceFractionPpm(maintenanceFractionPpm uint32) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.MaintenanceFractionPpm = maintenanceFractionPpm
}
}
func WithImpactNotional(impactNotional uint64) LtModifierOption {
return func(lt *perptypes.LiquidityTier) {
lt.ImpactNotional = impactNotional
}
}
// GenerateLiquidityTier returns a `LiquidityTier` object set to default values.
// Passing in `LtModifierOption` methods alters the value of the `LiquidityTier` returned.
// It will start with the default, valid `LiquidityTier` value defined within the method
// and make the requested modifications before returning the object.
//
// Example usage:
// `GenerateLiquidityTier(WithId(7))`
// This will start with the default `LiquidityTier` object defined within the method and
// return the newly-created object after overriding the values of `Id` to 7.
func GenerateLiquidityTier(optionalModifications ...LtModifierOption) *perptypes.LiquidityTier {
lt := &perptypes.LiquidityTier{
Id: 0,
Name: "Large-Cap",
InitialMarginPpm: 1_000_000,
MaintenanceFractionPpm: 1_000_000,
ImpactNotional: 500_000_000,
}
for _, opt := range optionalModifications {
opt(lt)
}
return lt
}