import { FinalizedContext, IAccountState, IAssetFactoryState, IAssetState, IDelegateState, IIndexTable, IRollupBlock, IRollupState, IStakeState, ITokenFactoryState, ITokenState, TIndexedAccountState, TIndexedAssetState, TIndexedDelegationState, TIndexedTokenState, TPageInfo, TTokenDistribution, TTokenMeta } from "@ocap/types"; //#region src/util.d.ts /** * Token state with metadata for formatting * Note: foreignToken type from ITokenState (IForeignToken) differs from TForeignToken, * we use a flexible type here to accommodate both */ interface TokenStateInfo { address: string; decimal?: number; unit?: string; symbol?: string; icon?: string; /** Foreign token info - may be IForeignToken from state or TForeignToken when indexed */ foreignToken?: { type?: string; contractAddress?: string; chainType?: string; chainName?: string; chainId?: number; } | null; } /** Token with address and optional balance */ interface TokenWithBalance { address: string; balance?: string; value?: string; [key: string]: unknown; } /** Minimal IndexDB interface for indexed transaction creation */ interface IndexDBForTx { delegation?: IIndexTable<{ to: string; address: string; }>; token?: IIndexTable; } /** Inner transaction JSON structure */ interface ItxJson { type_url?: string; value?: string | number; to?: string; token?: string; assets?: string[]; tokens?: Array<{ address: string; value?: string; }>; inputs?: Array<{ assets?: string[]; tokens?: Array<{ address: string; value?: string; }>; }>; outputs?: Array<{ assets?: string[]; tokens?: Array<{ address: string; value?: string; }>; }>; sender?: { value?: string; assets?: string[]; tokens?: Array<{ address: string; value?: string; }>; }; receiver?: { value?: string; assets?: string[]; tokens?: Array<{ address: string; value?: string; }>; }; address?: string; factory?: string; data?: { type_url: string; value: string; }; [key: string]: unknown; } /** Decoded transaction structure */ interface DecodedTx { from: string; itxJson: ItxJson; [key: string]: unknown; } /** Transaction data for indexing */ interface TxData { hash?: string; type?: string; code?: string; sender?: string; receiver?: string; time?: string; valid?: boolean; tx: DecodedTx; receipts?: Array<{ changes: Array<{ target: string; value: string; }>; }>; accounts?: string[]; assets?: string[]; tokens?: string[]; factories?: string[]; stakes?: string[]; rollups?: string[]; delegations?: string[]; tokenFactories?: string[]; tokenSymbols?: Array>; [key: string]: unknown; } /** Context for creating indexed delegation */ interface DelegationContext { senderState?: IAccountState; receiverState?: IAccountState; tx?: { from: string; }; itx?: { to: string; }; } /** Context for creating indexed factory */ interface FactoryContext { factoryTokens?: Array<{ address: string; value: string; }>; tokenStates?: TokenStateInfo[]; } /** Context for creating indexed token factory */ interface TokenFactoryContext { itx?: { token?: TokenStateInfo; }; config?: { token?: TokenStateInfo; }; } /** Context for creating indexed rollup */ interface RollupContext { tokenStates?: TokenStateInfo[]; } /** Context for creating indexed rollup block */ interface RollupBlockContext { rollupState?: { tokenAddress: string; }; tokenStates?: TokenStateInfo[]; } /** * Format token with metadata from token states * @param token - Token with address * @param tokenStates - Array of token states for metadata lookup * @param rest - Additional args for debug logging */ declare const formatTokenMeta: (token: TokenWithBalance, tokenStates?: TokenStateInfo[] | null, ...rest: unknown[]) => TokenWithBalance; /** * Create indexed account from account state */ declare const createIndexedAccount: (x: IAccountState & { balance?: string; migratedTo?: string[]; migratedFrom?: string[]; numAssets?: number; numTxs?: number; }, getTokenFn: (address: string) => Promise) => Promise & { balance: string; nonce: number | string; numAssets: number | string; numTxs: number | string; }>; /** * Create indexed asset from asset state * Note: display/endpoint/data types from IAssetState may differ from TIndexedAssetState, * they are passed through without transformation */ declare const createIndexedAsset: (x: IAssetState) => Omit & { data?: IAssetState["data"]; display?: IAssetState["display"]; endpoint?: IAssetState["endpoint"]; }; /** * Create indexed delegation from delegation state */ declare const createIndexedDelegation: (x: IDelegateState, ctx: DelegationContext) => Partial & { ops: unknown[]; }; /** * Create indexed token from token state * Note: foreignToken/metadata/data types from ITokenState may differ from TIndexedTokenState, * they are passed through without transformation */ declare const createIndexedToken: (x: ITokenState) => Omit & { foreignToken?: ITokenState["foreignToken"]; metadata?: ITokenState["metadata"]; data?: ITokenState["data"]; }; /** * Create indexed token factory from token factory state * Note: token/reserveToken may not have all TIndexedTokenInput fields filled, * they are populated with available metadata from context */ declare const createIndexedTokenFactory: (tokenFactory: ITokenFactoryState & { tokenAddress: string; reserveAddress: string; }, context: TokenFactoryContext) => Record & { token: TokenWithBalance; reserveToken: TokenWithBalance; }; /** * Create indexed factory from asset factory state * Note: tokens array may not have all TTokenMeta fields filled, * they are populated with available metadata from context */ declare const createIndexedFactory: (factory: IAssetFactoryState & { input?: { tokens?: TokenWithBalance[]; }; }, context: FactoryContext) => Record & { tokens: TokenWithBalance[]; }; /** * Create indexed transaction from transaction context * These fields are used internally to filter transactions by some entity */ declare const createIndexedTransaction: (tx: TxData, ctx: FinalizedContext, indexdb: IndexDBForTx) => Promise; /** * Create indexed stake from stake state * Note: tokens/revokedTokens arrays may not have all TTokenMeta fields filled, * they are populated with available metadata from context */ declare const createIndexedStake: (x: IStakeState, ctx: { tokenStates?: TokenStateInfo[]; }, indexdb: { token?: IIndexTable; }) => Promise & { tokens: TokenWithBalance[]; revokedTokens: TokenWithBalance[]; }>; /** * Create indexed rollup from rollup state * Note: foreignToken from TokenStateInfo is passed through without transformation */ declare const createIndexedRollup: (x: IRollupState & { tokenAddress: string; }, ctx: RollupContext) => Record & { tokenInfo?: TokenWithBalance; foreignToken?: TokenStateInfo["foreignToken"]; }; /** * Create indexed rollup block from rollup block state * Note: tokenInfo may not have all TIndexedTokenInput fields filled, * they are populated with available metadata from context */ declare const createIndexedRollupBlock: (x: IRollupBlock & { signaturesList?: Array<{ signer: string; }>; }, ctx: RollupBlockContext) => Record & { tokenInfo?: TokenWithBalance; validators: string[]; }; /** * Create indexed token distribution */ declare const createIndexedTokenDistribution: (x: { tokenAddress: string; txTime: string; account: { toString: () => string; }; gas: { toString: () => string; }; fee: { toString: () => string; }; slashedVault: { toString: () => string; }; stake: { toString: () => string; }; revokedStake: { toString: () => string; }; gasStake: { toString: () => string; }; }) => Partial; /** * Format transaction before inserting to index */ declare const formatTxBeforeInsert: (row: TxData) => TxData; /** * Format transaction after reading from index (remove internal indexing fields) */ declare const formatTxAfterRead: (tx: TxData) => TxData; /** * Format delegation after reading from index */ declare const formatDelegationAfterRead: (delegation: { ops: unknown[] | Record; }) => { ops: Array<{ key: string; value: unknown; }>; }; /** * Parse date time string to ISO format */ declare const parseDateTime: (str: unknown) => string; /** Paging input parameters */ interface PagingInput { size?: number | null; cursor?: string | number; order?: { field?: string; type?: string; } | Array<{ field?: string; type?: string; }>; } /** Parameters for formatPagination */ interface FormatPaginationParams { paging?: PagingInput | null; defaultSortField: string; supportedSortFields?: string[]; } /** Formatted pagination result */ interface FormattedPagination { size: number; cursor: number; order: { field: string; type: string; }; } /** * Format pagination parameters with defaults */ declare const formatPagination: ({ paging, defaultSortField, supportedSortFields }: FormatPaginationParams) => FormattedPagination; /** * Format next pagination info for response */ declare const formatNextPagination: (total: number, pagination: { cursor: number; size: number; }) => TPageInfo; /** * Check if a transaction changes the default token balance */ declare const isDefaultTokenChanged: (tx: TxData, token: { address: string; }) => boolean; //#endregion export { DelegationContext, FactoryContext, FormatPaginationParams, FormattedPagination, IndexDBForTx, PagingInput, RollupBlockContext, RollupContext, TokenFactoryContext, TokenStateInfo, TokenWithBalance, TxData, createIndexedAccount, createIndexedAsset, createIndexedDelegation, createIndexedFactory, createIndexedRollup, createIndexedRollupBlock, createIndexedStake, createIndexedToken, createIndexedTokenDistribution, createIndexedTokenFactory, createIndexedTransaction, formatDelegationAfterRead, formatNextPagination, formatPagination, formatTokenMeta, formatTxAfterRead, formatTxBeforeInsert, isDefaultTokenChanged, parseDateTime };