-
Notifications
You must be signed in to change notification settings - Fork 119
/
types.go
72 lines (61 loc) · 1.67 KB
/
types.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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
const (
ModuleName = "margin"
// StoreKey is the string store representation
StoreKey = ModuleName
// QuerierRoute is the querier route
QuerierRoute = ModuleName
// RouterKey is the msg router key
RouterKey = ModuleName
)
func NewMTP(signer string, collateralAsset string, borrowAsset string, position Position, leverage sdk.Dec) *MTP {
return &MTP{
Address: signer,
CollateralAsset: collateralAsset,
CollateralAmount: sdk.ZeroUint(),
Liabilities: sdk.ZeroUint(),
InterestPaidCollateral: sdk.ZeroUint(),
InterestPaidCustody: sdk.ZeroUint(),
InterestUnpaidCollateral: sdk.ZeroUint(),
CustodyAsset: borrowAsset,
CustodyAmount: sdk.ZeroUint(),
Leverage: leverage,
MtpHealth: sdk.ZeroDec(),
Position: position,
}
}
func (mtp MTP) Validate() error {
if mtp.CollateralAsset == "" {
return sdkerrors.Wrap(ErrMTPInvalid, "no asset specified")
}
if mtp.Address == "" {
return sdkerrors.Wrap(ErrMTPInvalid, "no address specified")
}
if mtp.Position == Position_UNSPECIFIED {
return sdkerrors.Wrap(ErrMTPInvalid, "no position specified")
}
if mtp.Id == 0 {
return sdkerrors.Wrap(ErrMTPInvalid, "no id specified")
}
return nil
}
func GetSettlementAsset() string {
return "rowan"
}
func GetPositionFromString(s string) Position {
switch s {
case "long":
return Position_LONG
case "short":
return Position_SHORT
default:
return Position_UNSPECIFIED
}
}
func StringCompare(a, b string) bool {
return a == b
}