All files version.ts

100% Statements 36/36
100% Branches 5/5
100% Functions 2/2
100% Lines 36/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                      1x         1x                       1x         1x 5x 5x         1x 10x 10x 10x 7x 7x 7x 7x 7x 7x 7x 3x 3x 3x 3x 3x   10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x   10x 10x  
/**
 * Protocol version compatibility tracking.
 *
 * The Kraiken contract exposes a VERSION constant that must be checked
 * at runtime by indexers and frontends to ensure data compatibility.
 */
 
/**
 * Current version this library is built for.
 * Should match the deployed Kraiken contract VERSION.
 */
export const KRAIKEN_LIB_VERSION = 2;
 
/**
 * Singleton ID used for stack metadata rows across services.
 */
export const STACK_META_ID = 'stack-meta';
 
/**
 * List of Kraiken contract versions this library is compatible with.
 *
 * - Indexers MUST validate contract.VERSION is in this list at startup
 * - Frontends SHOULD validate indexer version matches KRAIKEN_LIB_VERSION
 *
 * Version History:
 * - v1: Initial deployment (30-tier TAX_RATES, index-based staking)
 * - v2: OptimizerV3, VWAP mirror floor, directional VWAP recording
 */
export const COMPATIBLE_CONTRACT_VERSIONS = [1, 2];
 
/**
 * Validates if a contract version is compatible with this library.
 */
export function isCompatibleVersion(contractVersion: number): boolean {
  return COMPATIBLE_CONTRACT_VERSIONS.includes(contractVersion);
}
 
/**
 * Error message generator for version mismatches.
 */
export function getVersionMismatchError(contractVersion: number, context: 'ponder' | 'frontend'): string {
  const compatibleVersions = COMPATIBLE_CONTRACT_VERSIONS.join(', ');
  const instructions =
    context === 'ponder'
      ? [
        '1. Check if contract was upgraded',
        '2. Update COMPATIBLE_CONTRACT_VERSIONS in kraiken-lib/src/version.ts',
        '3. Run: ./scripts/build-kraiken-lib.sh',
        '4. Run: rm -rf services/ponder/.ponder/',
        '5. Restart Ponder for full re-index',
      ]
      : [
        '1. Contact administrator - indexer may need updating',
        '2. Try refreshing the page',
        '3. Check if contract was recently upgraded',
      ];
 
  const lines = [
    '╔════════════════════════════════════════════════════════════╗',
    `║  ❌ CRITICAL: VERSION MISMATCH (${context})`.padEnd(61) + '║',
    '╠════════════════════════════════════════════════════════════╣',
    `║  Contract VERSION:      ${contractVersion}`.padEnd(61) + '║',
    `║  Library VERSION:       ${KRAIKEN_LIB_VERSION}`.padEnd(61) + '║',
    `║  Compatible versions:   ${compatibleVersions}`.padEnd(61) + '║',
    '║'.padEnd(61) + '║',
    '║  📋 Required Actions:'.padEnd(61) + '║',
    ...instructions.map(line => `║  ${line}`.padEnd(61) + '║'),
    '╚════════════════════════════════════════════════════════════╝',
  ];
 
  return lines.join('\n');
}