/ src / ui-config / errorMapping.tsx
errorMapping.tsx
  1  import { Trans } from '@lingui/macro';
  2  import { ReactElement } from 'react';
  3  
  4  export enum TxAction {
  5    APPROVAL,
  6    MAIN_ACTION,
  7    GAS_ESTIMATION,
  8  }
  9  
 10  export type TxErrorType = {
 11    blocking: boolean;
 12    actionBlocked: boolean;
 13    rawError: Error;
 14    error: ReactElement | undefined;
 15    txAction: TxAction;
 16  };
 17  
 18  export const getErrorTextFromError = (
 19    error: Error,
 20    txAction: TxAction,
 21    blocking = true
 22  ): TxErrorType => {
 23    let errorNumber = 1;
 24  
 25    if (error.message.startsWith('user rejected transaction')) {
 26      return {
 27        error: errorMapping[4001],
 28        blocking: false,
 29        actionBlocked: false,
 30        rawError: error,
 31        txAction,
 32      };
 33    }
 34  
 35    // Try to parse the Pool error number from RPC provider revert error
 36    try {
 37      // eslint-disable-next-line @typescript-eslint/no-explicit-any
 38      const parsedError = JSON.parse((error as any)?.error?.body);
 39      const parsedNumber = Number(parsedError.error.message.split(': ')[1]);
 40      if (!isNaN(parsedNumber)) {
 41        errorNumber = parsedNumber;
 42      }
 43    } catch {}
 44  
 45    const errorRender = errorMapping[errorNumber];
 46  
 47    if (errorRender) {
 48      return {
 49        error: errorRender,
 50        blocking,
 51        actionBlocked: true,
 52        rawError: error,
 53        txAction,
 54      };
 55    }
 56  
 57    return {
 58      error: undefined,
 59      blocking,
 60      actionBlocked: true,
 61      rawError: error,
 62      txAction,
 63    };
 64  };
 65  
 66  export const errorMapping: Record<number, ReactElement> = {
 67    // 1: <Trans>The caller of the function is not a pool admin</Trans>,
 68    // 2: <Trans>The caller of the function is not an emergency admin</Trans>,
 69    // 3: <Trans>The caller of the function is not a pool or emergency admin</Trans>,
 70    // 4: <Trans>The caller of the function is not a risk or pool admin</Trans>,
 71    // 5: <Trans>The caller of the function is not an asset listing or pool admin</Trans>,
 72    // 6: <Trans>The caller of the function is not a bridge</Trans>,
 73    7: <Trans>Pool addresses provider is not registered</Trans>,
 74    // 8: <Trans>Invalid id for the pool addresses provider</Trans>,
 75    9: <Trans>Address is not a contract</Trans>,
 76    // 10: <Trans>The caller of the function is not the pool configurator</Trans>,
 77    11: <Trans>The caller of the function is not an AToken</Trans>,
 78    12: <Trans>The address of the pool addresses provider is invalid</Trans>,
 79    13: <Trans>Invalid return value of the flashloan executor function</Trans>,
 80    // 14: <Trans>Reserve has already been added to reserve list</Trans>,
 81    // 15: <Trans>Maximum amount of reserves in the pool reached</Trans>,
 82    // 16: <Trans>Zero eMode category is reserved for volatile heterogeneous assets</Trans>,
 83    // 17: <Trans>Invalid eMode category assignment to asset</Trans>,
 84    // 18: <Trans>The liquidity of the reserve needs to be 0</Trans>,
 85    19: <Trans>Invalid flashloan premium</Trans>,
 86    // 20: <Trans>Invalid risk parameters for the reserve</Trans>,
 87    // 21: <Trans>Invalid risk parameters for the eMode category</Trans>,
 88    22: <Trans>Invalid bridge protocol fee</Trans>,
 89    23: <Trans>The caller of this function must be a pool</Trans>,
 90    24: <Trans>Invalid amount to mint</Trans>,
 91    25: <Trans>Invalid amount to burn</Trans>,
 92    26: <Trans>Amount must be greater than 0</Trans>,
 93    27: <Trans>Action requires an active reserve</Trans>,
 94    28: <Trans>Action cannot be performed because the reserve is frozen</Trans>,
 95    29: <Trans>Action cannot be performed because the reserve is paused</Trans>,
 96    30: <Trans>Borrowing is not enabled</Trans>,
 97    31: <Trans>Stable borrowing is not enabled</Trans>,
 98    32: <Trans>User cannot withdraw more than the available balance</Trans>,
 99    // 33: <Trans>Invalid interest rate mode selected</Trans>,
100    34: <Trans>The collateral balance is 0</Trans>,
101    35: <Trans>Health factor is lesser than the liquidation threshold</Trans>,
102    36: <Trans>There is not enough collateral to cover a new borrow</Trans>,
103    37: <Trans>Collateral is (mostly) the same currency that is being borrowed</Trans>,
104    38: <Trans>The requested amount is greater than the max loan size in stable rate mode</Trans>,
105    39: (
106      <Trans>For repayment of a specific type of debt, the user needs to have debt that type</Trans>
107    ),
108    40: <Trans>To repay on behalf of a user an explicit amount to repay is needed</Trans>,
109    41: <Trans>User does not have outstanding stable rate debt on this reserve</Trans>,
110    42: <Trans>User does not have outstanding variable rate debt on this reserve</Trans>,
111    43: <Trans>The underlying balance needs to be greater than 0</Trans>,
112    44: <Trans>Interest rate rebalance conditions were not met</Trans>,
113    45: <Trans>Health factor is not below the threshold</Trans>,
114    46: <Trans>The collateral chosen cannot be liquidated</Trans>,
115    47: <Trans>User did not borrow the specified currency</Trans>,
116    48: <Trans>Borrow and repay in same block is not allowed</Trans>,
117    49: <Trans>Inconsistent flashloan parameters</Trans>,
118    50: <Trans>Borrow cap is exceeded</Trans>,
119    51: <Trans>Supply cap is exceeded</Trans>,
120    52: <Trans>Unbacked mint cap is exceeded</Trans>,
121    53: <Trans>Debt ceiling is exceeded</Trans>,
122    54: <Trans>AToken supply is not zero</Trans>,
123    55: <Trans>Stable debt supply is not zero</Trans>,
124    56: <Trans>Variable debt supply is not zero</Trans>,
125    57: <Trans>Ltv validation failed</Trans>,
126    // 58: <Trans>Inconsistent eMode category</Trans>,
127    // 59: <Trans>Price oracle sentinel validation failed</Trans>,
128    60: <Trans>Asset is not borrowable in isolation mode</Trans>,
129    // 61: <Trans>Reserve has already been initialized</Trans>,
130    62: <Trans>User is in isolation mode or LTV is zero</Trans>,
131    // 63: <Trans>Invalid ltv parameter for the reserve</Trans>,
132    // 64: <Trans>Invalid liquidity threshold parameter for the reserve</Trans>,
133    // 65: <Trans>Invalid liquidity bonus parameter for the reserve</Trans>,
134    // 66: <Trans>Invalid decimals parameter of the underlying asset of the reserve</Trans>,
135    // 67: <Trans>Invalid reserve factor parameter for the reserve</Trans>,
136    // 68: <Trans>Invalid borrow cap for the reserve</Trans>,
137    // 69: <Trans>Invalid supply cap for the reserve</Trans>,
138    // 70: <Trans>Invalid liquidation protocol fee for the reserve</Trans>,
139    // 71: <Trans>Invalid eMode category for the reserve</Trans>,
140    // 72: <Trans>Invalid unbacked mint cap for the reserve</Trans>,
141    // 73: <Trans>Invalid debt ceiling for the reserve</Trans>,
142    // 74: <Trans>Invalid reserve index</Trans>,
143    // 75: <Trans>ACL admin cannot be set to the zero address</Trans>,
144    76: <Trans>Array parameters that should be equal length are not</Trans>,
145    77: <Trans>Zero address not valid</Trans>,
146    78: <Trans>Invalid expiration</Trans>,
147    79: <Trans>Invalid signature</Trans>,
148    80: <Trans>Operation not supported</Trans>,
149    81: <Trans>Debt ceiling is not zero</Trans>,
150    82: <Trans>Asset is not listed</Trans>,
151    // 83: <Trans>Invalid optimal usage ratio</Trans>,
152    // 84: <Trans>Invalid optimal stable to total debt ratio</Trans>,
153    85: <Trans>The underlying asset cannot be rescued</Trans>,
154    // 86: <Trans>Reserve has already been added to reserve list</Trans>,
155    // 87: (
156    //   <Trans>
157    //     The token implementation pool address and the pool address provided by the initializing pool
158    //     do not match
159    //   </Trans>
160    // ),
161    88: <Trans>Stable borrowing is enabled</Trans>,
162    89: <Trans>User is trying to borrow multiple assets including a siloed one</Trans>,
163    // 90: <Trans>the total debt of the reserve needs to be</Trans>,
164  
165    4001: <Trans>You cancelled the transaction.</Trans>,
166  };