@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.
Files changed (42) hide show
  1. package/README.md +207 -77
  2. package/dist/executors/aptos.d.mts +1 -1
  3. package/dist/executors/aptos.d.ts +1 -1
  4. package/dist/executors/aptos.js.map +1 -1
  5. package/dist/executors/aptos.mjs.map +1 -1
  6. package/dist/executors/bitcoin.d.mts +1 -1
  7. package/dist/executors/bitcoin.d.ts +1 -1
  8. package/dist/executors/bitcoin.js.map +1 -1
  9. package/dist/executors/bitcoin.mjs.map +1 -1
  10. package/dist/executors/evm.d.mts +1 -1
  11. package/dist/executors/evm.d.ts +1 -1
  12. package/dist/executors/evm.js.map +1 -1
  13. package/dist/executors/evm.mjs.map +1 -1
  14. package/dist/executors/near.d.mts +1 -1
  15. package/dist/executors/near.d.ts +1 -1
  16. package/dist/executors/near.js.map +1 -1
  17. package/dist/executors/near.mjs.map +1 -1
  18. package/dist/executors/solana.d.mts +1 -1
  19. package/dist/executors/solana.d.ts +1 -1
  20. package/dist/executors/solana.js.map +1 -1
  21. package/dist/executors/solana.mjs.map +1 -1
  22. package/dist/executors/sui.d.mts +1 -1
  23. package/dist/executors/sui.d.ts +1 -1
  24. package/dist/executors/sui.js.map +1 -1
  25. package/dist/executors/sui.mjs.map +1 -1
  26. package/dist/executors/tron.d.mts +1 -1
  27. package/dist/executors/tron.d.ts +1 -1
  28. package/dist/executors/tron.js.map +1 -1
  29. package/dist/executors/tron.mjs.map +1 -1
  30. package/dist/executors/zcash.d.mts +1 -1
  31. package/dist/executors/zcash.d.ts +1 -1
  32. package/dist/executors/zcash.js.map +1 -1
  33. package/dist/executors/zcash.mjs.map +1 -1
  34. package/dist/index.d.mts +82 -6
  35. package/dist/index.d.ts +82 -6
  36. package/dist/index.js +454 -71
  37. package/dist/index.js.map +1 -1
  38. package/dist/index.mjs +451 -72
  39. package/dist/index.mjs.map +1 -1
  40. package/dist/{shared-D0_DbMT2.d.mts → shared-COkGiqaz.d.mts} +84 -2
  41. package/dist/{shared-D0_DbMT2.d.ts → shared-COkGiqaz.d.ts} +84 -2
  42. package/package.json +1 -1
package/README.md CHANGED
@@ -8,85 +8,113 @@ Supported chain families: EVM, Solana, Aptos, NEAR, Tron, Bitcoin, Zcash, and Su
8
8
 
9
9
  ## Supported chains and tokens
10
10
 
11
- The product support list matches `multi-chain-lending` Trade: **18 mainnets**. Use the HTTP API chain ID for `fromChain` / `toChain` in Swap calls, and the token-query alias when fetching token metadata.
12
-
13
- | Chain | Type | HTTP / SDK chain ID | Token query alias |
14
- | --- | --- | --- | --- |
15
- | Ethereum | EVM | `1` | `eth` |
16
- | BNB Smart Chain | EVM | `56` | `bsc` |
17
- | Arbitrum One | EVM | `42161` | `arb` |
18
- | Base | EVM | `8453` | `base` |
19
- | Optimism | EVM | `10` | `op` |
20
- | Berachain | EVM | `1385` | `bera` |
21
- | Monad | EVM | `143` | `monad` |
22
- | X Layer | EVM | `196` | `xlayer` |
23
- | Polygon PoS | EVM | `137` | `pol` |
24
- | Gnosis Chain | EVM | `100` | `gnosis` |
25
- | Plasma | EVM | `9745` | `plasma` |
26
- | Solana | Non-EVM | `solana` | `sol` |
27
- | Bitcoin | Non-EVM | `btc` | `btc` |
28
- | NEAR | Non-EVM | `near` | `near` |
29
- | Zcash | Non-EVM | `zcash` | `zcash` (also accepts `zec`) |
30
- | Aptos | Non-EVM | `aptos` | `aptos` |
31
- | Tron | Non-EVM | `tron` | `tron` |
32
- | Sui | Non-EVM | `sui` | `sui` |
11
+ The product support list matches `multi-chain-lending` Trade: **25 mainnets**. Use the HTTP API chain ID for `fromChain` / `toChain` in Swap calls. Token-list endpoints use the separate numeric ID shown below; for EVM chains the two IDs are the same.
12
+
13
+ | Chain | Type | HTTP / SDK chain ID | Token-list chain ID | `blockchain` alias |
14
+ | --- | --- | --- | --- | --- |
15
+ | Ethereum | EVM | `1` | `1` | `eth` |
16
+ | Optimism | EVM | `10` | `10` | `op` |
17
+ | Avalanche | EVM | `43114` | `43114` | `avax` |
18
+ | Robinhood Chain | EVM | `4663` | `4663` | `robinhood` |
19
+ | Katana | EVM | `747474` | `747474` | `katana` |
20
+ | Sonic | EVM | `146` | `146` | `sonic` |
21
+ | Unichain | EVM | `130` | `130` | `unichain` |
22
+ | Pharos | EVM | `1672` | `1672` | `pharos` |
23
+ | Tempo | EVM | `4217` | `4217` | `tempo` |
24
+ | BNB Smart Chain | EVM | `56` | `56` | `bsc` |
25
+ | Gnosis Chain | EVM | `100` | `100` | `gnosis` |
26
+ | Polygon PoS | EVM | `137` | `137` | `pol` |
27
+ | Monad | EVM | `143` | `143` | `monad` |
28
+ | X Layer | EVM | `196` | `196` | `xlayer` |
29
+ | Base | EVM | `8453` | `8453` | `base` |
30
+ | Plasma | EVM | `9745` | `9745` | `plasma` |
31
+ | Arbitrum One | EVM | `42161` | `42161` | `arb` |
32
+ | Berachain | EVM | `80094` | `80094` | `bera` |
33
+ | Tron | Non-EVM | `tron` | `195` | `tron` |
34
+ | Solana | Non-EVM | `solana` | `501` | `sol` |
35
+ | Sui | Non-EVM | `sui` | `784` | `sui` |
36
+ | NEAR | Non-EVM | `near` | `900001` | `near` |
37
+ | Bitcoin | Non-EVM | `btc` | `900002` | `btc` |
38
+ | Zcash | Non-EVM | `zcash` | `900010` | `zec` |
39
+ | Aptos | Non-EVM | `aptos` | `900012` | `aptos` |
33
40
 
