-
Notifications
You must be signed in to change notification settings - Fork 117
/
types.go
executable file
·102 lines (80 loc) · 3.22 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
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
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
func (p Pool) Validate() bool {
return p.ExternalAsset.Validate()
}
// NewPool returns a new Pool
func NewPool(externalAsset *Asset, nativeAssetBalance, externalAssetBalance, poolUnits sdk.Uint) Pool {
pool := Pool{ExternalAsset: externalAsset,
NativeAssetBalance: nativeAssetBalance,
ExternalAssetBalance: externalAssetBalance,
PoolUnits: poolUnits}
return pool
}
func (p *Pool) ExtractValues(to Asset) (sdk.Uint, sdk.Uint, bool) {
var X, Y sdk.Uint
var toRowan bool
if to.IsSettlementAsset() {
Y = p.NativeAssetBalance
X = p.ExternalAssetBalance
toRowan = true
} else {
X = p.NativeAssetBalance
Y = p.ExternalAssetBalance
toRowan = false
}
return X, Y, toRowan
}
func (p *Pool) UpdateBalances(toRowan bool, X, x, Y, swapResult sdk.Uint) {
if toRowan {
p.ExternalAssetBalance = X.Add(x)
p.NativeAssetBalance = Y.Sub(swapResult)
} else {
p.NativeAssetBalance = X.Add(x)
p.ExternalAssetBalance = Y.Sub(swapResult)
}
}
type Pools []Pool
type LiquidityProviders []LiquidityProvider
func (l LiquidityProvider) Validate() bool {
if !l.Asset.Validate() {
return false
}
return true
}
// NewLiquidityProvider returns a new LiquidityProvider
func NewLiquidityProvider(asset *Asset, liquidityProviderUnits sdk.Uint, liquidityProviderAddress sdk.AccAddress) LiquidityProvider {
return LiquidityProvider{Asset: asset, LiquidityProviderUnits: liquidityProviderUnits, LiquidityProviderAddress: liquidityProviderAddress.String()}
}
// ----------------------------------------------------------------------------
// Client Types
func NewLiquidityProviderResponse(liquidityProvider LiquidityProvider, height int64, nativeBalance string, externalBalance string) LiquidityProviderRes {
return LiquidityProviderRes{LiquidityProvider: &liquidityProvider, Height: height, NativeAssetBalance: nativeBalance, ExternalAssetBalance: externalBalance}
}
func NewLiquidityProviderDataResponse(liquidityProviderData []*LiquidityProviderData, height int64) LiquidityProviderDataRes {
return LiquidityProviderDataRes{LiquidityProviderData: liquidityProviderData, Height: height}
}
func NewLiquidityProviderData(liquidityProvider LiquidityProvider, nativeBalance string, externalBalance string) LiquidityProviderData {
return LiquidityProviderData{LiquidityProvider: &liquidityProvider, NativeAssetBalance: nativeBalance, ExternalAssetBalance: externalBalance}
}
func NewPmtpParamsResponse(params *PmtpParams, pmtpRateParams PmtpRateParams, pmtpEpoch PmtpEpoch, height int64) PmtpParamsRes {
return PmtpParamsRes{Params: params, PmtpRateParams: &pmtpRateParams, PmtpEpoch: &pmtpEpoch, Height: height}
}
func NewLiquidityProtectionParamsResponse(params *LiquidityProtectionParams, rateParams LiquidityProtectionRateParams, height int64) LiquidityProtectionParamsRes {
return LiquidityProtectionParamsRes{Params: params, RateParams: &rateParams, Height: height}
}
func (p *Pool) ExtractDebt(X, Y sdk.Uint, toRowan bool) (sdk.Uint, sdk.Uint) {
if toRowan {
Y = Y.Add(p.NativeLiabilities)
X = X.Add(p.ExternalLiabilities)
} else {
X = X.Add(p.NativeLiabilities)
Y = Y.Add(p.ExternalLiabilities)
}
return X, Y
}
func StringCompare(a, b string) bool {
return a == b
}