From e790055d03df0786c93db54d4d3294160fac1ad5 Mon Sep 17 00:00:00 2001 From: dtfiedler Date: Wed, 16 Oct 2024 15:46:42 -0500 Subject: [PATCH] fix(io): update `getTokenSupply` to type that returns full breakdown of tokens Note: this is a breaking change, but the API was known to be underdvelopment and not used by many clients, so we will keep it as a fix. --- src/common/io.ts | 5 +++-- src/io.ts | 12 +++++++++++- tests/e2e/esm/index.test.js | 7 +++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/common/io.ts b/src/common/io.ts index 628fb558..016b94fc 100644 --- a/src/common/io.ts +++ b/src/common/io.ts @@ -38,6 +38,7 @@ import { AoGatewayWithAddress, AoJoinNetworkParams, AoMessageResult, + AoTokenSupplyData, AoUpdateGatewaySettingsParams, AoWeightedObserver, ContractSigner, @@ -131,8 +132,8 @@ export class IOReadable implements AoIORead { }); } - async getTokenSupply(): Promise { - return this.process.read({ + async getTokenSupply(): Promise { + return this.process.read({ tags: [{ name: 'Action', value: 'Total-Token-Supply' }], }); } diff --git a/src/io.ts b/src/io.ts index 7d0daf73..4f87e24f 100644 --- a/src/io.ts +++ b/src/io.ts @@ -166,6 +166,16 @@ export type AoEpochData = { distributions: AoEpochDistributionData; }; +export type AoTokenSupplyData = { + total: number; + circulating: number; + locked: number; + withdrawn: number; + delegated: number; + staked: number; + protocolBalance: number; +}; + export type AoGatewayService = { fqdn: string; path: string; @@ -323,7 +333,7 @@ export interface AoIORead { Handlers: string[]; LastTickedEpochIndex: number; }>; - getTokenSupply(): Promise; + getTokenSupply(): Promise; getEpochSettings(params?: EpochInput): Promise; getGateway({ address, diff --git a/tests/e2e/esm/index.test.js b/tests/e2e/esm/index.test.js index 22a56585..24bbdc3d 100644 --- a/tests/e2e/esm/index.test.js +++ b/tests/e2e/esm/index.test.js @@ -71,6 +71,13 @@ describe('IO', async () => { it('should be able to get the total token supply', async () => { const tokenSupply = await io.getTokenSupply(); assert.ok(tokenSupply); + assert(typeof tokenSupply.total === 'number'); + assert(typeof tokenSupply.circulating === 'number'); + assert(typeof tokenSupply.locked === 'number'); + assert(typeof tokenSupply.withdrawn === 'number'); + assert(typeof tokenSupply.delegated === 'number'); + assert(typeof tokenSupply.staked === 'number'); + assert(typeof tokenSupply.protocolBalance === 'number'); }); it('should be able to get first set of arns records', async () => {