-
Notifications
You must be signed in to change notification settings - Fork 127
/
minter.go
53 lines (44 loc) · 1.56 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
package types
import (
"fmt"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
blocksPerYear = 60 * 60 * 8766 / 5 // 5 second a block, 8766 = 365.25 * 24
)
var initialIssue = sdk.NewIntWithDecimal(20, 8)
// Create a new minter object
func NewMinter(lastUpdate time.Time, inflationBase sdk.Int) Minter {
return Minter{
LastUpdate: lastUpdate,
InflationBase: inflationBase,
}
}
// DefaultMinter returns minter object for a new chain
func DefaultMinter() Minter {
return NewMinter(
time.Unix(0, 0).UTC(),
initialIssue.Mul(sdk.NewIntWithDecimal(1, 6)), // 20*(10^8)iris, 20*(10^8)*(10^6)uiris
)
}
// ValidateMinter returns err if the Minter is invalid
func ValidateMinter(m Minter) error {
if m.LastUpdate.Before(time.Unix(0, 0)) {
return fmt.Errorf("minter last update time(%s) should not be a time before January 1, 1970 UTC", m.LastUpdate.String())
}
if !m.InflationBase.GT(sdk.ZeroInt()) {
return fmt.Errorf("minter inflation basement (%s) should be positive", m.InflationBase.String())
}
return nil
}
// NextAnnualProvisions gets the provisions for a block based on the annual provisions rate
func (m Minter) NextAnnualProvisions(params Params) (provisions sdk.Dec) {
return params.Inflation.MulInt(m.InflationBase)
}
// BlockProvision gets the provisions for a block based on the annual provisions rate
func (m Minter) BlockProvision(params Params) sdk.Coin {
provisions := m.NextAnnualProvisions(params)
blockInflationAmount := provisions.QuoInt(sdk.NewInt(blocksPerYear))
return sdk.NewCoin(params.MintDenom, blockInflationAmount.TruncateInt())
}