@swapdk/wdk-protocol-swidge-swapdk 1.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/README.md +140 -0
  2. package/dist/SwapDKSwidge.d.ts +94 -0
  3. package/dist/SwapDKSwidge.d.ts.map +1 -0
  4. package/dist/SwapDKSwidge.js +405 -0
  5. package/dist/SwapDKSwidge.js.map +1 -0
  6. package/dist/adapters/btc.d.ts +23 -0
  7. package/dist/adapters/btc.d.ts.map +1 -0
  8. package/dist/adapters/btc.js +159 -0
  9. package/dist/adapters/btc.js.map +1 -0
  10. package/dist/adapters/cosmos.d.ts +31 -0
  11. package/dist/adapters/cosmos.d.ts.map +1 -0
  12. package/dist/adapters/cosmos.js +103 -0
  13. package/dist/adapters/cosmos.js.map +1 -0
  14. package/dist/adapters/evm.d.ts +21 -0
  15. package/dist/adapters/evm.d.ts.map +1 -0
  16. package/dist/adapters/evm.js +72 -0
  17. package/dist/adapters/evm.js.map +1 -0
  18. package/dist/adapters/index.d.ts +18 -0
  19. package/dist/adapters/index.d.ts.map +1 -0
  20. package/dist/adapters/index.js +45 -0
  21. package/dist/adapters/index.js.map +1 -0
  22. package/dist/adapters/solana.d.ts +32 -0
  23. package/dist/adapters/solana.d.ts.map +1 -0
  24. package/dist/adapters/solana.js +96 -0
  25. package/dist/adapters/solana.js.map +1 -0
  26. package/dist/adapters/tron.d.ts +18 -0
  27. package/dist/adapters/tron.d.ts.map +1 -0
  28. package/dist/adapters/tron.js +119 -0
  29. package/dist/adapters/tron.js.map +1 -0
  30. package/dist/adapters/types.d.ts +69 -0
  31. package/dist/adapters/types.d.ts.map +1 -0
  32. package/dist/adapters/types.js +16 -0
  33. package/dist/adapters/types.js.map +1 -0
  34. package/dist/asset-encode.d.ts +34 -0
  35. package/dist/asset-encode.d.ts.map +1 -0
  36. package/dist/asset-encode.js +95 -0
  37. package/dist/asset-encode.js.map +1 -0
  38. package/dist/chain-map.d.ts +23 -0
  39. package/dist/chain-map.d.ts.map +1 -0
  40. package/dist/chain-map.js +85 -0
  41. package/dist/chain-map.js.map +1 -0
  42. package/dist/index.d.ts +8 -0
  43. package/dist/index.d.ts.map +1 -0
  44. package/dist/index.js +10 -0
  45. package/dist/index.js.map +1 -0
  46. package/dist/types.d.ts +163 -0
  47. package/dist/types.d.ts.map +1 -0
  48. package/dist/types.js +12 -0
  49. package/dist/types.js.map +1 -0
  50. package/package.json +64 -0
