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

Added listCommunityBalances RPC #368

Merged
merged 9 commits into from
Jun 23, 2021
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { MasterNodeRegTestContainer } from '@defichain/testcontainers'
import { ContainerAdapterClient } from '../../container_adapter_client'
import { BigNumber } from '@defichain/jellyfish-json'

describe('Account', () => {
const container = new MasterNodeRegTestContainer()
const client = new ContainerAdapterClient(container)

beforeAll(async () => {
await container.start()
await container.waitForReady()
canonbrother marked this conversation as resolved.
Show resolved Hide resolved
})

afterAll(async () => {
await container.stop()
})

it('should listCommunityBalances', async () => {
const data = await client.account.listCommunityBalances()

expect(data.AnchorReward instanceof BigNumber).toStrictEqual(true)
expect(data.IncentiveFunding instanceof BigNumber).toStrictEqual(true)
expect(data.Burnt instanceof BigNumber).toStrictEqual(true)
expect(data.Swap).toBeUndefined()
expect(data.Futures).toBeUndefined()
expect(data.Options).toBeUndefined()
expect(data.Unallocated).toBeUndefined()
expect(data.Unknown).toBeUndefined()
})
})
28 changes: 24 additions & 4 deletions packages/jellyfish-api-core/src/category/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export enum OwnerType {
}

export enum DfTxType {
MINT_TOKEN ='M',
MINT_TOKEN = 'M',
POOL_SWAP = 's',
ADD_POOL_LIQUIDITY = 'l',
REMOVE_POOL_LIQUIDITY = 'r',
Expand Down Expand Up @@ -73,7 +73,7 @@ export class Account {
* @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet
* @return {Promise<Array<AccountResult<string, string>>>}
*/
listAccounts (pagination: AccountPagination, verbose: false, options: {indexedAmounts: false, isMineOnly: boolean}): Promise<Array<AccountResult<string, string>>>
listAccounts (pagination: AccountPagination, verbose: false, options: { indexedAmounts: false, isMineOnly: boolean }): Promise<Array<AccountResult<string, string>>>

/**
* Get information about all accounts on chain
Expand All @@ -89,7 +89,7 @@ export class Account {
* @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet
* @return {Promise<Array<AccountResult<AccountOwner, AccountAmount>>>}
*/
listAccounts (pagination: AccountPagination, verbose: true, options: {indexedAmounts: true, isMineOnly: boolean}): Promise<Array<AccountResult<AccountOwner, AccountAmount>>>
listAccounts (pagination: AccountPagination, verbose: true, options: { indexedAmounts: true, isMineOnly: boolean }): Promise<Array<AccountResult<AccountOwner, AccountAmount>>>

/**
* Get information about all accounts on chain
Expand All @@ -105,7 +105,7 @@ export class Account {
* @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet
* @return {Promise<Array<AccountResult<string, AccountAmount>>>}
*/
listAccounts (pagination: AccountPagination, verbose: false, options: {indexedAmounts: true, isMineOnly: boolean}): Promise<Array<AccountResult<string, AccountAmount>>>
listAccounts (pagination: AccountPagination, verbose: false, options: { indexedAmounts: true, isMineOnly: boolean }): Promise<Array<AccountResult<string, AccountAmount>>>

async listAccounts<T, U> (
pagination: AccountPagination = { limit: 100 },
Expand Down Expand Up @@ -311,6 +311,15 @@ export class Account {
): Promise<number> {
return await this.client.call('accounthistorycount', [owner, options], 'number')
}

/**
* Returns information about current anchor bonus, incentive funding, burnt token(s)
*
* @return {Promise<CommunityBalanceData>}
*/
async listCommunityBalances (): Promise<CommunityBalanceData> {
return await this.client.call('listcommunitybalances', [], 'bignumber')
}
}

export interface AccountPagination {
Expand Down Expand Up @@ -387,3 +396,14 @@ export interface AccountHistoryCountOptions {
txtype?: DfTxType
no_rewards?: boolean
}

export interface CommunityBalanceData {
AnchorReward: BigNumber
IncentiveFunding?: BigNumber
Burnt: BigNumber
izzycsy marked this conversation as resolved.
Show resolved Hide resolved
Swap?: BigNumber
Futures?: BigNumber
Options?: BigNumber
Unallocated?: BigNumber
Unknown?: BigNumber
}
21 changes: 21 additions & 0 deletions website/docs/jellyfish/api/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,3 +283,24 @@ interface AccountHistoryCountOptions {
no_rewards?: boolean
}
```

izzycsy marked this conversation as resolved.
Show resolved Hide resolved
canonbrother marked this conversation as resolved.
Show resolved Hide resolved
## listCommunityBalances

Returns information about current anchor bonus, incentive funding, burnt token(s)

```ts title="client.account.listCommunityBalances()"
interface account {
listCommunityBalances (): Promise<CommunityBalanceData>
}

interface CommunityBalanceData {
AnchorReward: BigNumber
IncentiveFunding?: BigNumber
Burnt: BigNumber
Swap?: BigNumber
Futures?: BigNumber
Options?: BigNumber
Unallocated?: BigNumber
Unknown?: BigNumber
}
```