diff --git a/src/types/ant.ts b/src/types/ant.ts index ae2f799a..b47c4b3a 100644 --- a/src/types/ant.ts +++ b/src/types/ant.ts @@ -38,6 +38,18 @@ export const ArweaveTxIdSchema = z .refine((val) => ARWEAVE_TX_REGEX.test(val), { message: 'Must be an Arweave Transaction ID', }); + +export const IntegerStringSchema = z + .string({ + description: 'Integer String', + }) + .refine( + (val) => { + const num = parseInt(val); + return Number.isInteger(num) && num >= 0; + }, + { message: 'Must be a non negative integer string' }, + ); export const AntRecordSchema = z.object({ transactionId: ArweaveTxIdSchema.describe('The Target ID of the undername'), ttlSeconds: z.number(), @@ -56,7 +68,12 @@ export const AntBalancesSchema = z.record( export const AntStateSchema = z.object({ Name: z.string().describe('The name of the ANT.'), Ticker: z.string().describe('The ticker symbol for the ANT.'), - Denomination: z.number(), + Denomination: z + .number() + .describe( + 'The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.', + ) + .min(0, { message: 'Denomination must be a non-negative number' }), Owner: ArweaveTxIdSchema.describe('The Owners address.'), Controllers: AntControllersSchema.describe( 'Controllers of the ANT who have administrative privileges.', @@ -87,12 +104,13 @@ export const AntInfoSchema = z.object({ 'Transaction ID of the Source Code for the ANT.', ), Ticker: z.string().describe('The ticker symbol for the ANT.'), - ['Total-Supply']: z - .number() - .describe('Total supply of the ANT in circulation.') - .min(0, { message: 'Total supply must be a non-negative number' }), + ['Total-Supply']: IntegerStringSchema.describe( + 'Total supply of the ANT in circulation.', + ), Logo: ArweaveTxIdSchema.describe('Transaction ID of the ANT logo.'), - Denomination: z.number(), + Denomination: IntegerStringSchema.describe( + 'The number of decimal places to use for the ANT. Defaults to 0 if not set representing whole numbers.', + ), }); export type AoANTInfo = z.infer; diff --git a/tests/unit/ant.test.ts b/tests/unit/ant.test.ts index 1cb40741..a79c2989 100644 --- a/tests/unit/ant.test.ts +++ b/tests/unit/ant.test.ts @@ -63,9 +63,9 @@ describe('ANT Schemas', () => { Owner: stub_address, ['Source-Code-TX-ID']: stub_address, Ticker: 'TST', - ['Total-Supply']: 1, + ['Total-Supply']: '1', Logo: stub_address, - Denomination: 0, + Denomination: '0', }; const invalidInfo = { Name: 'TestToken',