Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bank): supply by denom API #76

Merged
merged 1 commit into from
Feb 6, 2024
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terra-money/feather.js",
"version": "2.0.2",
"version": "2.0.3",
"description": "The JavaScript SDK for Terra and Feather chains",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down
12 changes: 11 additions & 1 deletion src/client/lcd/api/BankAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import exp from 'constants';

Check warning on line 1 in src/client/lcd/api/BankAPI.spec.ts

View workflow job for this annotation

GitHub Actions / build

'exp' is defined but never used
import { LCDClient } from '../LCDClient';
import { BankAPI } from './BankAPI';

Expand Down Expand Up @@ -27,9 +28,18 @@

describe('parameters', () => {
it('parameters', async () => {
const param = await bank.parameters('pisco-1');
const param = await bank.params('pisco-1');

expect(param.default_send_enabled).toBeDefined();
});
});

describe('supplyByDenom', () => {
it('query uluna supplyByDenom', async () => {
const res = await bank.supplyByDenom('pisco-1', 'uluna');

expect(res.denom).toBe('uluna');
expect(res.amount.toNumber()).toBeGreaterThan(0);
});
});
});
66 changes: 42 additions & 24 deletions src/client/lcd/api/BankAPI.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseAPI } from './BaseAPI';
import { Coins, AccAddress } from '../../../core';
import { Coins, Coin, AccAddress } from '../../../core';
import { APIParams, Pagination, PaginationOptions } from '../APIRequester';
import { LCDClient } from '../LCDClient';

Expand Down Expand Up @@ -31,6 +31,23 @@ export class BankAPI extends BaseAPI {
super(lcd.apiRequesters, lcd.config);
}

/**
* Query parameters of the bank module,
* @param chainID chain id
* @returns params of the bank module
*/
public async params(
chainID: string,
params: APIParams = {}
): Promise<BankParams> {
return this.getReqFromChainID(chainID)
.get<{ params: BankParams.Data }>(`/cosmos/bank/v1beta1/params`, params)
.then(({ params: d }) => ({
send_enabled: d.send_enabled,
default_send_enabled: d.default_send_enabled,
}));
}

/**
* Look up the balance of an account by its address.
* @param address address of account to look up.
Expand All @@ -47,6 +64,22 @@ export class BankAPI extends BaseAPI {
.then(d => [Coins.fromData(d.balances), d.pagination]);
}

/**
* Lqueries the spenable balance of all coins for a single account.
* @param address address of account to look up.
*/
public async spendableBalances(
address: AccAddress,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<[Coins, Pagination]> {
return this.getReqFromAddress(address)
.get<{
balances: Coins.Data;
pagination: Pagination;
}>(`/cosmos/bank/v1beta1/spendable_balances/${address}`, params)
.then(d => [Coins.fromData(d.balances), d.pagination]);
}

/**
* Get the total supply of tokens in circulation for all denominations.
* @param chainID chain id
Expand All @@ -64,31 +97,16 @@ export class BankAPI extends BaseAPI {
}

/**
* Lqueries the spenable balance of all coins for a single account.
* @param address address of account to look up.
* Get the total supply of tokens in circulation for all denom.
* @param chainID chain id
* @param denom denom of the coin
*/
public async spendableBalances(
address: AccAddress,
params: Partial<PaginationOptions & APIParams> = {}
): Promise<[Coins, Pagination]> {
return this.getReqFromAddress(address)
.get<{
balances: Coins.Data;
pagination: Pagination;
}>(`/cosmos/bank/v1beta1/spendable_balances/${address}`, params)
.then(d => [Coins.fromData(d.balances), d.pagination]);
}

public async parameters(
chainID: string,
params: APIParams = {}
): Promise<BankParams> {
public async supplyByDenom(chainID: string, denom: string): Promise<Coin> {
return this.getReqFromChainID(chainID)
.get<{ params: BankParams.Data }>(`/cosmos/bank/v1beta1/params`, params)
.then(({ params: d }) => ({
send_enabled: d.send_enabled,
default_send_enabled: d.default_send_enabled,
}));
.get<{ amount: Coin.Data }>(`/cosmos/bank/v1beta1/supply/by_denom`, {
denom: denom,
})
.then(d => Coin.fromData(d.amount));
}

// TODO: TBD: implement denoms_medata?
Expand Down
Loading