Skip to content

Commit 080176e

Browse files
authored
fix: roll back FT supply display, update docs instead (#288)
* Revert "fix: display token supply with correct decimals (#287)" This reverts commit 94c7b4a. * docs: update
1 parent 94c7b4a commit 080176e

File tree

6 files changed

+41
-22
lines changed

6 files changed

+41
-22
lines changed

src/api/init.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import FastifyCors from '@fastify/cors';
88
import { StatusRoutes } from './routes/status';
99
import FastifyMetrics, { IFastifyMetrics } from 'fastify-metrics';
1010
import { Server } from 'http';
11-
import { isProdEnv, PINO_LOGGER_CONFIG } from '@hirosystems/api-toolkit';
11+
import { isProdEnv } from './util/helpers';
12+
import { PINO_LOGGER_CONFIG } from '@hirosystems/api-toolkit';
1213

1314
export const Api: FastifyPluginAsync<Record<never, never>, Server, TypeBoxTypeProvider> = async (
1415
fastify,

src/api/routes/ft.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
import { handleChainTipCache, handleTokenCache } from '../util/cache';
2020
import { generateTokenErrorResponse, TokenErrorResponseSchema } from '../util/errors';
2121
import { parseMetadataLocaleBundle } from '../util/helpers';
22-
import BigNumber from 'bignumber.js';
2322

2423
const IndexRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTypeProvider> = (
2524
fastify,
@@ -122,16 +121,11 @@ const ShowRoutes: FastifyPluginCallback<Record<never, never>, Server, TypeBoxTyp
122121
locale: request.query.locale,
123122
});
124123
const contract = metadataBundle?.smartContract;
125-
const decimals = metadataBundle?.token?.decimals ?? undefined;
126-
const total_supply = metadataBundle?.token?.total_supply ?? undefined;
127124
await reply.send({
128125
name: metadataBundle?.token?.name ?? undefined,
129126
symbol: metadataBundle?.token?.symbol ?? undefined,
130-
decimals,
131-
total_supply:
132-
decimals != undefined && total_supply != undefined
133-
? BigNumber(total_supply).shiftedBy(-decimals).toString()
134-
: undefined,
127+
decimals: metadataBundle?.token?.decimals ?? undefined,
128+
total_supply: metadataBundle?.token?.total_supply ?? undefined,
135129
token_uri: metadataBundle?.token?.uri ?? undefined,
136130
description: metadataBundle?.metadataLocale?.metadata?.description ?? undefined,
137131
tx_id: contract.tx_id,

src/api/schemas.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,19 @@ const TokenDescription = Type.String({
156156
examples: [
157157
'Heavy hitters, all-stars and legends of the game join forces to create a collection of unique varsity jackets',
158158
],
159+
description: 'Description',
159160
});
160161

161162
const TokenImage = Type.String({
162163
format: 'uri',
163164
examples: ['ipfs://ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
165+
description: 'Original image URL',
164166
});
165167

166168
const TokenCachedImage = Type.String({
167169
format: 'uri',
168170
examples: ['https://ipfs.io/ipfs/QmZMqhh2ztwuZ3Y8PyEp2z5auyH3TCm3nnr5ZfjjgDjd5q/12199.png'],
171+
description: 'Cached image URL',
169172
});
170173

171174
export const Metadata = Type.Object(
@@ -187,6 +190,7 @@ export type MetadataType = Static<typeof Metadata>;
187190
export const TokenUri = Type.String({
188191
format: 'uri',
189192
examples: ['ipfs://ipfs/Qmf9yDYuPTrp8NRUFf8xxDd5Ud24Dx9uYMwMn8o8G2cWPW/12200.json'],
193+
description: "URI for this token's metadata JSON",
190194
});
191195

192196
export const TokenNotFoundResponse = Type.Object(
@@ -245,21 +249,37 @@ export const PaginatedResponse = <T extends TSchema>(type: T, title: string) =>
245249

246250
export const FtMetadataResponse = Type.Object(
247251
{
248-
name: Type.Optional(Type.String({ examples: ['Wrapped USD'] })),
249-
symbol: Type.Optional(Type.String({ examples: ['xUSD'] })),
250-
decimals: Type.Optional(Type.Integer({ examples: [8] })),
251-
total_supply: Type.Optional(Type.String({ examples: ['9999980000000'] })),
252+
name: Type.Optional(Type.String({ examples: ['Wrapped USD'], description: 'Token name' })),
253+
symbol: Type.Optional(Type.String({ examples: ['xUSD'], description: 'Token symbol' })),
254+
decimals: Type.Optional(
255+
Type.Integer({
256+
examples: [8],
257+
description: "Number of decimal places clients should use to format this token's amounts",
258+
})
259+
),
260+
total_supply: Type.Optional(
261+
Type.String({
262+
examples: ['9999980000000'],
263+
description:
264+
'Current circulating supply as reported by its contract. Clients should format this amount with the correct number of `decimals` before displaying to users',
265+
})
266+
),
252267
token_uri: Type.Optional(TokenUri),
253268
description: Type.Optional(TokenDescription),
254269
image_uri: Type.Optional(TokenCachedImage),
255270
image_thumbnail_uri: Type.Optional(TokenCachedImage),
256271
image_canonical_uri: Type.Optional(TokenImage),
257272
tx_id: Type.String({
258273
examples: ['0x5642ca7d68976b6b2a2055689d9a57de26d67f0dd8b016d1b0d94cb634454cdd'],
274+
description: 'ID for the transaction that deployed this token',
275+
}),
276+
sender_address: Type.String({
277+
examples: ['SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6'],
278+
description: 'Deployer address',
259279
}),
260-
sender_address: Type.String({ examples: ['SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6'] }),
261280
asset_identifier: Type.String({
262281
examples: ['SPZA22A4D15RKH5G8XDGQ7BPC20Q5JNMH0VQKSR6.token-ststx-earn-v1::stSTXearn'],
282+
description: 'Clarity asset identifier',
263283
}),
264284
metadata: Type.Optional(Metadata),
265285
},

src/api/util/helpers.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { DbMetadataLocaleBundle } from '../../pg/types';
22
import { MetadataPropertiesType, MetadataType, MetadataValueType } from '../schemas';
33

4+
export const isDevEnv = process.env.NODE_ENV === 'development';
5+
export const isTestEnv = process.env.NODE_ENV === 'test';
6+
export const isProdEnv =
7+
process.env.NODE_ENV === 'production' ||
8+
process.env.NODE_ENV === 'prod' ||
9+
!process.env.NODE_ENV ||
10+
(!isTestEnv && !isDevEnv);
11+
412
export function parseMetadataLocaleBundle(
513
locale?: DbMetadataLocaleBundle
614
): MetadataType | undefined {

src/index.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@ import { buildApiServer, buildPromServer } from './api/init';
44
import { TokenProcessorMetrics } from './token-processor/token-processor-metrics';
55
import { ENV } from './env';
66
import { buildAdminRpcServer } from './admin-rpc/init';
7-
import {
8-
buildProfilerServer,
9-
isProdEnv,
10-
logger,
11-
registerShutdownConfig,
12-
} from '@hirosystems/api-toolkit';
7+
import { isProdEnv } from './api/util/helpers';
8+
import { buildProfilerServer, logger, registerShutdownConfig } from '@hirosystems/api-toolkit';
139
import { closeChainhookServer, startChainhookServer } from './chainhook/server';
1410

1511
/**

tests/api/ft.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ describe('FT routes', () => {
167167
name: 'hello-world',
168168
symbol: 'HELLO',
169169
token_uri: 'http://test.com/uri.json',
170-
total_supply: '0.000001',
170+
total_supply: '1',
171171
sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS',
172172
asset_identifier: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS.hello-world::ft-token',
173173
tx_id: '0x123456',
@@ -240,7 +240,7 @@ describe('FT routes', () => {
240240
name: 'hello-world',
241241
symbol: 'HELLO',
242242
token_uri: 'http://test.com/uri.json',
243-
total_supply: '0.000001',
243+
total_supply: '1',
244244
decimals: 6,
245245
sender_address: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS',
246246
asset_identifier: 'SP2SYHR84SDJJDK8M09HFS4KBFXPPCX9H7RZ9YVTS.hello-world::ft-token',

0 commit comments

Comments
 (0)