|
| 1 | +/** |
| 2 | + * @fileoverview Canonical SoroTask error codes and human-readable message decoder. |
| 3 | + * Maps categorized on-chain Soroban contracterror discriminants into human-readable error descriptions. |
| 4 | + * @module backend-abi-registry/errorCodes |
| 5 | + */ |
| 6 | + |
| 7 | +const ERROR_CODES = { |
| 8 | + // ── 100..199: Authorization & Role-Based Access ────────────────────────────── |
| 9 | + 100: { name: 'Unauthorized', category: 'Auth', message: 'Caller is not authorized to perform this action' }, |
| 10 | + 101: { name: 'UnauthorizedSlasher', category: 'Auth', message: 'Caller is not authorized to slash keeper' }, |
| 11 | + 102: { name: 'OperatorAlreadySet', category: 'Auth', message: 'Operator address has already been set' }, |
| 12 | + 103: { name: 'NotInitialized', category: 'Auth', message: 'Contract has not been initialized' }, |
| 13 | + 104: { name: 'AlreadyInitialized', category: 'Auth', message: 'Contract has already been initialized' }, |
| 14 | + 105: { name: 'FeatureDisabled', category: 'Auth', message: 'Requested protocol feature is disabled' }, |
| 15 | + 106: { name: 'InsufficientDelegation', category: 'Auth', message: 'Keeper delegation amount is insufficient' }, |
| 16 | + 107: { name: 'InvalidCommissionRate', category: 'Auth', message: 'Commission rate exceeds allowable maximum' }, |
| 17 | + |
| 18 | + // ── 200..299: Task Lifecycle & Validation ──────────────────────────────────── |
| 19 | + 200: { name: 'InvalidInterval', category: 'TaskValidation', message: 'Task execution interval is invalid' }, |
| 20 | + 201: { name: 'TaskPaused', category: 'TaskValidation', message: 'Task execution is currently paused' }, |
| 21 | + 202: { name: 'TaskAlreadyPaused', category: 'TaskValidation', message: 'Task is already in a paused state' }, |
| 22 | + 203: { name: 'TaskAlreadyActive', category: 'TaskValidation', message: 'Task is already in an active state' }, |
| 23 | + 204: { name: 'TaskNotFound', category: 'TaskValidation', message: 'Specified task ID does not exist' }, |
| 24 | + 205: { name: 'DuplicateTask', category: 'TaskValidation', message: 'Duplicate task registration detected' }, |
| 25 | + 206: { name: 'InvalidPayload', category: 'TaskValidation', message: 'Task payload or arguments are malformed' }, |
| 26 | + 207: { name: 'ArgsTooMany', category: 'TaskValidation', message: 'Number of task arguments exceeds limit' }, |
| 27 | + 208: { name: 'ArgsTooLarge', category: 'TaskValidation', message: 'Total size of task arguments exceeds limit' }, |
| 28 | + 209: { name: 'BountyBelowMinimum', category: 'TaskValidation', message: 'Task execution bounty is below required minimum' }, |
| 29 | + 210: { name: 'InvalidBounty', category: 'TaskValidation', message: 'Task execution bounty parameters are invalid' }, |
| 30 | + 211: { name: 'InvalidUpgradeVersion', category: 'TaskValidation', message: 'Target WASM upgrade version is invalid' }, |
| 31 | + 212: { name: 'InvalidInsurancePolicy', category: 'TaskValidation', message: 'Insurance policy parameters are invalid' }, |
| 32 | + |
| 33 | + // ── 300..399: Execution, Dependency & Reentrancy ───────────────────────────── |
| 34 | + 300: { name: 'ReentrantCall', category: 'Execution', message: 'Reentrancy guard triggered on recursive entry' }, |
| 35 | + 301: { name: 'SelfDependency', category: 'Execution', message: 'Task cannot depend on itself' }, |
| 36 | + 302: { name: 'DependencyNotFound', category: 'Execution', message: 'Required task dependency not found' }, |
| 37 | + 303: { name: 'CircularDependency', category: 'Execution', message: 'Circular dependency cycle detected' }, |
| 38 | + 304: { name: 'DependencyBlocked', category: 'Execution', message: 'Task execution blocked by unresolved dependencies' }, |
| 39 | + 305: { name: 'DependencyLimitExceeded', category: 'Execution', message: 'Maximum dependency count exceeded' }, |
| 40 | + 306: { name: 'DependencyDepthExceeded', category: 'Execution', message: 'Maximum dependency tree depth exceeded' }, |
| 41 | + 307: { name: 'KeeperStakeTooLow', category: 'Execution', message: 'Keeper active stake is below minimum threshold' }, |
| 42 | + 308: { name: 'EmptyBundle', category: 'Execution', message: 'Task execution bundle contains zero steps' }, |
| 43 | + 309: { name: 'BundleTooLarge', category: 'Execution', message: 'Task bundle size exceeds block limit' }, |
| 44 | + 310: { name: 'BundleStepFailed', category: 'Execution', message: 'One or more bundle execution steps failed' }, |
| 45 | + 311: { name: 'BlockExecutionLimitReached', category: 'Execution', message: 'Per-block task execution cap reached' }, |
| 46 | + 312: { name: 'DecryptionFailed', category: 'Execution', message: 'Encrypted task parameter decryption failed' }, |
| 47 | + 313: { name: 'OptimisticClaimPending', category: 'Execution', message: 'Optimistic challenge claim is currently pending' }, |
| 48 | + 314: { name: 'NoOptimisticClaim', category: 'Execution', message: 'No active optimistic challenge claim found' }, |
| 49 | + 315: { name: 'ChallengeWindowClosed', category: 'Execution', message: 'Optimistic challenge window has expired' }, |
| 50 | + 316: { name: 'ChallengeWindowActive', category: 'Execution', message: 'Challenge window is still active' }, |
| 51 | + 317: { name: 'FraudProofInvalid', category: 'Execution', message: 'Supplied optimistic fraud proof is invalid' }, |
| 52 | + |
| 53 | + // ── 400..499: Oracles, VRF & ZK Verifier ───────────────────────────────────── |
| 54 | + 400: { name: 'OracleNotSet', category: 'Oracle', message: 'Required price or data oracle is not configured' }, |
| 55 | + 401: { name: 'OracleRequestFailed', category: 'Oracle', message: 'Oracle data request failed or reverted' }, |
| 56 | + 402: { name: 'OracleInvalidResponse', category: 'Oracle', message: 'Oracle returned invalid or unparseable data' }, |
| 57 | + 403: { name: 'OracleTimeout', category: 'Oracle', message: 'Oracle response exceeded timeout window' }, |
| 58 | + 404: { name: 'OracleUnsupportedProvider', category: 'Oracle', message: 'Specified oracle provider is not supported' }, |
| 59 | + 405: { name: 'VrfOracleNotSet', category: 'Oracle', message: 'VRF randomness oracle is not configured' }, |
| 60 | + 406: { name: 'InvalidVrfRequest', category: 'Oracle', message: 'VRF randomness request parameters are invalid' }, |
| 61 | + 407: { name: 'VrfRequestFailed', category: 'Oracle', message: 'VRF randomness fulfillment request failed' }, |
| 62 | + 408: { name: 'VrfAlreadyFulfilled', category: 'Oracle', message: 'VRF request has already been fulfilled' }, |
| 63 | + 409: { name: 'InvalidZkProof', category: 'Oracle', message: 'Zero-knowledge verification proof is invalid' }, |
| 64 | + 410: { name: 'InvalidVdfProof', category: 'Oracle', message: 'Verifiable delay function proof is invalid' }, |
| 65 | + |
| 66 | + // ── 500..599: Yield, Flash Swaps & Treasury ────────────────────────────────── |
| 67 | + 500: { name: 'InsufficientBalance', category: 'Treasury', message: 'Contract or task escrow balance is insufficient' }, |
| 68 | + 501: { name: 'YieldStrategyNotInitialized', category: 'Treasury', message: 'Yield strategy adapter has not been initialized' }, |
| 69 | + 502: { name: 'InvalidYieldStrategy', category: 'Treasury', message: 'Yield strategy configuration is invalid' }, |
| 70 | + 503: { name: 'YieldHarvestFailed', category: 'Treasury', message: 'Harvesting yield from external protocol failed' }, |
| 71 | + 504: { name: 'InsufficientYield', category: 'Treasury', message: 'Yield generated is below expected threshold' }, |
| 72 | + 505: { name: 'FlashSwapFailed', category: 'Treasury', message: 'Flash swap callback execution failed' }, |
| 73 | + 506: { name: 'InsufficientFlashProfit', category: 'Treasury', message: 'Flash swap did not generate required minimum profit' }, |
| 74 | + 507: { name: 'InvalidSlippage', category: 'Treasury', message: 'Slippage parameter exceeds maximum allowed tolerance' }, |
| 75 | + |
| 76 | + // ── 600..699: Volatility & Circuit Breakers ────────────────────────────────── |
| 77 | + 600: { name: 'VolatilityExceeded', category: 'Volatility', message: 'Asset volatility exceeds allowed tolerance limit' }, |
| 78 | + 601: { name: 'VolatilityCircuitBreakerTripped', category: 'Volatility', message: 'Volatility circuit breaker tripped; execution paused' }, |
| 79 | + 602: { name: 'VolatilityTimelockActive', category: 'Volatility', message: 'Volatility timelock is active; cannot execute until window expires' }, |
| 80 | +}; |
| 81 | + |
| 82 | +/** |
| 83 | + * Decodes an on-chain numeric error code into a human-readable error description. |
| 84 | + * |
| 85 | + * @param {number} code - On-chain error discriminant. |
| 86 | + * @returns {{ code: number, name: string, category: string, message: string }} Error metadata. |
| 87 | + */ |
| 88 | +function decodeErrorCode(code) { |
| 89 | + const info = ERROR_CODES[code]; |
| 90 | + if (info) { |
| 91 | + return { code, ...info }; |
| 92 | + } |
| 93 | + return { |
| 94 | + code, |
| 95 | + name: 'UnknownError', |
| 96 | + category: 'Unknown', |
| 97 | + message: `Unknown contract error code: ${code}`, |
| 98 | + }; |
| 99 | +} |
| 100 | + |
| 101 | +module.exports = { |
| 102 | + ERROR_CODES, |
| 103 | + decodeErrorCode, |
| 104 | +}; |
0 commit comments