34
41
  "Supported" means the product can load tokens for that chain and send them into the unified quote flow. It does **not** guarantee a route for every pair. Live liquidity, routers, amount, and service status still decide whether a quote succeeds.
35
42
 
36
43
  ### Token coverage (Unified Swap)
37
44
 
38
- Across the 18 product chains above, Unified Swap currently covers **4,000+** tokens (same-chain DEX metadata plus cross-chain Intents tokens, deduplicated per direction). Snapshot: 2026-07-24. Counts change as liquidity providers and Intents listings update; always fetch the live token APIs below for the current list.
45
+ Token coverage is dynamic and direction-specific. The from-token list combines same-chain routing metadata with cross-chain-capable assets, while the cross-chain to-token list is maintained independently. Do not hard-code a token count or assume every from token can also be selected as a cross-chain destination; fetch both live endpoints described below.
39
46
 
40
- ### How to fetch supported tokens
47
+ ### How to load supported tokens
41
48
 
42
- Token discovery uses HTTP endpoints **outside** `/api/swap/*`. The SDK does not wrap these calls; applications should `fetch` them directly and map results into `AssetRef` when calling `client.quote()`.
49
+ Use the SDK methods for application selectors. Both methods return the same normalized `SwapTokenListItem[]` shape, even though the two HTTP endpoints have different raw response formats:
43
50
 
44
- #### 1. Product token list (recommended for Trade UI)
51
+ ```ts
52
+ const fromTokens = await client.getFromTokens({ chainId: 8453 });
53
+ const crossChainToTokens = await client.getCrossChainToTokens({ chainId: 501 });
45
54
 
46
- ```http
47
- GET https://api.rhea.finance/get_multichain_lending_tokens_data?chains=<COMMA_SEPARATED_ALIASES>
55
+ const tokenIn = fromTokens.find((token) => token.symbol === "USDC")!;
56
+ const tokenOut = crossChainToTokens.find((token) => token.symbol === "USDC")!;
57
+
58
+ const quote = await client.quote({
59
+ fromChain: tokenIn.chain,
60
+ toChain: tokenOut.chain,
61
+ tokenIn,
62
+ tokenOut,
63
+ amountIn: "1000000",
64
+ slippageBps: 50,
65
+ sender: "0x...",
66
+ recipient: "...",
67
+ });
48
68
  ```
49
69
 
50
- Query all currently supported product chains:
70
+ `chainId` is the numeric **token-list chain ID** from the table above. For same-chain tokenOut, reuse `getFromTokens`; call `getCrossChainToTokens` only for a destination on another chain.
51
71
 
52
- ```bash
53
- curl "https://api.rhea.finance/get_multichain_lending_tokens_data?chains=bsc,eth,arb,base,op,bera,monad,xlayer,pol,gnosis,plasma,sol,btc,near,zcash,zec,aptos,tron,sui"
54
- ```
72
+ The normalized item extends `AssetRef`:
55
73
 
56
- A successful response is a **JSON array** of token objects (not the `/api/swap` `{ code, data, msg }` envelope). Typical fields:
74
+ ```ts
75
+ interface SwapTokenListItem extends AssetRef {
76
+ chain: ChainRef;
77
+ address: string;
78
+ symbol: string;
79
+ decimals: number;
80
+ isNative: boolean;
81
+ tokenListChainId: number;
82
+ blockchain: string;
83
+ assetId: string;
84
+ contractAddress: string | null;
85
+ coinType: string | null;
86
+ name: string | null;
87
+ logoURI: string | null;
88
+ price: string | number | null;
89
+ priceUpdatedAt: number | null;
90
+ sources: string[];
91
+ raw: Record<string, unknown>;
92
+ }
93
+ ```
57
94
 
58
- | Field | Description |
59
- | --- | --- |
60
- | `assetId` | Multichain / Intents asset ID |
61
- | `blockchain` | Token query alias (`eth`, `near`, …) |
62
- | `symbol` | Display symbol |
63
- | `decimals` | Token decimals |
64
- | `contractAddress` | On-chain address; may be empty for natives |
65
- | `price` / `priceUpdatedAt` | Display price only; not a swap quote |
66
- | `icon` | Optional icon URL |
95
+ `address` and `assetId` contain the identifier accepted by the unified quote API. `contractAddress` separately preserves the on-chain contract/mint when available and is `null` for native assets. Unknown backend fields remain available in `raw`.
67
96
 
68
- Integration tips:
97
+ The methods cache successful lists for 10 minutes per direction and chain, and merge concurrent identical loads. Failures are never cached. Configure `tokenListCacheTtlMs`, or set it to `0` to disable caching. Requests with an `AbortSignal` are not shared with another caller.
69
98
 
70
- - Group by `blockchain`; do not merge tokens by `symbol` alone.
71
- - For `quote()`, pass the chain-specific token address/ID as `AssetRef.address`, and use the HTTP/SDK chain ID in `fromChain` / `toChain` / `AssetRef.chain` (for example Base `"8453"`, Solana `"solana"`).
72
- - Presence in this list means the token is discoverable. Confirm a route with `client.quote()` (or `POST /api/swap/quote`) before trading.
73
- - Prefer short-lived cache; refresh periodically instead of hard-coding the list.
99
+ The corresponding HTTP endpoints are documented below for server integrations that do not use the SDK.
74
100
 
75
- #### 2. Per-chain token price metadata
101
+ #### 1. From-token list
76
102
 
77
103
  ```http
