Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare-genesis cmd: Add flags related to inflation #306

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cmd/babylond/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const (
flagBaseBtcHeaderHex = "btc-base-header"
flagBaseBtcHeaderHeight = "btc-base-header-height"
flagGenesisTime = "genesis-time"
flagInflationRateChange = "inflation-rate-change"
flagInflationMax = "inflation-max"
flagInflationMin = "inflation-min"
)

type GenesisCLIArgs struct {
Expand All @@ -25,6 +28,9 @@ type GenesisCLIArgs struct {
EpochInterval uint64
BaseBtcHeaderHex string
BaseBtcHeaderHeight uint64
InflationRateChange float64
InflationMax float64
InflationMin float64
GenesisTime time.Time
}

Expand All @@ -42,6 +48,9 @@ func addGenesisFlags(cmd *cobra.Command) {
cmd.Flags().String(flagBaseBtcHeaderHex, "0100000000000000000000000000000000000000000000000000000000000000000000003ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a45068653ffff7f2002000000", "Hex of the base Bitcoin header.")
cmd.Flags().Uint64(flagBaseBtcHeaderHeight, 0, "Height of the base Bitcoin header.")
cmd.Flags().Int64(flagGenesisTime, time.Now().Unix(), "Genesis time")
cmd.Flags().Float64(flagInflationRateChange, 0.13, "Inflation rate change")
cmd.Flags().Float64(flagInflationMax, 0.2, "Maximum inflation")
cmd.Flags().Float64(flagInflationMin, 0.07, "Minimum inflation")
}

func parseGenesisFlags(cmd *cobra.Command) *GenesisCLIArgs {
Expand All @@ -53,6 +62,9 @@ func parseGenesisFlags(cmd *cobra.Command) *GenesisCLIArgs {
baseBtcHeaderHex, _ := cmd.Flags().GetString(flagBaseBtcHeaderHex)
baseBtcHeaderHeight, _ := cmd.Flags().GetUint64(flagBaseBtcHeaderHeight)
genesisTimeUnix, _ := cmd.Flags().GetInt64(flagGenesisTime)
inflationRateChange, _ := cmd.Flags().GetFloat64(flagInflationRateChange)
inflationMax, _ := cmd.Flags().GetFloat64(flagInflationMax)
inflationMin, _ := cmd.Flags().GetFloat64(flagInflationMin)

if chainID == "" {
chainID = "chain-" + tmrand.NewRand().Str(6)
Expand All @@ -69,5 +81,8 @@ func parseGenesisFlags(cmd *cobra.Command) *GenesisCLIArgs {
BaseBtcHeaderHeight: baseBtcHeaderHeight,
BaseBtcHeaderHex: baseBtcHeaderHex,
GenesisTime: genesisTime,
InflationRateChange: inflationRateChange,
InflationMax: inflationMax,
InflationMin: inflationMin,
}
}
10 changes: 8 additions & 2 deletions cmd/babylond/cmd/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Example:
genesisParams = TestnetGenesisParams(genesisCliArgs.MaxActiveValidators,
genesisCliArgs.BtcConfirmationDepth, genesisCliArgs.BtcFinalizationTimeout,
genesisCliArgs.EpochInterval, genesisCliArgs.BaseBtcHeaderHex,
genesisCliArgs.BaseBtcHeaderHeight, genesisCliArgs.GenesisTime)
genesisCliArgs.BaseBtcHeaderHeight, genesisCliArgs.InflationRateChange,
genesisCliArgs.InflationMin, genesisCliArgs.InflationMax, genesisCliArgs.GenesisTime)
} else if network == "mainnet" {
// TODO: mainnet genesis params
panic("Mainnet params not implemented.")
Expand Down Expand Up @@ -191,7 +192,8 @@ type GenesisParams struct {

func TestnetGenesisParams(maxActiveValidators uint32, btcConfirmationDepth uint64,
btcFinalizationTimeout uint64, epochInterval uint64, baseBtcHeaderHex string,
baseBtcHeaderHeight uint64, genesisTime time.Time) GenesisParams {
baseBtcHeaderHeight uint64, inflationRateChange float64,
inflationMin float64, inflationMax float64, genesisTime time.Time) GenesisParams {

genParams := GenesisParams{}

Expand Down Expand Up @@ -226,6 +228,10 @@ func TestnetGenesisParams(maxActiveValidators uint32, btcConfirmationDepth uint6

genParams.MintParams = minttypes.DefaultParams()
genParams.MintParams.MintDenom = genParams.NativeCoinMetadatas[0].Base
// This should always work as inflation rate is already a float64
genParams.MintParams.InflationRateChange = sdk.MustNewDecFromStr(fmt.Sprintf("%f", inflationRateChange))
genParams.MintParams.InflationMin = sdk.MustNewDecFromStr(fmt.Sprintf("%f", inflationMin))
genParams.MintParams.InflationMax = sdk.MustNewDecFromStr(fmt.Sprintf("%f", inflationMax))

genParams.GovParams = govv1.DefaultParams()
genParams.GovParams.DepositParams.MinDeposit = sdk.NewCoins(sdk.NewCoin(
Expand Down
3 changes: 2 additions & 1 deletion cmd/babylond/cmd/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ Example:
genesisParams := TestnetGenesisParams(genesisCliArgs.MaxActiveValidators,
genesisCliArgs.BtcConfirmationDepth, genesisCliArgs.BtcFinalizationTimeout,
genesisCliArgs.EpochInterval, genesisCliArgs.BaseBtcHeaderHex,
genesisCliArgs.BaseBtcHeaderHeight, genesisCliArgs.GenesisTime)
genesisCliArgs.BaseBtcHeaderHeight, genesisCliArgs.InflationRateChange,
genesisCliArgs.InflationMin, genesisCliArgs.InflationMax, genesisCliArgs.GenesisTime)

return InitTestnet(
clientCtx, cmd, config, mbm, genBalIterator, outputDir, genesisCliArgs.ChainID, minGasPrices,
Expand Down