@gala-chain/launchpad-sdk
Version:
TypeScript SDK for Gala Launchpad Backend API - Production-ready DeFi token launchpad integration with wallet-based authentication, GalaChain trading, and comprehensive user operations. 100% tested (22/22 endpoints working).
206 lines • 6.18 kB
TypeScript
/**
* Backend Response Interfaces
*
* Type definitions for raw backend API responses before normalization.
* These interfaces capture the various response formats the backend API
* returns, enabling type-safe response normalization.
*
* @category Types
* @since 3.12.0
*/
import { PoolData } from './launchpad.dto';
import { TradeInfo } from './trade.dto';
import { UserTokenInfo } from './user.dto';
/**
* Backend pool response format - handles three variations:
* 1. Single token: { tokens: PoolData }
* 2. Multiple tokens: { tokens: PoolData[] }
* 3. Legacy format: { pools: PoolData[] }
*/
export interface BackendPoolResponse {
/** Single pool data or array of pools (modern format) */
tokens?: PoolData | PoolData[];
/** Array of pools (legacy format) */
pools?: PoolData[];
/** Total count field from backend (not "total") */
count?: number;
/** Optional pagination fields (rarely provided by backend) */
page?: number;
limit?: number;
total?: number;
totalPages?: number;
}
/**
* Raw pool item from backend (before date normalization)
*/
export interface RawBackendPool {
id: string;
tokenName: string;
symbol: string;
description: string;
amount: string;
creatorAddress: string;
vaultAddress: string;
/** Backend returns created_at as string or createdAt */
created_at?: string;
createdAt?: string;
/** Optional reverse bonding curve fee fields */
reverseBondingCurveMinFeePortion?: string;
reverseBondingCurveMaxFeePortion?: string;
hasReverseBondingCurveFee?: boolean;
/** Additional pool metadata - use unknown for type safety, narrow with type guards when accessing */
[key: string]: unknown;
}
/**
* Backend trade response format - handles two variations:
* 1. Direct array: TradeInfo[]
* 2. Wrapped object: { trades: TradeInfo[] }
*/
export type BackendTradeResponse = TradeInfo[] | {
trades: TradeInfo[];
/** Optional pagination metadata */
page?: number;
limit?: number;
total?: number;
totalPages?: number;
hasNextPage?: boolean;
hasPrevPage?: boolean;
};
/**
* Raw trade item from backend (before date normalization)
*/
export interface RawBackendTrade {
id: string;
userAddress: string;
tradeType: 'buy' | 'sell';
tokenAmount: string;
vaultAddress: string;
/** Backend returns timestamps as strings */
createdAt: string;
updatedAt: string;
slippageTolerance?: string;
deadline?: number;
/** Additional trade metadata - use unknown for type safety, narrow with type guards when accessing */
[key: string]: unknown;
}
/**
* Backend token list response format - handles two variations:
* 1. Direct array: UserTokenInfo[]
* 2. Wrapped object: { token: UserTokenInfo[] }
*/
export type BackendTokenListResponse = UserTokenInfo[] | {
token: UserTokenInfo[];
/** Optional pagination metadata */
count?: number;
page?: number;
limit?: number;
total?: number;
totalPages?: number;
};
/**
* Raw token item from backend (before date normalization)
*/
export interface RawBackendToken {
id: string;
name: string;
symbol: string;
type: 'all' | 'DEFI' | 'ASSET';
address: string;
balance: string;
decimals: number;
metadata?: {
description?: string;
image?: string;
/** Additional nested metadata - use unknown for type safety */
[key: string]: unknown;
};
/** Backend returns timestamps as strings */
createdAt: string;
updatedAt: string;
/** Additional token metadata - use unknown for type safety, narrow with type guards when accessing */
[key: string]: unknown;
}
/**
* Raw pagination metadata from backend responses
* Different endpoints return different field combinations
*/
export interface RawPaginationMetadata {
/** Current page (string or number) */
page?: string | number;
/** Items per page (string or number) */
limit?: string | number;
/** Total items (string or number) */
total?: string | number;
/** Total items via count field (backend preference) */
count?: string | number;
/** Total pages (rarely provided) */
totalPages?: string | number;
/** Next page flag */
hasNextPage?: boolean;
/** Previous page flag */
hasPrevPage?: boolean;
/** Has next (alternative naming) */
hasNext?: boolean;
/** Has previous (alternative naming) */
hasPrevious?: boolean;
}
/**
* Normalized pagination metadata
*/
export interface NormalizedPaginationMetadata {
/** Current page number */
page: number;
/** Items per page */
limit: number;
/** Total number of items */
total: number;
/** Total number of pages (calculated) */
totalPages: number;
}
/**
* Pagination navigation flags
*/
export interface PaginationFlags {
/** Whether there is a next page */
hasNext: boolean;
/** Whether there is a previous page */
hasPrevious: boolean;
}
/**
* Default pagination values
*/
export interface PaginationDefaults {
/** Default page number */
page: number;
/** Default items per page */
limit: number;
}
/**
* Type guard to check if response is a wrapped pool response with tokens field
*/
export declare function isWrappedPoolResponse(response: unknown): response is {
tokens: PoolData | PoolData[];
};
/**
* Type guard to check if response is a legacy pool response with pools field
*/
export declare function isLegacyPoolResponse(response: unknown): response is {
pools: PoolData[];
};
/**
* Type guard to check if trade response is wrapped with trades field
*/
export declare function isWrappedTradeResponse(response: unknown): response is {
trades: TradeInfo[];
};
/**
* Type guard to check if token response is wrapped with token field
*/
export declare function isWrappedTokenResponse(response: unknown): response is {
token: UserTokenInfo[];
};
/**
* Type guard to check if response has pagination metadata
*/
export declare function hasPaginationMetadata(response: unknown): response is RawPaginationMetadata;
//# sourceMappingURL=backend-responses.d.ts.map