@lidofinance/lido-csm-sdk 2.0.0-alpha.62 → 2.0.0-alpha.63

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,6 +16,8 @@
16
16
 
17
17
  ## Installation
18
18
 
19
+ Requires **Node.js >= 24**, `@lidofinance/lido-ethereum-sdk >= 4.8.0`, and `viem >= 2.46.0` (peer dependencies).
20
+
19
21
  Install via npm or yarn:
20
22
 
21
23
  ```bash
@@ -118,7 +120,7 @@ The SDK is designed for extensibility. You can instantiate individual modules di
118
120
 
119
121
  ## License
120
122
 
121
- This project is licensed under the MIT License. See the [LICENSE.txt](LICENSE.txt) file for details.
123
+ This project is licensed under the GPL-3.0-or-later License. See the [LICENSE.txt](LICENSE.txt) file for details.
122
124
 
123
125
  ## Changelog
124
126
 
@@ -42,6 +42,15 @@ var SDKError = class SDKError extends Error {
42
42
  this.code = code ?? require_sdk_error_code.ERROR_CODE.UNKNOWN_ERROR;
43
43
  this.decodedRevert = decodedRevert;
44
44
  }
45
+ /**
46
+ * @deprecated Use `message` (the idiomatic `Error` field) instead — this is
47
+ * a thin alias kept for pre-refactor consumers and will be removed in the
48
+ * next major. For structured access to a decoded contract revert, read
49
+ * `decodedRevert` ({ name, args }).
50
+ */
51
+ get errorMessage() {
52
+ return this.message || void 0;
53
+ }
45
54
  };
46
55
  function invariant(condition, message, code) {
47
56
  if (condition) return;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-error.cjs","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"sourcesContent":["import { classifyError } from './classify-error';\nimport { type DecodedRevert, decodeRevertData } from './decode-revert-data';\nimport { ERROR_CODE } from './sdk-error-code';\n\nexport { ERROR_CODE } from './sdk-error-code';\n\nexport type SDKErrorProps = {\n code?: ERROR_CODE;\n error?: unknown;\n message?: string;\n decodedRevert?: DecodedRevert;\n};\n\nconst messageOf = (error: unknown): string =>\n typeof error === 'object' &&\n error !== null &&\n 'message' in error &&\n typeof error.message === 'string'\n ? error.message\n : 'something went wrong';\n\n/**\n * Canonical `Name(arg1, arg2, ...)` label for a decoded contract revert.\n * Falls back to bare `Name` when the error has no args. Exposed so consumers\n * with a raw `decodedRevert` (e.g. from logs) can render the same string the\n * SDK uses as `Error.message`.\n */\nexport const formatDecodedRevert = (decoded: DecodedRevert): string => {\n if (!decoded.args.length) return decoded.name;\n const args = (decoded.args as readonly unknown[]).map(String).join(', ');\n return `${decoded.name}(${args})`;\n};\n\n/**\n * Typed wrapper around every error thrown by the SDK. Invariants:\n * - `code` is always set (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n * - `cause` preserves the original upstream error (typically a viem\n * `BaseError`) so consumers can walk the chain.\n * - `decodedRevert` is present iff the underlying error carried a custom\n * error selector decodable against the SDK's known ABIs.\n *\n * Branch on `code` for wallet / network conditions; narrow on\n * `decodedRevert.name` for typed contract revert args.\n *\n * @example\n * try { await sdk.bond.claimBondStETH(...) } catch (e) {\n * if (!(e instanceof SDKError)) throw e;\n * if (e.code === ERROR_CODE.USER_REJECTED) return;\n * if (e.decodedRevert?.name === 'AccessControlUnauthorizedAccount') {\n * const [account, role] = e.decodedRevert.args; // typed tuple\n * showRoleErrorToast(account, role);\n * }\n * }\n */\nexport class SDKError extends Error {\n /**\n * Wrap any thrown value into an `SDKError`. Pass `code` as a context hint\n * (e.g. `TRANSACTION_ERROR`); it is only used when {@link classifyError}\n * yields nothing. The classifier always wins because viem class detection\n * is strictly more specific than a context code.\n */\n public static from(error: unknown, code?: ERROR_CODE): SDKError {\n if (error instanceof SDKError) return error;\n\n const decodedRevert = decodeRevertData(error);\n const message = decodedRevert\n ? formatDecodedRevert(decodedRevert)\n : messageOf(error);\n\n const finalCode =\n classifyError(error, decodedRevert) ?? code ?? ERROR_CODE.UNKNOWN_ERROR;\n\n return new SDKError({ code: finalCode, error, message, decodedRevert });\n }\n\n /** Classified error category. Always set. See {@link ERROR_CODE}. */\n public code: ERROR_CODE;\n\n /**\n * Decoded contract revert, when the upstream error carried a selector\n * decodable against the SDK's combined ABI. Discriminated union: narrow on\n * `name` to get a typed `args` tuple.\n */\n public decodedRevert: DecodedRevert | undefined;\n\n /**\n * Original upstream error (typically a viem `BaseError`). Inherited from\n * `Error.cause`. Walk via `e.cause` to inspect the full chain.\n */\n declare public cause?: unknown;\n\n constructor({ code, error, message, decodedRevert }: SDKErrorProps) {\n super(message);\n this.name = 'SDKError';\n // Preserve full upstream error as `cause` — consumers walk it via the\n // standard Error chain. Previous code assigned `error.cause` and silently\n // dropped the top viem BaseError.\n if (error !== undefined) {\n this.cause = error;\n }\n if (error instanceof Error && error.stack) {\n this.stack = error.stack;\n }\n this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;\n this.decodedRevert = decodedRevert;\n }\n}\n\n/**\n * Assert `condition` is truthy, otherwise throw an `SDKError` with the given\n * `message` and optional `code` (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n */\n// eslint-disable-next-line func-style\nexport function invariant(\n condition: any,\n message: string,\n code?: ERROR_CODE,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ message, code });\n}\n\n/**\n * Shortcut for argument validation: throws with\n * {@link ERROR_CODE.INVALID_ARGUMENT}.\n */\n// eslint-disable-next-line func-style\nexport function invariantArgument(\n condition: any,\n message: string,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });\n}\n\n/**\n * Await `func`; on rejection, rethrow as `SDKError.from(error, code)`.\n * `code` is a context fallback — the classifier still wins when it matches.\n */\nexport const withSDKError = async <TResult>(\n func: Promise<TResult>,\n code?: ERROR_CODE,\n): Promise<TResult> => {\n try {\n return await func;\n } catch (error) {\n throw SDKError.from(error, code);\n }\n};\n"],"mappings":";;;;AAaA,MAAM,aAAa,UACjB,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,WACrB,MAAM,UACN;AAQC,MAAM,uBAAuB,YAAmC;AACrE,KAAI,CAAC,QAAQ,KAAK,OAAQ,QAAO,QAAQ;CACzC,MAAM,OAAQ,QAAQ,KAA4B,IAAI,OAAM,CAAE,KAAK,KAAI;AACvE,QAAO,GAAG,QAAQ,KAAI,GAAI,KAAI;;AAwBzB,IAAM,WAAN,MAAM,iBAAiB,MAAM;;;;;;;CAOlC,OAAc,KAAK,OAAgB,MAA6B;AAC9D,MAAI,iBAAiB,SAAU,QAAO;EAEtC,MAAM,gBAAgB,2BAAA,iBAAiB,MAAK;EAC5C,MAAM,UAAU,gBACZ,oBAAoB,cAAa,GACjC,UAAU,MAAK;AAKnB,SAAO,IAAI,SAAS;GAAE,MAFpB,uBAAA,cAAc,OAAO,cAAa,IAAK,QAAQ,uBAAA,WAAW;GAErB;GAAO;GAAS;GAAe,CAAA;;;CAIjE;;;;;;CAOA;CAQP,YAAY,EAAE,MAAM,OAAO,SAAS,iBAAgC;AAClE,QAAM,QAAO;AACb,OAAK,OAAO;AAIZ,MAAI,UAAU,KAAA,EACZ,MAAK,QAAQ;AAEf,MAAI,iBAAiB,SAAS,MAAM,MAClC,MAAK,QAAQ,MAAM;AAErB,OAAK,OAAO,QAAQ,uBAAA,WAAW;AAC/B,OAAK,gBAAgB;;;AASlB,SAAS,UACd,WACA,SACA,MACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE;EAAS;EAAM,CAAA;;AAQ/B,SAAS,kBACd,WACA,SACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE,MAAM,uBAAA,WAAW;EAAkB;EAAS,CAAA;;AAO5D,MAAM,eAAe,OAC1B,MACA,SACqB;AACrB,KAAI;AACF,SAAO,MAAM;UACN,OAAO;AACd,QAAM,SAAS,KAAK,OAAO,KAAI"}
1
+ {"version":3,"file":"sdk-error.cjs","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"sourcesContent":["import { classifyError } from './classify-error';\nimport { type DecodedRevert, decodeRevertData } from './decode-revert-data';\nimport { ERROR_CODE } from './sdk-error-code';\n\nexport { ERROR_CODE } from './sdk-error-code';\n\nexport type SDKErrorProps = {\n code?: ERROR_CODE;\n error?: unknown;\n message?: string;\n decodedRevert?: DecodedRevert;\n};\n\nconst messageOf = (error: unknown): string =>\n typeof error === 'object' &&\n error !== null &&\n 'message' in error &&\n typeof error.message === 'string'\n ? error.message\n : 'something went wrong';\n\n/**\n * Canonical `Name(arg1, arg2, ...)` label for a decoded contract revert.\n * Falls back to bare `Name` when the error has no args. Exposed so consumers\n * with a raw `decodedRevert` (e.g. from logs) can render the same string the\n * SDK uses as `Error.message`.\n */\nexport const formatDecodedRevert = (decoded: DecodedRevert): string => {\n if (!decoded.args.length) return decoded.name;\n const args = (decoded.args as readonly unknown[]).map(String).join(', ');\n return `${decoded.name}(${args})`;\n};\n\n/**\n * Typed wrapper around every error thrown by the SDK. Invariants:\n * - `code` is always set (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n * - `cause` preserves the original upstream error (typically a viem\n * `BaseError`) so consumers can walk the chain.\n * - `decodedRevert` is present iff the underlying error carried a custom\n * error selector decodable against the SDK's known ABIs.\n *\n * Branch on `code` for wallet / network conditions; narrow on\n * `decodedRevert.name` for typed contract revert args.\n *\n * @example\n * try { await sdk.bond.claimBondStETH(...) } catch (e) {\n * if (!(e instanceof SDKError)) throw e;\n * if (e.code === ERROR_CODE.USER_REJECTED) return;\n * if (e.decodedRevert?.name === 'AccessControlUnauthorizedAccount') {\n * const [account, role] = e.decodedRevert.args; // typed tuple\n * showRoleErrorToast(account, role);\n * }\n * }\n */\nexport class SDKError extends Error {\n /**\n * Wrap any thrown value into an `SDKError`. Pass `code` as a context hint\n * (e.g. `TRANSACTION_ERROR`); it is only used when {@link classifyError}\n * yields nothing. The classifier always wins because viem class detection\n * is strictly more specific than a context code.\n */\n public static from(error: unknown, code?: ERROR_CODE): SDKError {\n if (error instanceof SDKError) return error;\n\n const decodedRevert = decodeRevertData(error);\n const message = decodedRevert\n ? formatDecodedRevert(decodedRevert)\n : messageOf(error);\n\n const finalCode =\n classifyError(error, decodedRevert) ?? code ?? ERROR_CODE.UNKNOWN_ERROR;\n\n return new SDKError({ code: finalCode, error, message, decodedRevert });\n }\n\n /** Classified error category. Always set. See {@link ERROR_CODE}. */\n public code: ERROR_CODE;\n\n /**\n * Decoded contract revert, when the upstream error carried a selector\n * decodable against the SDK's combined ABI. Discriminated union: narrow on\n * `name` to get a typed `args` tuple.\n */\n public decodedRevert: DecodedRevert | undefined;\n\n /**\n * Original upstream error (typically a viem `BaseError`). Inherited from\n * `Error.cause`. Walk via `e.cause` to inspect the full chain.\n */\n declare public cause?: unknown;\n\n constructor({ code, error, message, decodedRevert }: SDKErrorProps) {\n super(message);\n this.name = 'SDKError';\n // Preserve full upstream error as `cause` — consumers walk it via the\n // standard Error chain. Previous code assigned `error.cause` and silently\n // dropped the top viem BaseError.\n if (error !== undefined) {\n this.cause = error;\n }\n if (error instanceof Error && error.stack) {\n this.stack = error.stack;\n }\n this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;\n this.decodedRevert = decodedRevert;\n }\n\n /**\n * @deprecated Use `message` (the idiomatic `Error` field) instead — this is\n * a thin alias kept for pre-refactor consumers and will be removed in the\n * next major. For structured access to a decoded contract revert, read\n * `decodedRevert` ({ name, args }).\n */\n public get errorMessage(): string | undefined {\n return this.message || undefined;\n }\n}\n\n/**\n * Assert `condition` is truthy, otherwise throw an `SDKError` with the given\n * `message` and optional `code` (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n */\n// eslint-disable-next-line func-style\nexport function invariant(\n condition: any,\n message: string,\n code?: ERROR_CODE,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ message, code });\n}\n\n/**\n * Shortcut for argument validation: throws with\n * {@link ERROR_CODE.INVALID_ARGUMENT}.\n */\n// eslint-disable-next-line func-style\nexport function invariantArgument(\n condition: any,\n message: string,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });\n}\n\n/**\n * Await `func`; on rejection, rethrow as `SDKError.from(error, code)`.\n * `code` is a context fallback — the classifier still wins when it matches.\n */\nexport const withSDKError = async <TResult>(\n func: Promise<TResult>,\n code?: ERROR_CODE,\n): Promise<TResult> => {\n try {\n return await func;\n } catch (error) {\n throw SDKError.from(error, code);\n }\n};\n"],"mappings":";;;;AAaA,MAAM,aAAa,UACjB,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,WACrB,MAAM,UACN;AAQC,MAAM,uBAAuB,YAAmC;AACrE,KAAI,CAAC,QAAQ,KAAK,OAAQ,QAAO,QAAQ;CACzC,MAAM,OAAQ,QAAQ,KAA4B,IAAI,OAAM,CAAE,KAAK,KAAI;AACvE,QAAO,GAAG,QAAQ,KAAI,GAAI,KAAI;;AAwBzB,IAAM,WAAN,MAAM,iBAAiB,MAAM;;;;;;;CAOlC,OAAc,KAAK,OAAgB,MAA6B;AAC9D,MAAI,iBAAiB,SAAU,QAAO;EAEtC,MAAM,gBAAgB,2BAAA,iBAAiB,MAAK;EAC5C,MAAM,UAAU,gBACZ,oBAAoB,cAAa,GACjC,UAAU,MAAK;AAKnB,SAAO,IAAI,SAAS;GAAE,MAFpB,uBAAA,cAAc,OAAO,cAAa,IAAK,QAAQ,uBAAA,WAAW;GAErB;GAAO;GAAS;GAAe,CAAA;;;CAIjE;;;;;;CAOA;CAQP,YAAY,EAAE,MAAM,OAAO,SAAS,iBAAgC;AAClE,QAAM,QAAO;AACb,OAAK,OAAO;AAIZ,MAAI,UAAU,KAAA,EACZ,MAAK,QAAQ;AAEf,MAAI,iBAAiB,SAAS,MAAM,MAClC,MAAK,QAAQ,MAAM;AAErB,OAAK,OAAO,QAAQ,uBAAA,WAAW;AAC/B,OAAK,gBAAgB;;;;;;;;CASvB,IAAW,eAAmC;AAC5C,SAAO,KAAK,WAAW,KAAA;;;AASpB,SAAS,UACd,WACA,SACA,MACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE;EAAS;EAAM,CAAA;;AAQ/B,SAAS,kBACd,WACA,SACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE,MAAM,uBAAA,WAAW;EAAkB;EAAS,CAAA;;AAO5D,MAAM,eAAe,OAC1B,MACA,SACqB;AACrB,KAAI;AACF,SAAO,MAAM;UACN,OAAO;AACd,QAAM,SAAS,KAAK,OAAO,KAAI"}
@@ -63,6 +63,13 @@ declare class SDKError extends Error {
63
63
  message,
64
64
  decodedRevert
65
65
  }: SDKErrorProps);
66
+ /**
67
+ * @deprecated Use `message` (the idiomatic `Error` field) instead — this is
68
+ * a thin alias kept for pre-refactor consumers and will be removed in the
69
+ * next major. For structured access to a decoded contract revert, read
70
+ * `decodedRevert` ({ name, args }).
71
+ */
72
+ get errorMessage(): string | undefined;
66
73
  }
67
74
  /**
68
75
  * Assert `condition` is truthy, otherwise throw an `SDKError` with the given
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-error.d.cts","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"mappings":";;;;KAMY,aAAA;EACV,IAAA,GAAO,UAAA;EACP,KAAA;EACA,OAAA;EACA,aAAA,GAAgB,aAAA;AAAA;;;;;;;cAiBL,mBAAA,GAAuB,OAAA,EAAS,aAAA;AAA7C;;;;;AA2BA;;;;;;;;;;;;;;;;AA3BA,cA2Ba,QAAA,SAAiB,KAAA;EAOT;;;;;;EAAA,OAAL,IAAA,CAAK,KAAA,WAAgB,IAAA,GAAO,UAAA,GAAa,QAAA;EAsBjC;EAPf,IAAA,EAAM,UAAA;;;;;;EAON,aAAA,EAAe,aAAA;EAQK;;;;EAFZ,KAAA;;IAED,IAAA;IAAM,KAAA;IAAO,OAAA;IAAS;EAAA,GAAiB,aAAA;AAAA;;;;;iBAsBvC,SAAA,CACd,SAAA,OACA,OAAA,UACA,IAAA,GAAO,UAAA,WACE,SAAA;;;;;iBAWK,iBAAA,CACd,SAAA,OACA,OAAA,mBACS,SAAA;AAHX;;;;AAAA,cAaa,YAAA,YACX,IAAA,EAAM,OAAA,CAAQ,OAAA,GACd,IAAA,GAAO,UAAA,KACN,OAAA,CAAQ,OAAA"}
1
+ {"version":3,"file":"sdk-error.d.cts","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"mappings":";;;;KAMY,aAAA;EACV,IAAA,GAAO,UAAA;EACP,KAAA;EACA,OAAA;EACA,aAAA,GAAgB,aAAA;AAAA;;;;;;;cAiBL,mBAAA,GAAuB,OAAA,EAAS,aAAA;AAA7C;;;;;AA2BA;;;;;;;;;;;;;;;;AA3BA,cA2Ba,QAAA,SAAiB,KAAA;EAOT;;;;;;EAAA,OAAL,IAAA,CAAK,KAAA,WAAgB,IAAA,GAAO,UAAA,GAAa,QAAA;EAsBjC;EAPf,IAAA,EAAM,UAAA;;;;;;EAON,aAAA,EAAe,aAAA;EAQK;;;;EAFZ,KAAA;;IAED,IAAA;IAAM,KAAA;IAAO,OAAA;IAAS;EAAA,GAAiB,aAAA;EAsB9B;AAUzB;;;;;EAVyB,IAAZ,YAAA,CAAA;AAAA;;;;;iBAUG,SAAA,CACd,SAAA,OACA,OAAA,UACA,IAAA,GAAO,UAAA,WACE,SAAA;;;;;iBAWK,iBAAA,CACd,SAAA,OACA,OAAA,mBACS,SAAA;;;;AAUX;cAAa,YAAA,YACX,IAAA,EAAM,OAAA,CAAQ,OAAA,GACd,IAAA,GAAO,UAAA,KACN,OAAA,CAAQ,OAAA"}
@@ -63,6 +63,13 @@ declare class SDKError extends Error {
63
63
  message,
64
64
  decodedRevert
65
65
  }: SDKErrorProps);
66
+ /**
67
+ * @deprecated Use `message` (the idiomatic `Error` field) instead — this is
68
+ * a thin alias kept for pre-refactor consumers and will be removed in the
69
+ * next major. For structured access to a decoded contract revert, read
70
+ * `decodedRevert` ({ name, args }).
71
+ */
72
+ get errorMessage(): string | undefined;
66
73
  }
67
74
  /**
68
75
  * Assert `condition` is truthy, otherwise throw an `SDKError` with the given
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-error.d.mts","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"mappings":";;;;KAMY,aAAA;EACV,IAAA,GAAO,UAAA;EACP,KAAA;EACA,OAAA;EACA,aAAA,GAAgB,aAAA;AAAA;;;;;;;cAiBL,mBAAA,GAAuB,OAAA,EAAS,aAAA;AAA7C;;;;;AA2BA;;;;;;;;;;;;;;;;AA3BA,cA2Ba,QAAA,SAAiB,KAAA;EAOT;;;;;;EAAA,OAAL,IAAA,CAAK,KAAA,WAAgB,IAAA,GAAO,UAAA,GAAa,QAAA;EAsBjC;EAPf,IAAA,EAAM,UAAA;;;;;;EAON,aAAA,EAAe,aAAA;EAQK;;;;EAFZ,KAAA;;IAED,IAAA;IAAM,KAAA;IAAO,OAAA;IAAS;EAAA,GAAiB,aAAA;AAAA;;;;;iBAsBvC,SAAA,CACd,SAAA,OACA,OAAA,UACA,IAAA,GAAO,UAAA,WACE,SAAA;;;;;iBAWK,iBAAA,CACd,SAAA,OACA,OAAA,mBACS,SAAA;AAHX;;;;AAAA,cAaa,YAAA,YACX,IAAA,EAAM,OAAA,CAAQ,OAAA,GACd,IAAA,GAAO,UAAA,KACN,OAAA,CAAQ,OAAA"}
1
+ {"version":3,"file":"sdk-error.d.mts","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"mappings":";;;;KAMY,aAAA;EACV,IAAA,GAAO,UAAA;EACP,KAAA;EACA,OAAA;EACA,aAAA,GAAgB,aAAA;AAAA;;;;;;;cAiBL,mBAAA,GAAuB,OAAA,EAAS,aAAA;AAA7C;;;;;AA2BA;;;;;;;;;;;;;;;;AA3BA,cA2Ba,QAAA,SAAiB,KAAA;EAOT;;;;;;EAAA,OAAL,IAAA,CAAK,KAAA,WAAgB,IAAA,GAAO,UAAA,GAAa,QAAA;EAsBjC;EAPf,IAAA,EAAM,UAAA;;;;;;EAON,aAAA,EAAe,aAAA;EAQK;;;;EAFZ,KAAA;;IAED,IAAA;IAAM,KAAA;IAAO,OAAA;IAAS;EAAA,GAAiB,aAAA;EAsB9B;AAUzB;;;;;EAVyB,IAAZ,YAAA,CAAA;AAAA;;;;;iBAUG,SAAA,CACd,SAAA,OACA,OAAA,UACA,IAAA,GAAO,UAAA,WACE,SAAA;;;;;iBAWK,iBAAA,CACd,SAAA,OACA,OAAA,mBACS,SAAA;;;;AAUX;cAAa,YAAA,YACX,IAAA,EAAM,OAAA,CAAQ,OAAA,GACd,IAAA,GAAO,UAAA,KACN,OAAA,CAAQ,OAAA"}
@@ -42,6 +42,15 @@ var SDKError = class SDKError extends Error {
42
42
  this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;
43
43
  this.decodedRevert = decodedRevert;
44
44
  }
45
+ /**
46
+ * @deprecated Use `message` (the idiomatic `Error` field) instead — this is
47
+ * a thin alias kept for pre-refactor consumers and will be removed in the
48
+ * next major. For structured access to a decoded contract revert, read
49
+ * `decodedRevert` ({ name, args }).
50
+ */
51
+ get errorMessage() {
52
+ return this.message || void 0;
53
+ }
45
54
  };
46
55
  function invariant(condition, message, code) {
47
56
  if (condition) return;
@@ -1 +1 @@
1
- {"version":3,"file":"sdk-error.mjs","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"sourcesContent":["import { classifyError } from './classify-error';\nimport { type DecodedRevert, decodeRevertData } from './decode-revert-data';\nimport { ERROR_CODE } from './sdk-error-code';\n\nexport { ERROR_CODE } from './sdk-error-code';\n\nexport type SDKErrorProps = {\n code?: ERROR_CODE;\n error?: unknown;\n message?: string;\n decodedRevert?: DecodedRevert;\n};\n\nconst messageOf = (error: unknown): string =>\n typeof error === 'object' &&\n error !== null &&\n 'message' in error &&\n typeof error.message === 'string'\n ? error.message\n : 'something went wrong';\n\n/**\n * Canonical `Name(arg1, arg2, ...)` label for a decoded contract revert.\n * Falls back to bare `Name` when the error has no args. Exposed so consumers\n * with a raw `decodedRevert` (e.g. from logs) can render the same string the\n * SDK uses as `Error.message`.\n */\nexport const formatDecodedRevert = (decoded: DecodedRevert): string => {\n if (!decoded.args.length) return decoded.name;\n const args = (decoded.args as readonly unknown[]).map(String).join(', ');\n return `${decoded.name}(${args})`;\n};\n\n/**\n * Typed wrapper around every error thrown by the SDK. Invariants:\n * - `code` is always set (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n * - `cause` preserves the original upstream error (typically a viem\n * `BaseError`) so consumers can walk the chain.\n * - `decodedRevert` is present iff the underlying error carried a custom\n * error selector decodable against the SDK's known ABIs.\n *\n * Branch on `code` for wallet / network conditions; narrow on\n * `decodedRevert.name` for typed contract revert args.\n *\n * @example\n * try { await sdk.bond.claimBondStETH(...) } catch (e) {\n * if (!(e instanceof SDKError)) throw e;\n * if (e.code === ERROR_CODE.USER_REJECTED) return;\n * if (e.decodedRevert?.name === 'AccessControlUnauthorizedAccount') {\n * const [account, role] = e.decodedRevert.args; // typed tuple\n * showRoleErrorToast(account, role);\n * }\n * }\n */\nexport class SDKError extends Error {\n /**\n * Wrap any thrown value into an `SDKError`. Pass `code` as a context hint\n * (e.g. `TRANSACTION_ERROR`); it is only used when {@link classifyError}\n * yields nothing. The classifier always wins because viem class detection\n * is strictly more specific than a context code.\n */\n public static from(error: unknown, code?: ERROR_CODE): SDKError {\n if (error instanceof SDKError) return error;\n\n const decodedRevert = decodeRevertData(error);\n const message = decodedRevert\n ? formatDecodedRevert(decodedRevert)\n : messageOf(error);\n\n const finalCode =\n classifyError(error, decodedRevert) ?? code ?? ERROR_CODE.UNKNOWN_ERROR;\n\n return new SDKError({ code: finalCode, error, message, decodedRevert });\n }\n\n /** Classified error category. Always set. See {@link ERROR_CODE}. */\n public code: ERROR_CODE;\n\n /**\n * Decoded contract revert, when the upstream error carried a selector\n * decodable against the SDK's combined ABI. Discriminated union: narrow on\n * `name` to get a typed `args` tuple.\n */\n public decodedRevert: DecodedRevert | undefined;\n\n /**\n * Original upstream error (typically a viem `BaseError`). Inherited from\n * `Error.cause`. Walk via `e.cause` to inspect the full chain.\n */\n declare public cause?: unknown;\n\n constructor({ code, error, message, decodedRevert }: SDKErrorProps) {\n super(message);\n this.name = 'SDKError';\n // Preserve full upstream error as `cause` — consumers walk it via the\n // standard Error chain. Previous code assigned `error.cause` and silently\n // dropped the top viem BaseError.\n if (error !== undefined) {\n this.cause = error;\n }\n if (error instanceof Error && error.stack) {\n this.stack = error.stack;\n }\n this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;\n this.decodedRevert = decodedRevert;\n }\n}\n\n/**\n * Assert `condition` is truthy, otherwise throw an `SDKError` with the given\n * `message` and optional `code` (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n */\n// eslint-disable-next-line func-style\nexport function invariant(\n condition: any,\n message: string,\n code?: ERROR_CODE,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ message, code });\n}\n\n/**\n * Shortcut for argument validation: throws with\n * {@link ERROR_CODE.INVALID_ARGUMENT}.\n */\n// eslint-disable-next-line func-style\nexport function invariantArgument(\n condition: any,\n message: string,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });\n}\n\n/**\n * Await `func`; on rejection, rethrow as `SDKError.from(error, code)`.\n * `code` is a context fallback — the classifier still wins when it matches.\n */\nexport const withSDKError = async <TResult>(\n func: Promise<TResult>,\n code?: ERROR_CODE,\n): Promise<TResult> => {\n try {\n return await func;\n } catch (error) {\n throw SDKError.from(error, code);\n }\n};\n"],"mappings":";;;;AAaA,MAAM,aAAa,UACjB,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,WACrB,MAAM,UACN;AAQC,MAAM,uBAAuB,YAAmC;AACrE,KAAI,CAAC,QAAQ,KAAK,OAAQ,QAAO,QAAQ;CACzC,MAAM,OAAQ,QAAQ,KAA4B,IAAI,OAAM,CAAE,KAAK,KAAI;AACvE,QAAO,GAAG,QAAQ,KAAI,GAAI,KAAI;;AAwBzB,IAAM,WAAN,MAAM,iBAAiB,MAAM;;;;;;;CAOlC,OAAc,KAAK,OAAgB,MAA6B;AAC9D,MAAI,iBAAiB,SAAU,QAAO;EAEtC,MAAM,gBAAgB,iBAAiB,MAAK;EAC5C,MAAM,UAAU,gBACZ,oBAAoB,cAAa,GACjC,UAAU,MAAK;AAKnB,SAAO,IAAI,SAAS;GAAE,MAFpB,cAAc,OAAO,cAAa,IAAK,QAAQ,WAAW;GAErB;GAAO;GAAS;GAAe,CAAA;;;CAIjE;;;;;;CAOA;CAQP,YAAY,EAAE,MAAM,OAAO,SAAS,iBAAgC;AAClE,QAAM,QAAO;AACb,OAAK,OAAO;AAIZ,MAAI,UAAU,KAAA,EACZ,MAAK,QAAQ;AAEf,MAAI,iBAAiB,SAAS,MAAM,MAClC,MAAK,QAAQ,MAAM;AAErB,OAAK,OAAO,QAAQ,WAAW;AAC/B,OAAK,gBAAgB;;;AASlB,SAAS,UACd,WACA,SACA,MACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE;EAAS;EAAM,CAAA;;AAQ/B,SAAS,kBACd,WACA,SACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE,MAAM,WAAW;EAAkB;EAAS,CAAA;;AAO5D,MAAM,eAAe,OAC1B,MACA,SACqB;AACrB,KAAI;AACF,SAAO,MAAM;UACN,OAAO;AACd,QAAM,SAAS,KAAK,OAAO,KAAI"}
1
+ {"version":3,"file":"sdk-error.mjs","names":[],"sources":["../../../src/common/utils/sdk-error.ts"],"sourcesContent":["import { classifyError } from './classify-error';\nimport { type DecodedRevert, decodeRevertData } from './decode-revert-data';\nimport { ERROR_CODE } from './sdk-error-code';\n\nexport { ERROR_CODE } from './sdk-error-code';\n\nexport type SDKErrorProps = {\n code?: ERROR_CODE;\n error?: unknown;\n message?: string;\n decodedRevert?: DecodedRevert;\n};\n\nconst messageOf = (error: unknown): string =>\n typeof error === 'object' &&\n error !== null &&\n 'message' in error &&\n typeof error.message === 'string'\n ? error.message\n : 'something went wrong';\n\n/**\n * Canonical `Name(arg1, arg2, ...)` label for a decoded contract revert.\n * Falls back to bare `Name` when the error has no args. Exposed so consumers\n * with a raw `decodedRevert` (e.g. from logs) can render the same string the\n * SDK uses as `Error.message`.\n */\nexport const formatDecodedRevert = (decoded: DecodedRevert): string => {\n if (!decoded.args.length) return decoded.name;\n const args = (decoded.args as readonly unknown[]).map(String).join(', ');\n return `${decoded.name}(${args})`;\n};\n\n/**\n * Typed wrapper around every error thrown by the SDK. Invariants:\n * - `code` is always set (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n * - `cause` preserves the original upstream error (typically a viem\n * `BaseError`) so consumers can walk the chain.\n * - `decodedRevert` is present iff the underlying error carried a custom\n * error selector decodable against the SDK's known ABIs.\n *\n * Branch on `code` for wallet / network conditions; narrow on\n * `decodedRevert.name` for typed contract revert args.\n *\n * @example\n * try { await sdk.bond.claimBondStETH(...) } catch (e) {\n * if (!(e instanceof SDKError)) throw e;\n * if (e.code === ERROR_CODE.USER_REJECTED) return;\n * if (e.decodedRevert?.name === 'AccessControlUnauthorizedAccount') {\n * const [account, role] = e.decodedRevert.args; // typed tuple\n * showRoleErrorToast(account, role);\n * }\n * }\n */\nexport class SDKError extends Error {\n /**\n * Wrap any thrown value into an `SDKError`. Pass `code` as a context hint\n * (e.g. `TRANSACTION_ERROR`); it is only used when {@link classifyError}\n * yields nothing. The classifier always wins because viem class detection\n * is strictly more specific than a context code.\n */\n public static from(error: unknown, code?: ERROR_CODE): SDKError {\n if (error instanceof SDKError) return error;\n\n const decodedRevert = decodeRevertData(error);\n const message = decodedRevert\n ? formatDecodedRevert(decodedRevert)\n : messageOf(error);\n\n const finalCode =\n classifyError(error, decodedRevert) ?? code ?? ERROR_CODE.UNKNOWN_ERROR;\n\n return new SDKError({ code: finalCode, error, message, decodedRevert });\n }\n\n /** Classified error category. Always set. See {@link ERROR_CODE}. */\n public code: ERROR_CODE;\n\n /**\n * Decoded contract revert, when the upstream error carried a selector\n * decodable against the SDK's combined ABI. Discriminated union: narrow on\n * `name` to get a typed `args` tuple.\n */\n public decodedRevert: DecodedRevert | undefined;\n\n /**\n * Original upstream error (typically a viem `BaseError`). Inherited from\n * `Error.cause`. Walk via `e.cause` to inspect the full chain.\n */\n declare public cause?: unknown;\n\n constructor({ code, error, message, decodedRevert }: SDKErrorProps) {\n super(message);\n this.name = 'SDKError';\n // Preserve full upstream error as `cause` — consumers walk it via the\n // standard Error chain. Previous code assigned `error.cause` and silently\n // dropped the top viem BaseError.\n if (error !== undefined) {\n this.cause = error;\n }\n if (error instanceof Error && error.stack) {\n this.stack = error.stack;\n }\n this.code = code ?? ERROR_CODE.UNKNOWN_ERROR;\n this.decodedRevert = decodedRevert;\n }\n\n /**\n * @deprecated Use `message` (the idiomatic `Error` field) instead — this is\n * a thin alias kept for pre-refactor consumers and will be removed in the\n * next major. For structured access to a decoded contract revert, read\n * `decodedRevert` ({ name, args }).\n */\n public get errorMessage(): string | undefined {\n return this.message || undefined;\n }\n}\n\n/**\n * Assert `condition` is truthy, otherwise throw an `SDKError` with the given\n * `message` and optional `code` (defaults to {@link ERROR_CODE.UNKNOWN_ERROR}).\n */\n// eslint-disable-next-line func-style\nexport function invariant(\n condition: any,\n message: string,\n code?: ERROR_CODE,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ message, code });\n}\n\n/**\n * Shortcut for argument validation: throws with\n * {@link ERROR_CODE.INVALID_ARGUMENT}.\n */\n// eslint-disable-next-line func-style\nexport function invariantArgument(\n condition: any,\n message: string,\n): asserts condition {\n if (condition) return;\n\n throw new SDKError({ code: ERROR_CODE.INVALID_ARGUMENT, message });\n}\n\n/**\n * Await `func`; on rejection, rethrow as `SDKError.from(error, code)`.\n * `code` is a context fallback — the classifier still wins when it matches.\n */\nexport const withSDKError = async <TResult>(\n func: Promise<TResult>,\n code?: ERROR_CODE,\n): Promise<TResult> => {\n try {\n return await func;\n } catch (error) {\n throw SDKError.from(error, code);\n }\n};\n"],"mappings":";;;;AAaA,MAAM,aAAa,UACjB,OAAO,UAAU,YACjB,UAAU,QACV,aAAa,SACb,OAAO,MAAM,YAAY,WACrB,MAAM,UACN;AAQC,MAAM,uBAAuB,YAAmC;AACrE,KAAI,CAAC,QAAQ,KAAK,OAAQ,QAAO,QAAQ;CACzC,MAAM,OAAQ,QAAQ,KAA4B,IAAI,OAAM,CAAE,KAAK,KAAI;AACvE,QAAO,GAAG,QAAQ,KAAI,GAAI,KAAI;;AAwBzB,IAAM,WAAN,MAAM,iBAAiB,MAAM;;;;;;;CAOlC,OAAc,KAAK,OAAgB,MAA6B;AAC9D,MAAI,iBAAiB,SAAU,QAAO;EAEtC,MAAM,gBAAgB,iBAAiB,MAAK;EAC5C,MAAM,UAAU,gBACZ,oBAAoB,cAAa,GACjC,UAAU,MAAK;AAKnB,SAAO,IAAI,SAAS;GAAE,MAFpB,cAAc,OAAO,cAAa,IAAK,QAAQ,WAAW;GAErB;GAAO;GAAS;GAAe,CAAA;;;CAIjE;;;;;;CAOA;CAQP,YAAY,EAAE,MAAM,OAAO,SAAS,iBAAgC;AAClE,QAAM,QAAO;AACb,OAAK,OAAO;AAIZ,MAAI,UAAU,KAAA,EACZ,MAAK,QAAQ;AAEf,MAAI,iBAAiB,SAAS,MAAM,MAClC,MAAK,QAAQ,MAAM;AAErB,OAAK,OAAO,QAAQ,WAAW;AAC/B,OAAK,gBAAgB;;;;;;;;CASvB,IAAW,eAAmC;AAC5C,SAAO,KAAK,WAAW,KAAA;;;AASpB,SAAS,UACd,WACA,SACA,MACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE;EAAS;EAAM,CAAA;;AAQ/B,SAAS,kBACd,WACA,SACmB;AACnB,KAAI,UAAW;AAEf,OAAM,IAAI,SAAS;EAAE,MAAM,WAAW;EAAkB;EAAS,CAAA;;AAO5D,MAAM,eAAe,OAC1B,MACA,SACqB;AACrB,KAAI;AACF,SAAO,MAAM;UACN,OAAO;AACd,QAAM,SAAS,KAAK,OAAO,KAAI"}