Skip to content

Commit b3e08e7

Browse files
committed
fix: use current circulating STX tokens for stx_supply endpoint, year 2050 estimate in new field
1 parent ad4e1ca commit b3e08e7

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/api/routes/stx-supply.ts

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import BigNumber from 'bignumber.js';
2-
import { microStxToStx, STACKS_DECIMAL_PLACES, TOTAL_STACKS } from '../../helpers';
2+
import { microStxToStx, STACKS_DECIMAL_PLACES, TOTAL_STACKS_YEAR_2050 } from '../../helpers';
33
import { handleChainTipCache } from '../controllers/cache-controller';
44

55
import { FastifyPluginAsync } from 'fastify';
@@ -23,18 +23,23 @@ export const StxSupplyRoutes: FastifyPluginAsync<
2323
): Promise<{
2424
unlockedPercent: string;
2525
totalStx: string;
26+
totalStxYear2050: string;
2627
unlockedStx: string;
2728
blockHeight: number;
2829
}> {
2930
const { stx: unlockedSupply, blockHeight } = await fastify.db.getUnlockedStxSupply(args);
30-
const totalMicroStx = new BigNumber(TOTAL_STACKS).shiftedBy(STACKS_DECIMAL_PLACES);
31+
const totalMicroStx = unlockedSupply;
32+
const totalMicroStxYear2050 = new BigNumber(TOTAL_STACKS_YEAR_2050).shiftedBy(
33+
STACKS_DECIMAL_PLACES
34+
);
3135
const unlockedPercent = new BigNumber(unlockedSupply.toString())
32-
.div(totalMicroStx)
36+
.div(new BigNumber(totalMicroStx.toString()))
3337
.times(100)
3438
.toFixed(2);
3539
return {
3640
unlockedPercent,
3741
totalStx: microStxToStx(totalMicroStx),
42+
totalStxYear2050: microStxToStx(totalMicroStxYear2050),
3843
unlockedStx: microStxToStx(unlockedSupply),
3944
blockHeight: blockHeight,
4045
};
@@ -47,8 +52,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
4752
schema: {
4853
operationId: 'get_stx_supply',
4954
summary: 'Get total and unlocked STX supply',
50-
description: `Retrieves the total and unlocked STX supply. More information on Stacking can be found [here] (https://docs.stacks.co/understand-stacks/stacking).
51-
**Note:** This uses the estimated future total supply for the year 2050.`,
55+
description: `Retrieves the total and unlocked STX supply. More information on Stacking can be found [here] (https://docs.stacks.co/understand-stacks/stacking).`,
5256
tags: ['Info'],
5357
querystring: Type.Object({
5458
height: Type.Optional(
@@ -70,7 +74,11 @@ export const StxSupplyRoutes: FastifyPluginAsync<
7074
'String quoted decimal number of the percentage of STX that have unlocked',
7175
}),
7276
total_stx: Type.String({
73-
description: 'String quoted decimal number of the total possible number of STX',
77+
description: 'String quoted decimal number of the total circulating number of STX',
78+
}),
79+
total_stx_year_2050: Type.String({
80+
description:
81+
'The Stacks cryptocurrency has a predefined future supply that reaches approx 1,818M STX by year 2050',
7482
}),
7583
unlocked_stx: Type.String({
7684
description:
@@ -98,6 +106,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
98106
await reply.send({
99107
unlocked_percent: supply.unlockedPercent,
100108
total_stx: supply.totalStx,
109+
total_stx_year_2050: supply.totalStxYear2050,
101110
unlocked_stx: supply.unlockedStx,
102111
block_height: supply.blockHeight,
103112
});
@@ -111,8 +120,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
111120
schema: {
112121
operationId: 'get_stx_supply_total_supply_plain',
113122
summary: 'Get total STX supply in plain text format',
114-
description: `Retrieves the total supply for STX tokens as plain text.
115-
**Note:** this uses the estimated future total supply for the year 2050.`,
123+
description: `Retrieves the total circulating STX token supply as plain text.`,
116124
tags: ['Info'],
117125
response: {
118126
200: {
@@ -165,8 +173,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
165173
operationId: 'get_total_stx_supply_legacy_format',
166174
summary:
167175
'Get total and unlocked STX supply (results formatted the same as the legacy 1.0 API)',
168-
description: `Retrieves total supply of STX tokens including those currently in circulation that have been unlocked.
169-
**Note:** this uses the estimated future total supply for the year 2050.`,
176+
description: `Retrieves total supply of STX tokens including those currently in circulation that have been unlocked.`,
170177
tags: ['Info'],
171178
querystring: Type.Object({
172179
height: Type.Optional(
@@ -188,11 +195,19 @@ export const StxSupplyRoutes: FastifyPluginAsync<
188195
'String quoted decimal number of the percentage of STX that have unlocked',
189196
}),
190197
totalStacks: Type.String({
191-
description: 'String quoted decimal number of the total possible number of STX',
198+
description: 'String quoted decimal number of the total circulating number of STX',
192199
}),
193200
totalStacksFormatted: Type.String({
194201
description: 'Same as `totalStacks` but formatted with comma thousands separators',
195202
}),
203+
totalStacksYear2050: Type.String({
204+
description:
205+
'The Stacks cryptocurrency has a predefined future supply that reaches approx 1,818M STX by year 2050',
206+
}),
207+
totalStacksYear2050Formatted: Type.String({
208+
description:
209+
'Same as `totalStacksYear2050` but formatted with comma thousands separators',
210+
}),
196211
unlockedSupply: Type.String({
197212
description:
198213
'String quoted decimal number of the STX that have been mined or unlocked',
@@ -224,6 +239,11 @@ export const StxSupplyRoutes: FastifyPluginAsync<
224239
unlockedPercent: supply.unlockedPercent,
225240
totalStacks: supply.totalStx,
226241
totalStacksFormatted: new BigNumber(supply.totalStx).toFormat(STACKS_DECIMAL_PLACES, 8),
242+
totalStacksYear2050: supply.totalStxYear2050,
243+
totalStacksYear2050Formatted: new BigNumber(supply.totalStxYear2050).toFormat(
244+
STACKS_DECIMAL_PLACES,
245+
8
246+
),
227247
unlockedSupply: supply.unlockedStx,
228248
unlockedSupplyFormatted: new BigNumber(supply.unlockedStx).toFormat(
229249
STACKS_DECIMAL_PLACES,

src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export function formatMapToObject<TKey extends string, TValue, TFormatted>(
149149
// > 500 STX/block for following 4 yrs;
150150
// > 250 for the 4 yrs after that; and then 125 STX/block in perpetuity after that.
151151
// We are going to use the year 2050 projected supply because "125 STX/block in perpetuity" means the total supply is infinite.
152-
export const TOTAL_STACKS = new BigNumber(1_818_000_000n.toString());
152+
export const TOTAL_STACKS_YEAR_2050 = new BigNumber(1_818_000_000n.toString());
153153

154154
const MICROSTACKS_IN_STACKS = 1_000_000n;
155155
export const STACKS_DECIMAL_PLACES = 6;

0 commit comments

Comments
 (0)