@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,23 @@
1
+ import type { SwidgeAdapter } from "./types.js";
2
+ /**
3
+ * Structural subset of `@tetherto/wdk-wallet-btc` (or the SwapDK fork).
4
+ * The `memo` field is a SwapDK fork addition; when running against
5
+ * unmodified upstream `@tetherto/wdk-wallet-btc` (which lacks memo
6
+ * support until the pending upstream PR lands) the adapter throws
7
+ * loudly at `sendTransaction()` time on THORChain routes.
8
+ */
9
+ export interface SwidgeBtcAccount {
10
+ getAddress(): string | Promise<string>;
11
+ sendTransaction(options: {
12
+ to: string;
13
+ value: bigint;
14
+ feeRate?: number | bigint;
15
+ confirmationTarget?: number;
16
+ memo?: string | Uint8Array;
17
+ }): Promise<{
18
+ hash: string;
19
+ fee: bigint;
20
+ }>;
21
+ }
22
+ export declare const btcAdapter: SwidgeAdapter;
23
+ //# sourceMappingURL=btc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"btc.d.ts","sourceRoot":"","sources":["../../src/adapters/btc.ts"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAQpB;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,eAAe,CAAC,OAAO,EAAE;QACvB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,EAAE,MAAM,CAAC;QACd,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;KAC5B,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5C;AAeD,eAAO,MAAM,UAAU,EAAE,aAwBxB,CAAC"}
@@ -0,0 +1,159 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge adapter: Bitcoin source.
3
+ //
4
+ // Two provider paths, picked from the route's `providers[]`:
5
+ //
6
+ // - THORChain / MAYAChain: deposit to the rotating Asgard vault with
7
+ // the swap memo as an OP_RETURN output. Tx params come from the
8
+ // /quote response (`inboundAddress`, `memo`, `sellAmount`) — no
9
+ // /swap call needed. The paired BTC wallet's `sendTransaction`
10
+ // accepts an optional `memo` field and appends it as OP_RETURN.
11
+ //
12
+ // - Chainflip: broker-channel model. Adapter opens a channel via
13
+ // swap-engine's `/chainflip/broker/channel`, receives a
14
+ // per-swap-intent deposit address, and sends a plain BTC transfer
15
+ // there (no memo — the address itself encodes the intent).
16
+ //
17
+ // Same dispatch pattern the legacy `SwapDKBridgeBtc` uses; this adapter
18
+ // is that dispatch loop lifted into a swidge-friendly shape.
19
+ // ---------------------------------------------------------------------------
20
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
21
+ import { fromHumanAmount } from "../asset-encode.js";
22
+ // BTC's native decimals; sats-per-BTC = 1e8.
23
+ const BTC_DECIMALS = 8;
24
+ const THOR_PROVIDERS = new Set(["THORCHAIN", "MAYACHAIN"]);
25
+ const CHAINFLIP_PROVIDER = "CHAINFLIP";
26
+ // SwapKit chain prefix → Chainflip's long-form chain name. Mirrors the
27
+ // `CHAINFLIP_CHAIN_BY_PREFIX` map in packages/btc/src/SwapDKBridgeBtc.ts
28
+ // and `chainflipChainShort` in swap-engine's utils/track_chainflip.go.
29
+ const CHAINFLIP_CHAIN_BY_PREFIX = {
30
+ BTC: "Bitcoin",
31
+ ETH: "Ethereum",
32
+ ARB: "Arbitrum",
33
+ BASE: "Base",
34
+ SOL: "Solana",
35
+ DOT: "Polkadot",
36
+ ASSETHUB: "AssetHub",
37
+ };
38
+ export const btcAdapter = {
39
+ family: "bitcoin",
40
+ // BTC's THORChain path builds its tx from /quote alone; the Chainflip
41
+ // path uses /chainflip/broker/channel. Neither needs /swap.
42
+ needsSwapResponse: false,
43
+ async execute(account, ctx) {
44
+ const { route } = ctx;
45
+ const kind = classifyProvider(route);
46
+ if (kind === "thor") {
47
+ return dispatchThor(account, ctx);
48
+ }
49
+ if (kind === "chainflip") {
50
+ return dispatchChainflip(account, ctx);
51
+ }
52
+ throw new SwapDKUserError("SwapDKSwidge (btc): unsupported provider(s) on route: " +
53
+ `${(route.providers ?? []).join(", ") || "<none>"}. ` +
54
+ "Supported: THORCHAIN, MAYACHAIN, CHAINFLIP.");
55
+ },
56
+ };
57
+ // -- dispatch branches ---------------------------------------------------
58
+ async function dispatchThor(account, ctx) {
59
+ const { route, config, fromChain } = ctx;
60
+ if (!route.inboundAddress) {
61
+ throw new SwapDKUserError("SwapDKSwidge (btc/thor): swap-engine quote returned no inboundAddress. " +
62
+ `Providers: ${route.providers.join(", ")}`);
63
+ }
64
+ if (!route.memo) {
65
+ throw new SwapDKUserError("SwapDKSwidge (btc/thor): swap-engine quote returned no memo. Without an " +
66
+ "OP_RETURN memo THORChain refunds the deposit. Providers: " +
67
+ route.providers.join(", "));
68
+ }
69
+ if (route.expiration) {
70
+ const expiresAt = Number(route.expiration) * 1000;
71
+ if (Number.isFinite(expiresAt) && expiresAt < Date.now()) {
72
+ throw new SwapDKUserError(`SwapDKSwidge (btc/thor): quoted inbound vault expired at ${route.expiration}. Re-quote and try again.`);
73
+ }
74
+ }
75
+ const value = fromHumanAmount(route.sellAmount, BTC_DECIMALS);
76
+ const { hash } = await account.sendTransaction({
77
+ to: route.inboundAddress,
78
+ value,
79
+ feeRate: config.feeRate,
80
+ memo: route.memo,
81
+ });
82
+ const transactions = [
83
+ { hash, chain: fromChain, type: "source" },
84
+ ];
85
+ return { hash, transactions };
86
+ }
87
+ async function dispatchChainflip(account, ctx) {
88
+ const { route, client, options, config, fromChain, sourceAddress } = ctx;
89
+ if (!options.recipient) {
90
+ throw new SwapDKUserError("SwapDKSwidge (btc/chainflip): options.recipient is required — Chainflip " +
91
+ "encodes the destination in the broker-channel deposit address.");
92
+ }
93
+ const req = {
94
+ sellAsset: swapKitAssetToChainflip(route.sellAsset),
95
+ buyAsset: swapKitAssetToChainflip(route.buyAsset),
96
+ destinationAddress: options.recipient,
97
+ // sellAmount surfaces swap-engine's `CheckChainflipMinimumDeposit`
98
+ // guard — sub-min deposits are unrecoverable on Chainflip, so we
99
+ // want the pre-flight check on the server before allocating a
100
+ // channel.
101
+ sellAmount: route.sellAmount,
102
+ refundParameters: {
103
+ refundAddress: options.refundAddress ?? sourceAddress,
104
+ minPrice: config.chainflip?.refundMinPrice ?? "0x0",
105
+ retryDuration: config.chainflip?.refundRetryDuration ?? 100,
106
+ },
107
+ };
108
+ const dcaChunks = config.chainflip?.dcaChunks ?? 1;
109
+ if (dcaChunks > 1) {
110
+ if (config.chainflip?.dcaChunkInterval === undefined) {
111
+ throw new SwapDKUserError("SwapDKSwidge (btc/chainflip): config.chainflip.dcaChunkInterval is required when dcaChunks > 1");
112
+ }
113
+ req.dcaParameters = {
114
+ chunkInterval: config.chainflip.dcaChunkInterval,
115
+ numberOfChunks: dcaChunks,
116
+ };
117
+ }
118
+ const maxBoostFeeBps = config.chainflip?.maxBoostFeeBps ?? 0;
119
+ if (maxBoostFeeBps > 0) {
120
+ req.maxBoostFeeBps = maxBoostFeeBps;
121
+ }
122
+ const channel = await client.openBrokerChannel(req);
123
+ const value = fromHumanAmount(route.sellAmount, BTC_DECIMALS);
124
+ const { hash } = await account.sendTransaction({
125
+ to: channel.depositAddress,
126
+ value,
127
+ feeRate: config.feeRate,
128
+ // No memo on Chainflip — the deposit address encodes the intent.
129
+ });
130
+ const transactions = [
131
+ { hash, chain: fromChain, type: "source" },
132
+ ];
133
+ return { hash, transactions };
134
+ }
135
+ // -- helpers -------------------------------------------------------------
136
+ function classifyProvider(route) {
137
+ const providers = route.providers ?? [];
138
+ if (providers.some((p) => THOR_PROVIDERS.has(p)))
139
+ return "thor";
140
+ if (providers.includes(CHAINFLIP_PROVIDER))
141
+ return "chainflip";
142
+ return undefined;
143
+ }
144
+ function swapKitAssetToChainflip(asset) {
145
+ const dot = asset.indexOf(".");
146
+ if (dot < 0) {
147
+ throw new SwapDKUserError(`SwapDKSwidge (btc/chainflip): cannot convert asset "${asset}" to Chainflip notation — not a SwapKit asset string.`);
148
+ }
149
+ const chainPrefix = asset.slice(0, dot).toUpperCase();
150
+ const rest = asset.slice(dot + 1);
151
+ const dash = rest.indexOf("-");
152
+ const symbol = dash < 0 ? rest : rest.slice(0, dash);
153
+ const chain = CHAINFLIP_CHAIN_BY_PREFIX[chainPrefix];
154
+ if (!chain) {
155
+ throw new SwapDKUserError(`SwapDKSwidge (btc/chainflip): Chainflip does not support chain prefix "${chainPrefix}" (asset: ${asset}).`);
156
+ }
157
+ return { chain, asset: symbol.toUpperCase() };
158
+ }
159
+ //# sourceMappingURL=btc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"btc.js","sourceRoot":"","sources":["../../src/adapters/btc.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kCAAkC;AAClC,EAAE;AACF,6DAA6D;AAC7D,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,oEAAoE;AACpE,mEAAmE;AACnE,oEAAoE;AACpE,EAAE;AACF,mEAAmE;AACnE,4DAA4D;AAC5D,sEAAsE;AACtE,+DAA+D;AAC/D,EAAE;AACF,wEAAwE;AACxE,6DAA6D;AAC7D,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAO7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAQrD,6CAA6C;AAC7C,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C;IAClC,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC/B,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,yBAAyB,CAAC,WAAW,CAAC,CAAC;IACrD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,eAAe,CACvB,0EAA0E,WAAW,aAAa,KAAK,IAAI,CAC5G,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,EAAE,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { SwidgeAdapter } from "./types.js";
2
+ /**
3
+ * Structural subset of `@base58-io/wdk-wallet-cosmos` / the SwapDK fork.
4
+ * Both `deposit()` (MsgDeposit) and `transfer()` (MsgSend with memo)
5
+ * are required — an unmodified upstream that lacks `deposit()` will
6
+ * fail loudly at execute() time on the THORChain-native path.
7
+ */
8
+ export interface SwidgeCosmosAccount {
9
+ getAddress(): string | Promise<string>;
10
+ deposit(options: {
11
+ asset: string;
12
+ amount: bigint | string;
13
+ memo: string;
14
+ }, overrides?: {
15
+ gas?: string | number;
16
+ }): Promise<{
17
+ hash: string;
18
+ fee: bigint;
19
+ }>;
20
+ transfer(options: {
21
+ token: string;
22
+ recipient: string;
23
+ amount: bigint | string;
24
+ memo?: string;
25
+ }): Promise<{
26
+ hash: string;
27
+ fee: bigint;
28
+ }>;
29
+ }
30
+ export declare const cosmosAdapter: SwidgeAdapter;
31
+ //# sourceMappingURL=cosmos.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cosmos.d.ts","sourceRoot":"","sources":["../../src/adapters/cosmos.ts"],"names":[],"mappings":"AA4BA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAYpB;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC,OAAO,CACL,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EACjE,SAAS,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GACpC,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE1C,QAAQ,CAAC,OAAO,EAAE;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,CAAC;QAClB,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;QACxB,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAC5C;AAED,eAAO,MAAM,aAAa,EAAE,aA6D3B,CAAC"}
@@ -0,0 +1,103 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge adapter: Cosmos-family source (THORChain / MAYAChain).
3
+ //
4
+ // Two broadcast strategies, picked from the /swap response shape:
5
+ //
6
+ // - MsgDeposit (protocol-native): swap-engine returns an empty
7
+ // inboundAddress (or one equal to the source address). The user
8
+ // signs `types.MsgDeposit` against their own THORChain / MAYAChain
9
+ // wallet; the protocol's Asgard module observes the memo. This is
10
+ // the case for RUNE-originated swaps routed through THORChain
11
+ // pools (RUNE → BTC via THORChain), or CACAO-originated swaps via
12
+ // MAYAChain.
13
+ //
14
+ // - MsgSend (cross-protocol): inboundAddress is a vault on the source
15
+ // chain — funds must be sent there with the memo attached to the
16
+ // tx body. The paired wallet's `transfer()` method emits a
17
+ // `MsgSend` with the memo set. Used for cross-protocol routes
18
+ // (e.g. RUNE → BTC routed via MAYAChain sends RUNE to MAYAChain's
19
+ // THORChain vault).
20
+ //
21
+ // The paired wallet is `@base58-io/wdk-wallet-cosmos` (once the upstream
22
+ // PRs land) or the SwapDK `@swapdk/wdk-wallet-cosmos` fork with
23
+ // `deposit()` + memo-in-transfer support today.
24
+ // ---------------------------------------------------------------------------
25
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
26
+ /**
27
+ * Native bank-module denom for the Cosmos source chain. Used as the
28
+ * `token` field on the MsgSend cross-protocol path. Mirrors the
29
+ * `nativeDenom` value the paired wallet manager was constructed with.
30
+ */
31
+ const NATIVE_DENOM_FOR_CHAIN = {
32
+ thorchain: "rune",
33
+ mayachain: "cacao",
34
+ };
35
+ export const cosmosAdapter = {
36
+ family: "cosmos",
37
+ needsSwapResponse: true,
38
+ async execute(account, ctx) {
39
+ const { swapRes, sourceAddress, fromChain } = ctx;
40
+ if (!swapRes) {
41
+ throw new SwapDKUserError("SwapDKSwidge (cosmos): missing /swap response — this is a bug in the swidge module (adapter should have signalled needsSwapResponse=true).");
42
+ }
43
+ if (!swapRes.memo) {
44
+ throw new SwapDKUserError("SwapDKSwidge (cosmos): swap-engine returned no routing memo. Without a memo the deposit/transfer cannot be processed and funds would be lost. " +
45
+ `Providers: ${swapRes.providers.join(", ")}`);
46
+ }
47
+ // Sell amount comes through the /swap response in human-decimal
48
+ // form. Wallet.deposit() / wallet.transfer() accept either bigint
49
+ // (base units) or string (human-decimal); we pass the string
50
+ // through unchanged and let the wallet do the decimal conversion.
51
+ // This is deliberate — the wallet knows the chain's native
52
+ // decimals (8 for RUNE, 10 for CACAO), so a client-side conversion
53
+ // here would duplicate that logic.
54
+ const amount = swapRes.sellAmount;
55
+ const inboundVault = detectInboundVault(swapRes, sourceAddress);
56
+ let txResult;
57
+ if (inboundVault === undefined) {
58
+ // MsgDeposit — protocol-native path.
59
+ txResult = await account.deposit({
60
+ asset: swapRes.sellAsset,
61
+ amount,
62
+ memo: swapRes.memo,
63
+ });
64
+ }
65
+ else {
66
+ // MsgSend — cross-protocol path.
67
+ const denom = nativeDenomFor(fromChain);
68
+ if (!denom) {
69
+ throw new SwapDKUserError(`SwapDKSwidge (cosmos): unsupported source chain "${fromChain}" for MsgSend dispatch. ` +
70
+ `Supported: ${Object.keys(NATIVE_DENOM_FOR_CHAIN).join(", ")}.`);
71
+ }
72
+ txResult = await account.transfer({
73
+ token: denom,
74
+ recipient: inboundVault,
75
+ amount,
76
+ memo: swapRes.memo,
77
+ });
78
+ }
79
+ const transactions = [
80
+ { hash: txResult.hash, chain: fromChain, type: "source" },
81
+ ];
82
+ return { hash: txResult.hash, transactions };
83
+ },
84
+ };
85
+ // -- helpers -------------------------------------------------------------
86
+ /**
87
+ * Returns the inbound vault address for a MsgSend dispatch, or
88
+ * undefined when the route is protocol-native (MsgDeposit). bech32
89
+ * is case-sensitive but addresses sometimes arrive with surrounding
90
+ * whitespace — trim before comparing to the source address.
91
+ */
92
+ function detectInboundVault(swapRes, sourceAddress) {
93
+ const candidate = (swapRes.inboundAddress ?? swapRes.targetAddress ?? "").trim();
94
+ if (!candidate)
95
+ return undefined;
96
+ if (candidate === sourceAddress)
97
+ return undefined;
98
+ return candidate;
99
+ }
100
+ function nativeDenomFor(swidgeChain) {
101
+ return NATIVE_DENOM_FOR_CHAIN[swidgeChain.toLowerCase()];
102
+ }
103
+ //# sourceMappingURL=cosmos.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cosmos.js","sourceRoot":"","sources":["../../src/adapters/cosmos.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,gEAAgE;AAChE,EAAE;AACF,kEAAkE;AAClE,EAAE;AACF,iEAAiE;AACjE,oEAAoE;AACpE,uEAAuE;AACvE,sEAAsE;AACtE,kEAAkE;AAClE,sEAAsE;AACtE,iBAAiB;AACjB,EAAE;AACF,wEAAwE;AACxE,qEAAqE;AACrE,+DAA+D;AAC/D,kEAAkE;AAClE,s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AccountEvm`). We only need
5
+ * `sendTransaction` and an optional `waitForTransaction`; getAddress
6
+ * lives on the account too but SwapDKSwidge resolves it upstream and
7
+ * threads through the swap-engine calldata rather than the adapter.
8
+ */
9
+ export interface SwidgeEvmAccount {
10
+ sendTransaction(tx: {
11
+ to: string;
12
+ value?: bigint;
13
+ data?: string;
14
+ gas?: bigint;
15
+ }): Promise<string | {
16
+ hash: string;
17
+ }>;
18
+ waitForTransaction?(hash: string, timeoutMs?: number): Promise<void>;
19
+ }
20
+ export declare const evmAdapter: SwidgeAdapter;
21
+ //# sourceMappingURL=evm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/adapters/evm.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAEpB;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B,eAAe,CAAC,EAAE,EAAE;QAClB,EAAE,EAAE,MAAM,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACvC,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtE;AAED,eAAO,MAAM,UAAU,EAAE,aA4DxB,CAAC"}
@@ -0,0 +1,72 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Swidge adapter: EVM source (Ethereum, Arbitrum, Base, BSC, Avalanche, …).
3
+ //
4
+ // Wraps the WDK EVM wallet account and dispatches:
5
+ // 1. An optional ERC-20 approval tx (when the source is a fungible and
6
+ // the swap-engine returned an `approvalTx`).
7
+ // 2. The main deposit / router-contract call.
8
+ //
9
+ // The tx bodies come pre-built from swap-engine (`/swap` response); the
10
+ // adapter just coerces field types and forwards through the wallet. Same
11
+ // pattern as the legacy `SwapDKBridgeEvm` — this adapter is essentially
12
+ // its dispatch loop lifted into a swidge-friendly shape.
13
+ // ---------------------------------------------------------------------------
14
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
15
+ export const evmAdapter = {
16
+ family: "evm",
17
+ needsSwapResponse: true,
18
+ async execute(account, ctx) {
19
+ const { swapRes, fromChain } = ctx;
20
+ if (!swapRes) {
21
+ throw new SwapDKUserError("SwapDKSwidge (evm): missing /swap response — this is a bug in the swidge module (adapter should have signalled needsSwapResponse=true).");
22
+ }
23
+ const transactions = [];
24
+ // 1. Optional ERC-20 approval leg.
25
+ if (swapRes.approvalTx) {
26
+ const approveResult = await account.sendTransaction({
27
+ to: swapRes.approvalTx.to,
28
+ data: swapRes.approvalTx.data,
29
+ value: swapRes.approvalTx.value
30
+ ? BigInt(swapRes.approvalTx.value)
31
+ : 0n,
32
+ gas: swapRes.approvalTx.gasLimit
33
+ ? BigInt(swapRes.approvalTx.gasLimit)
34
+ : undefined,
35
+ });
36
+ const approveHash = extractHash(approveResult);
37
+ transactions.push({
38
+ hash: approveHash,
39
+ chain: fromChain,
40
+ type: "approval",
41
+ });
42
+ if (account.waitForTransaction) {
43
+ await account.waitForTransaction(approveHash);
44
+ }
45
+ }
46
+ // 2. Main deposit / router call.
47
+ const tx = swapRes.tx;
48
+ if (!tx) {
49
+ throw new SwapDKUserError("SwapDKSwidge (evm): swap-engine returned no transaction data — " +
50
+ "the route may require a manual deposit. Providers: " +
51
+ swapRes.providers.join(", "));
52
+ }
53
+ const sendResult = await account.sendTransaction({
54
+ to: tx.to,
55
+ data: tx.data,
56
+ value: tx.value ? BigInt(tx.value) : 0n,
57
+ gas: tx.gas ? BigInt(tx.gas) : undefined,
58
+ });
59
+ const hash = extractHash(sendResult);
60
+ transactions.push({ hash, chain: fromChain, type: "source" });
61
+ return { hash, transactions };
62
+ },
63
+ };
64
+ /**
65
+ * WDK EVM wallets diverge on `sendTransaction`'s return shape: some ship
66
+ * the tx hash as a raw hex string, others wrap it as `{ hash }`. Accept
67
+ * both — same handling as `SwapDKBridgeEvm`'s `txHash` helper.
68
+ */
69
+ function extractHash(result) {
70
+ return typeof result === "string" ? result : result.hash;
71
+ }
72
+ //# sourceMappingURL=evm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"evm.js","sourceRoot":"","sources":["../../src/adapters/evm.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4EAA4E;AAC5E,EAAE;AACF,mDAAmD;AACnD,yEAAyE;AACzE,kDAAkD;AAClD,gDAAgD;AAChD,EAAE;AACF,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AACxE,yDAAyD;AACzD,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AA0B7D,MAAM,CAAC,MAAM,UAAU,GAAkB;IACvC,MAAM,EAAE,KAAK;IACb,iBAAiB,EAAE,IAAI;IAEvB,KAAK,CAAC,OAAO,CACX,OAAyB,EACzB,GAAyB;QAEzB,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;QACnC,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,eAAe,CACvB,yIAAyI,CAC1I,CAAC;QACJ,CAAC;QACD,MAAM,YAAY,GAAwB,EAAE,CAAC;QAE7C,mCAAmC;QACnC,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC;gBAClD,EAAE,EAAE,OAAO,CAAC,UAAU,CAAC,EAAE;gBACzB,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,IAAI;gBAC7B,KAAK,EAAE,OAAO,CAAC,UAAU,CAAC,KAAK;oBAC7B,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;oBAClC,CAAC,CAAC,EAAE;gBACN,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AAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;IAChC,CAAC;CACF,CAAC;AAEF;;;;GAIG;AACH,SAAS,WAAW,CAAC,MAAiC;IACpD,OAAO,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;AAC3D,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { SwidgeAdapter } from "./types.js";
2
+ export type { SwidgeAdapter, SwidgeAdapterContext, SwidgeAdapterResult } from "./types.js";
3
+ export type { SwidgeBtcAccount } from "./btc.js";
4
+ export type { SwidgeCosmosAccount } from "./cosmos.js";
5
+ export type { SwidgeEvmAccount } from "./evm.js";
6
+ export type { SwidgeSolanaAccount } from "./solana.js";
7
+ export type { SwidgeTronAccount } from "./tron.js";
8
+ export { btcAdapter } from "./btc.js";
9
+ export { cosmosAdapter } from "./cosmos.js";
10
+ export { evmAdapter } from "./evm.js";
11
+ export { solanaAdapter } from "./solana.js";
12
+ export { tronAdapter } from "./tron.js";
13
+ /**
14
+ * Resolve the adapter for a given swidge source chain id. Throws with
15
+ * a clear message when the chain has no adapter yet.
16
+ */
17
+ export declare function adapterFor(swidgeChain: string): SwidgeAdapter;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAC3F,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAYxC;;;GAGG;AACH,wBAAgB,UAAU,CAAC,WAAW,EAAE,MAAM,GAAG,aAAa,CAe7D"}
@@ -0,0 +1,45 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Adapter registry — one entry per source-chain family.
3
+ //
4
+ // SwapDKSwidge.swidge() calls `adapterFor(fromChain)` at dispatch time.
5
+ // Missing adapters throw a `SwapDKUserError` with a clear next step (usually
6
+ // "install the corresponding wallet package"); the discovery methods
7
+ // (getSupportedChains / getSupportedTokens) never advertise a source chain
8
+ // whose adapter isn't registered here.
9
+ // ---------------------------------------------------------------------------
10
+ import { SwapDKUserError } from "@swapdk/swap-engine-client";
11
+ import { chainFamilyFor } from "../chain-map.js";
12
+ import { btcAdapter } from "./btc.js";
13
+ import { cosmosAdapter } from "./cosmos.js";
14
+ import { evmAdapter } from "./evm.js";
15
+ import { solanaAdapter } from "./solana.js";
16
+ import { tronAdapter } from "./tron.js";
17
+ export { btcAdapter } from "./btc.js";
18
+ export { cosmosAdapter } from "./cosmos.js";
19
+ export { evmAdapter } from "./evm.js";
20
+ export { solanaAdapter } from "./solana.js";
21
+ export { tronAdapter } from "./tron.js";
22
+ const ADAPTERS_BY_FAMILY = {
23
+ bitcoin: btcAdapter,
24
+ cosmos: cosmosAdapter,
25
+ evm: evmAdapter,
26
+ solana: solanaAdapter,
27
+ tron: tronAdapter,
28
+ };
29
+ /**
30
+ * Resolve the adapter for a given swidge source chain id. Throws with
31
+ * a clear message when the chain has no adapter yet.
32
+ */
33
+ export function adapterFor(swidgeChain) {
34
+ const family = chainFamilyFor(swidgeChain);
35
+ if (family === "") {
36
+ throw new SwapDKUserError(`SwapDKSwidge: unknown source chain "${swidgeChain}" — see getSupportedChains()`);
37
+ }
38
+ const adapter = ADAPTERS_BY_FAMILY[family];
39
+ if (!adapter) {
40
+ throw new SwapDKUserError(`SwapDKSwidge: source chain "${swidgeChain}" (family "${family}") is not yet supported by this package. ` +
41
+ `Currently supported families: ${Object.keys(ADAPTERS_BY_FAMILY).join(", ")}.`);
42
+ }
43
+ return adapter;
44
+ }
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/adapters/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,wDAAwD;AACxD,EAAE;AACF,wEAAwE;AACxE,6EAA6E;AAC7E,qEAAqE;AACrE,2EAA2E;AAC3E,uCAAuC;AACvC,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AASxC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,kBAAkB,GAEpB;IACF,OAAO,EAAE,UAAU;IACnB,MAAM,EAAE,aAAa;IACrB,GAAG,EAAE,UAAU;IACf,MAAM,EAAE,aAAa;IACrB,IAAI,EAAE,WAAW;CAClB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,WAAmB;IAC5C,MAAM,MAAM,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QAClB,MAAM,IAAI,eAAe,CACvB,uCAAuC,WAAW,8BAA8B,CACjF,CAAC;IACJ,CAAC;IACD,MAAM,OAAO,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CACvB,+BAA+B,WAAW,cAAc,MAAM,2CAA2C;YACvG,iCAAiC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CACjF,CAAC;IACJ,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,32 @@
1
+ import { type TransactionMessage } from "@solana/transaction-messages";
2
+ import type { SwidgeAdapter } from "./types.js";
3
+ /**
4
+ * Structural subset of `@tetherto/wdk-wallet-solana`'s
5
+ * `WalletAccountSolana`. The wallet fills in blockhash + fee payer,
6
+ * signs with the account's keypair, and broadcasts.
7
+ */
8
+ export interface SwidgeSolanaAccount {
9
+ getAddress(): string | Promise<string>;
10
+ sendTransaction(tx: any): Promise<{
11
+ hash: string;
12
+ fee?: bigint;
13
+ }>;
14
+ waitForTransaction?(hash: string): Promise<void>;
15
+ }
16
+ export declare const solanaAdapter: SwidgeAdapter;
17
+ /**
18
+ * Build a Solana `transactionMessage` containing:
19
+ * 1. SystemProgram transfer of `lamports` from `source` → `destination`
20
+ * 2. Memo Program instruction carrying `memo` as UTF-8 bytes
21
+ *
22
+ * Lifetime (recent blockhash) + fee payer are NOT set here — the WDK
23
+ * Solana wallet's `sendTransaction` fills both. Pure function; no RPC.
24
+ */
25
+ export interface BuildNativeTransferWithMemoArgs {
26
+ source: string;
27
+ destination: string;
28
+ lamports: bigint;
29
+ memo: string;
30
+ }
31
+ export declare function buildNativeTransferWithMemo(args: BuildNativeTransferWithMemoArgs): TransactionMessage;
32
+ //# sourceMappingURL=solana.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/adapters/solana.ts"],"names":[],"mappings":"AAyBA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AAMtC,OAAO,KAAK,EACV,aAAa,EAGd,MAAM,YAAY,CAAC;AAKpB;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvC,eAAe,CAAC,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAClE,kBAAkB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClD;AAED,eAAO,MAAM,aAAa,EAAE,aAoD3B,CAAC;AAeF;;;;;;;GAOG;AACH,MAAM,WAAW,+BAA+B;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,+BAA+B,GACpC,kBAAkB,CAwBpB"}