@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
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @swapdk/wdk-protocol-swidge-swapdk — public exports.
3
+ // ---------------------------------------------------------------------------
4
+ export { SwapDKSwidge } from "./SwapDKSwidge.js";
5
+ export { swapkitChainFor, swidgeChainFor, chainFamilyFor, nativeMetaFor, allSwidgeChains, } from "./chain-map.js";
6
+ export { encodeSwapKitAsset, toHumanAmount, fromHumanAmount, } from "./asset-encode.js";
7
+ // Re-export the swap-engine-client errors that consumers may catch on
8
+ // their end so they don't need to install the client package directly.
9
+ export { SwapDKError, SwapDKNetworkError, SwapDKApiError, SwapDKProviderError, SwapDKUserError, } from "@swapdk/swap-engine-client";
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,uDAAuD;AACvD,8EAA8E;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAgCjD,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;AAE3B,sEAAsE;AACtE,uEAAuE;AACvE,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,eAAe,GAChB,MAAM,4BAA4B,CAAC"}
@@ -0,0 +1,163 @@
1
+ import type { SwapDKClientConfig } from "@swapdk/swap-engine-client";
2
+ import type { SwidgeProtocolConfig } from "@tetherto/wdk-wallet/protocols";
3
+ /**
4
+ * Wallet-account interface SwapDKSwidge accepts. This is intentionally a
5
+ * structural subset of `IWalletAccount` from `@tetherto/wdk-wallet` — we
6
+ * only need `getAddress()` for source-address handling and `sendTransaction`
7
+ * for broadcasting. The concrete wallet manager module (e.g.
8
+ * `@tetherto/wdk-wallet-evm`, `@tetherto/wdk-wallet-tron`) supplies these.
9
+ *
10
+ * `sendTransaction` is intentionally typed `unknown`; each source-chain
11
+ * adapter narrows the argument shape internally and validates before
12
+ * dispatching. This keeps the type surface small at the top level.
13
+ */
14
+ export interface SwidgeWalletAccount {
15
+ getAddress(): string | Promise<string>;
16
+ sendTransaction(tx: unknown, timeoutMs?: number): Promise<{
17
+ hash: string;
18
+ fee: bigint;
19
+ [key: string]: unknown;
20
+ }>;
21
+ }
22
+ /**
23
+ * Opaque marker for a prebuilt tronweb `Transaction`. Downstream
24
+ * (`@tetherto/wdk-wallet-tron@^1.0.0-beta.8`) detects the prebuilt
25
+ * shape via `!!tx.txID` and signs + broadcasts it verbatim.
26
+ */
27
+ export interface TronPrebuiltTransaction {
28
+ txID: string;
29
+ [key: string]: unknown;
30
+ }
31
+ /**
32
+ * Structural subset of the `tronweb` client used by the TRON adapter.
33
+ * Any object satisfying this shape works — the concrete `TronWeb`
34
+ * from `import { TronWeb } from 'tronweb'`, forks, or test mocks.
35
+ */
36
+ export interface TronWebLike {
37
+ address: {
38
+ toHex(addr: string): string;
39
+ };
40
+ /** Fallback per-tx energy cap when the swap-engine SwapTx doesn't supply one. */
41
+ feeLimit?: number;
42
+ transactionBuilder: {
43
+ /**
44
+ * Build a `TriggerSmartContract` transaction. When `functionSelector`
45
+ * is empty and `options.input` is set, tronweb passes the raw hex
46
+ * as calldata verbatim — the same code path used for the THORChain
47
+ * router `depositWithExpiry` call and TRC-20 `approve`.
48
+ */
49
+ triggerSmartContract(contractAddress: string, functionSelector: string, options: {
50
+ feeLimit?: number;
51
+ callValue?: number;
52
+ input?: string;
53
+ }, parameters: Array<{
54
+ type: string;
55
+ value: string | number | bigint;
56
+ }>, issuerAddress: string): Promise<{
57
+ transaction: TronPrebuiltTransaction;
58
+ }>;
59
+ /** Build a plain `TransferContract` (native TRX transfer). */
60
+ sendTrx(to: string, value: number, from: string): Promise<TronPrebuiltTransaction>;
61
+ /**
62
+ * Attach a memo to a `TransferContract` via `raw_data.data`. The
63
+ * memo is part of the tx hash preimage so this MUST be called
64
+ * before signing — the returned tx has a fresh `txID`.
65
+ */
66
+ addUpdateData(transaction: TronPrebuiltTransaction, data: string, encoding?: string): Promise<TronPrebuiltTransaction>;
67
+ };
68
+ }
69
+ /**
70
+ * Configuration for `SwapDKSwidge`.
71
+ *
72
+ * `defaultFromChain` seeds `fromChain` for quoteSwidge / swidge calls that
73
+ * omit it — useful when an instance is bound to a specific source (an
74
+ * `example-wdk-wallet` CLI running with NETWORK=ethereum, for instance).
75
+ * Per-call `fromChain` in options always wins over this default.
76
+ */
77
+ export interface SwapDKSwidgeConfig extends SwapDKClientConfig, SwidgeProtocolConfig {
78
+ /** SwapDK swap-engine base URL (e.g. `"https://api.swapdk.com"`). */
79
+ apiUrl: string;
80
+ /** SwapDK API key (sent as `x-api-key`). */
81
+ apiKey: string;
82
+ /** Default source chain when options don't set `fromChain`. Optional. */
83
+ defaultFromChain?: string;
84
+ /**
85
+ * Default slippage (decimal, e.g. 0.03 for 3%) when options don't set
86
+ * either `slippage` or `minAmountOut`. Optional (fallback: 0.03).
87
+ */
88
+ defaultSlippage?: number;
89
+ /**
90
+ * Bitcoin miner-fee rate in sats/vB. Consumed by the BTC adapter for
91
+ * both THORChain-path and Chainflip-path deposits. Optional — when
92
+ * omitted the paired WDK BTC wallet estimates the fee from its
93
+ * connected Electrum backend.
94
+ */
95
+ feeRate?: number | bigint;
96
+ /**
97
+ * TronWeb instance the TRON adapter uses to build the prebuilt
98
+ * transaction (router-contract call or TransferContract-with-memo)
99
+ * before handing it to `wallet.sendTransaction`. Required for TRON
100
+ * sources, ignored otherwise. Pass the same tronweb instance the
101
+ * paired `WalletManagerTron` was constructed with.
102
+ *
103
+ * Structurally typed via `TronWebLike` — a subset covering
104
+ * `address.toHex`, `transactionBuilder.{triggerSmartContract,sendTrx,addUpdateData}`,
105
+ * and an optional `feeLimit` fallback.
106
+ */
107
+ tronWeb?: TronWebLike;
108
+ /** Optional Chainflip-broker-channel defaults for the BTC adapter. */
109
+ chainflip?: {
110
+ /** Refund min-price hex (default: `"0x0"`, no floor). */
111
+ refundMinPrice?: string;
112
+ /** Blocks the broker will retry the refund tx (default: 100). */
113
+ refundRetryDuration?: number;
114
+ /** DCA number of chunks (default: 1, no DCA). */
115
+ dcaChunks?: number;
116
+ /** DCA chunk interval in blocks. Required if `dcaChunks > 1`. */
117
+ dcaChunkInterval?: number;
118
+ /** Max boost fee in basis points (default: 0, no boost). */
119
+ maxBoostFeeBps?: number;
120
+ };
121
+ }
122
+ /**
123
+ * Extension of the base `SwidgeOptions` with a source-chain field. Kept
124
+ * separate from the module's `SwidgeOptions` re-export so consumers using
125
+ * the base type keep working; consumers that need multi-chain source
126
+ * routing import this instead.
127
+ */
128
+ export interface SwapDKSwidgeOptions {
129
+ /**
130
+ * Source token identifier. For native gas coins, the upper-case ticker
131
+ * (`"ETH"`, `"BTC"`, `"TRX"`). For fungibles, the contract address in
132
+ * its chain-native format (EIP-55 hex for EVM, base58 for TRON /
133
+ * Solana). Matches the `token` field returned by `getSupportedTokens`.
134
+ */
135
+ fromToken: string;
136
+ /**
137
+ * Source chain identifier (matches `SwidgeSupportedChain.id`). Required
138
+ * for multi-family source support unless `SwapDKSwidgeConfig.defaultFromChain`
139
+ * is set on the instance. Accepts numeric chain-ids for parity with
140
+ * the base `SwidgeOptions` shape; internally normalized to string.
141
+ */
142
+ fromChain?: string | number;
143
+ /** Destination token identifier — same conventions as `fromToken`. */
144
+ toToken: string;
145
+ /**
146
+ * Destination chain identifier. Omit for same-chain swaps. Accepts
147
+ * numeric chain-ids for parity with the base `SwidgeOptions` shape.
148
+ */
149
+ toChain?: string | number;
150
+ /** Address receiving the destination tokens. */
151
+ recipient?: string;
152
+ /** Address receiving refunds if the route cannot complete. */
153
+ refundAddress?: string;
154
+ /** Slippage tolerance as a decimal (0.01 = 1%). Mutually exclusive with `minAmountOut`. */
155
+ slippage?: number;
156
+ /** Explicit minimum destination amount (base units). Overrides `slippage`. */
157
+ minAmountOut?: bigint | number;
158
+ /** Exact amount to spend (base units of the source token). Mutually exclusive with `toTokenAmount`. */
159
+ fromTokenAmount?: bigint | number;
160
+ /** Exact amount to receive (base units of the destination token). Mutually exclusive with `fromTokenAmount`. */
161
+ toTokenAmount?: bigint | number;
162
+ }
163
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE3E;;;;;;;;;;GAUG;AACH,MAAM,WAAW,mBAAmB;IAClC,UAAU,IAAI,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACvC,eAAe,CAAC,EAAE,EAAE,OAAO,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;QACxD,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B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G;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;IACtB,sEAAsE;IACtE,SAAS,CAAC,EAAE;QACV,yDAAyD;QACzD,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,iEAAiE;QACjE,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,iDAAiD;QACjD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,iEAAiE;QACjE,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,4DAA4D;QAC5D,cAAc,CAAC,EAAE,MAAM,CAAC;KACzB,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2FAA2F;IAC3F,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,8EAA8E;IAC9E,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,uGAAuG;IACvG,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,gHAAgH;IAChH,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ // ---------------------------------------------------------------------------
2
+ // SwapDKSwidge public types.
3
+ //
4
+ // The base `SwidgeOptions` in @tetherto/wdk-wallet/protocols does not carry a
5
+ // `fromChain` field (only `toChain`), and its `fromToken` is expected to be
6
+ // unambiguous on its own. For SwapDK's multi-family source support (BTC / EVM
7
+ // / Cosmos / Solana / TRON) a plain "USDC" identifier can't disambiguate
8
+ // between ethereum-USDC and arbitrum-USDC, so we extend the base with an
9
+ // explicit `fromChain` — same pattern Orchestra's module uses.
10
+ // ---------------------------------------------------------------------------
11
+ export {};
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,6BAA6B;AAC7B,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,8EAA8E;AAC9E,yEAAyE;AACzE,yEAAyE;AACzE,+DAA+D;AAC/D,8EAA8E"}
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@swapdk/wdk-protocol-swidge-swapdk",
3
+ "version": "1.0.0-alpha.0",
4
+ "description": "WDK swidge protocol module for arbitrary-asset cross-chain swaps and bridges via the SwapDK swap-engine (THORChain, MAYAChain, Chainflip). Single class covering Bitcoin, EVM, Cosmos-family, Solana, and TRON source chains.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "clean": "rm -rf dist tsconfig.tsbuildinfo",
19
+ "build": "tsc -b",
20
+ "prepack": "npm run clean && npm run build",
21
+ "dev": "tsc -b --watch",
22
+ "lint": "tsc -b --dry"
23
+ },
24
+ "keywords": [
25
+ "wdk",
26
+ "tether",
27
+ "swapdk",
28
+ "swidge",
29
+ "cross-chain",
30
+ "bridge",
31
+ "swap",
32
+ "thorchain",
33
+ "mayachain",
34
+ "chainflip"
35
+ ],
36
+ "license": "MIT",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Swap-DK/wdk-protocol-bridges-swapdk.git",
40
+ "directory": "packages/swidge"
41
+ },
42
+ "author": "SwapDK",
43
+ "bugs": {
44
+ "url": "https://github.com/Swap-DK/wdk-protocol-bridges-swapdk/issues"
45
+ },
46
+ "homepage": "https://swapdk.com",
47
+ "engines": {
48
+ "node": ">=18"
49
+ },
50
+ "dependencies": {
51
+ "@solana-program/memo": "^0.11.0",
52
+ "@solana-program/system": "^0.12.0",
53
+ "@solana/addresses": "^6.8.0",
54
+ "@solana/signers": "^6.8.0",
55
+ "@solana/transaction-messages": "^6.8.0",
56
+ "@swapdk/swap-engine-client": "^0.3.0"
57
+ },
58
+ "peerDependencies": {
59
+ "@tetherto/wdk-wallet": "1.0.0-beta.11"
60
+ },
61
+ "devDependencies": {
62
+ "@tetherto/wdk-wallet": "1.0.0-beta.11"
63
+ }
64
+ }