-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueries.ts
61 lines (57 loc) · 1.76 KB
/
queries.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { TendermintClient } from "npm:@cosmjs/tendermint-rpc";
import {
Coin,
coin,
decodeCosmosSdkDecFromProto,
QueryClient,
setupBankExtension,
setupDistributionExtension,
setupIbcExtension
} from "npm:@cosmjs/stargate";
import { setupWasmExtension } from "npm:@cosmjs/cosmwasm-stargate";
export async function totalSupply(tmClient: TendermintClient, searchDenom: string): Promise<Coin> {
const queryClient = QueryClient.withExtensions(tmClient, setupBankExtension);
return await queryClient.bank.supplyOf(searchDenom);
}
/* Queries the community pool funds in full unois. */
export async function communityPoolFunds(
tmClient: TendermintClient,
searchDenom: string
): Promise<Coin> {
const queryClient = QueryClient.withExtensions(tmClient, setupDistributionExtension);
const resp = await queryClient.distribution.communityPool();
const unois = resp.pool.find((coin) => coin.denom === searchDenom);
if (!unois) {
return coin(0, searchDenom);
} else {
const amount = decodeCosmosSdkDecFromProto(unois.amount).floor().toString();
return coin(amount, searchDenom);
}
}
export async function getContractUsage(
tmClient: TendermintClient,
contractAddress: string,
) {
const queryClient = QueryClient.withExtensions(tmClient, setupWasmExtension);
let res: any;
try {
res = await queryClient.wasm.queryContractSmart(contractAddress, {
customers: {},
});
} catch (error) {
console.error(error);
}
return res;
}
export async function getIbcChannels(
tmClient: TendermintClient
) {
const queryClient = QueryClient.withExtensions(tmClient, setupIbcExtension);
let res, filteredChannels;
try {
res = await queryClient.ibc.channel.channels();
} catch (error) {
console.error(error);
}
return res.channels;
}