@rhea-finance/cross-chain-aggregation-dex 2.0.5 → 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 +147 -69
- 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 +40 -4
- package/dist/index.d.ts +40 -4
- package/dist/index.js +264 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +263 -16
- package/dist/index.mjs.map +1 -1
- package/dist/{shared-DmMJXknE.d.mts → shared-COkGiqaz.d.mts} +30 -2
- package/dist/{shared-DmMJXknE.d.ts → shared-COkGiqaz.d.ts} +30 -2
- 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: **
|
|
12
|
-
|
|
13
|
-
| Chain | Type | HTTP / SDK chain ID | Token
|
|
14
|
-
| --- | --- | --- | --- |
|
|
15
|
-
| Ethereum | EVM | `1` | `eth` |
|
|
16
|
-
|
|
|
17
|
-
|
|
|
18
|
-
|
|
|
19
|
-
|
|
|
20
|
-
|
|
|
21
|
-
|
|
|
22
|
-
|
|
|
23
|
-
|
|
|
24
|
-
|
|
|
25
|
-
|
|
|
26
|
-
|
|
|
27
|
-
|
|
|
28
|
-
|
|
|
29
|
-
|
|
|
30
|
-
|
|
|
31
|
-
|
|
|
32
|
-
|
|
|
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
|
-
|
|
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.
|
|
46
|
+
|
|
47
|
+
### How to load supported tokens
|
|
39
48
|
|
|
40
|
-
|
|
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:
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
```ts
|
|
52
|
+
const fromTokens = await client.getFromTokens({ chainId: 8453 });
|
|
53
|
+
const crossChainToTokens = await client.getCrossChainToTokens({ chainId: 501 });
|
|
43
54
|
|
|
44
|
-
|
|
55
|
+
const tokenIn = fromTokens.find((token) => token.symbol === "USDC")!;
|
|
56
|
+
const tokenOut = crossChainToTokens.find((token) => token.symbol === "USDC")!;
|
|
45
57
|
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
####
|
|
101
|
+
#### 1. From-token list
|
|
76
102
|
|
|
77
103
|
```http
|
|
78
|
-
GET https://api.rhea.finance/get_chain_prices?chain=<
|
|
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=
|
|
85
|
-
curl "https://api.rhea.finance/get_chain_prices?chain=
|
|
86
|
-
curl "https://api.rhea.finance/get_chain_prices?chain=
|
|
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
|
|
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
|
|
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
|
|
|
@@ -234,6 +305,8 @@ const quoteRequest: QuoteRequest = {
|
|
|
234
305
|
amountIn: "1000000",
|
|
235
306
|
slippageBps: 50,
|
|
236
307
|
quoteWaitingTimeMs: 3000,
|
|
308
|
+
sameChainTimeoutMs: 500,
|
|
309
|
+
crossChainTimeoutMs: 3000,
|
|
237
310
|
sender: "0xYourBaseAddress",
|
|
238
311
|
recipient: "YourSolanaAddress",
|
|
239
312
|
};
|
|
@@ -241,7 +314,7 @@ const quoteRequest: QuoteRequest = {
|
|
|
241
314
|
const quote = await client.quote(quoteRequest);
|
|
242
315
|
```
|
|
243
316
|
|
|
244
|
-
`quote()` calls `POST /api/swap/quote`. The frontend can
|
|
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.
|
|
245
318
|
|
|
246
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:
|
|
247
320
|
|
|
@@ -252,27 +325,27 @@ const confidentialQuote = await client.quote({
|
|
|
252
325
|
});
|
|
253
326
|
```
|
|
254
327
|
|
|
255
|
-
#### 3.3.1 Configure
|
|
328
|
+
#### 3.3.1 Configure quote timing
|
|
256
329
|
|
|
257
|
-
`quoteWaitingTimeMs`
|
|
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.
|
|
258
331
|
|
|
259
332
|
```ts
|
|
260
333
|
// Frontend: allow Near Intents up to 5 seconds to return a route quote.
|
|
261
334
|
const quote = await client.quote({
|
|
262
335
|
...quoteRequest,
|
|
263
336
|
quoteWaitingTimeMs: 5000,
|
|
337
|
+
sameChainTimeoutMs: 750,
|
|
338
|
+
crossChainTimeoutMs: 6000,
|
|
264
339
|
});
|
|
265
340
|
```
|
|
266
341
|
|
|
267
|
-
|
|
|
268
|
-
| --- | --- |
|
|
269
|
-
|
|
|
270
|
-
|
|
|
271
|
-
|
|
|
272
|
-
| 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. |
|
|
273
|
-
| 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. |
|
|
274
347
|
|
|
275
|
-
|
|
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.
|
|
276
349
|
|
|
277
350
|
### 3.4 Execute the swap directly
|
|
278
351
|
|
|
@@ -309,7 +382,9 @@ if (result.status === "completed") {
|
|
|
309
382
|
}
|
|
310
383
|
```
|
|
311
384
|
|
|
312
|
-
`"completed"` polls the API
|
|
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.
|
|
313
388
|
|
|
314
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.
|
|
315
390
|
|
|
@@ -357,6 +432,7 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
|
|
|
357
432
|
| `logger` | `SdkLogger` | No | Receives structured `api.request`, `api.response`, and `api.retry` entries. |
|
|
358
433
|
| `executors` | `readonly ChainExecutor[]` | Required for execution | Wallet executors. May be omitted when only calling `quote()` or `buildSwap()`. |
|
|
359
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. |
|
|
360
436
|
| `reportMode` | `"auto" \| "manual" \| "disabled"` | No | Reporting policy. Default: `"auto"`. A reporting failure does not turn a submitted swap into a failed swap. |
|
|
361
437
|
| `onEvent` | `(event) => void` | No | Receives all lifecycle events. |
|
|
362
438
|
| `now` | `() => number` | No | Custom millisecond clock, mainly for testing. Default: `Date.now`. |
|
|
@@ -383,7 +459,9 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
|
|
|
383
459
|
| `tokenOut` | `AssetRef` | Yes | Asset being received. |
|
|
384
460
|
| `amountIn` | `string` | Yes | A non-negative base-unit decimal integer string. Do not pass `"1.5"` or scientific notation. |
|
|
385
461
|
| `slippageBps` | `number` | Yes | Slippage in basis points. `50` means 0.5%; `100` means 1%. |
|
|
386
|
-
| `quoteWaitingTimeMs` | `number` | No |
|
|
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`. |
|
|
387
465
|
| `confidentiality` | `"basic"` | No | Enables the confidential 1Click route and marks the resulting report. Omit for public swaps. |
|
|
388
466
|
| `sender` | `string` | Yes | Sender address on the source chain. |
|
|
389
467
|
| `recipient` | `string` | No | Recipient address on the destination chain. Cross-chain requests should normally provide it explicitly. |
|
|
@@ -419,7 +497,7 @@ Wait modes:
|
|
|
419
497
|
| --- | --- |
|
|
420
498
|
| `submitted` | Returns after the wallet signs or broadcasts the source action. |
|
|
421
499
|
| `source-confirmed` | Calls the required wallet confirmation method and returns only when it reports `confirmed`. A `failed` or malformed status throws `BROADCAST_FAILED`. |
|
|
422
|
-
| `completed` | After source execution, polls the server until a delivery terminal state
|
|
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. |
|
|
423
501
|
|
|
424
502
|
`waitForOrder()` accepts the same polling values directly:
|
|
425
503
|
|
|
@@ -437,7 +515,7 @@ Wait modes:
|
|
|
437
515
|
| `router` | `string` | Router used for execution. Pass it unchanged when querying order status. |
|
|
438
516
|
| `txHash` | `string?` | Hash of a single source-chain transaction. |
|
|
439
517
|
| `txHashes` | `string[]?` | Hashes of multiple source-chain transactions, such as a NEAR transaction batch. |
|
|
440
|
-
| `orderId` | `string?` |
|
|
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()`. |
|
|
441
519
|
| `depositAddress` | `string?` | Cross-chain deposit address. |
|
|
442
520
|
| `report` | `object?` | Reporting state: `reported`, `failed`, or `skipped`. A report warning does not invalidate the source submission. |
|
|
443
521
|
| `raw` | `unknown` | Executor confirmation response or original swap API build data. |
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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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B,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 | \"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,OAA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ALID_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,EAC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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 | \"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;AAC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"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 {
|
|
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 {
|
|
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>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/bitcoin/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,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kB,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":"bitcoin.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 type { SwapExecution } from \"../../types/execution\";\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\ntype BitcoinExecution = Extract<\n SwapExecution,\n { kind: \"bitcoin-transfer\" }\n>;\n\nexport interface BitcoinWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n feeRate: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport interface BitcoinExecutorOptions {\n defaultFeeRate?: number;\n}\n\nexport function createBitcoinExecutor(\n adapter: BitcoinWalletAdapter,\n options: BitcoinExecutorOptions = {}\n): ChainExecutor<\"bitcoin-transfer\"> {\n return {\n ...exposeExecutorSigner(\"btc\", adapter),\n kinds: [\"bitcoin-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 invalid(\"Invalid Bitcoin deposit address\");\n }\n resolveFeeRate(execution, options);\n },\n\n async execute(execution, context) {\n const feeRate = resolveFeeRate(execution, options);\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n feeRate,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n feeRate,\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to broadcast Bitcoin transfer\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nfunction resolveFeeRate(\n execution: BitcoinExecution,\n options: BitcoinExecutorOptions\n): number {\n const feeRate = execution.feeRate ?? options.defaultFeeRate;\n if (feeRate === undefined || !Number.isFinite(feeRate) || feeRate <= 0) {\n throw invalid(\"Bitcoin fee rate is required and must be positive\");\n }\n return feeRate;\n}\n\nfunction invalid(message: string): SwapSdkError {\n return new SwapSdkError(\"INVALID_TRANSACTION\", \"sign\", message);\n}\n\nasync function confirm(\n adapter: BitcoinWalletAdapter,\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: \"Bitcoin 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 Bitcoin transfer\"\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/bitcoin/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,IAA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,OAAO,IAAI,YAAA,CAAa,qBAAA,EAAuB,MAAA,EAAQ,OAAO,CAAA;AAChE;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":"bitcoin.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 type { SwapExecution } from \"../../types/execution\";\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\ntype BitcoinExecution = Extract<\n SwapExecution,\n { kind: \"bitcoin-transfer\" }\n>;\n\nexport interface BitcoinWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n sendTransfer(input: {\n amount: string;\n depositAddress: string;\n feeRate: number;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport interface BitcoinExecutorOptions {\n defaultFeeRate?: number;\n}\n\nexport function createBitcoinExecutor(\n adapter: BitcoinWalletAdapter,\n options: BitcoinExecutorOptions = {}\n): ChainExecutor<\"bitcoin-transfer\"> {\n return {\n ...exposeExecutorSigner(\"btc\", adapter),\n kinds: [\"bitcoin-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 invalid(\"Invalid Bitcoin deposit address\");\n }\n resolveFeeRate(execution, options);\n },\n\n async execute(execution, context) {\n const feeRate = resolveFeeRate(execution, options);\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n feeRate,\n });\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n feeRate,\n signal: context.signal,\n });\n } catch (error) {\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to broadcast Bitcoin transfer\"\n );\n }\n return confirm(adapter, submission, context);\n },\n };\n}\n\nfunction resolveFeeRate(\n execution: BitcoinExecution,\n options: BitcoinExecutorOptions\n): number {\n const feeRate = execution.feeRate ?? options.defaultFeeRate;\n if (feeRate === undefined || !Number.isFinite(feeRate) || feeRate <= 0) {\n throw invalid(\"Bitcoin fee rate is required and must be positive\");\n }\n return feeRate;\n}\n\nfunction invalid(message: string): SwapSdkError {\n return new SwapSdkError(\"INVALID_TRANSACTION\", \"sign\", message);\n}\n\nasync function confirm(\n adapter: BitcoinWalletAdapter,\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: \"Bitcoin 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 Bitcoin transfer\"\n );\n }\n}\n"]}
|