-
Notifications
You must be signed in to change notification settings - Fork 39
/
genesis.go
88 lines (72 loc) · 2.71 KB
/
genesis.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
package treasury
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
core "github.com/classic-terra/core/v2/types"
"github.com/classic-terra/core/v2/x/treasury/keeper"
"github.com/classic-terra/core/v2/x/treasury/types"
)
// InitGenesis initializes default parameters
// and the keeper's address to pubkey map
func InitGenesis(ctx sdk.Context, keeper keeper.Keeper, data *types.GenesisState) {
keeper.SetParams(ctx, data.Params)
keeper.SetTaxRate(ctx, data.TaxRate)
keeper.SetRewardWeight(ctx, data.RewardWeight)
keeper.SetEpochTaxProceeds(ctx, data.TaxProceeds)
// If EpochInitialIssuance is empty, we use current supply as epoch initial issuance
if data.EpochInitialIssuance.IsZero() {
keeper.RecordEpochInitialIssuance(ctx)
} else {
keeper.SetEpochInitialIssuance(ctx, data.EpochInitialIssuance)
}
// store tax caps
for _, cap := range data.TaxCaps {
keeper.SetTaxCap(ctx, cap.Denom, cap.TaxCap)
}
for _, epochState := range data.EpochStates {
keeper.SetTR(ctx, int64(epochState.Epoch), epochState.TaxReward)
keeper.SetSR(ctx, int64(epochState.Epoch), epochState.SeigniorageReward)
keeper.SetTSL(ctx, int64(epochState.Epoch), epochState.TotalStakedLuna)
}
// check if the module account exists
moduleAcc := keeper.GetTreasuryModuleAccount(ctx)
if moduleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.ModuleName))
}
// check if the burn module account exists
burnModuleAcc := keeper.GetBurnModuleAccount(ctx)
if burnModuleAcc == nil {
panic(fmt.Sprintf("%s module account has not been set", types.BurnModuleName))
}
}
// ExportGenesis writes the current store values
// to a genesis file, which can be imported again
// with InitGenesis
func ExportGenesis(ctx sdk.Context, keeper keeper.Keeper) (data *types.GenesisState) {
params := keeper.GetParams(ctx)
taxRate := keeper.GetTaxRate(ctx)
rewardWeight := keeper.GetRewardWeight(ctx)
taxProceeds := keeper.PeekEpochTaxProceeds(ctx)
epochInitialIssuance := keeper.GetEpochInitialIssuance(ctx)
var taxCaps []types.TaxCap
keeper.IterateTaxCap(ctx, func(denom string, taxCap sdk.Int) bool {
taxCaps = append(taxCaps, types.TaxCap{
Denom: denom,
TaxCap: taxCap,
})
return false
})
var epochStates []types.EpochState
curEpoch := keeper.GetEpoch(ctx)
for e := int64(0); e < curEpoch ||
(e == curEpoch && core.IsPeriodLastBlock(ctx, core.BlocksPerWeek)); e++ {
epochStates = append(epochStates, types.EpochState{
Epoch: uint64(e),
TaxReward: keeper.GetTR(ctx, e),
SeigniorageReward: keeper.GetSR(ctx, e),
TotalStakedLuna: keeper.GetTSL(ctx, e),
})
}
return types.NewGenesisState(params, taxRate, rewardWeight,
taxCaps, taxProceeds, epochInitialIssuance, epochStates)
}