@gorbchain-xyz/chaindecode
Version:
GorbchainSDK V1.3+ - Complete Solana development toolkit with advanced cryptography, messaging, and collaboration features. Build secure applications with blockchain, DeFi, and end-to-end encryption.
172 lines (171 loc) • 5.48 kB
TypeScript
/**
* Rich Token Operations - Enhanced token functions with metadata and context
*
* These functions provide comprehensive token information including metadata,
* market data, and decoded transaction context for frontend developers.
*/
import type { GorbchainSDK } from '../sdk/GorbchainSDK.js';
/**
* Rich token account information with complete metadata
*/
export interface RichTokenAccount {
/** Token account address */
address: string;
/** Owner wallet address */
owner: string;
/** Token mint address */
mint: string;
/** Raw token balance */
amount: string;
/** Formatted balance with decimals */
balance: string;
/** Token decimals */
decimals: number;
/** Whether account is frozen */
frozen: boolean;
/** Token metadata */
metadata: {
/** Token name */
name?: string;
/** Token symbol */
symbol?: string;
/** Token description */
description?: string;
/** Token image/logo URL */
image?: string;
/** External URL */
externalUrl?: string;
/** Token attributes */
attributes?: Array<{
trait_type: string;
value: string | number;
}>;
/** Whether this is an NFT */
isNFT: boolean;
/** NFT collection information */
collection?: {
name: string;
family: string;
verified: boolean;
};
};
/** Market information (if available) */
market?: {
/** Current USD price */
priceUsd?: number;
/** 24h price change percentage */
priceChange24h?: number;
/** Market cap */
marketCap?: number;
/** Total supply */
totalSupply?: string;
/** Circulating supply */
circulatingSupply?: string;
};
/** Program information */
program: {
/** Program ID that manages this token */
id: string;
/** Program type (SPL Token, Token-2022, etc.) */
type: 'spl-token' | 'token-2022' | 'nft' | 'custom';
/** Program version */
version?: string;
};
/** Account creation info */
created: {
/** Block slot when account was created */
slot?: number;
/** Approximate creation timestamp */
timestamp?: number;
/** Creation transaction signature */
signature?: string;
};
}
/**
* Rich token accounts response with portfolio summary
*/
export interface RichTokenAccountsResponse {
/** Array of rich token accounts */
accounts: RichTokenAccount[];
/** Portfolio summary */
summary: {
/** Total number of tokens */
totalTokens: number;
/** Total number of NFTs */
totalNFTs: number;
/** Total USD value (if available) */
totalValueUsd?: number;
/** Portfolio diversity score (0-1) */
diversityScore: number;
/** Top 5 holdings by value */
topHoldings: Array<{
symbol: string;
percentage: number;
valueUsd?: number;
}>;
};
/** Metadata about the operation */
meta: {
/** Whether metadata resolution was successful */
metadataResolved: boolean;
/** Whether market data was fetched */
marketDataFetched: boolean;
/** Number of failed metadata requests */
failedMetadataRequests: number;
/** Operation duration in milliseconds */
duration: number;
/** Timestamp of the operation */
timestamp: number;
};
}
/**
* Get rich token accounts with complete metadata and context
*
* This function enhances the basic getTokenAccountsByOwner with:
* - Complete token metadata (name, symbol, image, etc.)
* - Market data (price, market cap, etc.)
* - NFT collection information
* - Portfolio analysis and summary
* - Performance metrics
*
* @param sdk - GorbchainSDK instance
* @param ownerAddress - Wallet address to get token accounts for
* @param options - Configuration options
* @returns Promise resolving to rich token accounts with metadata
*
* @example
* ```typescript
* const sdk = new GorbchainSDK({ rpcEndpoint: 'https://rpc.gorbchain.xyz' });
*
* const richTokens = await getRichTokenAccountsByOwner(sdk, 'wallet_address', {
* includeMetadata: true,
* includeMarketData: true,
* includeNFTs: true
* });
*
* console.log(`Found ${richTokens.accounts.length} tokens`);
* console.log(`Portfolio value: $${richTokens.summary.totalValueUsd}`);
*
* // Access individual token data
* richTokens.accounts.forEach(token => {
* console.log(`${token.metadata.symbol}: ${token.balance} tokens`);
* if (token.metadata.isNFT) {
* console.log(`NFT: ${token.metadata.name} from ${token.metadata.collection?.name}`);
* }
* });
* ```
*/
export declare function getRichTokenAccountsByOwner(sdk: GorbchainSDK, ownerAddress: string, options?: {
/** Whether to fetch token metadata */
includeMetadata?: boolean;
/** Whether to fetch market data */
includeMarketData?: boolean;
/** Whether to include NFT accounts */
includeNFTs?: boolean;
/** Whether to include zero balance accounts */
includeZeroBalance?: boolean;
/** Maximum number of concurrent metadata requests */
maxConcurrentRequests?: number;
/** Custom token programs to include */
customPrograms?: string[];
}): Promise<RichTokenAccountsResponse>;