0g-chain/x/validator-vesting/querier.go
drklee3 f757d7ab15
feat: upgrade to Cosmos v0.46 (#1477)
* Update cosmos-sdk to v0.45.10-kava

* Add RegisterNodeService to app

* Update cosmos proto files

* Update cosmos proto files

* Use tagged v0.45.10-kava-v0.19-0.21 cosmos version

* update x/auth/legacy to x/auth/migrations

* Delete rest packages and registration

* Remove rest from proposal handlers

* Remove legacy types referencing removed sdk types

* Remove legacy tx broadcast handler

* Update incentive staking hooks to return error

* Remove grpc replace directive, use new grpc version

* Fix storetypes import

* Update tally_handler with updated gov types

* Delete legacy types

* Use new gov default config

* Update RegisterTendermintService params

Signed-off-by: drklee3 <derrick@dlee.dev>

* Replace sdk.StoreKey with storetypes.StoreKey

* Replace sdk.Int#ToDec with sdk.NewDecFromInt

* Replace sdk.NewUintFromBigInt with sdkmath.NewUintFromBigInt

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update most intances of govtypes to govv1beta1

* Unpack coin slice for Coins#Sub and Coins#SafeSub

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update committee gov codec registration

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update migrate utils period_vesting Coins#Sub

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update Coin#Sub in community proposal handler

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update Coin#Sub, FundModuleAccount/FundAccount in banktestutil

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update community, earn, kavadist proposal gov registration

* Update evm cli client EthSecp256k1Type check

* AccAddressFromHex to AccAddressFromHexUnsafe

* Add mint DefaultInflationCalculationFn to earn test

* Update use of removed staking.NewHandler

* Rename FlagIAVLFastNode -> FlagDisableIAVLFastNode

* cmd: Update new snapshot app option

Signed-off-by: drklee3 <derrick@dlee.dev>

* cmd: Add tendermint default config, use cosmos rpc status command

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update ethermint import path

github.com/tharsis/ethermint -> github.com/evmos/ethermint

* Upgrade ibc-go to v6

* Update proto dependencies

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update Tally handler test with new gov types

* Update helpers.GenTx -> helpers.GenSignedMockTx

* Update evmkeeper.NewKeeper params

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update ante authz, tests

* Add feemarket transient key, pass subspaces to evm/feemarket keepers

* Update new ante decorators

* Add new addModuleInitFlags to server commands

* Pass codec to keyring.New in genaccounts

* Pass codec to client keys add

* Add SendCoins to evmutil bank_keeper

* Use github.com/cosmos/iavl@v0.19.5

* Add ante HandlerOptions

* Add unimplemented SendCoins to evmutil bank keeper

Ethermint x/evm does not use this method

* Update init-new-chain script to disable post-london blocks

* Modify test genesis states to append 1 validator

* Update tally handler test to use string values

* Prevent querying balance for empty sdk.AccAddress in auction bidding test

* Set default bond denom to ukava

* Remove overwritten bank genesis total supply in committee proposal test

Signed-off-by: drklee3 <derrick@dlee.dev>

* Use ukava for testing staked balance

* Disable minting in community proposal handler test

Previously stake denom is used, which resulted in 0 minted coins

* Update hard APYToSPY test expected value

Increased iterations in sdk.ApproxRoot, updated closer to real value

* Fix NewDecCoinsFromCoins bug in incentive collectDerivativeStakingRewards

* Allow bkava earn incentive test values to match within small margin for rounding

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update invalid denom in issuance message coin validation

Colons are now valid in denoms

Signed-off-by: drklee3 <derrick@dlee.dev>

* Remove genesis validator in incentive delegation tests

* Update pricefeed market test for invalid denom

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update incentive delegator rewards test without genesis validator

Signed-off-by: drklee3 <derrick@dlee.dev>

* Add validator to export test

* Clear bank state in minting tests

Signed-off-by: drklee3 <derrick@dlee.dev>

* Remove validator for no stake tally test

Signed-off-by: drklee3 <derrick@dlee.dev>

* Clear incentive state before InitGenesis in incentive genesis export test

* Update swagger

Signed-off-by: drklee3 <derrick@dlee.dev>

* Update ethermint version to match replaced version

* Remove legacy swagger

* Add NewEthEmitEventDecorator

* Remove redundant func for AddModuleInitFlags

* Remove unused addBankBalanceForAddress func

* Add SetIAVLLazyLoading option to app cmd

* Use legacy.RegisterAminoMsg for committee msg concrete registration

* Remove unnecessary Amino field

* Add evm_util bankkeeper SendCoins comment

* Update test method ResetBankState to DeleteGenesisValidatorCoins to be more clear

* Validate incentive params.RewardsPerSecond to be non-zero

* Validate swap pools to disallow colons in token denoms

* Register all legacy amino types on gov modulecdc

* Remove redundant Comittee interface registration

* Pin goleveldb to v1.0.1-0.20210819022825-2ae1ddf74ef7

Causes failed to load state at height errors

* Update ethermint to new pinned version with minGasPrices parse error fix

* Update cosmos fork dependcy commit to include reverted account constructor patch

* Update Cosmos v0.46.11 and cometbft v0.34.27

* Bump minimum go version to 1.19

* Update tendermint proto

* Update internal testnet genesis

* Move NewCanTransferDecorator before NewEthGasConsumeDecorator

* Add hard borrow store tests (#1514)

* add store tests for Borrow type

* refactor Deposit tests to match

* Fix old bep3 tests (#1515)

* Update Ethermint to 1b17445 to fix duplicate proto registration

* Add custom status command to use snake_case and stdout

* Add SetInflation helper

* Reduce ambiguity with evm CanSignEthTx error

* Remove init genesis validator claim in test

* Add disabled evmante.NewMinGasPriceDecorator with x/feemarket note

* chore: use tagged versions for Cosmos and Ethermint forks

* update kvtool & increase wait for ibc transfer test

---------

Signed-off-by: drklee3 <derrick@dlee.dev>
Co-authored-by: Ruaridh <rhuairahrighairidh@users.noreply.github.com>
Co-authored-by: Robert Pirtle <astropirtle@gmail.com>
2023-04-03 20:08:45 -04:00

357 lines
20 KiB
Go

package validator_vesting
import (
"time"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/kava-labs/kava/x/validator-vesting/types"
abci "github.com/tendermint/tendermint/abci/types"
)
const SafuFund int64 = 10000000 // 10 million KAVA
// NewQuerier is the module level router for state queries
func NewQuerier(bk types.BankKeeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) (res []byte, err error) {
switch path[0] {
case types.QueryCirculatingSupply:
return queryGetCirculatingSupply(ctx, req, bk, legacyQuerierCdc)
case types.QueryTotalSupply:
return queryGetTotalSupply(ctx, req, bk, legacyQuerierCdc)
case types.QueryCirculatingSupplyHARD:
return getCirculatingSupplyHARD(ctx, req, legacyQuerierCdc)
case types.QueryCirculatingSupplyUSDX:
return getCirculatingSupplyUSDX(ctx, req, bk, legacyQuerierCdc)
case types.QueryCirculatingSupplySWP:
return getCirculatingSupplySWP(ctx, req, legacyQuerierCdc)
case types.QueryTotalSupplyHARD:
return getTotalSupplyHARD(ctx, req, bk, legacyQuerierCdc)
case types.QueryTotalSupplyUSDX:
return getCirculatingSupplyUSDX(ctx, req, bk, legacyQuerierCdc) // Intentional - USDX total supply is the circulating supply
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown %s query endpoint: %s", types.ModuleName, path[0])
}
}
}
func queryGetTotalSupply(ctx sdk.Context, req abci.RequestQuery, bk types.BankKeeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
totalSupply := bk.GetSupply(ctx, "ukava").Amount
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt64()
bz, err := legacyQuerierCdc.MarshalJSON(supplyInt)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}
func queryGetCirculatingSupply(ctx sdk.Context, req abci.RequestQuery, bk types.BankKeeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
totalSupply := bk.GetSupply(ctx, "ukava").Amount
supplyInt := getCirculatingSupply(ctx.BlockTime(), totalSupply)
bz, err := legacyQuerierCdc.MarshalJSON(supplyInt)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}
func getCirculatingSupply(blockTime time.Time, totalSupply sdk.Int) sdk.Int {
vestingDates := []time.Time{
time.Date(2022, 2, 5, 14, 0, 0, 0, time.UTC),
time.Date(2022, 5, 5, 14, 0, 0, 0, time.UTC),
time.Date(2022, 8, 5, 14, 0, 0, 0, time.UTC),
time.Date(2022, 11, 5, 14, 0, 0, 0, time.UTC),
}
switch {
case blockTime.Before(vestingDates[0]):
return sdk.NewDecFromInt(totalSupply.Sub(sdk.NewInt(9937500000000))).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
case blockTime.After(vestingDates[0]) && blockTime.Before(vestingDates[1]) || blockTime.Equal(vestingDates[0]):
return sdk.NewDecFromInt(totalSupply.Sub(sdk.NewInt(7453125000000))).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
case blockTime.After(vestingDates[1]) && blockTime.Before(vestingDates[2]) || blockTime.Equal(vestingDates[1]):
return sdk.NewDecFromInt(totalSupply.Sub(sdk.NewInt(4968750000000))).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
case blockTime.After(vestingDates[2]) && blockTime.Before(vestingDates[3]) || blockTime.Equal(vestingDates[2]):
return sdk.NewDecFromInt(totalSupply.Sub(sdk.NewInt(2484375000000))).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
default:
return sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
}
}
func getCirculatingSupplyHARD(ctx sdk.Context, req abci.RequestQuery, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
supplyIncreaseDates := []time.Time{
time.Date(2020, 10, 15, 14, 0, 0, 0, time.UTC), // + 30,000,000 *** Year ONE ***
time.Date(2020, 11, 15, 14, 0, 0, 0, time.UTC), // + 5,000,000
time.Date(2020, 12, 15, 14, 0, 0, 0, time.UTC), // + 5,000,000
time.Date(2021, 1, 15, 14, 0, 0, 0, time.UTC), // + 7,708,334
time.Date(2021, 2, 15, 14, 0, 0, 0, time.UTC), // + 3,333,333
time.Date(2021, 3, 15, 14, 0, 0, 0, time.UTC), // + 3,333,333
time.Date(2021, 4, 15, 14, 0, 0, 0, time.UTC), // + 6,875,000
time.Date(2021, 5, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2021, 6, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2021, 7, 15, 14, 0, 0, 0, time.UTC), // + 6,875,000
time.Date(2021, 8, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2021, 9, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000 *** Year ONE ***
time.Date(2021, 10, 15, 14, 0, 0, 0, time.UTC), // + 13,541,667 *** Year TWO ***
time.Date(2021, 11, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2021, 12, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 1, 15, 14, 0, 0, 0, time.UTC), // + 8,541,667
time.Date(2022, 2, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 3, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 4, 15, 14, 0, 0, 0, time.UTC), // + 8,541,667
time.Date(2022, 5, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 6, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 7, 15, 14, 0, 0, 0, time.UTC), // + 8,541,667
time.Date(2022, 8, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 9, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000 *** Year TWO ***
time.Date(2022, 10, 15, 14, 0, 0, 0, time.UTC), // + 8,541,667 *** Year THREE ***
time.Date(2022, 11, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2022, 12, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 1, 15, 14, 0, 0, 0, time.UTC), // + 4,166,667
time.Date(2023, 2, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 3, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 4, 15, 14, 0, 0, 0, time.UTC), // + 4,166,667
time.Date(2023, 5, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 6, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 7, 15, 14, 0, 0, 0, time.UTC), // + 4,166,667
time.Date(2023, 8, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000
time.Date(2023, 9, 15, 14, 0, 0, 0, time.UTC), // + 2,500,000 *** Year THREE ***
time.Date(2023, 10, 15, 14, 0, 0, 0, time.UTC), // + 3,333,334 *** Year FOUR ***
time.Date(2023, 11, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2023, 12, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 1, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 2, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 3, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 4, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 5, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 6, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 7, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 8, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667
time.Date(2024, 9, 15, 14, 0, 0, 0, time.UTC), // + 1,666,667 *** Year FOUR ***
}
circSupply := sdk.ZeroInt()
blockTime := ctx.BlockTime()
switch {
case blockTime.Before(supplyIncreaseDates[0]):
circSupply = sdk.NewInt(0)
case blockTime.After(supplyIncreaseDates[0]) && blockTime.Before(supplyIncreaseDates[1]) || blockTime.Equal(supplyIncreaseDates[0]):
circSupply = sdk.NewInt(30000000) // Start year ONE
case blockTime.After(supplyIncreaseDates[1]) && blockTime.Before(supplyIncreaseDates[2]) || blockTime.Equal(supplyIncreaseDates[1]):
circSupply = sdk.NewInt(35000000)
case blockTime.After(supplyIncreaseDates[2]) && blockTime.Before(supplyIncreaseDates[3]) || blockTime.Equal(supplyIncreaseDates[2]):
circSupply = sdk.NewInt(40000000)
case blockTime.After(supplyIncreaseDates[3]) && blockTime.Before(supplyIncreaseDates[4]) || blockTime.Equal(supplyIncreaseDates[3]):
circSupply = sdk.NewInt(47708334)
case blockTime.After(supplyIncreaseDates[4]) && blockTime.Before(supplyIncreaseDates[5]) || blockTime.Equal(supplyIncreaseDates[4]):
circSupply = sdk.NewInt(51041667)
case blockTime.After(supplyIncreaseDates[5]) && blockTime.Before(supplyIncreaseDates[6]) || blockTime.Equal(supplyIncreaseDates[5]):
circSupply = sdk.NewInt(54375000)
case blockTime.After(supplyIncreaseDates[6]) && blockTime.Before(supplyIncreaseDates[7]) || blockTime.Equal(supplyIncreaseDates[6]):
circSupply = sdk.NewInt(61250000)
case blockTime.After(supplyIncreaseDates[7]) && blockTime.Before(supplyIncreaseDates[8]) || blockTime.Equal(supplyIncreaseDates[7]):
circSupply = sdk.NewInt(63750000)
case blockTime.After(supplyIncreaseDates[8]) && blockTime.Before(supplyIncreaseDates[9]) || blockTime.Equal(supplyIncreaseDates[8]):
circSupply = sdk.NewInt(66250000)
case blockTime.After(supplyIncreaseDates[9]) && blockTime.Before(supplyIncreaseDates[10]) || blockTime.Equal(supplyIncreaseDates[9]):
circSupply = sdk.NewInt(73125000)
case blockTime.After(supplyIncreaseDates[10]) && blockTime.Before(supplyIncreaseDates[11]) || blockTime.Equal(supplyIncreaseDates[10]):
circSupply = sdk.NewInt(75625000)
case blockTime.After(supplyIncreaseDates[11]) && blockTime.Before(supplyIncreaseDates[12]) || blockTime.Equal(supplyIncreaseDates[11]):
circSupply = sdk.NewInt(78125000) // End year ONE
case blockTime.After(supplyIncreaseDates[12]) && blockTime.Before(supplyIncreaseDates[13]) || blockTime.Equal(supplyIncreaseDates[12]):
circSupply = sdk.NewInt(91666667) // Start year TWO
case blockTime.After(supplyIncreaseDates[13]) && blockTime.Before(supplyIncreaseDates[14]) || blockTime.Equal(supplyIncreaseDates[13]):
circSupply = sdk.NewInt(94166667)
case blockTime.After(supplyIncreaseDates[14]) && blockTime.Before(supplyIncreaseDates[15]) || blockTime.Equal(supplyIncreaseDates[14]):
circSupply = sdk.NewInt(96666667)
case blockTime.After(supplyIncreaseDates[15]) && blockTime.Before(supplyIncreaseDates[16]) || blockTime.Equal(supplyIncreaseDates[15]):
circSupply = sdk.NewInt(105208334)
case blockTime.After(supplyIncreaseDates[16]) && blockTime.Before(supplyIncreaseDates[17]) || blockTime.Equal(supplyIncreaseDates[16]):
circSupply = sdk.NewInt(107708334)
case blockTime.After(supplyIncreaseDates[17]) && blockTime.Before(supplyIncreaseDates[18]) || blockTime.Equal(supplyIncreaseDates[17]):
circSupply = sdk.NewInt(110208334)
case blockTime.After(supplyIncreaseDates[18]) && blockTime.Before(supplyIncreaseDates[19]) || blockTime.Equal(supplyIncreaseDates[18]):
circSupply = sdk.NewInt(118750000)
case blockTime.After(supplyIncreaseDates[19]) && blockTime.Before(supplyIncreaseDates[20]) || blockTime.Equal(supplyIncreaseDates[19]):
circSupply = sdk.NewInt(121250000)
case blockTime.After(supplyIncreaseDates[20]) && blockTime.Before(supplyIncreaseDates[21]) || blockTime.Equal(supplyIncreaseDates[20]):
circSupply = sdk.NewInt(123750000)
case blockTime.After(supplyIncreaseDates[21]) && blockTime.Before(supplyIncreaseDates[22]) || blockTime.Equal(supplyIncreaseDates[21]):
circSupply = sdk.NewInt(132291668)
case blockTime.After(supplyIncreaseDates[22]) && blockTime.Before(supplyIncreaseDates[23]) || blockTime.Equal(supplyIncreaseDates[22]):
circSupply = sdk.NewInt(134791668)
case blockTime.After(supplyIncreaseDates[23]) && blockTime.Before(supplyIncreaseDates[24]) || blockTime.Equal(supplyIncreaseDates[23]):
circSupply = sdk.NewInt(137291668) // End year TWO
case blockTime.After(supplyIncreaseDates[24]) && blockTime.Before(supplyIncreaseDates[25]) || blockTime.Equal(supplyIncreaseDates[24]):
circSupply = sdk.NewInt(145833335) // Start year THREE
case blockTime.After(supplyIncreaseDates[25]) && blockTime.Before(supplyIncreaseDates[26]) || blockTime.Equal(supplyIncreaseDates[25]):
circSupply = sdk.NewInt(148333335)
case blockTime.After(supplyIncreaseDates[26]) && blockTime.Before(supplyIncreaseDates[27]) || blockTime.Equal(supplyIncreaseDates[26]):
circSupply = sdk.NewInt(150833335)
case blockTime.After(supplyIncreaseDates[27]) && blockTime.Before(supplyIncreaseDates[28]) || blockTime.Equal(supplyIncreaseDates[27]):
circSupply = sdk.NewInt(155000000)
case blockTime.After(supplyIncreaseDates[28]) && blockTime.Before(supplyIncreaseDates[29]) || blockTime.Equal(supplyIncreaseDates[28]):
circSupply = sdk.NewInt(157500000)
case blockTime.After(supplyIncreaseDates[29]) && blockTime.Before(supplyIncreaseDates[30]) || blockTime.Equal(supplyIncreaseDates[29]):
circSupply = sdk.NewInt(160000000)
case blockTime.After(supplyIncreaseDates[30]) && blockTime.Before(supplyIncreaseDates[31]) || blockTime.Equal(supplyIncreaseDates[30]):
circSupply = sdk.NewInt(164166669)
case blockTime.After(supplyIncreaseDates[31]) && blockTime.Before(supplyIncreaseDates[32]) || blockTime.Equal(supplyIncreaseDates[31]):
circSupply = sdk.NewInt(166666669)
case blockTime.After(supplyIncreaseDates[32]) && blockTime.Before(supplyIncreaseDates[33]) || blockTime.Equal(supplyIncreaseDates[32]):
circSupply = sdk.NewInt(169166669)
case blockTime.After(supplyIncreaseDates[33]) && blockTime.Before(supplyIncreaseDates[34]) || blockTime.Equal(supplyIncreaseDates[33]):
circSupply = sdk.NewInt(173333336)
case blockTime.After(supplyIncreaseDates[34]) && blockTime.Before(supplyIncreaseDates[35]) || blockTime.Equal(supplyIncreaseDates[34]):
circSupply = sdk.NewInt(175833336)
case blockTime.After(supplyIncreaseDates[35]) && blockTime.Before(supplyIncreaseDates[36]) || blockTime.Equal(supplyIncreaseDates[35]):
circSupply = sdk.NewInt(178333336) // End year THREE
case blockTime.After(supplyIncreaseDates[36]) && blockTime.Before(supplyIncreaseDates[37]) || blockTime.Equal(supplyIncreaseDates[36]):
circSupply = sdk.NewInt(181666670) // Start year FOUR
case blockTime.After(supplyIncreaseDates[37]) && blockTime.Before(supplyIncreaseDates[38]) || blockTime.Equal(supplyIncreaseDates[37]):
circSupply = sdk.NewInt(183333337)
case blockTime.After(supplyIncreaseDates[38]) && blockTime.Before(supplyIncreaseDates[39]) || blockTime.Equal(supplyIncreaseDates[38]):
circSupply = sdk.NewInt(185000000)
case blockTime.After(supplyIncreaseDates[39]) && blockTime.Before(supplyIncreaseDates[40]) || blockTime.Equal(supplyIncreaseDates[39]):
circSupply = sdk.NewInt(186666670)
case blockTime.After(supplyIncreaseDates[40]) && blockTime.Before(supplyIncreaseDates[41]) || blockTime.Equal(supplyIncreaseDates[40]):
circSupply = sdk.NewInt(188333338)
case blockTime.After(supplyIncreaseDates[41]) && blockTime.Before(supplyIncreaseDates[42]) || blockTime.Equal(supplyIncreaseDates[41]):
circSupply = sdk.NewInt(190000000)
case blockTime.After(supplyIncreaseDates[42]) && blockTime.Before(supplyIncreaseDates[43]) || blockTime.Equal(supplyIncreaseDates[42]):
circSupply = sdk.NewInt(191666670)
case blockTime.After(supplyIncreaseDates[43]) && blockTime.Before(supplyIncreaseDates[44]) || blockTime.Equal(supplyIncreaseDates[43]):
circSupply = sdk.NewInt(193333339)
case blockTime.After(supplyIncreaseDates[44]) && blockTime.Before(supplyIncreaseDates[45]) || blockTime.Equal(supplyIncreaseDates[44]):
circSupply = sdk.NewInt(195000000)
case blockTime.After(supplyIncreaseDates[45]) && blockTime.Before(supplyIncreaseDates[46]) || blockTime.Equal(supplyIncreaseDates[45]):
circSupply = sdk.NewInt(196666670)
case blockTime.After(supplyIncreaseDates[46]) && blockTime.Before(supplyIncreaseDates[47]) || blockTime.Equal(supplyIncreaseDates[46]):
circSupply = sdk.NewInt(198333340)
case blockTime.After(supplyIncreaseDates[47]) && blockTime.Before(supplyIncreaseDates[48]) || blockTime.Equal(supplyIncreaseDates[47]):
circSupply = sdk.NewInt(200000000) // End year FOUR
default:
circSupply = sdk.NewInt(200000000)
}
bz, err := legacyQuerierCdc.MarshalJSON(circSupply)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}
func getCirculatingSupplyUSDX(ctx sdk.Context, req abci.RequestQuery, bk types.BankKeeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
totalSupply := bk.GetSupply(ctx, "usdx").Amount
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt64()
bz, err := legacyQuerierCdc.MarshalJSON(supplyInt)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}
func getCirculatingSupplySWP(ctx sdk.Context, req abci.RequestQuery, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
// Start values
year := 2021
month := 8
var supplyIncreaseDates []time.Time
// Add month times for 4 years
for i := 0; i < 12*4; i++ {
// Always day 30 unless it's Feb
day := 30
if month == 2 {
day = 28
}
date := time.Date(year, time.Month(month), day, 15 /* hour */, 0, 0, 0, time.UTC)
supplyIncreaseDates = append(supplyIncreaseDates, date)
// Update year and month
if month == 12 {
month = 1
year += 1
} else {
month += 1
}
}
// Repeated tokens released
teamSwp := int64(4_687_500)
treasurySwp := int64(5_859_375)
monthlyStakersSwp := int64(520_833)
monthlyLPIncentivesSwp := int64(2_343_750)
// []{Ecosystem, Team, Treasury, Kava Stakers, LP Incentives}
scheduleAmounts := [][]int64{
{12_500_000, 0, 15_625_000, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year ONE ***
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 1
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 2
{0, 0, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 3
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 4
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 5
{0, 0, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 6
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 7
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 8
{0, 0, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 9
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 10
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 11
{0, 18_750_000, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year TWO ***
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 13
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 14
{0, teamSwp, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 15
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 16
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 17
{0, teamSwp, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 18
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 19
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 20
{0, teamSwp, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 21
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 22
{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp}, // 23
{0, teamSwp, treasurySwp, monthlyStakersSwp, monthlyLPIncentivesSwp}, // *** Year THREE ***
}
// Months 25-47 are the same
for i := 0; i < 23; i++ {
scheduleAmounts = append(scheduleAmounts, []int64{0, 0, 0, monthlyStakersSwp, monthlyLPIncentivesSwp})
}
circSupply := sdk.ZeroInt()
blockTime := ctx.BlockTime()
for i := 0; i < len(scheduleAmounts); i++ {
if blockTime.Before(supplyIncreaseDates[i]) {
break
}
// Sum up each category of token release
monthTotal := int64(0)
for _, val := range scheduleAmounts[i] {
monthTotal += val
}
circSupply = circSupply.Add(sdk.NewInt(monthTotal))
}
bz, err := legacyQuerierCdc.MarshalJSON(circSupply)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}
func getTotalSupplyHARD(ctx sdk.Context, req abci.RequestQuery, bk types.BankKeeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
totalSupply := bk.GetSupply(ctx, "hard").Amount
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt64()
bz, err := legacyQuerierCdc.MarshalJSON(supplyInt)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONUnmarshal, err.Error())
}
return bz, nil
}