@@ -0,0 +1,96 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge adapter: Solana source.
3
+ //
4
+ // Builds a Solana `transactionMessage` combining two instructions:
5
+ // 1. SystemProgram transfer of `lamports` from source → THORChain inbound vault
6
+ // 2. Memo Program instruction carrying the THORChain swap memo
7
+ //
8
+ // Both come from the /quote response — swap-engine returns
9
+ // `route.inboundAddress` (the rotating THORChain SOL vault) and
10
+ // `route.memo` (the encoded swap intent). No /swap round-trip needed;
11
+ // Solana source is a pure /quote-driven build like Bitcoin's
12
+ // THORChain path.
13
+ //
14
+ // Native SOL only in this MVP. SPL sources are not yet supported —
15
+ // they need a different instruction (SPL Token transfer) and an
16
+ // associated token account lookup, which is a separate design pass.
17
+ //
18
+ // The paired wallet is `@tetherto/wdk-wallet-solana` — its
19
+ // `sendTransaction` fills in blockhash + fee payer, signs, and
20
+ // broadcasts.
21
+ // ---------------------------------------------------------------------------
22
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
23
+ import { address } from "@solana/addresses";
24
+ import { createNoopSigner } from "@solana/signers";
25
+ import { appendTransactionMessageInstruction, createTransactionMessage, } from "@solana/transaction-messages";
26
+ import { getTransferSolInstruction } from "@solana-program/system";
27
+ import { getAddMemoInstruction } from "@solana-program/memo";
28
+ import { fromHumanAmount } from "../asset-encode.js";
29
+ // SOL native decimals — 1 SOL = 1e9 lamports.
30
+ const SOL_DECIMALS = 9;
31
+ export const solanaAdapter = {
32
+ family: "solana",
33
+ // Solana source builds its tx from /quote alone (inboundAddress +
34
+ // memo + sellAmount) — same pattern as Bitcoin's THORChain path.
35
+ needsSwapResponse: false,
36
+ async execute(account, ctx) {
37
+ const { route, sourceAddress, fromChain, options } = ctx;
38
+ if (isSplToken(options.fromToken)) {
39
+ throw new SwapDKUserError("SwapDKSwidge (solana): SPL-token sources are not yet supported — " +
40
+ "pass `fromToken: \"SOL\"` for native SOL. SPL support requires a " +
41
+ "separate SPL Token instruction path.");
42
+ }
43
+ if (!route.inboundAddress) {
44
+ throw new SwapDKUserError("SwapDKSwidge (solana): swap-engine quote returned no inboundAddress. " +
45
+ `Providers: ${route.providers.join(", ")}`);
46
+ }
47
+ if (!route.memo) {
48
+ throw new SwapDKUserError("SwapDKSwidge (solana): swap-engine quote returned no memo. Without a " +
49
+ "memo the THORChain observer cannot route the deposit and funds " +
50
+ `would be lost. Providers: ${route.providers.join(", ")}`);
51
+ }
52
+ const lamports = fromHumanAmount(route.sellAmount, SOL_DECIMALS);
53
+ const transactionMessage = buildNativeTransferWithMemo({
54
+ source: sourceAddress,
55
+ destination: route.inboundAddress,
56
+ lamports,
57
+ memo: route.memo,
58
+ });
59
+ const result = await account.sendTransaction(transactionMessage);
60
+ if (account.waitForTransaction) {
61
+ await account.waitForTransaction(result.hash);
62
+ }
63
+ const transactions = [
64
+ { hash: result.hash, chain: fromChain, type: "source" },
65
+ ];
66
+ return { hash: result.hash, transactions };
67
+ },
68
+ };
69
+ // -- helpers -------------------------------------------------------------
70
+ /**
71
+ * Best-effort SPL detection: a swidge `fromToken` that isn't "SOL"
72
+ * (case-insensitive) is treated as an SPL mint address. Discovery
73
+ * endpoints return SPL mints in their raw base58 form; native SOL
74
+ * comes back as the uppercase ticker.
75
+ */
76
+ function isSplToken(fromToken) {
77
+ if (!fromToken)
78
+ return false;
79
+ return fromToken.trim().toUpperCase() !== "SOL";
80
+ }
81
+ export function buildNativeTransferWithMemo(args) {
82
+ const sourceAddr = address(args.source);
83
+ const destAddr = address(args.destination);
84
+ // A NoopSigner is a placeholder with the right shape carrying only
85
+ // the address. The WDK Solana wallet later attaches the real
86
+ // fee-payer signer, which covers the whole tx.
87
+ const sourceSigner = createNoopSigner(sourceAddr);
88
+ const transferIx = getTransferSolInstruction({
89
+ source: sourceSigner,
90
+ destination: destAddr,
91
+ amount: args.lamports,
92
+ });
93
+ const memoIx = getAddMemoInstruction({ memo: args.memo });
94
+ return appendTransactionMessageInstruction(memoIx, appendTransactionMessageInstruction(transferIx, createTransactionMessage({ version: 0 })));
95
+ }
96
+ //# sourceMappingURL=solana.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana.js","sourceRoot":"","sources":["../../src/adapters/solana.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,iCAAiC;AACjC,EAAE;AACF,mEAAmE;AACnE,kFAAkF;AAClF,iEAAiE;AACjE,EAAE;AACF,2DAA2D;AAC3D,gEAAgE;AAChE,sEAAsE;AACtE,6DAA6D;AAC7D,kBAAkB;AAClB,EAAE;AACF,mEAAmE;AACnE,gEAAgE;AAChE,oEAAoE;AACpE,EAAE;AACF,2DAA2D;AAC3D,+DAA+D;AAC/D,cAAc;AACd,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAgB,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACL,mCAAmC,EACnC,wBAAwB,GAEzB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAQrD,8CAA8C;AAC9C,MAAM,YAAY,GAAG,CAAC,CAAC;AAcvB,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,MAAM,EAAE,QAAQ;IAChB,kE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KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;SACxD,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,YAAY,EAAE,CAAC;IAC7C,CAAC;CACF,CAAC;AAEF,2EAA2E;AAE3E;;;;;GAKG;AACH,SAAS,UAAU,CAAC,SAA6B;IAC/C,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,SAAS,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;AAClD,CAAC;AAiBD,MAAM,UAAU,2BAA2B,CACzC,IAAqC;IAErC,MAAM,UAAU,GAAY,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAY,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAEpD,mEAAmE;IACnE,6DAA6D;IAC7D,+CAA+C;IAC/C,MAAM,YAAY,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAElD,MAAM,UAAU,GAAG,yBAAyB,CAAC;QAC3C,MAAM,EAAE,YAAY;QACpB,WAAW,EAAE,QAAQ;QACrB,MAAM,EAAE,IAAI,CAAC,QAAQ;KACtB,CAAC,CAAC;IAEH,MAAM,MAAM,GAAG,qBAAqB,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAE1D,OAAO,mCAAmC,CACxC,MAAM,EACN,mCAAmC,CACjC,UAAU,EACV,wBAAwB,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC,CACzC,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { TronPrebuiltTransaction } from "../types.js";
2
+ import type { SwidgeAdapter } from "./types.js";
3
+ /**
4
+ * Structural subset of `@tetherto/wdk-wallet-tron@^1.0.0-beta.8`'s
5
+ * `WalletAccountTron`. Adapter never touches key material — only
6
+ * `getAddress()` (base58) and `sendTransaction(prebuiltTx)`.
7
+ */
8
+ export interface SwidgeTronAccount {
9
+ getAddress(): string | Promise<string>;
10
+ sendTransaction(tx: TronPrebuiltTransaction): Promise<{
11
+ hash: string;
12
+ fee: bigint;
13
+ activationFee?: bigint;
14
+ }>;
15
+ waitForTransaction?(hash: string, timeoutMs?: number): Promise<void>;
16
+ }
17
+ export declare const tronAdapter: SwidgeAdapter;
18
+ //# sourceMappingURL=tron.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.d.ts","sourceRoot":"","sources":["../../src/adapters/tron.ts"],"names":[],"mappings":"AAgCA,OAAO,KAAK,EAAE,uBAAuB,EAAe,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,EAAE,uBAAuB,GAAG,OAAO,CAAC;QACpD,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC,CAAC;IACH,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,eAAO,MAAM,WAAW,EAAE,aAqFzB,CAAC"}
@@ -0,0 +1,119 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge adapter: TRON source.
3
+ //
4
+ // Two tx shapes swap-engine may emit for TRON, picked from the /swap
5
+ // response:
6
+ //
7
+ // - Router path (default): `tx.data` carries `depositWithExpiry`
8
+ // calldata, `tx.to` is the router contract, `tx.memo` is empty.
9
+ // Adapter builds a `TriggerSmartContract` with raw calldata via
10
+ // `tronWeb.transactionBuilder.triggerSmartContract(to, "", { input }, [], ownerHex)`.
11
+ //
12
+ // - Direct-vault path: `tx.data` is empty, `tx.memo` carries the
13
+ // routing memo. Used when THORChain has the TRON pool unhalted for
14
+ // trading but the router contract isn't deployed (transitional
15
+ // state observed mid-2026). Adapter builds a `TransferContract` via
16
+ // `sendTrx()` + attaches the memo through `addUpdateData()` — the
17
+ // latter recomputes `txID` because the memo is part of the tx hash
18
+ // preimage.
19
+ //
20
+ // For TRC-20 sources, swap-engine emits an `approvalTx` alongside the
21
+ // main tx; adapter dispatches it first, waits for confirmation, then
22
+ // sends the router call. Same pattern as `SwapDKBridgeTron`.
23
+ //
24
+ // Requires a `tronWeb` instance on `SwapDKSwidgeConfig.tronWeb`. Pass
25
+ // the same tronweb instance the paired `WalletManagerTron` was built
26
+ // with — the adapter only reads from it (address encoding, feeLimit
27
+ // fallback, transactionBuilder), no key material is exchanged.
28
+ // ---------------------------------------------------------------------------
29
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
30
+ export const tronAdapter = {
31
+ family: "tron",
32
+ needsSwapResponse: true,
33
+ async execute(account, ctx) {
34
+ const { swapRes, config, sourceAddress, fromChain } = ctx;
35
+ if (!swapRes) {
36
+ throw new SwapDKUserError("SwapDKSwidge (tron): missing /swap response — this is a bug in the swidge module (adapter should have signalled needsSwapResponse=true).");
37
+ }
38
+ const tronWeb = config.tronWeb;
39
+ if (!tronWeb) {
40
+ throw new SwapDKUserError("SwapDKSwidge (tron): config.tronWeb is required. Pass the tronweb instance the paired WalletManagerTron was constructed with.");
41
+ }
42
+ const sourceAddressHex = tronWeb.address.toHex(sourceAddress);
43
+ const transactions = [];
44
+ // 1. TRC-20 approval leg, when present.
45
+ if (swapRes.approvalTx) {
46
+ const approvePrebuilt = await buildContractCallTx(tronWeb, {
47
+ to: swapRes.approvalTx.to,
48
+ data: swapRes.approvalTx.data,
49
+ value: swapRes.approvalTx.value,
50
+ feeLimit: swapRes.approvalTx.feeLimit,
51
+ ownerHex: sourceAddressHex,
52
+ });
53
+ const approveResult = await account.sendTransaction(approvePrebuilt);
54
+ transactions.push({
55
+ hash: approveResult.hash,
56
+ chain: fromChain,
57
+ type: "approval",
58
+ });
59
+ if (account.waitForTransaction) {
60
+ await account.waitForTransaction(approveResult.hash);
61
+ }
62
+ }
63
+ // 2. Main leg — dispatch on tx.data (router) vs tx.memo (direct vault).
64
+ const tx = swapRes.tx;
65
+ if (!tx) {
66
+ throw new SwapDKUserError("SwapDKSwidge (tron): swap-engine returned no transaction data. " +
67
+ `Providers: ${swapRes.providers.join(", ")}`);
68
+ }
69
+ let prebuilt;
70
+ if (tx.data && tx.data !== "") {
71
+ prebuilt = await buildContractCallTx(tronWeb, {
72
+ to: tx.to,
73
+ data: tx.data,
74
+ value: tx.value,
75
+ feeLimit: tx.feeLimit,
76
+ ownerHex: sourceAddressHex,
77
+ });
78
+ }
79
+ else if (tx.memo && tx.memo !== "") {
80
+ prebuilt = await buildTransferWithMemoTx(tronWeb, {
81
+ to: tx.to,
82
+ value: tx.value,
83
+ memo: tx.memo,
84
+ ownerAddress: sourceAddress,
85
+ });
86
+ }
87
+ else {
88
+ throw new SwapDKUserError("SwapDKSwidge (tron): swap-engine returned a SwapTx with neither `data` nor `memo` — cannot dispatch. " +
89
+ `Providers: ${swapRes.providers.join(", ")}`);
90
+ }
91
+ const sendResult = await account.sendTransaction(prebuilt);
92
+ transactions.push({
93
+ hash: sendResult.hash,
94
+ chain: fromChain,
95
+ type: "source",
96
+ });
97
+ return { hash: sendResult.hash, transactions };
98
+ },
99
+ };
100
+ // -- prebuilt-tx builders (shared with the legacy SwapDKBridgeTron) ------
101
+ async function buildContractCallTx(tronWeb, args) {
102
+ if (!args.data) {
103
+ throw new SwapDKUserError("SwapDKSwidge (tron): buildContractCallTx requires `data` (ABI calldata)");
104
+ }
105
+ const inputHex = String(args.data).replace(/^0x/, "");
106
+ const callValue = args.value !== undefined && args.value !== "" ? Number(args.value) : 0;
107
+ const energyCap = args.feeLimit !== undefined && args.feeLimit !== ""
108
+ ? Number(args.feeLimit)
109
+ : tronWeb.feeLimit;
110
+ const { transaction } = await tronWeb.transactionBuilder.triggerSmartContract(args.to, "", // functionSelector empty → options.input carries the raw calldata
111
+ { feeLimit: energyCap, callValue, input: inputHex }, [], args.ownerHex);
112
+ return transaction;
113
+ }
114
+ async function buildTransferWithMemoTx(tronWeb, args) {
115
+ const sun = args.value !== undefined && args.value !== "" ? Number(args.value) : 0;
116
+ const transferTx = await tronWeb.transactionBuilder.sendTrx(args.to, sun, args.ownerAddress);
117
+ return await tronWeb.transactionBuilder.addUpdateData(transferTx, args.memo, "utf8");
118
+ }
119
+ //# sourceMappingURL=tron.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tron.js","sourceRoot":"","sources":["../../src/adapters/tron.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,+BAA+B;AAC/B,EAAE;AACF,qEAAqE;AACrE,YAAY;AACZ,EAAE;AACF,mEAAmE;AACnE,oEAAoE;AACpE,oEAAoE;AACpE,0FAA0F;AAC1F,EAAE;AACF,mEAAmE;AACnE,uEAAuE;AACvE,mEAAmE;AACnE,wEAAwE;AACxE,sEAAsE;AACtE,uEAAuE;AACvE,gBAAgB;AAChB,EAAE;AACF,sEAAsE;AACtE,qEAAqE;AACrE,6DAA6D;AAC7D,EAAE;AACF,sEAAsE;AACtE,qEAAqE;AACrE,oEAAoE;AACpE,+DAA+D;AAC/D,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAyB7D,MAAM,CAAC,MAAM,WAAW,GAAkB;IACxC,MAAM,EAAE,MAAM;IACd,iBAAiB,EAAE,IAAI;IAEvB,KAAK,CAAC,OAAO,CACX,OAA0B,EAC1B,GAAyB;QAEzB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;QAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,eAAe,CACvB,0IAA0I,CAC3I,CAAC;QACJ,CAAC;QACD,MAAM,OAAO,GAAG,MA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,69 @@
1
+ import type { QuoteRoute, SwapDKClient, SwapResponse } from "@swapdk/swap-engine-client";
2
+ import type { SwidgeTransaction } from "../SwapDKSwidge.js";
3
+ import type { SwapDKSwidgeConfig, SwapDKSwidgeOptions } from "../types.js";
4
+ /**
5
+ * Context threaded from SwapDKSwidge into the adapter.
6
+ *
7
+ * `route` is the best route selected from /quote — every adapter has
8
+ * this. `swapRes` is the finalized /swap response with calldata; it's
9
+ * populated only when SwapDKSwidge determined the family needs it (EVM,
10
+ * Cosmos-MsgSend, TRON — all need calldata from /swap). Bitcoin's
11
+ * THORChain path constructs its tx directly from `route.inboundAddress`
12
+ * + `route.memo` so `swapRes` is omitted for that adapter.
13
+ *
14
+ * `client` gives the adapter access to additional endpoints — currently
15
+ * only `openBrokerChannel` (Chainflip); most adapters won't touch it.
16
+ *
17
+ * `sourceAddress` is pre-resolved from `account.getAddress()` — some
18
+ * adapters need it for /swap parameters or refund addresses; pre-
19
+ * resolving avoids duplicate calls.
20
+ */
21
+ export interface SwidgeAdapterContext {
22
+ route: QuoteRoute;
23
+ swapRes?: SwapResponse;
24
+ client: SwapDKClient;
25
+ options: SwapDKSwidgeOptions;
26
+ config: SwapDKSwidgeConfig;
27
+ fromChain: string;
28
+ sourceAddress: string;
29
+ }
30
+ /**
31
+ * Result an adapter produces. `hash` is the primary source-chain
32
+ * transaction hash — surfaced on `SwidgeResult.hash` for the caller.
33
+ * `transactions` is the full per-tx list including any approval /
34
+ * auxiliary steps; SwapDKSwidge writes it verbatim into
35
+ * `SwidgeResult.transactions`.
36
+ */
37
+ export interface SwidgeAdapterResult {
38
+ hash: string;
39
+ transactions: SwidgeTransaction[];
40
+ }
41
+ /**
42
+ * Common interface every source-chain adapter implements. Adapters are
43
+ * chain-family-specific — one per {btc, cosmos, evm, solana, tron}.
44
+ */
45
+ export interface SwidgeAdapter {
46
+ /**
47
+ * Chain family this adapter handles. Matches the `family` return
48
+ * value from `chainFamilyFor()` in chain-map.ts.
49
+ */
50
+ readonly family: "bitcoin" | "cosmos" | "evm" | "solana" | "tron";
51
+ /**
52
+ * Whether SwapDKSwidge should fetch the /swap response before
53
+ * dispatching. Adapters that build their tx from /quote data alone
54
+ * (Bitcoin's THORChain path) return `false`; adapters that need
55
+ * finalized calldata (EVM, Cosmos-MsgSend, TRON) return `true`.
56
+ *
57
+ * Default (undefined) is treated as `true` to preserve backwards
58
+ * compatibility with the initial EVM-only shape.
59
+ */
60
+ readonly needsSwapResponse?: boolean;
61
+ /**
62
+ * Dispatch the outbound transaction(s). Adapters are expected to
63
+ * throw a `SwapDKUserError` on caller-fixable problems (missing
64
+ * calldata, unsupported route shape) and a `SwapDKError` subclass
65
+ * on transport failures.
66
+ */
67
+ execute(account: any, ctx: SwidgeAdapterContext): Promise<SwidgeAdapterResult>;
68
+ }
69
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,KAAK,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAE3E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,oBAAoB;IACnC,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,mBAAmB,CAAC;IAC7B,MAAM,EAAE,kBAAkB,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,iBAAiB,EAAE,CAAC;CACnC;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;IAElE;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAErC;;;;;OAKG;IACH,OAAO,CAEL,OAAO,EAAE,GAAG,EACZ,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjC"}
@@ -0,0 +1,16 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Shared shape for source-chain adapters.
3
+ //
4
+ // Each adapter takes the /swap response from swap-engine and the source
5
+ // wallet account, dispatches the outbound transaction(s), and returns the
6
+ // data SwapDKSwidge needs to build its `SwidgeResult` (primary tx hash,
7
+ // per-tx list, and any auxiliary results the source chain produces —
8
+ // approval tx for ERC-20, activation fee for TRON, etc.).
9
+ //
10
+ // Adapters are intentionally isolated from the swap-engine HTTP layer:
11
+ // SwapDKSwidge fetches the /swap response and hands the parsed tx to the
12
+ // adapter's `execute()`. This keeps the adapter's dependency surface small
13
+ // (only the paired wallet account interface + a few internal helpers).
14
+ // ---------------------------------------------------------------------------
15
+ export {};
16
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/adapters/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,0CAA0C;AAC1C,EAAE;AACF,wEAAwE;AACxE,0EAA0E;AAC1E,wEAAwE;AACxE,qEAAqE;AACrE,0DAA0D;AAC1D,EAAE;AACF,uEAAuE;AACvE,yEAAyE;AACzE,2EAA2E;AAC3E,uEAAuE;AACvE,8EAA8E"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Encodes a swidge {chain, token} pair into the SwapKit asset string the
3
+ * swap-engine `/quote` / `/swap` endpoints consume.
4
+ *
5
+ * Rules:
6
+ * - Native token (matches the chain's nativeSymbol): `"CHAIN.TICKER"`.
7
+ * - Address-based token: `"CHAIN.<TICKER-placeholder>-<address>"`. The
8
+ * swap-engine parser strips everything before the '-' when resolving
9
+ * the actual asset, so the placeholder is unused — we pass "T" as a
10
+ * non-empty stub.
11
+ *
12
+ * Throws `Error` when the chain is not in the swidge catalogue.
13
+ */
14
+ export declare function encodeSwapKitAsset(swidgeChain: string, token: string): string;
15
+ /**
16
+ * Converts a base-unit amount (bigint or number) to the human-decimal
17
+ * string the swap-engine expects on the wire.
18
+ *
19
+ * Example: `toHumanAmount(100_000_000n, 8)` → `"1"` (1 BTC).
20
+ * Example: `toHumanAmount(500_000n, 6)` → `"0.5"` (0.5 USDC).
21
+ *
22
+ * Rejects negative and fractional numeric inputs — the swap-engine
23
+ * expects integer base units on the way in, and JS `number` cannot
24
+ * safely represent large integers (> 2^53), so callers should prefer
25
+ * `bigint`.
26
+ */
27
+ export declare function toHumanAmount(baseUnits: bigint | number, decimals: number): string;
28
+ /**
29
+ * Inverse of `toHumanAmount`: parses a human-decimal string returned
30
+ * by the swap-engine and rounds to base units. Truncates rather than
31
+ * rounds to avoid over-quoting.
32
+ */
33
+ export declare function fromHumanAmount(human: string, decimals: number): bigint;
34
+ //# sourceMappingURL=asset-encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-encode.d.ts","sourceRoot":"","sources":["../src/asset-encode.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;GAYG;AACH,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAoB7E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,MAAM,GACf,MAAM,CA+BR;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAOvE"}
@@ -0,0 +1,95 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Translation between the swidge public API and the SwapKit-shaped HTTP
3
+ // surface of the swap-engine.
4
+ //
5
+ // Downstream code speaks swidge — { fromToken, fromChain, toToken, toChain }
6
+ // with `token` = ticker (native) or address (fungible). The swap-engine
7
+ // still speaks SwapKit — a single `"CHAIN.TICKER-0xAddress"` string per
8
+ // asset. This module encodes / decodes those two conventions.
9
+ // ---------------------------------------------------------------------------
10
+ import { swapkitChainFor, nativeMetaFor } from "./chain-map.js";
11
+ /**
12
+ * Encodes a swidge {chain, token} pair into the SwapKit asset string the
13
+ * swap-engine `/quote` / `/swap` endpoints consume.
14
+ *
15
+ * Rules:
16
+ * - Native token (matches the chain's nativeSymbol): `"CHAIN.TICKER"`.
17
+ * - Address-based token: `"CHAIN.<TICKER-placeholder>-<address>"`. The
18
+ * swap-engine parser strips everything before the '-' when resolving
19
+ * the actual asset, so the placeholder is unused — we pass "T" as a
20
+ * non-empty stub.
21
+ *
22
+ * Throws `Error` when the chain is not in the swidge catalogue.
23
+ */
24
+ export function encodeSwapKitAsset(swidgeChain, token) {
25
+ const chainCode = swapkitChainFor(swidgeChain);
26
+ if (chainCode === "") {
27
+ throw new Error(`SwapDKSwidge: unknown chain "${swidgeChain}" — must be one of the swidge chain ids from getSupportedChains()`);
28
+ }
29
+ const native = nativeMetaFor(swidgeChain);
30
+ const upper = token.trim().toUpperCase();
31
+ if (native && upper === native.symbol.toUpperCase()) {
32
+ return `${chainCode}.${native.symbol.toUpperCase()}`;
33
+ }
34
+ // Fungible: prefix with a placeholder ticker so the SwapKit parser
35
+ // sees a well-formed identifier. The swap-engine's parser drops the
36
+ // ticker part and keeps only the trailing address, so the stub is
37
+ // never surfaced downstream.
38
+ const trimmed = token.trim();
39
+ return `${chainCode}.T-${trimmed}`;
40
+ }
41
+ /**
42
+ * Converts a base-unit amount (bigint or number) to the human-decimal
43
+ * string the swap-engine expects on the wire.
44
+ *
45
+ * Example: `toHumanAmount(100_000_000n, 8)` → `"1"` (1 BTC).
46
+ * Example: `toHumanAmount(500_000n, 6)` → `"0.5"` (0.5 USDC).
47
+ *
48
+ * Rejects negative and fractional numeric inputs — the swap-engine
49
+ * expects integer base units on the way in, and JS `number` cannot
50
+ * safely represent large integers (> 2^53), so callers should prefer
51
+ * `bigint`.
52
+ */
53
+ export function toHumanAmount(baseUnits, decimals) {
54
+ if (typeof baseUnits === "number") {
55
+ if (!Number.isFinite(baseUnits) || baseUnits < 0) {
56
+ throw new Error(`toHumanAmount: bad amount ${baseUnits}`);
57
+ }
58
+ if (!Number.isInteger(baseUnits)) {
59
+ throw new Error(`toHumanAmount: fractional number ${baseUnits}; pass a bigint for large integer base-unit values`);
60
+ }
61
+ baseUnits = BigInt(baseUnits);
62
+ }
63
+ if (baseUnits < 0n)
64
+ throw new Error(`toHumanAmount: negative amount ${baseUnits}`);
65
+ if (decimals < 0 || !Number.isInteger(decimals)) {
66
+ throw new Error(`toHumanAmount: bad decimals ${decimals}`);
67
+ }
68
+ const raw = baseUnits.toString();
69
+ if (decimals === 0)
70
+ return raw;
71
+ if (raw.length <= decimals) {
72
+ const padded = raw.padStart(decimals + 1, "0");
73
+ const intPart = padded.slice(0, padded.length - decimals);
74
+ const fracPart = padded.slice(padded.length - decimals).replace(/0+$/, "");
75
+ return fracPart === "" ? intPart : `${intPart}.${fracPart}`;
76
+ }
77
+ const intPart = raw.slice(0, raw.length - decimals);
78
+ const fracPart = raw.slice(raw.length - decimals).replace(/0+$/, "");
79
+ return fracPart === "" ? intPart : `${intPart}.${fracPart}`;
80
+ }
81
+ /**
82
+ * Inverse of `toHumanAmount`: parses a human-decimal string returned
83
+ * by the swap-engine and rounds to base units. Truncates rather than
84
+ * rounds to avoid over-quoting.
85
+ */
86
+ export function fromHumanAmount(human, decimals) {
87
+ const trimmed = human.trim();
88
+ if (trimmed === "")
89
+ return 0n;
90
+ const [intPart, fracPartRaw = ""] = trimmed.split(".");
91
+ const fracPart = fracPartRaw.slice(0, decimals).padEnd(decimals, "0");
92
+ const combined = `${intPart}${fracPart}`.replace(/^0+/, "") || "0";
93
+ return BigInt(combined);
94
+ }
95
+ //# sourceMappingURL=asset-encode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asset-encode.js","sourceRoot":"","sources":["../src/asset-encode.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wEAAwE;AACxE,8BAA8B;AAC9B,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,wEAAwE;AACxE,8DAA8D;AAC9D,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEhE;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,kBAAkB,CAAC,WAAmB,EAAE,KAAa;IACnE,MAAM,SAAS,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAC/C,IAAI,SAAS,KAAK,EAAE,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,gCAAgC,WAAW,mEAAmE,CAC/G,CAAC;IACJ,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAC1C,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAEzC,IAAI,MAAM,IAAI,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;QACpD,OAAO,GAAG,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;IACvD,CAAC;IAED,mEAAmE;IACnE,oEAAoE;IACpE,kEAAkE;IAClE,6BAA6B;IAC7B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,OAAO,GAAG,SAAS,MAAM,OAAO,EAAE,CAAC;AACrC,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAC3B,SAA0B,EAC1B,QAAgB;IAEhB,IAAI,OAAO,SAAS,KAAK,QAA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AAI,QAAQ,EAAE,CAAC;IAC9D,CAAC;IAED,MAAM,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACrE,OAAO,QAAQ,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,IAAI,QAAQ,EAAE,CAAC;AAC9D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAa,EAAE,QAAgB;IAC7D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,OAAO,KAAK,EAAE;QAAE,OAAO,EAAE,CAAC;IAC9B,MAAM,CAAC,OAAO,EAAE,WAAW,GAAG,EAAE,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IACtE,MAAM,QAAQ,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;IACnE,OAAO,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Resolves a swidge chain id to the SwapKit chain code used by the
3
+ * `/quote` and `/swap` HTTP surface. Case-insensitive. Returns `""`
4
+ * when the swidge id is unknown — callers must check and surface a
5
+ * user-facing error.
6
+ */
7
+ export declare function swapkitChainFor(swidgeChain: string): string;
8
+ /** Reverse lookup: SwapKit code → swidge id. Returns `""` when unknown. */
9
+ export declare function swidgeChainFor(swapkitChain: string): string;
10
+ /** Chain family (used by the source-dispatch layer to pick an adapter). */
11
+ export declare function chainFamilyFor(swidgeChain: string): "bitcoin" | "evm" | "cosmos" | "tron" | "solana" | "";
12
+ /**
13
+ * Metadata for a chain's native gas coin — ticker + decimals. Used by
14
+ * the option translator to convert between base-unit `fromTokenAmount`
15
+ * and the human-decimal string the swap-engine expects on /quote.
16
+ */
17
+ export declare function nativeMetaFor(swidgeChain: string): {
18
+ symbol: string;
19
+ decimals: number;
20
+ } | null;
21
+ /** All swidge chain ids the module knows about — used by tests. */
22
+ export declare function allSwidgeChains(): string[];
23
+ //# sourceMappingURL=chain-map.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-map.d.ts","sourceRoot":"","sources":["../src/chain-map.ts"],"names":[],"mappings":"AA0CA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAM3D;AAED,2EAA2E;AAC3E,wBAAgB,cAAc,CAC5B,WAAW,EAAE,MAAM,GAClB,SAAS,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,QAAQ,GAAG,EAAE,CAMvD;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,MAAM,GAClB;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAQ7C;AAED,mEAAmE;AACnE,wBAAgB,eAAe,IAAI,MAAM,EAAE,CAE1C"}
@@ -0,0 +1,85 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge chain identifier ↔ SwapKit-style chain code translation.
3
+ //
4
+ // The swap-engine `/quote` and `/swap` HTTP surface still speaks SwapKit
5
+ // notation (`"ETH.USDC-0x…"`, `"BTC.BTC"`, `"THOR.RUNE"`). The swidge protocol
6
+ // speaks lower-case swidge chain ids (`"ethereum"`, `"bitcoin"`, `"thorchain"`).
7
+ // This file is the single translation table.
8
+ //
9
+ // Order matters: the map is the source of truth for supported source chains.
10
+ // Adding a new chain here + wiring an adapter is enough to make the
11
+ // swidge module route it — the /chains discovery endpoint on swap-engine
12
+ // carries the same list on the backend.
13
+ // ---------------------------------------------------------------------------
14
+ /**
15
+ * Ordered list of every swidge chain the module recognises. Kept as an
16
+ * array of tuples so the same source of truth serves both lookup
17
+ * directions.
18
+ */
19
+ const CHAIN_TABLE = [
20
+ { swidge: "bitcoin", swapkit: "BTC", family: "bitcoin", nativeSymbol: "BTC", nativeDecimals: 8 },
21
+ { swidge: "ethereum", swapkit: "ETH", family: "evm", nativeSymbol: "ETH", nativeDecimals: 18 },
22
+ { swidge: "arbitrum", swapkit: "ARB", family: "evm", nativeSymbol: "ETH", nativeDecimals: 18 },
23
+ { swidge: "base", swapkit: "BASE", family: "evm", nativeSymbol: "ETH", nativeDecimals: 18 },
24
+ { swidge: "bsc", swapkit: "BSC", family: "evm", nativeSymbol: "BNB", nativeDecimals: 18 },
25
+ { swidge: "avalanche", swapkit: "AVAX", family: "evm", nativeSymbol: "AVAX", nativeDecimals: 18 },
26
+ { swidge: "tron", swapkit: "TRON", family: "tron", nativeSymbol: "TRX", nativeDecimals: 6 },
27
+ { swidge: "solana", swapkit: "SOL", family: "solana", nativeSymbol: "SOL", nativeDecimals: 9 },
28
+ { swidge: "thorchain", swapkit: "THOR", family: "cosmos", nativeSymbol: "RUNE", nativeDecimals: 8 },
29
+ { swidge: "mayachain", swapkit: "MAYA", family: "cosmos", nativeSymbol: "CACAO", nativeDecimals: 10 },
30
+ { swidge: "cosmoshub", swapkit: "GAIA", family: "cosmos", nativeSymbol: "ATOM", nativeDecimals: 6 },
31
+ { swidge: "dogecoin", swapkit: "DOGE", family: "bitcoin", nativeSymbol: "DOGE", nativeDecimals: 8 },
32
+ { swidge: "bitcoincash", swapkit: "BCH", family: "bitcoin", nativeSymbol: "BCH", nativeDecimals: 8 },
33
+ { swidge: "litecoin", swapkit: "LTC", family: "bitcoin", nativeSymbol: "LTC", nativeDecimals: 8 },
34
+ ];
35
+ /**
36
+ * Resolves a swidge chain id to the SwapKit chain code used by the
37
+ * `/quote` and `/swap` HTTP surface. Case-insensitive. Returns `""`
38
+ * when the swidge id is unknown — callers must check and surface a
39
+ * user-facing error.
40
+ */
41
+ export function swapkitChainFor(swidgeChain) {
42
+ const target = swidgeChain.trim().toLowerCase();
43
+ for (const row of CHAIN_TABLE) {
44
+ if (row.swidge === target)
45
+ return row.swapkit;
46
+ }
47
+ return "";
48
+ }
49
+ /** Reverse lookup: SwapKit code → swidge id. Returns `""` when unknown. */
50
+ export function swidgeChainFor(swapkitChain) {
51
+ const target = swapkitChain.trim().toUpperCase();
52
+ for (const row of CHAIN_TABLE) {
53
+ if (row.swapkit === target)
54
+ return row.swidge;
55
+ }
56
+ return "";
57
+ }
58
+ /** Chain family (used by the source-dispatch layer to pick an adapter). */
59
+ export function chainFamilyFor(swidgeChain) {
60
+ const target = swidgeChain.trim().toLowerCase();
61
+ for (const row of CHAIN_TABLE) {
62
+ if (row.swidge === target)
63
+ return row.family;
64
+ }
65
+ return "";
66
+ }
67
+ /**
68
+ * Metadata for a chain's native gas coin — ticker + decimals. Used by
69
+ * the option translator to convert between base-unit `fromTokenAmount`
70
+ * and the human-decimal string the swap-engine expects on /quote.
71
+ */
72
+ export function nativeMetaFor(swidgeChain) {
73
+ const target = swidgeChain.trim().toLowerCase();
74
+ for (const row of CHAIN_TABLE) {
75
+ if (row.swidge === target) {
76
+ return { symbol: row.nativeSymbol, decimals: row.nativeDecimals };
77
+ }
78
+ }
79
+ return null;
80
+ }
81
+ /** All swidge chain ids the module knows about — used by tests. */
82
+ export function allSwidgeChains() {
83
+ return CHAIN_TABLE.map((r) => r.swidge);
84
+ }
85
+ //# sourceMappingURL=chain-map.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain-map.js","sourceRoot":"","sources":["../src/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eStatusOptions, SwidgeStatusResult, } from "./SwapDKSwidge.js";
3
+ export type { SwapDKSwidgeConfig, SwapDKSwidgeOptions, SwidgeWalletAccount, TronPrebuiltTransaction, TronWebLike, } from "./types.js";
4
+ export type { SwidgeBtcAccount, SwidgeCosmosAccount, SwidgeEvmAccount, SwidgeSolanaAccount, SwidgeTronAccount, } from "./adapters/index.js";
5
+ export { swapkitChainFor, swidgeChainFor, chainFamilyFor, nativeMetaFor, allSwidgeChains, } from "./chain-map.js";
6
+ export { encodeSwapKitAsset, toHumanAmount, fromHumanAmount, } from "./asset-encode.js";
7
+ export { SwapDKError, SwapDKNetworkError, SwapDKApiError, SwapDKProviderError, SwapDKUserError, } from "@swapdk/swap-engine-client";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EACV,YAAY,EACZ,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,YAAY,EACZ,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,WAAW,GACZ,MAAM,YAAY,CAAC;AAMpB,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,gBAAgB,EAChB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACL,eAAe,EACf,cAAc,EACd,cAAc,EACd,aAAa,EACb,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,eAAe,GAChB,MAAM,4BAA4B,CAAC"}