-
Notifications
You must be signed in to change notification settings - Fork 291
/
params.go
62 lines (54 loc) · 1.93 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
package oracle
import (
"fmt"
"github.com/terra-project/core/types/util"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Params oracle parameters
type Params struct {
VotePeriod int64 `json:"vote_period"` // voting period in block height; tallys and reward claim period
VoteThreshold sdk.Dec `json:"vote_threshold"` // minimum stake power threshold to clear vote
DropThreshold sdk.Int `json:"drop_threshold"` // tolerated drops before blacklist
OracleRewardBand sdk.Dec `json:"oracle_reward_band"` // band around the oracle weighted median to reward
}
// NewParams creates a new param instance
func NewParams(votePeriod int64, voteThreshold, oracleRewardBand sdk.Dec, dropThreshold sdk.Int) Params {
return Params{
VotePeriod: votePeriod,
VoteThreshold: voteThreshold,
OracleRewardBand: oracleRewardBand,
DropThreshold: dropThreshold,
}
}
// DefaultParams creates default oracle module parameters
func DefaultParams() Params {
return NewParams(
util.BlocksPerMinute*15, // 15 minutes
sdk.NewDecWithPrec(67, 2), // 67%
sdk.NewDecWithPrec(1, 2), // 1%
sdk.NewInt(10),
)
}
func validateParams(params Params) error {
if params.VotePeriod <= 0 {
return fmt.Errorf("oracle parameter VotePeriod must be > 0, is %d", params.VotePeriod)
}
if params.VoteThreshold.LT(sdk.NewDecWithPrec(33, 2)) {
return fmt.Errorf("oracle parameter VoteThreshold must be greater than 33 percent")
}
if params.OracleRewardBand.IsNegative() {
return fmt.Errorf("oracle parameter OracleRewardBand must be positive")
}
if params.DropThreshold.LTE(sdk.NewInt(3)) {
return fmt.Errorf("oracle parameter DropThreshold must be greater than 3")
}
return nil
}
func (params Params) String() string {
return fmt.Sprintf(`Oracle Params:
VotePeriod: %d
VoteThreshold: %s
OracleRewardBand: %s
DropThresdhold: %s
`, params.VotePeriod, params.VoteThreshold, params.OracleRewardBand, params.DropThreshold)
}