Skip to content

Commit ff13799

Browse files
authored
Merge pull request #2093 from hirosystems/fix/stx-supply
Cut beta release
2 parents ad4e1ca + 2506eab commit ff13799

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/api/routes/stx-supply.ts

+36-11
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,12 @@ 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:
78+
'String quoted decimal number of the total circulating number of STX (at the input block height if provided, otherwise the current block height)',
79+
}),
80+
total_stx_year_2050: Type.String({
81+
description:
82+
'String quoted decimal number of total circulating STX supply in year 2050. STX supply grows approx 0.3% annually thereafter in perpetuity.',
7483
}),
7584
unlocked_stx: Type.String({
7685
description:
@@ -98,6 +107,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
98107
await reply.send({
99108
unlocked_percent: supply.unlockedPercent,
100109
total_stx: supply.totalStx,
110+
total_stx_year_2050: supply.totalStxYear2050,
101111
unlocked_stx: supply.unlockedStx,
102112
block_height: supply.blockHeight,
103113
});
@@ -109,10 +119,10 @@ export const StxSupplyRoutes: FastifyPluginAsync<
109119
{
110120
preHandler: handleChainTipCache,
111121
schema: {
122+
deprecated: true,
112123
operationId: 'get_stx_supply_total_supply_plain',
113124
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.`,
125+
description: `Retrieves the total circulating STX token supply as plain text.`,
116126
tags: ['Info'],
117127
response: {
118128
200: {
@@ -136,6 +146,7 @@ export const StxSupplyRoutes: FastifyPluginAsync<
136146
{
137147
preHandler: handleChainTipCache,
138148
schema: {
149+
deprecated: true,
139150
operationId: 'get_stx_supply_circulating_plain',
140151
summary: 'Get circulating STX supply in plain text format',
141152
description: `Retrieves the STX tokens currently in circulation that have been unlocked as plain text.`,
@@ -162,11 +173,11 @@ export const StxSupplyRoutes: FastifyPluginAsync<
162173
{
163174
preHandler: handleChainTipCache,
164175
schema: {
176+
deprecated: true,
165177
operationId: 'get_total_stx_supply_legacy_format',
166178
summary:
167179
'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.`,
180+
description: `Retrieves total supply of STX tokens including those currently in circulation that have been unlocked.`,
170181
tags: ['Info'],
171182
querystring: Type.Object({
172183
height: Type.Optional(
@@ -188,11 +199,20 @@ export const StxSupplyRoutes: FastifyPluginAsync<
188199
'String quoted decimal number of the percentage of STX that have unlocked',
189200
}),
190201
totalStacks: Type.String({
191-
description: 'String quoted decimal number of the total possible number of STX',
202+
description:
203+
'String quoted decimal number of the total circulating number of STX (at the input block height if provided, otherwise the current block height)',
192204
}),
193205
totalStacksFormatted: Type.String({
194206
description: 'Same as `totalStacks` but formatted with comma thousands separators',
195207
}),
208+
totalStacksYear2050: Type.String({
209+
description:
210+
'String quoted decimal number of total circulating STX supply in year 2050. STX supply grows approx 0.3% annually thereafter in perpetuity.',
211+
}),
212+
totalStacksYear2050Formatted: Type.String({
213+
description:
214+
'Same as `totalStacksYear2050` but formatted with comma thousands separators',
215+
}),
196216
unlockedSupply: Type.String({
197217
description:
198218
'String quoted decimal number of the STX that have been mined or unlocked',
@@ -224,6 +244,11 @@ export const StxSupplyRoutes: FastifyPluginAsync<
224244
unlockedPercent: supply.unlockedPercent,
225245
totalStacks: supply.totalStx,
226246
totalStacksFormatted: new BigNumber(supply.totalStx).toFormat(STACKS_DECIMAL_PLACES, 8),
247+
totalStacksYear2050: supply.totalStxYear2050,
248+
totalStacksYear2050Formatted: new BigNumber(supply.totalStxYear2050).toFormat(
249+
STACKS_DECIMAL_PLACES,
250+
8
251+
),
227252
unlockedSupply: supply.unlockedStx,
228253
unlockedSupplyFormatted: new BigNumber(supply.unlockedStx).toFormat(
229254
STACKS_DECIMAL_PLACES,

src/api/routes/ws/channels/socket-io-channel.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ export class SocketIOChannel extends WebSocketChannel {
123123
if (!this.io && callback) {
124124
callback();
125125
}
126-
this.io?.close(callback);
126+
this.io?.close(callback).catch(err => {
127+
logger.error(err, `Error closing socket.io`);
128+
});
127129
this.io = undefined;
128130
}
129131

src/helpers.ts

+1-1
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)