UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

48 lines 1.69 kB
/** * Helper functions for working with Lunar Indexer marketId and tokenId formats */ /** * Build a marketId string from chainId and market address * Format: {chainId}-{marketAddress} * @param chainId - The chain ID * @param marketAddress - The market contract address * @returns Formatted marketId string */ export function buildMarketId(chainId, marketAddress) { return `${chainId}-${marketAddress.toLowerCase()}`; } /** * Parse a marketId string into chainId and marketAddress * @param marketId - The marketId string to parse * @returns Object containing chainId and marketAddress */ export function parseMarketId(marketId) { const [chainIdStr, ...addressParts] = marketId.split("-"); return { chainId: Number.parseInt(chainIdStr, 10), marketAddress: addressParts.join("-"), // Handle addresses that might contain dashes }; } /** * Build a tokenId string from chainId and token address * Format: {chainId}-{tokenAddress} * @param chainId - The chain ID * @param tokenAddress - The token contract address * @returns Formatted tokenId string */ export function buildTokenId(chainId, tokenAddress) { return `${chainId}-${tokenAddress.toLowerCase()}`; } /** * Parse a tokenId string into chainId and tokenAddress * @param tokenId - The tokenId string to parse * @returns Object containing chainId and tokenAddress */ export function parseTokenId(tokenId) { const [chainIdStr, ...addressParts] = tokenId.split("-"); return { chainId: Number.parseInt(chainIdStr, 10), tokenAddress: addressParts.join("-"), // Handle addresses that might contain dashes }; } //# sourceMappingURL=lunar-indexer-helpers.js.map