@rhea-finance/cross-chain-aggregation-dex 2.0.4 → 2.0.6
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 +207 -77
- package/dist/executors/aptos.d.mts +1 -1
- package/dist/executors/aptos.d.ts +1 -1
- package/dist/executors/aptos.js.map +1 -1
- package/dist/executors/aptos.mjs.map +1 -1
- package/dist/executors/bitcoin.d.mts +1 -1
- package/dist/executors/bitcoin.d.ts +1 -1
- package/dist/executors/bitcoin.js.map +1 -1
- package/dist/executors/bitcoin.mjs.map +1 -1
- package/dist/executors/evm.d.mts +1 -1
- package/dist/executors/evm.d.ts +1 -1
- package/dist/executors/evm.js.map +1 -1
- package/dist/executors/evm.mjs.map +1 -1
- package/dist/executors/near.d.mts +1 -1
- package/dist/executors/near.d.ts +1 -1
- package/dist/executors/near.js.map +1 -1
- package/dist/executors/near.mjs.map +1 -1
- package/dist/executors/solana.d.mts +1 -1
- package/dist/executors/solana.d.ts +1 -1
- package/dist/executors/solana.js.map +1 -1
- package/dist/executors/solana.mjs.map +1 -1
- package/dist/executors/sui.d.mts +1 -1
- package/dist/executors/sui.d.ts +1 -1
- package/dist/executors/sui.js.map +1 -1
- package/dist/executors/sui.mjs.map +1 -1
- package/dist/executors/tron.d.mts +1 -1
- package/dist/executors/tron.d.ts +1 -1
- package/dist/executors/tron.js.map +1 -1
- package/dist/executors/tron.mjs.map +1 -1
- package/dist/executors/zcash.d.mts +1 -1
- package/dist/executors/zcash.d.ts +1 -1
- package/dist/executors/zcash.js.map +1 -1
- package/dist/executors/zcash.mjs.map +1 -1
- package/dist/index.d.mts +82 -6
- package/dist/index.d.ts +82 -6
- package/dist/index.js +454 -71
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +451 -72
- package/dist/index.mjs.map +1 -1
- package/dist/{shared-D0_DbMT2.d.mts → shared-COkGiqaz.d.mts} +84 -2
- package/dist/{shared-D0_DbMT2.d.ts → shared-COkGiqaz.d.ts} +84 -2
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/zcash/index.ts"],"names":[],"mappings":";;;AAyCO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAGtC,YACW,IAAA,EACA,KAAA,EACT,OAAA,EACS,OAAA,GAA+B,EAAC,EACzC;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AALJ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAEA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AANX,IAAA,IAAA,CAAS,IAAA,GAAO,cAAA;AASd,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AAAA,EAEA,IAAI,SAAA,GAAqB;AACvB,IAAA,OAAO,IAAA,CAAK,QAAQ,SAAA,IAAa,KAAA;AAAA,EACnC;AAAA,EAEA,IAAI,KAAA,GAAiB;AACnB,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACtB;AAAA,EAEA,IAAI,OAAA,GAA+C;AACjD,IAAA,OAAO,KAAK,OAAA,CAAQ,OAAA;AAAA,EACtB;AACF,CAAA;;;AC7BO,SAAS,oBAAA,CACd,aACA,OAAA,EAIA;AACA,EAAA,OAAO;AAAA,IACL,WAAA;AAAA,IACA,GAAI,OAAA,CAAQ,cAAA,GACR,EAAE,cAAA,EAAgB,MAAM,OAAA,CAAQ,cAAA,EAAgB,EAAE,GAClD,EAAC;AAAA,IACL,GAAI,QAAQ,WAAA,GACR;AAAA,MACE,aAAa,CACX,OAAA,EACA,YACG,OAAA,CAAQ,WAAA,CAAa,SAAS,OAAO;AAAA,QAE5C;AAAC,GACP;AACF;AAEO,SAAS,cAAA,CACd,MAAA,EACA,KAAA,GAAwB,MAAA,EAClB;AACN,EAAA,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,MAAM,IAAI,YAAA;AAAA,UACR,kBAAA;AAAA,UACA,WAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AACA,MAAA,OAAO,QAAQ,OAAA,EAAS,UAAA,CAAW,MAAA,EAAQ,UAAA,CAAW,KAAK,OAAO,CAAA;AAAA,IACpE;AAAA,GACF;AACF;AAEA,eAAe,OAAA,CACb,OAAA,EACA,MAAA,EACA,GAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,MAAA;AAAA,MACA,GAAI,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,KAAQ;AAAC,KACrC;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,MAAA,EAAQ;AAAA,MAC5D,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,2BAA2B,YAAA,EAAc;AAAA,MAC/D,IAAA,EAAM,kBAAA;AAAA,MACN,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS;AAAA,KACV,CAAA;AACD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,kBAAA;AAAA,MACR,MAAA;AAAA,MACA,KAAK,eAAA,IAAmB;AAAA,KAC1B;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,gBAAA;AAAA,MACJ,KAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,kBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"zcash.js","sourcesContent":["export type SwapErrorCode =\n | \"HTTP_ERROR\"\n | \"API_ERROR\"\n | \"RATE_LIMITED\"\n | \"AUTH_FAILED\"\n | \"REQUEST_ABORTED\"\n | \"REQUEST_TIMEOUT\"\n | \"INVALID_REQUEST\"\n | \"INVALID_API_RESPONSE\"\n | \"QUOTE_EXPIRED\"\n | \"ROUTE_NOT_FOUND\"\n | \"EXECUTOR_NOT_FOUND\"\n | \"UNSUPPORTED_CHAIN\"\n | \"CHAIN_MISMATCH\"\n | \"INVALID_TRANSACTION\"\n | \"USER_REJECTED\"\n | \"INSUFFICIENT_BALANCE\"\n | \"APPROVAL_FAILED\"\n | \"SIGNING_FAILED\"\n | \"BROADCAST_FAILED\"\n | \"ORDER_SUBMIT_FAILED\"\n | \"ORDER_TIMEOUT\"\n | \"REPORT_FAILED\";\n\nexport type SwapErrorStage =\n | \"quote\"\n | \"build\"\n | \"approve\"\n | \"sign\"\n | \"broadcast\"\n | \"submit\"\n | \"report\"\n | \"status\"\n | \"history\";\n\nexport interface SwapSdkErrorOptions {\n retryable?: boolean;\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\nexport class SwapSdkError extends Error {\n readonly name = \"SwapSdkError\";\n\n constructor(\n readonly code: SwapErrorCode,\n readonly stage: SwapErrorStage,\n message: string,\n readonly options: SwapSdkErrorOptions = {}\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n get retryable(): boolean {\n return this.options.retryable ?? false;\n }\n\n get cause(): unknown {\n return this.options.cause;\n }\n\n get details(): Record<string, unknown> | undefined {\n return this.options.details;\n }\n}\n\nexport function asSwapSdkError(\n error: unknown,\n stage: SwapErrorStage\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n\n const message = error instanceof Error ? error.message : String(error);\n return new SwapSdkError(\"API_ERROR\", stage, message, { cause: error });\n}\n","import {\n SwapSdkError,\n type SwapErrorCode,\n type SwapErrorStage,\n} from \"../core/errors\";\nimport type {\n ChainExecutor,\n ExecutionContext,\n MessageSignOptions,\n} from \"../core/registry\";\nimport type { ChainRef } from \"../types/chain\";\n\nexport interface TransactionSubmission {\n txHash: string;\n raw?: unknown;\n}\n\nexport interface TransactionConfirmation {\n status: \"confirmed\" | \"failed\";\n raw?: unknown;\n}\n\nexport interface ExecutorErrorAdapter {\n isUserRejection?(error: unknown): boolean;\n /** Identity serialized as `mca.signer.identityKey` for MCA quotes. */\n getIdentityKey?(): string | Promise<string>;\n /**\n * Optional offline message signing for flows such as MCA relayer withdraw.\n * Chain transfer executors do not call this during normal swap execution.\n */\n signMessage?(\n message: string,\n options?: MessageSignOptions\n ): Promise<string>;\n}\n\nexport function exposeExecutorSigner(\n signerChain: string,\n adapter: ExecutorErrorAdapter\n): Pick<\n ChainExecutor,\n \"signerChain\" | \"getIdentityKey\" | \"signMessage\"\n> {\n return {\n signerChain,\n ...(adapter.getIdentityKey\n ? { getIdentityKey: () => adapter.getIdentityKey!() }\n : {}),\n ...(adapter.signMessage\n ? {\n signMessage: (\n message: string,\n options?: MessageSignOptions\n ) => adapter.signMessage!(message, options),\n }\n : {}),\n };\n}\n\nexport function throwIfAborted(\n signal: AbortSignal | undefined,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (!signal?.aborted) return;\n throw new SwapSdkError(\"REQUEST_ABORTED\", stage, \"Execution was aborted\", {\n cause: signal.reason,\n });\n}\n\nexport function assertChain(\n expected: ChainRef,\n actual: ChainRef,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (expected === actual) return;\n throw new SwapSdkError(\n \"CHAIN_MISMATCH\",\n stage,\n `Connected chain ${actual} does not match execution chain ${expected}`,\n { details: { expected, actual } }\n );\n}\n\nexport async function requestSignApproval(\n context: ExecutionContext,\n chain: ChainRef,\n kind: string,\n summary: Record<string, unknown>\n): Promise<void> {\n throwIfAborted(context.signal, \"sign\");\n await context.beforeSign?.({ chain, kind, summary });\n throwIfAborted(context.signal, \"sign\");\n}\n\nexport function mapExecutorError(\n error: unknown,\n adapter: ExecutorErrorAdapter,\n stage: SwapErrorStage,\n code: SwapErrorCode,\n message: string\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n if (isUserRejection(error, adapter)) {\n return new SwapSdkError(\"USER_REJECTED\", stage, \"User rejected the request\", {\n cause: error,\n });\n }\n return new SwapSdkError(code, stage, message, { cause: error });\n}\n\nexport function assertTransactionConfirmed(\n confirmation: TransactionConfirmation,\n options: {\n code: SwapErrorCode;\n stage: SwapErrorStage;\n message: string;\n }\n): unknown {\n if (confirmation?.status === \"confirmed\") {\n return confirmation.raw;\n }\n const status =\n confirmation &&\n typeof confirmation === \"object\" &&\n \"status\" in confirmation\n ? String(confirmation.status)\n : \"missing\";\n throw new SwapSdkError(\n options.code,\n options.stage,\n `${options.message}: wallet confirmation status is ${status}`,\n {\n cause:\n confirmation &&\n typeof confirmation === \"object\" &&\n \"raw\" in confirmation\n ? confirmation.raw\n : confirmation,\n details: { confirmationStatus: status },\n }\n );\n}\n\nfunction isUserRejection(\n error: unknown,\n adapter: ExecutorErrorAdapter\n): boolean {\n if (adapter.isUserRejection?.(error)) return true;\n if (typeof error !== \"object\" || error === null) return false;\n const code = \"code\" in error ? error.code : undefined;\n if (code === 4001 || code === \"ACTION_REJECTED\") return true;\n const message =\n \"message\" in error && typeof error.message === \"string\"\n ? error.message.toLowerCase()\n : \"\";\n return /user (rejected|denied)|request rejected|cancelled by user/.test(message);\n}\n","import { SwapSdkError } from \"../../core/errors\";\nimport type {\n ChainExecutionResult,\n ChainExecutor,\n ExecutionContext,\n} from \"../../core/registry\";\nimport type { ChainRef } from \"../../types/chain\";\nimport {\n assertTransactionConfirmed,\n assertChain,\n exposeExecutorSigner,\n mapExecutorError,\n requestSignApproval,\n throwIfAborted,\n type ExecutorErrorAdapter,\n type TransactionConfirmation,\n type TransactionSubmission,\n} from \"../shared\";\n\nexport interface ZcashWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n decimals?: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createZcashExecutor(\n adapter: ZcashWalletAdapter\n): ChainExecutor<\"zcash-transfer\"> {\n return {\n ...exposeExecutorSigner(\"zcash\", adapter),\n kinds: [\"zcash-transfer\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n if (!adapter.isAddress(execution.depositAddress)) {\n throw new SwapSdkError(\n \"INVALID_TRANSACTION\",\n \"sign\",\n \"Invalid Zcash transparent deposit address\"\n );\n }\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n decimals: execution.decimals,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n ...(execution.decimals !== undefined\n ? { decimals: execution.decimals }\n : {}),\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to submit Zcash transfer\"\n );\n }\n if (!submission.txHash?.trim()) {\n throw new SwapSdkError(\n \"BROADCAST_FAILED\",\n \"broadcast\",\n \"Zcash wallet returned no transaction hash\"\n );\n }\n return confirm(adapter, submission.txHash, submission.raw, context);\n },\n };\n}\n\nasync function confirm(\n adapter: ZcashWalletAdapter,\n txHash: string,\n raw: unknown,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash,\n ...(raw !== undefined ? { raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Zcash transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash,\n raw: confirmationRaw ?? raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Zcash transfer\"\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/zcash/index.ts"],"names":[],"mappings":";;;AA0CO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAGtC,YACW,IAAA,EACA,KAAA,EACT,OAAA,EACS,OAAA,GAA+B,EAAC,EACzC;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AALJ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAEA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AANX,IAAA,IAAA,CAAS,IAAA,GAAO,cAAA;AASd,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AAAA,EAEA,IAAI,SAAA,GAAqB;AACvB,IAAA,OAAO,IAAA,CAAK,QAAQ,SAAA,IAAa,KAAA;AAAA,EACnC;AAAA,EAEA,IAAI,KAAA,GAAiB;AACnB,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACtB;AAAA,EAEA,IAAI,OAAA,GAA+C;AACjD,IAAA,OAAO,KAAK,OAAA,CAAQ,OAAA;AAAA,EACtB;AACF,CAAA;;;AC9BO,SAAS,oBAAA,CACd,aACA,OAAA,EAIA;AACA,EAAA,OAAO;AAAA,IACL,WAAA;AAAA,IACA,GAAI,OAAA,CAAQ,cAAA,GACR,EAAE,cAAA,EAAgB,MAAM,OAAA,CAAQ,cAAA,EAAgB,EAAE,GAClD,EAAC;AAAA,IACL,GAAI,QAAQ,WAAA,GACR;AAAA,MACE,aAAa,CACX,OAAA,EACA,YACG,OAAA,CAAQ,WAAA,CAAa,SAAS,OAAO;AAAA,QAE5C;AAAC,GACP;AACF;AAEO,SAAS,cAAA,CACd,MAAA,EACA,KAAA,GAAwB,MAAA,EAClB;AACN,EAAA,IAAI,CAAC,QAAQ,OAAA,EAAS;AACtB,EAAA,MA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A,WAAA;AAAA,UACA;AAAA,SACF;AAAA,MACF;AACA,MAAA,OAAO,QAAQ,OAAA,EAAS,UAAA,CAAW,MAAA,EAAQ,UAAA,CAAW,KAAK,OAAO,CAAA;AAAA,IACpE;AAAA,GACF;AACF;AAEA,eAAe,OAAA,CACb,OAAA,EACA,MAAA,EACA,GAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,MAAA;AAAA,MACA,GAAI,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,KAAQ;AAAC,KACrC;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,MAAA,EAAQ;AAAA,MAC5D,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,2BAA2B,YAAA,EAAc;AAAA,MAC/D,IAAA,EAAM,kBAAA;AAAA,MACN,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS;AAAA,KACV,CAAA;AACD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,kBAAA;AAAA,MACR,MAAA;AAAA,MACA,KAAK,eAAA,IAAmB;AAAA,KAC1B;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,gBAAA;AAAA,MACJ,KAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,kBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"zcash.js","sourcesContent":["export type SwapErrorCode =\n | \"HTTP_ERROR\"\n | \"API_ERROR\"\n | \"RATE_LIMITED\"\n | \"AUTH_FAILED\"\n | \"REQUEST_ABORTED\"\n | \"REQUEST_TIMEOUT\"\n | \"INVALID_REQUEST\"\n | \"INVALID_API_RESPONSE\"\n | \"QUOTE_EXPIRED\"\n | \"ROUTE_NOT_FOUND\"\n | \"EXECUTOR_NOT_FOUND\"\n | \"UNSUPPORTED_CHAIN\"\n | \"CHAIN_MISMATCH\"\n | \"INVALID_TRANSACTION\"\n | \"USER_REJECTED\"\n | \"INSUFFICIENT_BALANCE\"\n | \"APPROVAL_FAILED\"\n | \"SIGNING_FAILED\"\n | \"BROADCAST_FAILED\"\n | \"ORDER_SUBMIT_FAILED\"\n | \"ORDER_TIMEOUT\"\n | \"REPORT_FAILED\";\n\nexport type SwapErrorStage =\n | \"quote\"\n | \"build\"\n | \"approve\"\n | \"sign\"\n | \"broadcast\"\n | \"submit\"\n | \"report\"\n | \"status\"\n | \"tokens\"\n | \"history\";\n\nexport interface SwapSdkErrorOptions {\n retryable?: boolean;\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\nexport class SwapSdkError extends Error {\n readonly name = \"SwapSdkError\";\n\n constructor(\n readonly code: SwapErrorCode,\n readonly stage: SwapErrorStage,\n message: string,\n readonly options: SwapSdkErrorOptions = {}\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n get retryable(): boolean {\n return this.options.retryable ?? false;\n }\n\n get cause(): unknown {\n return this.options.cause;\n }\n\n get details(): Record<string, unknown> | undefined {\n return this.options.details;\n }\n}\n\nexport function asSwapSdkError(\n error: unknown,\n stage: SwapErrorStage\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n\n const message = error instanceof Error ? error.message : String(error);\n return new SwapSdkError(\"API_ERROR\", stage, message, { cause: error });\n}\n","import {\n SwapSdkError,\n type SwapErrorCode,\n type SwapErrorStage,\n} from \"../core/errors\";\nimport type {\n ChainExecutor,\n ExecutionContext,\n MessageSignOptions,\n} from \"../core/registry\";\nimport type { ChainRef } from \"../types/chain\";\n\nexport interface TransactionSubmission {\n txHash: string;\n raw?: unknown;\n}\n\nexport interface TransactionConfirmation {\n status: \"confirmed\" | \"failed\";\n raw?: unknown;\n}\n\nexport interface ExecutorErrorAdapter {\n isUserRejection?(error: unknown): boolean;\n /** Identity serialized as `mca.signer.identityKey` for MCA quotes. */\n getIdentityKey?(): string | Promise<string>;\n /**\n * Optional offline message signing for flows such as MCA relayer withdraw.\n * Chain transfer executors do not call this during normal swap execution.\n */\n signMessage?(\n message: string,\n options?: MessageSignOptions\n ): Promise<string>;\n}\n\nexport function exposeExecutorSigner(\n signerChain: string,\n adapter: ExecutorErrorAdapter\n): Pick<\n ChainExecutor,\n \"signerChain\" | \"getIdentityKey\" | \"signMessage\"\n> {\n return {\n signerChain,\n ...(adapter.getIdentityKey\n ? { getIdentityKey: () => adapter.getIdentityKey!() }\n : {}),\n ...(adapter.signMessage\n ? {\n signMessage: (\n message: string,\n options?: MessageSignOptions\n ) => adapter.signMessage!(message, options),\n }\n : {}),\n };\n}\n\nexport function throwIfAborted(\n signal: AbortSignal | undefined,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (!signal?.aborted) return;\n throw new SwapSdkError(\"REQUEST_ABORTED\", stage, \"Execution was aborted\", {\n cause: signal.reason,\n });\n}\n\nexport function assertChain(\n expected: ChainRef,\n actual: ChainRef,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (expected === actual) return;\n throw new SwapSdkError(\n \"CHAIN_MISMATCH\",\n stage,\n `Connected chain ${actual} does not match execution chain ${expected}`,\n { details: { expected, actual } }\n );\n}\n\nexport async function requestSignApproval(\n context: ExecutionContext,\n chain: ChainRef,\n kind: string,\n summary: Record<string, unknown>\n): Promise<void> {\n throwIfAborted(context.signal, \"sign\");\n await context.beforeSign?.({ chain, kind, summary });\n throwIfAborted(context.signal, \"sign\");\n}\n\nexport function mapExecutorError(\n error: unknown,\n adapter: ExecutorErrorAdapter,\n stage: SwapErrorStage,\n code: SwapErrorCode,\n message: string\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n if (isUserRejection(error, adapter)) {\n return new SwapSdkError(\"USER_REJECTED\", stage, \"User rejected the request\", {\n cause: error,\n });\n }\n return new SwapSdkError(code, stage, message, { cause: error });\n}\n\nexport function assertTransactionConfirmed(\n confirmation: TransactionConfirmation,\n options: {\n code: SwapErrorCode;\n stage: SwapErrorStage;\n message: string;\n }\n): unknown {\n if (confirmation?.status === \"confirmed\") {\n return confirmation.raw;\n }\n const status =\n confirmation &&\n typeof confirmation === \"object\" &&\n \"status\" in confirmation\n ? String(confirmation.status)\n : \"missing\";\n throw new SwapSdkError(\n options.code,\n options.stage,\n `${options.message}: wallet confirmation status is ${status}`,\n {\n cause:\n confirmation &&\n typeof confirmation === \"object\" &&\n \"raw\" in confirmation\n ? confirmation.raw\n : confirmation,\n details: { confirmationStatus: status },\n }\n );\n}\n\nfunction isUserRejection(\n error: unknown,\n adapter: ExecutorErrorAdapter\n): boolean {\n if (adapter.isUserRejection?.(error)) return true;\n if (typeof error !== \"object\" || error === null) return false;\n const code = \"code\" in error ? error.code : undefined;\n if (code === 4001 || code === \"ACTION_REJECTED\") return true;\n const message =\n \"message\" in error && typeof error.message === \"string\"\n ? error.message.toLowerCase()\n : \"\";\n return /user (rejected|denied)|request rejected|cancelled by user/.test(message);\n}\n","import { SwapSdkError } from \"../../core/errors\";\nimport type {\n ChainExecutionResult,\n ChainExecutor,\n ExecutionContext,\n} from \"../../core/registry\";\nimport type { ChainRef } from \"../../types/chain\";\nimport {\n assertTransactionConfirmed,\n assertChain,\n exposeExecutorSigner,\n mapExecutorError,\n requestSignApproval,\n throwIfAborted,\n type ExecutorErrorAdapter,\n type TransactionConfirmation,\n type TransactionSubmission,\n} from \"../shared\";\n\nexport interface ZcashWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n decimals?: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createZcashExecutor(\n adapter: ZcashWalletAdapter\n): ChainExecutor<\"zcash-transfer\"> {\n return {\n ...exposeExecutorSigner(\"zcash\", adapter),\n kinds: [\"zcash-transfer\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n if (!adapter.isAddress(execution.depositAddress)) {\n throw new SwapSdkError(\n \"INVALID_TRANSACTION\",\n \"sign\",\n \"Invalid Zcash transparent deposit address\"\n );\n }\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n decimals: execution.decimals,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n ...(execution.decimals !== undefined\n ? { decimals: execution.decimals }\n : {}),\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to submit Zcash transfer\"\n );\n }\n if (!submission.txHash?.trim()) {\n throw new SwapSdkError(\n \"BROADCAST_FAILED\",\n \"broadcast\",\n \"Zcash wallet returned no transaction hash\"\n );\n }\n return confirm(adapter, submission.txHash, submission.raw, context);\n },\n };\n}\n\nasync function confirm(\n adapter: ZcashWalletAdapter,\n txHash: string,\n raw: unknown,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash,\n ...(raw !== undefined ? { raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Zcash transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash,\n raw: confirmationRaw ?? raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Zcash transfer\"\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/zcash/index.ts"],"names":[],"mappings":";AAyCO,IAAM,YAAA,GAAN,cAA2B,KAAA,CAAM;AAAA,EAGtC,YACW,IAAA,EACA,KAAA,EACT,OAAA,EACS,OAAA,GAA+B,EAAC,EACzC;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AALJ,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AACA,IAAA,IAAA,CAAA,KAAA,GAAA,KAAA;AAEA,IAAA,IAAA,CAAA,OAAA,GAAA,OAAA;AANX,IAAA,IAAA,CAAS,IAAA,GAAO,cAAA;AASd,IAAA,MAAA,CAAO,cAAA,CAAe,IAAA,EAAM,GAAA,CAAA,MAAA,CAAW,SAAS,CAAA;AAAA,EAClD;AAAA,EAEA,IAAI,SAAA,GAAqB;AACvB,IAAA,OAAO,IAAA,CAAK,QAAQ,SAAA,IAAa,KAAA;AAAA,EACnC;AAAA,EAEA,IAAI,KAAA,GAAiB;AACnB,IAAA,OAAO,KAAK,OAAA,CAAQ,KAAA;AAAA,EACtB;AAAA,EAEA,IAAI,OAAA,GAA+C;AACjD,IAAA,OAAO,KAAK,OAAA,CAAQ,OAAA;AAAA,EACtB;AACF,CAAA;;;AC7BO,SAAS,oBAAA,CACd,aACA,OAAA,EAIA;AACA,EAAA,OAAO;AAAA,IACL,WAAA;AAAA,IACA,GAAI,OAAA,CAAQ,cAAA,GACR,EAAE,cAAA,EAAgB,MAAM,OAAA,CAAQ,cAAA,EAAgB,EAAE,GAClD,EAAC;AAAA,IACL,GAAI,QAAQ,WAAA,GACR;AAAA,MACE,aAAa,CACX,OAAA,EACA,YACG,OAAA,CAAQ,WAAA,CAAa,SAAS,OAAO;AAAA,QAE5C;AAAC,GACP;AACF;AAEO,SAAS,cAAA,CACd,MAAA,EACA,KAAA,GAAwB,MAAA,EAClB;AACN,EAAA,IAAI,CAAC,QAAQ,OAAA,EAAS;AACtB,EAAA,MAAM,IAAI,YAAA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UACA;AAAA,SACF;AAAA,MACF;AACA,MAAA,OAAO,QAAQ,OAAA,EAAS,UAAA,CAAW,MAAA,EAAQ,UAAA,CAAW,KAAK,OAAO,CAAA;AAAA,IACpE;AAAA,GACF;AACF;AAEA,eAAe,OAAA,CACb,OAAA,EACA,MAAA,EACA,GAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,MAAA;AAAA,MACA,GAAI,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,KAAQ;AAAC,KACrC;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,MAAA,EAAQ;AAAA,MAC5D,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,2BAA2B,YAAA,EAAc;AAAA,MAC/D,IAAA,EAAM,kBAAA;AAAA,MACN,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS;AAAA,KACV,CAAA;AACD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,kBAAA;AAAA,MACR,MAAA;AAAA,MACA,KAAK,eAAA,IAAmB;AAAA,KAC1B;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,gBAAA;AAAA,MACJ,KAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,kBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"zcash.mjs","sourcesContent":["export type SwapErrorCode =\n | \"HTTP_ERROR\"\n | \"API_ERROR\"\n | \"RATE_LIMITED\"\n | \"AUTH_FAILED\"\n | \"REQUEST_ABORTED\"\n | \"REQUEST_TIMEOUT\"\n | \"INVALID_REQUEST\"\n | \"INVALID_API_RESPONSE\"\n | \"QUOTE_EXPIRED\"\n | \"ROUTE_NOT_FOUND\"\n | \"EXECUTOR_NOT_FOUND\"\n | \"UNSUPPORTED_CHAIN\"\n | \"CHAIN_MISMATCH\"\n | \"INVALID_TRANSACTION\"\n | \"USER_REJECTED\"\n | \"INSUFFICIENT_BALANCE\"\n | \"APPROVAL_FAILED\"\n | \"SIGNING_FAILED\"\n | \"BROADCAST_FAILED\"\n | \"ORDER_SUBMIT_FAILED\"\n | \"ORDER_TIMEOUT\"\n | \"REPORT_FAILED\";\n\nexport type SwapErrorStage =\n | \"quote\"\n | \"build\"\n | \"approve\"\n | \"sign\"\n | \"broadcast\"\n | \"submit\"\n | \"report\"\n | \"status\"\n | \"history\";\n\nexport interface SwapSdkErrorOptions {\n retryable?: boolean;\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\nexport class SwapSdkError extends Error {\n readonly name = \"SwapSdkError\";\n\n constructor(\n readonly code: SwapErrorCode,\n readonly stage: SwapErrorStage,\n message: string,\n readonly options: SwapSdkErrorOptions = {}\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n get retryable(): boolean {\n return this.options.retryable ?? false;\n }\n\n get cause(): unknown {\n return this.options.cause;\n }\n\n get details(): Record<string, unknown> | undefined {\n return this.options.details;\n }\n}\n\nexport function asSwapSdkError(\n error: unknown,\n stage: SwapErrorStage\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n\n const message = error instanceof Error ? error.message : String(error);\n return new SwapSdkError(\"API_ERROR\", stage, message, { cause: error });\n}\n","import {\n SwapSdkError,\n type SwapErrorCode,\n type SwapErrorStage,\n} from \"../core/errors\";\nimport type {\n ChainExecutor,\n ExecutionContext,\n MessageSignOptions,\n} from \"../core/registry\";\nimport type { ChainRef } from \"../types/chain\";\n\nexport interface TransactionSubmission {\n txHash: string;\n raw?: unknown;\n}\n\nexport interface TransactionConfirmation {\n status: \"confirmed\" | \"failed\";\n raw?: unknown;\n}\n\nexport interface ExecutorErrorAdapter {\n isUserRejection?(error: unknown): boolean;\n /** Identity serialized as `mca.signer.identityKey` for MCA quotes. */\n getIdentityKey?(): string | Promise<string>;\n /**\n * Optional offline message signing for flows such as MCA relayer withdraw.\n * Chain transfer executors do not call this during normal swap execution.\n */\n signMessage?(\n message: string,\n options?: MessageSignOptions\n ): Promise<string>;\n}\n\nexport function exposeExecutorSigner(\n signerChain: string,\n adapter: ExecutorErrorAdapter\n): Pick<\n ChainExecutor,\n \"signerChain\" | \"getIdentityKey\" | \"signMessage\"\n> {\n return {\n signerChain,\n ...(adapter.getIdentityKey\n ? { getIdentityKey: () => adapter.getIdentityKey!() }\n : {}),\n ...(adapter.signMessage\n ? {\n signMessage: (\n message: string,\n options?: MessageSignOptions\n ) => adapter.signMessage!(message, options),\n }\n : {}),\n };\n}\n\nexport function throwIfAborted(\n signal: AbortSignal | undefined,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (!signal?.aborted) return;\n throw new SwapSdkError(\"REQUEST_ABORTED\", stage, \"Execution was aborted\", {\n cause: signal.reason,\n });\n}\n\nexport function assertChain(\n expected: ChainRef,\n actual: ChainRef,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (expected === actual) return;\n throw new SwapSdkError(\n \"CHAIN_MISMATCH\",\n stage,\n `Connected chain ${actual} does not match execution chain ${expected}`,\n { details: { expected, actual } }\n );\n}\n\nexport async function requestSignApproval(\n context: ExecutionContext,\n chain: ChainRef,\n kind: string,\n summary: Record<string, unknown>\n): Promise<void> {\n throwIfAborted(context.signal, \"sign\");\n await context.beforeSign?.({ chain, kind, summary });\n throwIfAborted(context.signal, \"sign\");\n}\n\nexport function mapExecutorError(\n error: unknown,\n adapter: ExecutorErrorAdapter,\n stage: SwapErrorStage,\n code: SwapErrorCode,\n message: string\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n if (isUserRejection(error, adapter)) {\n return new SwapSdkError(\"USER_REJECTED\", stage, \"User rejected the request\", {\n cause: error,\n });\n }\n return new SwapSdkError(code, stage, message, { cause: error });\n}\n\nexport function assertTransactionConfirmed(\n confirmation: TransactionConfirmation,\n options: {\n code: SwapErrorCode;\n stage: SwapErrorStage;\n message: string;\n }\n): unknown {\n if (confirmation?.status === \"confirmed\") {\n return confirmation.raw;\n }\n const status =\n confirmation &&\n typeof confirmation === \"object\" &&\n \"status\" in confirmation\n ? String(confirmation.status)\n : \"missing\";\n throw new SwapSdkError(\n options.code,\n options.stage,\n `${options.message}: wallet confirmation status is ${status}`,\n {\n cause:\n confirmation &&\n typeof confirmation === \"object\" &&\n \"raw\" in confirmation\n ? confirmation.raw\n : confirmation,\n details: { confirmationStatus: status },\n }\n );\n}\n\nfunction isUserRejection(\n error: unknown,\n adapter: ExecutorErrorAdapter\n): boolean {\n if (adapter.isUserRejection?.(error)) return true;\n if (typeof error !== \"object\" || error === null) return false;\n const code = \"code\" in error ? error.code : undefined;\n if (code === 4001 || code === \"ACTION_REJECTED\") return true;\n const message =\n \"message\" in error && typeof error.message === \"string\"\n ? error.message.toLowerCase()\n : \"\";\n return /user (rejected|denied)|request rejected|cancelled by user/.test(message);\n}\n","import { SwapSdkError } from \"../../core/errors\";\nimport type {\n ChainExecutionResult,\n ChainExecutor,\n ExecutionContext,\n} from \"../../core/registry\";\nimport type { ChainRef } from \"../../types/chain\";\nimport {\n assertTransactionConfirmed,\n assertChain,\n exposeExecutorSigner,\n mapExecutorError,\n requestSignApproval,\n throwIfAborted,\n type ExecutorErrorAdapter,\n type TransactionConfirmation,\n type TransactionSubmission,\n} from \"../shared\";\n\nexport interface ZcashWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n decimals?: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createZcashExecutor(\n adapter: ZcashWalletAdapter\n): ChainExecutor<\"zcash-transfer\"> {\n return {\n ...exposeExecutorSigner(\"zcash\", adapter),\n kinds: [\"zcash-transfer\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n if (!adapter.isAddress(execution.depositAddress)) {\n throw new SwapSdkError(\n \"INVALID_TRANSACTION\",\n \"sign\",\n \"Invalid Zcash transparent deposit address\"\n );\n }\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n decimals: execution.decimals,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n ...(execution.decimals !== undefined\n ? { decimals: execution.decimals }\n : {}),\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to submit Zcash transfer\"\n );\n }\n if (!submission.txHash?.trim()) {\n throw new SwapSdkError(\n \"BROADCAST_FAILED\",\n \"broadcast\",\n \"Zcash wallet returned no transaction hash\"\n );\n }\n return confirm(adapter, submission.txHash, submission.raw, context);\n },\n };\n}\n\nasync function confirm(\n adapter: ZcashWalletAdapter,\n txHash: string,\n raw: unknown,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash,\n ...(raw !== undefined ? { raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Zcash transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash,\n raw: confirmationRaw ?? raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Zcash transfer\"\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src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AQ,OAAA,EAAS,UAAA,CAAW,MAAA,EAAQ,UAAA,CAAW,KAAK,OAAO,CAAA;AAAA,IACpE;AAAA,GACF;AACF;AAEA,eAAe,OAAA,CACb,OAAA,EACA,MAAA,EACA,GAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,MAAA;AAAA,MACA,GAAI,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,KAAQ;AAAC,KACrC;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,MAAA,EAAQ;AAAA,MAC5D,QAAQ,OAAA,CAAQ;AAAA,KACjB,CAAA;AACD,IAAA,MAAM,eAAA,GAAkB,2BAA2B,YAAA,EAAc;AAAA,MAC/D,IAAA,EAAM,kBAAA;AAAA,MACN,KAAA,EAAO,WAAA;AAAA,MACP,OAAA,EAAS;AAAA,KACV,CAAA;AACD,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,kBAAA;AAAA,MACR,MAAA;AAAA,MACA,KAAK,eAAA,IAAmB;AAAA,KAC1B;AAAA,EACF,SAAS,KAAA,EAAO;AACd,IAAA,MAAM,gBAAA;AAAA,MACJ,KAAA;AAAA,MACA,OAAA;AAAA,MACA,WAAA;AAAA,MACA,kBAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF","file":"zcash.mjs","sourcesContent":["export type SwapErrorCode =\n | \"HTTP_ERROR\"\n | \"API_ERROR\"\n | \"RATE_LIMITED\"\n | \"AUTH_FAILED\"\n | \"REQUEST_ABORTED\"\n | \"REQUEST_TIMEOUT\"\n | \"INVALID_REQUEST\"\n | \"INVALID_API_RESPONSE\"\n | \"QUOTE_EXPIRED\"\n | \"ROUTE_NOT_FOUND\"\n | \"EXECUTOR_NOT_FOUND\"\n | \"UNSUPPORTED_CHAIN\"\n | \"CHAIN_MISMATCH\"\n | \"INVALID_TRANSACTION\"\n | \"USER_REJECTED\"\n | \"INSUFFICIENT_BALANCE\"\n | \"APPROVAL_FAILED\"\n | \"SIGNING_FAILED\"\n | \"BROADCAST_FAILED\"\n | \"ORDER_SUBMIT_FAILED\"\n | \"ORDER_TIMEOUT\"\n | \"REPORT_FAILED\";\n\nexport type SwapErrorStage =\n | \"quote\"\n | \"build\"\n | \"approve\"\n | \"sign\"\n | \"broadcast\"\n | \"submit\"\n | \"report\"\n | \"status\"\n | \"tokens\"\n | \"history\";\n\nexport interface SwapSdkErrorOptions {\n retryable?: boolean;\n cause?: unknown;\n details?: Record<string, unknown>;\n}\n\nexport class SwapSdkError extends Error {\n readonly name = \"SwapSdkError\";\n\n constructor(\n readonly code: SwapErrorCode,\n readonly stage: SwapErrorStage,\n message: string,\n readonly options: SwapSdkErrorOptions = {}\n ) {\n super(message);\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n get retryable(): boolean {\n return this.options.retryable ?? false;\n }\n\n get cause(): unknown {\n return this.options.cause;\n }\n\n get details(): Record<string, unknown> | undefined {\n return this.options.details;\n }\n}\n\nexport function asSwapSdkError(\n error: unknown,\n stage: SwapErrorStage\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n\n const message = error instanceof Error ? error.message : String(error);\n return new SwapSdkError(\"API_ERROR\", stage, message, { cause: error });\n}\n","import {\n SwapSdkError,\n type SwapErrorCode,\n type SwapErrorStage,\n} from \"../core/errors\";\nimport type {\n ChainExecutor,\n ExecutionContext,\n MessageSignOptions,\n} from \"../core/registry\";\nimport type { ChainRef } from \"../types/chain\";\n\nexport interface TransactionSubmission {\n txHash: string;\n raw?: unknown;\n}\n\nexport interface TransactionConfirmation {\n status: \"confirmed\" | \"failed\";\n raw?: unknown;\n}\n\nexport interface ExecutorErrorAdapter {\n isUserRejection?(error: unknown): boolean;\n /** Identity serialized as `mca.signer.identityKey` for MCA quotes. */\n getIdentityKey?(): string | Promise<string>;\n /**\n * Optional offline message signing for flows such as MCA relayer withdraw.\n * Chain transfer executors do not call this during normal swap execution.\n */\n signMessage?(\n message: string,\n options?: MessageSignOptions\n ): Promise<string>;\n}\n\nexport function exposeExecutorSigner(\n signerChain: string,\n adapter: ExecutorErrorAdapter\n): Pick<\n ChainExecutor,\n \"signerChain\" | \"getIdentityKey\" | \"signMessage\"\n> {\n return {\n signerChain,\n ...(adapter.getIdentityKey\n ? { getIdentityKey: () => adapter.getIdentityKey!() }\n : {}),\n ...(adapter.signMessage\n ? {\n signMessage: (\n message: string,\n options?: MessageSignOptions\n ) => adapter.signMessage!(message, options),\n }\n : {}),\n };\n}\n\nexport function throwIfAborted(\n signal: AbortSignal | undefined,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (!signal?.aborted) return;\n throw new SwapSdkError(\"REQUEST_ABORTED\", stage, \"Execution was aborted\", {\n cause: signal.reason,\n });\n}\n\nexport function assertChain(\n expected: ChainRef,\n actual: ChainRef,\n stage: SwapErrorStage = \"sign\"\n): void {\n if (expected === actual) return;\n throw new SwapSdkError(\n \"CHAIN_MISMATCH\",\n stage,\n `Connected chain ${actual} does not match execution chain ${expected}`,\n { details: { expected, actual } }\n );\n}\n\nexport async function requestSignApproval(\n context: ExecutionContext,\n chain: ChainRef,\n kind: string,\n summary: Record<string, unknown>\n): Promise<void> {\n throwIfAborted(context.signal, \"sign\");\n await context.beforeSign?.({ chain, kind, summary });\n throwIfAborted(context.signal, \"sign\");\n}\n\nexport function mapExecutorError(\n error: unknown,\n adapter: ExecutorErrorAdapter,\n stage: SwapErrorStage,\n code: SwapErrorCode,\n message: string\n): SwapSdkError {\n if (error instanceof SwapSdkError) return error;\n if (isUserRejection(error, adapter)) {\n return new SwapSdkError(\"USER_REJECTED\", stage, \"User rejected the request\", {\n cause: error,\n });\n }\n return new SwapSdkError(code, stage, message, { cause: error });\n}\n\nexport function assertTransactionConfirmed(\n confirmation: TransactionConfirmation,\n options: {\n code: SwapErrorCode;\n stage: SwapErrorStage;\n message: string;\n }\n): unknown {\n if (confirmation?.status === \"confirmed\") {\n return confirmation.raw;\n }\n const status =\n confirmation &&\n typeof confirmation === \"object\" &&\n \"status\" in confirmation\n ? String(confirmation.status)\n : \"missing\";\n throw new SwapSdkError(\n options.code,\n options.stage,\n `${options.message}: wallet confirmation status is ${status}`,\n {\n cause:\n confirmation &&\n typeof confirmation === \"object\" &&\n \"raw\" in confirmation\n ? confirmation.raw\n : confirmation,\n details: { confirmationStatus: status },\n }\n );\n}\n\nfunction isUserRejection(\n error: unknown,\n adapter: ExecutorErrorAdapter\n): boolean {\n if (adapter.isUserRejection?.(error)) return true;\n if (typeof error !== \"object\" || error === null) return false;\n const code = \"code\" in error ? error.code : undefined;\n if (code === 4001 || code === \"ACTION_REJECTED\") return true;\n const message =\n \"message\" in error && typeof error.message === \"string\"\n ? error.message.toLowerCase()\n : \"\";\n return /user (rejected|denied)|request rejected|cancelled by user/.test(message);\n}\n","import { SwapSdkError } from \"../../core/errors\";\nimport type {\n ChainExecutionResult,\n ChainExecutor,\n ExecutionContext,\n} from \"../../core/registry\";\nimport type { ChainRef } from \"../../types/chain\";\nimport {\n assertTransactionConfirmed,\n assertChain,\n exposeExecutorSigner,\n mapExecutorError,\n requestSignApproval,\n throwIfAborted,\n type ExecutorErrorAdapter,\n type TransactionConfirmation,\n type TransactionSubmission,\n} from \"../shared\";\n\nexport interface ZcashWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n decimals?: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createZcashExecutor(\n adapter: ZcashWalletAdapter\n): ChainExecutor<\"zcash-transfer\"> {\n return {\n ...exposeExecutorSigner(\"zcash\", adapter),\n kinds: [\"zcash-transfer\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n if (!adapter.isAddress(execution.depositAddress)) {\n throw new SwapSdkError(\n \"INVALID_TRANSACTION\",\n \"sign\",\n \"Invalid Zcash transparent deposit address\"\n );\n }\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n decimals: execution.decimals,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n ...(execution.decimals !== undefined\n ? { decimals: execution.decimals }\n : {}),\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to submit Zcash transfer\"\n );\n }\n if (!submission.txHash?.trim()) {\n throw new SwapSdkError(\n \"BROADCAST_FAILED\",\n \"broadcast\",\n \"Zcash wallet returned no transaction hash\"\n );\n }\n return confirm(adapter, submission.txHash, submission.raw, context);\n },\n };\n}\n\nasync function confirm(\n adapter: ZcashWalletAdapter,\n txHash: string,\n raw: unknown,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash,\n ...(raw !== undefined ? { raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Zcash transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash,\n raw: confirmationRaw ?? raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Zcash transfer\"\n );\n }\n}\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { S as SwapQuoteRequestRaw, a as SwapQuoteDataRaw, b as SwapBuildRequestRaw, c as SwapBuildDataRaw, d as SwapOrderSubmitRequestRaw, e as SwapOrderSubmitDataRaw, f as SwapOrderStatusParamsRaw, g as SwapOrderStatusDataRaw, h as SwapReportRequestRaw, i as SwapReportDataRaw, j as SwapHistoryParamsRaw, k as SwapHistoryDataRaw, Q as QuoteRequest,
|
|
2
|
-
export {
|
|
1
|
+
import { S as SwapQuoteRequestRaw, a as SwapQuoteDataRaw, b as SwapBuildRequestRaw, c as SwapBuildDataRaw, d as SwapOrderSubmitRequestRaw, e as SwapOrderSubmitDataRaw, f as SwapOrderStatusParamsRaw, g as SwapOrderStatusDataRaw, h as SwapReportRequestRaw, i as SwapReportDataRaw, j as SwapHistoryParamsRaw, k as SwapHistoryDataRaw, l as SwapHistoryAuthChallengeRequestRaw, m as SwapHistoryAuthChallengeRaw, n as SwapHistoryAuthVerifyRequestRaw, o as SwapHistoryAuthTokenRaw, p as SwapFromTokensDataRaw, q as SwapCrossChainToTokensDataRaw, Q as QuoteRequest, r as Quote, s as SwapMcaPayloadRaw, W as WaitMode, O as OrderPollingOptions, t as SwapLifecycleEvent, u as SwapExecutionResult, C as ChainRef, A as AssetRef, B as BaseUnitAmount, v as SwapHistoryRecordRaw, w as ChainExecutor, E as ExecutorRegistry, x as SwapBuild, y as ExecuteSwapInput, z as SwapInput, D as OrderStatusResult, F as WaitForOrderInput, G as SwapHistoryAuthProofRaw, N as NearTransaction, H as SwapMcaRelayerRequestRaw } from './shared-COkGiqaz.mjs';
|
|
2
|
+
export { ac as BuildContext, Z as ChainExecutionResult, a8 as DepositInfo, a4 as EvmApproval, a5 as EvmSigningRequest, a3 as EvmTx, _ as ExecutionContext, a0 as ExecutorIdentityProvider, a1 as ExecutorMessageSigner, $ as MessageSignOptions, a7 as OrderReference, X as OrderStatus, ab as RouteSummary, V as SignRequestPreview, a6 as SolanaMetadata, I as SwapApiResponse, J as SwapApiTokenMetaRaw, P as SwapBuildApproveRaw, aa as SwapExecution, R as SwapHistoryWalletChainFamilyRaw, L as SwapMcaSignerPayloadRaw, a9 as SwapReportContext, M as SwapSigningRequestRaw, K as SwapTokenListRowRaw, U as SwapWarning, T as TransactionConfirmation, a2 as assertBaseUnitAmount, Y as normalizeOrderStatus } from './shared-COkGiqaz.mjs';
|
|
3
3
|
|
|
4
4
|
type SwapErrorCode = "HTTP_ERROR" | "API_ERROR" | "RATE_LIMITED" | "AUTH_FAILED" | "REQUEST_ABORTED" | "REQUEST_TIMEOUT" | "INVALID_REQUEST" | "INVALID_API_RESPONSE" | "QUOTE_EXPIRED" | "ROUTE_NOT_FOUND" | "EXECUTOR_NOT_FOUND" | "UNSUPPORTED_CHAIN" | "CHAIN_MISMATCH" | "INVALID_TRANSACTION" | "USER_REJECTED" | "INSUFFICIENT_BALANCE" | "APPROVAL_FAILED" | "SIGNING_FAILED" | "BROADCAST_FAILED" | "ORDER_SUBMIT_FAILED" | "ORDER_TIMEOUT" | "REPORT_FAILED";
|
|
5
|
-
type SwapErrorStage = "quote" | "build" | "approve" | "sign" | "broadcast" | "submit" | "report" | "status" | "history";
|
|
5
|
+
type SwapErrorStage = "quote" | "build" | "approve" | "sign" | "broadcast" | "submit" | "report" | "status" | "tokens" | "history";
|
|
6
6
|
interface SwapSdkErrorOptions {
|
|
7
7
|
retryable?: boolean;
|
|
8
8
|
cause?: unknown;
|
|
@@ -66,6 +66,10 @@ declare class ApiClient {
|
|
|
66
66
|
getOrderStatus(params: SwapOrderStatusParamsRaw, options?: ApiRequestOptions): Promise<SwapOrderStatusDataRaw>;
|
|
67
67
|
report(body: SwapReportRequestRaw, options?: ApiRequestOptions): Promise<SwapReportDataRaw>;
|
|
68
68
|
getHistory(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
|
|
69
|
+
createHistoryAuthChallenge(body: SwapHistoryAuthChallengeRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthChallengeRaw>;
|
|
70
|
+
verifyHistoryAuthChallenge(body: SwapHistoryAuthVerifyRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
71
|
+
getFromTokenRows(chainId: number, options?: ApiRequestOptions): Promise<SwapFromTokensDataRaw>;
|
|
72
|
+
getCrossChainToTokenRows(chainId: number, options?: ApiRequestOptions): Promise<SwapCrossChainToTokensDataRaw>;
|
|
69
73
|
private request;
|
|
70
74
|
private requestOnce;
|
|
71
75
|
private buildUrl;
|
|
@@ -89,7 +93,14 @@ interface McaDepositCollateral {
|
|
|
89
93
|
useAsCollateral: boolean;
|
|
90
94
|
}
|
|
91
95
|
interface McaWithdrawCollateral {
|
|
92
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated The SDK derives this value from decreaseAmountBurrow.
|
|
98
|
+
*
|
|
99
|
+
* Compatibility hint. The SDK derives the API's needDecreaseCollateral
|
|
100
|
+
* from decreaseAmountBurrow so contradictory values cannot be sent.
|
|
101
|
+
*/
|
|
102
|
+
needDecrease?: boolean;
|
|
103
|
+
/** Required collateral decrease: max(amountBurrow - suppliedBalance, 0). */
|
|
93
104
|
decreaseAmountBurrow: string;
|
|
94
105
|
withdrawAll?: boolean;
|
|
95
106
|
}
|
|
@@ -159,6 +170,10 @@ interface HistoryRequest {
|
|
|
159
170
|
page?: number;
|
|
160
171
|
pageSize?: number;
|
|
161
172
|
status?: HistoryStatus[];
|
|
173
|
+
/** Queries wallet-authorized confidential history. */
|
|
174
|
+
mode?: "confidential";
|
|
175
|
+
/** Token returned by the confidential history auth verify endpoint. */
|
|
176
|
+
walletToken?: string;
|
|
162
177
|
}
|
|
163
178
|
interface SwapHistoryPage {
|
|
164
179
|
items: SwapHistoryItem[];
|
|
@@ -191,12 +206,38 @@ interface SwapHistoryItem {
|
|
|
191
206
|
raw: SwapHistoryRecordRaw;
|
|
192
207
|
}
|
|
193
208
|
|
|
209
|
+
interface TokenListRequest {
|
|
210
|
+
/** Numeric ID accepted by the token-list endpoints. */
|
|
211
|
+
chainId: number;
|
|
212
|
+
}
|
|
213
|
+
interface SwapTokenListItem extends AssetRef {
|
|
214
|
+
chain: ChainRef;
|
|
215
|
+
/** Token identifier accepted by the unified quote API. */
|
|
216
|
+
address: string;
|
|
217
|
+
symbol: string;
|
|
218
|
+
decimals: number;
|
|
219
|
+
isNative: boolean;
|
|
220
|
+
tokenListChainId: number;
|
|
221
|
+
blockchain: string;
|
|
222
|
+
assetId: string;
|
|
223
|
+
contractAddress: string | null;
|
|
224
|
+
coinType: string | null;
|
|
225
|
+
name: string | null;
|
|
226
|
+
logoURI: string | null;
|
|
227
|
+
price: string | number | null;
|
|
228
|
+
priceUpdatedAt: number | null;
|
|
229
|
+
sources: string[];
|
|
230
|
+
raw: Record<string, unknown>;
|
|
231
|
+
}
|
|
232
|
+
|
|
194
233
|
interface SwapClientConfig extends ApiClientConfig {
|
|
195
234
|
maxQuoteAgeMs?: number | null;
|
|
196
235
|
reportMode?: "auto" | "manual" | "disabled";
|
|
197
236
|
executors?: readonly ChainExecutor[];
|
|
198
237
|
onEvent?: (event: SwapLifecycleEvent) => void;
|
|
199
238
|
now?: () => number;
|
|
239
|
+
/** Token-list cache lifetime in milliseconds. Defaults to 10 minutes; use 0 to disable. */
|
|
240
|
+
tokenListCacheTtlMs?: number;
|
|
200
241
|
}
|
|
201
242
|
interface BuildSwapInput {
|
|
202
243
|
quote: Quote;
|
|
@@ -212,12 +253,17 @@ declare class SwapClient {
|
|
|
212
253
|
private readonly now;
|
|
213
254
|
private readonly inFlight;
|
|
214
255
|
private readonly reportRequests;
|
|
256
|
+
private readonly tokenListCache;
|
|
257
|
+
private readonly tokenListInflight;
|
|
215
258
|
constructor(config: SwapClientConfig);
|
|
216
259
|
quoteRaw(request: SwapQuoteRequestRaw, options?: ApiRequestOptions): Promise<SwapQuoteDataRaw>;
|
|
217
260
|
quote(request: McaQuoteRequest, options?: ApiRequestOptions): Promise<McaQuote>;
|
|
218
261
|
quote(request: QuoteRequest, options?: ApiRequestOptions): Promise<Quote>;
|
|
219
262
|
private quoteStandard;
|
|
220
263
|
buildRaw(request: SwapBuildRequestRaw, options?: ApiRequestOptions): Promise<SwapBuildDataRaw>;
|
|
264
|
+
getFromTokens(request: TokenListRequest, options?: ApiRequestOptions): Promise<SwapTokenListItem[]>;
|
|
265
|
+
getCrossChainToTokens(request: TokenListRequest, options?: ApiRequestOptions): Promise<SwapTokenListItem[]>;
|
|
266
|
+
private loadTokenList;
|
|
221
267
|
buildSwap(input: BuildSwapInput): Promise<SwapBuild>;
|
|
222
268
|
private buildStandardSwap;
|
|
223
269
|
executeSwap(input: ExecuteSwapInput): Promise<SwapExecutionResult>;
|
|
@@ -236,6 +282,9 @@ declare class SwapClient {
|
|
|
236
282
|
report(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
|
|
237
283
|
retryReport(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
|
|
238
284
|
getHistoryRaw(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
|
|
285
|
+
createHistoryAuthChallenge(request: SwapHistoryAuthChallengeRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthChallengeRaw>;
|
|
286
|
+
verifyHistoryAuthChallenge(request: SwapHistoryAuthVerifyRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
287
|
+
authorizeConfidentialHistory(request: SwapHistoryAuthChallengeRequestRaw, signChallenge: (challenge: SwapHistoryAuthChallengeRaw) => SwapHistoryAuthProofRaw | Promise<SwapHistoryAuthProofRaw>, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
239
288
|
getHistory(request: HistoryRequest, options?: ApiRequestOptions): Promise<SwapHistoryPage>;
|
|
240
289
|
protected emit(event: SwapLifecycleEvent): void;
|
|
241
290
|
private assertQuoteFresh;
|
|
@@ -255,15 +304,42 @@ declare function normalizeHistoryStatus(status: unknown): HistoryStatus;
|
|
|
255
304
|
declare function serializeQuoteRequest(request: QuoteRequest): SwapQuoteRequestRaw;
|
|
256
305
|
declare function normalizeQuote(request: QuoteRequest, raw: SwapQuoteDataRaw, receivedAt?: number): Quote;
|
|
257
306
|
|
|
307
|
+
declare function normalizeFromTokenList(raw: SwapFromTokensDataRaw, chainId: number): SwapTokenListItem[];
|
|
308
|
+
declare function normalizeCrossChainToTokenList(raw: SwapCrossChainToTokensDataRaw, chainId: number): SwapTokenListItem[];
|
|
309
|
+
|
|
258
310
|
interface ResolveMcaWithdrawPolicyInput {
|
|
259
|
-
|
|
311
|
+
/** Requested withdraw amount in Burrow internal decimals. */
|
|
312
|
+
amountBurrow: string;
|
|
313
|
+
/** Current supplied balance for the token in Burrow internal decimals. */
|
|
314
|
+
suppliedBalance: string;
|
|
260
315
|
availableBalance: string;
|
|
316
|
+
/** Human/display withdraw amount, in the same precision as availableBalance. */
|
|
261
317
|
amountIn: string;
|
|
262
318
|
isMax: boolean;
|
|
263
319
|
}
|
|
264
320
|
declare function resolveMcaWithdrawPolicy(input: ResolveMcaWithdrawPolicyInput): McaWithdrawCollateral & {
|
|
321
|
+
needDecrease: boolean;
|
|
265
322
|
withdrawAll: boolean;
|
|
266
323
|
};
|
|
324
|
+
interface ResolveMcaRequiredCollateralDecreaseInput {
|
|
325
|
+
amountBurrow: string;
|
|
326
|
+
suppliedBalance: string;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Matches Lending Withdraw and multi-chain-lending's 2026-08-20 hotfix:
|
|
330
|
+
* only the part of the requested withdraw that exceeds supplied balance must
|
|
331
|
+
* be removed from collateral.
|
|
332
|
+
*/
|
|
333
|
+
declare function resolveMcaRequiredCollateralDecrease(input: ResolveMcaRequiredCollateralDecreaseInput): Pick<McaWithdrawCollateral, "needDecrease" | "decreaseAmountBurrow"> & {
|
|
334
|
+
needDecrease: boolean;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Derive needDecreaseCollateral from an already-computed required decrease and
|
|
338
|
+
* serialize it in canonical, non-exponential decimal form.
|
|
339
|
+
*/
|
|
340
|
+
declare function resolveMcaDecreaseCollateral(decreaseAmountBurrow: string, field?: string): Pick<McaWithdrawCollateral, "needDecrease" | "decreaseAmountBurrow"> & {
|
|
341
|
+
needDecrease: boolean;
|
|
342
|
+
};
|
|
267
343
|
|
|
268
344
|
declare function serializeMcaQuoteRequest(request: McaQuoteRequest, signer: McaSignerIdentity): SwapQuoteRequestRaw;
|
|
269
345
|
declare function normalizeMcaQuote(request: McaQuoteRequest, signer: McaSignerIdentity, quote: Quote): McaQuote;
|
|
@@ -304,4 +380,4 @@ declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRe
|
|
|
304
380
|
declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
|
|
305
381
|
declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
|
|
306
382
|
|
|
307
|
-
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, WaitForOrderInput, WaitMode, asSwapSdkError, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, parseUnits, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
|
|
383
|
+
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { S as SwapQuoteRequestRaw, a as SwapQuoteDataRaw, b as SwapBuildRequestRaw, c as SwapBuildDataRaw, d as SwapOrderSubmitRequestRaw, e as SwapOrderSubmitDataRaw, f as SwapOrderStatusParamsRaw, g as SwapOrderStatusDataRaw, h as SwapReportRequestRaw, i as SwapReportDataRaw, j as SwapHistoryParamsRaw, k as SwapHistoryDataRaw, Q as QuoteRequest,
|
|
2
|
-
export {
|
|
1
|
+
import { S as SwapQuoteRequestRaw, a as SwapQuoteDataRaw, b as SwapBuildRequestRaw, c as SwapBuildDataRaw, d as SwapOrderSubmitRequestRaw, e as SwapOrderSubmitDataRaw, f as SwapOrderStatusParamsRaw, g as SwapOrderStatusDataRaw, h as SwapReportRequestRaw, i as SwapReportDataRaw, j as SwapHistoryParamsRaw, k as SwapHistoryDataRaw, l as SwapHistoryAuthChallengeRequestRaw, m as SwapHistoryAuthChallengeRaw, n as SwapHistoryAuthVerifyRequestRaw, o as SwapHistoryAuthTokenRaw, p as SwapFromTokensDataRaw, q as SwapCrossChainToTokensDataRaw, Q as QuoteRequest, r as Quote, s as SwapMcaPayloadRaw, W as WaitMode, O as OrderPollingOptions, t as SwapLifecycleEvent, u as SwapExecutionResult, C as ChainRef, A as AssetRef, B as BaseUnitAmount, v as SwapHistoryRecordRaw, w as ChainExecutor, E as ExecutorRegistry, x as SwapBuild, y as ExecuteSwapInput, z as SwapInput, D as OrderStatusResult, F as WaitForOrderInput, G as SwapHistoryAuthProofRaw, N as NearTransaction, H as SwapMcaRelayerRequestRaw } from './shared-COkGiqaz.js';
|
|
2
|
+
export { ac as BuildContext, Z as ChainExecutionResult, a8 as DepositInfo, a4 as EvmApproval, a5 as EvmSigningRequest, a3 as EvmTx, _ as ExecutionContext, a0 as ExecutorIdentityProvider, a1 as ExecutorMessageSigner, $ as MessageSignOptions, a7 as OrderReference, X as OrderStatus, ab as RouteSummary, V as SignRequestPreview, a6 as SolanaMetadata, I as SwapApiResponse, J as SwapApiTokenMetaRaw, P as SwapBuildApproveRaw, aa as SwapExecution, R as SwapHistoryWalletChainFamilyRaw, L as SwapMcaSignerPayloadRaw, a9 as SwapReportContext, M as SwapSigningRequestRaw, K as SwapTokenListRowRaw, U as SwapWarning, T as TransactionConfirmation, a2 as assertBaseUnitAmount, Y as normalizeOrderStatus } from './shared-COkGiqaz.js';
|
|
3
3
|
|
|
4
4
|
type SwapErrorCode = "HTTP_ERROR" | "API_ERROR" | "RATE_LIMITED" | "AUTH_FAILED" | "REQUEST_ABORTED" | "REQUEST_TIMEOUT" | "INVALID_REQUEST" | "INVALID_API_RESPONSE" | "QUOTE_EXPIRED" | "ROUTE_NOT_FOUND" | "EXECUTOR_NOT_FOUND" | "UNSUPPORTED_CHAIN" | "CHAIN_MISMATCH" | "INVALID_TRANSACTION" | "USER_REJECTED" | "INSUFFICIENT_BALANCE" | "APPROVAL_FAILED" | "SIGNING_FAILED" | "BROADCAST_FAILED" | "ORDER_SUBMIT_FAILED" | "ORDER_TIMEOUT" | "REPORT_FAILED";
|
|
5
|
-
type SwapErrorStage = "quote" | "build" | "approve" | "sign" | "broadcast" | "submit" | "report" | "status" | "history";
|
|
5
|
+
type SwapErrorStage = "quote" | "build" | "approve" | "sign" | "broadcast" | "submit" | "report" | "status" | "tokens" | "history";
|
|
6
6
|
interface SwapSdkErrorOptions {
|
|
7
7
|
retryable?: boolean;
|
|
8
8
|
cause?: unknown;
|
|
@@ -66,6 +66,10 @@ declare class ApiClient {
|
|
|
66
66
|
getOrderStatus(params: SwapOrderStatusParamsRaw, options?: ApiRequestOptions): Promise<SwapOrderStatusDataRaw>;
|
|
67
67
|
report(body: SwapReportRequestRaw, options?: ApiRequestOptions): Promise<SwapReportDataRaw>;
|
|
68
68
|
getHistory(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
|
|
69
|
+
createHistoryAuthChallenge(body: SwapHistoryAuthChallengeRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthChallengeRaw>;
|
|
70
|
+
verifyHistoryAuthChallenge(body: SwapHistoryAuthVerifyRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
71
|
+
getFromTokenRows(chainId: number, options?: ApiRequestOptions): Promise<SwapFromTokensDataRaw>;
|
|
72
|
+
getCrossChainToTokenRows(chainId: number, options?: ApiRequestOptions): Promise<SwapCrossChainToTokensDataRaw>;
|
|
69
73
|
private request;
|
|
70
74
|
private requestOnce;
|
|
71
75
|
private buildUrl;
|
|
@@ -89,7 +93,14 @@ interface McaDepositCollateral {
|
|
|
89
93
|
useAsCollateral: boolean;
|
|
90
94
|
}
|
|
91
95
|
interface McaWithdrawCollateral {
|
|
92
|
-
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated The SDK derives this value from decreaseAmountBurrow.
|
|
98
|
+
*
|
|
99
|
+
* Compatibility hint. The SDK derives the API's needDecreaseCollateral
|
|
100
|
+
* from decreaseAmountBurrow so contradictory values cannot be sent.
|
|
101
|
+
*/
|
|
102
|
+
needDecrease?: boolean;
|
|
103
|
+
/** Required collateral decrease: max(amountBurrow - suppliedBalance, 0). */
|
|
93
104
|
decreaseAmountBurrow: string;
|
|
94
105
|
withdrawAll?: boolean;
|
|
95
106
|
}
|
|
@@ -159,6 +170,10 @@ interface HistoryRequest {
|
|
|
159
170
|
page?: number;
|
|
160
171
|
pageSize?: number;
|
|
161
172
|
status?: HistoryStatus[];
|
|
173
|
+
/** Queries wallet-authorized confidential history. */
|
|
174
|
+
mode?: "confidential";
|
|
175
|
+
/** Token returned by the confidential history auth verify endpoint. */
|
|
176
|
+
walletToken?: string;
|
|
162
177
|
}
|
|
163
178
|
interface SwapHistoryPage {
|
|
164
179
|
items: SwapHistoryItem[];
|
|
@@ -191,12 +206,38 @@ interface SwapHistoryItem {
|
|
|
191
206
|
raw: SwapHistoryRecordRaw;
|
|
192
207
|
}
|
|
193
208
|
|
|
209
|
+
interface TokenListRequest {
|
|
210
|
+
/** Numeric ID accepted by the token-list endpoints. */
|
|
211
|
+
chainId: number;
|
|
212
|
+
}
|
|
213
|
+
interface SwapTokenListItem extends AssetRef {
|
|
214
|
+
chain: ChainRef;
|
|
215
|
+
/** Token identifier accepted by the unified quote API. */
|
|
216
|
+
address: string;
|
|
217
|
+
symbol: string;
|
|
218
|
+
decimals: number;
|
|
219
|
+
isNative: boolean;
|
|
220
|
+
tokenListChainId: number;
|
|
221
|
+
blockchain: string;
|
|
222
|
+
assetId: string;
|
|
223
|
+
contractAddress: string | null;
|
|
224
|
+
coinType: string | null;
|
|
225
|
+
name: string | null;
|
|
226
|
+
logoURI: string | null;
|
|
227
|
+
price: string | number | null;
|
|
228
|
+
priceUpdatedAt: number | null;
|
|
229
|
+
sources: string[];
|
|
230
|
+
raw: Record<string, unknown>;
|
|
231
|
+
}
|
|
232
|
+
|
|
194
233
|
interface SwapClientConfig extends ApiClientConfig {
|
|
195
234
|
maxQuoteAgeMs?: number | null;
|
|
196
235
|
reportMode?: "auto" | "manual" | "disabled";
|
|
197
236
|
executors?: readonly ChainExecutor[];
|
|
198
237
|
onEvent?: (event: SwapLifecycleEvent) => void;
|
|
199
238
|
now?: () => number;
|
|
239
|
+
/** Token-list cache lifetime in milliseconds. Defaults to 10 minutes; use 0 to disable. */
|
|
240
|
+
tokenListCacheTtlMs?: number;
|
|
200
241
|
}
|
|
201
242
|
interface BuildSwapInput {
|
|
202
243
|
quote: Quote;
|
|
@@ -212,12 +253,17 @@ declare class SwapClient {
|
|
|
212
253
|
private readonly now;
|
|
213
254
|
private readonly inFlight;
|
|
214
255
|
private readonly reportRequests;
|
|
256
|
+
private readonly tokenListCache;
|
|
257
|
+
private readonly tokenListInflight;
|
|
215
258
|
constructor(config: SwapClientConfig);
|
|
216
259
|
quoteRaw(request: SwapQuoteRequestRaw, options?: ApiRequestOptions): Promise<SwapQuoteDataRaw>;
|
|
217
260
|
quote(request: McaQuoteRequest, options?: ApiRequestOptions): Promise<McaQuote>;
|
|
218
261
|
quote(request: QuoteRequest, options?: ApiRequestOptions): Promise<Quote>;
|
|
219
262
|
private quoteStandard;
|
|
220
263
|
buildRaw(request: SwapBuildRequestRaw, options?: ApiRequestOptions): Promise<SwapBuildDataRaw>;
|
|
264
|
+
getFromTokens(request: TokenListRequest, options?: ApiRequestOptions): Promise<SwapTokenListItem[]>;
|
|
265
|
+
getCrossChainToTokens(request: TokenListRequest, options?: ApiRequestOptions): Promise<SwapTokenListItem[]>;
|
|
266
|
+
private loadTokenList;
|
|
221
267
|
buildSwap(input: BuildSwapInput): Promise<SwapBuild>;
|
|
222
268
|
private buildStandardSwap;
|
|
223
269
|
executeSwap(input: ExecuteSwapInput): Promise<SwapExecutionResult>;
|
|
@@ -236,6 +282,9 @@ declare class SwapClient {
|
|
|
236
282
|
report(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
|
|
237
283
|
retryReport(result: SwapExecutionResult): Promise<SwapReportDataRaw>;
|
|
238
284
|
getHistoryRaw(params: SwapHistoryParamsRaw, options?: ApiRequestOptions): Promise<SwapHistoryDataRaw>;
|
|
285
|
+
createHistoryAuthChallenge(request: SwapHistoryAuthChallengeRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthChallengeRaw>;
|
|
286
|
+
verifyHistoryAuthChallenge(request: SwapHistoryAuthVerifyRequestRaw, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
287
|
+
authorizeConfidentialHistory(request: SwapHistoryAuthChallengeRequestRaw, signChallenge: (challenge: SwapHistoryAuthChallengeRaw) => SwapHistoryAuthProofRaw | Promise<SwapHistoryAuthProofRaw>, options?: ApiRequestOptions): Promise<SwapHistoryAuthTokenRaw>;
|
|
239
288
|
getHistory(request: HistoryRequest, options?: ApiRequestOptions): Promise<SwapHistoryPage>;
|
|
240
289
|
protected emit(event: SwapLifecycleEvent): void;
|
|
241
290
|
private assertQuoteFresh;
|
|
@@ -255,15 +304,42 @@ declare function normalizeHistoryStatus(status: unknown): HistoryStatus;
|
|
|
255
304
|
declare function serializeQuoteRequest(request: QuoteRequest): SwapQuoteRequestRaw;
|
|
256
305
|
declare function normalizeQuote(request: QuoteRequest, raw: SwapQuoteDataRaw, receivedAt?: number): Quote;
|
|
257
306
|
|
|
307
|
+
declare function normalizeFromTokenList(raw: SwapFromTokensDataRaw, chainId: number): SwapTokenListItem[];
|
|
308
|
+
declare function normalizeCrossChainToTokenList(raw: SwapCrossChainToTokensDataRaw, chainId: number): SwapTokenListItem[];
|
|
309
|
+
|
|
258
310
|
interface ResolveMcaWithdrawPolicyInput {
|
|
259
|
-
|
|
311
|
+
/** Requested withdraw amount in Burrow internal decimals. */
|
|
312
|
+
amountBurrow: string;
|
|
313
|
+
/** Current supplied balance for the token in Burrow internal decimals. */
|
|
314
|
+
suppliedBalance: string;
|
|
260
315
|
availableBalance: string;
|
|
316
|
+
/** Human/display withdraw amount, in the same precision as availableBalance. */
|
|
261
317
|
amountIn: string;
|
|
262
318
|
isMax: boolean;
|
|
263
319
|
}
|
|
264
320
|
declare function resolveMcaWithdrawPolicy(input: ResolveMcaWithdrawPolicyInput): McaWithdrawCollateral & {
|
|
321
|
+
needDecrease: boolean;
|
|
265
322
|
withdrawAll: boolean;
|
|
266
323
|
};
|
|
324
|
+
interface ResolveMcaRequiredCollateralDecreaseInput {
|
|
325
|
+
amountBurrow: string;
|
|
326
|
+
suppliedBalance: string;
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Matches Lending Withdraw and multi-chain-lending's 2026-08-20 hotfix:
|
|
330
|
+
* only the part of the requested withdraw that exceeds supplied balance must
|
|
331
|
+
* be removed from collateral.
|
|
332
|
+
*/
|
|
333
|
+
declare function resolveMcaRequiredCollateralDecrease(input: ResolveMcaRequiredCollateralDecreaseInput): Pick<McaWithdrawCollateral, "needDecrease" | "decreaseAmountBurrow"> & {
|
|
334
|
+
needDecrease: boolean;
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* Derive needDecreaseCollateral from an already-computed required decrease and
|
|
338
|
+
* serialize it in canonical, non-exponential decimal form.
|
|
339
|
+
*/
|
|
340
|
+
declare function resolveMcaDecreaseCollateral(decreaseAmountBurrow: string, field?: string): Pick<McaWithdrawCollateral, "needDecrease" | "decreaseAmountBurrow"> & {
|
|
341
|
+
needDecrease: boolean;
|
|
342
|
+
};
|
|
267
343
|
|
|
268
344
|
declare function serializeMcaQuoteRequest(request: McaQuoteRequest, signer: McaSignerIdentity): SwapQuoteRequestRaw;
|
|
269
345
|
declare function normalizeMcaQuote(request: McaQuoteRequest, signer: McaSignerIdentity, quote: Quote): McaQuote;
|
|
@@ -304,4 +380,4 @@ declare function buildMcaWithdrawRelayerRequest(input: BuildMcaWithdrawRelayerRe
|
|
|
304
380
|
declare function parseUnits(value: string, decimals: number): BaseUnitAmount;
|
|
305
381
|
declare function formatUnits(value: BaseUnitAmount, decimals: number): string;
|
|
306
382
|
|
|
307
|
-
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, WaitForOrderInput, WaitMode, asSwapSdkError, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, parseUnits, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
|
|
383
|
+
export { ApiClient, type ApiClientConfig, type ApiRequestOptions, AssetRef, BaseUnitAmount, type BuildMcaWithdrawRelayerRequestInput, type BuildNearMcaWithdrawTransactionsInput, type BuildSwapInput, ChainExecutor, ChainRef, DEFAULT_MCA_SIGNER_PRIORITY, ExecuteSwapInput, ExecutorRegistry, type ExtractMcaWithdrawDepositAddressInput, type HistoryRequest, type HistoryStatus, type McaDepositCollateral, type McaDepositQuote, type McaDepositQuoteRequest, type McaFlow, type McaQuote, type McaQuoteRequest, type McaSignerChain, type McaSignerIdentity, type McaSwapInput, type McaSwapResult, type McaWalletDescriptor, type McaWalletKey, type McaWithdrawCollateral, type McaWithdrawNearQuote, type McaWithdrawQuoteRequest, type McaWithdrawRelayerQuote, NearTransaction, OrderPollingOptions, OrderStatusResult, Quote, QuoteRequest, type ResolveMcaRequiredCollateralDecreaseInput, type ResolveMcaWithdrawPolicyInput, type RetryConfig, type SdkLogEntry, type SdkLogLevel, type SdkLogger, SwapBuild, SwapBuildDataRaw, SwapBuildRequestRaw, SwapClient, type SwapClientConfig, SwapCrossChainToTokensDataRaw, type SwapErrorCode, type SwapErrorStage, SwapExecutionResult, SwapFromTokensDataRaw, SwapHistoryAuthChallengeRaw, SwapHistoryAuthChallengeRequestRaw, SwapHistoryAuthProofRaw, SwapHistoryAuthTokenRaw, SwapHistoryAuthVerifyRequestRaw, SwapHistoryDataRaw, type SwapHistoryItem, type SwapHistoryPage, SwapHistoryParamsRaw, SwapHistoryRecordRaw, SwapInput, SwapLifecycleEvent, SwapMcaPayloadRaw, SwapMcaRelayerRequestRaw, SwapOrderStatusDataRaw, SwapOrderStatusParamsRaw, SwapOrderSubmitDataRaw, SwapOrderSubmitRequestRaw, SwapQuoteDataRaw, SwapQuoteRequestRaw, SwapReportDataRaw, SwapReportRequestRaw, SwapSdkError, type SwapSdkErrorOptions, type SwapTokenListItem, type TokenListRequest, WaitForOrderInput, WaitMode, asSwapSdkError, buildMcaWithdrawRelayerRequest, buildNearMcaWithdrawTransactions, createExecutionId, extractMcaWithdrawBusiness, extractMcaWithdrawDepositAddress, extractMcaWithdrawSignerWallet, formatMcaWallet, formatUnits, fromApiChain, isSameMcaSignerIdentity, normalizeBuild, normalizeCrossChainToTokenList, normalizeFromTokenList, normalizeHistory, normalizeHistoryStatus, normalizeMcaQuote, normalizeQuote, parseUnits, resolveMcaDecreaseCollateral, resolveMcaRequiredCollateralDecrease, resolveMcaWithdrawPolicy, selectMcaSigner, serializeMcaQuoteRequest, serializeQuoteRequest, toApiAssetAddress, toApiChain };
|