UNPKG

@cheqd/sdk

Version:

A TypeScript SDK built with CosmJS to interact with the cheqd network ledger

242 lines 11.5 kB
import { GasPriceResponse, GasPricesResponse, ParamsResponse } from '@cheqd/ts-proto/feemarket/feemarket/v1/index.js'; import { EncodeObject, GeneratedType } from '@cosmjs/proto-signing'; import { GasPrice, QueryClient } from '@cosmjs/stargate'; import { AbstractCheqdSDKModule, MinimalImportableCheqdSDKModule } from './_.js'; import { DidStdFee, IContext, QueryExtensionSetup } from '../types.js'; import { CheqdQuerier } from '../querier.js'; import { CheqdSigningStargateClient } from '../signer.js'; /** Default extension key for fee market-related query operations */ export declare const defaultFeemarketExtensionKey: "feemarket"; /** * Protobuf message type literals for fee market operations. * Used for consistent message type identification across the module. */ export declare const protobufLiterals: { /** Gas price response message type */ readonly GasPriceResponse: "GasPriceResponse"; /** Gas prices response message type */ readonly GasPricesResponse: "GasPricesResponse"; /** Parameters response message type */ readonly ParamsResponse: "ParamsResponse"; }; /** Type URL for GasPriceResponse messages */ export declare const typeUrlGasPriceResponse: "/feemarket.feemarket.v1.GasPriceResponse"; /** Type URL for GasPricesResponse messages */ export declare const typeUrlGasPricesResponse: "/feemarket.feemarket.v1.GasPricesResponse"; /** Type URL for ParamsResponse messages */ export declare const typeUrlParamsResponse: "/feemarket.feemarket.v1.ParamsResponse"; /** * Default gas price tier names for fee calculation. * Provides predefined tiers for different transaction priority levels. */ export declare const defaultGasPriceTiers: { /** Low priority tier with lowest gas prices */ readonly Low: "DefaultLowTier"; /** Average priority tier with moderate gas prices */ readonly Avg: "DefaultAvgTier"; /** High priority tier with highest gas prices */ readonly High: "DefaultHighTier"; }; /** Type representing the available default gas price tiers */ export type DefaultGasPriceTiers = (typeof defaultGasPriceTiers)[keyof typeof defaultGasPriceTiers]; /** * Encode object interface for GasPriceResponse messages. * Used for type-safe message encoding in gas price operations. */ export interface GasPriceEncodeObject extends EncodeObject { readonly typeUrl: typeof typeUrlGasPriceResponse; readonly value: Partial<GasPriceResponse>; } /** * Type guard function to check if an object is a GasPriceEncodeObject. * * @param obj - EncodeObject to check * @returns True if the object is a GasPriceEncodeObject */ export declare function isGasPriceEncodeObject(obj: EncodeObject): obj is GasPriceEncodeObject; /** * Encode object interface for GasPricesResponse messages. * Used for type-safe message encoding in gas prices query operations. */ export interface GasPricesEncodeObject extends EncodeObject { readonly typeUrl: typeof typeUrlGasPricesResponse; readonly value: Partial<GasPricesResponse>; } /** * Type guard function to check if an object is a GasPricesEncodeObject. * * @param obj - EncodeObject to check * @returns True if the object is a GasPricesEncodeObject */ export declare function isGasPricesEncodeObject(obj: EncodeObject): obj is GasPricesEncodeObject; /** * Encode object interface for ParamsResponse messages. * Used for type-safe message encoding in fee market parameters operations. */ export interface ParamsEncodeObject extends EncodeObject { readonly typeUrl: typeof typeUrlParamsResponse; readonly value: Partial<ParamsResponse>; } /** * Type guard function to check if an object is a ParamsEncodeObject. * * @param obj - EncodeObject to check * @returns True if the object is a ParamsEncodeObject */ export declare function isParamsEncodeObject(obj: EncodeObject): obj is ParamsEncodeObject; /** Minimal importable version of the fee market module for clean external interfaces */ export type MinimalImportableFeemarketModule = MinimalImportableCheqdSDKModule<FeemarketModule>; /** * Fee market extension interface for querier functionality. * Provides methods for querying gas prices and fee market parameters. */ export type FeemarketExtension = { readonly [defaultFeemarketExtensionKey]: { /** Query gas price for a specific denomination */ readonly gasPrice: (denom: string) => Promise<GasPriceResponse>; /** Query all available gas prices */ readonly gasPrices: () => Promise<GasPricesResponse>; /** Query fee market module parameters */ readonly params: () => Promise<ParamsResponse>; }; }; /** * Sets up the fee market extension for the querier client. * Creates and configures the fee market-specific query methods. * * @param base - Base QueryClient to extend * @returns Configured fee market extension with query methods */ export declare const setupFeemarketExtension: (base: QueryClient) => FeemarketExtension; /** * Fee Market Module class providing comprehensive fee market functionality. * Handles gas price queries, dynamic fee calculation, and fee market parameter management. */ export declare class FeemarketModule extends AbstractCheqdSDKModule { static readonly registryTypes: Iterable<[string, GeneratedType]>; /** * Default gas prices for different priority tiers. * Used as fallback when live gas price queries are unavailable. */ static readonly defaultGasPrices: { readonly DefaultLowTier: { readonly amount: "5000"; readonly denom: "ncheq"; }; readonly DefaultAvgTier: { readonly amount: "7500"; readonly denom: "ncheq"; }; readonly DefaultHighTier: { readonly amount: "10000"; readonly denom: "ncheq"; }; }; /** Gas offset factor used for adjusting live gas prices */ static readonly gasOffsetFactor: number; /** Address of the fee collector account that receives transaction fees */ static readonly feeCollectorAddress: "cheqd13pxn9n3qw79e03844rdadagmg0nshmwfszqu0g"; /** Address of the fee market module account */ static readonly moduleAccountAddress: "cheqd1el68mjnzv87uurqks8u29tec0cj3297047g2dl"; /** Querier extension setup function for fee market operations */ static readonly querierExtensionSetup: QueryExtensionSetup<FeemarketExtension>; /** Querier instance with fee market extension capabilities */ querier: CheqdQuerier & FeemarketExtension; /** * Constructs a new fee market module instance. * * @param signer - Signing client for blockchain transactions * @param querier - Querier client with fee market extension for data retrieval */ constructor(signer: CheqdSigningStargateClient, querier: CheqdQuerier & FeemarketExtension); /** * Gets the registry types for fee market message encoding/decoding. * * @returns Iterable of [typeUrl, GeneratedType] pairs for the registry */ getRegistryTypes(): Iterable<[string, GeneratedType]>; /** * Gets the querier extension setup for fee market operations. * * @returns Query extension setup function for fee market functionality */ getQuerierExtensionSetup(): QueryExtensionSetup<FeemarketExtension>; /** * Queries the current gas price for a specific denomination. * Retrieves live gas price data from the fee market module. * * @param denom - Token denomination to query gas price for * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the gas price response */ queryGasPrice(denom: string, context?: IContext): Promise<GasPriceResponse>; /** * Queries all available gas prices from the fee market. * Retrieves comprehensive gas pricing information for all denominations. * * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the gas prices response */ queryGasPrices(context?: IContext): Promise<GasPricesResponse>; /** * Queries the fee market module parameters. * Retrieves configuration settings for the fee market functionality. * * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the parameters response */ queryParams(context?: IContext): Promise<ParamsResponse>; /** * Generates gas price for a denomination by live polling the fee market. * Queries current gas prices and adjusts them using the gas offset factor. * Throws an error if live polling fails. * * @param denom - Token denomination to generate gas price for * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the calculated gas price * @throws Error if live poll for gas price fails or returns invalid data */ generateGasPrice(denom: string, context?: IContext): Promise<GasPrice>; /** * Generates offline gas price for a denomination using static tier pricing. * Uses predefined gas prices as fallback when live polling is unavailable. * * @param denom - Token denomination to generate gas price for * @param tier - Priority tier for gas price calculation (defaults to Low) * @returns Promise resolving to the static gas price * @throws Error if denomination or tier is invalid */ generateOfflineGasPrice(denom: string, tier?: DefaultGasPriceTiers): Promise<GasPrice>; /** * Generates safe gas price with automatic fallback to offline pricing. * Attempts live polling first, falls back to static tier pricing if it fails. * * @param denom - Token denomination to generate gas price for * @param tier - Priority tier for fallback gas price calculation (defaults to Low) * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the gas price (live or fallback) */ generateSafeGasPrice(denom: string, tier?: DefaultGasPriceTiers, context?: IContext): Promise<GasPrice>; /** * Generates safe gas price with exponential backoff retry mechanism. * Retries live polling with exponential backoff before falling back to offline pricing. * * @param denom - Token denomination to generate gas price for * @param tier - Priority tier for fallback gas price calculation (defaults to Low) * @param backoffOptions - Retry configuration options (defaults to DefaultBackoffOptions) * @param context - Optional SDK context for accessing clients * @returns Promise resolving to the gas price (live with retries or fallback) */ generateSafeGasPriceWithExponentialBackoff(denom: string, tier?: DefaultGasPriceTiers, backoffOptions?: Partial<import("exponential-backoff").IBackOffOptions>, context?: IContext): Promise<GasPrice>; /** * Generates transaction fees from a given gas price. * Calculates the total fee amount based on gas price and gas limit. * * @param gasPrice - Gas price to use for fee calculation * @param payer - Address of the account paying the transaction fees * @param gas - Gas limit for the transaction (defaults to '200000') * @returns Standard fee configuration for the transaction */ static generateFeesFromGasPrice(gasPrice: GasPrice, payer: string, gas?: string): DidStdFee; } //# sourceMappingURL=feemarket.d.ts.map