From 94c350e068051b6d01ea412e69df403bed7db7b4 Mon Sep 17 00:00:00 2001 From: Bella Date: Thu, 10 Jun 2021 21:32:30 +0800 Subject: [PATCH 1/8] /kind feature Add rpc_accounts listCommunityBalances --- .../account/listCommunityBalances.test.ts | 24 +++++++++++++++++++ .../src/category/account.ts | 14 +++++++---- website/docs/jellyfish/api/account.md | 1 + 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts new file mode 100644 index 0000000000..0866e760de --- /dev/null +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -0,0 +1,24 @@ +import { MasterNodeRegTestContainer } from '@defichain/testcontainers' +import { ContainerAdapterClient } from '../../container_adapter_client' + +describe('Account', () => { + const container = new MasterNodeRegTestContainer() + const client = new ContainerAdapterClient(container) + + beforeAll(async () => { + await container.start() + await container.waitForReady() + }) + + afterAll(async () => { + await container.stop() + }) + + it('should listCommunityBalances', async () => { + const data = await client.account.listCommunityBalances() + + expect(data.AnchorReward).toBeGreaterThanOrEqual(0) + expect(data.IncentiveFunding).toBeGreaterThanOrEqual(0) + expect(data.Burnt).toBeGreaterThanOrEqual(0) + }) +}) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 7607e13dbb..6e0d75a6d7 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -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', @@ -73,7 +73,7 @@ export class Account { * @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet * @return {Promise>>} */ - listAccounts (pagination: AccountPagination, verbose: false, options: {indexedAmounts: false, isMineOnly: boolean}): Promise>> + listAccounts (pagination: AccountPagination, verbose: false, options: { indexedAmounts: false, isMineOnly: boolean }): Promise>> /** * Get information about all accounts on chain @@ -89,7 +89,7 @@ export class Account { * @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet * @return {Promise>>} */ - listAccounts (pagination: AccountPagination, verbose: true, options: {indexedAmounts: true, isMineOnly: boolean}): Promise>> + listAccounts (pagination: AccountPagination, verbose: true, options: { indexedAmounts: true, isMineOnly: boolean }): Promise>> /** * Get information about all accounts on chain @@ -105,7 +105,7 @@ export class Account { * @param {boolean} [options.isMineOnly=false] get balances about all accounts belonging to the wallet * @return {Promise>>} */ - listAccounts (pagination: AccountPagination, verbose: false, options: {indexedAmounts: true, isMineOnly: boolean}): Promise>> + listAccounts (pagination: AccountPagination, verbose: false, options: { indexedAmounts: true, isMineOnly: boolean }): Promise>> async listAccounts ( pagination: AccountPagination = { limit: 100 }, @@ -387,3 +387,9 @@ export interface AccountHistoryCountOptions { txtype?: DfTxType no_rewards?: boolean } + +export interface CommunityBalanceData { + AnchorReward: number + IncentiveFunding?: number + Burnt: number +} diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index 30ad88b7c1..7e312b8994 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -283,3 +283,4 @@ interface AccountHistoryCountOptions { no_rewards?: boolean } ``` + From 02a93b1cd7fe9ec3bbcfe6bf27d93bb464db8b54 Mon Sep 17 00:00:00 2001 From: Bella Date: Thu, 10 Jun 2021 22:25:01 +0800 Subject: [PATCH 2/8] /kind feature Added listCommunityBalances RPC --- .../jellyfish-api-core/src/category/account.ts | 9 +++++++++ website/docs/jellyfish/api/account.md | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 6e0d75a6d7..438037f8f0 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -311,6 +311,15 @@ export class Account { ): Promise { return await this.client.call('accounthistorycount', [owner, options], 'number') } + + /** + * Returns information about current anchor bonus, incentive funding, burnt token(s) + * + * @return {Promise} + */ + async listCommunityBalances (): Promise { + return await this.client.call('listcommunitybalances', [], 'number') + } } export interface AccountPagination { diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index 7e312b8994..6356e78d32 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -284,3 +284,19 @@ interface AccountHistoryCountOptions { } ``` + +## listCommunityBalances + +Returns information about current anchor bonus + +```ts title="client.account.listCommunityBalances()" +interface account { + listCommunityBalances (): Promise +} + +interface CommunityBalanceData { + AnchorReward: number + IncentiveFunding?: number + Burnt: number +} +``` From efb914897faadf076244a59df5fa8dd28c7ae411 Mon Sep 17 00:00:00 2001 From: Bella Date: Fri, 11 Jun 2021 18:55:34 +0800 Subject: [PATCH 3/8] listCommunityBalances RPC: amend to Bignumber --- .../category/account/listCommunityBalances.test.ts | 7 ++++--- packages/jellyfish-api-core/src/category/account.ts | 8 ++++---- website/docs/jellyfish/api/account.md | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts index 0866e760de..195c19ed91 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -1,5 +1,6 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' +import { BigNumber } from '@defichain/jellyfish-json' describe('Account', () => { const container = new MasterNodeRegTestContainer() @@ -17,8 +18,8 @@ describe('Account', () => { it('should listCommunityBalances', async () => { const data = await client.account.listCommunityBalances() - expect(data.AnchorReward).toBeGreaterThanOrEqual(0) - expect(data.IncentiveFunding).toBeGreaterThanOrEqual(0) - expect(data.Burnt).toBeGreaterThanOrEqual(0) + expect(data.AnchorReward instanceof BigNumber).toStrictEqual(true) + expect(data.IncentiveFunding instanceof BigNumber).toStrictEqual(true) + expect(data.Burnt instanceof BigNumber).toStrictEqual(true) }) }) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index 438037f8f0..f7f5b2dc8c 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -318,7 +318,7 @@ export class Account { * @return {Promise} */ async listCommunityBalances (): Promise { - return await this.client.call('listcommunitybalances', [], 'number') + return await this.client.call('listcommunitybalances', [], 'bignumber') } } @@ -398,7 +398,7 @@ export interface AccountHistoryCountOptions { } export interface CommunityBalanceData { - AnchorReward: number - IncentiveFunding?: number - Burnt: number + AnchorReward: BigNumber + IncentiveFunding?: BigNumber + Burnt: BigNumber } diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index 6356e78d32..ebc6ae5637 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -295,8 +295,8 @@ interface account { } interface CommunityBalanceData { - AnchorReward: number - IncentiveFunding?: number - Burnt: number + AnchorReward: BigNumber + IncentiveFunding?: BigNumber + Burnt: BigNumber } ``` From 4fd8686a54c130f2edb2287f4f771aa443e6c148 Mon Sep 17 00:00:00 2001 From: Bella Date: Sat, 12 Jun 2021 01:43:10 +0800 Subject: [PATCH 4/8] account.md: - remove extra break line - updated #listCommunityBalances definition --- website/docs/jellyfish/api/account.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index ebc6ae5637..f3b1303c8b 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -284,10 +284,9 @@ interface AccountHistoryCountOptions { } ``` - ## listCommunityBalances -Returns information about current anchor bonus +Returns information about current anchor bonus, incentive funding, burnt token(s) ```ts title="client.account.listCommunityBalances()" interface account { From 4bbbf50a3a8a0f9b3a72402142b53264ec3684eb Mon Sep 17 00:00:00 2001 From: Bella Date: Mon, 14 Jun 2021 23:33:26 +0800 Subject: [PATCH 5/8] add props: Swap, Futures, Options, Unallocated, Unknown --- .../__tests__/category/account/listCommunityBalances.test.ts | 5 +++++ packages/jellyfish-api-core/src/category/account.ts | 5 +++++ website/docs/jellyfish/api/account.md | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts index 195c19ed91..06ec5169c4 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -20,6 +20,11 @@ describe('Account', () => { expect(data.AnchorReward instanceof BigNumber).toStrictEqual(true) expect(data.IncentiveFunding instanceof BigNumber).toStrictEqual(true) + expect(data.Swap instanceof BigNumber).toStrictEqual(false) + expect(data.Futures instanceof BigNumber).toStrictEqual(false) + expect(data.Options instanceof BigNumber).toStrictEqual(false) + expect(data.Unallocated instanceof BigNumber).toStrictEqual(false) + expect(data.Unknown instanceof BigNumber).toStrictEqual(false) expect(data.Burnt instanceof BigNumber).toStrictEqual(true) }) }) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index f7f5b2dc8c..e4c9a9cd25 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -400,5 +400,10 @@ export interface AccountHistoryCountOptions { export interface CommunityBalanceData { AnchorReward: BigNumber IncentiveFunding?: BigNumber + Swap?: BigNumber + Futures?: BigNumber + Options?: BigNumber + Unallocated?: BigNumber + Unknown?: BigNumber Burnt: BigNumber } diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index f3b1303c8b..60073e3a0c 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -296,6 +296,11 @@ interface account { interface CommunityBalanceData { AnchorReward: BigNumber IncentiveFunding?: BigNumber + Swap?: BigNumber + Futures?: BigNumber + Options?: BigNumber + Unallocated?: BigNumber + Unknown?: BigNumber Burnt: BigNumber } ``` From 983205261be1923e99e1686ee9eb93277cfdb0ab Mon Sep 17 00:00:00 2001 From: Bella Date: Tue, 15 Jun 2021 19:46:56 +0800 Subject: [PATCH 6/8] props: Swap, Futures, Options, Unallocated, Unknown change toBeUndefined() --- .../category/account/listCommunityBalances.test.ts | 10 +++++----- packages/jellyfish-api-core/src/category/account.ts | 2 +- website/docs/jellyfish/api/account.md | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts index 06ec5169c4..a9228b2222 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -20,11 +20,11 @@ describe('Account', () => { expect(data.AnchorReward instanceof BigNumber).toStrictEqual(true) expect(data.IncentiveFunding instanceof BigNumber).toStrictEqual(true) - expect(data.Swap instanceof BigNumber).toStrictEqual(false) - expect(data.Futures instanceof BigNumber).toStrictEqual(false) - expect(data.Options instanceof BigNumber).toStrictEqual(false) - expect(data.Unallocated instanceof BigNumber).toStrictEqual(false) - expect(data.Unknown instanceof BigNumber).toStrictEqual(false) 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() }) }) diff --git a/packages/jellyfish-api-core/src/category/account.ts b/packages/jellyfish-api-core/src/category/account.ts index e4c9a9cd25..58b1c3e66c 100644 --- a/packages/jellyfish-api-core/src/category/account.ts +++ b/packages/jellyfish-api-core/src/category/account.ts @@ -400,10 +400,10 @@ export interface AccountHistoryCountOptions { export interface CommunityBalanceData { AnchorReward: BigNumber IncentiveFunding?: BigNumber + Burnt: BigNumber Swap?: BigNumber Futures?: BigNumber Options?: BigNumber Unallocated?: BigNumber Unknown?: BigNumber - Burnt: BigNumber } diff --git a/website/docs/jellyfish/api/account.md b/website/docs/jellyfish/api/account.md index 60073e3a0c..f005f92610 100644 --- a/website/docs/jellyfish/api/account.md +++ b/website/docs/jellyfish/api/account.md @@ -296,11 +296,11 @@ interface account { interface CommunityBalanceData { AnchorReward: BigNumber IncentiveFunding?: BigNumber + Burnt: BigNumber Swap?: BigNumber Futures?: BigNumber Options?: BigNumber Unallocated?: BigNumber Unknown?: BigNumber - Burnt: BigNumber } ``` From 2fde04bae685c11baf35207c0dc809e082e21022 Mon Sep 17 00:00:00 2001 From: Bella Date: Wed, 16 Jun 2021 16:19:07 +0800 Subject: [PATCH 7/8] Amend '@defichain/jellyfish-json' to 'bignumber.js' --- .../__tests__/category/account/listCommunityBalances.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts index a9228b2222..148b8b3d39 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -1,6 +1,6 @@ import { MasterNodeRegTestContainer } from '@defichain/testcontainers' import { ContainerAdapterClient } from '../../container_adapter_client' -import { BigNumber } from '@defichain/jellyfish-json' +import BigNumber from 'bignumber.js' describe('Account', () => { const container = new MasterNodeRegTestContainer() From 84503e9c4222983c537597db2fc6c4c1d62f0165 Mon Sep 17 00:00:00 2001 From: Bella Date: Tue, 22 Jun 2021 16:20:57 +0800 Subject: [PATCH 8/8] Added `container.waitForWalletCoinbaseMaturity()` --- .../__tests__/category/account/listCommunityBalances.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts index 148b8b3d39..11c1df3b1c 100644 --- a/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/account/listCommunityBalances.test.ts @@ -9,6 +9,7 @@ describe('Account', () => { beforeAll(async () => { await container.start() await container.waitForReady() + await container.waitForWalletCoinbaseMaturity() }) afterAll(async () => {