mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 15:55:18 +00:00
Merge branch 'master' into release/v0.26.x
This commit is contained in:
commit
17691e95a8
21
.github/workflows/cd-internal-testnet.yml
vendored
21
.github/workflows/cd-internal-testnet.yml
vendored
@ -1,5 +1,6 @@
|
||||
name: Continuous Deployment (Internal Testnet)
|
||||
# run after every successful CI job of new commits to the master branch
|
||||
# if deploy version or config has changed
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: [Continuous Integration (Kava Master)]
|
||||
@ -7,6 +8,23 @@ on:
|
||||
- completed
|
||||
|
||||
jobs:
|
||||
changed_files:
|
||||
runs-on: ubuntu-latest
|
||||
# define output for first job forwarding output of changedInternalTestnetConfig job
|
||||
outputs:
|
||||
changedInternalTestnetConfig: ${{ steps.changed-internal-testnet-config.outputs.any_changed }}
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # OR "2" -> To retrieve the preceding commit.
|
||||
- name: Get all changed internal testnet files
|
||||
id: changed-internal-testnet-config
|
||||
uses: tj-actions/changed-files@v42
|
||||
with:
|
||||
# Avoid using single or double quotes for multiline patterns
|
||||
files: |
|
||||
ci/env/kava-internal-testnet/**
|
||||
|
||||
# in order:
|
||||
# enter standby (prevents autoscaling group from killing node during deploy)
|
||||
# stop kava
|
||||
@ -14,8 +32,9 @@ jobs:
|
||||
# download updated binary and genesis
|
||||
# reset application database state (only done on internal testnet)
|
||||
reset-chain-to-zero-state:
|
||||
needs: [changed_files]
|
||||
# only start cd pipeline if last ci run was successful
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' && needs.changed_files.outputs.changedInternalTestnetConfig == 'true' }}
|
||||
uses: ./.github/workflows/cd-reset-internal-testnet.yml
|
||||
with:
|
||||
aws-region: us-east-1
|
||||
|
@ -42,6 +42,9 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
- (cdp) [#1818] Add module param and logic for running x/cdp begin blocker every `n` blocks
|
||||
- (cli) [#1804] Add `rocksdb compact` command for manual DB compaction of state or blockstore.
|
||||
- (cosmos-sdk) [#1811] Upgrades app to cosmos-sdk v0.47.7
|
||||
- (validator-vesting) [#1832] Add grpc query service to replace removed legacy querier
|
||||
- (incentive) [#1836] Update x/incentive cli to use grpc query client
|
||||
- (ibc) [#1839] Add ibc packet forward middleware for ibc transfers
|
||||
|
||||
## [v0.25.0]
|
||||
|
||||
@ -324,6 +327,9 @@ the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.38.4/CHANGELOG.md).
|
||||
- [#257](https://github.com/Kava-Labs/kava/pulls/257) Include scripts to run
|
||||
large-scale simulations remotely using aws-batch
|
||||
|
||||
[#1839]: https://github.com/Kava-Labs/kava/pull/1839
|
||||
[#1836]: https://github.com/Kava-Labs/kava/pull/1836
|
||||
[#1832]: https://github.com/Kava-Labs/kava/pull/1832
|
||||
[#1811]: https://github.com/Kava-Labs/kava/pull/1811
|
||||
[#1804]: https://github.com/Kava-Labs/kava/pull/1804
|
||||
[#1785]: https://github.com/Kava-Labs/kava/pull/1785
|
||||
|
48
app/app.go
48
app/app.go
@ -79,6 +79,9 @@ import (
|
||||
upgradeclient "github.com/cosmos/cosmos-sdk/x/upgrade/client"
|
||||
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
|
||||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
|
||||
"github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward"
|
||||
packetforwardkeeper "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper"
|
||||
packetforwardtypes "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types"
|
||||
transfer "github.com/cosmos/ibc-go/v7/modules/apps/transfer"
|
||||
ibctransferkeeper "github.com/cosmos/ibc-go/v7/modules/apps/transfer/keeper"
|
||||
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
|
||||
@ -86,7 +89,7 @@ import (
|
||||
ibcclient "github.com/cosmos/ibc-go/v7/modules/core/02-client"
|
||||
ibcclientclient "github.com/cosmos/ibc-go/v7/modules/core/02-client/client"
|
||||
ibcclienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
|
||||
porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
|
||||
ibcporttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types"
|
||||
ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported"
|
||||
ibckeeper "github.com/cosmos/ibc-go/v7/modules/core/keeper"
|
||||
solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine"
|
||||
@ -199,6 +202,7 @@ var (
|
||||
ibc.AppModuleBasic{},
|
||||
ibctm.AppModuleBasic{},
|
||||
solomachine.AppModuleBasic{},
|
||||
packetforward.AppModuleBasic{},
|
||||
upgrade.AppModuleBasic{},
|
||||
evidence.AppModuleBasic{},
|
||||
authzmodule.AppModuleBasic{},
|
||||
@ -307,6 +311,7 @@ type App struct {
|
||||
crisisKeeper crisiskeeper.Keeper
|
||||
slashingKeeper slashingkeeper.Keeper
|
||||
ibcKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
|
||||
packetForwardKeeper *packetforwardkeeper.Keeper
|
||||
evmKeeper *evmkeeper.Keeper
|
||||
evmutilKeeper evmutilkeeper.Keeper
|
||||
feeMarketKeeper feemarketkeeper.Keeper
|
||||
@ -375,7 +380,7 @@ func NewApp(
|
||||
|
||||
keys := sdk.NewKVStoreKeys(
|
||||
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
|
||||
distrtypes.StoreKey, slashingtypes.StoreKey,
|
||||
distrtypes.StoreKey, slashingtypes.StoreKey, packetforwardtypes.StoreKey,
|
||||
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey,
|
||||
upgradetypes.StoreKey, evidencetypes.StoreKey, ibctransfertypes.StoreKey,
|
||||
evmtypes.StoreKey, feemarkettypes.StoreKey, authzkeeper.StoreKey,
|
||||
@ -429,6 +434,7 @@ func NewApp(
|
||||
savingsSubspace := app.paramsKeeper.Subspace(savingstypes.ModuleName)
|
||||
ibcSubspace := app.paramsKeeper.Subspace(ibcexported.ModuleName)
|
||||
ibctransferSubspace := app.paramsKeeper.Subspace(ibctransfertypes.ModuleName)
|
||||
packetforwardSubspace := app.paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable())
|
||||
feemarketSubspace := app.paramsKeeper.Subspace(feemarkettypes.ModuleName)
|
||||
evmSubspace := app.paramsKeeper.Subspace(evmtypes.ModuleName)
|
||||
evmutilSubspace := app.paramsKeeper.Subspace(evmutiltypes.ModuleName)
|
||||
@ -551,23 +557,49 @@ func NewApp(
|
||||
|
||||
app.evmutilKeeper.SetEvmKeeper(app.evmKeeper)
|
||||
|
||||
// It's important to note that the PFM Keeper must be initialized before the Transfer Keeper
|
||||
app.packetForwardKeeper = packetforwardkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[packetforwardtypes.StoreKey],
|
||||
nil, // will be zero-value here, reference is set later on with SetTransferKeeper.
|
||||
app.ibcKeeper.ChannelKeeper,
|
||||
app.distrKeeper,
|
||||
app.bankKeeper,
|
||||
app.ibcKeeper.ChannelKeeper,
|
||||
govAuthAddrStr,
|
||||
)
|
||||
|
||||
app.transferKeeper = ibctransferkeeper.NewKeeper(
|
||||
appCodec,
|
||||
keys[ibctransfertypes.StoreKey],
|
||||
ibctransferSubspace,
|
||||
app.ibcKeeper.ChannelKeeper,
|
||||
app.packetForwardKeeper,
|
||||
app.ibcKeeper.ChannelKeeper,
|
||||
&app.ibcKeeper.PortKeeper,
|
||||
app.accountKeeper,
|
||||
app.bankKeeper,
|
||||
scopedTransferKeeper,
|
||||
)
|
||||
app.packetForwardKeeper.SetTransferKeeper(app.transferKeeper)
|
||||
transferModule := transfer.NewAppModule(app.transferKeeper)
|
||||
transferIBCModule := transfer.NewIBCModule(app.transferKeeper)
|
||||
|
||||
// allow ibc packet forwarding for ibc transfers.
|
||||
// transfer stack contains (from top to bottom):
|
||||
// - Packet Forward Middleware
|
||||
// - Transfer
|
||||
var transferStack ibcporttypes.IBCModule
|
||||
transferStack = transfer.NewIBCModule(app.transferKeeper)
|
||||
transferStack = packetforward.NewIBCMiddleware(
|
||||
transferStack,
|
||||
app.packetForwardKeeper,
|
||||
0, // retries on timeout
|
||||
packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
|
||||
packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
|
||||
)
|
||||
|
||||
// Create static IBC router, add transfer route, then set and seal it
|
||||
ibcRouter := porttypes.NewRouter()
|
||||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferIBCModule)
|
||||
ibcRouter := ibcporttypes.NewRouter()
|
||||
ibcRouter.AddRoute(ibctransfertypes.ModuleName, transferStack)
|
||||
app.ibcKeeper.SetRouter(ibcRouter)
|
||||
|
||||
app.auctionKeeper = auctionkeeper.NewKeeper(
|
||||
@ -789,6 +821,7 @@ func NewApp(
|
||||
slashing.NewAppModule(appCodec, app.slashingKeeper, app.accountKeeper, app.bankKeeper, app.stakingKeeper, slashingSubspace),
|
||||
consensus.NewAppModule(appCodec, app.consensusParamsKeeper),
|
||||
ibc.NewAppModule(app.ibcKeeper),
|
||||
packetforward.NewAppModule(app.packetForwardKeeper, packetforwardSubspace),
|
||||
evm.NewAppModule(app.evmKeeper, app.accountKeeper),
|
||||
feemarket.NewAppModule(app.feeMarketKeeper, feemarketSubspace),
|
||||
upgrade.NewAppModule(&app.upgradeKeeper),
|
||||
@ -870,6 +903,7 @@ func NewApp(
|
||||
earntypes.ModuleName,
|
||||
routertypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
)
|
||||
|
||||
// Warning: Some end blockers must run before others. Ensure the dependencies are understood before modifying this list.
|
||||
@ -914,6 +948,7 @@ func NewApp(
|
||||
communitytypes.ModuleName,
|
||||
metricstypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
)
|
||||
|
||||
// Warning: Some init genesis methods must run before others. Ensure the dependencies are understood before modifying this list
|
||||
@ -956,6 +991,7 @@ func NewApp(
|
||||
routertypes.ModuleName,
|
||||
metricstypes.ModuleName,
|
||||
consensusparamtypes.ModuleName,
|
||||
packetforwardtypes.ModuleName,
|
||||
crisistypes.ModuleName, // runs the invariants at genesis, should run after other modules
|
||||
)
|
||||
|
||||
|
4
ci/env/kava-internal-testnet/genesis.json
vendored
4
ci/env/kava-internal-testnet/genesis.json
vendored
@ -582,6 +582,10 @@
|
||||
"denom": "erc20/axelar/wbtc",
|
||||
"amount": "1000000000"
|
||||
},
|
||||
{
|
||||
"denom": "erc20/tether/usdt",
|
||||
"amount": "100000000000"
|
||||
},
|
||||
{
|
||||
"denom": "hard",
|
||||
"amount": "1000000000"
|
||||
|
6
ci/env/kava-protonet/genesis.json
vendored
6
ci/env/kava-protonet/genesis.json
vendored
@ -3000,6 +3000,12 @@
|
||||
}
|
||||
},
|
||||
"params": null,
|
||||
"packetfowardmiddleware": {
|
||||
"params": {
|
||||
"fee_percentage": "0.000000000000000000"
|
||||
},
|
||||
"in_flight_packets": {}
|
||||
},
|
||||
"pricefeed": {
|
||||
"params": {
|
||||
"markets": [
|
||||
|
@ -31,6 +31,7 @@ import (
|
||||
const (
|
||||
flagMempoolEnableAuth = "mempool.enable-authentication"
|
||||
flagMempoolAuthAddresses = "mempool.authorized-addresses"
|
||||
flagSkipLoadLatest = "skip-load-latest"
|
||||
)
|
||||
|
||||
// appCreator holds functions used by the sdk server to control the kava app.
|
||||
@ -101,10 +102,15 @@ func (ac appCreator) newApp(
|
||||
chainID = appGenesis.ChainID
|
||||
}
|
||||
|
||||
skipLoadLatest := false
|
||||
if appOpts.Get(flagSkipLoadLatest) != nil {
|
||||
skipLoadLatest = cast.ToBool(appOpts.Get(flagSkipLoadLatest))
|
||||
}
|
||||
|
||||
return app.NewApp(
|
||||
logger, db, homeDir, traceStore, ac.encodingConfig,
|
||||
app.Options{
|
||||
SkipLoadLatest: false,
|
||||
SkipLoadLatest: skipLoadLatest,
|
||||
SkipUpgradeHeights: skipUpgradeHeights,
|
||||
SkipGenesisInvariants: cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants)),
|
||||
InvariantCheckPeriod: cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
dbm "github.com/cometbft/cometbft-db"
|
||||
@ -23,9 +24,11 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
flagShardStartBlock = "start"
|
||||
flagShardEndBlock = "end"
|
||||
flagShardOnlyAppState = "only-app-state"
|
||||
flagShardStartBlock = "start"
|
||||
flagShardEndBlock = "end"
|
||||
flagShardOnlyAppState = "only-app-state"
|
||||
flagShardForceAppVersion = "force-app-version"
|
||||
flagShardOnlyCometbftState = "only-cometbft-state"
|
||||
// TODO: --preserve flag for creating & operating on a copy?
|
||||
|
||||
// allow using -1 to mean "latest" (perform no rollbacks)
|
||||
@ -34,7 +37,7 @@ const (
|
||||
|
||||
func newShardCmd(opts ethermintserver.StartOptions) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state]",
|
||||
Use: "shard --home <path-to-home-dir> --start <start-block> --end <end-block> [--only-app-state] [--only-cometbft-state] [--force-app-version <app-version>]",
|
||||
Short: "Strip all blocks from the database outside of a given range",
|
||||
Long: `shard opens a local kava home directory's databases and removes all blocks outside a range defined by --start and --end. The range is inclusive of the end block.
|
||||
|
||||
@ -42,8 +45,14 @@ It works by first rolling back the latest state to the block before the end bloc
|
||||
|
||||
Setting the end block to -1 signals to keep the latest block (no rollbacks).
|
||||
|
||||
The application.db can be loaded at a particular height via the --force-app-version option. This is useful if the sharding process is prematurely terminated while the application.db is being sharded.
|
||||
|
||||
The --only-app-state flag can be used to skip the pruning of the blockstore and cometbft state. This matches the functionality of the cosmos-sdk's "prune" command. Note that rolled back blocks will still affect all stores.
|
||||
|
||||
Similarly, the --only-cometbft-state flag skips pruning app state. This can be useful if the shard command is prematurely terminated during the shard process.
|
||||
|
||||
The shard command only flags the iavl tree nodes for deletion. Actual removal from the databases will be performed when each database is compacted.
|
||||
|
||||
WARNING: this is a destructive action.`,
|
||||
Example: `Create a 1M block data shard (keeps blocks kava 1,000,000 to 2,000,000)
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end 2000000
|
||||
@ -54,7 +63,9 @@ $ kava shard --home path/to/.kava --start 5000000 --end -1
|
||||
Prune first 1M blocks _without_ affecting blockstore or cometBFT state:
|
||||
$ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
// read & validate flags
|
||||
//////////////////////////
|
||||
// parse & validate flags
|
||||
//////////////////////////
|
||||
startBlock, err := cmd.Flags().GetInt64(flagShardStartBlock)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -70,16 +81,23 @@ $ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
forceAppVersion, err := cmd.Flags().GetInt64(flagShardForceAppVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
onlyCometbftState, err := cmd.Flags().GetBool(flagShardOnlyCometbftState)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
clientCtx := client.GetClientContextFromCmd(cmd)
|
||||
|
||||
ctx := server.GetServerContextFromCmd(cmd)
|
||||
ctx.Config.SetRoot(clientCtx.HomeDir)
|
||||
|
||||
//////////////////////////////
|
||||
// Rollback state to endBlock
|
||||
//////////////////////////////
|
||||
|
||||
////////////////////////
|
||||
// manage db connection
|
||||
////////////////////////
|
||||
// connect to database
|
||||
db, err := opts.DBOpener(ctx.Viper, clientCtx.HomeDir, server.GetAppDBBackend(ctx.Viper))
|
||||
if err != nil {
|
||||
@ -93,109 +111,59 @@ $ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
}
|
||||
}()
|
||||
|
||||
///////////////////
|
||||
// load multistore
|
||||
///////////////////
|
||||
// create app in order to load the multistore
|
||||
// skip loading the latest version so the desired height can be manually loaded
|
||||
ctx.Viper.Set("skip-load-latest", true)
|
||||
|
||||
app := opts.AppCreator(ctx.Logger, db, nil, ctx.Viper).(*app.App)
|
||||
if forceAppVersion == shardEndBlockLatest {
|
||||
if err := app.LoadLatestVersion(); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := app.LoadVersion(forceAppVersion); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
// get the multistore
|
||||
app := opts.AppCreator(ctx.Logger, db, nil, ctx.Viper)
|
||||
cms := app.CommitMultiStore()
|
||||
multistore, ok := cms.(*rootmulti.Store)
|
||||
if !ok {
|
||||
return fmt.Errorf("only sharding of rootmulti.Store type is supported")
|
||||
}
|
||||
|
||||
// handle desired endblock being latest
|
||||
latest := multistore.LatestVersion()
|
||||
fmt.Printf("latest height: %d\n", latest)
|
||||
if endBlock == shardEndBlockLatest {
|
||||
endBlock = latest
|
||||
}
|
||||
shardSize := endBlock - startBlock + 1
|
||||
|
||||
// error if requesting block range the database does not have
|
||||
if endBlock > latest {
|
||||
return fmt.Errorf("data does not contain end block (%d): latest version is %d", endBlock, latest)
|
||||
}
|
||||
|
||||
fmt.Printf("pruning data in %s down to heights %d - %d (%d blocks)\n", clientCtx.HomeDir, startBlock, endBlock, shardSize)
|
||||
|
||||
// set pruning options to prevent no-ops from `PruneStores`
|
||||
multistore.SetPruning(pruningtypes.PruningOptions{KeepRecent: uint64(shardSize), Interval: 0})
|
||||
|
||||
// rollback application state
|
||||
if err = multistore.RollbackToVersion(endBlock); err != nil {
|
||||
return fmt.Errorf("failed to rollback application state: %s", err)
|
||||
////////////////////////
|
||||
// shard application.db
|
||||
////////////////////////
|
||||
if !onlyCometbftState {
|
||||
if err := shardApplicationDb(multistore, startBlock, endBlock); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("[%s] skipping sharding of application.db\n", flagShardOnlyCometbftState)
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
// shard blockstore.db & state.db
|
||||
//////////////////////////////////
|
||||
// open block store & cometbft state
|
||||
blockStore, stateStore, err := openCometBftDbs(ctx.Config)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to open cometbft dbs: %s", err)
|
||||
}
|
||||
|
||||
// prep for outputting progress repeatedly to same line
|
||||
needsRollback := endBlock < latest
|
||||
progress := "rolling back blockstore & cometbft state to height %d"
|
||||
numChars := len(fmt.Sprintf(progress, latest))
|
||||
clearLine := fmt.Sprintf("\r%s\r", strings.Repeat(" ", numChars))
|
||||
printRollbackProgress := func(h int64) {
|
||||
fmt.Print(clearLine)
|
||||
fmt.Printf(progress, h)
|
||||
}
|
||||
|
||||
// rollback tendermint db
|
||||
height := latest
|
||||
for height > endBlock {
|
||||
printRollbackProgress(height - 1)
|
||||
height, _, err = tmstate.Rollback(blockStore, stateStore, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rollback tendermint state: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
if needsRollback {
|
||||
fmt.Println()
|
||||
} else {
|
||||
fmt.Printf("latest store height is already %d\n", latest)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Prune blocks to startBlock
|
||||
//////////////////////////////
|
||||
|
||||
// enumerate all heights to prune
|
||||
pruneHeights := make([]int64, 0, latest-shardSize)
|
||||
for i := int64(1); i < startBlock; i++ {
|
||||
pruneHeights = append(pruneHeights, i)
|
||||
}
|
||||
|
||||
if len(pruneHeights) > 0 {
|
||||
// prune application state
|
||||
fmt.Printf("pruning application state to height %d\n", startBlock)
|
||||
if err := multistore.PruneStores(true, pruneHeights); err != nil {
|
||||
return fmt.Errorf("failed to prune application state: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// get starting block of block store
|
||||
baseBlock := blockStore.Base()
|
||||
|
||||
// only prune if data exists, otherwise blockStore.PruneBlocks will panic
|
||||
if !onlyAppState && baseBlock < startBlock {
|
||||
// prune block store
|
||||
fmt.Printf("pruning block store from %d - %d\n", baseBlock, startBlock)
|
||||
if _, err := blockStore.PruneBlocks(startBlock); err != nil {
|
||||
return fmt.Errorf("failed to prune block store (retainHeight=%d): %s", startBlock, err)
|
||||
}
|
||||
|
||||
// prune cometbft state
|
||||
fmt.Printf("pruning cometbft state from %d - %d\n", baseBlock, startBlock)
|
||||
if err := stateStore.PruneStates(baseBlock, startBlock); err != nil {
|
||||
return fmt.Errorf("failed to prune cometbft state store (%d - %d): %s", baseBlock, startBlock, err)
|
||||
if !onlyAppState {
|
||||
if err := shardCometBftDbs(blockStore, stateStore, startBlock, endBlock); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("blockstore and cometbft state begins at block %d\n", baseBlock)
|
||||
fmt.Printf("[%s] skipping sharding of blockstore.db and state.db\n", flagShardOnlyAppState)
|
||||
fmt.Printf("blockstore contains blocks %d - %d\n", blockStore.Base(), blockStore.Height())
|
||||
}
|
||||
|
||||
// TODO: db compaction
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@ -204,10 +172,130 @@ $ kava shard --home path/to/.kava --start 1000000 --end -1 --only-app-state`,
|
||||
cmd.Flags().Int64(flagShardStartBlock, 1, "Start block of data shard (inclusive)")
|
||||
cmd.Flags().Int64(flagShardEndBlock, 0, "End block of data shard (inclusive)")
|
||||
cmd.Flags().Bool(flagShardOnlyAppState, false, "Skip pruning of blockstore & cometbft state")
|
||||
cmd.Flags().Bool(flagShardOnlyCometbftState, false, "Skip pruning of application state")
|
||||
cmd.Flags().Int64(flagShardForceAppVersion, shardEndBlockLatest, "Instead of loading latest, force set the version of the multistore that is loaded")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// shardApplicationDb prunes the multistore up to startBlock and rolls it back to endBlock
|
||||
func shardApplicationDb(multistore *rootmulti.Store, startBlock, endBlock int64) error {
|
||||
//////////////////////////////
|
||||
// Rollback state to endBlock
|
||||
//////////////////////////////
|
||||
// handle desired endblock being latest
|
||||
latest := multistore.LastCommitID().Version
|
||||
if latest == 0 {
|
||||
return fmt.Errorf("failed to find latest height >0")
|
||||
}
|
||||
fmt.Printf("latest height: %d\n", latest)
|
||||
if endBlock == shardEndBlockLatest {
|
||||
endBlock = latest
|
||||
}
|
||||
shardSize := endBlock - startBlock + 1
|
||||
|
||||
// error if requesting block range the database does not have
|
||||
if endBlock > latest {
|
||||
return fmt.Errorf("data does not contain end block (%d): latest version is %d", endBlock, latest)
|
||||
}
|
||||
|
||||
fmt.Printf("pruning data down to heights %d - %d (%d blocks)\n", startBlock, endBlock, shardSize)
|
||||
|
||||
// set pruning options to prevent no-ops from `PruneStores`
|
||||
multistore.SetPruning(pruningtypes.PruningOptions{KeepRecent: uint64(shardSize), Interval: 0})
|
||||
|
||||
// rollback application state
|
||||
if err := multistore.RollbackToVersion(endBlock); err != nil {
|
||||
return fmt.Errorf("failed to rollback application state: %s", err)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Prune blocks to startBlock
|
||||
//////////////////////////////
|
||||
// enumerate all heights to prune
|
||||
pruneHeights := make([]int64, 0, latest-shardSize)
|
||||
for i := int64(1); i < startBlock; i++ {
|
||||
pruneHeights = append(pruneHeights, i)
|
||||
}
|
||||
|
||||
if len(pruneHeights) > 0 {
|
||||
// prune application state
|
||||
fmt.Printf("pruning application state to height %d\n", startBlock)
|
||||
if err := multistore.PruneStores(true, pruneHeights); err != nil {
|
||||
return fmt.Errorf("failed to prune application state: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// shardCometBftDbs shrinks blockstore.db & state.db down to the desired block range
|
||||
func shardCometBftDbs(blockStore *store.BlockStore, stateStore tmstate.Store, startBlock, endBlock int64) error {
|
||||
var err error
|
||||
latest := blockStore.Height()
|
||||
if endBlock == shardEndBlockLatest {
|
||||
endBlock = latest
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Rollback state to endBlock
|
||||
//////////////////////////////
|
||||
// prep for outputting progress repeatedly to same line
|
||||
needsRollback := endBlock < latest
|
||||
progress := "rolling back blockstore & cometbft state to height %d"
|
||||
numChars := len(fmt.Sprintf(progress, latest))
|
||||
clearLine := fmt.Sprintf("\r%s\r", strings.Repeat(" ", numChars))
|
||||
printRollbackProgress := func(h int64) {
|
||||
fmt.Print(clearLine)
|
||||
fmt.Printf(progress, h)
|
||||
}
|
||||
|
||||
// rollback tendermint db
|
||||
height := latest
|
||||
for height > endBlock {
|
||||
beforeRollbackHeight := height
|
||||
printRollbackProgress(height - 1)
|
||||
height, _, err = tmstate.Rollback(blockStore, stateStore, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rollback cometbft state: %w", err)
|
||||
}
|
||||
if beforeRollbackHeight == height {
|
||||
return fmt.Errorf("attempting to rollback cometbft state height %d failed (no rollback performed)", height)
|
||||
}
|
||||
}
|
||||
|
||||
if needsRollback {
|
||||
fmt.Println()
|
||||
} else {
|
||||
fmt.Printf("latest store height is already %d\n", latest)
|
||||
}
|
||||
|
||||
//////////////////////////////
|
||||
// Prune blocks to startBlock
|
||||
//////////////////////////////
|
||||
// get starting block of block store
|
||||
baseBlock := blockStore.Base()
|
||||
|
||||
// only prune if data exists, otherwise blockStore.PruneBlocks will panic
|
||||
if baseBlock < startBlock {
|
||||
// prune block store
|
||||
fmt.Printf("pruning block store from %d - %d\n", baseBlock, startBlock)
|
||||
if _, err := blockStore.PruneBlocks(startBlock); err != nil {
|
||||
return fmt.Errorf("failed to prune block store (retainHeight=%d): %s", startBlock, err)
|
||||
}
|
||||
|
||||
// prune cometbft state
|
||||
fmt.Printf("pruning cometbft state from %d - %d\n", baseBlock, startBlock)
|
||||
if err := stateStore.PruneStates(baseBlock, startBlock); err != nil {
|
||||
return fmt.Errorf("failed to prune cometbft state store (%d - %d): %s", baseBlock, startBlock, err)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("blockstore and cometbft state begins at block %d\n", baseBlock)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// inspired by https://github.com/Kava-Labs/cometbft/blob/277b0853db3f67865a55aa1c54f59790b5f591be/node/node.go#L234
|
||||
func openCometBftDbs(config *tmconfig.Config) (blockStore *store.BlockStore, stateStore tmstate.Store, err error) {
|
||||
dbProvider := node.DefaultDBProvider
|
||||
|
@ -580,6 +580,24 @@
|
||||
|
||||
- [Msg](#kava.swap.v1beta1.Msg)
|
||||
|
||||
- [kava/validatorvesting/v1beta1/query.proto](#kava/validatorvesting/v1beta1/query.proto)
|
||||
- [QueryCirculatingSupplyHARDRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDRequest)
|
||||
- [QueryCirculatingSupplyHARDResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDResponse)
|
||||
- [QueryCirculatingSupplyRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyRequest)
|
||||
- [QueryCirculatingSupplyResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyResponse)
|
||||
- [QueryCirculatingSupplySWPRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPRequest)
|
||||
- [QueryCirculatingSupplySWPResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPResponse)
|
||||
- [QueryCirculatingSupplyUSDXRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXRequest)
|
||||
- [QueryCirculatingSupplyUSDXResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXResponse)
|
||||
- [QueryTotalSupplyHARDRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyHARDRequest)
|
||||
- [QueryTotalSupplyHARDResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyHARDResponse)
|
||||
- [QueryTotalSupplyRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyRequest)
|
||||
- [QueryTotalSupplyResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyResponse)
|
||||
- [QueryTotalSupplyUSDXRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXRequest)
|
||||
- [QueryTotalSupplyUSDXResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXResponse)
|
||||
|
||||
- [Query](#kava.validatorvesting.v1beta1.Query)
|
||||
|
||||
- [Scalar Value Types](#scalar-value-types)
|
||||
|
||||
|
||||
@ -7861,6 +7879,213 @@ Msg defines the swap Msg service.
|
||||
|
||||
|
||||
|
||||
<a name="kava/validatorvesting/v1beta1/query.proto"></a>
|
||||
<p align="right"><a href="#top">Top</a></p>
|
||||
|
||||
## kava/validatorvesting/v1beta1/query.proto
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDRequest"></a>
|
||||
|
||||
### QueryCirculatingSupplyHARDRequest
|
||||
QueryCirculatingSupplyHARDRequest is the request type for the Query/CirculatingSupplyHARD RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDResponse"></a>
|
||||
|
||||
### QueryCirculatingSupplyHARDResponse
|
||||
QueryCirculatingSupplyHARDResponse is the response type for the Query/CirculatingSupplyHARD RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyRequest"></a>
|
||||
|
||||
### QueryCirculatingSupplyRequest
|
||||
QueryCirculatingSupplyRequest is the request type for the Query/CirculatingSupply RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyResponse"></a>
|
||||
|
||||
### QueryCirculatingSupplyResponse
|
||||
QueryCirculatingSupplyResponse is the response type for the Query/CirculatingSupply RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPRequest"></a>
|
||||
|
||||
### QueryCirculatingSupplySWPRequest
|
||||
QueryCirculatingSupplySWPRequest is the request type for the Query/CirculatingSupplySWP RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPResponse"></a>
|
||||
|
||||
### QueryCirculatingSupplySWPResponse
|
||||
QueryCirculatingSupplySWPResponse is the response type for the Query/CirculatingSupplySWP RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXRequest"></a>
|
||||
|
||||
### QueryCirculatingSupplyUSDXRequest
|
||||
QueryCirculatingSupplyUSDXRequest is the request type for the Query/CirculatingSupplyUSDX RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXResponse"></a>
|
||||
|
||||
### QueryCirculatingSupplyUSDXResponse
|
||||
QueryCirculatingSupplyUSDXResponse is the response type for the Query/CirculatingSupplyUSDX RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyHARDRequest"></a>
|
||||
|
||||
### QueryTotalSupplyHARDRequest
|
||||
QueryTotalSupplyHARDRequest is the request type for the Query/TotalSupplyHARD RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyHARDResponse"></a>
|
||||
|
||||
### QueryTotalSupplyHARDResponse
|
||||
QueryTotalSupplyHARDResponse is the response type for the Query/TotalSupplyHARD RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyRequest"></a>
|
||||
|
||||
### QueryTotalSupplyRequest
|
||||
QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyResponse"></a>
|
||||
|
||||
### QueryTotalSupplyResponse
|
||||
QueryTotalSupplyResponse is the response type for the Query/TotalSupply RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXRequest"></a>
|
||||
|
||||
### QueryTotalSupplyUSDXRequest
|
||||
QueryTotalSupplyUSDXRequest is the request type for the Query/TotalSupplyUSDX RPC method
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXResponse"></a>
|
||||
|
||||
### QueryTotalSupplyUSDXResponse
|
||||
QueryTotalSupplyUSDXResponse is the response type for the Query/TotalSupplyUSDX RPC method
|
||||
|
||||
|
||||
| Field | Type | Label | Description |
|
||||
| ----- | ---- | ----- | ----------- |
|
||||
| `amount` | [string](#string) | | |
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<!-- end messages -->
|
||||
|
||||
<!-- end enums -->
|
||||
|
||||
<!-- end HasExtensions -->
|
||||
|
||||
|
||||
<a name="kava.validatorvesting.v1beta1.Query"></a>
|
||||
|
||||
### Query
|
||||
Query defines the gRPC querier service for validator-vesting module
|
||||
|
||||
| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
|
||||
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
|
||||
| `CirculatingSupply` | [QueryCirculatingSupplyRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyRequest) | [QueryCirculatingSupplyResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyResponse) | CirculatingSupply returns the total amount of kava tokens in circulation | GET|/kava/validator-vesting/v1beta1/circulating_supply|
|
||||
| `TotalSupply` | [QueryTotalSupplyRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyRequest) | [QueryTotalSupplyResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyResponse) | TotalSupply returns the total amount of kava tokens | GET|/kava/validator-vesting/v1beta1/total_supply|
|
||||
| `CirculatingSupplyHARD` | [QueryCirculatingSupplyHARDRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDRequest) | [QueryCirculatingSupplyHARDResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyHARDResponse) | CirculatingSupplyHARD returns the total amount of hard tokens in circulation | GET|/kava/validator-vesting/v1beta1/circulating_supply_hard|
|
||||
| `CirculatingSupplyUSDX` | [QueryCirculatingSupplyUSDXRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXRequest) | [QueryCirculatingSupplyUSDXResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplyUSDXResponse) | CirculatingSupplyUSDX returns the total amount of usdx tokens in circulation | GET|/kava/validator-vesting/v1beta1/circulating_supply_usdx|
|
||||
| `CirculatingSupplySWP` | [QueryCirculatingSupplySWPRequest](#kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPRequest) | [QueryCirculatingSupplySWPResponse](#kava.validatorvesting.v1beta1.QueryCirculatingSupplySWPResponse) | CirculatingSupplySWP returns the total amount of swp tokens in circulation | GET|/kava/validator-vesting/v1beta1/circulating_supply_swp|
|
||||
| `TotalSupplyHARD` | [QueryTotalSupplyHARDRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyHARDRequest) | [QueryTotalSupplyHARDResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyHARDResponse) | TotalSupplyHARD returns the total amount of hard tokens | GET|/kava/validator-vesting/v1beta1/total_supply_hard|
|
||||
| `TotalSupplyUSDX` | [QueryTotalSupplyUSDXRequest](#kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXRequest) | [QueryTotalSupplyUSDXResponse](#kava.validatorvesting.v1beta1.QueryTotalSupplyUSDXResponse) | TotalSupplyUSDX returns the total amount of usdx tokens | GET|/kava/validator-vesting/v1beta1/total_supply_usdx|
|
||||
|
||||
<!-- end services -->
|
||||
|
||||
|
||||
|
||||
## Scalar Value Types
|
||||
|
||||
| .proto Type | Notes | C++ | Java | Python | Go | C# | PHP | Ruby |
|
||||
|
2
go.mod
2
go.mod
@ -13,6 +13,7 @@ require (
|
||||
github.com/cosmos/cosmos-sdk v0.47.7
|
||||
github.com/cosmos/go-bip39 v1.0.0
|
||||
github.com/cosmos/gogoproto v1.4.10
|
||||
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.2
|
||||
github.com/cosmos/ibc-go/v7 v7.3.1
|
||||
github.com/ethereum/go-ethereum v1.10.26
|
||||
github.com/evmos/ethermint v0.21.0
|
||||
@ -133,6 +134,7 @@ require (
|
||||
github.com/holiman/uint256 v1.2.1 // indirect
|
||||
github.com/huandu/skiplist v1.2.0 // indirect
|
||||
github.com/huin/goupnp v1.0.3 // indirect
|
||||
github.com/iancoleman/orderedmap v0.2.0 // indirect
|
||||
github.com/improbable-eng/grpc-web v0.15.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
|
||||
|
6
go.sum
6
go.sum
@ -416,6 +416,8 @@ github.com/cosmos/gogoproto v1.4.10 h1:QH/yT8X+c0F4ZDacDv3z+xE3WU1P1Z3wQoLMBRJoK
|
||||
github.com/cosmos/gogoproto v1.4.10/go.mod h1:3aAZzeRWpAwr+SS/LLkICX2/kDFyaYVzckBDzygIxek=
|
||||
github.com/cosmos/iavl v0.20.1 h1:rM1kqeG3/HBT85vsZdoSNsehciqUQPWrR4BYmqE2+zg=
|
||||
github.com/cosmos/iavl v0.20.1/go.mod h1:WO7FyvaZJoH65+HFOsDir7xU9FWk2w9cHXNW1XHcl7A=
|
||||
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.2 h1:6zjj+yIpMbCTRI2eJ2fXuflElENs3mrUSLH/TSWL8fk=
|
||||
github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7 v7.1.2/go.mod h1:UvDmcGIWJPIytq+Q78/ff5NTOsuX/7IrNgEugTW5i0s=
|
||||
github.com/cosmos/ibc-go/v7 v7.3.1 h1:bil1IjnHdyWDASFYKfwdRiNtFP6WK3osW7QFEAgU4I8=
|
||||
github.com/cosmos/ibc-go/v7 v7.3.1/go.mod h1:wvx4pPBofe5ZdMNV3OFRxSI4auEP5Qfqf8JXLLNV04g=
|
||||
github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM=
|
||||
@ -813,6 +815,8 @@ github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj
|
||||
github.com/huin/goupnp v1.0.3 h1:N8No57ls+MnjlB+JPiCVSOyy/ot7MJTqlo7rn+NYSqQ=
|
||||
github.com/huin/goupnp v1.0.3/go.mod h1:ZxNlw5WqJj6wSsRK5+YfflQGXYfccj5VgQsMNixHM7Y=
|
||||
github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o=
|
||||
github.com/iancoleman/orderedmap v0.2.0 h1:sq1N/TFpYH++aViPcaKjys3bDClUEU7s5B+z6jq8pNA=
|
||||
github.com/iancoleman/orderedmap v0.2.0/go.mod h1:N0Wam8K1arqPXNWjMo21EXnBPOPp36vB07FNRdD2geA=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/improbable-eng/grpc-web v0.15.0 h1:BN+7z6uNXZ1tQGcNAuaU1YjsLTApzkjt2tzCixLaUPQ=
|
||||
@ -1292,6 +1296,8 @@ go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqe
|
||||
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
|
||||
go.uber.org/mock v0.2.0 h1:TaP3xedm7JaAgScZO7tlvlKrqT0p7I6OsdGB5YNSMDU=
|
||||
go.uber.org/mock v0.2.0/go.mod h1:J0y0rp9L3xiff1+ZBfKxlC1fz2+aO16tw0tsDOixfuM=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
|
||||
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
|
||||
|
131
proto/kava/validatorvesting/v1beta1/query.proto
Normal file
131
proto/kava/validatorvesting/v1beta1/query.proto
Normal file
@ -0,0 +1,131 @@
|
||||
syntax = "proto3";
|
||||
package kava.validatorvesting.v1beta1;
|
||||
|
||||
import "cosmos_proto/cosmos.proto";
|
||||
import "gogoproto/gogo.proto";
|
||||
import "google/api/annotations.proto";
|
||||
|
||||
option go_package = "github.com/kava-labs/kava/x/validator-vesting/types";
|
||||
option (gogoproto.goproto_getters_all) = false;
|
||||
|
||||
// Query defines the gRPC querier service for validator-vesting module
|
||||
service Query {
|
||||
// CirculatingSupply returns the total amount of kava tokens in circulation
|
||||
rpc CirculatingSupply(QueryCirculatingSupplyRequest) returns (QueryCirculatingSupplyResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/circulating_supply";
|
||||
}
|
||||
|
||||
// TotalSupply returns the total amount of kava tokens
|
||||
rpc TotalSupply(QueryTotalSupplyRequest) returns (QueryTotalSupplyResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/total_supply";
|
||||
}
|
||||
|
||||
// CirculatingSupplyHARD returns the total amount of hard tokens in circulation
|
||||
rpc CirculatingSupplyHARD(QueryCirculatingSupplyHARDRequest) returns (QueryCirculatingSupplyHARDResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/circulating_supply_hard";
|
||||
}
|
||||
|
||||
// CirculatingSupplyUSDX returns the total amount of usdx tokens in circulation
|
||||
rpc CirculatingSupplyUSDX(QueryCirculatingSupplyUSDXRequest) returns (QueryCirculatingSupplyUSDXResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/circulating_supply_usdx";
|
||||
}
|
||||
|
||||
// CirculatingSupplySWP returns the total amount of swp tokens in circulation
|
||||
rpc CirculatingSupplySWP(QueryCirculatingSupplySWPRequest) returns (QueryCirculatingSupplySWPResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/circulating_supply_swp";
|
||||
}
|
||||
|
||||
// TotalSupplyHARD returns the total amount of hard tokens
|
||||
rpc TotalSupplyHARD(QueryTotalSupplyHARDRequest) returns (QueryTotalSupplyHARDResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/total_supply_hard";
|
||||
}
|
||||
|
||||
// TotalSupplyUSDX returns the total amount of usdx tokens
|
||||
rpc TotalSupplyUSDX(QueryTotalSupplyUSDXRequest) returns (QueryTotalSupplyUSDXResponse) {
|
||||
option (google.api.http).get = "/kava/validator-vesting/v1beta1/total_supply_usdx";
|
||||
}
|
||||
}
|
||||
|
||||
// QueryCirculatingSupplyRequest is the request type for the Query/CirculatingSupply RPC method
|
||||
message QueryCirculatingSupplyRequest {}
|
||||
|
||||
// QueryCirculatingSupplyResponse is the response type for the Query/CirculatingSupply RPC method
|
||||
message QueryCirculatingSupplyResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryTotalSupplyRequest is the request type for the Query/TotalSupply RPC method
|
||||
message QueryTotalSupplyRequest {}
|
||||
|
||||
// QueryTotalSupplyResponse is the response type for the Query/TotalSupply RPC method
|
||||
message QueryTotalSupplyResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryCirculatingSupplyHARDRequest is the request type for the Query/CirculatingSupplyHARD RPC method
|
||||
message QueryCirculatingSupplyHARDRequest {}
|
||||
|
||||
// QueryCirculatingSupplyHARDResponse is the response type for the Query/CirculatingSupplyHARD RPC method
|
||||
message QueryCirculatingSupplyHARDResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryCirculatingSupplyUSDXRequest is the request type for the Query/CirculatingSupplyUSDX RPC method
|
||||
message QueryCirculatingSupplyUSDXRequest {}
|
||||
|
||||
// QueryCirculatingSupplyUSDXResponse is the response type for the Query/CirculatingSupplyUSDX RPC method
|
||||
message QueryCirculatingSupplyUSDXResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryCirculatingSupplySWPRequest is the request type for the Query/CirculatingSupplySWP RPC method
|
||||
message QueryCirculatingSupplySWPRequest {}
|
||||
|
||||
// QueryCirculatingSupplySWPResponse is the response type for the Query/CirculatingSupplySWP RPC method
|
||||
message QueryCirculatingSupplySWPResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryTotalSupplyHARDRequest is the request type for the Query/TotalSupplyHARD RPC method
|
||||
message QueryTotalSupplyHARDRequest {}
|
||||
|
||||
// QueryTotalSupplyHARDResponse is the response type for the Query/TotalSupplyHARD RPC method
|
||||
message QueryTotalSupplyHARDResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
||||
|
||||
// QueryTotalSupplyUSDXRequest is the request type for the Query/TotalSupplyUSDX RPC method
|
||||
message QueryTotalSupplyUSDXRequest {}
|
||||
|
||||
// QueryTotalSupplyUSDXResponse is the response type for the Query/TotalSupplyUSDX RPC method
|
||||
message QueryTotalSupplyUSDXResponse {
|
||||
string amount = 1 [
|
||||
(cosmos_proto.scalar) = "cosmos.Int",
|
||||
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||
(gogoproto.nullable) = false
|
||||
];
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
|
||||
"github.com/kava-labs/kava/x/auction/types"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultPage = 1
|
||||
defaultLimit = 100
|
||||
)
|
||||
|
||||
// QueryAuctionByID returns an auction from state if present or falls back to searching old blocks
|
||||
func QueryAuctionByID(cliCtx client.Context, cdc *codec.Codec, queryRoute string, auctionID uint64) (types.Auction, int64, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(types.NewQueryAuctionParams(auctionID))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetAuction), bz)
|
||||
|
||||
if err == nil {
|
||||
var auction types.Auction
|
||||
cliCtx.LegacyAmino.MustUnmarshalJSON(res, &auction)
|
||||
|
||||
return auction, height, nil
|
||||
}
|
||||
|
||||
if err != nil && !strings.Contains(err.Error(), "auction not found") {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, height, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryNextAuctionID), nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var nextAuctionID uint64
|
||||
cliCtx.LegacyAmino.MustUnmarshalJSON(res, &nextAuctionID)
|
||||
|
||||
if auctionID >= nextAuctionID {
|
||||
return nil, 0, errorsmod.Wrapf(types.ErrAuctionNotFound, "%d", auctionID)
|
||||
}
|
||||
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, "place_bid"),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeAuctionBid, types.AttributeKeyAuctionID, []byte(fmt.Sprintf("%d", auctionID))),
|
||||
}
|
||||
|
||||
// if the auction is closed, query for previous bid transactions
|
||||
// note, will only fetch a maximum of 100 bids, so if an auction had more than that this
|
||||
// query may fail to retreive the final state of the auction
|
||||
searchResult, err := authtx.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit, "")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
maxHeight := int64(0)
|
||||
found := false
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
_, ok := msg.(*types.MsgPlaceBid)
|
||||
if ok {
|
||||
found = true
|
||||
if info.Height > maxHeight {
|
||||
maxHeight = info.Height
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
return nil, 0, errorsmod.Wrapf(types.ErrAuctionNotFound, "%d", auctionID)
|
||||
}
|
||||
|
||||
queryCLIContext := cliCtx.WithHeight(maxHeight)
|
||||
res, height, err = queryCLIContext.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryGetAuction), bz)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Decode and print results
|
||||
var auction types.Auction
|
||||
cliCtx.LegacyAmino.MustUnmarshalJSON(res, &auction)
|
||||
return auction, height, nil
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// QueryGetAuction is the query path for querying one auction
|
||||
QueryGetAuction = "auction"
|
||||
// QueryGetAuctions is the query path for querying all auctions
|
||||
QueryGetAuctions = "auctions"
|
||||
// QueryGetParams is the query path for querying the global auction params
|
||||
QueryGetParams = "params"
|
||||
// QueryNextAuctionID is the query path for querying the id of the next auction
|
||||
QueryNextAuctionID = "next-auction-id"
|
||||
)
|
||||
|
||||
// QueryAuctionParams params for query /auction/auction
|
||||
type QueryAuctionParams struct {
|
||||
AuctionID uint64
|
||||
}
|
||||
|
||||
// NewQueryAuctionParams returns a new QueryAuctionParams
|
||||
func NewQueryAuctionParams(id uint64) QueryAuctionParams {
|
||||
return QueryAuctionParams{
|
||||
AuctionID: id,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryAllAuctionParams is the params for an auctions query
|
||||
type QueryAllAuctionParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
Phase string `json:"phase" yaml:"phase"`
|
||||
}
|
||||
|
||||
// NewQueryAllAuctionParams creates a new QueryAllAuctionParams
|
||||
func NewQueryAllAuctionParams(page, limit int, aucType, aucDenom, aucPhase string, aucOwner sdk.AccAddress) QueryAllAuctionParams {
|
||||
return QueryAllAuctionParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Type: aucType,
|
||||
Owner: aucOwner,
|
||||
Denom: aucDenom,
|
||||
Phase: aucPhase,
|
||||
}
|
||||
}
|
||||
|
||||
// AuctionWithPhase augmented type for collateral auctions which includes auction phase for querying
|
||||
type AuctionWithPhase struct {
|
||||
Auction Auction `json:"auction" yaml:"auction"`
|
||||
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Phase string `json:"phase" yaml:"phase"`
|
||||
}
|
||||
|
||||
// NewAuctionWithPhase returns new AuctionWithPhase
|
||||
func NewAuctionWithPhase(a Auction) AuctionWithPhase {
|
||||
return AuctionWithPhase{
|
||||
Auction: a,
|
||||
Type: a.GetType(),
|
||||
Phase: a.GetPhase(),
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
tmbytes "github.com/cometbft/cometbft/libs/bytes"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
const (
|
||||
// QueryGetAssetSupply command for getting info about an asset's supply
|
||||
QueryGetAssetSupply = "supply"
|
||||
// QueryGetAssetSupplies command for getting a list of asset supplies
|
||||
QueryGetAssetSupplies = "supplies"
|
||||
// QueryGetAtomicSwap command for getting info about an atomic swap
|
||||
QueryGetAtomicSwap = "swap"
|
||||
// QueryGetAtomicSwaps command for getting a list of atomic swaps
|
||||
QueryGetAtomicSwaps = "swaps"
|
||||
// QueryGetParams command for getting module params
|
||||
QueryGetParams = "parameters"
|
||||
)
|
||||
|
||||
// Legacy querier requests
|
||||
|
||||
// QueryAssetSupply contains the params for query 'custom/bep3/supply'
|
||||
type QueryAssetSupply struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryAssetSupply creates a new QueryAssetSupply
|
||||
func NewQueryAssetSupply(denom string) QueryAssetSupply {
|
||||
return QueryAssetSupply{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryAssetSupplies contains the params for an AssetSupplies query
|
||||
type QueryAssetSupplies struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
}
|
||||
|
||||
// NewQueryAssetSupplies creates a new QueryAssetSupplies
|
||||
func NewQueryAssetSupplies(page int, limit int) QueryAssetSupplies {
|
||||
return QueryAssetSupplies{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryAtomicSwapByID contains the params for query 'custom/bep3/swap'
|
||||
type QueryAtomicSwapByID struct {
|
||||
SwapID tmbytes.HexBytes `json:"swap_id" yaml:"swap_id"`
|
||||
}
|
||||
|
||||
// NewQueryAtomicSwapByID creates a new QueryAtomicSwapByID
|
||||
func NewQueryAtomicSwapByID(swapBytes tmbytes.HexBytes) QueryAtomicSwapByID {
|
||||
return QueryAtomicSwapByID{
|
||||
SwapID: swapBytes,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryAtomicSwaps contains the params for an AtomicSwaps query
|
||||
type QueryAtomicSwaps struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Involve sdk.AccAddress `json:"involve" yaml:"involve"`
|
||||
Expiration uint64 `json:"expiration" yaml:"expiration"`
|
||||
Status SwapStatus `json:"status" yaml:"status"`
|
||||
Direction SwapDirection `json:"direction" yaml:"direction"`
|
||||
}
|
||||
|
||||
// NewQueryAtomicSwaps creates a new instance of QueryAtomicSwaps
|
||||
func NewQueryAtomicSwaps(page, limit int, involve sdk.AccAddress, expiration uint64,
|
||||
status SwapStatus, direction SwapDirection,
|
||||
) QueryAtomicSwaps {
|
||||
return QueryAtomicSwaps{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Involve: involve,
|
||||
Expiration: expiration,
|
||||
Status: status,
|
||||
Direction: direction,
|
||||
}
|
||||
}
|
@ -4,36 +4,6 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Querier routes for the cdp module
|
||||
const (
|
||||
QueryGetCdp = "cdp"
|
||||
QueryGetCdps = "cdps"
|
||||
QueryGetCdpDeposits = "deposits"
|
||||
QueryGetCdpsByCollateralization = "ratio" // legacy query, maintained for REST API
|
||||
QueryGetCdpsByCollateralType = "collateralType" // legacy query, maintained for REST API
|
||||
QueryGetParams = "params"
|
||||
QueryGetAccounts = "accounts"
|
||||
QueryGetTotalPrincipal = "totalPrincipal"
|
||||
QueryGetTotalCollateral = "totalCollateral"
|
||||
RestOwner = "owner"
|
||||
RestCollateralType = "collateral-type"
|
||||
RestRatio = "ratio"
|
||||
)
|
||||
|
||||
// QueryCdpParams params for query /cdp/cdp
|
||||
type QueryCdpParams struct {
|
||||
CollateralType string // get CDPs with this collateral type
|
||||
Owner sdk.AccAddress // get CDPs belonging to this owner
|
||||
}
|
||||
|
||||
// NewQueryCdpParams returns QueryCdpParams
|
||||
func NewQueryCdpParams(owner sdk.AccAddress, collateralType string) QueryCdpParams {
|
||||
return QueryCdpParams{
|
||||
Owner: owner,
|
||||
CollateralType: collateralType,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryCdpsParams is the params for a filtered CDP query
|
||||
type QueryCdpsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
@ -55,67 +25,3 @@ func NewQueryCdpsParams(page, limit int, collateralType string, owner sdk.AccAdd
|
||||
Ratio: ratio,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryCdpDeposits params for query /cdp/deposits
|
||||
type QueryCdpDeposits struct {
|
||||
CollateralType string // get CDPs with this collateral type
|
||||
Owner sdk.AccAddress // get CDPs belonging to this owner
|
||||
}
|
||||
|
||||
// NewQueryCdpDeposits returns QueryCdpDeposits
|
||||
func NewQueryCdpDeposits(owner sdk.AccAddress, collateralType string) QueryCdpDeposits {
|
||||
return QueryCdpDeposits{
|
||||
Owner: owner,
|
||||
CollateralType: collateralType,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryCdpsByCollateralTypeParams params for query /cdp/cdps/{denom}
|
||||
type QueryCdpsByCollateralTypeParams struct {
|
||||
CollateralType string // get CDPs with this collateral type
|
||||
}
|
||||
|
||||
// NewQueryCdpsByCollateralTypeParams returns QueryCdpsByCollateralTypeParams
|
||||
func NewQueryCdpsByCollateralTypeParams(collateralType string) QueryCdpsByCollateralTypeParams {
|
||||
return QueryCdpsByCollateralTypeParams{
|
||||
CollateralType: collateralType,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryCdpsByRatioParams params for query /cdp/cdps/ratio
|
||||
type QueryCdpsByRatioParams struct {
|
||||
CollateralType string
|
||||
Ratio sdk.Dec // get CDPs below this collateral:debt ratio
|
||||
}
|
||||
|
||||
// NewQueryCdpsByRatioParams returns QueryCdpsByRatioParams
|
||||
func NewQueryCdpsByRatioParams(collateralType string, ratio sdk.Dec) QueryCdpsByRatioParams {
|
||||
return QueryCdpsByRatioParams{
|
||||
CollateralType: collateralType,
|
||||
Ratio: ratio,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryGetTotalPrincipalParams params for query /cdp/totalPrincipal
|
||||
type QueryGetTotalPrincipalParams struct {
|
||||
CollateralType string
|
||||
}
|
||||
|
||||
// NewQueryGetTotalPrincipalParams returns QueryGetTotalPrincipalParams
|
||||
func NewQueryGetTotalPrincipalParams(collateralType string) QueryGetTotalPrincipalParams {
|
||||
return QueryGetTotalPrincipalParams{
|
||||
CollateralType: collateralType,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryGetTotalCollateralParams params for query /cdp/totalCollateral
|
||||
type QueryGetTotalCollateralParams struct {
|
||||
CollateralType string
|
||||
}
|
||||
|
||||
// NewQueryGetTotalCollateralParams returns QueryGetTotalCollateralParams
|
||||
func NewQueryGetTotalCollateralParams(collateralType string) QueryGetTotalCollateralParams {
|
||||
return QueryGetTotalCollateralParams{
|
||||
CollateralType: collateralType,
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,9 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
errorsmod "cosmossdk.io/errors"
|
||||
"github.com/cosmos/cosmos-sdk/client"
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
|
||||
|
||||
@ -62,99 +57,3 @@ func QueryProposer(cliCtx client.Context, proposalID uint64) (Proposer, error) {
|
||||
|
||||
return Proposer{}, fmt.Errorf("failed to find the proposer for proposalID %d", proposalID)
|
||||
}
|
||||
|
||||
// QueryProposalByID returns a proposal from state if present or fallbacks to searching old blocks
|
||||
func QueryProposalByID(cliCtx client.Context, cdc *codec.LegacyAmino, queryRoute string, proposalID uint64) (*types.Proposal, int64, error) {
|
||||
bz, err := cdc.MarshalJSON(types.NewQueryProposalParams(proposalID))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryProposal), bz)
|
||||
|
||||
if err == nil {
|
||||
var proposal types.Proposal
|
||||
cdc.MustUnmarshalJSON(res, &proposal)
|
||||
|
||||
return &proposal, height, nil
|
||||
}
|
||||
|
||||
// NOTE: !errors.Is(err, types.ErrUnknownProposal) does not work here
|
||||
if err != nil && !strings.Contains(err.Error(), "proposal not found") {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
res, height, err = cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryNextProposalID), nil)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
var nextProposalID uint64
|
||||
cdc.MustUnmarshalJSON(res, &nextProposalID)
|
||||
|
||||
if proposalID >= nextProposalID {
|
||||
return nil, 0, errorsmod.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
||||
}
|
||||
|
||||
events := []string{
|
||||
fmt.Sprintf("%s.%s='%s'", sdk.EventTypeMessage, sdk.AttributeKeyAction, types.TypeMsgSubmitProposal),
|
||||
fmt.Sprintf("%s.%s='%s'", types.EventTypeProposalSubmit, types.AttributeKeyProposalID, []byte(fmt.Sprintf("%d", proposalID))),
|
||||
}
|
||||
|
||||
searchResult, err := authtx.QueryTxsByEvents(cliCtx, events, defaultPage, defaultLimit, "")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
for _, info := range searchResult.Txs {
|
||||
for _, msg := range info.GetTx().GetMsgs() {
|
||||
if subMsg, ok := msg.(*types.MsgSubmitProposal); ok {
|
||||
deadline, err := calculateDeadline(cliCtx, cdc, queryRoute, subMsg.CommitteeID, info.Height)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
proposal, err := types.NewProposal(subMsg.GetPubProposal(), proposalID, subMsg.CommitteeID, deadline)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return &proposal, height, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil, 0, errorsmod.Wrapf(types.ErrUnknownProposal, "%d", proposalID)
|
||||
}
|
||||
|
||||
// calculateDeadline returns the proposal deadline for a committee and block height
|
||||
func calculateDeadline(cliCtx client.Context, cdc *codec.LegacyAmino, queryRoute string, committeeID uint64, blockHeight int64) (time.Time, error) {
|
||||
var deadline time.Time
|
||||
|
||||
bz, err := cdc.MarshalJSON(types.NewQueryCommitteeParams(committeeID))
|
||||
if err != nil {
|
||||
return deadline, err
|
||||
}
|
||||
|
||||
res, _, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", queryRoute, types.QueryCommittee), bz)
|
||||
if err != nil {
|
||||
return deadline, err
|
||||
}
|
||||
|
||||
var committee types.Committee
|
||||
err = cdc.UnmarshalJSON(res, &committee)
|
||||
if err != nil {
|
||||
return deadline, err
|
||||
}
|
||||
|
||||
node, err := cliCtx.GetNode()
|
||||
if err != nil {
|
||||
return deadline, err
|
||||
}
|
||||
|
||||
resultBlock, err := node.Block(context.Background(), &blockHeight)
|
||||
if err != nil {
|
||||
return deadline, err
|
||||
}
|
||||
|
||||
deadline = resultBlock.Block.Header.Time.Add(committee.GetProposalDuration())
|
||||
return deadline, nil
|
||||
}
|
||||
|
@ -1,62 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Query endpoints supported by the Querier
|
||||
const (
|
||||
QueryCommittees = "committees"
|
||||
QueryCommittee = "committee"
|
||||
QueryProposals = "proposals"
|
||||
QueryProposal = "proposal"
|
||||
QueryNextProposalID = "next-proposal-id"
|
||||
QueryVotes = "votes"
|
||||
QueryVote = "vote"
|
||||
QueryTally = "tally"
|
||||
QueryRawParams = "raw_params"
|
||||
)
|
||||
|
||||
type QueryCommitteeParams struct {
|
||||
CommitteeID uint64 `json:"committee_id" yaml:"committee_id"`
|
||||
}
|
||||
|
||||
func NewQueryCommitteeParams(committeeID uint64) QueryCommitteeParams {
|
||||
return QueryCommitteeParams{
|
||||
CommitteeID: committeeID,
|
||||
}
|
||||
}
|
||||
|
||||
type QueryProposalParams struct {
|
||||
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"`
|
||||
}
|
||||
|
||||
func NewQueryProposalParams(proposalID uint64) QueryProposalParams {
|
||||
return QueryProposalParams{
|
||||
ProposalID: proposalID,
|
||||
}
|
||||
}
|
||||
|
||||
type QueryVoteParams struct {
|
||||
ProposalID uint64 `json:"proposal_id" yaml:"proposal_id"`
|
||||
Voter sdk.AccAddress `json:"voter" yaml:"voter"`
|
||||
}
|
||||
|
||||
func NewQueryVoteParams(proposalID uint64, voter sdk.AccAddress) QueryVoteParams {
|
||||
return QueryVoteParams{
|
||||
ProposalID: proposalID,
|
||||
Voter: voter,
|
||||
}
|
||||
}
|
||||
|
||||
type QueryRawParamsParams struct {
|
||||
Subspace string
|
||||
Key string
|
||||
}
|
||||
|
||||
func NewQueryRawParamsParams(subspace, key string) QueryRawParamsParams {
|
||||
return QueryRawParamsParams{
|
||||
Subspace: subspace,
|
||||
Key: key,
|
||||
}
|
||||
}
|
@ -1,200 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
)
|
||||
|
||||
// Querier routes for the hard module
|
||||
const (
|
||||
QueryGetParams = "params"
|
||||
QueryGetModuleAccounts = "accounts"
|
||||
QueryGetDeposits = "deposits"
|
||||
QueryGetUnsyncedDeposits = "unsynced-deposits"
|
||||
QueryGetTotalDeposited = "total-deposited"
|
||||
QueryGetBorrows = "borrows"
|
||||
QueryGetUnsyncedBorrows = "unsynced-borrows"
|
||||
QueryGetTotalBorrowed = "total-borrowed"
|
||||
QueryGetInterestRate = "interest-rate"
|
||||
QueryGetReserves = "reserves"
|
||||
QueryGetInterestFactors = "interest-factors"
|
||||
)
|
||||
|
||||
// QueryDepositsParams is the params for a filtered deposit query
|
||||
type QueryDepositsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
}
|
||||
|
||||
// NewQueryDepositsParams creates a new QueryDepositsParams
|
||||
func NewQueryDepositsParams(page, limit int, denom string, owner sdk.AccAddress) QueryDepositsParams {
|
||||
return QueryDepositsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Denom: denom,
|
||||
Owner: owner,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryUnsyncedDepositsParams is the params for a filtered unsynced deposit query.
|
||||
type QueryUnsyncedDepositsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
}
|
||||
|
||||
// NewQueryUnsyncedDepositsParams creates a new QueryUnsyncedDepositsParams
|
||||
func NewQueryUnsyncedDepositsParams(page, limit int, denom string, owner sdk.AccAddress) QueryUnsyncedDepositsParams {
|
||||
return QueryUnsyncedDepositsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Denom: denom,
|
||||
Owner: owner,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryAccountParams is the params for a filtered module account query
|
||||
type QueryAccountParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Name string `json:"name" yaml:"name"`
|
||||
}
|
||||
|
||||
// NewQueryAccountParams returns QueryAccountParams
|
||||
func NewQueryAccountParams(page, limit int, name string) QueryAccountParams {
|
||||
return QueryAccountParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Name: name,
|
||||
}
|
||||
}
|
||||
|
||||
// ModAccountWithCoins includes the module account with its coins
|
||||
type ModAccountWithCoins struct {
|
||||
Account authtypes.ModuleAccountI `json:"account" yaml:"account"`
|
||||
Coins sdk.Coins `json:"coins" yaml:"coins"`
|
||||
}
|
||||
|
||||
// QueryBorrowsParams is the params for a filtered borrows query
|
||||
type QueryBorrowsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryBorrowsParams creates a new QueryBorrowsParams
|
||||
func NewQueryBorrowsParams(page, limit int, owner sdk.AccAddress, denom string) QueryBorrowsParams {
|
||||
return QueryBorrowsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Owner: owner,
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryUnsyncedBorrowsParams is the params for a filtered unsynced borrows query
|
||||
type QueryUnsyncedBorrowsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryUnsyncedBorrowsParams creates a new QueryUnsyncedBorrowsParams
|
||||
func NewQueryUnsyncedBorrowsParams(page, limit int, owner sdk.AccAddress, denom string) QueryUnsyncedBorrowsParams {
|
||||
return QueryUnsyncedBorrowsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Owner: owner,
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryTotalBorrowedParams is the params for a filtered total borrowed coins query
|
||||
type QueryTotalBorrowedParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryTotalBorrowedParams creates a new QueryTotalBorrowedParams
|
||||
func NewQueryTotalBorrowedParams(denom string) QueryTotalBorrowedParams {
|
||||
return QueryTotalBorrowedParams{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryTotalDepositedParams is the params for a filtered total deposited coins query
|
||||
type QueryTotalDepositedParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryTotalDepositedParams creates a new QueryTotalDepositedParams
|
||||
func NewQueryTotalDepositedParams(denom string) QueryTotalDepositedParams {
|
||||
return QueryTotalDepositedParams{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryInterestRateParams is the params for a filtered interest rate query
|
||||
type QueryInterestRateParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryInterestRateParams creates a new QueryInterestRateParams
|
||||
func NewQueryInterestRateParams(denom string) QueryInterestRateParams {
|
||||
return QueryInterestRateParams{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// NewMoneyMarketInterestRate returns a new instance of MoneyMarketInterestRate
|
||||
func NewMoneyMarketInterestRate(denom string, supplyInterestRate, borrowInterestRate sdk.Dec) MoneyMarketInterestRate {
|
||||
return MoneyMarketInterestRate{
|
||||
Denom: denom,
|
||||
SupplyInterestRate: supplyInterestRate.String(),
|
||||
BorrowInterestRate: borrowInterestRate.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// MoneyMarketInterestRates is a slice of MoneyMarketInterestRate
|
||||
type MoneyMarketInterestRates []MoneyMarketInterestRate
|
||||
|
||||
// QueryReservesParams is the params for a filtered reserves query
|
||||
type QueryReservesParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryReservesParams creates a new QueryReservesParams
|
||||
func NewQueryReservesParams(denom string) QueryReservesParams {
|
||||
return QueryReservesParams{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryInterestFactorsParams is the params for a filtered interest factors query
|
||||
type QueryInterestFactorsParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
||||
|
||||
// NewQueryInterestFactorsParams creates a new QueryInterestFactorsParams
|
||||
func NewQueryInterestFactorsParams(denom string) QueryInterestFactorsParams {
|
||||
return QueryInterestFactorsParams{
|
||||
Denom: denom,
|
||||
}
|
||||
}
|
||||
|
||||
// NewInterestFactor returns a new instance of InterestFactor
|
||||
func NewInterestFactor(denom string, supplyInterestFactor, borrowInterestFactor sdk.Dec) InterestFactor {
|
||||
return InterestFactor{
|
||||
Denom: denom,
|
||||
SupplyInterestFactor: supplyInterestFactor.String(),
|
||||
BorrowInterestFactor: borrowInterestFactor.String(),
|
||||
}
|
||||
}
|
||||
|
||||
// InterestFactors is a slice of InterestFactor
|
||||
type InterestFactors []InterestFactor
|
7
x/hard/types/query.go
Normal file
7
x/hard/types/query.go
Normal file
@ -0,0 +1,7 @@
|
||||
package types
|
||||
|
||||
// MoneyMarketInterestRates is a slice of MoneyMarketInterestRate
|
||||
type MoneyMarketInterestRates []MoneyMarketInterestRate
|
||||
|
||||
// InterestFactors is a slice of InterestFactor
|
||||
type InterestFactors []InterestFactor
|
@ -1,6 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
@ -11,6 +12,7 @@ import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/version"
|
||||
|
||||
"github.com/kava-labs/kava/x/incentive/keeper"
|
||||
"github.com/kava-labs/kava/x/incentive/types"
|
||||
)
|
||||
|
||||
@ -19,16 +21,16 @@ const (
|
||||
flagType = "type"
|
||||
flagUnsynced = "unsynced"
|
||||
flagDenom = "denom"
|
||||
|
||||
typeDelegator = "delegator"
|
||||
typeHard = "hard"
|
||||
typeUSDXMinting = "usdx-minting"
|
||||
typeSwap = "swap"
|
||||
typeSavings = "savings"
|
||||
typeEarn = "earn"
|
||||
)
|
||||
|
||||
var rewardTypes = []string{typeDelegator, typeHard, typeUSDXMinting, typeSwap, typeEarn}
|
||||
var rewardTypes = []string{
|
||||
keeper.RewardTypeHard,
|
||||
keeper.RewardTypeUSDXMinting,
|
||||
keeper.RewardTypeDelegator,
|
||||
keeper.RewardTypeSwap,
|
||||
keeper.RewardTypeSavings,
|
||||
keeper.RewardTypeEarn,
|
||||
}
|
||||
|
||||
// GetQueryCmd returns the cli query commands for the incentive module
|
||||
func GetQueryCmd() *cobra.Command {
|
||||
@ -41,6 +43,7 @@ func GetQueryCmd() *cobra.Command {
|
||||
queryParamsCmd(),
|
||||
queryRewardsCmd(),
|
||||
queryRewardFactorsCmd(),
|
||||
queryApyCmd(),
|
||||
}
|
||||
|
||||
for _, cmd := range cmds {
|
||||
@ -79,8 +82,6 @@ func queryRewardsCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
page, _ := cmd.Flags().GetInt(flags.FlagPage)
|
||||
limit, _ := cmd.Flags().GetInt(flags.FlagLimit)
|
||||
strOwner, _ := cmd.Flags().GetString(flagOwner)
|
||||
strType, _ := cmd.Flags().GetString(flagType)
|
||||
boolUnsynced, _ := cmd.Flags().GetBool(flagUnsynced)
|
||||
@ -93,109 +94,18 @@ func queryRewardsCmd() *cobra.Command {
|
||||
}
|
||||
}
|
||||
|
||||
switch strings.ToLower(strType) {
|
||||
case typeHard:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeHardRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
case typeUSDXMinting:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeUSDXMintingRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
case typeDelegator:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeDelegatorRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
case typeSwap:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeSwapRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
case typeSavings:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeSavingsRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
case typeEarn:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
claims, err := executeEarnRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(claims)
|
||||
default:
|
||||
params := types.NewQueryRewardsParams(page, limit, owner, boolUnsynced)
|
||||
|
||||
hardClaims, err := executeHardRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
usdxMintingClaims, err := executeUSDXMintingRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
delegatorClaims, err := executeDelegatorRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
swapClaims, err := executeSwapRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
savingsClaims, err := executeSavingsRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
earnClaims, err := executeEarnRewardsQuery(cliCtx, params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(hardClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(hardClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(usdxMintingClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(usdxMintingClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(delegatorClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(delegatorClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(swapClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(swapClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(savingsClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(savingsClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if len(earnClaims) > 0 {
|
||||
if err := cliCtx.PrintObjectLegacy(earnClaims); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
rewardType := strings.ToLower(strType)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
request := types.QueryRewardsRequest{
|
||||
RewardType: rewardType,
|
||||
Owner: owner.String(),
|
||||
Unsynchronized: boolUnsynced,
|
||||
}
|
||||
return nil
|
||||
rewards, err := queryClient.Rewards(context.Background(), &request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintProto(rewards)
|
||||
},
|
||||
}
|
||||
cmd.Flags().String(flagOwner, "", "(optional) filter by owner address")
|
||||
@ -218,20 +128,12 @@ func queryParamsCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetParams)
|
||||
res, height, err := cliCtx.QueryWithData(route, nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var params types.Params
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, ¶ms); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal params: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(params)
|
||||
return cliCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -248,154 +150,36 @@ func queryRewardFactorsCmd() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Execute query
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetRewardFactors)
|
||||
res, height, err := cliCtx.QueryWithData(route, nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.RewardFactors(context.Background(), &types.QueryRewardFactorsRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var response types.QueryGetRewardFactorsResponse
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &response); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal reward factors: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(response)
|
||||
return cliCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
cmd.Flags().String(flagDenom, "", "(optional) filter reward factors by denom")
|
||||
return cmd
|
||||
}
|
||||
|
||||
func executeHardRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.HardLiquidityProviderClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.HardLiquidityProviderClaims{}, err
|
||||
func queryApyCmd() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "apy",
|
||||
Short: "queries incentive reward apy for a reward",
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cliCtx, err := client.GetClientQueryContext(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.Apy(context.Background(), &types.QueryApyRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return cliCtx.PrintProto(res)
|
||||
},
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetHardRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.HardLiquidityProviderClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.HardLiquidityProviderClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.HardLiquidityProviderClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func executeUSDXMintingRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.USDXMintingClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.USDXMintingClaims{}, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetUSDXMintingRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.USDXMintingClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.USDXMintingClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.USDXMintingClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func executeDelegatorRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.DelegatorClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.DelegatorClaims{}, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetDelegatorRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.DelegatorClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.DelegatorClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.DelegatorClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func executeSwapRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.SwapClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.SwapClaims{}, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetSwapRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.SwapClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.SwapClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.SwapClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func executeSavingsRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.SavingsClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.SavingsClaims{}, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetSavingsRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.SavingsClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.SavingsClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.SavingsClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
func executeEarnRewardsQuery(cliCtx client.Context, params types.QueryRewardsParams) (types.EarnClaims, error) {
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
return types.EarnClaims{}, err
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.ModuleName, types.QueryGetEarnRewards)
|
||||
res, height, err := cliCtx.QueryWithData(route, bz)
|
||||
if err != nil {
|
||||
return types.EarnClaims{}, err
|
||||
}
|
||||
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
var claims types.EarnClaims
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &claims); err != nil {
|
||||
return types.EarnClaims{}, fmt.Errorf("failed to unmarshal claims: %w", err)
|
||||
}
|
||||
|
||||
return claims, nil
|
||||
return cmd
|
||||
}
|
||||
|
@ -1,79 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Querier routes for the incentive module
|
||||
const (
|
||||
QueryGetHardRewards = "hard-rewards"
|
||||
QueryGetUSDXMintingRewards = "usdx-minting-rewards"
|
||||
QueryGetDelegatorRewards = "delegator-rewards"
|
||||
QueryGetSwapRewards = "swap-rewards"
|
||||
QueryGetSavingsRewards = "savings-rewards"
|
||||
QueryGetEarnRewards = "earn-rewards"
|
||||
QueryGetRewardFactors = "reward-factors"
|
||||
QueryGetParams = "parameters"
|
||||
QueryGetAPYs = "apys"
|
||||
|
||||
RestClaimCollateralType = "collateral_type"
|
||||
RestClaimOwner = "owner"
|
||||
RestClaimType = "type"
|
||||
RestUnsynced = "unsynced"
|
||||
)
|
||||
|
||||
// QueryRewardsParams params for query /incentive/rewards/<claim type>
|
||||
type QueryRewardsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Unsynchronized bool `json:"unsynchronized" yaml:"unsynchronized"`
|
||||
}
|
||||
|
||||
// NewQueryRewardsParams returns QueryRewardsParams
|
||||
func NewQueryRewardsParams(page, limit int, owner sdk.AccAddress, unsynchronized bool) QueryRewardsParams {
|
||||
return QueryRewardsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Owner: owner,
|
||||
Unsynchronized: unsynchronized,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryGetRewardFactorsResponse holds the response to a reward factor query
|
||||
type QueryGetRewardFactorsResponse struct {
|
||||
USDXMintingRewardFactors RewardIndexes `json:"usdx_minting_reward_factors" yaml:"usdx_minting_reward_factors"`
|
||||
HardSupplyRewardFactors MultiRewardIndexes `json:"hard_supply_reward_factors" yaml:"hard_supply_reward_factors"`
|
||||
HardBorrowRewardFactors MultiRewardIndexes `json:"hard_borrow_reward_factors" yaml:"hard_borrow_reward_factors"`
|
||||
DelegatorRewardFactors MultiRewardIndexes `json:"delegator_reward_factors" yaml:"delegator_reward_factors"`
|
||||
SwapRewardFactors MultiRewardIndexes `json:"swap_reward_factors" yaml:"swap_reward_factors"`
|
||||
SavingsRewardFactors MultiRewardIndexes `json:"savings_reward_factors" yaml:"savings_reward_factors"`
|
||||
EarnRewardFactors MultiRewardIndexes `json:"earn_reward_factors" yaml:"earn_reward_factors"`
|
||||
}
|
||||
|
||||
// NewQueryGetRewardFactorsResponse returns a new instance of QueryAllRewardFactorsResponse
|
||||
func NewQueryGetRewardFactorsResponse(usdxMintingFactors RewardIndexes, supplyFactors,
|
||||
hardBorrowFactors, delegatorFactors, swapFactors, savingsFactors, earnFactors MultiRewardIndexes,
|
||||
) QueryGetRewardFactorsResponse {
|
||||
return QueryGetRewardFactorsResponse{
|
||||
USDXMintingRewardFactors: usdxMintingFactors,
|
||||
HardSupplyRewardFactors: supplyFactors,
|
||||
HardBorrowRewardFactors: hardBorrowFactors,
|
||||
DelegatorRewardFactors: delegatorFactors,
|
||||
SwapRewardFactors: swapFactors,
|
||||
SavingsRewardFactors: savingsFactors,
|
||||
EarnRewardFactors: earnFactors,
|
||||
}
|
||||
}
|
||||
|
||||
// QueryGetAPYsResponse holds the response to a APY query
|
||||
type QueryGetAPYsResponse struct {
|
||||
Earn []Apy `json:"earn" yaml:"earn"`
|
||||
}
|
||||
|
||||
// NewQueryGetAPYsResponse returns a new instance of QueryGetAPYsResponse
|
||||
func NewQueryGetAPYsResponse(earn []Apy) QueryGetAPYsResponse {
|
||||
return QueryGetAPYsResponse{
|
||||
Earn: earn,
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package types
|
||||
|
||||
// Querier routes for the issuance module
|
||||
const (
|
||||
QueryGetParams = "parameters"
|
||||
QueryGetAsset = "asset"
|
||||
)
|
||||
|
||||
// QueryAssetParams params for querying an asset by denom
|
||||
type QueryAssetParams struct {
|
||||
Denom string `json:"denom" yaml:"denom"`
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package types
|
||||
|
||||
// Querier routes for the kavadist module
|
||||
const (
|
||||
QueryGetParams = "params"
|
||||
QueryGetBalance = "balance"
|
||||
)
|
@ -1,32 +0,0 @@
|
||||
package types
|
||||
|
||||
// price Takes an [assetcode] and returns CurrentPrice for that asset
|
||||
// pricefeed Takes an [assetcode] and returns the raw []PostedPrice for that asset
|
||||
// assets Returns []Assets in the pricefeed system
|
||||
|
||||
const (
|
||||
// QueryGetParams command for params query
|
||||
QueryGetParams = "parameters"
|
||||
// QueryMarkets command for assets query
|
||||
QueryMarkets = "markets"
|
||||
// QueryOracles command for oracles query
|
||||
QueryOracles = "oracles"
|
||||
// QueryRawPrices command for raw price queries
|
||||
QueryRawPrices = "rawprices"
|
||||
// QueryPrice command for price queries
|
||||
QueryPrice = "price"
|
||||
// QueryPrices command for quering all prices
|
||||
QueryPrices = "prices"
|
||||
)
|
||||
|
||||
// QueryWithMarketIDParams fields for querying information from a specific market
|
||||
type QueryWithMarketIDParams struct {
|
||||
MarketID string
|
||||
}
|
||||
|
||||
// NewQueryWithMarketIDParams creates a new instance of QueryWithMarketIDParams
|
||||
func NewQueryWithMarketIDParams(marketID string) QueryWithMarketIDParams {
|
||||
return QueryWithMarketIDParams{
|
||||
MarketID: marketID,
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package types
|
||||
|
||||
import (
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
)
|
||||
|
||||
// Querier routes for the swap module
|
||||
const (
|
||||
QueryGetParams = "params"
|
||||
QueryGetDeposits = "deposits"
|
||||
QueryGetPool = "pool"
|
||||
QueryGetPools = "pools"
|
||||
)
|
||||
|
||||
// QueryDepositsParams is the params for a filtered deposits query
|
||||
type QueryDepositsParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
Owner sdk.AccAddress `json:"owner" yaml:"owner"`
|
||||
Pool string `json:"pool" yaml:"pool"`
|
||||
}
|
||||
|
||||
// NewQueryDepositsParams creates a new QueryDepositsParams
|
||||
func NewQueryDepositsParams(page, limit int, owner sdk.AccAddress, pool string) QueryDepositsParams {
|
||||
return QueryDepositsParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
Owner: owner,
|
||||
Pool: pool,
|
||||
}
|
||||
}
|
||||
|
||||
// DepositsQueryResult contains the result of a deposits query
|
||||
type DepositsQueryResult struct {
|
||||
Depositor sdk.AccAddress `json:"depositor" yaml:"depositor"`
|
||||
PoolID string `json:"pool_id" yaml:"pool_id"`
|
||||
SharesOwned sdkmath.Int `json:"shares_owned" yaml:"shares_owned"`
|
||||
SharesValue sdk.Coins `json:"shares_value" yaml:"shares_value"`
|
||||
}
|
||||
|
||||
// NewDepositsQueryResult creates a new DepositsQueryResult
|
||||
func NewDepositsQueryResult(shareRecord ShareRecord, sharesValue sdk.Coins) DepositsQueryResult {
|
||||
return DepositsQueryResult{
|
||||
Depositor: shareRecord.Depositor,
|
||||
PoolID: shareRecord.PoolID,
|
||||
SharesOwned: shareRecord.SharesOwned,
|
||||
SharesValue: sharesValue,
|
||||
}
|
||||
}
|
||||
|
||||
// DepositsQueryResults is a slice of DepositsQueryResult
|
||||
type DepositsQueryResults []DepositsQueryResult
|
||||
|
||||
// QueryPoolParams is the params for a pool query
|
||||
type QueryPoolParams struct {
|
||||
Pool string `json:"pool" yaml:"pool"`
|
||||
}
|
||||
|
||||
// NewQueryPoolParams creates a new QueryPoolParams
|
||||
func NewQueryPoolParams(pool string) QueryPoolParams {
|
||||
return QueryPoolParams{
|
||||
Pool: pool,
|
||||
}
|
||||
}
|
||||
|
||||
// PoolStatsQueryResult contains the result of a pool query
|
||||
type PoolStatsQueryResult struct {
|
||||
Name string `json:"name" yaml:"name"`
|
||||
Coins sdk.Coins `json:"coins" yaml:"coins"`
|
||||
TotalShares sdkmath.Int `json:"total_shares" yaml:"total_shares"`
|
||||
}
|
||||
|
||||
// NewPoolStatsQueryResult creates a new PoolStatsQueryResult
|
||||
func NewPoolStatsQueryResult(name string, coins sdk.Coins, totalShares sdkmath.Int) PoolStatsQueryResult {
|
||||
return PoolStatsQueryResult{
|
||||
Name: name,
|
||||
Coins: coins,
|
||||
TotalShares: totalShares,
|
||||
}
|
||||
}
|
||||
|
||||
// PoolStatsQueryResults is a slice of PoolStatsQueryResult
|
||||
type PoolStatsQueryResults []PoolStatsQueryResult
|
@ -1,7 +1,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"context"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
@ -48,19 +48,12 @@ func queryCirculatingSupply() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupply), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -76,20 +69,12 @@ func queryTotalSupply() *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupply(context.Background(), &types.QueryTotalSupplyRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -106,19 +91,12 @@ func queryCirculatingSupplyHARD() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplyHARD), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplyHARD(context.Background(), &types.QueryCirculatingSupplyHARDRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -135,19 +113,12 @@ func queryCirculatingSupplyUSDX() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplyUSDX), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplyUSDX(context.Background(), &types.QueryCirculatingSupplyUSDXRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -164,19 +135,12 @@ func queryCirculatingSupplySWP() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplySWP), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplySWP(context.Background(), &types.QueryCirculatingSupplySWPRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -193,19 +157,12 @@ func queryTotalSupplyHARD() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupplyHARD), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupplyHARD(context.Background(), &types.QueryTotalSupplyHARDRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -222,19 +179,12 @@ func queryTotalSupplyUSDX() *cobra.Command {
|
||||
return err
|
||||
}
|
||||
|
||||
// Query
|
||||
res, height, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupplyUSDX), nil)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupplyUSDX(context.Background(), &types.QueryTotalSupplyUSDXRequest{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cliCtx = cliCtx.WithHeight(height)
|
||||
|
||||
// Decode and print results
|
||||
var out int64
|
||||
if err := cliCtx.LegacyAmino.UnmarshalJSON(res, &out); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal supply: %w", err)
|
||||
}
|
||||
return cliCtx.PrintObjectLegacy(out)
|
||||
return cliCtx.PrintString(res.Amount.String())
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package rest
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
@ -25,37 +26,18 @@ func registerQueryRoutes(cliCtx client.Context, r *mux.Router) {
|
||||
|
||||
func getTotalSupplyHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupply)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupply(context.Background(), &types.QueryTotalSupplyRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
var totalSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &totalSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(totalSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -66,38 +48,18 @@ func getTotalSupplyHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getCirculatingSupplyHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupply)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var circSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &circSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(circSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -108,38 +70,18 @@ func getCirculatingSupplyHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getCirculatingSupplyHARDHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplyHARD)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplyHARD(context.Background(), &types.QueryCirculatingSupplyHARDRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var circSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &circSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(circSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -150,38 +92,18 @@ func getCirculatingSupplyHARDHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getCirculatingSupplyUSDXHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplyUSDX)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplyUSDX(context.Background(), &types.QueryCirculatingSupplyUSDXRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var circSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &circSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(circSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -192,38 +114,18 @@ func getCirculatingSupplyUSDXHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getCirculatingSupplySWPHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryCirculatingSupplySWP)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.CirculatingSupplySWP(context.Background(), &types.QueryCirculatingSupplySWPRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var circSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &circSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(circSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -234,37 +136,18 @@ func getCirculatingSupplySWPHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getTotalSupplyHARDHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupplyHARD)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupplyHARD(context.Background(), &types.QueryTotalSupplyHARDRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
var totalSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &totalSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(totalSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
@ -275,37 +158,18 @@ func getTotalSupplyHARDHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
|
||||
func getTotalSupplyUSDXHandlerFn(cliCtx client.Context) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, page, limit, err := rest.ParseHTTPArgsWithLimit(r, 0)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
params := types.NewBaseQueryParams(page, limit)
|
||||
bz, err := cliCtx.LegacyAmino.MarshalJSON(params)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusBadRequest, fmt.Sprintf("failed to marshal query params: %s", err))
|
||||
return
|
||||
}
|
||||
|
||||
route := fmt.Sprintf("custom/%s/%s", types.QuerierRoute, types.QueryTotalSupplyUSDX)
|
||||
res, _, err := cliCtx.QueryWithData(route, bz)
|
||||
queryClient := types.NewQueryClient(cliCtx)
|
||||
res, err := queryClient.TotalSupplyUSDX(context.Background(), &types.QueryTotalSupplyUSDXRequest{})
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
var totalSupply int64
|
||||
err = cliCtx.LegacyAmino.UnmarshalJSON(res, &totalSupply)
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
resBytes, err := json.Marshal(totalSupply)
|
||||
resBytes, err := json.Marshal(res.Amount.Int64())
|
||||
if err != nil {
|
||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
|
358
x/validator-vesting/keeper/grpc_query.go
Normal file
358
x/validator-vesting/keeper/grpc_query.go
Normal file
@ -0,0 +1,358 @@
|
||||
package keeper
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
type queryServer struct {
|
||||
bk types.BankKeeper
|
||||
}
|
||||
|
||||
var _ types.QueryServer = queryServer{}
|
||||
|
||||
// NewQueryServerImpl creates a new server for handling gRPC queries.
|
||||
func NewQueryServerImpl(bk types.BankKeeper) types.QueryServer {
|
||||
return &queryServer{bk: bk}
|
||||
}
|
||||
|
||||
// CirculatingSupply implements the gRPC service handler for querying the circulating supply of the kava token.
|
||||
func (s queryServer) CirculatingSupply(c context.Context, req *types.QueryCirculatingSupplyRequest) (*types.
|
||||
QueryCirculatingSupplyResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "ukava").Amount
|
||||
supplyInt := getCirculatingSupply(ctx.BlockTime(), totalSupply)
|
||||
return &types.QueryCirculatingSupplyResponse{
|
||||
Amount: supplyInt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TotalSupply returns the total amount of ukava tokens
|
||||
func (s queryServer) TotalSupply(c context.Context, req *types.QueryTotalSupplyRequest) (*types.QueryTotalSupplyResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "ukava").Amount
|
||||
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||
return &types.QueryTotalSupplyResponse{
|
||||
Amount: supplyInt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CirculatingSupplyHARD returns the total amount of hard tokens in circulation
|
||||
func (s queryServer) CirculatingSupplyHARD(c context.Context, req *types.QueryCirculatingSupplyHARDRequest) (*types.QueryCirculatingSupplyHARDResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
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 = sdkmath.NewInt(0)
|
||||
case blockTime.After(supplyIncreaseDates[0]) && blockTime.Before(supplyIncreaseDates[1]) || blockTime.Equal(supplyIncreaseDates[0]):
|
||||
circSupply = sdkmath.NewInt(30000000) // Start year ONE
|
||||
case blockTime.After(supplyIncreaseDates[1]) && blockTime.Before(supplyIncreaseDates[2]) || blockTime.Equal(supplyIncreaseDates[1]):
|
||||
circSupply = sdkmath.NewInt(35000000)
|
||||
case blockTime.After(supplyIncreaseDates[2]) && blockTime.Before(supplyIncreaseDates[3]) || blockTime.Equal(supplyIncreaseDates[2]):
|
||||
circSupply = sdkmath.NewInt(40000000)
|
||||
case blockTime.After(supplyIncreaseDates[3]) && blockTime.Before(supplyIncreaseDates[4]) || blockTime.Equal(supplyIncreaseDates[3]):
|
||||
circSupply = sdkmath.NewInt(47708334)
|
||||
case blockTime.After(supplyIncreaseDates[4]) && blockTime.Before(supplyIncreaseDates[5]) || blockTime.Equal(supplyIncreaseDates[4]):
|
||||
circSupply = sdkmath.NewInt(51041667)
|
||||
case blockTime.After(supplyIncreaseDates[5]) && blockTime.Before(supplyIncreaseDates[6]) || blockTime.Equal(supplyIncreaseDates[5]):
|
||||
circSupply = sdkmath.NewInt(54375000)
|
||||
case blockTime.After(supplyIncreaseDates[6]) && blockTime.Before(supplyIncreaseDates[7]) || blockTime.Equal(supplyIncreaseDates[6]):
|
||||
circSupply = sdkmath.NewInt(61250000)
|
||||
case blockTime.After(supplyIncreaseDates[7]) && blockTime.Before(supplyIncreaseDates[8]) || blockTime.Equal(supplyIncreaseDates[7]):
|
||||
circSupply = sdkmath.NewInt(63750000)
|
||||
case blockTime.After(supplyIncreaseDates[8]) && blockTime.Before(supplyIncreaseDates[9]) || blockTime.Equal(supplyIncreaseDates[8]):
|
||||
circSupply = sdkmath.NewInt(66250000)
|
||||
case blockTime.After(supplyIncreaseDates[9]) && blockTime.Before(supplyIncreaseDates[10]) || blockTime.Equal(supplyIncreaseDates[9]):
|
||||
circSupply = sdkmath.NewInt(73125000)
|
||||
case blockTime.After(supplyIncreaseDates[10]) && blockTime.Before(supplyIncreaseDates[11]) || blockTime.Equal(supplyIncreaseDates[10]):
|
||||
circSupply = sdkmath.NewInt(75625000)
|
||||
case blockTime.After(supplyIncreaseDates[11]) && blockTime.Before(supplyIncreaseDates[12]) || blockTime.Equal(supplyIncreaseDates[11]):
|
||||
circSupply = sdkmath.NewInt(78125000) // End year ONE
|
||||
case blockTime.After(supplyIncreaseDates[12]) && blockTime.Before(supplyIncreaseDates[13]) || blockTime.Equal(supplyIncreaseDates[12]):
|
||||
circSupply = sdkmath.NewInt(91666667) // Start year TWO
|
||||
case blockTime.After(supplyIncreaseDates[13]) && blockTime.Before(supplyIncreaseDates[14]) || blockTime.Equal(supplyIncreaseDates[13]):
|
||||
circSupply = sdkmath.NewInt(94166667)
|
||||
case blockTime.After(supplyIncreaseDates[14]) && blockTime.Before(supplyIncreaseDates[15]) || blockTime.Equal(supplyIncreaseDates[14]):
|
||||
circSupply = sdkmath.NewInt(96666667)
|
||||
case blockTime.After(supplyIncreaseDates[15]) && blockTime.Before(supplyIncreaseDates[16]) || blockTime.Equal(supplyIncreaseDates[15]):
|
||||
circSupply = sdkmath.NewInt(105208334)
|
||||
case blockTime.After(supplyIncreaseDates[16]) && blockTime.Before(supplyIncreaseDates[17]) || blockTime.Equal(supplyIncreaseDates[16]):
|
||||
circSupply = sdkmath.NewInt(107708334)
|
||||
case blockTime.After(supplyIncreaseDates[17]) && blockTime.Before(supplyIncreaseDates[18]) || blockTime.Equal(supplyIncreaseDates[17]):
|
||||
circSupply = sdkmath.NewInt(110208334)
|
||||
case blockTime.After(supplyIncreaseDates[18]) && blockTime.Before(supplyIncreaseDates[19]) || blockTime.Equal(supplyIncreaseDates[18]):
|
||||
circSupply = sdkmath.NewInt(118750000)
|
||||
case blockTime.After(supplyIncreaseDates[19]) && blockTime.Before(supplyIncreaseDates[20]) || blockTime.Equal(supplyIncreaseDates[19]):
|
||||
circSupply = sdkmath.NewInt(121250000)
|
||||
case blockTime.After(supplyIncreaseDates[20]) && blockTime.Before(supplyIncreaseDates[21]) || blockTime.Equal(supplyIncreaseDates[20]):
|
||||
circSupply = sdkmath.NewInt(123750000)
|
||||
case blockTime.After(supplyIncreaseDates[21]) && blockTime.Before(supplyIncreaseDates[22]) || blockTime.Equal(supplyIncreaseDates[21]):
|
||||
circSupply = sdkmath.NewInt(132291668)
|
||||
case blockTime.After(supplyIncreaseDates[22]) && blockTime.Before(supplyIncreaseDates[23]) || blockTime.Equal(supplyIncreaseDates[22]):
|
||||
circSupply = sdkmath.NewInt(134791668)
|
||||
case blockTime.After(supplyIncreaseDates[23]) && blockTime.Before(supplyIncreaseDates[24]) || blockTime.Equal(supplyIncreaseDates[23]):
|
||||
circSupply = sdkmath.NewInt(137291668) // End year TWO
|
||||
case blockTime.After(supplyIncreaseDates[24]) && blockTime.Before(supplyIncreaseDates[25]) || blockTime.Equal(supplyIncreaseDates[24]):
|
||||
circSupply = sdkmath.NewInt(145833335) // Start year THREE
|
||||
case blockTime.After(supplyIncreaseDates[25]) && blockTime.Before(supplyIncreaseDates[26]) || blockTime.Equal(supplyIncreaseDates[25]):
|
||||
circSupply = sdkmath.NewInt(148333335)
|
||||
case blockTime.After(supplyIncreaseDates[26]) && blockTime.Before(supplyIncreaseDates[27]) || blockTime.Equal(supplyIncreaseDates[26]):
|
||||
circSupply = sdkmath.NewInt(150833335)
|
||||
case blockTime.After(supplyIncreaseDates[27]) && blockTime.Before(supplyIncreaseDates[28]) || blockTime.Equal(supplyIncreaseDates[27]):
|
||||
circSupply = sdkmath.NewInt(155000000)
|
||||
case blockTime.After(supplyIncreaseDates[28]) && blockTime.Before(supplyIncreaseDates[29]) || blockTime.Equal(supplyIncreaseDates[28]):
|
||||
circSupply = sdkmath.NewInt(157500000)
|
||||
case blockTime.After(supplyIncreaseDates[29]) && blockTime.Before(supplyIncreaseDates[30]) || blockTime.Equal(supplyIncreaseDates[29]):
|
||||
circSupply = sdkmath.NewInt(160000000)
|
||||
case blockTime.After(supplyIncreaseDates[30]) && blockTime.Before(supplyIncreaseDates[31]) || blockTime.Equal(supplyIncreaseDates[30]):
|
||||
circSupply = sdkmath.NewInt(164166669)
|
||||
case blockTime.After(supplyIncreaseDates[31]) && blockTime.Before(supplyIncreaseDates[32]) || blockTime.Equal(supplyIncreaseDates[31]):
|
||||
circSupply = sdkmath.NewInt(166666669)
|
||||
case blockTime.After(supplyIncreaseDates[32]) && blockTime.Before(supplyIncreaseDates[33]) || blockTime.Equal(supplyIncreaseDates[32]):
|
||||
circSupply = sdkmath.NewInt(169166669)
|
||||
case blockTime.After(supplyIncreaseDates[33]) && blockTime.Before(supplyIncreaseDates[34]) || blockTime.Equal(supplyIncreaseDates[33]):
|
||||
circSupply = sdkmath.NewInt(173333336)
|
||||
case blockTime.After(supplyIncreaseDates[34]) && blockTime.Before(supplyIncreaseDates[35]) || blockTime.Equal(supplyIncreaseDates[34]):
|
||||
circSupply = sdkmath.NewInt(175833336)
|
||||
case blockTime.After(supplyIncreaseDates[35]) && blockTime.Before(supplyIncreaseDates[36]) || blockTime.Equal(supplyIncreaseDates[35]):
|
||||
circSupply = sdkmath.NewInt(178333336) // End year THREE
|
||||
case blockTime.After(supplyIncreaseDates[36]) && blockTime.Before(supplyIncreaseDates[37]) || blockTime.Equal(supplyIncreaseDates[36]):
|
||||
circSupply = sdkmath.NewInt(181666670) // Start year FOUR
|
||||
case blockTime.After(supplyIncreaseDates[37]) && blockTime.Before(supplyIncreaseDates[38]) || blockTime.Equal(supplyIncreaseDates[37]):
|
||||
circSupply = sdkmath.NewInt(183333337)
|
||||
case blockTime.After(supplyIncreaseDates[38]) && blockTime.Before(supplyIncreaseDates[39]) || blockTime.Equal(supplyIncreaseDates[38]):
|
||||
circSupply = sdkmath.NewInt(185000000)
|
||||
case blockTime.After(supplyIncreaseDates[39]) && blockTime.Before(supplyIncreaseDates[40]) || blockTime.Equal(supplyIncreaseDates[39]):
|
||||
circSupply = sdkmath.NewInt(186666670)
|
||||
case blockTime.After(supplyIncreaseDates[40]) && blockTime.Before(supplyIncreaseDates[41]) || blockTime.Equal(supplyIncreaseDates[40]):
|
||||
circSupply = sdkmath.NewInt(188333338)
|
||||
case blockTime.After(supplyIncreaseDates[41]) && blockTime.Before(supplyIncreaseDates[42]) || blockTime.Equal(supplyIncreaseDates[41]):
|
||||
circSupply = sdkmath.NewInt(190000000)
|
||||
case blockTime.After(supplyIncreaseDates[42]) && blockTime.Before(supplyIncreaseDates[43]) || blockTime.Equal(supplyIncreaseDates[42]):
|
||||
circSupply = sdkmath.NewInt(191666670)
|
||||
case blockTime.After(supplyIncreaseDates[43]) && blockTime.Before(supplyIncreaseDates[44]) || blockTime.Equal(supplyIncreaseDates[43]):
|
||||
circSupply = sdkmath.NewInt(193333339)
|
||||
case blockTime.After(supplyIncreaseDates[44]) && blockTime.Before(supplyIncreaseDates[45]) || blockTime.Equal(supplyIncreaseDates[44]):
|
||||
circSupply = sdkmath.NewInt(195000000)
|
||||
case blockTime.After(supplyIncreaseDates[45]) && blockTime.Before(supplyIncreaseDates[46]) || blockTime.Equal(supplyIncreaseDates[45]):
|
||||
circSupply = sdkmath.NewInt(196666670)
|
||||
case blockTime.After(supplyIncreaseDates[46]) && blockTime.Before(supplyIncreaseDates[47]) || blockTime.Equal(supplyIncreaseDates[46]):
|
||||
circSupply = sdkmath.NewInt(198333340)
|
||||
case blockTime.After(supplyIncreaseDates[47]) && blockTime.Before(supplyIncreaseDates[48]) || blockTime.Equal(supplyIncreaseDates[47]):
|
||||
circSupply = sdkmath.NewInt(200000000) // End year FOUR
|
||||
default:
|
||||
circSupply = sdkmath.NewInt(200000000)
|
||||
}
|
||||
|
||||
return &types.QueryCirculatingSupplyHARDResponse{
|
||||
Amount: circSupply,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CirculatingSupplyUSDX returns the total amount of usdx tokens in circulation
|
||||
func (s queryServer) CirculatingSupplyUSDX(c context.Context, req *types.QueryCirculatingSupplyUSDXRequest) (*types.QueryCirculatingSupplyUSDXResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "usdx").Amount
|
||||
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||
return &types.QueryCirculatingSupplyUSDXResponse{
|
||||
Amount: supplyInt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// CirculatingSupplySWP returns the total amount of swp tokens in circulation
|
||||
func (s queryServer) CirculatingSupplySWP(c context.Context, req *types.QueryCirculatingSupplySWPRequest) (*types.QueryCirculatingSupplySWPResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
// 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(sdkmath.NewInt(monthTotal))
|
||||
}
|
||||
|
||||
return &types.QueryCirculatingSupplySWPResponse{
|
||||
Amount: circSupply,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TotalSupplyHARD returns the total amount of hard tokens
|
||||
func (s queryServer) TotalSupplyHARD(c context.Context, req *types.QueryTotalSupplyHARDRequest) (*types.QueryTotalSupplyHARDResponse, error) {
|
||||
ctx := sdk.UnwrapSDKContext(c)
|
||||
|
||||
totalSupply := s.bk.GetSupply(ctx, "hard").Amount
|
||||
supplyInt := sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||
return &types.QueryTotalSupplyHARDResponse{
|
||||
Amount: supplyInt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TotalSupplyUSDX returns the total amount of usdx tokens
|
||||
func (s queryServer) TotalSupplyUSDX(c context.Context, req *types.QueryTotalSupplyUSDXRequest) (*types.QueryTotalSupplyUSDXResponse, error) {
|
||||
// USDX total supply is the circulating supply
|
||||
rsp, err := s.CirculatingSupplyUSDX(c, &types.QueryCirculatingSupplyUSDXRequest{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &types.QueryTotalSupplyUSDXResponse{
|
||||
Amount: rsp.Amount,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getCirculatingSupply(blockTime time.Time, totalSupply sdkmath.Int) sdkmath.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(sdkmath.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(sdkmath.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(sdkmath.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(sdkmath.NewInt(2484375000000))).Mul(sdk.MustNewDecFromStr("0.000001")).RoundInt()
|
||||
default:
|
||||
// align with total supply calculation and truncate int here instead of round
|
||||
return sdk.NewDecFromInt(totalSupply).Mul(sdk.MustNewDecFromStr("0.000001")).TruncateInt()
|
||||
}
|
||||
}
|
116
x/validator-vesting/keeper/grpc_query_test.go
Normal file
116
x/validator-vesting/keeper/grpc_query_test.go
Normal file
@ -0,0 +1,116 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
sdkmath "cosmossdk.io/math"
|
||||
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"github.com/kava-labs/kava/app"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
type grpcQueryTestSuite struct {
|
||||
suite.Suite
|
||||
app app.TestApp
|
||||
ctx sdk.Context
|
||||
queryClient types.QueryClient
|
||||
bk *mockBankKeeper
|
||||
}
|
||||
|
||||
type mockBankKeeper struct {
|
||||
supply sdk.Coin
|
||||
}
|
||||
|
||||
func (m *mockBankKeeper) SetSupply(ctx sdk.Context, denom string, amt sdkmath.Int) {
|
||||
m.supply = sdk.NewCoin(denom, amt)
|
||||
}
|
||||
|
||||
func (m *mockBankKeeper) GetSupply(ctx sdk.Context, denom string) sdk.Coin {
|
||||
return m.supply
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) SetupTest() {
|
||||
testTime := time.Date(2024, 2, 29, 12, 00, 00, 00, time.UTC)
|
||||
tApp := app.NewTestApp()
|
||||
ctx := tApp.NewContext(true, tmproto.Header{Height: 1, Time: testTime})
|
||||
suite.app = tApp
|
||||
suite.ctx = ctx
|
||||
suite.bk = &mockBankKeeper{}
|
||||
suite.queryClient = suite.queryClientWithBlockTime(testTime)
|
||||
}
|
||||
|
||||
func TestGrpcQueryTestSuite(t *testing.T) {
|
||||
suite.Run(t, new(grpcQueryTestSuite))
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestCirculatingSupply() {
|
||||
suite.Run("vesting period supply", func() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(2_500_000_000_000))
|
||||
lastVestingPeriod := time.Date(2022, 8, 5, 24, 0, 0, 0, time.UTC)
|
||||
queryClient := suite.queryClientWithBlockTime(lastVestingPeriod)
|
||||
res, err := queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(15_625), res.Amount)
|
||||
})
|
||||
|
||||
suite.Run("supply after last vesting period", func() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(100_000_000))
|
||||
res, err := suite.queryClient.CirculatingSupply(context.Background(), &types.QueryCirculatingSupplyRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||
})
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestTotalSupply() {
|
||||
suite.bk.SetSupply(suite.ctx, "ukava", sdkmath.NewInt(100_000_000))
|
||||
res, err := suite.queryClient.TotalSupply(context.Background(), &types.QueryTotalSupplyRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(100), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestCirculatingSupplyHARD() {
|
||||
res, err := suite.queryClient.CirculatingSupplyHARD(context.Background(), &types.QueryCirculatingSupplyHARDRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(188333338), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestCirculatingSupplyUSDX() {
|
||||
suite.bk.SetSupply(suite.ctx, "usdx", sdkmath.NewInt(150_000_000))
|
||||
res, err := suite.queryClient.CirculatingSupplyUSDX(context.Background(), &types.QueryCirculatingSupplyUSDXRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(150), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestCirculatingSupplySWP() {
|
||||
res, err := suite.queryClient.CirculatingSupplySWP(suite.ctx, &types.QueryCirculatingSupplySWPRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(201302073), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestTotalSupplyHARD() {
|
||||
suite.bk.SetSupply(suite.ctx, "hard", sdkmath.NewInt(150_000_000))
|
||||
res, err := suite.queryClient.TotalSupplyHARD(context.Background(), &types.QueryTotalSupplyHARDRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(150), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) TestTotalSupplyUSDX() {
|
||||
suite.bk.SetSupply(suite.ctx, "usdx", sdkmath.NewInt(150_000_000))
|
||||
res, err := suite.queryClient.TotalSupplyUSDX(context.Background(), &types.QueryTotalSupplyUSDXRequest{})
|
||||
suite.Require().NoError(err)
|
||||
suite.Require().Equal(sdkmath.NewInt(150), res.Amount)
|
||||
}
|
||||
|
||||
func (suite *grpcQueryTestSuite) queryClientWithBlockTime(blockTime time.Time) types.QueryClient {
|
||||
ctx := suite.ctx.WithBlockTime(blockTime)
|
||||
queryHelper := baseapp.NewQueryServerTestHelper(ctx, suite.app.InterfaceRegistry())
|
||||
types.RegisterQueryServer(queryHelper, keeper.NewQueryServerImpl(suite.bk))
|
||||
return types.NewQueryClient(queryHelper)
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package validator_vesting
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
@ -15,6 +16,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/types/module"
|
||||
|
||||
"github.com/kava-labs/kava/x/validator-vesting/client/cli"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/keeper"
|
||||
"github.com/kava-labs/kava/x/validator-vesting/types"
|
||||
)
|
||||
|
||||
@ -54,7 +56,11 @@ func (AppModuleBasic) ValidateGenesis(cdc codec.JSONCodec, config client.TxEncod
|
||||
}
|
||||
|
||||
// RegisterGRPCGatewayRoutes registers the gRPC Gateway routes for validator-vesting module.
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {}
|
||||
func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *runtime.ServeMux) {
|
||||
if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetTxCmd returns validator-vesting module's root tx command.
|
||||
func (a AppModuleBasic) GetTxCmd() *cobra.Command { return nil }
|
||||
@ -90,7 +96,9 @@ func (am AppModule) Name() string {
|
||||
|
||||
// RegisterServices registers a GRPC query service to respond to the
|
||||
// module-specific GRPC queries.
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {}
|
||||
func (am AppModule) RegisterServices(cfg module.Configurator) {
|
||||
types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServerImpl(am.bankKeeper))
|
||||
}
|
||||
|
||||
// RegisterInvariants registers validator-vesting module's invariants.
|
||||
func (am AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}
|
||||
|
@ -1,26 +0,0 @@
|
||||
package types
|
||||
|
||||
// Querier routes for the validator vesting module
|
||||
const (
|
||||
QueryCirculatingSupply = "circulating-supply"
|
||||
QueryTotalSupply = "total-supply"
|
||||
QueryCirculatingSupplyHARD = "circulating-supply-hard"
|
||||
QueryCirculatingSupplyUSDX = "circulating-supply-usdx"
|
||||
QueryCirculatingSupplySWP = "circulating-supply-swp"
|
||||
QueryTotalSupplyHARD = "total-supply-hard"
|
||||
QueryTotalSupplyUSDX = "total-supply-usdx"
|
||||
)
|
||||
|
||||
// BaseQueryParams defines the parameters necessary for querying for all Evidence.
|
||||
type BaseQueryParams struct {
|
||||
Page int `json:"page" yaml:"page"`
|
||||
Limit int `json:"limit" yaml:"limit"`
|
||||
}
|
||||
|
||||
// NewBaseQueryParams returns a new BaseQueryParams
|
||||
func NewBaseQueryParams(page, limit int) BaseQueryParams {
|
||||
return BaseQueryParams{
|
||||
Page: page,
|
||||
Limit: limit,
|
||||
}
|
||||
}
|
2503
x/validator-vesting/types/query.pb.go
Normal file
2503
x/validator-vesting/types/query.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
543
x/validator-vesting/types/query.pb.gw.go
Normal file
543
x/validator-vesting/types/query.pb.gw.go
Normal file
@ -0,0 +1,543 @@
|
||||
// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT.
|
||||
// source: kava/validatorvesting/v1beta1/query.proto
|
||||
|
||||
/*
|
||||
Package types is a reverse proxy.
|
||||
|
||||
It translates gRPC into RESTful JSON APIs.
|
||||
*/
|
||||
package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/golang/protobuf/descriptor"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/runtime"
|
||||
"github.com/grpc-ecosystem/grpc-gateway/utilities"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// Suppress "imported and not used" errors
|
||||
var _ codes.Code
|
||||
var _ io.Reader
|
||||
var _ status.Status
|
||||
var _ = runtime.String
|
||||
var _ = utilities.NewDoubleArray
|
||||
var _ = descriptor.ForMessage
|
||||
var _ = metadata.Join
|
||||
|
||||
func request_Query_CirculatingSupply_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.CirculatingSupply(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_CirculatingSupply_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.CirculatingSupply(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_TotalSupply_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.TotalSupply(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_TotalSupply_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.TotalSupply(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_CirculatingSupplyHARD_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyHARDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.CirculatingSupplyHARD(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_CirculatingSupplyHARD_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyHARDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.CirculatingSupplyHARD(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_CirculatingSupplyUSDX_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyUSDXRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.CirculatingSupplyUSDX(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_CirculatingSupplyUSDX_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplyUSDXRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.CirculatingSupplyUSDX(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_CirculatingSupplySWP_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplySWPRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.CirculatingSupplySWP(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_CirculatingSupplySWP_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryCirculatingSupplySWPRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.CirculatingSupplySWP(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_TotalSupplyHARD_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyHARDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.TotalSupplyHARD(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_TotalSupplyHARD_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyHARDRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.TotalSupplyHARD(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func request_Query_TotalSupplyUSDX_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyUSDXRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := client.TotalSupplyUSDX(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
func local_request_Query_TotalSupplyUSDX_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
|
||||
var protoReq QueryTotalSupplyUSDXRequest
|
||||
var metadata runtime.ServerMetadata
|
||||
|
||||
msg, err := server.TotalSupplyUSDX(ctx, &protoReq)
|
||||
return msg, metadata, err
|
||||
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerServer registers the http handlers for service Query to "mux".
|
||||
// UnaryRPC :call QueryServer directly.
|
||||
// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.
|
||||
// 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_CirculatingSupply_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_CirculatingSupply_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_CirculatingSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupply_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_TotalSupply_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_TotalSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplyHARD_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_CirculatingSupplyHARD_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_CirculatingSupplyHARD_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplyUSDX_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_CirculatingSupplyUSDX_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_CirculatingSupplyUSDX_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplySWP_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_CirculatingSupplySWP_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_CirculatingSupplySWP_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupplyHARD_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_TotalSupplyHARD_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_TotalSupplyHARD_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupplyUSDX_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_TotalSupplyUSDX_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_TotalSupplyUSDX_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but
|
||||
// automatically dials to "endpoint" and closes the connection when "ctx" gets done.
|
||||
func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
|
||||
conn, err := grpc.Dial(endpoint, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
if cerr := conn.Close(); cerr != nil {
|
||||
grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr)
|
||||
}
|
||||
}()
|
||||
}()
|
||||
|
||||
return RegisterQueryHandler(ctx, mux, conn)
|
||||
}
|
||||
|
||||
// RegisterQueryHandler registers the http handlers for service Query to "mux".
|
||||
// The handlers forward requests to the grpc endpoint over "conn".
|
||||
func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error {
|
||||
return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn))
|
||||
}
|
||||
|
||||
// RegisterQueryHandlerClient registers the http handlers for service Query
|
||||
// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient".
|
||||
// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient"
|
||||
// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in
|
||||
// "QueryClient" to call the correct interceptors.
|
||||
func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error {
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupply_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_CirculatingSupply_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_CirculatingSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupply_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_TotalSupply_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_TotalSupply_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplyHARD_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_CirculatingSupplyHARD_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_CirculatingSupplyHARD_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplyUSDX_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_CirculatingSupplyUSDX_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_CirculatingSupplyUSDX_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_CirculatingSupplySWP_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_CirculatingSupplySWP_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_CirculatingSupplySWP_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupplyHARD_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_TotalSupplyHARD_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_TotalSupplyHARD_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
mux.Handle("GET", pattern_Query_TotalSupplyUSDX_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_TotalSupplyUSDX_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_TotalSupplyUSDX_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
|
||||
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
pattern_Query_CirculatingSupply_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "circulating_supply"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_TotalSupply_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "total_supply"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_CirculatingSupplyHARD_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "circulating_supply_hard"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_CirculatingSupplyUSDX_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "circulating_supply_usdx"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_CirculatingSupplySWP_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "circulating_supply_swp"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_TotalSupplyHARD_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "total_supply_hard"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
|
||||
pattern_Query_TotalSupplyUSDX_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"kava", "validator-vesting", "v1beta1", "total_supply_usdx"}, "", runtime.AssumeColonVerbOpt(false)))
|
||||
)
|
||||
|
||||
var (
|
||||
forward_Query_CirculatingSupply_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_TotalSupply_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_CirculatingSupplyHARD_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_CirculatingSupplyUSDX_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_CirculatingSupplySWP_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_TotalSupplyHARD_0 = runtime.ForwardResponseMessage
|
||||
|
||||
forward_Query_TotalSupplyUSDX_0 = runtime.ForwardResponseMessage
|
||||
)
|
Loading…
Reference in New Issue
Block a user