This repository has been archived by the owner on Nov 16, 2022. It is now read-only.
/
genesis.go
195 lines (187 loc) · 6.52 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package app
import (
"encoding/json"
"io/ioutil"
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/crisis"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genaccounts"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/supply"
"github.com/bandprotocol/d3n/chain/x/zoracle"
)
// GenesisState defines a type alias for the Gaia genesis application state.
type GenesisState map[string]json.RawMessage
// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState() GenesisState {
return GenesisState{
genaccounts.ModuleName: genaccounts.ModuleCdc.MustMarshalJSON(
genaccounts.GenesisState{},
),
auth.ModuleName: auth.ModuleCdc.MustMarshalJSON(
auth.GenesisState{
Params: auth.Params{
MaxMemoCharacters: 512,
TxSigLimit: 7,
TxSizeCostPerByte: 10,
SigVerifyCostED25519: 590,
SigVerifyCostSecp256k1: 1000,
},
},
),
bank.ModuleName: bank.ModuleCdc.MustMarshalJSON(bank.GenesisState{
SendEnabled: true,
}),
staking.ModuleName: staking.ModuleCdc.MustMarshalJSON(staking.GenesisState{
Params: staking.Params{
UnbondingTime: time.Hour * 24 * 7 * 3, // 3 weeks
BondDenom: "uband",
MaxEntries: 7,
MaxValidators: 100,
},
}),
mint.ModuleName: mint.ModuleCdc.MustMarshalJSON(mint.GenesisState{
Minter: mint.Minter{
AnnualProvisions: sdk.NewDecWithPrec(0, 0),
Inflation: sdk.NewDecWithPrec(135, 3), // 13.5%
},
Params: mint.Params{
BlocksPerYear: 10519200, // 3 second block times
GoalBonded: sdk.NewDecWithPrec(67, 2), // 67%
InflationMax: sdk.NewDecWithPrec(20, 2), // 20%
InflationMin: sdk.NewDecWithPrec(7, 2), // 7%
InflationRateChange: sdk.NewDecWithPrec(13, 2), // 13%
MintDenom: "uband",
},
}),
distr.ModuleName: distr.ModuleCdc.MustMarshalJSON(distr.GenesisState{
FeePool: distr.InitialFeePool(),
CommunityTax: sdk.NewDecWithPrec(2, 2), // 2%
BaseProposerReward: sdk.NewDecWithPrec(1, 2), // 1%
BonusProposerReward: sdk.NewDecWithPrec(4, 2), // 4%
WithdrawAddrEnabled: true,
DelegatorWithdrawInfos: []distr.DelegatorWithdrawInfo{},
PreviousProposer: nil,
OutstandingRewards: []distr.ValidatorOutstandingRewardsRecord{},
ValidatorAccumulatedCommissions: []distr.ValidatorAccumulatedCommissionRecord{},
ValidatorHistoricalRewards: []distr.ValidatorHistoricalRewardsRecord{},
ValidatorCurrentRewards: []distr.ValidatorCurrentRewardsRecord{},
DelegatorStartingInfos: []distr.DelegatorStartingInfoRecord{},
ValidatorSlashEvents: []distr.ValidatorSlashEventRecord{},
}),
gov.ModuleName: gov.ModuleCdc.MustMarshalJSON(gov.GenesisState{
StartingProposalID: 1,
DepositParams: gov.DepositParams{
MinDeposit: sdk.NewCoins(sdk.NewCoin("uband", sdk.TokensFromConsensusPower(1000))),
MaxDepositPeriod: 86400 * 14 * time.Second, // 14 days
},
VotingParams: gov.VotingParams{
VotingPeriod: 86400 * 14 * time.Second, // 14 days
},
TallyParams: gov.TallyParams{
Quorum: sdk.NewDecWithPrec(4, 1), // 40%
Threshold: sdk.NewDecWithPrec(5, 1), // 50%
Veto: sdk.NewDecWithPrec(334, 3), // 33.4%
},
}),
crisis.ModuleName: crisis.ModuleCdc.MustMarshalJSON(crisis.GenesisState{
ConstantFee: sdk.NewCoin("uband", sdk.TokensFromConsensusPower(10000)),
}),
slashing.ModuleName: slashing.ModuleCdc.MustMarshalJSON(slashing.GenesisState{
Params: slashing.Params{
MaxEvidenceAge: 60 * 30240 * time.Second, // 3 weeks
SignedBlocksWindow: int64(30000),
MinSignedPerWindow: sdk.NewDecWithPrec(5, 2), // 5%
DowntimeJailDuration: 60 * 10 * time.Second, // 10 minutes
SlashFractionDoubleSign: sdk.NewDecWithPrec(5, 2), // 5%
SlashFractionDowntime: sdk.NewDecWithPrec(1, 4), // 0.01%
},
SigningInfos: make(map[string]slashing.ValidatorSigningInfo),
MissedBlocks: make(map[string][]slashing.MissedBlock),
}),
supply.ModuleName: supply.ModuleCdc.MustMarshalJSON(supply.GenesisState{
Supply: sdk.NewCoins(),
}),
zoracle.ModuleName: zoracle.ModuleCdc.MustMarshalJSON(zoracle.DefaultGenesisState()),
genutil.ModuleName: genutil.ModuleCdc.MustMarshalJSON(genutil.GenesisState{
GenTxs: []json.RawMessage{},
}),
}
}
func GetDefaultDataSourcesAndOracleScripts(owner sdk.AccAddress) json.RawMessage {
state := zoracle.DefaultGenesisState()
dataSources := []struct {
name string
description string
path string
}{
{
"Coingecko script",
"The Script that queries crypto price from https://coingecko.com",
"./datasources/coingecko_price.sh",
},
{
"Crypto compare script",
"The Script that queries crypto price from https://cryptocompare.com",
"./datasources/crypto_compare_price.sh",
},
{
"Binance price",
"The Script that queries crypto price from https://www.binance.com/en",
"./datasources/binance_price.sh",
},
{
"Open weather",
"The script that queries current weather",
"./datasources/open_weather_map.sh",
},
}
// TODO: Find a better way to specify path to data sources
state.DataSources = make([]zoracle.DataSource, len(dataSources))
for i, dataSource := range dataSources {
script, err := ioutil.ReadFile(dataSource.path)
if err != nil {
panic(err)
}
state.DataSources[i] = zoracle.NewDataSource(
owner,
dataSource.name,
dataSource.description,
sdk.Coins{},
script,
)
}
// TODO: Find a better way to specify path to oracle scripts
oracleScripts := []struct {
name string
description string
path string
}{
{
"Crypto price script",
"Oracle script for getting an average crypto price from many sources.",
"./owasm/res/crypto_price.wasm",
},
}
state.OracleScripts = make([]zoracle.OracleScript, len(oracleScripts))
for i, oracleScript := range oracleScripts {
code, err := ioutil.ReadFile(oracleScript.path)
if err != nil {
panic(err)
}
state.OracleScripts[i] = zoracle.NewOracleScript(
owner,
oracleScript.name,
oracleScript.description,
code,
)
}
return zoracle.ModuleCdc.MustMarshalJSON(state)
}