Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/passage/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/crisis"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
claimCmd "github.com/envadiv/Passage3D/x/claim/client/cli"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -198,6 +199,11 @@ func queryCommand() *cobra.Command {
)

app.ModuleBasics.AddQueryCommands(cmd)

// Add supply summary command in bank module queries
bankCmd, _, _ := cmd.Find([]string{"bank"})
bankCmd.AddCommand(claimCmd.GetCmdSupplySummary())

cmd.PersistentFlags().String(flags.FlagChainID, "", "The network chain ID")

return cmd
Expand Down
2,442 changes: 2,442 additions & 0 deletions go.sum

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions proto/passage3d/claim/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "google/api/annotations.proto";
import "cosmos/base/v1beta1/coin.proto";
import "passage3d/claim/v1beta1/params.proto";
import "passage3d/claim/v1beta1/claim_record.proto";
import "passage3d/claim/v1beta1/supply.proto";

option go_package = "github.com/envadiv/passage3d/x/claim/types";

Expand Down Expand Up @@ -36,6 +37,11 @@ service Query {
option (google.api.http).get = "/passage3d/claim/v1beta1/total_claimable/{address}";
}

// SupplySummary return supply summary
rpc SupplySummary(QuerySupplySummaryRequest) returns (QuerySupplySummaryResponse) {
option (google.api.http).get = "/passage3d/supply/v1beta1/summary";
}

}

// QueryModuleAccountBalanceRequest is the request type for the Query/ModuleAccountBalance RPC method.
Expand Down Expand Up @@ -101,3 +107,11 @@ message QueryTotalClaimableResponse {
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"
];
}

// QuerySupplySummaryRequest is request type for the Query/SupplySummary RPC method
message QuerySupplySummaryRequest {}

// QuerySupplySummaryResponse is response type for the Query/SupplySummary RPC method
message QuerySupplySummaryResponse {
Supply supply = 1 [ (gogoproto.nullable) = false ];
}
52 changes: 52 additions & 0 deletions proto/passage3d/claim/v1beta1/supply.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
syntax = "proto3";
package passage3d.claim.v1beta1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/envadiv/passage3d/x/claim/types";

// CoinDetails represents bonded and unbonded coin details
message CoinDetails {
repeated cosmos.base.v1beta1.Coin bonded = 1 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "bonded",
(gogoproto.moretags) = "yaml:\"bonded\""
];
repeated cosmos.base.v1beta1.Coin unbonded = 2 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "unbonded",
(gogoproto.moretags) = "yaml:\"unbonded\""
];
}

// Supply represents total coins vested, available and circulating supply
message Supply {
option (gogoproto.equal) = false;
option (gogoproto.goproto_getters) = false;

CoinDetails vesting = 1 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "vesting",
(gogoproto.moretags) = "yaml:\"vesting\""
];
CoinDetails available = 2 [
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "available",
(gogoproto.moretags) = "yaml:\"available\""
];
repeated cosmos.base.v1beta1.Coin circulating = 3 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "circulating",
(gogoproto.moretags) = "yaml:\"circulating\""
];
repeated cosmos.base.v1beta1.Coin total = 4 [
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins",
(gogoproto.nullable) = false,
(gogoproto.jsontag) = "total",
(gogoproto.moretags) = "yaml:\"total\""
];
}
2 changes: 1 addition & 1 deletion scripts/protocgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -eo pipefail
# get protoc executions
go get github.com/regen-network/cosmos-proto/protoc-gen-gocosmos 2>/dev/null
# get cosmos sdk from github
go get github.com/cosmos/cosmos-sdk 2>/dev/null
go get github.com/cosmos/cosmos-sdk@v0.45.16 2>/dev/null

# Get the path of the cosmos-sdk repo from go/pkg/mod
cosmos_sdk_dir=$(go list -f '{{ .Dir }}' -m github.com/cosmos/cosmos-sdk)
Expand Down
27 changes: 27 additions & 0 deletions x/claim/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,30 @@ $ %s query claim total-claimable osmo1ey69r37gfxvxg62sh4r0ktpuc46pzjrm23kcrx
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// GetCmdSupplySummary implements query for supply summary
func GetCmdSupplySummary() *cobra.Command {
cmd := &cobra.Command{
Use: "supply-summary",
Short: "Query for supply summary",
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.SupplySummary(context.Background(), &types.QuerySupplySummaryRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Supply)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}
62 changes: 62 additions & 0 deletions x/claim/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/envadiv/Passage3D/x/claim/types"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
vestingexported "github.com/cosmos/cosmos-sdk/x/auth/vesting/exported"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

// Querier is used as Keeper will have duplicate methods if used directly, and gRPC names take precedence over keeper
Expand Down Expand Up @@ -90,3 +93,62 @@ func (k Keeper) TotalClaimable(goCtx context.Context, req *types.QueryTotalClaim
Coins: coins,
}, err
}

