diff --git a/.envrc b/.envrc index 2f8e1d3f..cffc922b 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use flake --impure +use flake . --impure diff --git a/.github/workflows/proto.yml b/.github/workflows/proto.yml index e52c5d05..e32c23a2 100644 --- a/.github/workflows/proto.yml +++ b/.github/workflows/proto.yml @@ -2,6 +2,8 @@ name: Protobuf # Protobuf runs buf (https://buf.build/) lint and check-breakage # This workflow is only run when a .proto file has been changed on: + branches-ignore: + - 'coinomics_v2' # NOTE: breaking changes are not really breaking as they are introduced in a module which was never deployed on chain workflow_dispatch: pull_request: # paths: diff --git a/.github/workflows/snyk.yml b/.github/workflows/snyk.yml new file mode 100644 index 00000000..4e796d25 --- /dev/null +++ b/.github/workflows/snyk.yml @@ -0,0 +1,17 @@ +name: Snyk check + +on: push + +jobs: + security: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - uses: snyk/actions/setup@master + - uses: actions/setup-go@v1 + with: + go-version: '1.20' + - name: Snyk monitor + run: snyk code test + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index bd222168..ba5bfdd9 100644 --- a/.gitignore +++ b/.gitignore @@ -78,4 +78,5 @@ swagger-proto tmp-swagger-gen .devenv .secrets -.env \ No newline at end of file +.env +.dccache \ No newline at end of file diff --git a/Makefile b/Makefile index 480ae71a..adf259c8 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1) # VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//') -VERSION := "1.6.3" +VERSION := "1.6.4" TMVERSION := $(shell go list -m github.com/tendermint/tendermint | sed 's:.* ::') COMMIT := $(shell git log -1 --format='%H') LEDGER_ENABLED ?= true diff --git a/app/app.go b/app/app.go index bbf23a97..08d52a02 100644 --- a/app/app.go +++ b/app/app.go @@ -139,18 +139,11 @@ import ( vestingkeeper "github.com/haqq-network/haqq/x/vesting/keeper" vestingtypes "github.com/haqq-network/haqq/x/vesting/types" - v102 "github.com/haqq-network/haqq/app/upgrades/v1.0.2" - v120 "github.com/haqq-network/haqq/app/upgrades/v1.2.0" - v121 "github.com/haqq-network/haqq/app/upgrades/v1.2.1" - v130 "github.com/haqq-network/haqq/app/upgrades/v1.3.0" - v131 "github.com/haqq-network/haqq/app/upgrades/v1.3.1" - v140 "github.com/haqq-network/haqq/app/upgrades/v1.4.0" - v141 "github.com/haqq-network/haqq/app/upgrades/v1.4.1" - v142 "github.com/haqq-network/haqq/app/upgrades/v1.4.2" v160 "github.com/haqq-network/haqq/app/upgrades/v1.6.0" v161 "github.com/haqq-network/haqq/app/upgrades/v1.6.1" v162 "github.com/haqq-network/haqq/app/upgrades/v1.6.2" v163 "github.com/haqq-network/haqq/app/upgrades/v1.6.3" + v164 "github.com/haqq-network/haqq/app/upgrades/v1.6.4" // NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens "github.com/haqq-network/haqq/x/ibc/transfer" @@ -181,7 +174,7 @@ func init() { const ( // Name defines the application binary name Name = "haqqd" - UpgradeName = "v1.6.3" + UpgradeName = "v1.6.4" MainnetChainID = "haqq_11235" ) @@ -1106,82 +1099,6 @@ func initParamsKeeper( } func (app *Haqq) setupUpgradeHandlers() { - // v1.0.2 update handler - app.UpgradeKeeper.SetUpgradeHandler( - v102.UpgradeName, - v102.CreateUpgradeHandler( - app.mm, - app.configurator, - app.BankKeeper, - app.appCodec, - app.keys[distrtypes.StoreKey], - ), - ) - // v1.2.0 update handler (IBC Enable) - app.UpgradeKeeper.SetUpgradeHandler( - v120.UpgradeName, - v120.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - // v1.2.1 update handler (IBC Upgrade) - app.UpgradeKeeper.SetUpgradeHandler( - v121.UpgradeName, - v121.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - // v1.3.0 update handler (Coinomics) - app.UpgradeKeeper.SetUpgradeHandler( - v130.UpgradeName, - v130.CreateUpgradeHandler( - app.mm, - app.configurator, - app.DistrKeeper, - ), - ) - // v1.3.1 update handler (Coinomics) - app.UpgradeKeeper.SetUpgradeHandler( - v131.UpgradeName, - v131.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - - // v1.4.0 update handler (Reset Coinomics for TestEdge2) - app.UpgradeKeeper.SetUpgradeHandler( - v140.UpgradeName, - v140.CreateUpgradeHandler( - app.mm, - app.configurator, - app.StakingKeeper, - app.CoinomicsKeeper, - app.SlashingKeeper, - app.GovKeeper, - ), - ) - - // v1.4.1 Fix handle ERC20 fro IBC Channels - app.UpgradeKeeper.SetUpgradeHandler( - v141.UpgradeName, - v141.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - - // v1.4.2 Security upgrade - app.UpgradeKeeper.SetUpgradeHandler( - v142.UpgradeName, - v142.CreateUpgradeHandler( - app.mm, - app.configurator, - ), - ) - // v1.6.0 Security upgrade app.UpgradeKeeper.SetUpgradeHandler( v160.UpgradeName, @@ -1223,6 +1140,19 @@ func (app *Haqq) setupUpgradeHandlers() { v163.CreateUpgradeHandler(app.mm, app.configurator), ) + // v1.6.4 Coinomics v2 + app.UpgradeKeeper.SetUpgradeHandler( + v164.UpgradeName, + v164.CreateUpgradeHandler( + app.mm, + app.configurator, + app.GetKey(coinomicstypes.StoreKey), + app.GetKey(paramstypes.StoreKey), + app.DistrKeeper, + app.CoinomicsKeeper, + ), + ) + // When a planned update height is reached, the old binary will panic // writing on disk the height and name of the update that triggered it // This will read that value, and execute the preparations for the upgrade. @@ -1237,16 +1167,7 @@ func (app *Haqq) setupUpgradeHandlers() { var storeUpgrades *storetypes.StoreUpgrades - switch upgradeInfo.Name { - case v130.UpgradeName: - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{coinomicstypes.ModuleName}, - } - case v140.UpgradeName: - storeUpgrades = &storetypes.StoreUpgrades{ - Added: []string{vestingtypes.ModuleName}, - } - case v160.UpgradeName: + if upgradeInfo.Name == v160.UpgradeName { storeUpgrades = &storetypes.StoreUpgrades{ Added: []string{ icahosttypes.SubModuleName, diff --git a/app/upgrades/v1.0.2/upgrades.go b/app/upgrades/v1.0.2/upgrades.go deleted file mode 100644 index ef304e94..00000000 --- a/app/upgrades/v1.0.2/upgrades.go +++ /dev/null @@ -1,88 +0,0 @@ -package v102 - -import ( - "math" - "math/big" - - "github.com/cosmos/cosmos-sdk/codec" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/haqq-network/haqq/utils" - erc20types "github.com/haqq-network/haqq/x/erc20/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.0.2 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - bk bankkeeper.Keeper, - cdc codec.BinaryCodec, - distrStoreKey storetypes.StoreKey, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - // Refs: - // - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations - // - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade - - if utils.IsMainNetwork(ctx.ChainID()) || - utils.IsTestEdge1Network(ctx.ChainID()) || - utils.IsLocalNetwork(ctx.ChainID()) { - logger.Debug("run migration v1.0.2") - - FixTotalSupply(ctx, bk, cdc, distrStoreKey) - } - - // Leave modules are as-is to avoid running InitGenesis. - return mm.RunMigrations(ctx, configurator, vm) - } -} - -// ref: https://github.com/haqq-network/haqq/issues/4 -func FixTotalSupply(ctx sdk.Context, bk bankkeeper.Keeper, cdc codec.BinaryCodec, distrStoreKey storetypes.StoreKey) { - logger := ctx.Logger() - - // get total supply - totalSupply := bk.GetSupply(ctx, "aISLM").Amount.BigInt() - - // 20*10^9*10^18 - expectedSupply := new(big.Int) - // 20*(10^9) - part1 := new(big.Int).Mul(big.NewInt(20), big.NewInt(int64(math.Pow(10, 9)))) - // part1 * (10^18) - expectedSupply.Mul(part1, big.NewInt(int64(math.Pow(10, 18)))) - - // if total supply lower then expected by white papper - if totalSupply.Cmp(expectedSupply) == -1 { - diff := big.NewInt(0).Sub(expectedSupply, totalSupply) - mintAmount := sdk.NewCoins(sdk.NewCoin("aISLM", sdk.NewIntFromBigInt(diff))) - - // mint to bank module - if err := bk.MintCoins(ctx, erc20types.ModuleName, mintAmount); err != nil { - logger.Error("FAILED TO MINT COINS", "error", err.Error()) - } - - // send coins to distribution module - if err := bk.SendCoinsFromModuleToModule(ctx, erc20types.ModuleName, distrtypes.ModuleName, mintAmount); err != nil { - logger.Error("FAILED TO SEND COINS TO MODULE", "error", err.Error()) - } - - // update community pool amount - kvstore := ctx.MultiStore().GetKVStore(distrStoreKey) - feePoolBin := kvstore.Get(distrtypes.FeePoolKey) - - var feePool distrtypes.FeePool - cdc.MustUnmarshal(feePoolBin, &feePool) - - coins := sdk.NewDecCoinsFromCoins(mintAmount...) - feePool.CommunityPool = feePool.CommunityPool.Add(coins...) - - b := cdc.MustMarshal(&feePool) - kvstore.Set(distrtypes.FeePoolKey, b) - } -} diff --git a/app/upgrades/v1.2.0/constants.go b/app/upgrades/v1.2.0/constants.go deleted file mode 100644 index 3a1f8fb7..00000000 --- a/app/upgrades/v1.2.0/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v120 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.2.0" -) diff --git a/app/upgrades/v1.2.0/upgrades.go b/app/upgrades/v1.2.0/upgrades.go deleted file mode 100644 index 16012b46..00000000 --- a/app/upgrades/v1.2.0/upgrades.go +++ /dev/null @@ -1,28 +0,0 @@ -package v120 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - ibc "github.com/cosmos/ibc-go/v6/modules/core" - ibchost "github.com/cosmos/ibc-go/v6/modules/core/24-host" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.2.0 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Debug("run migration v1.2.0") - - // Skip module migrations if existing version is greater than new one (should not happen). - moduleVersion := ibc.AppModule{}.ConsensusVersion() - if ibcVersion, exists := vm[ibchost.ModuleName]; exists && ibcVersion > moduleVersion { - vm[ibchost.ModuleName] = moduleVersion - } - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/app/upgrades/v1.2.1/constants.go b/app/upgrades/v1.2.1/constants.go deleted file mode 100644 index 251ee189..00000000 --- a/app/upgrades/v1.2.1/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v121 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.2.1" -) diff --git a/app/upgrades/v1.2.1/upgrades.go b/app/upgrades/v1.2.1/upgrades.go deleted file mode 100644 index cd56b7c3..00000000 --- a/app/upgrades/v1.2.1/upgrades.go +++ /dev/null @@ -1,24 +0,0 @@ -package v121 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.2.1 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Debug("run migration v1.2.1") - - // (evmos v8.2.0) feesplit module is deprecated since it is renamed to "revenue" module - logger.Debug("deleting feesplit module from version map...") - delete(vm, "feesplit") - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/app/upgrades/v1.2.1/upgrades_test.go b/app/upgrades/v1.2.1/upgrades_test.go deleted file mode 100644 index 2e168268..00000000 --- a/app/upgrades/v1.2.1/upgrades_test.go +++ /dev/null @@ -1,72 +0,0 @@ -package v121_test - -import ( - "testing" - "time" - - "github.com/stretchr/testify/suite" - - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/tendermint/tendermint/crypto/tmhash" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - "github.com/tendermint/tendermint/version" - - "github.com/haqq-network/haqq/app" - "github.com/haqq-network/haqq/crypto/ethsecp256k1" - feemarkettypes "github.com/haqq-network/haqq/x/feemarket/types" -) - -type UpgradeTestSuite struct { - suite.Suite - - ctx sdk.Context - app *app.Haqq - consAddress sdk.ConsAddress -} - -func (suite *UpgradeTestSuite) SetupTest(chainID string) { - checkTx := false - - // consensus key - priv, err := ethsecp256k1.GenerateKey() - suite.Require().NoError(err) - suite.consAddress = sdk.ConsAddress(priv.PubKey().Address()) - - // NOTE: this is the new binary, not the old one. - app, _ := app.Setup(checkTx, feemarkettypes.DefaultGenesisState()) - - suite.app = app - suite.ctx = suite.app.BaseApp.NewContext(checkTx, tmproto.Header{ - Height: 1, - ChainID: chainID, - Time: time.Date(2022, 5, 9, 8, 0, 0, 0, time.UTC), - ProposerAddress: suite.consAddress.Bytes(), - - Version: tmversion.Consensus{ - Block: version.BlockProtocol, - }, - LastBlockId: tmproto.BlockID{ - Hash: tmhash.Sum([]byte("block_id")), - PartSetHeader: tmproto.PartSetHeader{ - Total: 11, - Hash: tmhash.Sum([]byte("partset_header")), - }, - }, - AppHash: tmhash.Sum([]byte("app")), - DataHash: tmhash.Sum([]byte("data")), - EvidenceHash: tmhash.Sum([]byte("evidence")), - ValidatorsHash: tmhash.Sum([]byte("validators")), - NextValidatorsHash: tmhash.Sum([]byte("next_validators")), - ConsensusHash: tmhash.Sum([]byte("consensus")), - LastResultsHash: tmhash.Sum([]byte("last_result")), - }) - - cp := suite.app.BaseApp.GetConsensusParams(suite.ctx) - suite.ctx = suite.ctx.WithConsensusParams(cp) -} - -func TestUpgradeTestSuite(t *testing.T) { - s := new(UpgradeTestSuite) - suite.Run(t, s) -} diff --git a/app/upgrades/v1.3.0/constants.go b/app/upgrades/v1.3.0/constants.go deleted file mode 100644 index d0b40988..00000000 --- a/app/upgrades/v1.3.0/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v130 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.3.0" -) diff --git a/app/upgrades/v1.3.0/upgrades.go b/app/upgrades/v1.3.0/upgrades.go deleted file mode 100644 index 6111f85b..00000000 --- a/app/upgrades/v1.3.0/upgrades.go +++ /dev/null @@ -1,44 +0,0 @@ -package v130 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.3.0 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - dk distrkeeper.Keeper, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Info("run migration v1.3.0") - - // Refs: - // - https://docs.cosmos.network/master/building-modules/upgrade.html#registering-migrations - // - https://docs.cosmos.network/master/migrations/chain-upgrade-guide-044.html#chain-upgrade - - if err := MigrateDistributionParams(ctx, dk); err != nil { - logger.Error("FAILED: Migrate distribution params error: ", err.Error()) - } - - return mm.RunMigrations(ctx, configurator, vm) - } -} - -func MigrateDistributionParams(ctx sdk.Context, dk distrkeeper.Keeper) error { - newDistrParams := distrtypes.Params{ - CommunityTax: sdk.NewDecWithPrec(10, 2), - BaseProposerReward: sdk.NewDecWithPrec(1, 2), - BonusProposerReward: sdk.NewDecWithPrec(4, 2), - WithdrawAddrEnabled: true, - } - - dk.SetParams(ctx, newDistrParams) - - return nil -} diff --git a/app/upgrades/v1.3.1/constants.go b/app/upgrades/v1.3.1/constants.go deleted file mode 100644 index 873b42a9..00000000 --- a/app/upgrades/v1.3.1/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v131 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.3.1" -) diff --git a/app/upgrades/v1.3.1/upgrades.go b/app/upgrades/v1.3.1/upgrades.go deleted file mode 100644 index 9874e285..00000000 --- a/app/upgrades/v1.3.1/upgrades.go +++ /dev/null @@ -1,20 +0,0 @@ -package v131 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.3.1 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Info("run migration v1.3.1") - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/app/upgrades/v1.4.0/constants.go b/app/upgrades/v1.4.0/constants.go deleted file mode 100644 index 8231af8c..00000000 --- a/app/upgrades/v1.4.0/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v140 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.4.0" -) diff --git a/app/upgrades/v1.4.0/upgrades.go b/app/upgrades/v1.4.0/upgrades.go deleted file mode 100644 index 52fe981b..00000000 --- a/app/upgrades/v1.4.0/upgrades.go +++ /dev/null @@ -1,90 +0,0 @@ -package v140 - -import ( - "cosmossdk.io/math" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - "github.com/haqq-network/haqq/utils" - - coinomicskeeper "github.com/haqq-network/haqq/x/coinomics/keeper" - coinomicstypes "github.com/haqq-network/haqq/x/coinomics/types" - - slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" - - govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.4.0 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, - sk stakingkeeper.Keeper, - ck coinomicskeeper.Keeper, - slashk slashingkeeper.Keeper, - gk govkeeper.Keeper, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Info("### Run migration v1.4.0 ###") - - UpdateStakingParams(ctx, sk) - UpdateSlashingParams(ctx, slashk) - UpdateGovParams(ctx, gk, sk) - - // Reset coinomics state for TestEdge2 - if utils.IsTestEdge2Network(ctx.ChainID()) { - if err := ResetCoinomicsState(ctx, sk, ck); err != nil { - logger.Error("FAILED: reset coinomics params error: ", err.Error()) - } - } - - return mm.RunMigrations(ctx, configurator, vm) - } -} - -func UpdateGovParams(ctx sdk.Context, gk govkeeper.Keeper, sk stakingkeeper.Keeper) { - depositParams := gk.GetDepositParams(ctx) - - if utils.IsMainNetwork(ctx.ChainID()) { - minDeposit := math.NewIntWithDecimal(6_000, 18) // 6 000 ISLM - depositParams.MinDeposit = sdk.NewCoins( - sdk.NewCoin(sk.BondDenom(ctx), minDeposit), - ) - } else { - minDeposit := math.NewIntWithDecimal(60_000, 18) // 60 000 ISLM - depositParams.MinDeposit = sdk.NewCoins( - sdk.NewCoin(sk.BondDenom(ctx), minDeposit), - ) - } - - gk.SetDepositParams(ctx, depositParams) -} - -func UpdateSlashingParams(ctx sdk.Context, slashingkeeper slashingkeeper.Keeper) { - params := slashingkeeper.GetParams(ctx) - params.SignedBlocksWindow = 35000 - params.SlashFractionDowntime = sdk.NewDecWithPrec(1, 4) // 0.01% (0.0001) - slashingkeeper.SetParams(ctx, params) -} - -func UpdateStakingParams(ctx sdk.Context, sk stakingkeeper.Keeper) { - params := sk.GetParams(ctx) - params.MaxValidators = 150 - params.MinCommissionRate = sdk.NewDecWithPrec(5, 2) // 5% (0.05) - sk.SetParams(ctx, params) -} - -func ResetCoinomicsState(ctx sdk.Context, sk stakingkeeper.Keeper, ck coinomicskeeper.Keeper) error { - newCoinomicsParams := coinomicstypes.DefaultParams() - newCoinomicsParams.MintDenom = sk.BondDenom(ctx) - maxSupply := ck.GetMaxSupply(ctx) - doubledMaxSupply := maxSupply.Amount.Mul(sdk.NewInt(2)) - - ck.SetParams(ctx, newCoinomicsParams) - ck.SetEra(ctx, 0) - ck.SetMaxSupply(ctx, sdk.NewCoin(newCoinomicsParams.MintDenom, doubledMaxSupply)) - - return nil -} diff --git a/app/upgrades/v1.4.1/constants.go b/app/upgrades/v1.4.1/constants.go deleted file mode 100644 index 8a62d762..00000000 --- a/app/upgrades/v1.4.1/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v141 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.4.1" -) diff --git a/app/upgrades/v1.4.1/upgrades.go b/app/upgrades/v1.4.1/upgrades.go deleted file mode 100644 index aeb674b2..00000000 --- a/app/upgrades/v1.4.1/upgrades.go +++ /dev/null @@ -1,20 +0,0 @@ -package v141 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.4.1 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Info("run migration v1.4.1") - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/app/upgrades/v1.4.2/constants.go b/app/upgrades/v1.4.2/constants.go deleted file mode 100644 index d18a7fe4..00000000 --- a/app/upgrades/v1.4.2/constants.go +++ /dev/null @@ -1,6 +0,0 @@ -package v142 - -const ( - // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.4.2" -) diff --git a/app/upgrades/v1.4.2/upgrades.go b/app/upgrades/v1.4.2/upgrades.go deleted file mode 100644 index a576f3ed..00000000 --- a/app/upgrades/v1.4.2/upgrades.go +++ /dev/null @@ -1,20 +0,0 @@ -package v142 - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/module" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" -) - -// CreateUpgradeHandler creates an SDK upgrade handler for v1.4.2 -func CreateUpgradeHandler( - mm *module.Manager, - configurator module.Configurator, -) upgradetypes.UpgradeHandler { - return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { - logger := ctx.Logger() - logger.Info("run migration v1.4.2") - - return mm.RunMigrations(ctx, configurator, vm) - } -} diff --git a/app/upgrades/v1.0.2/constants.go b/app/upgrades/v1.6.4/constants.go similarity index 69% rename from app/upgrades/v1.0.2/constants.go rename to app/upgrades/v1.6.4/constants.go index 9a4d742f..0dfc19c9 100644 --- a/app/upgrades/v1.0.2/constants.go +++ b/app/upgrades/v1.6.4/constants.go @@ -1,6 +1,6 @@ -package v102 +package v164 const ( // UpgradeName is the shared upgrade plan name for mainnet and testnet - UpgradeName = "v1.0.2" + UpgradeName = "v1.6.4" ) diff --git a/app/upgrades/v1.6.4/upgrades.go b/app/upgrades/v1.6.4/upgrades.go new file mode 100644 index 00000000..fcd5854f --- /dev/null +++ b/app/upgrades/v1.6.4/upgrades.go @@ -0,0 +1,64 @@ +package v164 + +import ( + "strings" + + "cosmossdk.io/math" + storetypes "github.com/cosmos/cosmos-sdk/store/types" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" + coinomicskeeper "github.com/haqq-network/haqq/x/coinomics/keeper" + coinomicstypes "github.com/haqq-network/haqq/x/coinomics/types" +) + +// CreateUpgradeHandler creates an SDK upgrade handler for v1.6.4 +func CreateUpgradeHandler( + mm *module.Manager, + configurator module.Configurator, + storeKey storetypes.StoreKey, + paramsStoreKey storetypes.StoreKey, + dk distrkeeper.Keeper, + ck coinomicskeeper.Keeper, +) upgradetypes.UpgradeHandler { + return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) { + MigrateStore(ctx, storeKey, paramsStoreKey, dk, ck) + + return mm.RunMigrations(ctx, configurator, vm) + } +} + +// MigrateStore migrates the x/coinomics module state +func MigrateStore(ctx sdk.Context, + storeKey storetypes.StoreKey, + paramsStoreKey storetypes.StoreKey, + dk distrkeeper.Keeper, + ck coinomicskeeper.Keeper, +) { + // clean module state + store := ctx.KVStore(storeKey) + iterator := sdk.KVStorePrefixIterator(store, nil) + + for ; iterator.Valid(); iterator.Next() { + store.Delete(iterator.Key()) + } + + // clean params + paramsStore := ctx.KVStore(paramsStoreKey) + paramsIterator := sdk.KVStorePrefixIterator(paramsStore, nil) + + for ; paramsIterator.Valid(); paramsIterator.Next() { + if strings.Contains(string(paramsIterator.Key()), "coinomics/") { + paramsStore.Delete(paramsIterator.Key()) + } + } + + // reset coinomics params + defaultParams := coinomicstypes.DefaultParams() + maxSupply := sdk.Coin{Denom: "aISLM", Amount: math.NewIntWithDecimal(100_000_000_000, 18)} // 100bn ISLM + + ck.SetMaxSupply(ctx, maxSupply) + ck.SetParams(ctx, defaultParams) +} diff --git a/client/docs/swagger-ui/swagger.json b/client/docs/swagger-ui/swagger.json index c01880c6..d6a6c4d1 100644 --- a/client/docs/swagger-ui/swagger.json +++ b/client/docs/swagger-ui/swagger.json @@ -6347,15 +6347,15 @@ ] } }, - "/haqq/coinomics/v1/inflation_rate": { + "/haqq/coinomics/v1/params": { "get": { - "summary": "InflationRate retrieves current era inflation rate.", - "operationId": "InflationRate", + "summary": "Params retrieves coinomics moudle params.", + "operationId": "Params", "responses": { "200": { "description": "A successful response.", "schema": { - "$ref": "#/definitions/haqq.coinomics.v1.QueryInflationRateResponse" + "$ref": "#/definitions/haqq.coinomics.v1.QueryParamsResponse" } }, "default": { @@ -6370,15 +6370,15 @@ ] } }, - "/haqq/coinomics/v1/params": { + "/haqq/coinomics/v1/reward_coefficient": { "get": { - "summary": "Params retrieves coinomics moudle params.", - "operationId": "Params", + "summary": "InflationRewardCoefficientRate APY rate for staking rewards", + "operationId": "RewardCoefficient", "responses": { "200": { "description": "A successful response.", "schema": { - "$ref": "#/definitions/haqq.coinomics.v1.QueryParamsResponse" + "$ref": "#/definitions/haqq.coinomics.v1.QueryRewardCoefficientResponse" } }, "default": { @@ -6448,52 +6448,6 @@ ] } }, - "/haqqd/coinomics/v1/era": { - "get": { - "summary": "Era retrieves current era.", - "operationId": "Era", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/haqq.coinomics.v1.QueryEraResponse" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/google.rpc.Status" - } - } - }, - "tags": [ - "Query" - ] - } - }, - "/haqqd/coinomics/v1/era_closing_supply": { - "get": { - "summary": "EraTargetSupply retrieves current era target supply.", - "operationId": "EraClosingSupply", - "responses": { - "200": { - "description": "A successful response.", - "schema": { - "$ref": "#/definitions/haqq.coinomics.v1.QueryEraClosingSupplyResponse" - } - }, - "default": { - "description": "An unexpected error response.", - "schema": { - "$ref": "#/definitions/google.rpc.Status" - } - } - }, - "tags": [ - "Query" - ] - } - }, "/haqqd/coinomics/v1/max_supply": { "get": { "summary": "MaxSupply retrieves total coins of all eras and when mint ended.", @@ -13056,61 +13010,43 @@ "type": "string", "title": "type of coin to mint" }, - "blocksPerEra": { - "type": "string", - "format": "uint64", - "title": "number of blocks per era" - }, "enableCoinomics": { "type": "boolean", "title": "parameter to enable coinmoics" + }, + "rewardCoefficient": { + "type": "string", + "title": "current staking reward coefficient" } }, "description": "Params holds parameters for the coinomics module." }, - "haqq.coinomics.v1.QueryEraClosingSupplyResponse": { + "haqq.coinomics.v1.QueryMaxSupplyResponse": { "type": "object", "properties": { - "eraClosingSupply": { + "maxSupply": { "$ref": "#/definitions/cosmos.base.v1beta1.Coin" } } }, - "haqq.coinomics.v1.QueryEraResponse": { + "haqq.coinomics.v1.QueryParamsResponse": { "type": "object", "properties": { - "era": { - "type": "string", - "format": "uint64" + "params": { + "$ref": "#/definitions/haqq.coinomics.v1.Params", + "description": "params defines the parameters of the module." } } }, - "haqq.coinomics.v1.QueryInflationRateResponse": { + "haqq.coinomics.v1.QueryRewardCoefficientResponse": { "type": "object", "properties": { - "inflationRate": { + "rewardCoefficient": { "type": "string", "title": "rate by which the total supply increases within one era" } } }, - "haqq.coinomics.v1.QueryMaxSupplyResponse": { - "type": "object", - "properties": { - "maxSupply": { - "$ref": "#/definitions/cosmos.base.v1beta1.Coin" - } - } - }, - "haqq.coinomics.v1.QueryParamsResponse": { - "type": "object", - "properties": { - "params": { - "$ref": "#/definitions/haqq.coinomics.v1.Params", - "description": "params defines the parameters of the module." - } - } - }, "haqq.vesting.v1.QueryBalancesResponse": { "type": "object", "properties": { diff --git a/crypto/hd/algorithm.go b/crypto/hd/algorithm.go index 48688dcb..618caa4a 100644 --- a/crypto/hd/algorithm.go +++ b/crypto/hd/algorithm.go @@ -1,14 +1,16 @@ package hd import ( + "github.com/btcsuite/btcd/btcutil/hdkeychain" "github.com/btcsuite/btcd/chaincfg" - "github.com/btcsuite/btcutil/hdkeychain" + bip39 "github.com/tyler-smith/go-bip39" + + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/crypto" + "github.com/cosmos/cosmos-sdk/crypto/hd" "github.com/cosmos/cosmos-sdk/crypto/keyring" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/ethereum/go-ethereum/accounts" - "github.com/ethereum/go-ethereum/crypto" - bip39 "github.com/tyler-smith/go-bip39" "github.com/haqq-network/haqq/crypto/ethsecp256k1" ) diff --git a/crypto/hd/algorithm_test.go b/crypto/hd/algorithm_test.go index fdf7c226..dce1bb9c 100644 --- a/crypto/hd/algorithm_test.go +++ b/crypto/hd/algorithm_test.go @@ -7,11 +7,11 @@ import ( "github.com/stretchr/testify/require" + "github.com/ethereum/go-ethereum/common" + amino "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/ethereum/go-ethereum/common" - hdwallet "github.com/miguelmota/go-ethereum-hdwallet" cryptocodec "github.com/haqq-network/haqq/crypto/codec" enccodec "github.com/haqq-network/haqq/encoding/codec" @@ -73,11 +73,11 @@ func TestKeyring(t *testing.T) { addr := common.BytesToAddress(privkey.PubKey().Address().Bytes()) os.Setenv(hdWalletFixEnv, "true") - wallet, err := hdwallet.NewFromMnemonic(mnemonic) + wallet, err := NewFromMnemonic(mnemonic) os.Setenv(hdWalletFixEnv, "") require.NoError(t, err) - path := hdwallet.MustParseDerivationPath(hdPath) + path := MustParseDerivationPath(hdPath) account, err := wallet.Derive(path, false) require.NoError(t, err) @@ -100,14 +100,14 @@ func TestDerivation(t *testing.T) { require.False(t, privkey.Equals(badPrivKey)) - wallet, err := hdwallet.NewFromMnemonic(mnemonic) + wallet, err := NewFromMnemonic(mnemonic) require.NoError(t, err) - path := hdwallet.MustParseDerivationPath(haqqtypes.BIP44HDPath) + path := MustParseDerivationPath(haqqtypes.BIP44HDPath) account, err := wallet.Derive(path, false) require.NoError(t, err) - badPath := hdwallet.MustParseDerivationPath("44'/60'/0'/0/0") + badPath := MustParseDerivationPath("44'/60'/0'/0/0") badAccount, err := wallet.Derive(badPath, false) require.NoError(t, err) @@ -116,15 +116,15 @@ func TestDerivation(t *testing.T) { require.Equal(t, badAccount.Address.String(), "0xF8D6FDf2B8b488ea37e54903750dcd13F67E71cb") // Inequality of wrong derivation path address require.NotEqual(t, account.Address.String(), badAccount.Address.String()) - // Equality of Haqq Network implementation + // Equality of Haqq implementation require.Equal(t, common.BytesToAddress(privkey.PubKey().Address().Bytes()).String(), "0xA588C66983a81e800Db4dF74564F09f91c026351") require.Equal(t, common.BytesToAddress(badPrivKey.PubKey().Address().Bytes()).String(), "0xF8D6FDf2B8b488ea37e54903750dcd13F67E71cb") - // Equality of Eth and Haqq Network implementation + // Equality of Eth and Haqq implementation require.Equal(t, common.BytesToAddress(privkey.PubKey().Address()).String(), account.Address.String()) require.Equal(t, common.BytesToAddress(badPrivKey.PubKey().Address()).String(), badAccount.Address.String()) - // Inequality of wrong derivation path of Eth and Haqq Network implementation + // Inequality of wrong derivation path of Eth and Haqq implementation require.NotEqual(t, common.BytesToAddress(privkey.PubKey().Address()).String(), badAccount.Address.String()) require.NotEqual(t, common.BytesToAddress(badPrivKey.PubKey().Address()).String(), account.Address.Hex()) } diff --git a/crypto/hd/benchmark_test.go b/crypto/hd/benchmark_test.go index d208b06a..5317ea18 100644 --- a/crypto/hd/benchmark_test.go +++ b/crypto/hd/benchmark_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/cosmos/cosmos-sdk/crypto/keyring" - "github.com/haqq-network/haqq/types" ) diff --git a/crypto/hd/utils_test.go b/crypto/hd/utils_test.go new file mode 100644 index 00000000..2082368d --- /dev/null +++ b/crypto/hd/utils_test.go @@ -0,0 +1,181 @@ +// NOTE: This code is being used as test helper functions. +package hd + +import ( + "crypto/ecdsa" + "errors" + "os" + "sync" + + "github.com/ethereum/go-ethereum/accounts" + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/crypto" + + "github.com/btcsuite/btcd/btcutil/hdkeychain" + "github.com/btcsuite/btcd/chaincfg" + bip39 "github.com/tyler-smith/go-bip39" +) + +const issue179FixEnvar = "GO_ETHEREUM_HDWALLET_FIX_ISSUE_179" + +// Wallet is the underlying wallet struct. +type Wallet struct { + mnemonic string + masterKey *hdkeychain.ExtendedKey + seed []byte + paths map[common.Address]accounts.DerivationPath + accounts []accounts.Account + stateLock sync.RWMutex + fixIssue172 bool +} + +// NewFromMnemonic returns a new wallet from a BIP-39 mnemonic. +func NewFromMnemonic(mnemonic string) (*Wallet, error) { + if mnemonic == "" { + return nil, errors.New("mnemonic is required") + } + + if !bip39.IsMnemonicValid(mnemonic) { + return nil, errors.New("mnemonic is invalid") + } + + seed, err := NewSeedFromMnemonic(mnemonic) + if err != nil { + return nil, err + } + + wallet, err := newWallet(seed) + if err != nil { + return nil, err + } + wallet.mnemonic = mnemonic + + return wallet, nil +} + +// NewSeedFromMnemonic returns a BIP-39 seed based on a BIP-39 mnemonic. +func NewSeedFromMnemonic(mnemonic string) ([]byte, error) { + if mnemonic == "" { + return nil, errors.New("mnemonic is required") + } + + return bip39.NewSeedWithErrorChecking(mnemonic, "") +} + +func newWallet(seed []byte) (*Wallet, error) { + masterKey, err := hdkeychain.NewMaster(seed, &chaincfg.MainNetParams) + if err != nil { + return nil, err + } + + return &Wallet{ + masterKey: masterKey, + seed: seed, + accounts: []accounts.Account{}, + paths: map[common.Address]accounts.DerivationPath{}, + fixIssue172: false || len(os.Getenv(issue179FixEnvar)) > 0, + }, nil +} + +// Derive implements accounts.Wallet, deriving a new account at the specific +// derivation path. If pin is set to true, the account will be added to the list +// of tracked accounts. +func (w *Wallet) Derive(path accounts.DerivationPath, pin bool) (accounts.Account, error) { + // Try to derive the actual account and update its URL if successful + w.stateLock.RLock() // Avoid device disappearing during derivation + + address, err := w.deriveAddress(path) + + w.stateLock.RUnlock() + + // If an error occurred or no pinning was requested, return + if err != nil { + return accounts.Account{}, err + } + + account := accounts.Account{ + Address: address, + URL: accounts.URL{ + Scheme: "", + Path: path.String(), + }, + } + + if !pin { + return account, nil + } + + // Pinning needs to modify the state + w.stateLock.Lock() + defer w.stateLock.Unlock() + + if _, ok := w.paths[address]; !ok { + w.accounts = append(w.accounts, account) + w.paths[address] = path + } + + return account, nil +} + +// MustParseDerivationPath parses the derivation path in string format into +// []uint32 but will panic if it can't parse it. +func MustParseDerivationPath(path string) accounts.DerivationPath { + parsed, err := accounts.ParseDerivationPath(path) + if err != nil { + panic(err) + } + + return parsed +} + +// DerivePrivateKey derives the private key of the derivation path. +func (w *Wallet) derivePrivateKey(path accounts.DerivationPath) (*ecdsa.PrivateKey, error) { + var err error + key := w.masterKey + for _, n := range path { + if w.fixIssue172 && key.IsAffectedByIssue172() { + key, err = key.Derive(n) + } else { + //lint:ignore SA1019 this is used for testing only + key, err = key.DeriveNonStandard(n) //nolint:staticcheck + } + if err != nil { + return nil, err + } + } + + privateKey, err := key.ECPrivKey() + privateKeyECDSA := privateKey.ToECDSA() + if err != nil { + return nil, err + } + + return privateKeyECDSA, nil +} + +// derivePublicKey derives the public key of the derivation path. +func (w *Wallet) derivePublicKey(path accounts.DerivationPath) (*ecdsa.PublicKey, error) { + privateKeyECDSA, err := w.derivePrivateKey(path) + if err != nil { + return nil, err + } + + publicKey := privateKeyECDSA.Public() + publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey) + if !ok { + return nil, errors.New("failed to get public key") + } + + return publicKeyECDSA, nil +} + +// DeriveAddress derives the account address of the derivation path. +func (w *Wallet) deriveAddress(path accounts.DerivationPath) (common.Address, error) { + publicKeyECDSA, err := w.derivePublicKey(path) + if err != nil { + return common.Address{}, err + } + + address := crypto.PubkeyToAddress(*publicKeyECDSA) + return address, nil +} diff --git a/docker/build.Dockerfile b/docker/build.Dockerfile index ee1cfa22..1c9a48b5 100644 --- a/docker/build.Dockerfile +++ b/docker/build.Dockerfile @@ -24,11 +24,11 @@ COPY --from=build-env /go/bin/cosmovisor /usr/bin/cosmovisor COPY --from=build-env /go/src/github.com/haqq-network/haqq/build/haqqd /usr/bin/haqqd RUN apk add --no-cache \ - ca-certificates=20230506-r0 jq=~1.6 \ - curl=~8.4 bash=~5.2 \ - vim=~9.0 lz4=~1.9 \ - tini=~0.19 \ - gcompat=~1.1 + ca-certificates jq \ + curl bash \ + vim lz4 \ + tini \ + gcompat RUN addgroup -g 1000 haqq \ && adduser -S -h /home/haqq -D haqq -u 1000 -G haqq diff --git a/go.mod b/go.mod index 813d194b..ce7995ad 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/haqq-network/haqq -go 1.18 +go 1.20 require ( cosmossdk.io/errors v1.0.0-beta.7 cosmossdk.io/math v1.0.0-rc.0 github.com/armon/go-metrics v0.4.1 - github.com/btcsuite/btcd v0.22.2 - github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce + github.com/btcsuite/btcd v0.23.4 + github.com/btcsuite/btcd/btcutil v1.1.3 github.com/cosmos/cosmos-proto v1.0.0-beta.3 github.com/cosmos/cosmos-sdk v0.46.13 github.com/cosmos/go-bip39 v1.0.0 @@ -22,7 +22,6 @@ require ( github.com/grpc-ecosystem/grpc-gateway v1.16.0 github.com/hashicorp/go-version v1.6.0 github.com/improbable-eng/grpc-web v0.15.0 - github.com/miguelmota/go-ethereum-hdwallet v0.1.1 github.com/onsi/ginkgo/v2 v2.9.0 github.com/onsi/gomega v1.27.2 github.com/ory/dockertest/v3 v3.9.1 @@ -64,6 +63,7 @@ require ( github.com/StackExchange/wmi v1.2.1 // indirect github.com/VictoriaMetrics/fastcache v1.6.0 // indirect github.com/Workiva/go-datastructures v1.0.53 // indirect + github.com/allegro/bigcache v1.2.1 // indirect github.com/aws/aws-sdk-go v1.44.122 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect diff --git a/go.sum b/go.sum index 4b9e148f..db41bc8a 100644 --- a/go.sum +++ b/go.sum @@ -286,22 +286,28 @@ github.com/bmizerany/pat v0.0.0-20170815010413-6226ea591a40/go.mod h1:8rLXio+Wji github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/btcsuite/btcd v0.0.0-20190315201642-aa6e0f35703c/go.mod h1:DrZx5ec/dmnfpw9KyYoQyYo7d0KEvTkk/5M/vbZjAr8= github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= -github.com/btcsuite/btcd v0.21.0-beta/go.mod h1:ZSWyehm27aAuS9bvkATT+Xte3hjHZ+MRgMY/8NJ7K94= github.com/btcsuite/btcd v0.21.0-beta.0.20201114000516-e9c7a5ac6401/go.mod h1:Sv4JPQ3/M+teHz9Bo5jBpkNcP0x6r7rdihlNL/7tTAs= +github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= github.com/btcsuite/btcd v0.22.1/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= -github.com/btcsuite/btcd v0.22.2 h1:vBZ+lGGd1XubpOWO67ITJpAEsICWhA0YzqkcpkgNBfo= -github.com/btcsuite/btcd v0.22.2/go.mod h1:wqgTSL29+50LRkmOVknEdmt8ZojIzhuWvgu/iptuN7Y= +github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= +github.com/btcsuite/btcd v0.23.4 h1:IzV6qqkfwbItOS/sg/aDfPDsjPP8twrCOE2R93hxMlQ= +github.com/btcsuite/btcd v0.23.4/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= +github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= +github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= github.com/btcsuite/btcd/btcec/v2 v2.2.0/go.mod h1:U7MHm051Al6XmscBQ0BoNydpOTsFAn707034b5nY8zU= github.com/btcsuite/btcd/btcec/v2 v2.3.2 h1:5n0X6hX0Zk+6omWcihdYvdAlGf2DfasC0GMf7DClJ3U= github.com/btcsuite/btcd/btcec/v2 v2.3.2/go.mod h1:zYzJ8etWJQIv1Ogk7OzpWjowwOdXY1W/17j2MW85J04= -github.com/btcsuite/btcd/btcutil v1.1.2 h1:XLMbX8JQEiwMcYft2EGi8zPUkoa0abKIU6/BJSRsjzQ= +github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= +github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= +github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= +github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 h1:q0rUy8C/TYNBQS1+CGKw68tLOFYSNEs0TFnxxnS9+4U= github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= github.com/btcsuite/btcutil v0.0.0-20190207003914-4c204d697803/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts= -github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce h1:YtWJF7RHm2pYCvA5t0RPmAaLUhREsKuKd+SLhxFbFeQ= github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce/go.mod h1:0DVlHczLPewLcPGEIeUEzfOJhqGPQ0mJJRDBtD307+o= github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= @@ -903,8 +909,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5 github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo= github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= -github.com/miguelmota/go-ethereum-hdwallet v0.1.1 h1:zdXGlHao7idpCBjEGTXThVAtMKs+IxAgivZ75xqkWK0= -github.com/miguelmota/go-ethereum-hdwallet v0.1.1/go.mod h1:f9m9uXokAHA6WNoYOPjj4AqjJS5pquQRiYYj/XSyPYc= github.com/mimoo/StrobeGo v0.0.0-20181016162300-f8f6d4d2b643/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0 h1:QRUSJEgZn2Snx0EmT/QLXibWjSUDjKWvXIT19NBVp94= github.com/mimoo/StrobeGo v0.0.0-20210601165009-122bf33a46e0/go.mod h1:43+3pMjjKimDBf5Kr4ZFNGbLql1zKkbImw+fZbw3geM= diff --git a/nix/devshell.nix b/nix/devshell.nix index 9852aa13..3d4c7de0 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -29,7 +29,7 @@ languages.go = { enable = true; - package = pkgs.go_1_19; + package = pkgs.go_1_20; }; scripts.ci-proto.exec = '' diff --git a/proto/haqq/coinomics/v1/genesis.proto b/proto/haqq/coinomics/v1/genesis.proto index 19cf383f..bdc7d81d 100644 --- a/proto/haqq/coinomics/v1/genesis.proto +++ b/proto/haqq/coinomics/v1/genesis.proto @@ -11,34 +11,14 @@ message GenesisState { // params defines all the paramaters of the module. Params params = 1 [ (gogoproto.nullable) = false ]; - // current inflation rate - string inflation = 2 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", - (gogoproto.nullable) = false - ]; - - // current era number - uint64 era = 3; - - // era started block number - uint64 era_started_at_block = 4; - - // target mint for current era - cosmos.base.v1beta1.Coin era_target_mint = 5 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", - (gogoproto.moretags) = "yaml:\"era_target_mint\"", - (gogoproto.nullable) = false - ]; - - // closing supply for current era - cosmos.base.v1beta1.Coin era_closing_supply = 6 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", - (gogoproto.moretags) = "yaml:\"era_closing_supply\"", + // prev block block ts + string prev_block_ts = 2 [ + (gogoproto.customtype) = "cosmossdk.io/math.Int", (gogoproto.nullable) = false ]; // max supply - cosmos.base.v1beta1.Coin max_supply = 7 [ + cosmos.base.v1beta1.Coin max_supply = 3 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", (gogoproto.moretags) = "yaml:\"max_supply\"", (gogoproto.nullable) = false @@ -50,9 +30,12 @@ message Params { // type of coin to mint string mint_denom = 1; - // number of blocks per era - uint64 blocks_per_era = 2; - // parameter to enable coinmoics - bool enable_coinomics = 3; + bool enable_coinomics = 2; + + // current staking reward coefficient + string reward_coefficient = 3 [ + (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", + (gogoproto.nullable) = false + ]; } diff --git a/proto/haqq/coinomics/v1/query.proto b/proto/haqq/coinomics/v1/query.proto index 95b9a8ed..d02f81b6 100644 --- a/proto/haqq/coinomics/v1/query.proto +++ b/proto/haqq/coinomics/v1/query.proto @@ -10,26 +10,15 @@ option go_package = "github.com/haqq-network/haqq/x/coinomics/types"; // Query provides defines the gRPC querier service. service Query { - // Era retrieves current era. - rpc Era(QueryEraRequest) returns (QueryEraResponse) { - option (google.api.http).get = "/haqqd/coinomics/v1/era"; - } - - // EraTargetSupply retrieves current era target supply. - rpc EraClosingSupply(QueryEraClosingSupplyRequest) - returns (QueryEraClosingSupplyResponse) { - option (google.api.http).get = "/haqqd/coinomics/v1/era_closing_supply"; - } - // MaxSupply retrieves total coins of all eras and when mint ended. rpc MaxSupply(QueryMaxSupplyRequest) returns (QueryMaxSupplyResponse) { option (google.api.http).get = "/haqqd/coinomics/v1/max_supply"; } - // InflationRate retrieves current era inflation rate. - rpc InflationRate(QueryInflationRateRequest) - returns (QueryInflationRateResponse) { - option (google.api.http).get = "/haqq/coinomics/v1/inflation_rate"; + // InflationRewardCoefficientRate APY rate for staking rewards + rpc RewardCoefficient(QueryRewardCoefficientRequest) + returns (QueryRewardCoefficientResponse) { + option (google.api.http).get = "/haqq/coinomics/v1/reward_coefficient"; } // Params retrieves coinomics moudle params. @@ -38,17 +27,6 @@ service Query { } } -message QueryEraRequest {} -message QueryEraResponse { uint64 era = 1; } - -message QueryEraClosingSupplyRequest {} -message QueryEraClosingSupplyResponse { - cosmos.base.v1beta1.Coin era_closing_supply = 1 [ - (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Coin", - (gogoproto.nullable) = false - ]; -} - message QueryMaxSupplyRequest {} message QueryMaxSupplyResponse { cosmos.base.v1beta1.Coin max_supply = 1 [ @@ -57,10 +35,10 @@ message QueryMaxSupplyResponse { ]; } -message QueryInflationRateRequest {} -message QueryInflationRateResponse { +message QueryRewardCoefficientRequest {} +message QueryRewardCoefficientResponse { // rate by which the total supply increases within one era - string inflation_rate = 1 [ + string reward_coefficient = 1 [ (gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false ]; diff --git a/tests/e2e/upgrade/govexec.go b/tests/e2e/upgrade/govexec.go index 3337e840..52a3d549 100644 --- a/tests/e2e/upgrade/govexec.go +++ b/tests/e2e/upgrade/govexec.go @@ -27,9 +27,10 @@ func (m *Manager) CreateExec(cmd []string, containerID string) (string, error) { Context: ctx, AttachStdout: true, AttachStderr: true, - User: "root", - Container: containerID, - Cmd: cmd, + // deepcode ignore NoHardcodedCredentials/test: + User: "root", + Container: containerID, + Cmd: cmd, }) if err != nil { return "", err diff --git a/tests/e2e/upgrade/utils.go b/tests/e2e/upgrade/utils.go index 953d6181..dbd296a4 100644 --- a/tests/e2e/upgrade/utils.go +++ b/tests/e2e/upgrade/utils.go @@ -70,6 +70,7 @@ func RetrieveUpgradesList(upgradesPath string) ([]string, error) { // creating path to upgrade dir file with constant upgrade version constantsPath := fmt.Sprintf("%s/%s/constants.go", upgradesPath, d.Name()) + // deepcode ignore PT/test: f, err := os.ReadFile(constantsPath) if err != nil { return nil, err diff --git a/x/coinomics/client/cli/query.go b/x/coinomics/client/cli/query.go index a87baa90..dc28a09c 100644 --- a/x/coinomics/client/cli/query.go +++ b/x/coinomics/client/cli/query.go @@ -23,70 +23,14 @@ func GetQueryCmd() *cobra.Command { } cmd.AddCommand( - GetEra(), - GetEraClosingSupply(), - GetMaxSupply(), - GetInflationRate(), GetParams(), + GetMaxSupply(), + GetRewardCoefficient(), ) return cmd } -func GetEra() *cobra.Command { - cmd := &cobra.Command{ - Use: "era", - Short: "Query the current era", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryEraRequest{} - res, err := queryClient.Era(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintString(fmt.Sprintf("%v\n", res.Era)) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - -func GetEraClosingSupply() *cobra.Command { - cmd := &cobra.Command{ - Use: "era-closing-supply", - Short: "Query era closing supply", - Args: cobra.NoArgs, - RunE: func(cmd *cobra.Command, args []string) error { - clientCtx, err := client.GetClientQueryContext(cmd) - if err != nil { - return err - } - queryClient := types.NewQueryClient(clientCtx) - - params := &types.QueryEraClosingSupplyRequest{} - res, err := queryClient.EraClosingSupply(context.Background(), params) - if err != nil { - return err - } - - return clientCtx.PrintString(fmt.Sprintf("%v\n", res.EraClosingSupply)) - }, - } - - flags.AddQueryFlagsToCmd(cmd) - - return cmd -} - func GetMaxSupply() *cobra.Command { cmd := &cobra.Command{ Use: "max-supply", @@ -114,10 +58,10 @@ func GetMaxSupply() *cobra.Command { return cmd } -func GetInflationRate() *cobra.Command { +func GetRewardCoefficient() *cobra.Command { cmd := &cobra.Command{ - Use: "inflation-rate", - Short: "Query current era inflation rate", + Use: "reward-coefficient", + Short: "Query current reward coefficient", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { clientCtx, err := client.GetClientQueryContext(cmd) @@ -126,13 +70,13 @@ func GetInflationRate() *cobra.Command { } queryClient := types.NewQueryClient(clientCtx) - params := &types.QueryInflationRateRequest{} - res, err := queryClient.InflationRate(context.Background(), params) + params := &types.QueryRewardCoefficientRequest{} + res, err := queryClient.RewardCoefficient(context.Background(), params) if err != nil { return err } - return clientCtx.PrintString(fmt.Sprintf("%v\n", res.InflationRate)) + return clientCtx.PrintString(fmt.Sprintf("%v\n", res.RewardCoefficient)) }, } diff --git a/x/coinomics/genesis.go b/x/coinomics/genesis.go index e6056240..66008dc6 100644 --- a/x/coinomics/genesis.go +++ b/x/coinomics/genesis.go @@ -24,13 +24,8 @@ func InitGenesis( // Set genesis state params := data.Params - switch { - case haqqtypes.IsMainNetwork(ctx.ChainID()): + if haqqtypes.IsMainNetwork(ctx.ChainID()) { params.EnableCoinomics = false - case haqqtypes.IsTestEdge1Network(ctx.ChainID()): - params.BlocksPerEra = 8640 // 30 days until max supply minted - case haqqtypes.IsTestEdge2Network(ctx.ChainID()): - params.BlocksPerEra = 17280 // 60 days until max supply minted } k.SetParams(ctx, params) @@ -43,12 +38,8 @@ func InitGenesis( // ExportGenesis returns a GenesisState for a given context and keeper. func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { return &types.GenesisState{ - Params: k.GetParams(ctx), - Era: k.GetEra(ctx), - Inflation: k.GetInflation(ctx), - EraClosingSupply: k.GetEraClosingSupply(ctx), - EraStartedAtBlock: k.GetEraStartedAtBlock(ctx), - EraTargetMint: k.GetEraTargetMint(ctx), - MaxSupply: k.GetMaxSupply(ctx), + Params: k.GetParams(ctx), + PrevBlockTs: k.GetPrevBlockTS(ctx), + MaxSupply: k.GetMaxSupply(ctx), } } diff --git a/x/coinomics/keeper/abci.go b/x/coinomics/keeper/abci.go index ef05b0a3..8f44e43a 100644 --- a/x/coinomics/keeper/abci.go +++ b/x/coinomics/keeper/abci.go @@ -19,32 +19,7 @@ func (k Keeper) EndBlocker(ctx sdk.Context) { return } - currentBlock := uint64(ctx.BlockHeight()) - currentEra := k.GetEra(ctx) - - // Short-circuit as all inflation calculations will be 0 after 50 eras (100 years) have passed - if currentEra > 50 { - return - } - - eraForBlock := k.CountEraForBlock(ctx, params, currentEra, currentBlock) - - if currentEra != eraForBlock { - k.SetEra(ctx, eraForBlock) - k.SetEraStartedAtBlock(ctx, currentBlock) - - nextEraTargetMint := k.CalcTargetMintForEra(ctx, eraForBlock) - - currentTotalSupply := k.bankKeeper.GetSupply(ctx, types.DefaultMintDenom) - nextEraClosingSupply := currentTotalSupply.AddAmount(nextEraTargetMint.Amount) - nextEraInflation := k.CalcInflation(ctx, eraForBlock, nextEraClosingSupply, nextEraTargetMint) - - k.SetEraTargetMint(ctx, nextEraTargetMint) - k.SetEraClosingSupply(ctx, nextEraClosingSupply) - k.SetInflation(ctx, nextEraInflation) - } - - if err := k.MintAndAllocateInflation(ctx); err != nil { + if err := k.MintAndAllocate(ctx); err != nil { ctx.Logger().Error("Failed MintAndAllocateInflation: ", err.Error()) } } diff --git a/x/coinomics/keeper/era_info.go b/x/coinomics/keeper/era_info.go deleted file mode 100644 index 3be65ae2..00000000 --- a/x/coinomics/keeper/era_info.go +++ /dev/null @@ -1,153 +0,0 @@ -package keeper - -import ( - "fmt" - - sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/haqq-network/haqq/x/coinomics/types" -) - -func (k Keeper) GetInflation(ctx sdk.Context) sdk.Dec { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixInflation) - if len(bz) == 0 { - return sdk.ZeroDec() - } - - var inflationValue sdk.Dec - err := inflationValue.Unmarshal(bz) - if err != nil { - panic(fmt.Errorf("unable to unmarshal inflationValue value: %w", err)) - } - - return inflationValue -} - -func (k Keeper) SetInflation(ctx sdk.Context, inflation sdk.Dec) { - binaryInfValue, err := inflation.Marshal() - if err != nil { - panic(fmt.Errorf("unable to marshal amount value: %w", err)) - } - - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixInflation, binaryInfValue) -} - -// GetEra gets current era -func (k Keeper) GetEra(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixEra) - if len(bz) == 0 { - return 0 - } - - return sdk.BigEndianToUint64(bz) -} - -// SetEra stores the current era -func (k Keeper) SetEra(ctx sdk.Context, era uint64) { - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixEra, sdk.Uint64ToBigEndian(era)) -} - -// GetStartEraBlock gets current era start block number -func (k Keeper) GetEraStartedAtBlock(ctx sdk.Context) uint64 { - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixEraStartedAtBlock) - if len(bz) == 0 { - return 0 - } - - return sdk.BigEndianToUint64(bz) -} - -// SetStartEraBlock stores the start era block number -func (k Keeper) SetEraStartedAtBlock(ctx sdk.Context, block uint64) { - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixEraStartedAtBlock, sdk.Uint64ToBigEndian(block)) -} - -func (k Keeper) GetEraTargetMint(ctx sdk.Context) sdk.Coin { - params := k.GetParams(ctx) - - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KetPrefixEraTargetMint) - if len(bz) == 0 { - return sdk.NewCoin(params.MintDenom, sdk.ZeroInt()) - } - - var eraTargetMintValue sdk.Coin - err := eraTargetMintValue.Unmarshal(bz) - if err != nil { - panic(fmt.Errorf("unable to unmarshal eraTargetMintValue value: %w", err)) - } - - return eraTargetMintValue -} - -func (k Keeper) SetEraTargetMint(ctx sdk.Context, eraMint sdk.Coin) { - binaryEraTargetMintValue, err := eraMint.Marshal() - if err != nil { - panic(fmt.Errorf("unable to marshal amount value: %w", err)) - } - - store := ctx.KVStore(k.storeKey) - store.Set(types.KetPrefixEraTargetMint, binaryEraTargetMintValue) -} - -func (k Keeper) GetEraClosingSupply(ctx sdk.Context) sdk.Coin { - params := k.GetParams(ctx) - - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixEraClosingSupply) - if len(bz) == 0 { - return sdk.NewCoin(params.MintDenom, sdk.ZeroInt()) - } - - var eraTarget sdk.Coin - err := eraTarget.Unmarshal(bz) - if err != nil { - panic(fmt.Errorf("unable to unmarshal eraTarget value: %w", err)) - } - - return eraTarget -} - -func (k Keeper) SetEraClosingSupply(ctx sdk.Context, eraClosingSupply sdk.Coin) { - binaryEraClosingSupply, err := eraClosingSupply.Marshal() - if err != nil { - panic(fmt.Errorf("unable to marshal amount value: %w", err)) - } - - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixEraClosingSupply, binaryEraClosingSupply) -} - -func (k Keeper) GetMaxSupply(ctx sdk.Context) sdk.Coin { - params := k.GetParams(ctx) - - store := ctx.KVStore(k.storeKey) - bz := store.Get(types.KeyPrefixMaxSupply) - if len(bz) == 0 { - return sdk.NewCoin(params.MintDenom, sdk.ZeroInt()) - } - - var maxSupply sdk.Coin - err := maxSupply.Unmarshal(bz) - if err != nil { - panic(fmt.Errorf("unable to unmarshal maxSupply value: %w", err)) - } - - return maxSupply -} - -func (k Keeper) SetMaxSupply(ctx sdk.Context, maxSupply sdk.Coin) { - binaryMaxSupply, err := maxSupply.Marshal() - if err != nil { - panic(fmt.Errorf("unable to marshal amount value: %w", err)) - } - - store := ctx.KVStore(k.storeKey) - store.Set(types.KeyPrefixMaxSupply, binaryMaxSupply) -} diff --git a/x/coinomics/keeper/era_info_test.go b/x/coinomics/keeper/era_info_test.go deleted file mode 100644 index 7dbfe18b..00000000 --- a/x/coinomics/keeper/era_info_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package keeper_test - -import "fmt" - -func (suite *KeeperTestSuite) TestSetGetPeriod() { - expEra := uint64(9) - - testCases := []struct { - name string - malleate func() - ok bool - }{ - { - "default era", - func() {}, - false, - }, - { - "period set", - func() { - suite.app.CoinomicsKeeper.SetEra(suite.ctx, expEra) - }, - true, - }, - } - for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.name), func() { - suite.SetupTest() // reset - - tc.malleate() - - period := suite.app.CoinomicsKeeper.GetEra(suite.ctx) - if tc.ok { - suite.Require().Equal(expEra, period, tc.name) - } else { - suite.Require().Zero(period, tc.name) - } - }) - } -} diff --git a/x/coinomics/keeper/genesis_test.go b/x/coinomics/keeper/genesis_test.go index 43e014b2..dba05152 100644 --- a/x/coinomics/keeper/genesis_test.go +++ b/x/coinomics/keeper/genesis_test.go @@ -1,12 +1,12 @@ package keeper_test -import ( - sdk "github.com/cosmos/cosmos-sdk/types" -) +// import ( +// sdk "github.com/cosmos/cosmos-sdk/types" +// ) -func (suite *KeeperTestSuite) TestInitGenesis() { - // check calculated epochMintProvision at genesis - epochMintProvision := suite.app.CoinomicsKeeper.GetEraTargetMint(suite.ctx) - expMintProvision := sdk.NewCoin("aISLM", sdk.NewInt(0)) - suite.Require().Equal(expMintProvision, epochMintProvision) -} +// func (suite *KeeperTestSuite) TestInitGenesis() { +// // check calculated epochMintProvision at genesis +// epochMintProvision := suite.app.CoinomicsKeeper.GetEraTargetMint(suite.ctx) +// expMintProvision := sdk.NewCoin("aISLM", sdk.NewInt(0)) +// suite.Require().Equal(expMintProvision, epochMintProvision) +// } diff --git a/x/coinomics/keeper/grpc_query.go b/x/coinomics/keeper/grpc_query.go index af5572e7..2fbd0bc4 100644 --- a/x/coinomics/keeper/grpc_query.go +++ b/x/coinomics/keeper/grpc_query.go @@ -12,24 +12,14 @@ import ( var _ types.QueryServer = Keeper{} -func (k Keeper) Era( +func (k Keeper) RewardCoefficient( c context.Context, - _ *types.QueryEraRequest, -) (*types.QueryEraResponse, error) { + _ *types.QueryRewardCoefficientRequest, +) (*types.QueryRewardCoefficientResponse, error) { ctx := sdk.UnwrapSDKContext(c) - era := k.GetEra(ctx) - - return &types.QueryEraResponse{Era: era}, nil -} - -func (k Keeper) InflationRate( - c context.Context, - _ *types.QueryInflationRateRequest, -) (*types.QueryInflationRateResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - inflation := k.GetInflation(ctx) + params := k.GetParams(ctx) - return &types.QueryInflationRateResponse{InflationRate: inflation}, nil + return &types.QueryRewardCoefficientResponse{RewardCoefficient: params.RewardCoefficient}, nil } func (k Keeper) MaxSupply( @@ -42,16 +32,6 @@ func (k Keeper) MaxSupply( return &types.QueryMaxSupplyResponse{MaxSupply: maxSupply}, nil } -func (k Keeper) EraClosingSupply( - c context.Context, - _ *types.QueryEraClosingSupplyRequest, -) (*types.QueryEraClosingSupplyResponse, error) { - ctx := sdk.UnwrapSDKContext(c) - eraClosingSupply := k.GetEraClosingSupply(ctx) - - return &types.QueryEraClosingSupplyResponse{EraClosingSupply: eraClosingSupply}, nil -} - // Params returns params of the mint module. func (k Keeper) Params( c context.Context, diff --git a/x/coinomics/keeper/grpc_query_test.go b/x/coinomics/keeper/grpc_query_test.go index b96225b3..5dcb53c0 100644 --- a/x/coinomics/keeper/grpc_query_test.go +++ b/x/coinomics/keeper/grpc_query_test.go @@ -9,10 +9,10 @@ import ( "github.com/haqq-network/haqq/x/coinomics/types" ) -func (suite *KeeperTestSuite) TestEra() { +func (suite *KeeperTestSuite) TestRewardCoefficient() { var ( - req *types.QueryEraRequest - expRes *types.QueryEraResponse + req *types.QueryRewardCoefficientRequest + expRes *types.QueryRewardCoefficientResponse ) testCases := []struct { @@ -21,21 +21,22 @@ func (suite *KeeperTestSuite) TestEra() { expPass bool }{ { - "default era", + "default reward coefficient", func() { - req = &types.QueryEraRequest{} - expRes = &types.QueryEraResponse{} + req = &types.QueryRewardCoefficientRequest{} + expRes = &types.QueryRewardCoefficientResponse{RewardCoefficient: sdk.NewDecWithPrec(78, 1)} }, true, }, { - "set era", + "set reward coefficient", func() { - era := uint64(2) - suite.app.CoinomicsKeeper.SetEra(suite.ctx, era) + coinomicsParams := suite.app.CoinomicsKeeper.GetParams(s.ctx) + coinomicsParams.RewardCoefficient = sdk.NewDecWithPrec(10, 0) + s.app.CoinomicsKeeper.SetParams(s.ctx, coinomicsParams) - req = &types.QueryEraRequest{} - expRes = &types.QueryEraResponse{Era: era} + req = &types.QueryRewardCoefficientRequest{} + expRes = &types.QueryRewardCoefficientResponse{RewardCoefficient: sdk.NewDecWithPrec(10, 0)} }, true, }, @@ -47,108 +48,7 @@ func (suite *KeeperTestSuite) TestEra() { ctx := sdk.WrapSDKContext(suite.ctx) tc.malleate() - res, err := suite.queryClient.Era(ctx, req) - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(expRes, res) - } else { - suite.Require().Error(err) - } - }) - } -} - -func (suite *KeeperTestSuite) TestEraClosingSupply() { - var ( - req *types.QueryEraClosingSupplyRequest - expRes *types.QueryEraClosingSupplyResponse - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "default era closing supply", - func() { - req = &types.QueryEraClosingSupplyRequest{} - expRes = &types.QueryEraClosingSupplyResponse{EraClosingSupply: sdk.NewCoin("aISLM", sdk.NewInt(0))} - }, - true, - }, - { - "set era closing supply", - func() { - eraClosingSupply := sdk.NewCoin("aISLM", math.NewIntWithDecimal(1337, 18)) - suite.app.CoinomicsKeeper.SetEraClosingSupply(suite.ctx, eraClosingSupply) - - req = &types.QueryEraClosingSupplyRequest{} - expRes = &types.QueryEraClosingSupplyResponse{EraClosingSupply: eraClosingSupply} - }, - true, - }, - } - for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.name), func() { - suite.SetupTest() // reset - - ctx := sdk.WrapSDKContext(suite.ctx) - tc.malleate() - - res, err := suite.queryClient.EraClosingSupply(ctx, req) - - println("EraClosingSupply: ", res.EraClosingSupply.Amount.String()) - - if tc.expPass { - suite.Require().NoError(err) - suite.Require().Equal(expRes, res) - } else { - suite.Require().Error(err) - } - }) - } -} - -func (suite *KeeperTestSuite) TestInflationRate() { - var ( - req *types.QueryInflationRateRequest - expRes *types.QueryInflationRateResponse - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "default inflation rate", - func() { - req = &types.QueryInflationRateRequest{} - expRes = &types.QueryInflationRateResponse{InflationRate: sdk.ZeroDec()} - }, - true, - }, - { - "set inflation rate", - func() { - rate := sdk.NewDec(10) - suite.app.CoinomicsKeeper.SetInflation(suite.ctx, rate) - - req = &types.QueryInflationRateRequest{} - expRes = &types.QueryInflationRateResponse{InflationRate: rate} - }, - true, - }, - } - for _, tc := range testCases { - suite.Run(fmt.Sprintf("Case %s", tc.name), func() { - suite.SetupTest() // reset - - ctx := sdk.WrapSDKContext(suite.ctx) - tc.malleate() - - res, err := suite.queryClient.InflationRate(ctx, req) + res, err := suite.queryClient.RewardCoefficient(ctx, req) if tc.expPass { suite.Require().NoError(err) suite.Require().Equal(expRes, res) diff --git a/x/coinomics/keeper/inflation.go b/x/coinomics/keeper/inflation.go index bda1a6b8..dd1df91c 100644 --- a/x/coinomics/keeper/inflation.go +++ b/x/coinomics/keeper/inflation.go @@ -1,102 +1,67 @@ package keeper import ( - "math" + "fmt" + "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/pkg/errors" "github.com/haqq-network/haqq/x/coinomics/types" ) -// CountEraForBlock NextPhase calculus -func (k Keeper) CountEraForBlock(ctx sdk.Context, params types.Params, currentEra uint64, currentBlock uint64) uint64 { - if currentEra == 0 { - return 1 - } +func (k Keeper) MintAndAllocate(ctx sdk.Context) error { + // Convert current block timestamp to Dec type for calculations + currentBlockTS, _ := sdk.NewDecFromStr(math.NewInt(ctx.BlockTime().UnixMilli()).String()) - params = k.GetParams(ctx) + // Skip minting for the first block after activation, waiting for previous block timestamp to be set + if k.GetPrevBlockTS(ctx).Equal(sdk.ZeroInt()) { + k.SetPrevBlockTS(ctx, currentBlockTS.RoundInt()) + return nil + } - startedBlock := k.GetEraStartedAtBlock(ctx) - nextEraBlock := params.BlocksPerEra + startedBlock + // Determine if the current year is a leap year + currentYear := ctx.BlockTime().Year() + isLeapYear := (currentYear%4 == 0 && currentYear%100 != 0) || currentYear%400 == 0 - if currentBlock < nextEraBlock { - return currentEra + // Define milliseconds in a year, considering leap year + var yearInMillis sdk.Dec + if isLeapYear { + yearInMillis, _ = sdk.NewDecFromStr("31622400000") // 366 days in milliseconds + } else { + yearInMillis, _ = sdk.NewDecFromStr("31536000000") // 365 days in milliseconds } - return currentEra + 1 -} - -func (k Keeper) CalcTargetMintForEra(ctx sdk.Context, eraNumber uint64) sdk.Coin { + // Calculate the mint amount based on total bonded tokens and time elapsed since the last block. params := k.GetParams(ctx) + rewardCoefficient := params.RewardCoefficient.Quo(sdk.NewDec(100)) + prevBlockTS, _ := sdk.NewDecFromStr(k.GetPrevBlockTS(ctx).String()) + totalBonded, _ := sdk.NewDecFromStr(k.stakingKeeper.TotalBondedTokens(ctx).String()) - // eraCoef can't be declared as constant because it's a sdk.Dec with a dynamic constructor - eraCoef := sdk.NewDecWithPrec(95, 2) // 0.95 - - switch { - case eraNumber == 1: - currentTotalSupply := k.bankKeeper.GetSupply(ctx, types.DefaultMintDenom) - maxSupply := k.GetMaxSupply(ctx) - - totalMintNeeded := maxSupply.SubAmount(currentTotalSupply.Amount) - // ----------- NUM ------------- / ---------- DEN ------------- - // era_period = 2 years - // (1-era_coef)*total_mint_needed / (1-era_coef^(100/era_period)) - num := sdk.NewDecWithPrec(5, 2).Mul(sdk.NewDecFromInt(totalMintNeeded.Amount)) - den := sdk.OneDec().Sub(eraCoef.Power(50)) - target := num.Quo(den) - - return sdk.NewCoin(params.MintDenom, target.RoundInt()) - case eraNumber > 1 && eraNumber < 50: - prevTargetMint := k.GetEraTargetMint(ctx) - currTargetMint := sdk.NewDecFromInt(prevTargetMint.Amount).Mul(eraCoef) - - return sdk.NewCoin(types.DefaultMintDenom, currTargetMint.RoundInt()) - case eraNumber == 50: - currentTotalSupply := k.bankKeeper.GetSupply(ctx, types.DefaultMintDenom) - maxSupply := k.GetMaxSupply(ctx) - - return maxSupply.SubAmount(currentTotalSupply.Amount) - default: - return sdk.NewCoin(params.MintDenom, sdk.NewInt(0)) - } -} + // totalBonded * rewardCoefficient * ((currentBlockTS - prevBlockTS) / yearInMillis) + blockMint := totalBonded.Mul(rewardCoefficient).Mul((currentBlockTS.Sub(prevBlockTS)).Quo(yearInMillis)) -func (k Keeper) CalcInflation(_ sdk.Context, era uint64, eraTargetSupply sdk.Coin, eraTargetMint sdk.Coin) sdk.Dec { - if era > 50 { - return sdk.NewDec(0) - } + bankTotalSupply, _ := sdk.NewDecFromStr(k.bankKeeper.GetSupply(ctx, params.MintDenom).Amount.String()) + maxSupply, _ := sdk.NewDecFromStr(k.GetMaxSupply(ctx).Amount.String()) - if eraTargetSupply.IsZero() { - return sdk.NewDec(0) + // Ensure minting does not exceed the maximum supply + if bankTotalSupply.Add(blockMint).GT(maxSupply) { + blockMint = maxSupply.Sub(bankTotalSupply) + params.EnableCoinomics = false + k.SetParams(ctx, params) } - quoAmount := sdk.NewDecFromInt(eraTargetSupply.SubAmount(eraTargetMint.Amount).Amount) - if quoAmount.IsZero() { - return sdk.NewDec(0) - } + if blockMint.IsNegative() { + // state is corrupted + errStr := fmt.Sprintf("MintAndAllocate # blockMint is negative # blockMint: %s, totalBonded: %s, rewardCoefficient: %s, currentBlockTS: %s, prevBlockTS: %s, yearInMillis: %s", blockMint.String(), totalBonded.String(), rewardCoefficient.String(), currentBlockTS.String(), prevBlockTS.String(), yearInMillis.String()) - return sdk.NewDecFromInt(eraTargetMint.Amount).Quo(quoAmount).Mul(sdk.NewDec(100)) -} - -func (k Keeper) MintAndAllocateInflation(ctx sdk.Context) error { - params := k.GetParams(ctx) - eraTargetMint := k.GetEraTargetMint(ctx) - - // BlocksPerEra is unsigned and can't be negative, so check only for zero value - if params.BlocksPerEra == 0 { - return errors.New("BlocksPerEra is zero") - } + ctx.Logger().Error(errStr) - // Check if BlocksPerEra is within the uint64 range - if params.BlocksPerEra > math.MaxUint64 { - return errors.New("BlocksPerEra is out of uint64 range") + return nil } - totalMintOnBlockInt := eraTargetMint.Amount.Quo(sdk.NewIntFromUint64(params.BlocksPerEra)) - totalMintOnBlockCoin := sdk.NewCoin(params.MintDenom, totalMintOnBlockInt) - - // Mint coins to coinomics module + // Mint and allocate the calculated coin amount + totalMintOnBlockCoin := sdk.NewCoin(params.MintDenom, blockMint.RoundInt()) if err := k.MintCoins(ctx, totalMintOnBlockCoin); err != nil { return errors.Wrap(err, "failed mint coins") } @@ -112,16 +77,20 @@ func (k Keeper) MintAndAllocateInflation(ctx sdk.Context) error { return errors.Wrap(err, "failed send coins from coinomics to distribution") } + // Update the previous block timestamp for the next cycle. + k.SetPrevBlockTS(ctx, currentBlockTS.RoundInt()) + return nil } func (k Keeper) MintCoins(ctx sdk.Context, coin sdk.Coin) error { coins := sdk.NewCoins(coin) - // skip as no coins need to be minted + // Skip minting if no coins are specified if coins.Empty() { return nil } + // Perform the minting action return k.bankKeeper.MintCoins(ctx, types.ModuleName, coins) } diff --git a/x/coinomics/keeper/integration_test.go b/x/coinomics/keeper/integration_test.go index a3473d05..2beb6c77 100644 --- a/x/coinomics/keeper/integration_test.go +++ b/x/coinomics/keeper/integration_test.go @@ -1,28 +1,35 @@ package keeper_test import ( - "math/big" - . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" - // "github.com/cosmos/cosmos-sdk/x/staking/types" - // "github.com/haqq-network/haqq/crypto/ethsecp256k1" - // "github.com/haqq-network/haqq/testutil" + "github.com/haqq-network/haqq/crypto/ethsecp256k1" + "github.com/haqq-network/haqq/testutil" ) +func setupCoinomicsParams(s *KeeperTestSuite, rewardCoefficient sdk.Dec) { + coinomicsParams := s.app.CoinomicsKeeper.GetParams(s.ctx) + coinomicsParams.RewardCoefficient = rewardCoefficient + s.app.CoinomicsKeeper.SetParams(s.ctx, coinomicsParams) +} + +func isLeapYear(ctx sdk.Context) bool { + year := ctx.BlockTime().Year() + return year%4 == 0 && (year%100 != 0 || year%400 == 0) +} + var _ = Describe("Coinomics", Ordered, func() { BeforeEach(func() { s.SetupTest() - // make eras shorter - coinomicsParams := s.app.CoinomicsKeeper.GetParams(s.ctx) - coinomicsParams.BlocksPerEra = 100 - s.app.CoinomicsKeeper.SetParams(s.ctx, coinomicsParams) + // set coinomics params + rewardCoefficient := sdk.NewDecWithPrec(78, 1) // 7.8% + setupCoinomicsParams(s, rewardCoefficient) - // change distribution module params + // set distribution module params distributionParams := s.app.DistrKeeper.GetParams(s.ctx) distributionParams.CommunityTax = sdk.NewDecWithPrec(10, 2) distributionParams.BaseProposerReward = sdk.NewDecWithPrec(1, 2) @@ -32,7 +39,7 @@ var _ = Describe("Coinomics", Ordered, func() { s.app.DistrKeeper.SetParams(s.ctx, distributionParams) }) - Describe("Committing a block", func() { + Describe("Check coinomics on regular year", func() { Context("with coinomics disabled", func() { BeforeEach(func() { params := s.app.CoinomicsKeeper.GetParams(s.ctx) @@ -41,24 +48,23 @@ var _ = Describe("Coinomics", Ordered, func() { s.app.CoinomicsKeeper.SetParams(s.ctx, params) }) - It("check totals in all eras", func() { + It("should not mint coins when coinomics is disabled", func() { currentSupply := s.app.BankKeeper.GetSupply(s.ctx, denomMint) - currentEra := s.app.CoinomicsKeeper.GetEra(s.ctx) + currentBlock := s.ctx.BlockHeight() startExpectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_000_000_000, 18)) Expect(startExpectedSupply.Amount).To(Equal(currentSupply.Amount)) - Expect(currentEra).To(Equal(uint64(0))) - for era := 1; era <= 50; era++ { - s.Commit(100) + s.Commit(100) - currentSupply = s.app.BankKeeper.GetSupply(s.ctx, denomMint) - currentEra = s.app.CoinomicsKeeper.GetEra(s.ctx) + currentBlockAfterCommins := s.ctx.BlockHeight() - Expect(startExpectedSupply.Amount).To(Equal(currentSupply.Amount)) - Expect(currentEra).To(Equal(uint64(0))) - } + Expect(currentBlock + 100).To(Equal(currentBlockAfterCommins)) + + currentSupply = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + + Expect(startExpectedSupply.Amount).To(Equal(currentSupply.Amount)) }) }) @@ -70,150 +76,229 @@ var _ = Describe("Coinomics", Ordered, func() { s.app.CoinomicsKeeper.SetParams(s.ctx, params) }) - Context("check all eras mint", func() { - It("should allocate all eras correct", func() { - currentSupply := s.app.BankKeeper.GetSupply(s.ctx, denomMint) - currentEra := s.app.CoinomicsKeeper.GetEra(s.ctx) - - startExpectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_000_000_000, 18)) - - Expect(startExpectedSupply.Amount).To(Equal(currentSupply.Amount)) - Expect(currentEra).To(Equal(uint64(0))) - - expectedSupplys := []string{ - "24333436136376723087884929700", - "28450200465934610021375612900", - "32361126579014602608191762000", - "36076506386440595565667103600", - "39606117203495288875268678100", - "42959247479697247519390173900", - "46144721242089108231305594900", - "49170921316361375907625244900", - "52045811386920030200128912400", - "54776956953950751778007396500", - "57371545242629937276991956400", - "59836404116875163501027288300", - "62178020047408128413860853600", - "64402555181414445081052740600", - "66515863558720445914885033300", - "68523506517161146707025711300", - "70430767327679812459559355400", - "72242665097672544924466317300", - "73963967979165640766127931100", - "75599205716584081815706464200", - "77152681567131600812806070700", - "78628483625151743860050696800", - "80030495580270879754933091600", - "81362406937634058855071366700", - "82627722727129079000202728000", - "83829772727149348138077521300", - "84971720227168603819058574900", - "86056570352186896715990575800", - "87087177970954274968075976700", - "88066255208783284307557107500", - "88996378584720843180064181800", - "89879995791861524108945902400", - "90719432138645170991383536900", - "91516896668089635529699289700", - "92274487971061876841099254900", - "92994199708885506086929221800", - "93677925859817953870467690300", - "94327465703203779264829235400", - "94944528554420313389472703300", - "95530738263076020807883997800", - "96087637486298942855374727500", - "96616691748360718800490920800", - "97119293297319405948351304400", - "97596764768830158738818668800", - "98050362666765373889762665000", - "98481280669803828283159461400", - "98890652772690359956886417900", - "99279556270432565046927026600", - "99649014593287659882465604900", - "100000000000000000000000000000", - "100000000000000000000000000000", - } - - for era := 1; era <= len(expectedSupplys); era++ { - s.Commit(100) - - currentSupply = s.app.BankKeeper.GetSupply(s.ctx, denomMint) - currentEra = s.app.CoinomicsKeeper.GetEra(s.ctx) - - eraExpectedSupplyBigInt, _ := big.NewInt(0).SetString(expectedSupplys[era-1], 0) - eraExpectedSupply := sdk.NewCoin(denomMint, sdk.NewIntFromBigInt(eraExpectedSupplyBigInt)) - - Expect(eraExpectedSupply.Amount).To(Equal(currentSupply.Amount)) - Expect(currentEra).To(Equal(uint64(era))) - } - }) - It("should allocate funds to the evergreen pool", func() { - balanceCommunityPool := s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx) - Expect(balanceCommunityPool.IsZero()).To(BeTrue()) - - // skip some blocks - s.Commit(10) - - currentEra := s.app.CoinomicsKeeper.GetEra(s.ctx) - Expect(currentEra).To(Equal(uint64(1))) - - balanceCommunityPool = s.app.DistrKeeper.GetFeePoolCommunityCoins(s.ctx) - Expect(balanceCommunityPool.IsZero()).ToNot(BeTrue()) - }) - // It("delegations is works", func() { - // s.Commit(1) - - // accKey, err := ethsecp256k1.GenerateKey() // _accPrivKey - // s.Require().NoError(err) - // addr := sdk.AccAddress(accKey.PubKey().Address()) - - // fundAmount := sdk.TokensFromConsensusPower(100_000_000, sdk.DefaultPowerReduction) - - // err = testutil.FundAccount(s.ctx, s.app.BankKeeper, addr, sdk.NewCoins(sdk.NewCoin(denomMint, fundAmount))) - // s.Require().NoError(err) - - // s.Commit(1) - - // // delegation - // delAmount := sdk.TokensFromConsensusPower(11_000_000, sdk.DefaultPowerReduction) - // delCoin := sdk.NewCoin(denomMint, delAmount) - - // _, err = testutil.Delegate(s.ctx, s.app, accKey, delCoin, s.validator) - // s.Require().NoError(err) - - // // println("suite.validator #start# bonded tokens: ", s.validator.GetBondedTokens().String()) - // // println("suite.validator #start# get tokens: ", s.validator.GetTokens().String()) - - // s.Commit(1) - - // validators := s.app.StakingKeeper.GetValidators(s.ctx, 2) - - // for i, v := range validators { - // println("validator info", i, "status: ", v.Status.String()) - - // if v.Status == types.Bonded { - // println("Bonded!") - // _, err = testutil.Delegate(s.ctx, s.app, accKey, delCoin, v) - // s.Require().NoError(err) - // s.Commit(1) - - // // println("suite.validator #start# bonded tokens: ", v.GetBondedTokens().String()) - // // println("suite.validator #start# get tokens: ", v.GetTokens().String()) - // } - // } - - // s.Commit(10) - - // delegations := s.app.StakingKeeper.GetAllDelegations(s.ctx) - - // for i, del := range delegations { - // println("delegation #", i, "deladdr: ", del.DelegatorAddress, "valaddr: ", del.ValidatorAddress, "shares: ", del.Shares.String()) - - // endingPeriod := s.app.DistrKeeper.IncrementValidatorPeriod(s.ctx, s.validator) - // rewards := s.app.DistrKeeper.CalculateDelegationRewards(s.ctx, s.validator, del, endingPeriod) - // println("rewards: ", rewards.String()) - // } - // }) + It("check mint calculations on regular year", func() { + totalSupplyOnStart := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + startExpectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_000_000_000, 18)) + + Expect(startExpectedSupply.Amount).To(Equal(totalSupplyOnStart.Amount)) + + accKey, err := ethsecp256k1.GenerateKey() + s.Require().NoError(err) + addr := sdk.AccAddress(accKey.PubKey().Address()) + + fundAmount := sdk.TokensFromConsensusPower(100_000_000, sdk.DefaultPowerReduction) + + err = testutil.FundAccount(s.ctx, s.app.BankKeeper, addr, sdk.NewCoins(sdk.NewCoin(denomMint, fundAmount))) + s.Require().NoError(err) + + totalSupplyAfterFund := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + expectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_100_000_000, 18)) + + Expect(totalSupplyAfterFund.Amount).To(Equal(expectedSupply.Amount)) + + s.Commit(1) + + isLeapYear := isLeapYear(s.ctx) + Expect(isLeapYear).To(Equal(false)) + + // delegation + delAmount := sdk.TokensFromConsensusPower(10_000_000, sdk.DefaultPowerReduction) + delCoin := sdk.NewCoin(denomMint, delAmount) + + _, err = testutil.Delegate(s.ctx, s.app, accKey, delCoin, s.validator) + s.Require().NoError(err) + + totalBonded := s.app.StakingKeeper.TotalBondedTokens(s.ctx) + expectedTotalBonded := sdk.NewCoin(denomMint, math.NewIntWithDecimal(10_000_001, 18)) + Expect(totalBonded).To(Equal(expectedTotalBonded.Amount)) + + totalSupplyBeforeMint10Blocks := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + heightBeforeMint := s.ctx.BlockHeight() + PrevTSBeforeMint := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // mint blocks + s.Commit(10) + + PrevTSAfter10Blocks := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // check commit height is changed and prev block ts is changed + Expect(s.ctx.BlockHeight()).To(Equal(heightBeforeMint + 10)) + Expect(PrevTSAfter10Blocks).To(Equal(PrevTSBeforeMint.Add(math.NewInt(10 * 6 * 1000)))) + + // check mint amount with 7.8% coefficient + totalSupplyAfterMint10Blocks := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + diff7_8Coefficient10blocks := totalSupplyAfterMint10Blocks.Sub(totalSupplyBeforeMint10Blocks) + Expect(diff7_8Coefficient10blocks.Amount).To(Equal(sdk.NewInt(1484018413245226480))) + + // change params + rewardCoefficient := sdk.NewDecWithPrec(10, 1) // 10% + setupCoinomicsParams(s, rewardCoefficient) + + totalSupplyBeforeMint10Blocks = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + + // mint blocks + s.Commit(10) + + PrevTSAfter20Blocks := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // check commit height is changed and prev block ts is changed + Expect(s.ctx.BlockHeight()).To(Equal(heightBeforeMint + 20)) + Expect(PrevTSAfter20Blocks).To(Equal(PrevTSBeforeMint.Add(math.NewInt(20 * 6 * 1000)))) + + // check mint amount with 10.0% coefficient + totalSupplyAfterMint10Blocks = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + diff10_0Coefficient10blocks := totalSupplyAfterMint10Blocks.Sub(totalSupplyBeforeMint10Blocks) + Expect(diff10_0Coefficient10blocks.Amount).To(Equal(sdk.NewInt(190258770928875190))) + }) + + It("check mint calculations for leap year", func() { + totalSupplyOnStart := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + startExpectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_000_000_000, 18)) + + Expect(startExpectedSupply.Amount).To(Equal(totalSupplyOnStart.Amount)) + + accKey, err := ethsecp256k1.GenerateKey() + s.Require().NoError(err) + addr := sdk.AccAddress(accKey.PubKey().Address()) + + fundAmount := sdk.TokensFromConsensusPower(100_000_000, sdk.DefaultPowerReduction) + + err = testutil.FundAccount(s.ctx, s.app.BankKeeper, addr, sdk.NewCoins(sdk.NewCoin(denomMint, fundAmount))) + s.Require().NoError(err) + + totalSupplyAfterFund := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + expectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_100_000_000, 18)) + + Expect(totalSupplyAfterFund.Amount).To(Equal(expectedSupply.Amount)) + + s.CommitLeapYear() + + isLeapYear := isLeapYear(s.ctx) + Expect(isLeapYear).To(Equal(true)) + + // delegation + delAmount := sdk.TokensFromConsensusPower(10_000_000, sdk.DefaultPowerReduction) + delCoin := sdk.NewCoin(denomMint, delAmount) + + _, err = testutil.Delegate(s.ctx, s.app, accKey, delCoin, s.validator) + s.Require().NoError(err) + + totalBonded := s.app.StakingKeeper.TotalBondedTokens(s.ctx) + expectedTotalBonded := sdk.NewCoin(denomMint, math.NewIntWithDecimal(10_000_001, 18)) + Expect(totalBonded).To(Equal(expectedTotalBonded.Amount)) + + totalSupplyBeforeMint10Blocks := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + heightBeforeMint := s.ctx.BlockHeight() + PrevTSBeforeMint := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // mint blocks + s.Commit(10) + + PrevTSAfter10Blocks := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // check commit height is changed and prev block ts is changed + Expect(s.ctx.BlockHeight()).To(Equal(heightBeforeMint + 10)) + Expect(PrevTSAfter10Blocks).To(Equal(PrevTSBeforeMint.Add(math.NewInt(10 * 6 * 1000)))) + + // check mint amount with 7.8% coefficient + totalSupplyAfterMint10Blocks := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + diff7_8Coefficient10blocks := totalSupplyAfterMint10Blocks.Sub(totalSupplyBeforeMint10Blocks) + Expect(diff7_8Coefficient10blocks.Amount).To(Equal(sdk.NewInt(1479963718122957010))) + + // change params + rewardCoefficient := sdk.NewDecWithPrec(10, 1) // 10% + setupCoinomicsParams(s, rewardCoefficient) + + totalSupplyBeforeMint10Blocks = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + + // mint blocks + s.Commit(10) + + PrevTSAfter20Blocks := s.app.CoinomicsKeeper.GetPrevBlockTS(s.ctx) + + // check commit height is changed and prev block ts is changed + Expect(s.ctx.BlockHeight()).To(Equal(heightBeforeMint + 20)) + Expect(PrevTSAfter20Blocks).To(Equal(PrevTSBeforeMint.Add(math.NewInt(20 * 6 * 1000)))) + + // check mint amount with 10.0% coefficient + totalSupplyAfterMint10Blocks = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + diff10_0Coefficient10blocks := totalSupplyAfterMint10Blocks.Sub(totalSupplyBeforeMint10Blocks) + Expect(diff10_0Coefficient10blocks.Amount).To(Equal(sdk.NewInt(189738938220891920))) + }) + + It("check max supply limit", func() { + setupCoinomicsParams(s, sdk.NewDecWithPrec(15_000_000_000, 0)) // 15_000_000_000 % + + totalSupplyOnStart := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + startExpectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_000_000_000, 18)) + + Expect(startExpectedSupply.Amount).To(Equal(totalSupplyOnStart.Amount)) + + accKey, err := ethsecp256k1.GenerateKey() + s.Require().NoError(err) + addr := sdk.AccAddress(accKey.PubKey().Address()) + + fundAmount := sdk.TokensFromConsensusPower(100_000_000, sdk.DefaultPowerReduction) + + err = testutil.FundAccount(s.ctx, s.app.BankKeeper, addr, sdk.NewCoins(sdk.NewCoin(denomMint, fundAmount))) + s.Require().NoError(err) + + totalSupplyAfterFund := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + expectedSupply := sdk.NewCoin(denomMint, math.NewIntWithDecimal(20_100_000_000, 18)) + + Expect(totalSupplyAfterFund.Amount).To(Equal(expectedSupply.Amount)) + + s.Commit(1) + + // delegation + delAmount := sdk.TokensFromConsensusPower(90_000_000, sdk.DefaultPowerReduction) + delCoin := sdk.NewCoin(denomMint, delAmount) + + _, err = testutil.Delegate(s.ctx, s.app, accKey, delCoin, s.validator) + s.Require().NoError(err) + + totalBonded := s.app.StakingKeeper.TotalBondedTokens(s.ctx) + expectedTotalBonded := sdk.NewCoin(denomMint, math.NewIntWithDecimal(90_000_001, 18)) + Expect(totalBonded).To(Equal(expectedTotalBonded.Amount)) + + // mint blocks + s.Commit(10) + + maxSupply := s.app.CoinomicsKeeper.GetMaxSupply(s.ctx) + paramsAfterCommits := s.app.CoinomicsKeeper.GetParams(s.ctx) + totalSupplyAfterCommits := s.app.BankKeeper.GetSupply(s.ctx, denomMint) + + Expect(maxSupply.Amount).To(Not(Equal(totalSupplyAfterCommits.Amount))) + Expect(paramsAfterCommits.EnableCoinomics).To(Equal(true)) + + // mint blocks + s.Commit(60) + + totalSupplyAfterCommits = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + paramsAfterCommits = s.app.CoinomicsKeeper.GetParams(s.ctx) + + Expect(maxSupply.Amount).To(Equal(totalSupplyAfterCommits.Amount)) + Expect(paramsAfterCommits.EnableCoinomics).To(Equal(false)) + + // double check + s.Commit(10) + + totalSupplyAfterCommits = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + Expect(maxSupply.Amount).To(Equal(totalSupplyAfterCommits.Amount)) + + // check: not mint if coinomics enables back + params := s.app.CoinomicsKeeper.GetParams(s.ctx) + params.EnableCoinomics = true + + s.app.CoinomicsKeeper.SetParams(s.ctx, params) + + s.Commit(10) + + totalSupplyAfterCommits = s.app.BankKeeper.GetSupply(s.ctx, denomMint) + paramsAfterCommits = s.app.CoinomicsKeeper.GetParams(s.ctx) + + Expect(maxSupply.Amount).To(Equal(totalSupplyAfterCommits.Amount)) + Expect(paramsAfterCommits.EnableCoinomics).To(Equal(false)) }) }) }) diff --git a/x/coinomics/keeper/keeper.go b/x/coinomics/keeper/keeper.go index 0579f8b0..4bb77015 100644 --- a/x/coinomics/keeper/keeper.go +++ b/x/coinomics/keeper/keeper.go @@ -1,6 +1,7 @@ package keeper import ( + sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -61,6 +62,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+types.ModuleName) } -func (k Keeper) TokenSupply(ctx sdk.Context, denom string) sdk.Int { +func (k Keeper) TokenSupply(ctx sdk.Context, denom string) sdkmath.Int { return k.bankKeeper.GetSupply(ctx, denom).Amount } diff --git a/x/coinomics/keeper/keeper_test.go b/x/coinomics/keeper/keeper_test.go index 53601d50..b79a72c0 100644 --- a/x/coinomics/keeper/keeper_test.go +++ b/x/coinomics/keeper/keeper_test.go @@ -84,11 +84,13 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { // setup context app, valAddr1 := app.Setup(false, feemarkettypes.DefaultGenesisState()) + startTime := time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC) + suite.app = app suite.ctx = suite.app.BaseApp.NewContext(false, tmproto.Header{ Height: 1, ChainID: haqqtypes.MainNetChainID + "-1", - Time: time.Now().UTC(), + Time: startTime, ProposerAddress: valAddr1, Version: tmversion.Consensus{ @@ -144,15 +146,49 @@ func (suite *KeeperTestSuite) DoSetupTest(t require.TestingT) { func (suite *KeeperTestSuite) Commit(numBlocks uint64) { for i := uint64(0); i < numBlocks; i++ { - suite.CommitBlock() + suite.CommitBlock(6) + } +} + +func (suite *KeeperTestSuite) CommitWithShift(numBlocks uint64, shift uint64) { + for i := uint64(0); i < numBlocks; i++ { + suite.CommitBlock(shift) } } -func (suite *KeeperTestSuite) CommitBlock() { +func (suite *KeeperTestSuite) CommitBlock(shift uint64) { header := suite.ctx.BlockHeader() _ = suite.app.Commit() header.Height++ + header.Time = header.Time.Add(time.Second * time.Duration(shift)) + + // run begin block + suite.app.BeginBlock(abci.RequestBeginBlock{ + Header: header, + }) + + // run end block + suite.app.EndBlock(abci.RequestEndBlock{ + Height: header.Height, + }) + + // update ctx + suite.ctx = suite.app.BaseApp.NewContext(false, header) + + queryHelper := baseapp.NewQueryServerTestHelper(suite.ctx, suite.app.InterfaceRegistry()) + evm.RegisterQueryServer(queryHelper, suite.app.EvmKeeper) + suite.queryClientEvm = evm.NewQueryClient(queryHelper) +} + +func (suite *KeeperTestSuite) CommitLeapYear() { + header := suite.ctx.BlockHeader() + _ = suite.app.Commit() + + leapYearTime := time.Date(2024, 1, 1, 0, 0, 0, 0, time.UTC) + + header.Height++ + header.Time = leapYearTime // run begin block suite.app.BeginBlock(abci.RequestBeginBlock{ diff --git a/x/coinomics/keeper/mint_info.go b/x/coinomics/keeper/mint_info.go new file mode 100644 index 00000000..0b82d889 --- /dev/null +++ b/x/coinomics/keeper/mint_info.go @@ -0,0 +1,64 @@ +package keeper + +import ( + "fmt" + + sdkmath "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" + + "github.com/haqq-network/haqq/x/coinomics/types" +) + +func (k Keeper) GetPrevBlockTS(ctx sdk.Context) sdkmath.Int { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.KeyPrefixPrevBlockTS) + if len(bz) == 0 { + return sdk.ZeroInt() + } + + var prevBlockTSValue sdkmath.Int + err := prevBlockTSValue.Unmarshal(bz) + if err != nil { + panic(fmt.Errorf("unable to unmarshal prevBlockTSValue value: %w", err)) + } + + return prevBlockTSValue +} + +func (k Keeper) SetPrevBlockTS(ctx sdk.Context, prevBlockTS sdkmath.Int) { + binaryInfValue, err := prevBlockTS.Marshal() + if err != nil { + panic(fmt.Errorf("unable to marshal amount value: %w", err)) + } + + store := ctx.KVStore(k.storeKey) + store.Set(types.KeyPrefixPrevBlockTS, binaryInfValue) +} + +func (k Keeper) GetMaxSupply(ctx sdk.Context) sdk.Coin { + params := k.GetParams(ctx) + + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.KeyPrefixMaxSupply) + if len(bz) == 0 { + return sdk.NewCoin(params.MintDenom, sdk.ZeroInt()) + } + + var maxSupply sdk.Coin + err := maxSupply.Unmarshal(bz) + if err != nil { + panic(fmt.Errorf("unable to unmarshal maxSupply value: %w", err)) + } + + return maxSupply +} + +func (k Keeper) SetMaxSupply(ctx sdk.Context, maxSupply sdk.Coin) { + binaryMaxSupply, err := maxSupply.Marshal() + if err != nil { + panic(fmt.Errorf("unable to marshal amount value: %w", err)) + } + + store := ctx.KVStore(k.storeKey) + store.Set(types.KeyPrefixMaxSupply, binaryMaxSupply) +} diff --git a/x/coinomics/keeper/mint_info_test.go b/x/coinomics/keeper/mint_info_test.go new file mode 100644 index 00000000..6d98a80e --- /dev/null +++ b/x/coinomics/keeper/mint_info_test.go @@ -0,0 +1,84 @@ +package keeper_test + +import ( + "fmt" + + "cosmossdk.io/math" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +func (suite *KeeperTestSuite) TestSetGetPrevBlockTs() { + expEra := math.NewInt(100) + + testCases := []struct { + name string + malleate func() + ok bool + }{ + { + "default prevblockts", + func() {}, + false, + }, + { + "prevblockts set", + func() { + suite.app.CoinomicsKeeper.SetPrevBlockTS(suite.ctx, expEra) + }, + true, + }, + } + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.name), func() { + suite.SetupTest() // reset + + tc.malleate() + + prevBlockTS := suite.app.CoinomicsKeeper.GetPrevBlockTS(suite.ctx) + if tc.ok { + suite.Require().Equal(expEra, prevBlockTS, tc.name) + } else { + suite.Require().Equal(sdk.ZeroInt(), prevBlockTS, tc.name) + } + }) + } +} + +func (suite *KeeperTestSuite) TestSetGetMaxSupply() { + defaultMaxSupply := sdk.Coin{Denom: "aISLM", Amount: math.NewIntWithDecimal(100_000_000_000, 18)} + expMaxSupply := sdk.Coin{Denom: "aISLM", Amount: math.NewIntWithDecimal(1337, 18)} + + testCases := []struct { + name string + malleate func() + ok bool + }{ + { + "default MaxSupply", + func() {}, + false, + }, + { + "MaxSupply set", + func() { + suite.app.CoinomicsKeeper.SetMaxSupply(suite.ctx, expMaxSupply) + }, + true, + }, + } + for _, tc := range testCases { + suite.Run(fmt.Sprintf("Case %s", tc.name), func() { + suite.SetupTest() // reset + + tc.malleate() + + maxSupply := suite.app.CoinomicsKeeper.GetMaxSupply(suite.ctx) + + if tc.ok { + suite.Require().Equal(expMaxSupply, maxSupply, tc.name) + } else { + suite.Require().Equal(defaultMaxSupply, maxSupply, tc.name) + } + }) + } +} diff --git a/x/coinomics/types/genesis.go b/x/coinomics/types/genesis.go index 0e68a16e..5ef89cde 100644 --- a/x/coinomics/types/genesis.go +++ b/x/coinomics/types/genesis.go @@ -9,21 +9,12 @@ import ( func NewGenesisState( params Params, - inflation sdk.Dec, - era uint64, - eraStartedAtBlock uint64, - eraTargetMint sdk.Coin, - eraClosingSupply sdk.Coin, maxSupply sdk.Coin, ) GenesisState { return GenesisState{ - Params: params, - Inflation: inflation, - Era: era, - EraStartedAtBlock: eraStartedAtBlock, - EraTargetMint: eraTargetMint, - EraClosingSupply: eraClosingSupply, - MaxSupply: maxSupply, + Params: params, + PrevBlockTs: math.NewInt(0), + MaxSupply: maxSupply, } } @@ -33,38 +24,14 @@ func DefaultGenesisState() *GenesisState { maxSupply := math.NewIntWithDecimal(100_000_000_000, 18) return &GenesisState{ - Params: params, - Inflation: sdk.NewDec(0), - Era: uint64(0), - EraStartedAtBlock: uint64(0), - EraTargetMint: sdk.NewCoin(params.MintDenom, sdk.NewInt(0)), - EraClosingSupply: sdk.NewCoin(params.MintDenom, sdk.NewInt(0)), - MaxSupply: sdk.NewCoin(params.MintDenom, maxSupply), + Params: params, + PrevBlockTs: math.NewInt(0), + MaxSupply: sdk.NewCoin(params.MintDenom, maxSupply), } } // Validate genesis state func (gs GenesisState) Validate() error { - if err := validateInflationRate(gs.Inflation); err != nil { - return err - } - - if err := validateEraNumber(gs.Era); err != nil { - return err - } - - if err := validateEraStartedAtBlock(gs.EraStartedAtBlock); err != nil { - return err - } - - if err := validateEraTargetMint(gs.EraTargetMint); err != nil { - return err - } - - if err := validateEraClosingSupply(gs.EraClosingSupply); err != nil { - return err - } - if err := validateMaxSupply(gs.MaxSupply); err != nil { return err } @@ -72,64 +39,6 @@ func (gs GenesisState) Validate() error { return gs.Params.Validate() } -func validateInflationRate(i interface{}) error { - _, ok := i.(sdk.Dec) - - if !ok { - return fmt.Errorf("inflation rate: invalid genesis state type: %T", i) - } - - return nil -} - -func validateEraNumber(i interface{}) error { - _, ok := i.(uint64) - - if !ok { - return fmt.Errorf("era number: invalid genesis state type: %T", i) - } - - return nil -} - -func validateEraStartedAtBlock(i interface{}) error { - _, ok := i.(uint64) - - if !ok { - return fmt.Errorf("start era block: invalid genesis state type: %T", i) - } - - return nil -} - -func validateEraTargetMint(i interface{}) error { - targetMint, ok := i.(sdk.Coin) - - if !ok { - return fmt.Errorf("era mint: invalid genesis state type: %T", i) - } - - if targetMint.IsNil() { - return fmt.Errorf("era mint: can't be nil") - } - - return nil -} - -func validateEraClosingSupply(i interface{}) error { - eraTargetSupply, ok := i.(sdk.Coin) - - if !ok { - return fmt.Errorf("era closing supply: invalid genesis state type: %T", i) - } - - if eraTargetSupply.IsNil() { - return fmt.Errorf("era closing supply: can't be nil") - } - - return nil -} - func validateMaxSupply(i interface{}) error { totalTargetSupply, ok := i.(sdk.Coin) diff --git a/x/coinomics/types/genesis.pb.go b/x/coinomics/types/genesis.pb.go index 578b9d9a..de2199d5 100644 --- a/x/coinomics/types/genesis.pb.go +++ b/x/coinomics/types/genesis.pb.go @@ -4,6 +4,7 @@ package types import ( + cosmossdk_io_math "cosmossdk.io/math" fmt "fmt" _ "github.com/cosmos/cosmos-sdk/types" github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types" @@ -29,18 +30,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type GenesisState struct { // params defines all the paramaters of the module. Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` - // current inflation rate - Inflation github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=inflation,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation"` - // current era number - Era uint64 `protobuf:"varint,3,opt,name=era,proto3" json:"era,omitempty"` - // era started block number - EraStartedAtBlock uint64 `protobuf:"varint,4,opt,name=era_started_at_block,json=eraStartedAtBlock,proto3" json:"era_started_at_block,omitempty"` - // target mint for current era - EraTargetMint github_com_cosmos_cosmos_sdk_types.Coin `protobuf:"bytes,5,opt,name=era_target_mint,json=eraTargetMint,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"era_target_mint" yaml:"era_target_mint"` - // closing supply for current era - EraClosingSupply github_com_cosmos_cosmos_sdk_types.Coin `protobuf:"bytes,6,opt,name=era_closing_supply,json=eraClosingSupply,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"era_closing_supply" yaml:"era_closing_supply"` + // prev block block ts + PrevBlockTs cosmossdk_io_math.Int `protobuf:"bytes,2,opt,name=prev_block_ts,json=prevBlockTs,proto3,customtype=cosmossdk.io/math.Int" json:"prev_block_ts"` // max supply - MaxSupply github_com_cosmos_cosmos_sdk_types.Coin `protobuf:"bytes,7,opt,name=max_supply,json=maxSupply,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"max_supply" yaml:"max_supply"` + MaxSupply github_com_cosmos_cosmos_sdk_types.Coin `protobuf:"bytes,3,opt,name=max_supply,json=maxSupply,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"max_supply" yaml:"max_supply"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -83,28 +76,14 @@ func (m *GenesisState) GetParams() Params { return Params{} } -func (m *GenesisState) GetEra() uint64 { - if m != nil { - return m.Era - } - return 0 -} - -func (m *GenesisState) GetEraStartedAtBlock() uint64 { - if m != nil { - return m.EraStartedAtBlock - } - return 0 -} - // Params holds parameters for the coinomics module. type Params struct { // type of coin to mint MintDenom string `protobuf:"bytes,1,opt,name=mint_denom,json=mintDenom,proto3" json:"mint_denom,omitempty"` - // number of blocks per era - BlocksPerEra uint64 `protobuf:"varint,2,opt,name=blocks_per_era,json=blocksPerEra,proto3" json:"blocks_per_era,omitempty"` // parameter to enable coinmoics - EnableCoinomics bool `protobuf:"varint,3,opt,name=enable_coinomics,json=enableCoinomics,proto3" json:"enable_coinomics,omitempty"` + EnableCoinomics bool `protobuf:"varint,2,opt,name=enable_coinomics,json=enableCoinomics,proto3" json:"enable_coinomics,omitempty"` + // current staking reward coefficient + RewardCoefficient github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,3,opt,name=reward_coefficient,json=rewardCoefficient,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_coefficient"` } func (m *Params) Reset() { *m = Params{} } @@ -147,13 +126,6 @@ func (m *Params) GetMintDenom() string { return "" } -func (m *Params) GetBlocksPerEra() uint64 { - if m != nil { - return m.BlocksPerEra - } - return 0 -} - func (m *Params) GetEnableCoinomics() bool { if m != nil { return m.EnableCoinomics @@ -169,40 +141,34 @@ func init() { func init() { proto.RegisterFile("haqq/coinomics/v1/genesis.proto", fileDescriptor_228a4e7fa0b804ae) } var fileDescriptor_228a4e7fa0b804ae = []byte{ - // 521 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x53, 0x41, 0x6f, 0xd3, 0x30, - 0x18, 0x6d, 0xb6, 0x52, 0xa8, 0x19, 0xac, 0xb5, 0x26, 0x94, 0x4d, 0x22, 0xad, 0x22, 0x04, 0xe5, - 0x30, 0x47, 0x85, 0x03, 0x12, 0x37, 0xda, 0x22, 0x40, 0x1a, 0xd2, 0x94, 0x72, 0xe2, 0x12, 0x39, - 0xe9, 0x47, 0x16, 0x35, 0xb1, 0x33, 0xdb, 0x2b, 0xed, 0x85, 0x5f, 0xc0, 0x81, 0x0b, 0xff, 0x69, - 0xc7, 0x1d, 0x11, 0x87, 0x0a, 0xb5, 0xff, 0x80, 0x3f, 0x00, 0xb2, 0xdd, 0xad, 0x03, 0x0e, 0x63, - 0xa7, 0x38, 0xef, 0x7b, 0xf6, 0x7b, 0xdf, 0xe7, 0x67, 0xd4, 0x3a, 0xa2, 0xc7, 0xc7, 0x41, 0xc2, - 0x33, 0xc6, 0x8b, 0x2c, 0x91, 0xc1, 0xa4, 0x1b, 0xa4, 0xc0, 0x40, 0x66, 0x92, 0x94, 0x82, 0x2b, - 0x8e, 0x9b, 0x9a, 0x40, 0x2e, 0x08, 0x64, 0xd2, 0xdd, 0xdb, 0x49, 0x79, 0xca, 0x4d, 0x35, 0xd0, - 0x2b, 0x4b, 0xdc, 0xf3, 0x12, 0x2e, 0x0b, 0x2e, 0x83, 0x98, 0x4a, 0x08, 0x26, 0xdd, 0x18, 0x14, - 0xed, 0x9a, 0x83, 0x6d, 0xdd, 0xff, 0x55, 0x45, 0x5b, 0xaf, 0xec, 0xd1, 0x43, 0x45, 0x15, 0xe0, - 0x67, 0xa8, 0x56, 0x52, 0x41, 0x0b, 0xe9, 0x3a, 0x6d, 0xa7, 0x73, 0xfb, 0xc9, 0x2e, 0xf9, 0x47, - 0x8a, 0x1c, 0x1a, 0x42, 0xaf, 0x7a, 0x3a, 0x6f, 0x55, 0xc2, 0x15, 0x1d, 0x1f, 0xa0, 0x7a, 0xc6, - 0x3e, 0xe4, 0x54, 0x65, 0x9c, 0xb9, 0x1b, 0x6d, 0xa7, 0x53, 0xef, 0x11, 0x4d, 0xf8, 0x3e, 0x6f, - 0x3d, 0x4c, 0x33, 0x75, 0x74, 0x12, 0x93, 0x84, 0x17, 0xc1, 0xca, 0x8f, 0xfd, 0xec, 0xcb, 0xd1, - 0x38, 0x50, 0xb3, 0x12, 0x24, 0x19, 0x40, 0x12, 0xae, 0x0f, 0xc0, 0x0d, 0xb4, 0x09, 0x82, 0xba, - 0x9b, 0x6d, 0xa7, 0x53, 0x0d, 0xf5, 0x12, 0x07, 0x68, 0x07, 0x04, 0x8d, 0xa4, 0xa2, 0x42, 0xc1, - 0x28, 0xa2, 0x2a, 0x8a, 0x73, 0x9e, 0x8c, 0xdd, 0xaa, 0xa1, 0x34, 0x41, 0xd0, 0xa1, 0x2d, 0xbd, - 0x50, 0x3d, 0x5d, 0xc0, 0x9f, 0x1d, 0xb4, 0xad, 0x77, 0x28, 0x2a, 0x52, 0x50, 0x51, 0x91, 0x31, - 0xe5, 0xde, 0x58, 0xf5, 0x64, 0xe5, 0x89, 0x9e, 0x0a, 0x59, 0x4d, 0x85, 0xf4, 0x79, 0xc6, 0x7a, - 0x6f, 0x56, 0x96, 0x1f, 0xfd, 0x87, 0x65, 0xbd, 0xe1, 0xe7, 0xbc, 0x75, 0x6f, 0x46, 0x8b, 0xfc, - 0xb9, 0xff, 0x97, 0x94, 0x1f, 0xde, 0x01, 0x41, 0xdf, 0x19, 0xe0, 0x6d, 0xc6, 0x14, 0xfe, 0xea, - 0x20, 0xac, 0x39, 0x49, 0xce, 0x65, 0xc6, 0xd2, 0x48, 0x9e, 0x94, 0x65, 0x3e, 0x73, 0x6b, 0x57, - 0x39, 0x3a, 0xb8, 0xbe, 0xa3, 0xdd, 0xb5, 0xa3, 0x3f, 0xd5, 0xfc, 0xb0, 0x01, 0x82, 0xf6, 0x2d, - 0x36, 0x34, 0x10, 0xfe, 0x84, 0x50, 0x41, 0xa7, 0xe7, 0x76, 0x6e, 0x5e, 0x65, 0x67, 0x70, 0x7d, - 0x3b, 0x4d, 0x6b, 0x67, 0xad, 0xe2, 0x87, 0xf5, 0x82, 0x4e, 0xad, 0xbe, 0x3f, 0x45, 0x35, 0x9b, - 0x27, 0x7c, 0x1f, 0x21, 0x3d, 0xb9, 0x68, 0x04, 0x8c, 0x17, 0x26, 0x7e, 0xf5, 0xb0, 0xae, 0x91, - 0x81, 0x06, 0xf0, 0x03, 0x74, 0xd7, 0xdc, 0xb8, 0x8c, 0x4a, 0x10, 0x91, 0x4e, 0xc7, 0x86, 0xb9, - 0xfa, 0x2d, 0x8b, 0x1e, 0x82, 0x78, 0x29, 0x28, 0x7e, 0x8c, 0x1a, 0xc0, 0x68, 0x9c, 0x43, 0x74, - 0x11, 0x59, 0x93, 0xa2, 0x5b, 0xe1, 0xb6, 0xc5, 0xfb, 0xe7, 0x70, 0xef, 0xf5, 0xe9, 0xc2, 0x73, - 0xce, 0x16, 0x9e, 0xf3, 0x63, 0xe1, 0x39, 0x5f, 0x96, 0x5e, 0xe5, 0x6c, 0xe9, 0x55, 0xbe, 0x2d, - 0xbd, 0xca, 0x7b, 0x72, 0xa9, 0x39, 0x1d, 0xff, 0x7d, 0x06, 0xea, 0x23, 0x17, 0x63, 0xf3, 0x13, - 0x4c, 0x2f, 0xbd, 0x4c, 0xd3, 0x68, 0x5c, 0x33, 0x8f, 0xe9, 0xe9, 0xef, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xe0, 0x2f, 0x83, 0x10, 0xb8, 0x03, 0x00, 0x00, + // 432 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x92, 0xcf, 0x6e, 0xd3, 0x30, + 0x1c, 0xc7, 0x9b, 0x81, 0x2a, 0xe2, 0x81, 0xa0, 0x16, 0x48, 0x65, 0xd2, 0xd2, 0xa9, 0x07, 0x18, + 0x87, 0xd9, 0x0a, 0x1c, 0x90, 0xb8, 0x91, 0x56, 0x02, 0x6e, 0x28, 0xe3, 0x84, 0x84, 0x22, 0xc7, + 0xf1, 0x52, 0x2b, 0xb1, 0x9d, 0xc5, 0x5e, 0xd6, 0x5e, 0x78, 0x00, 0x4e, 0xbc, 0x0a, 0x6f, 0xb1, + 0xe3, 0x8e, 0x88, 0x43, 0x85, 0xda, 0x37, 0xe0, 0x09, 0x90, 0xed, 0xb0, 0x4d, 0xe2, 0xb2, 0x53, + 0x9c, 0x9f, 0xbf, 0x7f, 0xf2, 0x71, 0x0c, 0x26, 0x0b, 0x72, 0x7a, 0x8a, 0xa9, 0xe2, 0x52, 0x09, + 0x4e, 0x35, 0xee, 0x62, 0x5c, 0x32, 0xc9, 0x34, 0xd7, 0xa8, 0x69, 0x95, 0x51, 0x70, 0x64, 0x05, + 0xe8, 0x4a, 0x80, 0xba, 0x78, 0xef, 0x71, 0xa9, 0x4a, 0xe5, 0x76, 0xb1, 0x5d, 0x79, 0xe1, 0x5e, + 0x44, 0x95, 0x16, 0x4a, 0xe3, 0x9c, 0x68, 0x86, 0xbb, 0x38, 0x67, 0x86, 0xc4, 0x2e, 0xd8, 0xef, + 0x4f, 0xbf, 0xed, 0x80, 0xfb, 0xef, 0x7c, 0xf4, 0xb1, 0x21, 0x86, 0xc1, 0xd7, 0x60, 0xd8, 0x90, + 0x96, 0x08, 0x3d, 0x0e, 0x0e, 0x82, 0xc3, 0xdd, 0x97, 0x4f, 0xd1, 0x7f, 0x55, 0xe8, 0xa3, 0x13, + 0x24, 0x77, 0x2f, 0xd6, 0x93, 0x41, 0xda, 0xcb, 0xe1, 0x5b, 0xf0, 0xa0, 0x69, 0x59, 0x97, 0xe5, + 0xb5, 0xa2, 0x55, 0x66, 0xf4, 0x78, 0xe7, 0x20, 0x38, 0x0c, 0x93, 0x7d, 0x2b, 0xfa, 0xb5, 0x9e, + 0x3c, 0xf1, 0x1f, 0xa2, 0x8b, 0x0a, 0x71, 0x85, 0x05, 0x31, 0x0b, 0xf4, 0x41, 0x9a, 0x74, 0xd7, + 0x7a, 0x12, 0x6b, 0xf9, 0xa4, 0xe1, 0x57, 0x00, 0x04, 0x59, 0x66, 0xfa, 0xac, 0x69, 0xea, 0xd5, + 0xf8, 0x4e, 0xdf, 0xef, 0x8d, 0xc8, 0x12, 0xa0, 0x9e, 0x00, 0xcd, 0x14, 0x97, 0xc9, 0xbc, 0x8f, + 0x7e, 0x5e, 0x72, 0xb3, 0x38, 0xcb, 0x11, 0x55, 0x02, 0xf7, 0xb8, 0xfe, 0x71, 0xa4, 0x8b, 0x0a, + 0x9b, 0x55, 0xc3, 0xb4, 0x33, 0xfc, 0x59, 0x4f, 0x46, 0x2b, 0x22, 0xea, 0x37, 0xd3, 0xeb, 0x96, + 0x69, 0x1a, 0x0a, 0xb2, 0x3c, 0xf6, 0xeb, 0x1f, 0x01, 0x18, 0x7a, 0x36, 0xb8, 0x0f, 0x80, 0xe0, + 0xd2, 0x64, 0x05, 0x93, 0x4a, 0xb8, 0xa3, 0x08, 0xd3, 0xd0, 0x4e, 0xe6, 0x76, 0x00, 0x5f, 0x80, + 0x47, 0x4c, 0x92, 0xbc, 0x66, 0xd9, 0xd5, 0xc1, 0x38, 0xde, 0x7b, 0xe9, 0x43, 0x3f, 0x9f, 0xfd, + 0x1b, 0xc3, 0x2f, 0x00, 0xb6, 0xec, 0x9c, 0xb4, 0x45, 0x46, 0x15, 0x3b, 0x39, 0xe1, 0x94, 0x33, + 0x69, 0x1c, 0x5c, 0x98, 0xa0, 0x9e, 0xe0, 0xd9, 0x2d, 0x08, 0xe6, 0x8c, 0xa6, 0x23, 0x9f, 0x34, + 0xbb, 0x0e, 0x4a, 0xde, 0x5f, 0x6c, 0xa2, 0xe0, 0x72, 0x13, 0x05, 0xbf, 0x37, 0x51, 0xf0, 0x7d, + 0x1b, 0x0d, 0x2e, 0xb7, 0xd1, 0xe0, 0xe7, 0x36, 0x1a, 0x7c, 0x46, 0x37, 0x42, 0xed, 0x3f, 0x3c, + 0x92, 0xcc, 0x9c, 0xab, 0xb6, 0x72, 0x2f, 0x78, 0x79, 0xe3, 0x7a, 0xb9, 0x82, 0x7c, 0xe8, 0x6e, + 0xc4, 0xab, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xed, 0xce, 0x2b, 0x7d, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -234,41 +200,11 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x3a - { - size := m.EraClosingSupply.Size() - i -= size - if _, err := m.EraClosingSupply.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x32 + dAtA[i] = 0x1a { - size := m.EraTargetMint.Size() + size := m.PrevBlockTs.Size() i -= size - if _, err := m.EraTargetMint.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintGenesis(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0x2a - if m.EraStartedAtBlock != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.EraStartedAtBlock)) - i-- - dAtA[i] = 0x20 - } - if m.Era != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.Era)) - i-- - dAtA[i] = 0x18 - } - { - size := m.Inflation.Size() - i -= size - if _, err := m.Inflation.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.PrevBlockTs.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintGenesis(dAtA, i, uint64(size)) @@ -308,6 +244,16 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + { + size := m.RewardCoefficient.Size() + i -= size + if _, err := m.RewardCoefficient.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a if m.EnableCoinomics { i-- if m.EnableCoinomics { @@ -316,11 +262,6 @@ func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0 } i-- - dAtA[i] = 0x18 - } - if m.BlocksPerEra != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.BlocksPerEra)) - i-- dAtA[i] = 0x10 } if len(m.MintDenom) > 0 { @@ -352,17 +293,7 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) - l = m.Inflation.Size() - n += 1 + l + sovGenesis(uint64(l)) - if m.Era != 0 { - n += 1 + sovGenesis(uint64(m.Era)) - } - if m.EraStartedAtBlock != 0 { - n += 1 + sovGenesis(uint64(m.EraStartedAtBlock)) - } - l = m.EraTargetMint.Size() - n += 1 + l + sovGenesis(uint64(l)) - l = m.EraClosingSupply.Size() + l = m.PrevBlockTs.Size() n += 1 + l + sovGenesis(uint64(l)) l = m.MaxSupply.Size() n += 1 + l + sovGenesis(uint64(l)) @@ -379,12 +310,11 @@ func (m *Params) Size() (n int) { if l > 0 { n += 1 + l + sovGenesis(uint64(l)) } - if m.BlocksPerEra != 0 { - n += 1 + sovGenesis(uint64(m.BlocksPerEra)) - } if m.EnableCoinomics { n += 2 } + l = m.RewardCoefficient.Size() + n += 1 + l + sovGenesis(uint64(l)) return n } @@ -458,7 +388,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Inflation", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field PrevBlockTs", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -486,115 +416,11 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.Inflation.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.PrevBlockTs.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Era", wireType) - } - m.Era = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Era |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EraStartedAtBlock", wireType) - } - m.EraStartedAtBlock = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.EraStartedAtBlock |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 5: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EraTargetMint", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.EraTargetMint.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EraClosingSupply", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.EraClosingSupply.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field MaxSupply", wireType) } @@ -711,9 +537,9 @@ func (m *Params) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 2: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BlocksPerEra", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field EnableCoinomics", wireType) } - m.BlocksPerEra = 0 + var v int for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -723,16 +549,17 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.BlocksPerEra |= uint64(b&0x7F) << shift + v |= int(b&0x7F) << shift if b < 0x80 { break } } + m.EnableCoinomics = bool(v != 0) case 3: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field EnableCoinomics", wireType) + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RewardCoefficient", wireType) } - var v int + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowGenesis @@ -742,12 +569,26 @@ func (m *Params) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } - m.EnableCoinomics = bool(v != 0) + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.RewardCoefficient.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/coinomics/types/genesis_test.go b/x/coinomics/types/genesis_test.go index 0f0e198f..4df7337e 100644 --- a/x/coinomics/types/genesis_test.go +++ b/x/coinomics/types/genesis_test.go @@ -25,11 +25,6 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { newGen := NewGenesisState( validParams, - sdk.NewDec(100), - 1, - 100, - sdk.NewCoin("aISLM", sdk.NewInt(10_000_000)), - sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_0)), sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_000)), ) @@ -56,13 +51,8 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { { "valid genesis", &GenesisState{ - Params: validParams, - Inflation: sdk.NewDec(100), - Era: 1, - EraStartedAtBlock: 100, - EraTargetMint: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000)), - EraClosingSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_00)), - MaxSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_000)), + Params: validParams, + MaxSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_000)), }, true, }, @@ -73,39 +63,11 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { }, false, }, - { - "invalid genesis - EraTargetMint is nil", - &GenesisState{ - Params: validParams, - Inflation: sdk.NewDec(100), - Era: 1, - EraStartedAtBlock: 100, - EraClosingSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_00)), - MaxSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_000)), - }, - false, - }, - { - "invalid genesis - EraClosingSupply is nil", - &GenesisState{ - Params: validParams, - Inflation: sdk.NewDec(100), - Era: 1, - EraStartedAtBlock: 100, - EraTargetMint: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000)), - MaxSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_000)), - }, - false, - }, { "invalid genesis - MaxSupply is nil", &GenesisState{ - Params: validParams, - Inflation: sdk.NewDec(100), - Era: 1, - EraStartedAtBlock: 100, - EraTargetMint: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000)), - MaxSupply: sdk.NewCoin("aISLM", sdk.NewInt(10_000_000_00)), + Params: validParams, + MaxSupply: sdk.Coin{}, }, false, }, @@ -114,6 +76,7 @@ func (suite *GenesisTestSuite) TestValidateGenesis() { for _, tc := range testCases { tc := tc err := tc.genState.Validate() + if tc.expPass { suite.Require().NoError(err, tc.name) } else { diff --git a/x/coinomics/types/interfaces.go b/x/coinomics/types/interfaces.go index f53c3af0..c27401d0 100644 --- a/x/coinomics/types/interfaces.go +++ b/x/coinomics/types/interfaces.go @@ -1,6 +1,7 @@ package types // noalias import ( + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/auth/types" ) @@ -35,6 +36,6 @@ type DistrKeeper interface { type StakingKeeper interface { // BondedRatio the fraction of the staking tokens which are currently bonded BondedRatio(ctx sdk.Context) sdk.Dec - StakingTokenSupply(ctx sdk.Context) sdk.Int - TotalBondedTokens(ctx sdk.Context) sdk.Int + StakingTokenSupply(ctx sdk.Context) sdkmath.Int + TotalBondedTokens(ctx sdk.Context) sdkmath.Int } diff --git a/x/coinomics/types/keys.go b/x/coinomics/types/keys.go index 2620578e..67ee8747 100644 --- a/x/coinomics/types/keys.go +++ b/x/coinomics/types/keys.go @@ -16,20 +16,12 @@ const ( // prefix bytes for the inflation persistent store const ( - prefixInflation = iota + 1 - prefixEra - prefixEraStartedAtBlock - prefixEraTargetMint - prefixEraClosingSupply + prefixPrevBlockTS = iota + 1 prefixMaxSupply ) // KVStore key prefixes var ( - KeyPrefixInflation = []byte{prefixInflation} - KeyPrefixEra = []byte{prefixEra} - KeyPrefixEraStartedAtBlock = []byte{prefixEraStartedAtBlock} - KetPrefixEraTargetMint = []byte{prefixEraTargetMint} - KeyPrefixEraClosingSupply = []byte{prefixEraClosingSupply} - KeyPrefixMaxSupply = []byte{prefixMaxSupply} + KeyPrefixPrevBlockTS = []byte{prefixPrevBlockTS} + KeyPrefixMaxSupply = []byte{prefixMaxSupply} ) diff --git a/x/coinomics/types/params.go b/x/coinomics/types/params.go index 16a8742c..c1ccf221 100644 --- a/x/coinomics/types/params.go +++ b/x/coinomics/types/params.go @@ -3,7 +3,6 @@ package types import ( "errors" "fmt" - "math" "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -14,9 +13,9 @@ var DefaultMintDenom = "aISLM" // Parameter store keys var ( - ParamStoreKeyMintDenom = []byte("ParamStoreKeyMintDenom") - ParamStoreKeyBlockPerEra = []byte("ParamStoreKeyBlockPerEra") - ParamStoreKeyEnableCoinomics = []byte("ParamStoreKeyEnableCoinomics") + ParamStoreKeyMintDenom = []byte("ParamStoreKeyMintDenom") + ParamStoreKeyEnableCoinomics = []byte("ParamStoreKeyEnableCoinomics") + ParamStoreKeyRewardCoefficient = []byte("ParamStoreKeyRewardCoefficient") ) func ParamKeyTable() paramtypes.KeyTable { @@ -25,21 +24,21 @@ func ParamKeyTable() paramtypes.KeyTable { func NewParams( mintDenom string, - blockPerEra uint64, + rewardsCoefficient sdk.Dec, enableCoinomics bool, ) Params { return Params{ - MintDenom: mintDenom, - BlocksPerEra: blockPerEra, - EnableCoinomics: enableCoinomics, + MintDenom: mintDenom, + RewardCoefficient: rewardsCoefficient, + EnableCoinomics: enableCoinomics, } } func DefaultParams() Params { return Params{ - MintDenom: DefaultMintDenom, - BlocksPerEra: 5259600 * 2, // 2 years - EnableCoinomics: true, + MintDenom: DefaultMintDenom, + RewardCoefficient: sdk.NewDecWithPrec(78, 1), + EnableCoinomics: true, } } @@ -47,7 +46,7 @@ func DefaultParams() Params { func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { return paramtypes.ParamSetPairs{ paramtypes.NewParamSetPair(ParamStoreKeyMintDenom, &p.MintDenom, validateMintDenom), - paramtypes.NewParamSetPair(ParamStoreKeyBlockPerEra, &p.BlocksPerEra, validateBlockPerEra), + paramtypes.NewParamSetPair(ParamStoreKeyRewardCoefficient, &p.RewardCoefficient, validateRewardCoefficient), paramtypes.NewParamSetPair(ParamStoreKeyEnableCoinomics, &p.EnableCoinomics, validateBool), } } @@ -65,22 +64,13 @@ func validateMintDenom(i interface{}) error { return sdk.ValidateDenom(v) } -func validateBlockPerEra(i interface{}) error { - v, ok := i.(uint64) +func validateRewardCoefficient(i interface{}) error { + _, ok := i.(sdk.Dec) if !ok { return fmt.Errorf("invalid parameter type: %T", i) } - // Check if BlocksPerEra is within the uint64 range - if v > math.MaxUint64 { - return errors.New("BlocksPerEra is out of uint64 range") - } - - if v == 0 { - return errors.New("block per era must not be zero") - } - return nil } @@ -97,7 +87,7 @@ func (p Params) Validate() error { if err := validateMintDenom(p.MintDenom); err != nil { return err } - if err := validateBlockPerEra(p.BlocksPerEra); err != nil { + if err := validateRewardCoefficient(p.RewardCoefficient); err != nil { return err } diff --git a/x/coinomics/types/query.pb.go b/x/coinomics/types/query.pb.go index 4c0d1928..4eae826f 100644 --- a/x/coinomics/types/query.pb.go +++ b/x/coinomics/types/query.pb.go @@ -31,159 +31,6 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package -type QueryEraRequest struct { -} - -func (m *QueryEraRequest) Reset() { *m = QueryEraRequest{} } -func (m *QueryEraRequest) String() string { return proto.CompactTextString(m) } -func (*QueryEraRequest) ProtoMessage() {} -func (*QueryEraRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{0} -} -func (m *QueryEraRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryEraRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryEraRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryEraRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryEraRequest.Merge(m, src) -} -func (m *QueryEraRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryEraRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryEraRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryEraRequest proto.InternalMessageInfo - -type QueryEraResponse struct { - Era uint64 `protobuf:"varint,1,opt,name=era,proto3" json:"era,omitempty"` -} - -func (m *QueryEraResponse) Reset() { *m = QueryEraResponse{} } -func (m *QueryEraResponse) String() string { return proto.CompactTextString(m) } -func (*QueryEraResponse) ProtoMessage() {} -func (*QueryEraResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{1} -} -func (m *QueryEraResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryEraResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryEraResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryEraResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryEraResponse.Merge(m, src) -} -func (m *QueryEraResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryEraResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryEraResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryEraResponse proto.InternalMessageInfo - -func (m *QueryEraResponse) GetEra() uint64 { - if m != nil { - return m.Era - } - return 0 -} - -type QueryEraClosingSupplyRequest struct { -} - -func (m *QueryEraClosingSupplyRequest) Reset() { *m = QueryEraClosingSupplyRequest{} } -func (m *QueryEraClosingSupplyRequest) String() string { return proto.CompactTextString(m) } -func (*QueryEraClosingSupplyRequest) ProtoMessage() {} -func (*QueryEraClosingSupplyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{2} -} -func (m *QueryEraClosingSupplyRequest) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryEraClosingSupplyRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryEraClosingSupplyRequest.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryEraClosingSupplyRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryEraClosingSupplyRequest.Merge(m, src) -} -func (m *QueryEraClosingSupplyRequest) XXX_Size() int { - return m.Size() -} -func (m *QueryEraClosingSupplyRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryEraClosingSupplyRequest.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryEraClosingSupplyRequest proto.InternalMessageInfo - -type QueryEraClosingSupplyResponse struct { - EraClosingSupply github_com_cosmos_cosmos_sdk_types.Coin `protobuf:"bytes,1,opt,name=era_closing_supply,json=eraClosingSupply,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Coin" json:"era_closing_supply"` -} - -func (m *QueryEraClosingSupplyResponse) Reset() { *m = QueryEraClosingSupplyResponse{} } -func (m *QueryEraClosingSupplyResponse) String() string { return proto.CompactTextString(m) } -func (*QueryEraClosingSupplyResponse) ProtoMessage() {} -func (*QueryEraClosingSupplyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{3} -} -func (m *QueryEraClosingSupplyResponse) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *QueryEraClosingSupplyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_QueryEraClosingSupplyResponse.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *QueryEraClosingSupplyResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryEraClosingSupplyResponse.Merge(m, src) -} -func (m *QueryEraClosingSupplyResponse) XXX_Size() int { - return m.Size() -} -func (m *QueryEraClosingSupplyResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryEraClosingSupplyResponse.DiscardUnknown(m) -} - -var xxx_messageInfo_QueryEraClosingSupplyResponse proto.InternalMessageInfo - type QueryMaxSupplyRequest struct { } @@ -191,7 +38,7 @@ func (m *QueryMaxSupplyRequest) Reset() { *m = QueryMaxSupplyRequest{} } func (m *QueryMaxSupplyRequest) String() string { return proto.CompactTextString(m) } func (*QueryMaxSupplyRequest) ProtoMessage() {} func (*QueryMaxSupplyRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{4} + return fileDescriptor_bccdbe1913fce8f0, []int{0} } func (m *QueryMaxSupplyRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -228,7 +75,7 @@ func (m *QueryMaxSupplyResponse) Reset() { *m = QueryMaxSupplyResponse{} func (m *QueryMaxSupplyResponse) String() string { return proto.CompactTextString(m) } func (*QueryMaxSupplyResponse) ProtoMessage() {} func (*QueryMaxSupplyResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{5} + return fileDescriptor_bccdbe1913fce8f0, []int{1} } func (m *QueryMaxSupplyResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -257,21 +104,21 @@ func (m *QueryMaxSupplyResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryMaxSupplyResponse proto.InternalMessageInfo -type QueryInflationRateRequest struct { +type QueryRewardCoefficientRequest struct { } -func (m *QueryInflationRateRequest) Reset() { *m = QueryInflationRateRequest{} } -func (m *QueryInflationRateRequest) String() string { return proto.CompactTextString(m) } -func (*QueryInflationRateRequest) ProtoMessage() {} -func (*QueryInflationRateRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{6} +func (m *QueryRewardCoefficientRequest) Reset() { *m = QueryRewardCoefficientRequest{} } +func (m *QueryRewardCoefficientRequest) String() string { return proto.CompactTextString(m) } +func (*QueryRewardCoefficientRequest) ProtoMessage() {} +func (*QueryRewardCoefficientRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_bccdbe1913fce8f0, []int{2} } -func (m *QueryInflationRateRequest) XXX_Unmarshal(b []byte) error { +func (m *QueryRewardCoefficientRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryInflationRateRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryRewardCoefficientRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryInflationRateRequest.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryRewardCoefficientRequest.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -281,35 +128,35 @@ func (m *QueryInflationRateRequest) XXX_Marshal(b []byte, deterministic bool) ([ return b[:n], nil } } -func (m *QueryInflationRateRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryInflationRateRequest.Merge(m, src) +func (m *QueryRewardCoefficientRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRewardCoefficientRequest.Merge(m, src) } -func (m *QueryInflationRateRequest) XXX_Size() int { +func (m *QueryRewardCoefficientRequest) XXX_Size() int { return m.Size() } -func (m *QueryInflationRateRequest) XXX_DiscardUnknown() { - xxx_messageInfo_QueryInflationRateRequest.DiscardUnknown(m) +func (m *QueryRewardCoefficientRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRewardCoefficientRequest.DiscardUnknown(m) } -var xxx_messageInfo_QueryInflationRateRequest proto.InternalMessageInfo +var xxx_messageInfo_QueryRewardCoefficientRequest proto.InternalMessageInfo -type QueryInflationRateResponse struct { +type QueryRewardCoefficientResponse struct { // rate by which the total supply increases within one era - InflationRate github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=inflation_rate,json=inflationRate,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"inflation_rate"` + RewardCoefficient github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=reward_coefficient,json=rewardCoefficient,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"reward_coefficient"` } -func (m *QueryInflationRateResponse) Reset() { *m = QueryInflationRateResponse{} } -func (m *QueryInflationRateResponse) String() string { return proto.CompactTextString(m) } -func (*QueryInflationRateResponse) ProtoMessage() {} -func (*QueryInflationRateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{7} +func (m *QueryRewardCoefficientResponse) Reset() { *m = QueryRewardCoefficientResponse{} } +func (m *QueryRewardCoefficientResponse) String() string { return proto.CompactTextString(m) } +func (*QueryRewardCoefficientResponse) ProtoMessage() {} +func (*QueryRewardCoefficientResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_bccdbe1913fce8f0, []int{3} } -func (m *QueryInflationRateResponse) XXX_Unmarshal(b []byte) error { +func (m *QueryRewardCoefficientResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) } -func (m *QueryInflationRateResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { +func (m *QueryRewardCoefficientResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { if deterministic { - return xxx_messageInfo_QueryInflationRateResponse.Marshal(b, m, deterministic) + return xxx_messageInfo_QueryRewardCoefficientResponse.Marshal(b, m, deterministic) } else { b = b[:cap(b)] n, err := m.MarshalToSizedBuffer(b) @@ -319,17 +166,17 @@ func (m *QueryInflationRateResponse) XXX_Marshal(b []byte, deterministic bool) ( return b[:n], nil } } -func (m *QueryInflationRateResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_QueryInflationRateResponse.Merge(m, src) +func (m *QueryRewardCoefficientResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryRewardCoefficientResponse.Merge(m, src) } -func (m *QueryInflationRateResponse) XXX_Size() int { +func (m *QueryRewardCoefficientResponse) XXX_Size() int { return m.Size() } -func (m *QueryInflationRateResponse) XXX_DiscardUnknown() { - xxx_messageInfo_QueryInflationRateResponse.DiscardUnknown(m) +func (m *QueryRewardCoefficientResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryRewardCoefficientResponse.DiscardUnknown(m) } -var xxx_messageInfo_QueryInflationRateResponse proto.InternalMessageInfo +var xxx_messageInfo_QueryRewardCoefficientResponse proto.InternalMessageInfo type QueryParamsRequest struct { } @@ -338,7 +185,7 @@ func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } func (*QueryParamsRequest) ProtoMessage() {} func (*QueryParamsRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{8} + return fileDescriptor_bccdbe1913fce8f0, []int{4} } func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -376,7 +223,7 @@ func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } func (*QueryParamsResponse) ProtoMessage() {} func (*QueryParamsResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_bccdbe1913fce8f0, []int{9} + return fileDescriptor_bccdbe1913fce8f0, []int{5} } func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -413,14 +260,10 @@ func (m *QueryParamsResponse) GetParams() Params { } func init() { - proto.RegisterType((*QueryEraRequest)(nil), "haqq.coinomics.v1.QueryEraRequest") - proto.RegisterType((*QueryEraResponse)(nil), "haqq.coinomics.v1.QueryEraResponse") - proto.RegisterType((*QueryEraClosingSupplyRequest)(nil), "haqq.coinomics.v1.QueryEraClosingSupplyRequest") - proto.RegisterType((*QueryEraClosingSupplyResponse)(nil), "haqq.coinomics.v1.QueryEraClosingSupplyResponse") proto.RegisterType((*QueryMaxSupplyRequest)(nil), "haqq.coinomics.v1.QueryMaxSupplyRequest") proto.RegisterType((*QueryMaxSupplyResponse)(nil), "haqq.coinomics.v1.QueryMaxSupplyResponse") - proto.RegisterType((*QueryInflationRateRequest)(nil), "haqq.coinomics.v1.QueryInflationRateRequest") - proto.RegisterType((*QueryInflationRateResponse)(nil), "haqq.coinomics.v1.QueryInflationRateResponse") + proto.RegisterType((*QueryRewardCoefficientRequest)(nil), "haqq.coinomics.v1.QueryRewardCoefficientRequest") + proto.RegisterType((*QueryRewardCoefficientResponse)(nil), "haqq.coinomics.v1.QueryRewardCoefficientResponse") proto.RegisterType((*QueryParamsRequest)(nil), "haqq.coinomics.v1.QueryParamsRequest") proto.RegisterType((*QueryParamsResponse)(nil), "haqq.coinomics.v1.QueryParamsResponse") } @@ -428,46 +271,39 @@ func init() { func init() { proto.RegisterFile("haqq/coinomics/v1/query.proto", fileDescriptor_bccdbe1913fce8f0) } var fileDescriptor_bccdbe1913fce8f0 = []byte{ - // 622 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0x63, 0xda, 0x46, 0xca, 0xa1, 0x42, 0x7a, 0x14, 0x4a, 0xdc, 0xd6, 0x69, 0x5d, 0x08, - 0xa9, 0x44, 0xee, 0x48, 0x19, 0xd8, 0x53, 0x2a, 0xc1, 0x00, 0x02, 0x23, 0x16, 0x96, 0xe8, 0xe2, - 0x1e, 0xae, 0xd5, 0xd8, 0xe7, 0xf8, 0x9c, 0x90, 0x30, 0xc2, 0xc2, 0x88, 0xc4, 0x80, 0xf8, 0x00, - 0x7c, 0x10, 0xb6, 0x8e, 0x95, 0x58, 0x10, 0x43, 0x85, 0x12, 0x3e, 0x08, 0xf2, 0xf9, 0x9c, 0xc6, - 0x8e, 0x53, 0xb2, 0x74, 0x8a, 0x75, 0xff, 0xff, 0x7b, 0xef, 0x77, 0xce, 0xff, 0x19, 0x6c, 0x1e, - 0x91, 0x4e, 0x07, 0x9b, 0xcc, 0x76, 0x99, 0x63, 0x9b, 0x1c, 0xf7, 0xea, 0xb8, 0xd3, 0xa5, 0xfe, - 0x00, 0x79, 0x3e, 0x0b, 0x18, 0x5c, 0x09, 0x65, 0x34, 0x96, 0x51, 0xaf, 0xae, 0xae, 0x5a, 0xcc, - 0x62, 0x42, 0xc5, 0xe1, 0x53, 0x64, 0x54, 0x37, 0x2c, 0xc6, 0xac, 0x36, 0xc5, 0xc4, 0xb3, 0x31, - 0x71, 0x5d, 0x16, 0x90, 0xc0, 0x66, 0x2e, 0x97, 0xaa, 0x66, 0x32, 0xee, 0x30, 0x8e, 0x5b, 0x84, - 0x53, 0xdc, 0xab, 0xb7, 0x68, 0x40, 0xea, 0x62, 0xa8, 0xd4, 0xcb, 0xd3, 0x14, 0x16, 0x75, 0x29, - 0xb7, 0x65, 0x03, 0x7d, 0x05, 0x5c, 0x7f, 0x19, 0x62, 0x1d, 0xf8, 0xc4, 0xa0, 0x9d, 0x2e, 0xe5, - 0x81, 0x7e, 0x07, 0x14, 0xcf, 0x8f, 0xb8, 0xc7, 0x5c, 0x4e, 0x61, 0x11, 0x2c, 0x50, 0x9f, 0xdc, - 0x56, 0xb6, 0x94, 0xea, 0xa2, 0x11, 0x3e, 0xea, 0x1a, 0xd8, 0x88, 0x5d, 0xfb, 0x6d, 0xc6, 0x6d, - 0xd7, 0x7a, 0xd5, 0xf5, 0xbc, 0xf6, 0x20, 0xee, 0xf2, 0x4d, 0x01, 0x9b, 0x33, 0x0c, 0xb2, 0x67, - 0x1f, 0x40, 0xea, 0x93, 0xa6, 0x19, 0x89, 0x4d, 0x2e, 0x54, 0x31, 0xe2, 0xea, 0x5e, 0x09, 0x45, - 0x17, 0x43, 0xe1, 0xc5, 0x90, 0xbc, 0x18, 0xda, 0x67, 0xb6, 0xdb, 0xc0, 0x27, 0x67, 0xe5, 0xdc, - 0xef, 0xb3, 0xf2, 0x3d, 0xcb, 0x0e, 0x8e, 0xba, 0x2d, 0x64, 0x32, 0x07, 0xcb, 0xb7, 0x10, 0xfd, - 0xd4, 0xf8, 0xe1, 0x31, 0x0e, 0x06, 0x1e, 0xe5, 0xa2, 0xc0, 0x28, 0xd2, 0x14, 0x81, 0xbe, 0x06, - 0x6e, 0x0a, 0xb4, 0x67, 0xa4, 0x9f, 0x84, 0xfe, 0xa8, 0x80, 0x5b, 0x69, 0x45, 0xd2, 0xda, 0x00, - 0x38, 0xa4, 0x7f, 0x79, 0x94, 0x05, 0x27, 0x1e, 0xa9, 0xaf, 0x83, 0x92, 0x80, 0x78, 0xea, 0xbe, - 0x6d, 0x8b, 0x7f, 0xdb, 0x20, 0x01, 0x8d, 0x11, 0x39, 0x50, 0xb3, 0x44, 0x49, 0xf9, 0x1a, 0x5c, - 0xb3, 0x63, 0xa1, 0xe9, 0x93, 0x80, 0x0a, 0xd2, 0x42, 0x03, 0x49, 0x9c, 0xca, 0x1c, 0x38, 0x8f, - 0xa9, 0x69, 0x2c, 0xdb, 0x93, 0xed, 0xf5, 0x55, 0x00, 0xc5, 0xd0, 0x17, 0xc4, 0x27, 0x0e, 0x8f, - 0x51, 0x9e, 0x83, 0x1b, 0x89, 0x53, 0xc9, 0xf0, 0x08, 0xe4, 0x3d, 0x71, 0x32, 0x7e, 0x4b, 0x53, - 0x59, 0x47, 0x51, 0x49, 0x63, 0x31, 0xc4, 0x32, 0xa4, 0x7d, 0xef, 0xc7, 0x12, 0x58, 0x12, 0x0d, - 0x21, 0x03, 0x0b, 0x07, 0x3e, 0x81, 0x7a, 0x46, 0x65, 0x2a, 0xad, 0xea, 0xce, 0x85, 0x9e, 0x08, - 0x49, 0x2f, 0x7f, 0xf8, 0xf9, 0xf7, 0xcb, 0x95, 0x12, 0x5c, 0xc3, 0xa1, 0xf9, 0x30, 0xb9, 0x10, - 0xd4, 0x27, 0xf0, 0xbb, 0x02, 0x8a, 0xe9, 0xa0, 0x42, 0x7c, 0x41, 0xeb, 0xac, 0xcc, 0xab, 0x0f, - 0xe6, 0x2f, 0x90, 0x60, 0x48, 0x80, 0x55, 0x61, 0x65, 0x06, 0x58, 0x6a, 0x3b, 0xe0, 0x27, 0x05, - 0x14, 0xc6, 0xd9, 0x84, 0xd5, 0x59, 0xf3, 0xd2, 0xc1, 0x56, 0x77, 0xe7, 0x70, 0x4a, 0xa4, 0x8a, - 0x40, 0xda, 0x82, 0x5a, 0x16, 0xd2, 0xf9, 0x0a, 0xc0, 0xaf, 0x0a, 0x58, 0x4e, 0x84, 0x10, 0xde, - 0x9f, 0x35, 0x24, 0x2b, 0xc8, 0x6a, 0x6d, 0x4e, 0xb7, 0xc4, 0xda, 0x15, 0x58, 0x3b, 0x70, 0x1b, - 0x4f, 0x7f, 0xd2, 0x92, 0x91, 0x87, 0xef, 0x41, 0x3e, 0xca, 0x17, 0xbc, 0x3b, 0x6b, 0x46, 0x22, - 0xc8, 0x6a, 0xe5, 0x7f, 0x36, 0xc9, 0xb0, 0x2d, 0x18, 0xd6, 0x61, 0x29, 0x83, 0x21, 0xca, 0x70, - 0xe3, 0xc9, 0xc9, 0x50, 0x53, 0x4e, 0x87, 0x9a, 0xf2, 0x67, 0xa8, 0x29, 0x9f, 0x47, 0x5a, 0xee, - 0x74, 0xa4, 0xe5, 0x7e, 0x8d, 0xb4, 0xdc, 0x1b, 0x34, 0xb1, 0x7a, 0x61, 0x79, 0xcd, 0xa5, 0xc1, - 0x3b, 0xe6, 0x1f, 0x47, 0xbd, 0xfa, 0x13, 0xdd, 0xc4, 0x1a, 0xb6, 0xf2, 0xe2, 0x03, 0xfd, 0xf0, - 0x5f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x38, 0x00, 0xef, 0x71, 0x49, 0x06, 0x00, 0x00, + // 507 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0xcb, 0x6e, 0xd3, 0x40, + 0x14, 0x86, 0x63, 0x2e, 0x91, 0x32, 0xac, 0x32, 0x94, 0x4b, 0x0d, 0x75, 0x8a, 0xa5, 0xa6, 0x65, + 0x91, 0x19, 0x5c, 0x16, 0xec, 0x53, 0x16, 0x6c, 0x40, 0x60, 0x76, 0x48, 0xa8, 0x9a, 0x38, 0x53, + 0x77, 0xd4, 0x7a, 0x8e, 0xe3, 0x99, 0xa4, 0x09, 0x1b, 0x24, 0xd8, 0xb0, 0x44, 0xe2, 0x21, 0x78, + 0x05, 0x1e, 0xa1, 0xcb, 0x4a, 0x6c, 0x10, 0x8b, 0x0a, 0x25, 0x3c, 0x08, 0xf2, 0x78, 0x92, 0x36, + 0x75, 0x22, 0xda, 0x95, 0xad, 0xf3, 0x9f, 0xcb, 0xa7, 0xf3, 0x9f, 0x41, 0x6b, 0xfb, 0xac, 0xd7, + 0xa3, 0x11, 0x08, 0x09, 0x89, 0x88, 0x14, 0x1d, 0x04, 0xb4, 0xd7, 0xe7, 0xd9, 0x88, 0xa4, 0x19, + 0x68, 0xc0, 0xf5, 0x5c, 0x26, 0x33, 0x99, 0x0c, 0x02, 0x77, 0x25, 0x86, 0x18, 0x8c, 0x4a, 0xf3, + 0xbf, 0x22, 0xd1, 0x7d, 0x18, 0x03, 0xc4, 0x87, 0x9c, 0xb2, 0x54, 0x50, 0x26, 0x25, 0x68, 0xa6, + 0x05, 0x48, 0x65, 0x55, 0x2f, 0x02, 0x95, 0x80, 0xa2, 0x1d, 0xa6, 0x38, 0x1d, 0x04, 0x1d, 0xae, + 0x59, 0x60, 0x86, 0x5a, 0xbd, 0x51, 0xa6, 0x88, 0xb9, 0xe4, 0x4a, 0xd8, 0x06, 0xfe, 0x3d, 0x74, + 0xe7, 0x4d, 0x8e, 0xf5, 0x92, 0x0d, 0xdf, 0xf6, 0xd3, 0xf4, 0x70, 0x14, 0xf2, 0x5e, 0x9f, 0x2b, + 0xed, 0x7f, 0x76, 0xd0, 0xdd, 0x8b, 0x8a, 0x4a, 0x41, 0x2a, 0x8e, 0x05, 0x42, 0x09, 0x1b, 0xee, + 0x2a, 0x13, 0xbd, 0xef, 0xac, 0x3b, 0x5b, 0xb7, 0xb6, 0x57, 0x49, 0x41, 0x42, 0x72, 0x12, 0x62, + 0x49, 0xc8, 0x0e, 0x08, 0xd9, 0xa6, 0xc7, 0xa7, 0x8d, 0xca, 0xef, 0xd3, 0xc6, 0x66, 0x2c, 0xf4, + 0x7e, 0xbf, 0x43, 0x22, 0x48, 0xa8, 0xc5, 0x2e, 0x3e, 0x2d, 0xd5, 0x3d, 0xa0, 0x7a, 0x94, 0x72, + 0x65, 0x0a, 0xc2, 0x5a, 0x32, 0x1d, 0xe9, 0x37, 0xd0, 0x9a, 0x81, 0x08, 0xf9, 0x11, 0xcb, 0xba, + 0x3b, 0xc0, 0xf7, 0xf6, 0x44, 0x24, 0xb8, 0xd4, 0x53, 0xcc, 0x8f, 0xc8, 0x5b, 0x96, 0x60, 0x69, + 0xdf, 0x23, 0x9c, 0x19, 0x71, 0x37, 0x3a, 0x53, 0x0d, 0x75, 0xad, 0x4d, 0x2c, 0x5a, 0xf3, 0x12, + 0x68, 0xcf, 0x79, 0x14, 0xd6, 0xb3, 0x8b, 0x63, 0xfc, 0x15, 0x84, 0x0d, 0xc0, 0x6b, 0x96, 0xb1, + 0x44, 0x4d, 0xb1, 0x5e, 0xa1, 0xdb, 0x73, 0x51, 0xcb, 0xf2, 0x0c, 0x55, 0x53, 0x13, 0x99, 0x6d, + 0xad, 0x74, 0x06, 0xa4, 0x28, 0x69, 0xdf, 0xc8, 0xd1, 0x42, 0x9b, 0xbe, 0xfd, 0xe3, 0x3a, 0xba, + 0x69, 0x1a, 0xe2, 0x2f, 0x0e, 0xaa, 0xcd, 0x2c, 0xc1, 0x5b, 0x0b, 0x1a, 0x2c, 0xf4, 0xd3, 0x7d, + 0x7c, 0x89, 0xcc, 0x82, 0xd2, 0x6f, 0x7e, 0xfa, 0xf9, 0xf7, 0xdb, 0xb5, 0x75, 0xec, 0xd1, 0xbc, + 0xa4, 0x3b, 0x7f, 0x3e, 0x67, 0xce, 0xe3, 0xef, 0x0e, 0xaa, 0x97, 0xf6, 0x8e, 0x9f, 0x2c, 0x1b, + 0xb4, 0xcc, 0x43, 0x37, 0xb8, 0x42, 0x85, 0x45, 0x6c, 0x19, 0xc4, 0x4d, 0xbc, 0x41, 0xcb, 0x07, + 0x5e, 0x76, 0x1b, 0x7f, 0x40, 0xd5, 0x62, 0xad, 0x78, 0x63, 0xd9, 0xac, 0x39, 0xff, 0xdc, 0xe6, + 0xff, 0xd2, 0x2c, 0xc7, 0x23, 0xc3, 0xf1, 0x00, 0xaf, 0x2e, 0xe0, 0x28, 0xac, 0x6b, 0xbf, 0x38, + 0x1e, 0x7b, 0xce, 0xc9, 0xd8, 0x73, 0xfe, 0x8c, 0x3d, 0xe7, 0xeb, 0xc4, 0xab, 0x9c, 0x4c, 0xbc, + 0xca, 0xaf, 0x89, 0x57, 0x79, 0x47, 0xce, 0x5d, 0x5d, 0x5e, 0xde, 0x92, 0x5c, 0x1f, 0x41, 0x76, + 0x50, 0xf4, 0x1a, 0x9e, 0xeb, 0x66, 0x2e, 0xb0, 0x53, 0x35, 0x4f, 0xf6, 0xe9, 0xbf, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xfc, 0x25, 0x93, 0xcb, 0x5b, 0x04, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -482,14 +318,10 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { - // Era retrieves current era. - Era(ctx context.Context, in *QueryEraRequest, opts ...grpc.CallOption) (*QueryEraResponse, error) - // EraTargetSupply retrieves current era target supply. - EraClosingSupply(ctx context.Context, in *QueryEraClosingSupplyRequest, opts ...grpc.CallOption) (*QueryEraClosingSupplyResponse, error) // MaxSupply retrieves total coins of all eras and when mint ended. MaxSupply(ctx context.Context, in *QueryMaxSupplyRequest, opts ...grpc.CallOption) (*QueryMaxSupplyResponse, error) - // InflationRate retrieves current era inflation rate. - InflationRate(ctx context.Context, in *QueryInflationRateRequest, opts ...grpc.CallOption) (*QueryInflationRateResponse, error) + // InflationRewardCoefficientRate APY rate for staking rewards + RewardCoefficient(ctx context.Context, in *QueryRewardCoefficientRequest, opts ...grpc.CallOption) (*QueryRewardCoefficientResponse, error) // Params retrieves coinomics moudle params. Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } @@ -502,24 +334,6 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } -func (c *queryClient) Era(ctx context.Context, in *QueryEraRequest, opts ...grpc.CallOption) (*QueryEraResponse, error) { - out := new(QueryEraResponse) - err := c.cc.Invoke(ctx, "/haqq.coinomics.v1.Query/Era", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *queryClient) EraClosingSupply(ctx context.Context, in *QueryEraClosingSupplyRequest, opts ...grpc.CallOption) (*QueryEraClosingSupplyResponse, error) { - out := new(QueryEraClosingSupplyResponse) - err := c.cc.Invoke(ctx, "/haqq.coinomics.v1.Query/EraClosingSupply", in, out, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *queryClient) MaxSupply(ctx context.Context, in *QueryMaxSupplyRequest, opts ...grpc.CallOption) (*QueryMaxSupplyResponse, error) { out := new(QueryMaxSupplyResponse) err := c.cc.Invoke(ctx, "/haqq.coinomics.v1.Query/MaxSupply", in, out, opts...) @@ -529,9 +343,9 @@ func (c *queryClient) MaxSupply(ctx context.Context, in *QueryMaxSupplyRequest, return out, nil } -func (c *queryClient) InflationRate(ctx context.Context, in *QueryInflationRateRequest, opts ...grpc.CallOption) (*QueryInflationRateResponse, error) { - out := new(QueryInflationRateResponse) - err := c.cc.Invoke(ctx, "/haqq.coinomics.v1.Query/InflationRate", in, out, opts...) +func (c *queryClient) RewardCoefficient(ctx context.Context, in *QueryRewardCoefficientRequest, opts ...grpc.CallOption) (*QueryRewardCoefficientResponse, error) { + out := new(QueryRewardCoefficientResponse) + err := c.cc.Invoke(ctx, "/haqq.coinomics.v1.Query/RewardCoefficient", in, out, opts...) if err != nil { return nil, err } @@ -549,14 +363,10 @@ func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts . // QueryServer is the server API for Query service. type QueryServer interface { - // Era retrieves current era. - Era(context.Context, *QueryEraRequest) (*QueryEraResponse, error) - // EraTargetSupply retrieves current era target supply. - EraClosingSupply(context.Context, *QueryEraClosingSupplyRequest) (*QueryEraClosingSupplyResponse, error) // MaxSupply retrieves total coins of all eras and when mint ended. MaxSupply(context.Context, *QueryMaxSupplyRequest) (*QueryMaxSupplyResponse, error) - // InflationRate retrieves current era inflation rate. - InflationRate(context.Context, *QueryInflationRateRequest) (*QueryInflationRateResponse, error) + // InflationRewardCoefficientRate APY rate for staking rewards + RewardCoefficient(context.Context, *QueryRewardCoefficientRequest) (*QueryRewardCoefficientResponse, error) // Params retrieves coinomics moudle params. Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } @@ -565,17 +375,11 @@ type QueryServer interface { type UnimplementedQueryServer struct { } -func (*UnimplementedQueryServer) Era(ctx context.Context, req *QueryEraRequest) (*QueryEraResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method Era not implemented") -} -func (*UnimplementedQueryServer) EraClosingSupply(ctx context.Context, req *QueryEraClosingSupplyRequest) (*QueryEraClosingSupplyResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method EraClosingSupply not implemented") -} func (*UnimplementedQueryServer) MaxSupply(ctx context.Context, req *QueryMaxSupplyRequest) (*QueryMaxSupplyResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method MaxSupply not implemented") } -func (*UnimplementedQueryServer) InflationRate(ctx context.Context, req *QueryInflationRateRequest) (*QueryInflationRateResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method InflationRate not implemented") +func (*UnimplementedQueryServer) RewardCoefficient(ctx context.Context, req *QueryRewardCoefficientRequest) (*QueryRewardCoefficientResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RewardCoefficient not implemented") } func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") @@ -585,42 +389,6 @@ func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } -func _Query_Era_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryEraRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).Era(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/haqq.coinomics.v1.Query/Era", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).Era(ctx, req.(*QueryEraRequest)) - } - return interceptor(ctx, in, info, handler) -} - -func _Query_EraClosingSupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryEraClosingSupplyRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(QueryServer).EraClosingSupply(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/haqq.coinomics.v1.Query/EraClosingSupply", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).EraClosingSupply(ctx, req.(*QueryEraClosingSupplyRequest)) - } - return interceptor(ctx, in, info, handler) -} - func _Query_MaxSupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(QueryMaxSupplyRequest) if err := dec(in); err != nil { @@ -639,20 +407,20 @@ func _Query_MaxSupply_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } -func _Query_InflationRate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(QueryInflationRateRequest) +func _Query_RewardCoefficient_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryRewardCoefficientRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(QueryServer).InflationRate(ctx, in) + return srv.(QueryServer).RewardCoefficient(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/haqq.coinomics.v1.Query/InflationRate", + FullMethod: "/haqq.coinomics.v1.Query/RewardCoefficient", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(QueryServer).InflationRate(ctx, req.(*QueryInflationRateRequest)) + return srv.(QueryServer).RewardCoefficient(ctx, req.(*QueryRewardCoefficientRequest)) } return interceptor(ctx, in, info, handler) } @@ -679,21 +447,13 @@ var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "haqq.coinomics.v1.Query", HandlerType: (*QueryServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "Era", - Handler: _Query_Era_Handler, - }, - { - MethodName: "EraClosingSupply", - Handler: _Query_EraClosingSupply_Handler, - }, { MethodName: "MaxSupply", Handler: _Query_MaxSupply_Handler, }, { - MethodName: "InflationRate", - Handler: _Query_InflationRate_Handler, + MethodName: "RewardCoefficient", + Handler: _Query_RewardCoefficient_Handler, }, { MethodName: "Params", @@ -704,113 +464,6 @@ var _Query_serviceDesc = grpc.ServiceDesc{ Metadata: "haqq/coinomics/v1/query.proto", } -func (m *QueryEraRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryEraRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryEraRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryEraResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryEraResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryEraResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Era != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Era)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - -func (m *QueryEraClosingSupplyRequest) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryEraClosingSupplyRequest) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryEraClosingSupplyRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - return len(dAtA) - i, nil -} - -func (m *QueryEraClosingSupplyResponse) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *QueryEraClosingSupplyResponse) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *QueryEraClosingSupplyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - { - size := m.EraClosingSupply.Size() - i -= size - if _, err := m.EraClosingSupply.MarshalTo(dAtA[i:]); err != nil { - return 0, err - } - i = encodeVarintQuery(dAtA, i, uint64(size)) - } - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func (m *QueryMaxSupplyRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -867,7 +520,7 @@ func (m *QueryMaxSupplyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) return len(dAtA) - i, nil } -func (m *QueryInflationRateRequest) Marshal() (dAtA []byte, err error) { +func (m *QueryRewardCoefficientRequest) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -877,12 +530,12 @@ func (m *QueryInflationRateRequest) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryInflationRateRequest) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryRewardCoefficientRequest) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryInflationRateRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryRewardCoefficientRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int @@ -890,7 +543,7 @@ func (m *QueryInflationRateRequest) MarshalToSizedBuffer(dAtA []byte) (int, erro return len(dAtA) - i, nil } -func (m *QueryInflationRateResponse) Marshal() (dAtA []byte, err error) { +func (m *QueryRewardCoefficientResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) n, err := m.MarshalToSizedBuffer(dAtA[:size]) @@ -900,20 +553,20 @@ func (m *QueryInflationRateResponse) Marshal() (dAtA []byte, err error) { return dAtA[:n], nil } -func (m *QueryInflationRateResponse) MarshalTo(dAtA []byte) (int, error) { +func (m *QueryRewardCoefficientResponse) MarshalTo(dAtA []byte) (int, error) { size := m.Size() return m.MarshalToSizedBuffer(dAtA[:size]) } -func (m *QueryInflationRateResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { +func (m *QueryRewardCoefficientResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { i := len(dAtA) _ = i var l int _ = l { - size := m.InflationRate.Size() + size := m.RewardCoefficient.Size() i -= size - if _, err := m.InflationRate.MarshalTo(dAtA[i:]); err != nil { + if _, err := m.RewardCoefficient.MarshalTo(dAtA[i:]); err != nil { return 0, err } i = encodeVarintQuery(dAtA, i, uint64(size)) @@ -990,47 +643,6 @@ func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } -func (m *QueryEraRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryEraResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.Era != 0 { - n += 1 + sovQuery(uint64(m.Era)) - } - return n -} - -func (m *QueryEraClosingSupplyRequest) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - return n -} - -func (m *QueryEraClosingSupplyResponse) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = m.EraClosingSupply.Size() - n += 1 + l + sovQuery(uint64(l)) - return n -} - func (m *QueryMaxSupplyRequest) Size() (n int) { if m == nil { return 0 @@ -1051,7 +663,7 @@ func (m *QueryMaxSupplyResponse) Size() (n int) { return n } -func (m *QueryInflationRateRequest) Size() (n int) { +func (m *QueryRewardCoefficientRequest) Size() (n int) { if m == nil { return 0 } @@ -1060,13 +672,13 @@ func (m *QueryInflationRateRequest) Size() (n int) { return n } -func (m *QueryInflationRateResponse) Size() (n int) { +func (m *QueryRewardCoefficientResponse) Size() (n int) { if m == nil { return 0 } var l int _ = l - l = m.InflationRate.Size() + l = m.RewardCoefficient.Size() n += 1 + l + sovQuery(uint64(l)) return n } @@ -1097,258 +709,6 @@ func sovQuery(x uint64) (n int) { func sozQuery(x uint64) (n int) { return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) } -func (m *QueryEraRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryEraRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryEraRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryEraResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryEraResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryEraResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Era", wireType) - } - m.Era = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Era |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryEraClosingSupplyRequest) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryEraClosingSupplyRequest: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryEraClosingSupplyRequest: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func (m *QueryEraClosingSupplyResponse) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: QueryEraClosingSupplyResponse: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: QueryEraClosingSupplyResponse: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field EraClosingSupply", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowQuery - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthQuery - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthQuery - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := m.EraClosingSupply.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipQuery(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthQuery - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *QueryMaxSupplyRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 @@ -1482,7 +842,7 @@ func (m *QueryMaxSupplyResponse) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryInflationRateRequest) Unmarshal(dAtA []byte) error { +func (m *QueryRewardCoefficientRequest) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1505,10 +865,10 @@ func (m *QueryInflationRateRequest) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryInflationRateRequest: wiretype end group for non-group") + return fmt.Errorf("proto: QueryRewardCoefficientRequest: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryInflationRateRequest: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryRewardCoefficientRequest: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { default: @@ -1532,7 +892,7 @@ func (m *QueryInflationRateRequest) Unmarshal(dAtA []byte) error { } return nil } -func (m *QueryInflationRateResponse) Unmarshal(dAtA []byte) error { +func (m *QueryRewardCoefficientResponse) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 for iNdEx < l { @@ -1555,15 +915,15 @@ func (m *QueryInflationRateResponse) Unmarshal(dAtA []byte) error { fieldNum := int32(wire >> 3) wireType := int(wire & 0x7) if wireType == 4 { - return fmt.Errorf("proto: QueryInflationRateResponse: wiretype end group for non-group") + return fmt.Errorf("proto: QueryRewardCoefficientResponse: wiretype end group for non-group") } if fieldNum <= 0 { - return fmt.Errorf("proto: QueryInflationRateResponse: illegal tag %d (wire type %d)", fieldNum, wire) + return fmt.Errorf("proto: QueryRewardCoefficientResponse: illegal tag %d (wire type %d)", fieldNum, wire) } switch fieldNum { case 1: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field InflationRate", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field RewardCoefficient", wireType) } var stringLen uint64 for shift := uint(0); ; shift += 7 { @@ -1591,7 +951,7 @@ func (m *QueryInflationRateResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if err := m.InflationRate.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + if err := m.RewardCoefficient.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } iNdEx = postIndex diff --git a/x/coinomics/types/query.pb.gw.go b/x/coinomics/types/query.pb.gw.go index 924b4933..4a783522 100644 --- a/x/coinomics/types/query.pb.gw.go +++ b/x/coinomics/types/query.pb.gw.go @@ -33,42 +33,6 @@ var _ = utilities.NewDoubleArray var _ = descriptor.ForMessage var _ = metadata.Join -func request_Query_Era_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryEraRequest - var metadata runtime.ServerMetadata - - msg, err := client.Era(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_Era_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryEraRequest - var metadata runtime.ServerMetadata - - msg, err := server.Era(ctx, &protoReq) - return msg, metadata, err - -} - -func request_Query_EraClosingSupply_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryEraClosingSupplyRequest - var metadata runtime.ServerMetadata - - msg, err := client.EraClosingSupply(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) - return msg, metadata, err - -} - -func local_request_Query_EraClosingSupply_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryEraClosingSupplyRequest - var metadata runtime.ServerMetadata - - msg, err := server.EraClosingSupply(ctx, &protoReq) - return msg, metadata, err - -} - func request_Query_MaxSupply_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { var protoReq QueryMaxSupplyRequest var metadata runtime.ServerMetadata @@ -87,20 +51,20 @@ func local_request_Query_MaxSupply_0(ctx context.Context, marshaler runtime.Mars } -func request_Query_InflationRate_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryInflationRateRequest +func request_Query_RewardCoefficient_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRewardCoefficientRequest var metadata runtime.ServerMetadata - msg, err := client.InflationRate(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + msg, err := client.RewardCoefficient(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) return msg, metadata, err } -func local_request_Query_InflationRate_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { - var protoReq QueryInflationRateRequest +func local_request_Query_RewardCoefficient_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryRewardCoefficientRequest var metadata runtime.ServerMetadata - msg, err := server.InflationRate(ctx, &protoReq) + msg, err := server.RewardCoefficient(ctx, &protoReq) return msg, metadata, err } @@ -129,52 +93,6 @@ func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshal // Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { - mux.Handle("GET", pattern_Query_Era_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_Era_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Era_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_EraClosingSupply_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - var stream runtime.ServerTransportStream - ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := local_request_Query_EraClosingSupply_0(rctx, inboundMarshaler, server, req, pathParams) - md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_EraClosingSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_MaxSupply_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -198,7 +116,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv }) - mux.Handle("GET", pattern_Query_InflationRate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_RewardCoefficient_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() var stream runtime.ServerTransportStream @@ -209,7 +127,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := local_request_Query_InflationRate_0(rctx, inboundMarshaler, server, req, pathParams) + resp, md, err := local_request_Query_RewardCoefficient_0(rctx, inboundMarshaler, server, req, pathParams) md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { @@ -217,7 +135,7 @@ func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, serv return } - forward_Query_InflationRate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_RewardCoefficient_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -285,46 +203,6 @@ func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc // "QueryClient" to call the correct interceptors. func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { - mux.Handle("GET", pattern_Query_Era_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_Era_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_Era_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - - mux.Handle("GET", pattern_Query_EraClosingSupply_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { - ctx, cancel := context.WithCancel(req.Context()) - defer cancel() - inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) - rctx, err := runtime.AnnotateContext(ctx, mux, req) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - resp, md, err := request_Query_EraClosingSupply_0(rctx, inboundMarshaler, client, req, pathParams) - ctx = runtime.NewServerMetadataContext(ctx, md) - if err != nil { - runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) - return - } - - forward_Query_EraClosingSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) - - }) - mux.Handle("GET", pattern_Query_MaxSupply_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -345,7 +223,7 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie }) - mux.Handle("GET", pattern_Query_InflationRate_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + mux.Handle("GET", pattern_Query_RewardCoefficient_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) @@ -354,14 +232,14 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - resp, md, err := request_Query_InflationRate_0(rctx, inboundMarshaler, client, req, pathParams) + resp, md, err := request_Query_RewardCoefficient_0(rctx, inboundMarshaler, client, req, pathParams) ctx = runtime.NewServerMetadataContext(ctx, md) if err != nil { runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) return } - forward_Query_InflationRate_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + forward_Query_RewardCoefficient_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) }) @@ -389,25 +267,17 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Era_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqqd", "coinomics", "v1", "era"}, "", runtime.AssumeColonVerbOpt(false))) - - pattern_Query_EraClosingSupply_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqqd", "coinomics", "v1", "era_closing_supply"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_MaxSupply_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqqd", "coinomics", "v1", "max_supply"}, "", runtime.AssumeColonVerbOpt(false))) - pattern_Query_InflationRate_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqq", "coinomics", "v1", "inflation_rate"}, "", runtime.AssumeColonVerbOpt(false))) + pattern_Query_RewardCoefficient_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqq", "coinomics", "v1", "reward_coefficient"}, "", runtime.AssumeColonVerbOpt(false))) pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"haqq", "coinomics", "v1", "params"}, "", runtime.AssumeColonVerbOpt(false))) ) var ( - forward_Query_Era_0 = runtime.ForwardResponseMessage - - forward_Query_EraClosingSupply_0 = runtime.ForwardResponseMessage - forward_Query_MaxSupply_0 = runtime.ForwardResponseMessage - forward_Query_InflationRate_0 = runtime.ForwardResponseMessage + forward_Query_RewardCoefficient_0 = runtime.ForwardResponseMessage forward_Query_Params_0 = runtime.ForwardResponseMessage )