Skip to main content

index/functions/normalizeTokenKey.md

normalizeTokenKey(key): string

Normalizes a token identifier for consistent cache keys.

Used by the cache services (AbstractCacheService) for case-insensitive lookups of token symbols and tokenIds.

Current normalizations:

  • .trim() - Remove leading/trailing whitespace
  • .toUpperCase() - Convert to uppercase

Note: This uppercases the ENTIRE string including pipe-delimited tokenIds. This is intentional for cache lookup consistency - both the cache key and the lookup key are normalized identically. The original casing is preserved in the cached values themselves, not the keys.

Parameters​

ParameterTypeDescription
keystringThe token identifier (symbol or tokenId) to normalize

Returns​

string

Normalized key (trimmed and uppercased)

Example​

import { normalizeTokenKey } from '../utils/tokenNameNormalizer';

const normalized = normalizeTokenKey(' gala ');
console.log(normalized); // 'GALA'

// Full tokenId also uppercased (intentional for cache key consistency)
const tokenId = normalizeTokenKey('GUSDC|Unit|none|eth:0x...');
console.log(tokenId); // 'GUSDC|UNIT|NONE|ETH:0X...'

Since​

6.4.0