func (k Keeper) SupplySummary(goCtx context.Context, req *types.QuerySupplySummaryRequest) (
*types.QuerySupplySummaryResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)

var supplyData types.Supply
k.bankKeeper.IterateTotalSupply(ctx, func(c sdk.Coin) bool {
supplyData.Total = append(supplyData.Total, c)
return false
})
bondDenom := k.stakingKeeper.BondDenom(ctx)

delegationsMap := make(map[string]sdk.Coins)
k.stakingKeeper.IterateAllDelegations(ctx, func(delegation stakingtypes.Delegation) bool {
// Converting delegated shares to sdk.Coin
delegated := sdk.NewCoin(bondDenom, delegation.Shares.TruncateInt())
delegationsMap[delegation.DelegatorAddress] = delegationsMap[delegation.DelegatorAddress].Add(delegated)
return false
})

k.accountKeeper.IterateAccounts(ctx, func(account authtypes.AccountI) bool {
if ma, ok := account.(*authtypes.ModuleAccount); ok {
switch ma.Name {
case stakingtypes.NotBondedPoolName, stakingtypes.BondedPoolName:
return false
}
}
delegatedTokens := delegationsMap[account.GetAddress().String()]
balances := k.bankKeeper.GetAllBalances(ctx, account.GetAddress())
va, ok := account.(vestingexported.VestingAccount)
if !ok {
supplyData.Available.Bonded = supplyData.Available.Bonded.Add(delegatedTokens...)
supplyData.Available.Unbonded = supplyData.Available.Unbonded.Add(balances...)
} else {
vestingCoins := va.GetVestingCoins(ctx.BlockTime())
delegatedVesting := va.GetDelegatedVesting()
lockedCoins := va.LockedCoins(ctx.BlockTime())
spendableCoins := balances.Sub(lockedCoins)
if delegatedVesting.AmountOf(bondDenom).GT(vestingCoins.AmountOf(bondDenom)) {
supplyData.Vesting.Bonded = supplyData.Vesting.Bonded.Add(vestingCoins...)
supplyData.Available.Bonded = supplyData.Available.Bonded.Add(delegatedVesting...).Sub(vestingCoins)
} else {
supplyData.Vesting.Bonded = supplyData.Vesting.Bonded.Add(delegatedVesting...)
supplyData.Available.Bonded = supplyData.Available.Bonded.Add(delegatedTokens...).Sub(delegatedVesting)
}
supplyData.Vesting.Unbonded = supplyData.Vesting.Unbonded.Add(lockedCoins...)
supplyData.Available.Unbonded = supplyData.Available.Unbonded.Add(spendableCoins...)
}
return false
})

communityPool, _ := k.distrKeeper.GetFeePoolCommunityCoins(ctx).TruncateDecimal()

supplyData.Circulating = supplyData.Total.Sub(supplyData.Vesting.Unbonded).Sub(supplyData.Vesting.Bonded).Sub(communityPool)

return &types.QuerySupplySummaryResponse{
Supply: supplyData,
}, nil
}
6 changes: 6 additions & 0 deletions x/claim/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ func (suite *KeeperTestSuite) TestGrpcQueryClaimRecords() {
//suite.Require().NoError(err)
//suite.Require().Equal(actionResp.String(), sdk.NewCoins(sdk.NewCoin(types.DefaultClaimDenom, sdk.NewInt(100))).String())
}

func (suite *KeeperTestSuite) TestGrpcQuerySupplySummary() {
grpcClient := suite.queryClient
_, err := grpcClient.SupplySummary(context.Background(), &types.QuerySupplySummaryRequest{})
suite.Require().NoError(err)
}
2 changes: 2 additions & 0 deletions x/claim/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package types

import (
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)

type StakingKeeper interface {
BondDenom(sdk.Context) string
IterateAllDelegations(ctx sdk.Context, cb func(stakingtypes.Delegation) bool)
}
Loading