diff --git a/src/RpcClient.ts b/src/RpcClient.ts index bdfe2a1..8d8d2a0 100644 --- a/src/RpcClient.ts +++ b/src/RpcClient.ts @@ -28,7 +28,7 @@ export class RpcClient { constructor( protected readonly connection: Connection, protected readonly id?: string - ) {} + ) { } /** * Request an allocation of lamports to the specified address @@ -174,6 +174,40 @@ export class RpcClient { throw new Error(`Error in getAsset: ${error}`); } } + + /** + * Get RWA Asset by mint. + * @param {DAS.GetRwaAssetRequest} - RWA Asset ID + * @returns {Promise} + * @throws {Error} + */ + async getRwaAsset( + params: DAS.GetRwaAssetRequest + ): Promise { + try { + const url = `${this.connection.rpcEndpoint}`; + const response = await axios.post( + url, + { + jsonrpc: "2.0", + id: this.id, + method: "getRwaAccountsByMint", + params, + }, + { + headers: { + "Content-Type": "application/json", + }, + } + ); + + const result = response.data.result; + return result as DAS.GetRwaAssetResponse; + } catch (error) { + throw new Error(`Error in getRwaAsset: ${error}`); + } + } + /** * Get multiple assets. * @returns {Promise} diff --git a/src/types/das-types.ts b/src/types/das-types.ts index c058cf9..230d588 100644 --- a/src/types/das-types.ts +++ b/src/types/das-types.ts @@ -9,279 +9,287 @@ import { RoyaltyModel, UseMethods, } from "./enums"; +import { FullAccount } from "./types"; -export namespace DAS { -// getAssetsByOwner // -export interface AssetsByOwnerRequest { - ownerAddress: string; - page: number; - limit?: number; - before?: string; - after?: string; - displayOptions?: DisplayOptions; - sortBy?: AssetSortingRequest; -} +export namespace DAS { + // getAssetsByOwner // + export interface AssetsByOwnerRequest { + ownerAddress: string; + page: number; + limit?: number; + before?: string; + after?: string; + displayOptions?: DisplayOptions; + sortBy?: AssetSortingRequest; + } -// getAssetsByCreator // -export type AssetsByCreatorRequest = { - creatorAddress: string; - page: number; - onlyVerified?: boolean; - limit?: number; - before?: string; - after?: string; - displayOptions?: DisplayOptions; - sortBy?: AssetSortingRequest; -}; + // getAssetsByCreator // + export type AssetsByCreatorRequest = { + creatorAddress: string; + page: number; + onlyVerified?: boolean; + limit?: number; + before?: string; + after?: string; + displayOptions?: DisplayOptions; + sortBy?: AssetSortingRequest; + }; -export type GetAssetBatchRequest = { - ids: Array; - displayOptions?: GetAssetDisplayOptions; -} + export type GetAssetBatchRequest = { + ids: Array; + displayOptions?: GetAssetDisplayOptions; + } -// getAssetsByGroup // -export type AssetsByGroupRequest = { - groupValue: string; - groupKey: string; - page: number; - limit?: number; - before?: string; - after?: string; - displayOptions?: DisplayOptions; - sortBy?: AssetSortingRequest; -}; -export type GetAssetsBatchRequest = { - ids: string[]; -}; + // getAssetsByGroup // + export type AssetsByGroupRequest = { + groupValue: string; + groupKey: string; + page: number; + limit?: number; + before?: string; + after?: string; + displayOptions?: DisplayOptions; + sortBy?: AssetSortingRequest; + }; + export type GetAssetsBatchRequest = { + ids: string[]; + }; -// searchAssets -export interface SearchAssetsRequest { - page: number; // starts at 1 - limit?: number; - before?: string; - after?: string; - creatorAddress?: string; - ownerAddress?: string; - jsonUri?: string; - grouping?: string[]; - burnt?: boolean; - sortBy?: AssetSortingRequest; - frozen?: boolean; - supplyMint?: string; - supply?: number; - interface?: string; - delegate?: number; - ownerType?: OwnershipModel; - royaltyAmount?: number; - royaltyTarget?: string; - royaltyTargetType?: RoyaltyModel; - compressible?: boolean; - compressed?: boolean; -} + // searchAssets + export interface SearchAssetsRequest { + page: number; // starts at 1 + limit?: number; + before?: string; + after?: string; + creatorAddress?: string; + ownerAddress?: string; + jsonUri?: string; + grouping?: string[]; + burnt?: boolean; + sortBy?: AssetSortingRequest; + frozen?: boolean; + supplyMint?: string; + supply?: number; + interface?: string; + delegate?: number; + ownerType?: OwnershipModel; + royaltyAmount?: number; + royaltyTarget?: string; + royaltyTargetType?: RoyaltyModel; + compressible?: boolean; + compressed?: boolean; + } -// getAssetsByAuthority -export type AssetsByAuthorityRequest = { - authorityAddress: string; - page: number; - limit?: number; - before?: string; - after?: string; - displayOptions?: DisplayOptions; - sortBy?: AssetSortingRequest; -}; -// getAsset -export type GetAssetRequest = { - id: string; - displayOptions?: GetAssetDisplayOptions; + // getAssetsByAuthority + export type AssetsByAuthorityRequest = { + authorityAddress: string; + page: number; + limit?: number; + before?: string; + after?: string; + displayOptions?: DisplayOptions; + sortBy?: AssetSortingRequest; + }; + // getAsset + export type GetAssetRequest = { + id: string; + displayOptions?: GetAssetDisplayOptions; -}; -// getAssetProof -export type GetAssetProofRequest = { - id: string; -}; -// getSignaturesForAsset -export type GetSignaturesForAssetRequest = { - id: string; - page: number; - limit?: number; - before?: string; - after?: string; -}; + }; + // getRwaAsset + export type GetRwaAssetRequest = { + id: string; + }; + // getAssetProof + export type GetAssetProofRequest = { + id: string; + }; + // getSignaturesForAsset + export type GetSignaturesForAssetRequest = { + id: string; + page: number; + limit?: number; + before?: string; + after?: string; + }; -// Sorting on response -export interface AssetSorting { - sort_by: AssetSortBy; - sort_direction: AssetSortDirection; -} -// Sorting on request (camelCase) -export type AssetSortingRequest = { - sortBy: AssetSortBy; - sortDirection: AssetSortDirection; -}; -// Asset Response -export type GetAssetResponse = { - interface: Interface; // enum - id: string; - content?: Content; - authorities?: Authorities[]; - compression?: Compression; - grouping?: Grouping[]; - royalty?: Royalty; - ownership: Ownership; - creators?: Creators[]; - uses?: Uses; - supply?: Supply; - mutable: boolean; - burnt: boolean; -}; + // Sorting on response + export interface AssetSorting { + sort_by: AssetSortBy; + sort_direction: AssetSortDirection; + } + // Sorting on request (camelCase) + export type AssetSortingRequest = { + sortBy: AssetSortBy; + sortDirection: AssetSortDirection; + }; + // Asset Response + export type GetAssetResponse = { + interface: Interface; // enum + id: string; + content?: Content; + authorities?: Authorities[]; + compression?: Compression; + grouping?: Grouping[]; + royalty?: Royalty; + ownership: Ownership; + creators?: Creators[]; + uses?: Uses; + supply?: Supply; + mutable: boolean; + burnt: boolean; + }; + // RWA Asset Response + export type GetRwaAssetResponse = { + items: FullAccount + }; + export type GetAssetResponseList = { + grand_total?: boolean; + total: number; + limit: number; + page: number; + items: GetAssetResponse[]; + }; + export interface GetAssetProofResponse { + root: string; + proof: Array; + node_index: number; + leaf: string; + tree_id: string; + } + export interface GetSignaturesForAssetResponse { + total: number; + limit: number; + page?: number; + before?: string; + after?: string; + items: Array>; + } + // DisplayOptions -export type GetAssetResponseList = { - grand_total?: boolean; - total: number; - limit: number; - page: number; - items: GetAssetResponse[]; -}; -export interface GetAssetProofResponse { - root: string; - proof: Array; - node_index: number; - leaf: string; - tree_id: string; -} -export interface GetSignaturesForAssetResponse { - total: number; - limit: number; - page?: number; - before?: string; - after?: string; - items: Array>; -} -// DisplayOptions + export type DisplayOptions = { + showUnverifiedCollections?: boolean, + showCollectionMetadata?: boolean, + showGrandTotal?: boolean + } -export type DisplayOptions = { - showUnverifiedCollections?: boolean, - showCollectionMetadata?: boolean, - showGrandTotal?: boolean -} + // Display options for getAssetBatch do not include grand_total. + export type GetAssetDisplayOptions = { + showUnverifiedCollections?: boolean, + showCollectionMetadata?: boolean, + } -// Display options for getAssetBatch do not include grand_total. -export type GetAssetDisplayOptions = { - showUnverifiedCollections?: boolean, - showCollectionMetadata?: boolean, -} + // Ownership -- + export interface Ownership { + frozen: boolean; + delegated: boolean; + delegate?: string; + ownership_model: OwnershipModel; // enum + owner: string; + } + // Supply -- + export interface Supply { + print_max_supply: number; + print_current_supply: number; + edition_nonce?: number; + } + // Uses -- + export interface Uses { + use_method: UseMethods; // enum + remaining: number; + total: number; + } + // Creators -- + export interface Creators { + address: string; + share: number; + verified: boolean; + } + // Royalty -- + export interface Royalty { + royalty_model: RoyaltyModel; + target?: string; + percent: number; + basis_points: number; + primary_sale_happened: boolean; + locked: boolean; + } + // Grouping -- + export interface Grouping { + group_key: string; + group_value: string; + verified?: boolean; + collection_metadata?: CollectionMetadata; -// Ownership -- -export interface Ownership { - frozen: boolean; - delegated: boolean; - delegate?: string; - ownership_model: OwnershipModel; // enum - owner: string; -} -// Supply -- -export interface Supply { - print_max_supply: number; - print_current_supply: number; - edition_nonce?: number; -} -// Uses -- -export interface Uses { - use_method: UseMethods; // enum - remaining: number; - total: number; -} -// Creators -- -export interface Creators { - address: string; - share: number; - verified: boolean; -} -// Royalty -- -export interface Royalty { - royalty_model: RoyaltyModel; - target?: string; - percent: number; - basis_points: number; - primary_sale_happened: boolean; - locked: boolean; -} -// Grouping -- -export interface Grouping { - group_key: string; - group_value: string; - verified?: boolean; - collection_metadata?: CollectionMetadata; - -} -export interface CollectionMetadata { - name?: string; - symbol?: string; - image?: string; - description?: string; - external_url?: string; + } + export interface CollectionMetadata { + name?: string; + symbol?: string; + image?: string; + description?: string; + external_url?: string; -} -// Authorities -- -export interface Authorities { - address: string; - scopes: Array; -} + } + // Authorities -- + export interface Authorities { + address: string; + scopes: Array; + } -//Links -export type Links = { - external_url?: string; - image?: string; - animation_url?: string; - [Symbol.iterator](): Iterator; -}; + //Links + export type Links = { + external_url?: string; + image?: string; + animation_url?: string; + [Symbol.iterator](): Iterator; + }; -// Content -- -export interface Content { - $schema: string; - json_uri: string; - files?: Files; - metadata: Metadata; - links?: Links; -} + // Content -- + export interface Content { + $schema: string; + json_uri: string; + files?: Files; + metadata: Metadata; + links?: Links; + } -// FILE -- -export interface File { - uri?: string; - mime?: string; - cdn_uri?: string; - quality?: FileQuality; - contexts?: Context[]; - [Symbol.iterator](): Iterator; -} -// FILES -- -export type Files = File[]; -// Quality/ File -- -export interface FileQuality { - schema: string; -} -// Metadata/ Content -- -export interface Metadata { - attributes?: Attribute[]; - description: string; - name: string; - symbol: string; -} -// Attributes -export interface Attribute { - value: string; - trait_type: string; -} -// Compression -export interface Compression { - eligible: boolean; - compressed: boolean; - data_hash: string; - creator_hash: string; - asset_hash: string; - tree: string; - seq: number; - leaf_id: number; -} -// End of DAS + // FILE -- + export interface File { + uri?: string; + mime?: string; + cdn_uri?: string; + quality?: FileQuality; + contexts?: Context[]; + [Symbol.iterator](): Iterator; + } + // FILES -- + export type Files = File[]; + // Quality/ File -- + export interface FileQuality { + schema: string; + } + // Metadata/ Content -- + export interface Metadata { + attributes?: Attribute[]; + description: string; + name: string; + symbol: string; + } + // Attributes + export interface Attribute { + value: string; + trait_type: string; + } + // Compression + export interface Compression { + eligible: boolean; + compressed: boolean; + data_hash: string; + creator_hash: string; + asset_hash: string; + tree: string; + seq: number; + leaf_id: number; + } + // End of DAS } diff --git a/src/types/types.ts b/src/types/types.ts index c3a760d..0ffa5a9 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -274,3 +274,46 @@ export interface RevokeCollectionAuthorityRequest { revokeAuthorityKeypair: Keypair; payerKeypair?: Keypair; } + +// RWA Asset Types +interface AssetControllerAccount { + address: string; + mint: string; + authority: string; + delegate: string; + version: number; + closed: boolean; +} + +interface DataRegistryAccount { + address: string; + mint: string; + version: number; + closed: boolean; +} + +interface IdentityRegistryAccount { + address: string; + mint: string; + authority: string; + delegate: string; + version: number; + closed: boolean; +} + +interface PolicyEngine { + address: string; + mint: string; + authority: string; + delegate: string; + policies: string[]; + version: number; + closed: boolean; +} + +export interface FullRwaAccount { + asset_controller?: AssetControllerAccount; + data_registry?: DataRegistryAccount; + identity_registry?: IdentityRegistryAccount; + policy_engine?: PolicyEngine; +} \ No newline at end of file