@rhea-finance/cross-chain-aggregation-dex 2.1.9 → 2.1.10-beta.1
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 +53 -19
- package/dist/executors/aptos.d.mts +1 -1
- package/dist/executors/aptos.d.ts +1 -1
- package/dist/executors/bitcoin.d.mts +1 -1
- package/dist/executors/bitcoin.d.ts +1 -1
- package/dist/executors/dash.d.mts +21 -0
- package/dist/executors/dash.d.ts +21 -0
- package/dist/executors/dash.js +184 -0
- package/dist/executors/dash.js.map +1 -0
- package/dist/executors/dash.mjs +182 -0
- package/dist/executors/dash.mjs.map +1 -0
- package/dist/executors/evm.d.mts +1 -1
- package/dist/executors/evm.d.ts +1 -1
- package/dist/executors/near.d.mts +1 -1
- package/dist/executors/near.d.ts +1 -1
- package/dist/executors/pearl.d.mts +21 -0
- package/dist/executors/pearl.d.ts +21 -0
- package/dist/executors/pearl.js +240 -0
- package/dist/executors/pearl.js.map +1 -0
- package/dist/executors/pearl.mjs +238 -0
- package/dist/executors/pearl.mjs.map +1 -0
- package/dist/executors/qtc.d.mts +21 -0
- package/dist/executors/qtc.d.ts +21 -0
- package/dist/executors/qtc.js +184 -0
- package/dist/executors/qtc.js.map +1 -0
- package/dist/executors/qtc.mjs +182 -0
- package/dist/executors/qtc.mjs.map +1 -0
- package/dist/executors/solana.d.mts +1 -1
- package/dist/executors/solana.d.ts +1 -1
- package/dist/executors/starknet.d.mts +18 -0
- package/dist/executors/starknet.d.ts +18 -0
- package/dist/executors/starknet.js +189 -0
- package/dist/executors/starknet.js.map +1 -0
- package/dist/executors/starknet.mjs +187 -0
- package/dist/executors/starknet.mjs.map +1 -0
- package/dist/executors/sui.d.mts +1 -1
- package/dist/executors/sui.d.ts +1 -1
- package/dist/executors/tron.d.mts +1 -1
- package/dist/executors/tron.d.ts +1 -1
- package/dist/executors/zcash.d.mts +1 -1
- package/dist/executors/zcash.d.ts +1 -1
- package/dist/index.d.mts +99 -6
- package/dist/index.d.ts +99 -6
- package/dist/index.js +606 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +539 -18
- package/dist/index.mjs.map +1 -1
- package/dist/{shared-D_BnU1oa.d.mts → shared-CimaFxNY.d.mts} +61 -9
- package/dist/{shared-D_BnU1oa.d.ts → shared-CimaFxNY.d.ts} +61 -9
- package/package.json +22 -1
package/README.md
CHANGED
|
@@ -4,11 +4,11 @@ A TypeScript SDK for the RHEA unified multi-chain Swap API. The SDK handles quot
|
|
|
4
4
|
|
|
5
5
|
This package is a client SDK for the RHEA Cross-Chain Swap API. For endpoint contracts, request/response fields, and protocol details, see the [Cross-Chain Swap API documentation](https://github.com/rhea-finance/rhea-sdk-docs/blob/main/CrossChainDexAPI.md).
|
|
6
6
|
|
|
7
|
-
Supported chain families: EVM, Solana, Aptos, NEAR, Tron, Bitcoin, Zcash, and
|
|
7
|
+
Supported chain families: EVM, Solana, Aptos, NEAR, Tron, Bitcoin, Zcash, Sui, Dash, Pearl, Quantus, and Starknet. How to load the product token list and chain coverage is described in [Supported chains and tokens](#supported-chains-and-tokens).
|
|
8
8
|
|
|
9
9
|
## Supported chains and tokens
|
|
10
10
|
|
|
11
|
-
The product support list matches `multi-chain-lending` Trade: **
|
|
11
|
+
The product support list matches `multi-chain-lending` Trade: **29 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
12
|
|
|
13
13
|
| Chain | Type | HTTP / SDK chain ID | Token-list chain ID | `blockchain` alias |
|
|
14
14
|
| --- | --- | --- | --- | --- |
|
|
@@ -37,6 +37,10 @@ The product support list matches `multi-chain-lending` Trade: **25 mainnets**. U
|
|
|
37
37
|
| Bitcoin | Non-EVM | `btc` | `900002` | `btc` |
|
|
38
38
|
| Zcash | Non-EVM | `zcash` | `900010` | `zec` |
|
|
39
39
|
| Aptos | Non-EVM | `aptos` | `900012` | `aptos` |
|
|
40
|
+
| Starknet | Non-EVM | `starknet` | `900011` | `starknet` |
|
|
41
|
+
| Pearl | Non-EVM | `pearl` | `900013` | `prl` |
|
|
42
|
+
| Quantus | Non-EVM | `qtc` | `900014` | `qtc` |
|
|
43
|
+
| Dash | Non-EVM | `dash` | `900015` | `dash` |
|
|
40
44
|
|
|
41
45
|
"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.
|
|
42
46
|
|
|
@@ -92,7 +96,7 @@ interface SwapTokenListItem extends AssetRef {
|
|
|
92
96
|
}
|
|
93
97
|
```
|
|
94
98
|
|
|
95
|
-
`address`
|
|
99
|
+
`address` contains the on-chain contract/mint/coin type or native placeholder accepted by the unified quote API. `assetId` preserves the registry / Intents identifier for token identity and balances; it must not be substituted for a quote address. `contractAddress` separately preserves the on-chain contract/mint when available and is `null` for native assets. Rows without a resolvable quote address are omitted. Unknown backend fields remain available in `raw`.
|
|
96
100
|
|
|
97
101
|
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.
|
|
98
102
|
|
|
@@ -101,15 +105,15 @@ The corresponding HTTP endpoints are documented below for server integrations th
|
|
|
101
105
|
#### 1. From-token list
|
|
102
106
|
|
|
103
107
|
```http
|
|
104
|
-
GET https://
|
|
108
|
+
GET https://privateindexer.refburrow.top/get_chain_prices?chain=<NUMERIC_CHAIN_ID>
|
|
105
109
|
```
|
|
106
110
|
|
|
107
111
|
Example:
|
|
108
112
|
|
|
109
113
|
```bash
|
|
110
|
-
curl "https://
|
|
111
|
-
curl "https://
|
|
112
|
-
curl "https://
|
|
114
|
+
curl "https://privateindexer.refburrow.top/get_chain_prices?chain=1"
|
|
115
|
+
curl "https://privateindexer.refburrow.top/get_chain_prices?chain=56"
|
|
116
|
+
curl "https://privateindexer.refburrow.top/get_chain_prices?chain=8453"
|
|
113
117
|
```
|
|
114
118
|
|
|
115
119
|
`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`.
|
|
@@ -142,13 +146,13 @@ Use every returned row as the chain's from-token list. The same list is also use
|
|
|
142
146
|
#### 2. Cross-chain to-token list
|
|
143
147
|
|
|
144
148
|
```http
|
|
145
|
-
GET https://
|
|
149
|
+
GET https://privateindexer.refburrow.top/api/swap/supported_to_tokens?chain=<NUMERIC_CHAIN_ID>
|
|
146
150
|
```
|
|
147
151
|
|
|
148
152
|
Example:
|
|
149
153
|
|
|
150
154
|
```bash
|
|
151
|
-
curl "https://
|
|
155
|
+
curl "https://privateindexer.refburrow.top/api/swap/supported_to_tokens?chain=8453"
|
|
152
156
|
```
|
|
153
157
|
|
|
154
158
|
The response uses the standard envelope and returns the final destination list in `data.tokens`:
|
|
@@ -269,12 +273,16 @@ To request API access and an API key, sign in to the [RHEA Boss portal](https://
|
|
|
269
273
|
import { SwapClient } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
270
274
|
|
|
271
275
|
const client = new SwapClient({
|
|
272
|
-
baseUrl: "https://
|
|
276
|
+
baseUrl: "https://privateindexer.refburrow.top",
|
|
273
277
|
getAccessToken: () => sessionStorage.getItem("access-token") ?? "",
|
|
274
278
|
executors: [evmExecutor],
|
|
275
279
|
});
|
|
276
280
|
```
|
|
277
281
|
|
|
282
|
+
The SDK defaults to the private testing API at `https://privateindexer.refburrow.top`; `baseUrl` is optional and can override it. Quote, build, and report use `/crosschain/swap/quote`, `/crosschain/swap/swap`, and `/crosschain/swap/report`. Status, history, authentication, and order submission retain their `/api/swap/*` paths. Quote and build default `referral` to `rhea_crosschain_swap`; set `QuoteRequest.referral` to override it. Credentials remain supplied by the application.
|
|
283
|
+
|
|
284
|
+
The normalized `quote()` → `swap()` flow sends `enableDestinationSwap: false`. Routes with `BRIDGE_THEN_DESTINATION_SWAP` require another wallet action on the destination chain and are rejected by normalization. Applications managing both steps can use `quoteRaw()` with `enableDestinationSwap: true` and `buildRaw()` with `executionPlan` and `bridgeQuote`; they must track bridge arrival, execute the destination swap, and finalize the report separately.
|
|
285
|
+
|
|
278
286
|
### 3.3 Request a quote
|
|
279
287
|
|
|
280
288
|
```ts
|
|
@@ -314,7 +322,7 @@ const quoteRequest: QuoteRequest = {
|
|
|
314
322
|
const quote = await client.quote(quoteRequest);
|
|
315
323
|
```
|
|
316
324
|
|
|
317
|
-
`quote()` calls `POST /
|
|
325
|
+
`quote()` calls `POST /crosschain/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
326
|
|
|
319
327
|
Pass `excludeDexs` as a top-level string array to exclude routing providers. Use the API's exact lowercase provider identifiers, and pass the same array when refreshing a quote. This also applies to MCA deposit and withdrawal quotes. Omit the field when no exclusions are needed:
|
|
320
328
|
|
|
@@ -325,7 +333,7 @@ const filteredQuote = await client.quote({
|
|
|
325
333
|
});
|
|
326
334
|
```
|
|
327
335
|
|
|
328
|
-
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:
|
|
336
|
+
Set `confidentiality: "basic"` or `"advanced"` 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:
|
|
329
337
|
|
|
330
338
|
```ts
|
|
331
339
|
const confidentialQuote = await client.quote({
|
|
@@ -354,7 +362,7 @@ const quote = await client.quote({
|
|
|
354
362
|
| `sameChainTimeoutMs` | `500` | Timeout budget supplied to same-chain quote routing. |
|
|
355
363
|
| `crossChainTimeoutMs` | `3000` | Timeout budget supplied to cross-chain quote routing. |
|
|
356
364
|
|
|
357
|
-
All three values use milliseconds and must be non-negative integers. They affect only `POST /
|
|
365
|
+
All three values use milliseconds and must be non-negative integers. They affect only `POST /crosschain/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.
|
|
358
366
|
|
|
359
367
|
### 3.4 Execute the swap directly
|
|
360
368
|
|
|
@@ -391,7 +399,7 @@ if (result.status === "completed") {
|
|
|
391
399
|
}
|
|
392
400
|
```
|
|
393
401
|
|
|
394
|
-
After `POST /
|
|
402
|
+
After `POST /crosschain/swap/report` returns an `id`, the SDK polls `GET /api/swap/order-status?recordId=<report id>&router=<swap router>`. The router comes from the swap response. The SDK does not query by source `txHash`. 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 provides none of these identifiers, the SDK throws `INVALID_API_RESPONSE` at the `status` stage instead of treating source-chain confirmation as completion.
|
|
395
403
|
|
|
396
404
|
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.
|
|
397
405
|
|
|
@@ -444,7 +452,7 @@ Terminal statuses are `completed`, `failed`, `refunded`, and `expired`.
|
|
|
444
452
|
|
|
445
453
|
| Field | Type | Required | Description and default |
|
|
446
454
|
| --- | --- | --- | --- |
|
|
447
|
-
| `baseUrl` | `string` |
|
|
455
|
+
| `baseUrl` | `string` | No | Defaults to the private testing API, for example `https://privateindexer.refburrow.top`. A trailing `/` is removed. |
|
|
448
456
|
| `apiKey` | `string` | No | Static API credential sent with requests. Request one through the [RHEA Boss portal](https://boss.rhea.finance/#/login). |
|
|
449
457
|
| `getAccessToken` | `() => string \| Promise<string>` | No | Reads an access token before each request. Use this for refreshable sessions. |
|
|
450
458
|
| `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. |
|
|
@@ -743,7 +751,7 @@ Lifecycle events can be observed globally on the client or for an individual swa
|
|
|
743
751
|
|
|
744
752
|
```ts
|
|
745
753
|
const client = new SwapClient({
|
|
746
|
-
baseUrl: "https://
|
|
754
|
+
baseUrl: "https://privateindexer.refburrow.top",
|
|
747
755
|
executors: [evmExecutor],
|
|
748
756
|
onEvent(event) {
|
|
749
757
|
console.log("Swap lifecycle", event);
|
|
@@ -791,7 +799,7 @@ Cancellation only stops the SDK's current work. It cannot revert an approval, si
|
|
|
791
799
|
|
|
792
800
|
```ts
|
|
793
801
|
const client = new SwapClient({
|
|
794
|
-
baseUrl: "https://
|
|
802
|
+
baseUrl: "https://privateindexer.refburrow.top",
|
|
795
803
|
getAccessToken: async () => authStore.getToken(),
|
|
796
804
|
logger: {
|
|
797
805
|
log(entry) {
|
|
@@ -818,11 +826,11 @@ await client.verifyHistoryAuthChallenge(rawVerifyRequest);
|
|
|
818
826
|
await client.getHistoryRaw(rawHistoryRequest);
|
|
819
827
|
```
|
|
820
828
|
|
|
821
|
-
The default reporting mode is `reportMode: "auto"`. If a swap succeeds but reporting fails, `result.report.status` is `"failed"` and a warning is emitted. The SDK does not throw a misleading swap failure. When `waitFor: "completed"` requires order-status polling, the SDK still calls `POST /
|
|
829
|
+
The default reporting mode is `reportMode: "auto"`. If a swap succeeds but reporting fails, `result.report.status` is `"failed"` and a warning is emitted. The SDK does not throw a misleading swap failure. When `waitFor: "completed"` requires order-status polling, the SDK still calls `POST /crosschain/swap/report` first (even in `reportMode: "manual"`) so it can query status by the returned record id. For other manual reporting flows:
|
|
822
830
|
|
|
823
831
|
```ts
|
|
824
832
|
const client = new SwapClient({
|
|
825
|
-
baseUrl: "https://
|
|
833
|
+
baseUrl: "https://privateindexer.refburrow.top",
|
|
826
834
|
executors: [evmExecutor],
|
|
827
835
|
reportMode: "manual",
|
|
828
836
|
});
|
|
@@ -892,3 +900,29 @@ formatUnits("1250000", 6); // "1.25"
|
|
|
892
900
|
```
|
|
893
901
|
|
|
894
902
|
`parseUnits()` rejects fractional precision beyond the token's decimals. `formatUnits()` accepts only non-negative base-unit decimal integer strings.
|
|
903
|
+
|
|
904
|
+
## QTC and Pearl native transfers (2.1.10-beta.0)
|
|
905
|
+
|
|
906
|
+
Canonical API chain names are `qtc` and `pearl`; incoming `quantus` and legacy `prl` aliases are accepted. Quote/build requests send `pearl` in `fromChain` / `toChain`; the native token symbol and identifiers remain `PRL`, `prl`, and `nep141:prl.omft.near`. Native quote addresses serialize as `qtc` and `prl` (Dash uses `dash`); OMFT IDs remain registry asset identities. QTC uses 12 decimal places; Pearl uses 8.
|
|
907
|
+
|
|
908
|
+
Import `createQtcExecutor` from `@rhea-finance/cross-chain-aggregation-dex/executors/qtc` or `createPearlExecutor` from `@rhea-finance/cross-chain-aggregation-dex/executors/pearl`. Supply a wallet adapter with `getChain`, `isAddress`, `sendTransfer` (base-unit amount), and `waitForTransaction`. Transfer instructions alone are never transaction receipts: return an actual transaction hash and verify source confirmation.
|
|
909
|
+
|
|
910
|
+
Build lanes accept `qtc`/`quantus`/`substrate` and `prl`/`pearl` (including Pearl `utxo` lane resolution). Transfer kinds are `qtc_transfer`/`quantus_transfer` and `prl_transfer`/`pearl_transfer`/`utxo_transfer`, respectively. Chain/lane mismatches, wrong decimals and inconsistent transfer amounts are rejected.
|
|
911
|
+
|
|
912
|
+
## Private environment and four-chain adapters
|
|
913
|
+
|
|
914
|
+
The default endpoint is `https://privateindexer.refburrow.top` (the Lending `private` environment). This is a testing service for **mainnet chains**, not a blockchain testnet. To select production explicitly, pass `baseUrl: PRODUCTION_API_BASE_URL` from the root export. Supply your own environment-appropriate `apiKey` or `getAccessToken`.
|
|
915
|
+
|
|
916
|
+
```ts
|
|
917
|
+
import { SwapClient, PRIVATE_API_BASE_URL } from "@rhea-finance/cross-chain-aggregation-dex";
|
|
918
|
+
import { createDashExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/dash";
|
|
919
|
+
import { createPearlExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/pearl";
|
|
920
|
+
import { createQtcExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/qtc";
|
|
921
|
+
import { createStarknetExecutor } from "@rhea-finance/cross-chain-aggregation-dex/executors/starknet";
|
|
922
|
+
```
|
|
923
|
+
|
|
924
|
+
Dash, Pearl, and Quantus adapters implement `getChain()` (canonical `dash`, `pearl`, or `qtc`), `getAddress()`, `isAddress()`, `sendTransfer()`, and `waitForTransaction()`. Amounts are base units; Dash/Pearl use 8 decimals, Quantus uses 12. The SDK checks that the source wallet still matches the quoted sender. Raw builds must provide `tx.sender` or be normalized with the original build request to retain it. Each submission must return a real `txHash`; confirmations use `{ status: "confirmed" | "failed" }`.
|
|
925
|
+
|
|
926
|
+
The Starknet adapter implements `getChain()` returning `starknet` on mainnet, `getAddress()`, `sendTransaction({ sender, calls, signal })`, and `waitForTransaction()`. The adapter must check the connected network. `starknet_call` batches preserve call order; `starknet_transfer` becomes an ERC-20 `transfer` call with uint256 low/high calldata. Invalid field elements, amounts, chain hints, and changed senders are rejected before signing. A token contract address is required; an OMFT identifier cannot be executed as a Starknet contract.
|
|
927
|
+
|
|
928
|
+
`pnpm test:live-shapes -- --build` defaults to private. `RHEA_BASE_URL` overrides the host; `RHEA_ACCESS_TOKEN` supplies credentials. For new-chain quote/build checks, set `RHEA_SENDER_DASH`, `RHEA_SENDER_PRL`, `RHEA_SENDER_QTC`, and `RHEA_SENDER_STARKNET` to valid wallet addresses. The script only quotes and builds; it does not sign or broadcast.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.mjs';
|
|
2
2
|
|
|
3
3
|
interface AptosWalletAdapter extends ExecutorErrorAdapter {
|
|
4
4
|
getChain(): ChainRef | Promise<ChainRef>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.js';
|
|
2
2
|
|
|
3
3
|
interface AptosWalletAdapter extends ExecutorErrorAdapter {
|
|
4
4
|
getChain(): ChainRef | Promise<ChainRef>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.mjs';
|
|
2
2
|
|
|
3
3
|
interface BitcoinWalletAdapter extends ExecutorErrorAdapter {
|
|
4
4
|
getChain(): ChainRef | Promise<ChainRef>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.js';
|
|
2
2
|
|
|
3
3
|
interface BitcoinWalletAdapter extends ExecutorErrorAdapter {
|
|
4
4
|
getChain(): ChainRef | Promise<ChainRef>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.mjs';
|
|
2
|
+
|
|
3
|
+
interface DashWalletAdapter extends ExecutorErrorAdapter {
|
|
4
|
+
getChain(): ChainRef | Promise<ChainRef>;
|
|
5
|
+
isAddress(address: string): boolean;
|
|
6
|
+
/** Current source wallet address, checked against the quote before signing. */
|
|
7
|
+
getAddress(): string | Promise<string>;
|
|
8
|
+
sendTransfer(input: {
|
|
9
|
+
sender?: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
depositAddress: string;
|
|
12
|
+
decimals?: 8;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}): Promise<TransactionSubmission>;
|
|
15
|
+
waitForTransaction(txHash: string, options: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<TransactionConfirmation>;
|
|
18
|
+
}
|
|
19
|
+
declare function createDashExecutor(adapter: DashWalletAdapter): ChainExecutor<"dash-transfer">;
|
|
20
|
+
|
|
21
|
+
export { type DashWalletAdapter, createDashExecutor };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ah as ExecutorErrorAdapter, C as ChainRef, ai as TransactionSubmission, T as TransactionConfirmation, x as ChainExecutor } from '../shared-CimaFxNY.js';
|
|
2
|
+
|
|
3
|
+
interface DashWalletAdapter extends ExecutorErrorAdapter {
|
|
4
|
+
getChain(): ChainRef | Promise<ChainRef>;
|
|
5
|
+
isAddress(address: string): boolean;
|
|
6
|
+
/** Current source wallet address, checked against the quote before signing. */
|
|
7
|
+
getAddress(): string | Promise<string>;
|
|
8
|
+
sendTransfer(input: {
|
|
9
|
+
sender?: string;
|
|
10
|
+
amount: string;
|
|
11
|
+
depositAddress: string;
|
|
12
|
+
decimals?: 8;
|
|
13
|
+
signal?: AbortSignal;
|
|
14
|
+
}): Promise<TransactionSubmission>;
|
|
15
|
+
waitForTransaction(txHash: string, options: {
|
|
16
|
+
signal?: AbortSignal;
|
|
17
|
+
}): Promise<TransactionConfirmation>;
|
|
18
|
+
}
|
|
19
|
+
declare function createDashExecutor(adapter: DashWalletAdapter): ChainExecutor<"dash-transfer">;
|
|
20
|
+
|
|
21
|
+
export { type DashWalletAdapter, createDashExecutor };
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/core/catchLog.ts
|
|
4
|
+
|
|
5
|
+
// src/core/errors.ts
|
|
6
|
+
var SwapSdkError = class extends Error {
|
|
7
|
+
constructor(code, stage, message, options = {}) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.code = code;
|
|
10
|
+
this.stage = stage;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.name = "SwapSdkError";
|
|
13
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
14
|
+
}
|
|
15
|
+
get retryable() {
|
|
16
|
+
return this.options.retryable ?? false;
|
|
17
|
+
}
|
|
18
|
+
get cause() {
|
|
19
|
+
return this.options.cause;
|
|
20
|
+
}
|
|
21
|
+
get details() {
|
|
22
|
+
return this.options.details;
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/executors/shared.ts
|
|
27
|
+
function exposeExecutorSigner(signerChain, adapter) {
|
|
28
|
+
return {
|
|
29
|
+
signerChain,
|
|
30
|
+
...adapter.getIdentityKey ? { getIdentityKey: () => adapter.getIdentityKey() } : {},
|
|
31
|
+
...adapter.signMessage ? {
|
|
32
|
+
signMessage: (message, options) => adapter.signMessage(message, options)
|
|
33
|
+
} : {}
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function throwIfAborted(signal, stage = "sign") {
|
|
37
|
+
if (!signal?.aborted) return;
|
|
38
|
+
throw new SwapSdkError("REQUEST_ABORTED", stage, "Execution was aborted", {
|
|
39
|
+
cause: signal.reason
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function assertChain(expected, actual, stage = "sign") {
|
|
43
|
+
if (expected === actual) return;
|
|
44
|
+
throw new SwapSdkError(
|
|
45
|
+
"CHAIN_MISMATCH",
|
|
46
|
+
stage,
|
|
47
|
+
`Connected chain ${actual} does not match execution chain ${expected}`,
|
|
48
|
+
{ details: { expected, actual } }
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
async function requestSignApproval(context, chain, kind, summary) {
|
|
52
|
+
throwIfAborted(context.signal, "sign");
|
|
53
|
+
await context.beforeSign?.({ chain, kind, summary });
|
|
54
|
+
throwIfAborted(context.signal, "sign");
|
|
55
|
+
}
|
|
56
|
+
function mapExecutorError(error, adapter, stage, code, message) {
|
|
57
|
+
if (error instanceof SwapSdkError) return error;
|
|
58
|
+
if (isUserRejection(error, adapter)) {
|
|
59
|
+
return new SwapSdkError("USER_REJECTED", stage, "User rejected the request", {
|
|
60
|
+
cause: error
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return new SwapSdkError(code, stage, message, { cause: error });
|
|
64
|
+
}
|
|
65
|
+
function assertTransactionConfirmed(confirmation, options) {
|
|
66
|
+
if (confirmation?.status === "confirmed") {
|
|
67
|
+
return confirmation.raw;
|
|
68
|
+
}
|
|
69
|
+
const status = confirmation && typeof confirmation === "object" && "status" in confirmation ? String(confirmation.status) : "missing";
|
|
70
|
+
throw new SwapSdkError(
|
|
71
|
+
options.code,
|
|
72
|
+
options.stage,
|
|
73
|
+
`${options.message}: wallet confirmation status is ${status}`,
|
|
74
|
+
{
|
|
75
|
+
cause: confirmation && typeof confirmation === "object" && "raw" in confirmation ? confirmation.raw : confirmation,
|
|
76
|
+
details: { confirmationStatus: status }
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
function isUserRejection(error, adapter) {
|
|
81
|
+
if (adapter.isUserRejection?.(error)) return true;
|
|
82
|
+
if (typeof error !== "object" || error === null) return false;
|
|
83
|
+
const code = "code" in error ? error.code : void 0;
|
|
84
|
+
if (code === 4001 || code === "ACTION_REJECTED") return true;
|
|
85
|
+
const message = "message" in error && typeof error.message === "string" ? error.message.toLowerCase() : "";
|
|
86
|
+
return /user (rejected|denied)|request rejected|cancelled by user/.test(message);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/executors/dash/index.ts
|
|
90
|
+
function createDashExecutor(adapter) {
|
|
91
|
+
return {
|
|
92
|
+
...exposeExecutorSigner("dash", adapter),
|
|
93
|
+
kinds: ["dash-transfer"],
|
|
94
|
+
async validate(execution, context) {
|
|
95
|
+
throwIfAborted(context.signal, "sign");
|
|
96
|
+
assertChain("dash", execution.chain);
|
|
97
|
+
assertChain(execution.chain, await adapter.getChain());
|
|
98
|
+
if (!/^[1-9]\d*$/.test(execution.amount) || execution.decimals !== 8) {
|
|
99
|
+
throw new SwapSdkError("INVALID_TRANSACTION", "sign", "Invalid Dash amount or decimals");
|
|
100
|
+
}
|
|
101
|
+
if (!execution.sender || execution.sender !== await adapter.getAddress()) {
|
|
102
|
+
throw new SwapSdkError("CHAIN_MISMATCH", "sign", "Source wallet changed or quoted sender is missing");
|
|
103
|
+
}
|
|
104
|
+
if (!adapter.isAddress(execution.depositAddress)) {
|
|
105
|
+
throw new SwapSdkError(
|
|
106
|
+
"INVALID_TRANSACTION",
|
|
107
|
+
"sign",
|
|
108
|
+
"Invalid Dash deposit address"
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
async execute(execution, context) {
|
|
113
|
+
await this.validate(execution, context);
|
|
114
|
+
await requestSignApproval(context, execution.chain, execution.kind, {
|
|
115
|
+
amount: execution.amount,
|
|
116
|
+
depositAddress: execution.depositAddress,
|
|
117
|
+
decimals: execution.decimals
|
|
118
|
+
});
|
|
119
|
+
await this.validate(execution, context);
|
|
120
|
+
let submission;
|
|
121
|
+
try {
|
|
122
|
+
submission = await adapter.sendTransfer({
|
|
123
|
+
sender: execution.sender,
|
|
124
|
+
amount: execution.amount,
|
|
125
|
+
depositAddress: execution.depositAddress,
|
|
126
|
+
...execution.decimals !== void 0 ? { decimals: execution.decimals } : {},
|
|
127
|
+
signal: context.signal
|
|
128
|
+
});
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw mapExecutorError(
|
|
131
|
+
error,
|
|
132
|
+
adapter,
|
|
133
|
+
"broadcast",
|
|
134
|
+
"BROADCAST_FAILED",
|
|
135
|
+
"Failed to submit Dash transfer"
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
if (!submission.txHash?.trim()) {
|
|
139
|
+
throw new SwapSdkError(
|
|
140
|
+
"BROADCAST_FAILED",
|
|
141
|
+
"broadcast",
|
|
142
|
+
"Dash wallet returned no transaction hash"
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
return confirm(adapter, submission.txHash, submission.raw, context);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
async function confirm(adapter, txHash, raw, context) {
|
|
150
|
+
if (context.waitFor === "submitted") {
|
|
151
|
+
return {
|
|
152
|
+
status: "submitted",
|
|
153
|
+
txHash,
|
|
154
|
+
...raw !== void 0 ? { raw } : {}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
try {
|
|
158
|
+
const confirmation = await adapter.waitForTransaction(txHash, {
|
|
159
|
+
signal: context.signal
|
|
160
|
+
});
|
|
161
|
+
const confirmationRaw = assertTransactionConfirmed(confirmation, {
|
|
162
|
+
code: "BROADCAST_FAILED",
|
|
163
|
+
stage: "broadcast",
|
|
164
|
+
message: "Dash transaction failed"
|
|
165
|
+
});
|
|
166
|
+
return {
|
|
167
|
+
status: "source-confirmed",
|
|
168
|
+
txHash,
|
|
169
|
+
raw: confirmationRaw ?? raw
|
|
170
|
+
};
|
|
171
|
+
} catch (error) {
|
|
172
|
+
throw mapExecutorError(
|
|
173
|
+
error,
|
|
174
|
+
adapter,
|
|
175
|
+
"broadcast",
|
|
176
|
+
"BROADCAST_FAILED",
|
|
177
|
+
"Failed while confirming Dash transfer"
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
exports.createDashExecutor = createDashExecutor;
|
|
183
|
+
//# sourceMappingURL=dash.js.map
|
|
184
|
+
//# sourceMappingURL=dash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/core/errors.ts","../../src/executors/shared.ts","../../src/executors/dash/index.ts"],"names":[],"mappings":";;;;;AA4CO,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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nexport 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 logSdkCaughtError(`asSwapSdkError:${stage}`, error);\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\";\nimport { logSdkCaughtError } from \"../core/catchLog\";\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 logSdkCaughtError(`executor.mapExecutorError:${stage}:${code}`, error);\n if (error instanceof SwapSdkError) return error;\n if (isUserRejection(error, adapter)) {\n return new SwapSdkError(\"USER_REJECTED\", stage, \"User rejected the request\", {\n cause: error,\n });\n }\n return new SwapSdkError(code, stage, message, { cause: error });\n}\n\nexport function assertTransactionConfirmed(\n confirmation: TransactionConfirmation,\n options: {\n code: SwapErrorCode;\n stage: SwapErrorStage;\n message: string;\n }\n): unknown {\n if (confirmation?.status === \"confirmed\") {\n return confirmation.raw;\n }\n const status =\n confirmation &&\n typeof confirmation === \"object\" &&\n \"status\" in confirmation\n ? String(confirmation.status)\n : \"missing\";\n throw new SwapSdkError(\n options.code,\n options.stage,\n `${options.message}: wallet confirmation status is ${status}`,\n {\n cause:\n confirmation &&\n typeof confirmation === \"object\" &&\n \"raw\" in confirmation\n ? confirmation.raw\n : confirmation,\n details: { confirmationStatus: status },\n }\n );\n}\n\nfunction isUserRejection(\n error: unknown,\n adapter: ExecutorErrorAdapter\n): boolean {\n if (adapter.isUserRejection?.(error)) return true;\n if (typeof error !== \"object\" || error === null) return false;\n const code = \"code\" in error ? error.code : undefined;\n if (code === 4001 || code === \"ACTION_REJECTED\") return true;\n const message =\n \"message\" in error && typeof error.message === \"string\"\n ? error.message.toLowerCase()\n : \"\";\n return /user (rejected|denied)|request rejected|cancelled by user/.test(message);\n}\n","import { SwapSdkError } from \"../../core/errors\";\nimport type {\n ChainExecutionResult,\n ChainExecutor,\n ExecutionContext,\n} from \"../../core/registry\";\nimport type { ChainRef } from \"../../types/chain\";\nimport {\n assertTransactionConfirmed,\n assertChain,\n exposeExecutorSigner,\n mapExecutorError,\n requestSignApproval,\n throwIfAborted,\n type ExecutorErrorAdapter,\n type TransactionConfirmation,\n type TransactionSubmission,\n} from \"../shared\";\nimport { logSdkCaughtError } from \"../../core/catchLog\";\n\nexport interface DashWalletAdapter extends ExecutorErrorAdapter {\n getChain(): ChainRef | Promise<ChainRef>;\n isAddress(address: string): boolean;\n /** Current source wallet address, checked against the quote before signing. */\n getAddress(): string | Promise<string>;\n sendTransfer(input: {\n sender?: string;\n amount: string;\n depositAddress: string;\n decimals?: 8;\n signal?: AbortSignal;\n }): Promise<TransactionSubmission>;\n waitForTransaction(\n txHash: string,\n options: { signal?: AbortSignal }\n ): Promise<TransactionConfirmation>;\n}\n\nexport function createDashExecutor(\n adapter: DashWalletAdapter\n): ChainExecutor<\"dash-transfer\"> {\n return {\n ...exposeExecutorSigner(\"dash\", adapter),\n kinds: [\"dash-transfer\"],\n\n async validate(execution, context) {\n throwIfAborted(context.signal, \"sign\");\n assertChain(\"dash\", execution.chain);\n assertChain(execution.chain, await adapter.getChain());\n if (!/^[1-9]\\d*$/.test(execution.amount) || execution.decimals !== 8) {\n throw new SwapSdkError(\"INVALID_TRANSACTION\", \"sign\", \"Invalid Dash amount or decimals\");\n }\n if (!execution.sender || execution.sender !== await adapter.getAddress()) {\n throw new SwapSdkError(\"CHAIN_MISMATCH\", \"sign\", \"Source wallet changed or quoted sender is missing\");\n }\n if (!adapter.isAddress(execution.depositAddress)) {\n throw new SwapSdkError(\n \"INVALID_TRANSACTION\",\n \"sign\",\n \"Invalid Dash deposit address\"\n );\n }\n },\n\n async execute(execution, context) {\n await this.validate(execution, context);\n await requestSignApproval(context, execution.chain, execution.kind, {\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n decimals: execution.decimals,\n });\n // Recheck after application confirmation, which may change the wallet.\n await this.validate(execution, context);\n let submission: TransactionSubmission;\n try {\n submission = await adapter.sendTransfer({\n sender: execution.sender,\n amount: execution.amount,\n depositAddress: execution.depositAddress,\n ...(execution.decimals !== undefined\n ? { decimals: execution.decimals }\n : {}),\n signal: context.signal,\n });\n } catch (error) {\n logSdkCaughtError(\"executors/dash/index.ts\", error);\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed to submit Dash transfer\"\n );\n }\n if (!submission.txHash?.trim()) {\n throw new SwapSdkError(\n \"BROADCAST_FAILED\",\n \"broadcast\",\n \"Dash wallet returned no transaction hash\"\n );\n }\n return confirm(adapter, submission.txHash, submission.raw, context);\n },\n };\n}\n\nasync function confirm(\n adapter: DashWalletAdapter,\n txHash: string,\n raw: unknown,\n context: ExecutionContext\n): Promise<ChainExecutionResult> {\n if (context.waitFor === \"submitted\") {\n return {\n status: \"submitted\",\n txHash,\n ...(raw !== undefined ? { raw } : {}),\n };\n }\n try {\n const confirmation = await adapter.waitForTransaction(txHash, {\n signal: context.signal,\n });\n const confirmationRaw = assertTransactionConfirmed(confirmation, {\n code: \"BROADCAST_FAILED\",\n stage: \"broadcast\",\n message: \"Dash transaction failed\",\n });\n return {\n status: \"source-confirmed\",\n txHash,\n raw: confirmationRaw ?? raw,\n };\n } catch (error) {\n logSdkCaughtError(\"executors/dash/index.ts\", error);\n throw mapExecutorError(\n error,\n adapter,\n \"broadcast\",\n \"BROADCAST_FAILED\",\n \"Failed while confirming Dash transfer\"\n );\n }\n}\n"]}
|