@gala-chain/gswap-sdk 2.1.0-beta.0 → 2.1.0-beta.2
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 +6 -0
- package/dist/browser/classes/gswap_error_catalog.js +1 -1
- package/dist/browser/classes/gswap_error_catalog.js.map +1 -1
- package/dist/browser/classes/gswap_error_phase_table.js +1 -1
- package/dist/browser/classes/gswap_error_phase_table.js.map +1 -1
- package/dist/browser/classes/gswap_sdk_error.js +1 -1
- package/dist/browser/classes/gswap_sdk_error.js.map +1 -1
- package/dist/browser/utils/failure_classification.js +1 -1
- package/dist/browser/utils/failure_classification.js.map +1 -1
- package/dist/browser/utils/failure_guards.js +1 -1
- package/dist/browser/utils/failure_guards.js.map +1 -1
- package/dist/index.cjs +10 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.mjs +10 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"failure_guards.js","names":["isUniqueKeyConsumed","view","toFailureView","error","UNPROVEN_ACKNOWLEDGEMENT_CODES","isUnprovenAcknowledgement","hasCodeIn","isCodeIn","codes","known","code","RELAYABLE_REFUSAL_CODES","isRelayableRefusal","isUninterpretedAnswer","chainErrorKeyOf","errorKey","stringParamOf","NO_MARKET_CODES","isNoMarket","isWriteView"],"sources":["../../../src/utils/failure_guards.ts"],"sourcesContent":["import { isWriteView, stringParamOf, toFailureView } from '@gala-chain/gala-core-sdk';\nimport type { GSwapErrorCode } from '../classes/gswap_error_catalog.js';\nimport type { GSwapSDKError } from '../classes/gswap_sdk_error.js';\n\n/**\n * The yes/no questions an app asks about a failure from its CODE alone. They read only the failure\n * view and a short list of codes: no table of every code (that is `classifyFailure`'s, in\n * `failure_classification.ts`), no error class and no catalog (the imports above are types, erased\n * at build time). An app shell that imports one of them pays for this module and nothing else.\n */\n\n/**\n * True when the gateway answered that the write's `uniqueKey` was ALREADY CONSUMED: a\n * `CHAIN_DISPATCH_FAILED` with HTTP status 409. The first attempt under that key may be applied\n * (`classifyFailure` says `unknown`), so the app confirms the key it holds instead of submitting\n * again or showing the server's text. It replaces `error.code === 'CHAIN_DISPATCH_FAILED' &&\n * error.status === 409` and the regex on \"already saved\". Accepts an SDK error or a plain-object\n * view ({@link FailureView}: `code` and `status`); every other value is `false`.\n *\n * @example\n * ```ts\n * if (isUniqueKeyConsumed(error)) return confirmAndShowResult(error.uniqueKey);\n * ```\n */\nexport function isUniqueKeyConsumed(error: unknown): boolean {\n const view = toFailureView(error);\n return view?.code === 'CHAIN_DISPATCH_FAILED' && view.status === 409;\n}\n\nconst UNPROVEN_ACKNOWLEDGEMENT_CODES: readonly GSwapErrorCode[] = [\n 'GATEWAY_DATA_MISSING',\n 'GATEWAY_MODE_INVALID',\n 'GATEWAY_SYNC_REQUEST_TRADE',\n 'MISSING_UNIQUE_KEY',\n 'UNIQUE_KEY_MISMATCH',\n];\n\n/**\n * True when a write got a 2xx answer that does NOT prove it was queued under the signed key: no\n * `data`, an unreadable `mode`, a synchronous RequestTrade, or a missing or foreign `uniqueKey`.\n * The outcome is `unknown` (it may have been queued: confirm `error.uniqueKey`), and the copy an\n * app shows is one line for all five (\"the backend did not confirm it queued the request\"), so\n * the app asks this instead of keeping its own list of the codes. A gateway that says\n * `error: true` (`GATEWAY_REPORTED_ERROR`) is a refusal with its own message, not in this set.\n *\n * @example\n * ```ts\n * if (isUnprovenAcknowledgement(error)) keepPendingAndConfirm(error.uniqueKey);\n * ```\n */\nexport function isUnprovenAcknowledgement(error: unknown): boolean {\n return hasCodeIn(error, UNPROVEN_ACKNOWLEDGEMENT_CODES);\n}\n\n/** True when `code` is one of `codes` (a list of catalog codes), by exact spelling. */\nfunction isCodeIn(code: string, codes: readonly GSwapErrorCode[]): boolean {\n return codes.some((known) => known === code);\n}\n\n/**\n * True when `error` is an SDK error OR a plain-object view of one (see {@link FailureView}) whose\n * `code` is one of `codes`. The code is compared with the catalog's own spelling, so a wallet\n * error (`{ code: 'ACTION_REJECTED' }`, a numeric `4001`) is never a member.\n */\nfunction hasCodeIn(error: unknown, codes: readonly GSwapErrorCode[]): boolean {\n const view = toFailureView(error);\n // `codes` holds catalog codes only, so membership already means \"a catalog code\": no table needed.\n return view !== undefined && isCodeIn(view.code, codes);\n}\n\n/**\n * The codes whose `params.serverMessage` is the gateway's own answer to THIS write, which an app\n * may show as it is (and falls back to its own line when it is empty): a refusal the gateway made\n * (`GATEWAY_REPORTED_ERROR`, a 2xx with `error: true`) or a bounce it named (the gateway codes the\n * SDK knows, and `GATEWAY_REJECTED` for one it does not).\n */\nconst RELAYABLE_REFUSAL_CODES: readonly GSwapErrorCode[] = [\n 'GATEWAY_REPORTED_ERROR',\n 'METHOD_NOT_ALLOWED',\n 'SIGNATURE_INVALID',\n 'SIGNER_MISMATCH',\n 'DTO_INVALID',\n 'BOUNDS_VIOLATION',\n 'SYMBOL_CONFLICT',\n 'RATE_LIMITED',\n 'CHAIN_DISPATCH_FAILED',\n 'GATEWAY_REJECTED',\n];\n\n/**\n * True when the error is a gateway refusal whose `params.serverMessage` an app may relay to the\n * person as the gateway sent it: `GATEWAY_REPORTED_ERROR`, the gateway bounces (`METHOD_NOT_ALLOWED`,\n * `SIGNATURE_INVALID`, `SIGNER_MISMATCH`, `DTO_INVALID`, `BOUNDS_VIOLATION`, `SYMBOL_CONFLICT`,\n * `RATE_LIMITED`, `GATEWAY_REJECTED`) and `CHAIN_DISPATCH_FAILED`. The app shows `serverMessage` when\n * it is not empty and its own line when it is; the SDK's English `message` is never what to show.\n *\n * It accepts a plain-object view of an SDK error too ({@link FailureView}: an app's wrapper with a\n * `code`), and decides from the code in the same way. It narrows to `GSwapSDKError<...>` ONLY when\n * called with an SDK error; with an `unknown` or a view it answers `boolean` (narrow with\n * `isGSwapError` first, or read the view's own `params`).\n *\n * It is a test on the code alone, so it also holds for `CHAIN_DISPATCH_FAILED` with HTTP 409\n * (the `uniqueKey` was already consumed; `classifyFailure` says `unknown`): an app that words that\n * case itself (\"already submitted\", then confirm the key) checks `error.status === 409` BEFORE\n * relaying. It is false for `CHAIN_REJECTED` (the chain's verdict, worded by where it is shown: the\n * submit and confirm screens differ), for `HTTP_ERROR` (a proxy's page, not an answer to this\n * write) and for the five unproven acknowledgements (`isUnprovenAcknowledgement`: they carry no\n * server text).\n *\n * @example\n * ```ts\n * if (isRelayableRefusal(error)) show(error.params.serverMessage || t('swap.requestFailed'));\n * ```\n */\nexport function isRelayableRefusal(error: GSwapSDKError): error is GSwapSDKError<RelayableCode>;\nexport function isRelayableRefusal(error: unknown): boolean;\nexport function isRelayableRefusal(error: unknown): boolean {\n return hasCodeIn(error, RELAYABLE_REFUSAL_CODES);\n}\n\n/** The codes {@link isRelayableRefusal} is true for. */\nexport type RelayableCode =\n | 'GATEWAY_REPORTED_ERROR'\n | 'METHOD_NOT_ALLOWED'\n | 'SIGNATURE_INVALID'\n | 'SIGNER_MISMATCH'\n | 'DTO_INVALID'\n | 'BOUNDS_VIOLATION'\n | 'SYMBOL_CONFLICT'\n | 'RATE_LIMITED'\n | 'CHAIN_DISPATCH_FAILED'\n | 'GATEWAY_REJECTED';\n\n/**\n * True when a write got a 2xx answer the SDK refused to interpret, so the answer itself is in\n * `error.body` (or `error.bodyText`) for the app to read: the five unproven acknowledgements\n * (`isUnprovenAcknowledgement`) and `GATEWAY_REPORTED_ERROR` (a gateway that says `error: true`).\n * The outcome is `unknown` for all six. It replaces the app's own\n * `isUnprovenAcknowledgement(e) || isGSwapError(e, 'GATEWAY_REPORTED_ERROR')` pair.\n */\nexport function isUninterpretedAnswer(error: unknown): boolean {\n return isUnprovenAcknowledgement(error) || hasCodeIn(error, ['GATEWAY_REPORTED_ERROR']);\n}\n\n/**\n * The chain's own machine-readable `ErrorKey` of a failure (`'TOKEN_NOT_FOUND'`,\n * `'NOT_ENOUGH_LIQUIDITY'`, ...), for an app that maps a chain refusal to its own copy: the\n * `params.errorKey` of a `CHAIN_REJECTED` (an apply result, or a body that carries the chain's\n * error) and of a `CHAIN_DISPATCH_FAILED` (the gateway adds the chain's key to the body it\n * answered). `undefined` when the failure is neither, or when it carries no key (the gateway sent\n * none: the SDK writes `''`, which is not a key). Map the KEY, never the message text.\n *\n * Accepts an SDK error or a plain-object view ({@link FailureView}: `code` and `params`); every\n * other value is `undefined`. Other codes are `undefined` even when they have an `errorKey`-named\n * param, so a stray field cannot pass for a chain verdict.\n *\n * @example\n * ```ts\n * const key = chainErrorKeyOf(error);\n * if (key === 'NOT_ENOUGH_LIQUIDITY') showTooThin(); else showGeneric(error);\n * ```\n */\nexport function chainErrorKeyOf(error: unknown): string | undefined {\n const view = toFailureView(error);\n if (view === undefined) return undefined;\n if (view.code !== 'CHAIN_REJECTED' && view.code !== 'CHAIN_DISPATCH_FAILED') return undefined;\n const errorKey = stringParamOf(view, 'errorKey');\n return errorKey === undefined || errorKey === '' ? undefined : errorKey;\n}\n\n/** Codes that mean \"there is no market for this\" however the app reached them. */\nconst NO_MARKET_CODES: readonly GSwapErrorCode[] = [\n 'NO_POOL_AVAILABLE',\n 'INSUFFICIENT_LIQUIDITY',\n 'UNKNOWN_TOKEN',\n];\n\n/**\n * True when a failure means \"there is no market to trade this pair\": `NO_POOL_AVAILABLE` (no pool\n * at any fee tier), `INSUFFICIENT_LIQUIDITY` (a pool too thin to quote), `UNKNOWN_TOKEN` (the DEX\n * has no trading symbol for the token), or a READ that was answered 404 (a quote the backend\n * cannot find, `error.notFound`). It replaces an app's own `code === ... || code === ... ||\n * notFound` list, so the empty-state (\"No market for this pair\") has one definition.\n *\n * A write that was answered 404 (it carries a `uniqueKey`) is a missing route, not a missing\n * market, and is not this. Accepts an SDK error or a plain-object view ({@link FailureView}); every\n * other value is `false`.\n *\n * @example\n * ```ts\n * if (isNoMarket(error)) showEmptyState(t('swap.noMarket')); else showError(error);\n * ```\n */\nexport function isNoMarket(error: unknown): boolean {\n const view = toFailureView(error);\n if (view === undefined) return false;\n if (isCodeIn(view.code, NO_MARKET_CODES)) return true;\n return !isWriteView(view) && (view.notFound === true || view.status === 404);\n}\n"],"mappings":"A,8FAwBA,SAAgBA,EAAoB,EAAyB,CAC3D,IAAMC,EAAOC,EAAcC,CAAK,EAChC,OAAOF,GAAM,OAAS,yBAA2BA,EAAK,SAAW,GACnE,CAEA,MAAMG,EAA4D,CAChE,uBACA,uBACA,6BACA,qBACA,qBACF,EAeA,SAAgBC,EAA0B,EAAyB,CACjE,OAAOC,EAAUH,EAAOC,CAA8B,CACxD,CAGA,SAASG,EAAS,EAAc,EAA2C,CACzE,OAAOC,EAAM,KAAM,GAAUC,IAAUC,CAAI,CAC7C,CAOA,SAASJ,EAAU,EAAgB,EAA2C,CAC5E,IAAML,EAAOC,EAAcC,CAAK,EAEhC,OAAOF,IAAS,IAAA,IAAaM,EAASN,EAAK,KAAMO,CAAK,CACxD,CAQA,MAAMG,EAAqD,CACzD,yBACA,qBACA,oBACA,kBACA,cACA,mBACA,kBACA,eACA,wBACA,kBACF,EA6BA,SAAgBC,EAAmB,EAAyB,CAC1D,OAAON,EAAUH,EAAOQ,CAAuB,CACjD,CAsBA,SAAgBE,EAAsB,EAAyB,CAC7D,OAAOR,EAA0BF,CAAK,GAAKG,EAAUH,EAAO,CAAC,wBAAwB,CAAC,CACxF,CAoBA,SAAgBW,EAAgB,EAAoC,CAClE,IAAMb,EAAOC,EAAcC,CAAK,EAEhC,GADIF,IAAS,IAAA,IACTA,EAAK,OAAS,kBAAoBA,EAAK,OAAS,wBAAyB,OAC7E,IAAMc,EAAWC,EAAcf,EAAM,UAAU,EAC/C,OAAOc,IAAa,IAAA,IAAaA,IAAa,GAAK,IAAA,GAAYA,CACjE,CAGA,MAAME,EAA6C,CACjD,oBACA,yBACA,eACF,EAkBA,SAAgBC,EAAW,EAAyB,CAClD,IAAMjB,EAAOC,EAAcC,CAAK,EAGhC,OAFIF,IAAS,IAAA,GAAkB,GAC3BM,EAASN,EAAK,KAAMgB,CAAe,EAAU,GAC1C,CAACE,EAAYlB,CAAI,IAAMA,EAAK,WAAa,IAAQA,EAAK,SAAW,IAC1E,C"}
|
|
1
|
+
{"version":3,"file":"failure_guards.js","names":["isUniqueKeyConsumed","view","toFailureView","error","UNPROVEN_ACKNOWLEDGEMENT_CODES","isUnprovenAcknowledgement","hasCodeIn","isCodeIn","codes","known","code","RELAYABLE_REFUSAL_CODES","isRelayableRefusal","isUninterpretedAnswer","chainErrorKeyOf","errorKey","stringParamOf","NO_MARKET_CODES","isNoMarket","isWriteView"],"sources":["../../../src/utils/failure_guards.ts"],"sourcesContent":["import { isWriteView, stringParamOf, toFailureView } from '@gala-chain/gala-core-sdk';\nimport type { GSwapErrorCode } from '../classes/gswap_error_catalog.js';\nimport type { GSwapSDKError } from '../classes/gswap_sdk_error.js';\n\n/**\n * The yes/no questions an app asks about a failure from its CODE alone. They read only the failure\n * view and a short list of codes: no table of every code (that is `classifyFailure`'s, in\n * `failure_classification.ts`), no error class and no catalog (the imports above are types, erased\n * at build time). An app shell that imports one of them pays for this module and nothing else.\n */\n\n/**\n * True when the gateway answered that the write's `uniqueKey` was ALREADY CONSUMED: a\n * `CHAIN_DISPATCH_FAILED` with HTTP status 409. The first attempt under that key may be applied\n * (`classifyFailure` says `unknown`), so the app confirms the key it holds instead of submitting\n * again or showing the server's text. It replaces `error.code === 'CHAIN_DISPATCH_FAILED' &&\n * error.status === 409` and the regex on \"already saved\". Accepts an SDK error or a plain-object\n * view ({@link FailureView}: `code` and `status`); every other value is `false`.\n *\n * @example\n * ```ts\n * if (isUniqueKeyConsumed(error)) return confirmAndShowResult(error.uniqueKey);\n * ```\n */\nexport function isUniqueKeyConsumed(error: unknown): boolean {\n const view = toFailureView(error);\n return view?.code === 'CHAIN_DISPATCH_FAILED' && view.status === 409;\n}\n\nconst UNPROVEN_ACKNOWLEDGEMENT_CODES: readonly GSwapErrorCode[] = [\n 'GATEWAY_DATA_MISSING',\n 'GATEWAY_MODE_INVALID',\n 'GATEWAY_SYNC_REQUEST_TRADE',\n 'MISSING_UNIQUE_KEY',\n 'UNIQUE_KEY_MISMATCH',\n];\n\n/**\n * True when a write got a 2xx answer that does NOT prove it was queued under the signed key: no\n * `data`, an unreadable `mode`, a synchronous RequestTrade, or a missing or foreign `uniqueKey`.\n * The outcome is `unknown` (it may have been queued: confirm `error.uniqueKey`), and the copy an\n * app shows is one line for all five (\"the backend did not confirm it queued the request\"), so\n * the app asks this instead of keeping its own list of the codes. A gateway that says\n * `error: true` (`GATEWAY_REPORTED_ERROR`) is a refusal with its own message, not in this set.\n *\n * @example\n * ```ts\n * if (isUnprovenAcknowledgement(error)) keepPendingAndConfirm(error.uniqueKey);\n * ```\n */\nexport function isUnprovenAcknowledgement(error: unknown): boolean {\n return hasCodeIn(error, UNPROVEN_ACKNOWLEDGEMENT_CODES);\n}\n\n/** True when `code` is one of `codes` (a list of catalog codes), by exact spelling. */\nfunction isCodeIn(code: string, codes: readonly GSwapErrorCode[]): boolean {\n return codes.some((known) => known === code);\n}\n\n/**\n * True when `error` is an SDK error OR a plain-object view of one (see {@link FailureView}) whose\n * `code` is one of `codes`. The code is compared with the catalog's own spelling, so a wallet\n * error (`{ code: 'ACTION_REJECTED' }`, a numeric `4001`) is never a member.\n */\nfunction hasCodeIn(error: unknown, codes: readonly GSwapErrorCode[]): boolean {\n const view = toFailureView(error);\n // `codes` holds catalog codes only, so membership already means \"a catalog code\": no table needed.\n return view !== undefined && isCodeIn(view.code, codes);\n}\n\n/**\n * The codes whose `params.serverMessage` is the gateway's own answer to THIS write, which an app\n * may show as it is (and falls back to its own line when it is empty): a refusal the gateway made\n * (`GATEWAY_REPORTED_ERROR`, a 2xx with `error: true`) or a bounce it named (the gateway codes the\n * SDK knows, and `GATEWAY_REJECTED` for one it does not).\n */\nconst RELAYABLE_REFUSAL_CODES: readonly GSwapErrorCode[] = [\n 'GATEWAY_REPORTED_ERROR',\n 'METHOD_NOT_ALLOWED',\n 'SIGNATURE_INVALID',\n 'SIGNER_MISMATCH',\n 'DTO_INVALID',\n 'DTO_OPERATION_MISMATCH',\n 'BOUNDS_VIOLATION',\n 'SYMBOL_CONFLICT',\n 'RATE_LIMITED',\n 'CHAIN_DISPATCH_FAILED',\n 'GATEWAY_REJECTED',\n];\n\n/**\n * True when the error is a gateway refusal whose `params.serverMessage` an app may relay to the\n * person as the gateway sent it: `GATEWAY_REPORTED_ERROR`, the gateway bounces (`METHOD_NOT_ALLOWED`,\n * `SIGNATURE_INVALID`, `SIGNER_MISMATCH`, `DTO_INVALID`, `DTO_OPERATION_MISMATCH`, `BOUNDS_VIOLATION`,\n * `SYMBOL_CONFLICT`, `RATE_LIMITED`, `GATEWAY_REJECTED`) and `CHAIN_DISPATCH_FAILED`. The app shows `serverMessage` when\n * it is not empty and its own line when it is; the SDK's English `message` is never what to show.\n *\n * It accepts a plain-object view of an SDK error too ({@link FailureView}: an app's wrapper with a\n * `code`), and decides from the code in the same way. It narrows to `GSwapSDKError<...>` ONLY when\n * called with an SDK error; with an `unknown` or a view it answers `boolean` (narrow with\n * `isGSwapError` first, or read the view's own `params`).\n *\n * It is a test on the code alone, so it also holds for `CHAIN_DISPATCH_FAILED` with HTTP 409\n * (the `uniqueKey` was already consumed; `classifyFailure` says `unknown`): an app that words that\n * case itself (\"already submitted\", then confirm the key) checks `error.status === 409` BEFORE\n * relaying. It is false for `CHAIN_REJECTED` (the chain's verdict, worded by where it is shown: the\n * submit and confirm screens differ), for `HTTP_ERROR` (a proxy's page, not an answer to this\n * write) and for the five unproven acknowledgements (`isUnprovenAcknowledgement`: they carry no\n * server text).\n *\n * @example\n * ```ts\n * if (isRelayableRefusal(error)) show(error.params.serverMessage || t('swap.requestFailed'));\n * ```\n */\nexport function isRelayableRefusal(error: GSwapSDKError): error is GSwapSDKError<RelayableCode>;\nexport function isRelayableRefusal(error: unknown): boolean;\nexport function isRelayableRefusal(error: unknown): boolean {\n return hasCodeIn(error, RELAYABLE_REFUSAL_CODES);\n}\n\n/** The codes {@link isRelayableRefusal} is true for. */\nexport type RelayableCode =\n | 'GATEWAY_REPORTED_ERROR'\n | 'METHOD_NOT_ALLOWED'\n | 'SIGNATURE_INVALID'\n | 'SIGNER_MISMATCH'\n | 'DTO_INVALID'\n | 'DTO_OPERATION_MISMATCH'\n | 'BOUNDS_VIOLATION'\n | 'SYMBOL_CONFLICT'\n | 'RATE_LIMITED'\n | 'CHAIN_DISPATCH_FAILED'\n | 'GATEWAY_REJECTED';\n\n/**\n * True when a write got a 2xx answer the SDK refused to interpret, so the answer itself is in\n * `error.body` (or `error.bodyText`) for the app to read: the five unproven acknowledgements\n * (`isUnprovenAcknowledgement`) and `GATEWAY_REPORTED_ERROR` (a gateway that says `error: true`).\n * The outcome is `unknown` for all six. It replaces the app's own\n * `isUnprovenAcknowledgement(e) || isGSwapError(e, 'GATEWAY_REPORTED_ERROR')` pair.\n */\nexport function isUninterpretedAnswer(error: unknown): boolean {\n return isUnprovenAcknowledgement(error) || hasCodeIn(error, ['GATEWAY_REPORTED_ERROR']);\n}\n\n/**\n * The chain's own machine-readable `ErrorKey` of a failure (`'TOKEN_NOT_FOUND'`,\n * `'NOT_ENOUGH_LIQUIDITY'`, ...), for an app that maps a chain refusal to its own copy: the\n * `params.errorKey` of a `CHAIN_REJECTED` (an apply result, or a body that carries the chain's\n * error) and of a `CHAIN_DISPATCH_FAILED` (the gateway adds the chain's key to the body it\n * answered). `undefined` when the failure is neither, or when it carries no key (the gateway sent\n * none: the SDK writes `''`, which is not a key). Map the KEY, never the message text.\n *\n * Accepts an SDK error or a plain-object view ({@link FailureView}: `code` and `params`); every\n * other value is `undefined`. Other codes are `undefined` even when they have an `errorKey`-named\n * param, so a stray field cannot pass for a chain verdict.\n *\n * @example\n * ```ts\n * const key = chainErrorKeyOf(error);\n * if (key === 'NOT_ENOUGH_LIQUIDITY') showTooThin(); else showGeneric(error);\n * ```\n */\nexport function chainErrorKeyOf(error: unknown): string | undefined {\n const view = toFailureView(error);\n if (view === undefined) return undefined;\n if (view.code !== 'CHAIN_REJECTED' && view.code !== 'CHAIN_DISPATCH_FAILED') return undefined;\n const errorKey = stringParamOf(view, 'errorKey');\n return errorKey === undefined || errorKey === '' ? undefined : errorKey;\n}\n\n/** Codes that mean \"there is no market for this\" however the app reached them. */\nconst NO_MARKET_CODES: readonly GSwapErrorCode[] = [\n 'NO_POOL_AVAILABLE',\n 'INSUFFICIENT_LIQUIDITY',\n 'UNKNOWN_TOKEN',\n];\n\n/**\n * True when a failure means \"there is no market to trade this pair\": `NO_POOL_AVAILABLE` (no pool\n * at any fee tier), `INSUFFICIENT_LIQUIDITY` (a pool too thin to quote), `UNKNOWN_TOKEN` (the DEX\n * has no trading symbol for the token), or a READ that was answered 404 (a quote the backend\n * cannot find, `error.notFound`). It replaces an app's own `code === ... || code === ... ||\n * notFound` list, so the empty-state (\"No market for this pair\") has one definition.\n *\n * A write that was answered 404 (it carries a `uniqueKey`) is a missing route, not a missing\n * market, and is not this. Accepts an SDK error or a plain-object view ({@link FailureView}); every\n * other value is `false`.\n *\n * @example\n * ```ts\n * if (isNoMarket(error)) showEmptyState(t('swap.noMarket')); else showError(error);\n * ```\n */\nexport function isNoMarket(error: unknown): boolean {\n const view = toFailureView(error);\n if (view === undefined) return false;\n if (isCodeIn(view.code, NO_MARKET_CODES)) return true;\n return !isWriteView(view) && (view.notFound === true || view.status === 404);\n}\n"],"mappings":"A,8FAwBA,SAAgBA,EAAoB,EAAyB,CAC3D,IAAMC,EAAOC,EAAcC,CAAK,EAChC,OAAOF,GAAM,OAAS,yBAA2BA,EAAK,SAAW,GACnE,CAEA,MAAMG,EAA4D,CAChE,uBACA,uBACA,6BACA,qBACA,qBACF,EAeA,SAAgBC,EAA0B,EAAyB,CACjE,OAAOC,EAAUH,EAAOC,CAA8B,CACxD,CAGA,SAASG,EAAS,EAAc,EAA2C,CACzE,OAAOC,EAAM,KAAM,GAAUC,IAAUC,CAAI,CAC7C,CAOA,SAASJ,EAAU,EAAgB,EAA2C,CAC5E,IAAML,EAAOC,EAAcC,CAAK,EAEhC,OAAOF,IAAS,IAAA,IAAaM,EAASN,EAAK,KAAMO,CAAK,CACxD,CAQA,MAAMG,EAAqD,CACzD,yBACA,qBACA,oBACA,kBACA,cACA,yBACA,mBACA,kBACA,eACA,wBACA,kBACF,EA6BA,SAAgBC,EAAmB,EAAyB,CAC1D,OAAON,EAAUH,EAAOQ,CAAuB,CACjD,CAuBA,SAAgBE,EAAsB,EAAyB,CAC7D,OAAOR,EAA0BF,CAAK,GAAKG,EAAUH,EAAO,CAAC,wBAAwB,CAAC,CACxF,CAoBA,SAAgBW,EAAgB,EAAoC,CAClE,IAAMb,EAAOC,EAAcC,CAAK,EAEhC,GADIF,IAAS,IAAA,IACTA,EAAK,OAAS,kBAAoBA,EAAK,OAAS,wBAAyB,OAC7E,IAAMc,EAAWC,EAAcf,EAAM,UAAU,EAC/C,OAAOc,IAAa,IAAA,IAAaA,IAAa,GAAK,IAAA,GAAYA,CACjE,CAGA,MAAME,EAA6C,CACjD,oBACA,yBACA,eACF,EAkBA,SAAgBC,EAAW,EAAyB,CAClD,IAAMjB,EAAOC,EAAcC,CAAK,EAGhC,OAFIF,IAAS,IAAA,GAAkB,GAC3BM,EAASN,EAAK,KAAMgB,CAAe,EAAU,GAC1C,CAACE,EAAYlB,CAAI,IAAMA,EAAK,WAAa,IAAQA,EAAK,SAAW,IAC1E,C"}
|
package/dist/index.cjs
CHANGED
|
@@ -252,6 +252,11 @@ const GSWAP_ERROR_CATALOG = {
|
|
|
252
252
|
template: "The gateway rejected the DTO shape: {serverMessage}",
|
|
253
253
|
params: { serverMessage: "string" }
|
|
254
254
|
},
|
|
255
|
+
DTO_OPERATION_MISMATCH: {
|
|
256
|
+
phase: "post_send",
|
|
257
|
+
template: "The signed DTO has no dtoOperation, or one that is not the call it was sent to: {serverMessage}",
|
|
258
|
+
params: { serverMessage: "string" }
|
|
259
|
+
},
|
|
255
260
|
BOUNDS_VIOLATION: {
|
|
256
261
|
phase: "post_send",
|
|
257
262
|
template: "The gateway rejected a numeric, tick, symbol or range bound: {serverMessage}",
|
|
@@ -761,6 +766,7 @@ const GSWAP_ERROR_PHASE_BY_CODE = {
|
|
|
761
766
|
SIGNATURE_INVALID: "post_send",
|
|
762
767
|
SIGNER_MISMATCH: "post_send",
|
|
763
768
|
DTO_INVALID: "post_send",
|
|
769
|
+
DTO_OPERATION_MISMATCH: "post_send",
|
|
764
770
|
BOUNDS_VIOLATION: "post_send",
|
|
765
771
|
SYMBOL_CONFLICT: "post_send",
|
|
766
772
|
RATE_LIMITED: "post_send",
|
|
@@ -936,6 +942,7 @@ var GSwapSDKError = class GSwapSDKError extends _gala_chain_gala_core_sdk.GalaSD
|
|
|
936
942
|
case "SIGNATURE_INVALID": return new GSwapSDKError("SIGNATURE_INVALID", params, context);
|
|
937
943
|
case "SIGNER_MISMATCH": return new GSwapSDKError("SIGNER_MISMATCH", params, context);
|
|
938
944
|
case "DTO_INVALID": return new GSwapSDKError("DTO_INVALID", params, context);
|
|
945
|
+
case "DTO_OPERATION_MISMATCH": return new GSwapSDKError("DTO_OPERATION_MISMATCH", params, context);
|
|
939
946
|
case "BOUNDS_VIOLATION": return new GSwapSDKError("BOUNDS_VIOLATION", params, context);
|
|
940
947
|
case "SYMBOL_CONFLICT": return new GSwapSDKError("SYMBOL_CONFLICT", params, context);
|
|
941
948
|
case "RATE_LIMITED": return new GSwapSDKError("RATE_LIMITED", params, context);
|
|
@@ -5906,7 +5913,8 @@ const BY_CODE = {
|
|
|
5906
5913
|
METHOD_NOT_ALLOWED: NOT_QUEUED,
|
|
5907
5914
|
SIGNATURE_INVALID: NOT_QUEUED,
|
|
5908
5915
|
SIGNER_MISMATCH: NOT_QUEUED,
|
|
5909
|
-
DTO_INVALID:
|
|
5916
|
+
DTO_INVALID: NOT_QUEUED_FINAL,
|
|
5917
|
+
DTO_OPERATION_MISMATCH: NOT_QUEUED_FINAL,
|
|
5910
5918
|
BOUNDS_VIOLATION: NOT_QUEUED,
|
|
5911
5919
|
SYMBOL_CONFLICT: NOT_QUEUED,
|
|
5912
5920
|
RATE_LIMITED: NOT_QUEUED,
|
|
@@ -6575,6 +6583,7 @@ const RELAYABLE_REFUSAL_CODES = [
|
|
|
6575
6583
|
"SIGNATURE_INVALID",
|
|
6576
6584
|
"SIGNER_MISMATCH",
|
|
6577
6585
|
"DTO_INVALID",
|
|
6586
|
+
"DTO_OPERATION_MISMATCH",
|
|
6578
6587
|
"BOUNDS_VIOLATION",
|
|
6579
6588
|
"SYMBOL_CONFLICT",
|
|
6580
6589
|
"RATE_LIMITED",
|