78
- GET https://api.rhea.finance/get_chain_prices?chain=<TOKEN_QUERY_ALIAS>
104
+ GET https://api.rhea.finance/get_chain_prices?chain=<NUMERIC_CHAIN_ID>
79
105
  ```
80
106
 
81
107
  Example:
82
108
 
83
109
  ```bash
84
- curl "https://api.rhea.finance/get_chain_prices?chain=eth"
85
- curl "https://api.rhea.finance/get_chain_prices?chain=bsc"
86
- curl "https://api.rhea.finance/get_chain_prices?chain=base"
110
+ curl "https://api.rhea.finance/get_chain_prices?chain=1"
111
+ curl "https://api.rhea.finance/get_chain_prices?chain=56"
112
+ curl "https://api.rhea.finance/get_chain_prices?chain=8453"
87
113
  ```
88
114
 
89
- `chain` is required and must be a **token query alias** (`eth`, `bsc`, `base`, …). A successful response uses `{ code, data, msg }`:
115
+ `chain` is required and uses the token-list registry's numeric ID. EVM chains use their normal chain ID. Common non-EVM IDs are Solana `501`, Tron `195`, Sui `784`, NEAR `900001`, Bitcoin `900002`, Zcash `900010`, and Aptos `900012`.
116
+
117
+ A successful response uses `{ code, data, msg }`:
90
118
 
91
119
  ```ts
92
120
  // code === 0 && msg === "success"
@@ -109,7 +137,50 @@ type ChainPricesResponse = {
109
137
  };
110
138
  ```
111
139
 
112
- Use this endpoint for same-chain token metadata and display prices. It is keyed by token address. It does not replace `get_multichain_lending_tokens_data` for the full multi-chain Trade selector, and some non-EVM aliases may return an empty `data` object.
140
+ Use every returned row as the chain's from-token list. The same list is also used for tokenOut when the source and destination chains are the same.
141
+
142
+ #### 2. Cross-chain to-token list
143
+
144
+ ```http
145
+ GET https://api.rhea.finance/api/swap/supported_to_tokens?chain=<NUMERIC_CHAIN_ID>
146
+ ```
147
+
148
+ Example:
149
+
150
+ ```bash
151
+ curl "https://api.rhea.finance/api/swap/supported_to_tokens?chain=8453"
152
+ ```
153
+
154
+ The response uses the standard envelope and returns the final destination list in `data.tokens`:
155
+
156
+ ```ts
157
+ type SupportedToTokensResponse = {
158
+ code: number;
159
+ msg: string;
160
+ data: {
161
+ tokens: Array<{
162
+ address?: string;
163
+ assetId?: string;
164
+ symbol: string;
165
+ decimals: number;
166
+ logoURI?: string;
167
+ price?: string | number;
168
+ isNative?: boolean;
169
+ coinType?: string;
170
+ sources?: string[];
171
+ }>;
172
+ };
173
+ };
174
+ ```
175
+
176
+ Use this endpoint only when tokenOut is on a different chain from tokenIn. The returned rows are already the final supported tokenOut list; do not filter them again with legacy `crossChainTo` or `sameChain` flags.
177
+
178
+ Integration rules:
179
+
180
+ - Never build both selectors from one combined token list.
181
+ - Do not merge tokens by symbol alone; use chain plus address, asset ID, or coin type.
182
+ - Pass the selected normalized token to `client.quote()` and still confirm route availability with the quote API.
183
+ - Invalidate a selected cross-chain tokenOut if a refreshed destination list no longer contains its chain and `address` pair.
113
184
 
114
185
  ## 1. What the SDK does
115
186
 
@@ -192,6 +263,8 @@ The build normalizer accepts EVM chain IDs as numbers, decimal strings, or JSON-
192
263
 
193
264
  ### 3.2 Create a SwapClient
194
265
 
266
+ To request API access and an API key, sign in to the [RHEA Boss portal](https://boss.rhea.finance/#/login). Provide the issued credential through `apiKey` for a static credential or `getAccessToken` when your application refreshes access tokens.
267
+
195
268
  ```ts
