/
params.go
119 lines (103 loc) · 3.43 KB
/
params.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package keeper
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/lcnem/eurx/x/cdp/types"
)
func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
k.paramSpace.GetParamSet(ctx, ¶ms)
return params
}
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, ¶ms)
}
// GetCollateral returns the collateral param with corresponding denom
func (k Keeper) GetCollateral(ctx sdk.Context, collateralType string) (types.CollateralParam, bool) {
params := k.GetParams(ctx)
for _, cp := range params.CollateralParams {
if cp.Type == collateralType {
return cp, true
}
}
return types.CollateralParam{}, false
}
// GetCollateralTypes returns an array of collateral types
func (k Keeper) GetCollateralTypes(ctx sdk.Context) []string {
params := k.GetParams(ctx)
var denoms []string
for _, cp := range params.CollateralParams {
denoms = append(denoms, cp.Type)
}
return denoms
}
// GetDebtParam returns the debt param with matching denom
func (k Keeper) GetDebtParam(ctx sdk.Context, denom string) (types.DebtParam, bool) {
dp := k.GetParams(ctx).DebtParam
if dp.Denom == denom {
return dp, true
}
return types.DebtParam{}, false
}
// GetCollateralTypePrefix returns the prefix of the matching denom
func (k Keeper) GetCollateralTypePrefix(ctx sdk.Context, collateralType string) (byte, bool) {
params := k.GetParams(ctx)
for _, cp := range params.CollateralParams {
if cp.Type == collateralType {
return byte(cp.Prefix), true
}
}
return 0x00, false
}
// private methods assume collateral has been validated, panic if the input is invalid
func (k Keeper) getDenomFromByte(ctx sdk.Context, db byte) string {
params := k.GetParams(ctx)
for _, cp := range params.CollateralParams {
if byte(cp.Prefix) == db {
return cp.Denom
}
}
panic(fmt.Sprintf("no collateral denom with prefix %b", db))
}
func (k Keeper) getSpotMarketID(ctx sdk.Context, collateralType string) string {
cp, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("collateral not found: %s", collateralType))
}
return cp.SpotMarketId
}
func (k Keeper) getliquidationMarketID(ctx sdk.Context, collateralType string) string {
cp, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("collateral not found: %s", collateralType))
}
return cp.LiquidationMarketId
}
func (k Keeper) getLiquidationRatio(ctx sdk.Context, collateralType string) sdk.Dec {
cp, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("collateral not found: %s", collateralType))
}
return cp.LiquidationRatio
}
func (k Keeper) getLiquidationPenalty(ctx sdk.Context, collateralType string) sdk.Dec {
cp, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("collateral not found: %s", collateralType))
}
return cp.LiquidationPenalty
}
func (k Keeper) getAuctionSize(ctx sdk.Context, collateralType string) sdk.Int {
cp, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("collateral not found: %s", collateralType))
}
return cp.AuctionSize
}
// GetFeeRate returns the per second fee rate for the input denom
func (k Keeper) getFeeRate(ctx sdk.Context, collateralType string) (fee sdk.Dec) {
collalateralParam, found := k.GetCollateral(ctx, collateralType)
if !found {
panic(fmt.Sprintf("could not get fee rate for %s, collateral not found", collateralType))
}
return collalateralParam.StabilityFee
}