@@ -3,7 +3,7 @@ import * as z from "zod";
33/**
44 * Schema for token metadata attributes
55 */
6- const tokenAttributeSchema = z . object ( {
6+ const tokenAttributeSchema : z . ZodType < TokenMetadataAttribute > = z . object ( {
77 trait_type : z . string ( ) ,
88 value : z . union ( [ z . string ( ) , z . number ( ) ] ) ,
99 display_type : z . string ( ) . optional ( ) ,
@@ -12,33 +12,124 @@ const tokenAttributeSchema = z.object({
1212/**
1313 * Schema for token metadata files
1414 */
15- const tokenFileSchema = z . object ( {
15+ const tokenFileSchema : z . ZodType < TokenMetadataFile > = z . object ( {
1616 uri : z . string ( ) ,
1717 type : z . string ( ) ,
1818 cdn : z . boolean ( ) . optional ( ) ,
1919} ) ;
2020
21+ /**
22+ * Schema for token metadata creators
23+ */
24+ const tokenCreatorSchema : z . ZodType < TokenMetadataCreator > = z . object ( {
25+ address : z . string ( ) ,
26+ share : z . number ( ) . min ( 0 ) . max ( 100 ) ,
27+ } ) ;
28+
2129/**
2230 * Schema for token metadata properties
2331 */
24- const tokenPropertiesSchema = z . object ( {
32+ const tokenPropertiesSchema : z . ZodType < TokenMetadataProperties > = z . object ( {
2533 files : z . array ( tokenFileSchema ) . optional ( ) ,
2634 category : z . string ( ) . optional ( ) ,
27- creators : z
28- . array (
29- z . object ( {
30- address : z . string ( ) ,
31- share : z . number ( ) . min ( 0 ) . max ( 100 ) ,
32- } ) ,
33- )
34- . optional ( ) ,
35+ creators : z . array ( tokenCreatorSchema ) . optional ( ) ,
36+ } ) ;
37+
38+ /**
39+ * Schema for token metadata collection
40+ */
41+ const tokenCollectionSchema : z . ZodType < TokenMetadataCollection > = z . object ( {
42+ name : z . string ( ) ,
43+ family : z . string ( ) . optional ( ) ,
3544} ) ;
3645
46+ /**
47+ * Interface for token metadata attributes/traits
48+ */
49+ export interface TokenMetadataAttribute {
50+ /** The trait type/category */
51+ trait_type : string ;
52+ /** The trait value (string or number) */
53+ value : string | number ;
54+ /** Optional display type for UI formatting */
55+ display_type ?: string ;
56+ }
57+
58+ /**
59+ * Interface for token metadata file references
60+ */
61+ export interface TokenMetadataFile {
62+ /** File URI */
63+ uri : string ;
64+ /** File MIME type */
65+ type : string ;
66+ /** Whether the file is CDN cached */
67+ cdn ?: boolean ;
68+ }
69+
70+ /**
71+ * Interface for token creator information with royalty shares
72+ */
73+ export interface TokenMetadataCreator {
74+ /** Creator's wallet address */
75+ address : string ;
76+ /** Creator's royalty share percentage (0-100) */
77+ share : number ;
78+ }
79+
80+ /**
81+ * Interface for token metadata properties
82+ */
83+ export interface TokenMetadataProperties {
84+ /** Optional array of file references */
85+ files ?: TokenMetadataFile [ ] ;
86+ /** Optional category classification */
87+ category ?: string ;
88+ /** Optional array of creators with royalty shares */
89+ creators ?: TokenMetadataCreator [ ] ;
90+ }
91+
92+ /**
93+ * Interface for token collection information
94+ */
95+ export interface TokenMetadataCollection {
96+ /** Collection name */
97+ name : string ;
98+ /** Optional collection family */
99+ family ?: string ;
100+ }
101+
102+ /**
103+ * Interface for Solana token metadata following the Metaplex Token Metadata Standard
104+ */
105+ export interface TokenMetadata {
106+ /** The name of the token */
107+ name : string ;
108+ /** The symbol of the token */
109+ symbol : string ;
110+ /** Optional description of the token */
111+ description ?: string ;
112+ /** Optional image URI */
113+ image ?: string ;
114+ /** Optional animation URL for multimedia content */
115+ animation_url ?: string ;
116+ /** Optional external URL for additional information */
117+ external_url ?: string ;
118+ /** Optional array of attributes/traits */
119+ attributes ?: TokenMetadataAttribute [ ] ;
120+ /** Optional properties object */
121+ properties ?: TokenMetadataProperties ;
122+ /** Optional seller fee basis points (royalty percentage * 100) */
123+ seller_fee_basis_points ?: number ;
124+ /** Optional collection information */
125+ collection ?: TokenMetadataCollection ;
126+ }
127+
37128/**
38129 * Schema for Solana token metadata JSON
39130 * Based on Metaplex Token Metadata Standard
40131 */
41- export const tokenMetadataSchema = z . object ( {
132+ export const tokenMetadataSchema : z . ZodType < TokenMetadata > = z . object ( {
42133 name : z . string ( ) ,
43134 symbol : z . string ( ) ,
44135 description : z . string ( ) . optional ( ) ,
@@ -49,12 +140,5 @@ export const tokenMetadataSchema = z.object({
49140 properties : tokenPropertiesSchema . optional ( ) ,
50141 // Additional fields that may be present
51142 seller_fee_basis_points : z . number ( ) . optional ( ) ,
52- collection : z
53- . object ( {
54- name : z . string ( ) ,
55- family : z . string ( ) . optional ( ) ,
56- } )
57- . optional ( ) ,
143+ collection : tokenCollectionSchema . optional ( ) ,
58144} ) ;
59-
60- export type TokenMetadata = z . infer < typeof tokenMetadataSchema > ;
0 commit comments