196
269
  import { SwapClient } from "@rhea-finance/cross-chain-aggregation-dex";
197
270
 
@@ -232,6 +305,8 @@ const quoteRequest: QuoteRequest = {
232
305
  amountIn: "1000000",
233
306
  slippageBps: 50,
234
307
  quoteWaitingTimeMs: 3000,
308
+ sameChainTimeoutMs: 500,
309
+ crossChainTimeoutMs: 3000,
235
310
  sender: "0xYourBaseAddress",
236
311
  recipient: "YourSolanaAddress",
237
312
  };
@@ -239,29 +314,38 @@ const quoteRequest: QuoteRequest = {
239
314
  const quote = await client.quote(quoteRequest);
240
315
  ```
241
316
 
242
- `quote()` calls `POST /api/swap/quote`. The frontend can set `quoteWaitingTimeMs` on every `QuoteRequest` to control how long the quote service may wait for Near Intents and similar intent-based routes. The SDK sends `3000` when the field is omitted.
317
+ `quote()` calls `POST /api/swap/quote`. The frontend can configure the Near Intents wait plus the same-chain and cross-chain route timeouts on every `QuoteRequest`. The SDK sends the defaults shown above when fields are omitted.
318
+
319
+ Set `confidentiality: "basic"` to use the confidential 1Click route. The SDK preserves it through quote and build, and includes it in automatic or manual report payloads. Omit the field for public swaps:
320
+
321
+ ```ts
322
+ const confidentialQuote = await client.quote({
323
+ ...quoteRequest,
324
+ confidentiality: "basic",
325
+ });
326
+ ```
243
327
 
244
- #### 3.3.1 Configure the Near Intents quote wait
328
+ #### 3.3.1 Configure quote timing
245
329
 
246
- `quoteWaitingTimeMs` is a first-class SDK parameter. Pass it directly to `client.quote()`; do not put it in `extensions` or an executor configuration.
330
+ `quoteWaitingTimeMs`, `sameChainTimeoutMs`, and `crossChainTimeoutMs` are first-class SDK parameters. Pass them directly to `client.quote()`; do not put them in `extensions` or executor configuration.
247
331
 
248
332
  ```ts
249
333
  // Frontend: allow Near Intents up to 5 seconds to return a route quote.
250
334
  const quote = await client.quote({
251
335
  ...quoteRequest,
252
336
  quoteWaitingTimeMs: 5000,
337
+ sameChainTimeoutMs: 750,
338
+ crossChainTimeoutMs: 6000,
253
339
  });
254
340
  ```
255
341
 
256
- | Rule | Detail |
257
- | --- | --- |
258
- | Who sets it | The frontend or any other SDK caller, on each `client.quote(request)` call. |
259
- | Unit and range | Milliseconds; must be a non-negative integer. |
260
- | Default | `3000` (3 seconds) when omitted. Pass it explicitly when the product needs to control the Near Intents latency/route-availability tradeoff. |
261
- | Typical use | Increase it, for example to `5000`–`10000`, when Near Intents needs more time to return a quote. Decrease it, for example to `0`–`1000`, when a faster response is more important than waiting for that route. |
262
- | Scope | Quote aggregation for intent-based routes such as `nearintents` and `preswap-nearintents`. It also applies to MCA deposit/withdraw quote requests whose Near Intents previews are produced by the same quote call. |
342
+ | Field | SDK default | Scope |
343
+ | --- | --- | --- |
344
+ | `quoteWaitingTimeMs` | `3000` | Wait window for Near Intents and similar intent-based route quotes, including MCA previews produced by the quote call. |
345
+ | `sameChainTimeoutMs` | `500` | Timeout budget supplied to same-chain quote routing. |
346
+ | `crossChainTimeoutMs` | `3000` | Timeout budget supplied to cross-chain quote routing. |
263
347
 
264
- This value limits the server-side route-quote wait only. It does **not** control the SDK HTTP request timeout, wallet signing, source-chain confirmation, bridge settlement, or `waitFor: "completed"` order polling. If the frontend configures a value close to or above the client's `timeoutMs`, increase `timeoutMs` enough to include the quote wait plus network overhead; otherwise the HTTP request may time out first.
348
+ All three values use milliseconds and must be non-negative integers. They affect only `POST /api/swap/quote`; the SDK removes them from the subsequent build request. They do **not** control the SDK HTTP timeout, wallet signing, source-chain confirmation, bridge settlement, or order polling. Keep the client's `timeoutMs` above the configured quote budget plus network overhead.
265
349
 
266
350
  ### 3.4 Execute the swap directly
267
351
 
@@ -298,7 +382,9 @@ if (result.status === "completed") {
298
382
  }
299
383
  ```
300
384
 
301
- `"completed"` polls the API only when the build response contains a queryable `orderId`. The default polling interval is 5 seconds. There is no default polling timeout, so polling continues until the order reaches a terminal state or the supplied `AbortSignal` is aborted.
385
+ `"completed"` polls the order-status API whenever the swap has a queryable order reference. Confidential swaps also require order-status polling when they are same-chain. For confidential Near Intents builds, the SDK uses `deposit.orderId` when present and otherwise uses `deposit.depositAddress` as the status key. If a cross-chain or confidential swap does not provide a usable status key, the SDK throws `INVALID_API_RESPONSE` at the `status` stage instead of treating source-chain confirmation as completion.
386
+
387
+ The default polling interval is 5 seconds. There is no default polling timeout, so polling continues until the order reaches a terminal state or the supplied `AbortSignal` is aborted.
302
388
 
303
389
  Set `orderPolling.timeoutMs` only when the application needs a time limit. An explicit timeout throws `ORDER_TIMEOUT`, but it does not revert an already submitted on-chain transaction.
304
390
 
@@ -337,7 +423,7 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
337
423
  | Field | Type | Required | Description and default |
338
424
  | --- | --- | --- | --- |
339
425
  | `baseUrl` | `string` | Yes | API base URL, for example `https://api.rhea.finance`. A trailing `/` is removed. |
340
- | `apiKey` | `string` | No | API credential sent with requests. |
426
+ | `apiKey` | `string` | No | Static API credential sent with requests. Request one through the [RHEA Boss portal](https://boss.rhea.finance/#/login). |
341
427
  | `getAccessToken` | `() => string \| Promise<string>` | No | Reads an access token before each request. Use this for refreshable sessions. |
342
428
  | `fetch` | `typeof globalThis.fetch` | No | Custom fetch implementation. The SDK binds its invocation context to avoid browser `Illegal invocation` errors. It is normally required on Node.js 16. |
343
429
  | `headers` | `Record<string,string>` or function | No | Additional request headers. The function form may return a promise. |
@@ -346,6 +432,7 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
346
432
  | `logger` | `SdkLogger` | No | Receives structured `api.request`, `api.response`, and `api.retry` entries. |
347
433
  | `executors` | `readonly ChainExecutor[]` | Required for execution | Wallet executors. May be omitted when only calling `quote()` or `buildSwap()`. |
348
434
  | `maxQuoteAgeMs` | `number \| null` | No | Maximum local quote age in milliseconds. Default: `30000`. Set to `null` to disable the local age check; an API-provided `expiresAt` still applies. |
435
+ | `tokenListCacheTtlMs` | `number` | No | Successful token-list cache lifetime in milliseconds. Default: `600000` (10 minutes). Set to `0` to disable. |
349
436
  | `reportMode` | `"auto" \| "manual" \| "disabled"` | No | Reporting policy. Default: `"auto"`. A reporting failure does not turn a submitted swap into a failed swap. |
350
437
  | `onEvent` | `(event) => void` | No | Receives all lifecycle events. |
351
438
  | `now` | `() => number` | No | Custom millisecond clock, mainly for testing. Default: `Date.now`. |
@@ -372,7 +459,10 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
372
459
  | `tokenOut` | `AssetRef` | Yes | Asset being received. |
373
460
  | `amountIn` | `string` | Yes | A non-negative base-unit decimal integer string. Do not pass `"1.5"` or scientific notation. |
374
461
  | `slippageBps` | `number` | Yes | Slippage in basis points. `50` means 0.5%; `100` means 1%. |
375
- | `quoteWaitingTimeMs` | `number` | No | **Frontend-configurable Near Intents quote wait.** Milliseconds; must be a non-negative integer. Default: `3000`. See [Configure the Near Intents quote wait](#331-configure-the-near-intents-quote-wait). |
462
+ | `quoteWaitingTimeMs` | `number` | No | Near Intents quote wait in milliseconds. Must be a non-negative integer. Default: `3000`. See [Configure quote timing](#331-configure-quote-timing). |
463
+ | `sameChainTimeoutMs` | `number` | No | Same-chain route quote timeout in milliseconds. Must be a non-negative integer. Default: `500`. |
464
+ | `crossChainTimeoutMs` | `number` | No | Cross-chain route quote timeout in milliseconds. Must be a non-negative integer. Default: `3000`. |
465
+ | `confidentiality` | `"basic"` | No | Enables the confidential 1Click route and marks the resulting report. Omit for public swaps. |
376
466
  | `sender` | `string` | Yes | Sender address on the source chain. |
377
467
  | `recipient` | `string` | No | Recipient address on the destination chain. Cross-chain requests should normally provide it explicitly. |
378
468
  | `extensions` | `Record<string,unknown>` | No | Additional fields forwarded to the API. Regular applications should not use this to replace standard fields. |
@@ -407,7 +497,7 @@ Wait modes:
407
497
  | --- | --- |
408
498
  | `submitted` | Returns after the wallet signs or broadcasts the source action. |
409
499
  | `source-confirmed` | Calls the required wallet confirmation method and returns only when it reports `confirmed`. A `failed` or malformed status throws `BROADCAST_FAILED`. |
410
- | `completed` | After source execution, polls the server until a delivery terminal state when an order reference exists. Without an order reference, it returns the source execution result. |
500
+ | `completed` | After source execution, polls the server until a delivery terminal state. Same-chain confidential swaps are included. A cross-chain or confidential swap without a usable status key fails at the `status` stage instead of being reported as completed. |
411
501
 
412
502
  `waitForOrder()` accepts the same polling values directly:
413
503
 
@@ -425,7 +515,7 @@ Wait modes:
425
515
  | `router` | `string` | Router used for execution. Pass it unchanged when querying order status. |
426
516
  | `txHash` | `string?` | Hash of a single source-chain transaction. |
427
517
  | `txHashes` | `string[]?` | Hashes of multiple source-chain transactions, such as a NEAR transaction batch. |
428
- | `orderId` | `string?` | Server order identifier. When present, it can be passed to `waitForOrder()`. |
518
+ | `orderId` | `string?` | Status-query key. Usually a server order identifier; confidential Near Intents may use the deposit address. When present, it can be passed to `waitForOrder()`. |
429
519
  | `depositAddress` | `string?` | Cross-chain deposit address. |
430
520
  | `report` | `object?` | Reporting state: `reported`, `failed`, or `skipped`. A report warning does not invalidate the source submission. |
431
521
  | `raw` | `unknown` | Executor confirmation response or original swap API build data. |
@@ -577,6 +667,16 @@ const result = await client.swap({ quote, waitFor: "completed" });
577
667
  ### Withdraw
578
668
 
579
669
  ```ts
670
+ import { resolveMcaWithdrawPolicy } from "@rhea-finance/cross-chain-aggregation-dex";
671
+
672
+ const collateral = resolveMcaWithdrawPolicy({
673
+ amountBurrow, // requested withdraw in Burrow internal decimals
674
+ suppliedBalance, // current token supplied balance, same decimals
675
+ availableBalance, // human/display precision, matching amountInHuman
676
+ amountIn: amountInHuman,
677
+ isMax,
678
+ });
679
+
580
680
  const quote = await client.quote({
581
681
  flow: "withdraw",
582
682
  mcaAccountId: "account.near",
@@ -589,11 +689,7 @@ const quote = await client.quote({
589
689
  slippageBps: 50,
590
690
  sender: "account.near",
591
691
  recipient: "0xYourBaseAddress",
592
- collateral: {
593
- needDecrease: true,
594
- decreaseAmountBurrow: "1.0",
595
- withdrawAll: false,
596
- },
692
+ collateral,
597
693
  executionPreference: "relayer",
598
694
  });
599
695
 
@@ -610,14 +706,16 @@ Withdraw-only fields:
610
706
 
611
707
  | Field | Type | Required | Description |
612
708
  | --- | --- | --- | --- |
613
- | `collateral.needDecrease` | `boolean` | Yes | Whether Burrow collateral must be decreased. |
614
- | `collateral.decreaseAmountBurrow` | `string` | Yes | Human-readable Burrow decimal amount, such as `"1.0"`. This is not a token base-unit amount. |
709
+ | `collateral.needDecrease` | `boolean` | No | Compatibility hint only. The SDK derives the API value from `decreaseAmountBurrow` and corrects contradictory input. |
710
+ | `collateral.decreaseAmountBurrow` | `string` | Yes | Required collateral decrease in Burrow decimals: `max(amountBurrow - suppliedBalance, 0)`. The SDK canonicalizes the value and sends `"0"` when supplied balance covers the withdrawal. |
615
711
  | `collateral.withdrawAll` | `boolean` | No | Whether to withdraw the full available amount. |
616
712
  | `executionPreference` | `"auto" \| "near" \| "relayer"` | No | Default: `"auto"`. Set explicitly to force direct NEAR or relayer execution. |
617
713
  | `boundNearAccountId` | `string` | Required for automatic NEAR selection | In `auto` mode, direct NEAR execution is selected only when `toChain === "near"` and `recipient` exactly matches this field. Otherwise, the relayer is selected. |
618
714
 
619
715
  For direct NEAR execution, the NEAR executor submits `nearMcaWithdrawTx`. For relayer execution, the executor selected by `signerChain` uses `signMessage()` to sign the API-provided `messageToSign`, after which the SDK submits the order. Application code only calls `swap()`.
620
716
 
717
+ Derive the collateral policy from the same balances displayed by the application, as shown above. This mirrors Lending Withdraw and multi-chain Trade's 2026-08-20 withdraw fix: `decreaseCollateralAmountBurrow = max(amountBurrow - suppliedBalance, 0)`, and `needDecreaseCollateral` is true exactly when that result is positive. When relayer gas is reserved, use the supplied balance from the gas-adjusted portfolio snapshot, matching the amount used for the quote. `withdrawAll` remains an independent Max/available-balance decision.
718
+
621
719
  ## 9. Lifecycle, errors, and cancellation
622
720
 
623
721
  Lifecycle events can be observed globally on the client or for an individual swap:
@@ -700,6 +798,8 @@ await client.buildRaw(rawBuildRequest);
700
798
  await client.submitOrderRaw(rawSubmitRequest);
701
799
  await client.getOrderStatusRaw(rawStatusRequest);
702
800
  await client.reportRaw(rawReportRequest);
801
+ await client.createHistoryAuthChallenge(rawChallengeRequest);
802
+ await client.verifyHistoryAuthChallenge(rawVerifyRequest);
703
803
  await client.getHistoryRaw(rawHistoryRequest);
704
804
  ```
705
805
 
@@ -732,6 +832,36 @@ const history = await client.getHistory({
732
832
 
733
833
  The SDK applies `status` filtering locally. The returned page has `filteredLocally: true`.
734
834
 
835
+ For confidential history, authorize the connected wallet, then query with the returned short-lived token:
836
+
837
+ ```ts
838
+ const authorization = await client.authorizeConfidentialHistory(
839
+ {
840
+ chainFamily: "evm",
841
+ chainId: "1",
842
+ walletAddress: connectedAddress,
843
+ // Include mcaAccountId when authorizing an MCA principal.
844
+ },
845
+ async (challenge) => {
846
+ // Check the wallet/network has not changed, then sign exactly this message.
847
+ const signature = await signer.signMessage(
848
+ challenge.signingInput.message
849
+ );
850
+ return { signature };
851
+ }
852
+ );
853
+
854
+ const confidentialHistory = await client.getHistory({
855
+ sender: authorization.queryAddress,
856
+ mode: "confidential",
857
+ walletToken: authorization.token,
858
+ page: 1,
859
+ pageSize: 20,
860
+ });
861
+ ```
862
+
863
+ The callback returns the wallet-specific proof required by `challenge.signingMethod`; NEP-413 and other chain families may require additional proof fields. `authorizeConfidentialHistory()` validates that the challenge and verified token refer to the requested principal before returning them. The SDK sends the normal API credential in `Authorization` and the wallet token separately in `Authentication`. Public history omits `mode` and `walletToken`.
864
+
735
865
  ## 12. Amount utilities
736
866
 
737
867
  Avoid JavaScript floating-point arithmetic for token amounts:
@@ -1,4 +1,4 @@
1
- import { a4 as ExecutorErrorAdapter, C as ChainRef, a5 as TransactionSubmission, T as TransactionConfirmation, q as ChainExecutor } from '../shared-D0_DbMT2.mjs';
1
+ import { ad as ExecutorErrorAdapter, C as ChainRef, ae as TransactionSubmission, T as TransactionConfirmation, w as ChainExecutor } from '../shared-COkGiqaz.mjs';
2
2
 
3
3
  interface AptosWalletAdapter extends ExecutorErrorAdapter {
4
4
  getChain(): ChainRef | Promise<ChainRef>;
@@ -1,4 +1,4 @@
1
- import { a4 as ExecutorErrorAdapter, C as ChainRef, a5 as TransactionSubmission, T as TransactionConfirmation, q as ChainExecutor } from '../shared-D0_DbMT2.js';
1
+ import { ad as ExecutorErrorAdapter, C as ChainRef, ae as TransactionSubmission, T as TransactionConfirmation, w as ChainExecutor } from '../shared-COkGiqaz.js';
2
2
 
3
3
  interface AptosWalletAdapter extends ExecutorErrorAdapter {
4
4
  getChain(): ChainRef | Promise<ChainRef>;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/aptos/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;A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;AAAA,MACR,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAA,EAAK,mBAAmB,UAAA,CAAW;AAAA,KACrC;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":"aptos.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 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 AptosWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n signAndSubmitTransaction(\n payload: {\n function: string;\n typeArguments: string[];\n functionArguments: unknown[];\n },\n options: { signal?: AbortSignal }\n ): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createAptosExecutor(\n adapter: AptosWalletAdapter\n): ChainExecutor<\"aptos-entry-function\"> {\n return {\n ...exposeExecutorSigner(\"aptos\", adapter),\n kinds: [\"aptos-entry-function\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.signAndSubmitTransaction(\n {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n },\n { signal: context.signal }\n );\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to sign or submit Aptos transaction\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nasync function confirm(\n adapter: AptosWalletAdapter,\n submission: TransactionSubmission,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash: submission.txHash,\n ...(submission.raw !== undefined ? { raw: submission.raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(submission.txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Aptos transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash: submission.txHash,\n raw: confirmationRaw ?? submission.raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Aptos transaction\"\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/aptos/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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UAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAI,WAAW,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,UAAA,CAAW,GAAA,EAAI,GAAI;AAAC,KAChE;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,WAAW,MAAA,EAAQ;AAAA,MACvE,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,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAA,EAAK,mBAAmB,UAAA,CAAW;AAAA,KACrC;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":"aptos.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 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 AptosWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n signAndSubmitTransaction(\n payload: {\n function: string;\n typeArguments: string[];\n functionArguments: unknown[];\n },\n options: { signal?: AbortSignal }\n ): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createAptosExecutor(\n adapter: AptosWalletAdapter\n): ChainExecutor<\"aptos-entry-function\"> {\n return {\n ...exposeExecutorSigner(\"aptos\", adapter),\n kinds: [\"aptos-entry-function\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.signAndSubmitTransaction(\n {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n },\n { signal: context.signal }\n );\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to sign or submit Aptos transaction\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nasync function confirm(\n adapter: AptosWalletAdapter,\n submission: TransactionSubmission,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash: submission.txHash,\n ...(submission.raw !== undefined ? { raw: submission.raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(submission.txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Aptos transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash: submission.txHash,\n raw: confirmationRaw ?? submission.raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Aptos transaction\"\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/aptos/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,OAA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D,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,kBAAA;AAAA,MACR,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAA,EAAK,mBAAmB,UAAA,CAAW;AAAA,KACrC;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":"aptos.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 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 AptosWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n signAndSubmitTransaction(\n payload: {\n function: string;\n typeArguments: string[];\n functionArguments: unknown[];\n },\n options: { signal?: AbortSignal }\n ): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createAptosExecutor(\n adapter: AptosWalletAdapter\n): ChainExecutor<\"aptos-entry-function\"> {\n return {\n ...exposeExecutorSigner(\"aptos\", adapter),\n kinds: [\"aptos-entry-function\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.signAndSubmitTransaction(\n {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n },\n { signal: context.signal }\n );\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to sign or submit Aptos transaction\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nasync function confirm(\n adapter: AptosWalletAdapter,\n submission: TransactionSubmission,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash: submission.txHash,\n ...(submission.raw !== undefined ? { raw: submission.raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(submission.txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Aptos transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash: submission.txHash,\n raw: confirmationRaw ?? submission.raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Aptos transaction\"\n );\n }\n}\n"]}
1
+ {"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/aptos/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,E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,GACF;AACF;AAEA,eAAe,OAAA,CACb,OAAA,EACA,UAAA,EACA,OAAA,EAC+B;AAC/B,EAAA,IAAI,OAAA,CAAQ,YAAY,WAAA,EAAa;AACnC,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ,WAAA;AAAA,MACR,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAI,WAAW,GAAA,KAAQ,MAAA,GAAY,EAAE,GAAA,EAAK,UAAA,CAAW,GAAA,EAAI,GAAI;AAAC,KAChE;AAAA,EACF;AACA,EAAA,IAAI;AACF,IAAA,MAAM,YAAA,GAAe,MAAM,OAAA,CAAQ,kBAAA,CAAmB,WAAW,MAAA,EAAQ;AAAA,MACvE,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,QAAQ,UAAA,CAAW,MAAA;AAAA,MACnB,GAAA,EAAK,mBAAmB,UAAA,CAAW;AAAA,KACrC;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":"aptos.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 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 AptosWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n signAndSubmitTransaction(\n payload: {\n function: string;\n typeArguments: string[];\n functionArguments: unknown[];\n },\n options: { signal?: AbortSignal }\n ): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createAptosExecutor(\n adapter: AptosWalletAdapter\n): ChainExecutor<\"aptos-entry-function\"> {\n return {\n ...exposeExecutorSigner(\"aptos\", adapter),\n kinds: [\"aptos-entry-function\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(execution.chain, await adapter.getChain());\n },\n\n async execute(execution, context) {\n await requestSignApproval(context, execution.chain, execution.kind, {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.signAndSubmitTransaction(\n {\n function: execution.function,\n typeArguments: execution.typeArguments,\n functionArguments: execution.functionArguments,\n },\n { signal: context.signal }\n );\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to sign or submit Aptos transaction\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nasync function confirm(\n adapter: AptosWalletAdapter,\n submission: TransactionSubmission,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash: submission.txHash,\n ...(submission.raw !== undefined ? { raw: submission.raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(submission.txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Aptos transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash: submission.txHash,\n raw: confirmationRaw ?? submission.raw,\n };\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Aptos transaction\"\n );\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { a4 as ExecutorErrorAdapter, C as ChainRef, a5 as TransactionSubmission, T as TransactionConfirmation, q as ChainExecutor } from '../shared-D0_DbMT2.mjs';
1
+ import { ad as ExecutorErrorAdapter, C as ChainRef, ae as TransactionSubmission, T as TransactionConfirmation, w as ChainExecutor } from '../shared-COkGiqaz.mjs';
2
2
 
3
3
  interface BitcoinWalletAdapter extends ExecutorErrorAdapter {
4
4
  getChain(): ChainRef | Promise<ChainRef>;
@@ -1,4 +1,4 @@
1
- import { a4 as ExecutorErrorAdapter, C as ChainRef, a5 as TransactionSubmission, T as TransactionConfirmation, q as ChainExecutor } from '../shared-D0_DbMT2.js';
1
+ import { ad as ExecutorErrorAdapter, C as ChainRef, ae as TransactionSubmission, T as TransactionConfirmation, w as ChainExecutor } from '../shared-COkGiqaz.js';
2
2
 
3
3
  interface BitcoinWalletAdapter extends ExecutorErrorAdapter {
4
4
  getChain(): ChainRef | Promise<ChainRef>;