-
Notifications
You must be signed in to change notification settings - Fork 581
/
minter.go
70 lines (58 loc) · 2.2 KB
/
minter.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
package types
import (
"errors"
sdk "github.com/cosmos/cosmos-sdk/types"
)
var (
errNilEpochProvisions = errors.New("epoch provisions was nil in genesis")
errNegativeEpochProvisions = errors.New("epoch provisions should be non-negative")
)
// NewMinter returns a new Minter object with the given epoch
// provisions values.
func NewMinter(epochProvisions sdk.Dec) Minter {
return Minter{
EpochProvisions: epochProvisions,
}
}
// InitialMinter returns an initial Minter object.
func InitialMinter() Minter {
return NewMinter(sdk.NewDec(0))
}
// DefaultInitialMinter returns a default initial Minter object for a new chain.
func DefaultInitialMinter() Minter {
return InitialMinter()
}
// Validate validates minter. Returns nil on success, error otherewise.
func (m Minter) Validate() error {
if m.EpochProvisions.IsNil() {
return errNilEpochProvisions
}
if m.EpochProvisions.IsNegative() {
return errNegativeEpochProvisions
}
return nil
}
// NextEpochProvisions returns the epoch provisions.
func (m Minter) NextEpochProvisions(params Params) sdk.Dec {
return m.EpochProvisions.Mul(params.ReductionFactor)
}
// EpochProvision returns the provisions for a block based on the epoch
// provisions rate.
func (m Minter) EpochProvision(params Params) sdk.Coin {
provisionAmt := m.EpochProvisions
return sdk.NewCoin(params.MintDenom, provisionAmt.TruncateInt())
}
// GetInflationProvisions returns the inflation provisions.
// These are calculated as the current epoch provisons * (1 - developer rewards proportion)
// The returned denom is taken from input parameters.
func (m Minter) GetInflationProvisions(params Params) sdk.DecCoin {
provisionAmt := m.EpochProvisions.Mul(params.GetInflationProportion())
return sdk.NewDecCoinFromDec(params.MintDenom, provisionAmt)
}
// GetDeveloperVestingEpochProvisions returns the developer vesting provisions.
// These are calculated as the current epoch provisons * developer rewards proportion
// The returned denom is taken from input parameters.
func (m Minter) GetDeveloperVestingEpochProvisions(params Params) sdk.DecCoin {
provisionAmt := m.EpochProvisions.Mul(params.GetDeveloperVestingProportion())
return sdk.NewDecCoinFromDec(params.MintDenom, provisionAmt)
}