Function: transformRawApiTokenToDomainModel()
Gala Launchpad SDK 9.0.0-rc.5 / index / transformRawApiTokenToDomainModel
Function: transformRawApiTokenToDomainModel()
transformRawApiTokenToDomainModel(
rawToken):DomainToken
Defined in: packages/launchpad-sdk/dist/utils/data-transform-patterns.d.ts:100
Transform raw API token response to SDK domain model
Converts raw token data from various API sources (DEX, GalaChain, etc.) to a normalized domain model with sensible defaults.
Consolidates repeated token transformation logic.
Handles:
- Missing fields with defaults (decimals: 8, verified: false, etc.)
- Field name variations (tokenName vs name, tokenSymbol vs symbol)
- Symbol fallback chain: symbol → tokenSymbol (never
collection: a collection is not a symbol) - Validates required fields (name, symbol) exist and are non-empty
Parameters
rawToken
unknown
Raw token object from API response (may have missing fields)
Returns
Normalized token domain model with required fields and defaults applied
Throws
Error if required fields (name, symbol) are missing or empty
Examples
Basic transformation
const rawToken = {
tokenName: 'Anime',
tokenSymbol: 'ANI',
decimals: 18,
verified: true,
address: '0xabc123...'
};
const domain = transformRawApiTokenToDomainModel(rawToken);
// Returns: {
// name: 'Anime',
// symbol: 'ANI',
// decimals: 18,
// verified: true,
// address: '0xabc123...'
// }
With missing optional fields
const minimalToken = {
name: 'GALA',
symbol: 'GALA'
};
const domain = transformRawApiTokenToDomainModel(minimalToken);
// Returns: {
// name: 'GALA',
// symbol: 'GALA',
// decimals: 8, // default
// verified: false // default
// }
With field name variations
const apiResponse = {
tokenName: 'Demon K-Pop',
tokenSymbol: 'DEMONKPOP',
decimals: 18
};
const domain = transformRawApiTokenToDomainModel(apiResponse);
// Normalizes both name and symbol field names automatically
Error on missing required field
transformRawApiTokenToDomainModel({ name: 'Test' });
// Throws: Error('Token symbol is required')