-
Notifications
You must be signed in to change notification settings - Fork 590
/
pool_params.go
77 lines (63 loc) · 2.06 KB
/
pool_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
package balancer
import (
"errors"
"github.com/osmosis-labs/osmosis/osmomath"
"github.com/osmosis-labs/osmosis/v24/x/gamm/types"
)
func NewPoolParams(spreadFactor, exitFee osmomath.Dec, params *SmoothWeightChangeParams) PoolParams {
return PoolParams{
SwapFee: spreadFactor,
ExitFee: exitFee,
SmoothWeightChangeParams: params,
}
}
func (params PoolParams) Validate(poolWeights []PoolAsset) error {
if params.ExitFee.IsNegative() {
return types.ErrNegativeExitFee
}
if params.ExitFee.GTE(osmomath.OneDec()) {
return types.ErrTooMuchExitFee
}
if params.SwapFee.IsNegative() {
return types.ErrNegativeSpreadFactor
}
if params.SwapFee.GTE(osmomath.OneDec()) {
return types.ErrTooMuchSpreadFactor
}
if params.SmoothWeightChangeParams != nil {
targetWeights := params.SmoothWeightChangeParams.TargetPoolWeights
// Ensure it has the right number of weights
if len(targetWeights) != len(poolWeights) {
return types.ErrPoolParamsInvalidNumDenoms
}
// Validate all user specified weights
for _, v := range targetWeights {
err := ValidateUserSpecifiedWeight(v.Weight)
if err != nil {
return err
}
}
// Ensure that all the target weight denoms are same as pool asset weights
sortedTargetPoolWeights := sortPoolAssetsOutOfPlaceByDenom(targetWeights)
sortedPoolWeights := sortPoolAssetsOutOfPlaceByDenom(poolWeights)
for i, v := range sortedPoolWeights {
if sortedTargetPoolWeights[i].Token.Denom != v.Token.Denom {
return types.ErrPoolParamsInvalidDenom
}
}
// No start time validation needed
// We do not need to validate InitialPoolWeights, as we set that ourselves
// in setInitialPoolParams
// TODO: Is there anything else we can validate for duration?
if params.SmoothWeightChangeParams.Duration <= 0 {
return errors.New("params.SmoothWeightChangeParams must have a positive duration")
}
}
return nil
}
func (params PoolParams) GetPoolSpreadFactor() osmomath.Dec {
return params.SwapFee
}
func (params PoolParams) GetPoolExitFee() osmomath.Dec {
return params.ExitFee
}