@anywalletkit/protocol-swap2-layerswap 0.0.0-stage → 0.1.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.
Files changed (58) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +97 -2
  3. package/dist/activity.cjs +122 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +15 -0
  6. package/dist/activity.d.ts +15 -0
  7. package/dist/activity.js +10 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/chunk-5QTIHCE4.js +99 -0
  10. package/dist/chunk-5QTIHCE4.js.map +1 -0
  11. package/dist/chunk-KCAZCR4I.js +27 -0
  12. package/dist/chunk-KCAZCR4I.js.map +1 -0
  13. package/dist/chunk-TEL62A5J.js +564 -0
  14. package/dist/chunk-TEL62A5J.js.map +1 -0
  15. package/dist/chunk-WEMNS3LY.js +21 -0
  16. package/dist/chunk-WEMNS3LY.js.map +1 -0
  17. package/dist/chunk-ZKT24QPJ.js +123 -0
  18. package/dist/chunk-ZKT24QPJ.js.map +1 -0
  19. package/dist/chunk-ZTFJO6AI.js +410 -0
  20. package/dist/chunk-ZTFJO6AI.js.map +1 -0
  21. package/dist/config.cjs +143 -0
  22. package/dist/config.cjs.map +1 -0
  23. package/dist/config.d.cts +74 -0
  24. package/dist/config.d.ts +74 -0
  25. package/dist/config.js +31 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/index.cjs +1189 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +84 -0
  30. package/dist/index.d.ts +84 -0
  31. package/dist/index.js +126 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/pins.cjs +557 -0
  34. package/dist/pins.cjs.map +1 -0
  35. package/dist/pins.d.cts +6 -0
  36. package/dist/pins.d.ts +6 -0
  37. package/dist/pins.js +11 -0
  38. package/dist/pins.js.map +1 -0
  39. package/dist/protocol.cjs +1052 -0
  40. package/dist/protocol.cjs.map +1 -0
  41. package/dist/protocol.d.cts +19 -0
  42. package/dist/protocol.d.ts +19 -0
  43. package/dist/protocol.js +11 -0
  44. package/dist/protocol.js.map +1 -0
  45. package/dist/provider.cjs +1039 -0
  46. package/dist/provider.cjs.map +1 -0
  47. package/dist/provider.d.cts +23 -0
  48. package/dist/provider.d.ts +23 -0
  49. package/dist/provider.js +16 -0
  50. package/dist/provider.js.map +1 -0
  51. package/dist/verify.cjs +554 -0
  52. package/dist/verify.cjs.map +1 -0
  53. package/dist/verify.d.cts +169 -0
  54. package/dist/verify.d.ts +169 -0
  55. package/dist/verify.js +46 -0
  56. package/dist/verify.js.map +1 -0
  57. package/module.json +64 -0
  58. package/package.json +100 -3
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,98 @@
1
- # Temporary Holding Version
1
+ # @anywalletkit/protocol-swap2-layerswap
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Layerswap](https://layerswap.io) for the swap2 engine: cross-chain transfers from EVM, Solana, TON, Tron and Bitcoin to any chain Layerswap serves, talking to Layerswap's v2 API, with **every swap read back and every deposit checked on the device before it is signed**.
4
+
5
+ Layerswap is a solver bridge. One source transaction funds a swap Layerswap keeps under an id; Layerswap then pays the recipient on the destination chain from its own liquidity (or chains CCTP, a native rollup bridge or a DEX hop behind it), or refunds the source address. The deposit names the swap and nothing else — not the recipient, not the destination, not the minimum. Those live in Layerswap's record of the swap. This module holds that record to the request field by field when the swap is created, again before the build and again right before the signature, and rebuilds or reads the deposit itself.
6
+
7
+ - Exact input; same token or another (Layerswap prices the route; swaps through a DEX hop carry Layerswap's slippage, which this module sets from yours).
8
+ - Sources: 45 EVM chains with the Layerswap Depository, Solana, TON, Tron, Bitcoin. Destinations: every chain on Layerswap's list this module names (EVM by chain id, plus Solana, TON, Tron, Bitcoin).
9
+ - No provider SDK: `viem` for the Depository ABI, `@noble/curves` + `@noble/hashes` to derive Solana token accounts.
10
+ - Read endpoints need no key. `apiKey` (Partner Dashboard → app → key) attributes swaps to your app; `baseUrl` can point at your own proxy that adds it.
11
+
12
+ ```ts
13
+ import {layerswapProvider} from "@anywalletkit/protocol-swap2-layerswap";
14
+ import {CrossChainRouter} from "@anywalletkit/protocol-swap2-router";
15
+
16
+ const layerswap = layerswapProvider({baseUrl: "https://your-backend.example/layerswap"}); // or nothing: https://api.layerswap.io/api/v2
17
+ const router = new CrossChainRouter([layerswap /*, …other providers */]);
18
+ ```
19
+
20
+ Standalone: `new LayerswapSwap2Protocol(account, {fromChain: "ton:-239"})`.
21
+
22
+ | option | |
23
+ |---|---|
24
+ | `baseUrl` | Layerswap's API (default) or your proxy in front of it. |
25
+ | `apiKey` | Sent as `X-LS-APIKEY`; the key picks mainnet or testnet. Prefer a proxy: a key shipped in an app is public. |
26
+ | `fetchImpl` | Your own `fetch`. |
27
+ | `enabled` | Default `true`. |
28
+
29
+ ## How each source pays
30
+
31
+ | source | funding | what the account signs |
32
+ |---|---|---|
33
+ | EVM (45 chains) | Layerswap Depository (`use_depository`) | an exact approval of the input to the Depository (ERC-20), then `depositNative(id, receiver)` / `depositERC20(id, token, receiver, amount)` |
34
+ | Solana | wallet transfer | Layerswap's prepared legacy message: one transfer of the input with the swap's memo (sent unsigned; handed to the wallet behind one empty signature slot, the message bytes unchanged) |
35
+ | TON | wallet transfer | a TON transfer or a jetton transfer to Layerswap's address with the swap's comment |
36
+ | Tron | wallet transfer | a TRX / TRC-20 transfer to Layerswap's address with the memo in `raw_data.data` |
37
+ | Bitcoin | deposit address (`use_deposit_address`) | a send of the input to the address minted for the swap |
38
+
39
+ Why these: on Solana and Tron Layerswap's deposit-address flow costs a sweep (≈ $0.36 on 100 USDC from Solana, ≈ $4 from Tron, 2026-12-01), so the memo'd wallet transfer is used; TON has only the wallet transfer; on Bitcoin the wallet transfer needs an `OP_RETURN` output the Bitcoin account does not write, and the deposit address costs ≈ 0.03 %.
40
+
41
+ ## What is checked
42
+
43
+ A refusal reads `layerswap: <what was found>` and reaches `onRefusal` with a `Swap2RefusalReason` (`recipient_mismatch`, `vault_mismatch`, `policy_refused`, `quote_expired`, …); the thrown `LayerswapRefusal` also names its `check`.
44
+
45
+ **The swap is the one asked for** (`checkSwapRecord`; at creation, before the build, before the signature)
46
+
47
+ - source and destination networks, source and destination tokens (by contract, in each chain's spelling: EVM case, TON bounceable or not);
48
+ - the recipient; the amount (a JSON double, held within 1e-9 — the exact one is on the deposit);
49
+ - the source and refund addresses are sent as the sending account (a request naming another refund address is refused before anything is created). Layerswap's record echoes neither (2026-12-01); a record that does name a source address must name this account. The deposit is the account's own transfer or its own signature either way;
50
+ - no integrator fee split (`integrator_fee_splits` empty, on the record and on the quote);
51
+ - the funding method; a well-formed id and sequence number; status still `user_transfer_pending` at build and signature.
52
+
53
+ **The quote** — Layerswap prices again when the swap is created; that quote is the one reviewed. An integrator fee or a gas top-up (`refuel`) this module did not ask for is refused. Amounts come back as JSON numbers and are read down to base units; amounts go out as exact decimal literals, and an input with more than 15 significant digits (what a double keeps) is refused before any request — round it.
54
+
55
+ **The deposit, per family** (`verify.ts`)
56
+
57
+ - one action required; Layerswap's own approval step is never used, a signing step (gasless, Permit2) never taken;
58
+ - the action's network and token are the swap's input;
59
+ - **EVM:** the target is the pinned Depository; the call is rebuilt here from the swap's sequence number, the input token and amount and a **pinned** receiver, and must equal Layerswap's byte for byte; native value only for a native input; the approval spender is the Depository, for exactly the input;
60
+ - **Solana:** a legacy message signed by this account alone, sent with no signature slot or one empty one; only the system, token, associated-token, compute-budget and memo programs; at most one compute-unit limit (≤ 400 000) and one price (≤ 5 000 000 micro-lamports, so ≤ 0.002 SOL in priority fees); exactly one top-level memo whose bytes are the swap's sequence number; exactly one transfer of exactly the input — SOL to the deposit address, or SPL from this account's associated token account to the deposit address's (both derived here) — and at most one account creation (`CreateIdempotent`, optionally listing the rent sysvar), of this account's own token account or the deposit address's, under the transfer's own token program; the wallet then simulates it and holds balances to the input;
61
+ - **TON:** the comment is the swap's sequence number (on Layerswap's shared address it is what credits the deposit to this swap; seen on a live swap 2026-12-01); the jetton amount in the payload (the action's own amount reads `0` for a jetton) or the TON value is exactly the input;
62
+ - **Tron:** a Tron address, the memo the swap's sequence number, exactly the input;
63
+ - **Bitcoin:** a `manual_transfer` to a mainnet address, no memo output, exactly the input.
64
+
65
+ The whole deposit check runs again right before the signature, against the swap as Layerswap holds it then (`GET /swaps/{id}` for the record, `GET /swaps/{id}/deposit_actions?source_address=` for the deposit — the record alone lists a Solana deposit as a manual transfer without its transaction), and the transaction about to be signed must be that deposit. One deposit per swap from a provider instance. The Depository call goes out with the account's own gas estimate of exactly that call (`ownGasEstimate`).
66
+
67
+ ## What was seen live
68
+
69
+ On 2026-12-01 two unfunded swaps were created from burner addresses with no key (Solana USDC → Base USDC, TON USDT → Arbitrum USDT0); the answers are in `fixtures/api/real-2026-12-01.json` and replayed through the engine in `tests/real-api.test.ts`. Requests name networks by Layerswap's `name`, as those creates did.
70
+
71
+ The same day three funded runs went through this module and the SDK wallets, keyless, and all completed on Arbitrum within about 15 seconds of the deposit: 0.10 USDC from Base through the Depository, 0.10 USDC from Solana, 0.20 USDT from TON. Their answers are in `fixtures/api/real-funded-2026-12-01.json`, replayed in `tests/real-funded.test.ts`; the wallet's addresses, the swap ids and sequence numbers, the times and the Solana blockhashes there are stand-ins (consistent within each run), and the on-chain hashes are left out. What they showed:
72
+
73
+ - The EVM deposit is one `transfer` action to the Depository with `amount_in_base_units: "0"` (the value of an ERC-20 deposit) and `depositERC20(sequence_number, token, receiver, amount)` in `call_data`, plus `gas_limit` and `encoded_args`. The call rebuilt here was byte for byte Layerswap's. No approval action comes with it: the engine sends the exact approval.
74
+ - Every `deposit_actions` read answers the Solana message with a fresh blockhash; the quoted message is the one signed and the read-backs are held to it.
75
+ - `GET /networks` was 2.66 MB (hundreds of tokens on each big EVM chain), so it alone may be up to 8 MB; every other answer is held to 1 MB. It is cached for 15 minutes.
76
+ - A Solana account takes the engine's transaction through `sendSerialized` (map `sendSerializedTransaction: (tx, expect) => account.sendSerialized(tx, serializedGuardFromExecution(expect))`); its guard passed Layerswap's message with the bridge expectation.
77
+
78
+ Still read from the docs only: Tron's memo and Bitcoin's deposit address.
79
+
80
+ ## What no check here can see
81
+
82
+ Where Layerswap pays out is its own record. The read-back holds that record to the request, so a swap created for another recipient is refused — but an API (or a proxy) that answers one record and pays from another is trusted, as with every deposit-address venue. The Depository only proves the input reaches a solver address Layerswap's owner whitelisted (an account, not a Safe, on 2026-12-01) and that this module pinned.
83
+
84
+ Funds are in Layerswap's hands between the deposit and the payout. If Layerswap cannot fill the swap it refunds the source address in the source token, minus the refund's network fee (`pending_refund` → `refunded`); a deposit it never matches stays with Layerswap until its support resolves it — keep the swap id (`layerswap:<uuid>`) and the source hash.
85
+
86
+ ## Pins (read 2026-12-01)
87
+
88
+ - Depository `0xE226E4825CB215aBaFAd98fdd400583eAb6a594f`, the same address and runtime code on 45 EVM chains (`LAYERSWAP_DEPOSITORY_CHAINS`), owner `0xB6103502673173ab5Df6A57Ac3017Db4e16af399`, not paused. Hexens audit (March 2026). A second deployment at `0x8f00…B038` is not Layerswap's live one and is never a target.
89
+ - Receivers `0x2fc617e933a52713247ce25730f6695920b3befe`, `0x08b00ceee2fb66029b53d76110b19eeaabfd1e65` (`getWhitelistedAddresses()` on every chain).
90
+ - `watch.json` follows the network list, the OpenAPI document, the contract source, the code and whitelist on six chains, and the funding guides.
91
+
92
+ ## Status
93
+
94
+ `trackIntent` reads `GET /swaps/{id}`: `user_transfer_pending` → pending (the source hash is handed to `deposit_speedup` again while unmatched), `ls_transfer_pending` → pending with the deposit received, `completed` (with the payout hash), `pending_refund` → refund-pending, `refunded`, `failed`, `expired`.
95
+
96
+ ## Remote use
97
+
98
+ `layerswapPins` for `remoteProvider`: EVM builds may call and approve only the Depository; Solana / TON / Tron / Bitcoin legs pay an address Layerswap names per swap, so the stub is opened to deposit-address routes. Its `verifyQuote` re-runs the deposit checks on the device against the app's own request (the Depository call rebuilt, the Solana transaction read, the memo held to the swap's sequence number); which swap the deposit names, and Layerswap's record of it, remain the backend's word.
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/activity.ts
21
+ var activity_exports = {};
22
+ __export(activity_exports, {
23
+ LAYERSWAP_MODULE: () => LAYERSWAP_MODULE,
24
+ describeLayerswapActivity: () => describeLayerswapActivity
25
+ });
26
+ module.exports = __toCommonJS(activity_exports);
27
+ var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
28
+
29
+ // src/config.ts
30
+ var import_util = require("@anywalletkit/protocol-swap2-core/util");
31
+ var LAYERSWAP_DEPOSITORY = "0xe226e4825cb215abafad98fdd400583eab6a594f";
32
+ var LAYERSWAP_RECEIVERS = Object.freeze([
33
+ "0x2fc617e933a52713247ce25730f6695920b3befe",
34
+ "0x08b00ceee2fb66029b53d76110b19eeaabfd1e65"
35
+ ]);
36
+ var DEPOSIT_NATIVE_SELECTOR = "0x80a6de92";
37
+ var DEPOSIT_ERC20_SELECTOR = "0xf4371f63";
38
+ var LAYERSWAP_DEPOSITORY_CHAINS = Object.freeze([
39
+ 1,
40
+ 10,
41
+ 56,
42
+ 100,
43
+ 130,
44
+ 137,
45
+ 143,
46
+ 146,
47
+ 169,
48
+ 196,
49
+ 204,
50
+ 252,
51
+ 324,
52
+ 360,
53
+ 480,
54
+ 988,
55
+ 999,
56
+ 1329,
57
+ 1868,
58
+ 2020,
59
+ 2741,
60
+ 2818,
61
+ 4217,
62
+ 4326,
63
+ 4663,
64
+ 5e3,
65
+ 5042,
66
+ 8217,
67
+ 8453,
68
+ 9745,
69
+ 13371,
70
+ 42161,
71
+ 42220,
72
+ 42793,
73
+ 43114,
74
+ 48900,
75
+ 57073,
76
+ 59144,
77
+ 60808,
78
+ 80094,
79
+ 99901,
80
+ 167e3,
81
+ 534352,
82
+ 747474,
83
+ 7777777
84
+ ]);
85
+ var LAYERSWAP_EVM_CHAINS = Object.freeze([
86
+ ...LAYERSWAP_DEPOSITORY_CHAINS,
87
+ 14,
88
+ 25,
89
+ 30,
90
+ 40,
91
+ 122,
92
+ 747,
93
+ 4114,
94
+ 16661,
95
+ 34443
96
+ ].sort((a, b) => a - b));
97
+ var LAYERSWAP_NON_EVM = Object.freeze({
98
+ "solana:mainnet": "SOLANA_MAINNET",
99
+ "ton:-239": "TON_MAINNET",
100
+ "tron:728126428": "TRON_MAINNET",
101
+ "bitcoin:mainnet": "BITCOIN_MAINNET"
102
+ });
103
+ function fundingFor(sourceChain) {
104
+ const ns = (0, import_util.namespace)(sourceChain);
105
+ if (ns === "eip155") return LAYERSWAP_DEPOSITORY_CHAINS.includes(evmChainId(sourceChain) ?? -1) ? "depository" : null;
106
+ if (ns === "solana" || ns === "ton" || ns === "tron") return sourceChain in LAYERSWAP_NON_EVM ? "wallet" : null;
107
+ if (ns === "bitcoin") return sourceChain in LAYERSWAP_NON_EVM ? "deposit_address" : null;
108
+ return null;
109
+ }
110
+ function evmChainId(caip2) {
111
+ const m = /^eip155:([1-9]\d{0,9})$/.exec(caip2);
112
+ return m ? Number(m[1]) : null;
113
+ }
114
+
115
+ // src/activity.ts
116
+ var LAYERSWAP_MODULE = "@anywalletkit/protocol-swap2-layerswap";
117
+ function describeLayerswapActivity(tx, ctx) {
118
+ if (fundingFor(tx.chain) !== "depository") return null;
119
+ if (!(0, import_activity.matchesCall)(tx, [LAYERSWAP_DEPOSITORY], [DEPOSIT_NATIVE_SELECTOR, DEPOSIT_ERC20_SELECTOR])) return null;
120
+ return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: LAYERSWAP_MODULE, subtitle: `Layerswap \xB7 ${(0, import_activity.chainLabel)(tx.chain)}`, kind: "bridge", outVerb: "Bridged" });
121
+ }
122
+ //# sourceMappingURL=activity.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/activity.ts","../src/config.ts"],"sourcesContent":["/**\n * Activity recognition for Layerswap on every EVM chain with the pinned Depository: `depositNative` /\n * `depositERC20` on it is our source leg (\"Bridged USDC\").\n *\n * The other legs are not claimed. A Solana / TON / Tron / Bitcoin deposit is a plain transfer to an address Layerswap\n * names per swap, and the payout is an ordinary transfer from a Layerswap solver account: nothing on chain a stranger\n * could not imitate. The swap id the engine journals ties them back to the swap.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {DEPOSIT_ERC20_SELECTOR, DEPOSIT_NATIVE_SELECTOR, LAYERSWAP_DEPOSITORY, fundingFor} from \"./config.js\";\n\nexport const LAYERSWAP_MODULE = \"@anywalletkit/protocol-swap2-layerswap\";\n\nexport function describeLayerswapActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (fundingFor(tx.chain) !== \"depository\") return null;\n if (!matchesCall(tx, [LAYERSWAP_DEPOSITORY], [DEPOSIT_NATIVE_SELECTOR, DEPOSIT_ERC20_SELECTOR])) return null;\n return describeSwapLike(tx, ctx, {protocol: LAYERSWAP_MODULE, subtitle: `Layerswap · ${chainLabel(tx.chain)}`, kind: \"bridge\", outVerb: \"Bridged\"});\n}\n","import {namespace} from \"@anywalletkit/protocol-swap2-core/util\";\n\n/**\n * Layerswap (layerswap.io) — what this module pins and which chains it serves.\n *\n * Layerswap is a solver bridge: the source leg pays Layerswap on the source chain, and Layerswap pays the recipient\n * out of its own liquidity on the destination chain (or chains CCTP / a native rollup bridge / a DEX hop behind it).\n * The recipient, the destination and the minimum live in Layerswap's records under the swap id, not on chain: the\n * module reads the swap back and holds every field to the request before anything is signed (see `verify.ts`).\n */\n\n/** Layerswap's v2 API. One base URL for mainnet and testnet: the API key picks the environment. */\nexport const LAYERSWAP_API = \"https://api.layerswap.io/api/v2\";\n\n/**\n * LayerswapDepository (github.com/layerswap/layerswap-depository, `evm/src/LayerswapDepository.sol`; audited by\n * Hexens, March 2026). It holds nothing: `depositNative(id, receiver)` / `depositERC20(id, token, receiver, amount)`\n * forward the input in the same call to a receiver on the contract's own whitelist and emit\n * `Deposited(id, token, receiver, amount)`, `id` being the swap's sequence number. Deployed at one address; read on\n * 2026-12-01 on every EVM chain Layerswap lists (public RPCs from its `/networks`): runtime code keccak\n * `0xe2c5b091…` on each chain below, owner `0xB6103502673173ab5Df6A57Ac3017Db4e16af399`, not paused, whitelist\n * exactly {@link LAYERSWAP_RECEIVERS}. A second contract of the same code at `0x8f00775A…B038` (Ethereum, Mantle)\n * whitelists its own owner only and is not Layerswap's live one: it is never a target here.\n */\nexport const LAYERSWAP_DEPOSITORY = \"0xe226e4825cb215abafad98fdd400583eab6a594f\";\n\n/**\n * The solver addresses the Depository forwards to (`getWhitelistedAddresses()`, the same two on every chain on\n * 2026-12-01; 0x2fc6…befe is the address Layerswap has paid out of since 2022). A deposit naming any other receiver\n * is refused even if Layerswap's owner key whitelists it later: a new receiver ships in a module release, after it\n * is read on chain. Both are plain accounts (no code).\n */\nexport const LAYERSWAP_RECEIVERS: readonly string[] = Object.freeze([\n \"0x2fc617e933a52713247ce25730f6695920b3befe\",\n \"0x08b00ceee2fb66029b53d76110b19eeaabfd1e65\",\n]);\n\n/** `depositNative(bytes32,address)` and `depositERC20(bytes32,address,address,uint256)`. */\nexport const DEPOSIT_NATIVE_SELECTOR = \"0x80a6de92\";\nexport const DEPOSIT_ERC20_SELECTOR = \"0xf4371f63\";\n\n/**\n * EVM chains a deposit can leave from: the Depository at {@link LAYERSWAP_DEPOSITORY} with the pinned code, owner and\n * whitelist (read 2026-12-01). Layerswap also lists Flare, Cronos, Rootstock, Telos, Fuse, Flow, Citrea and 0G (no\n * Depository there) and Mode (its Depository did not answer the reads): those are destinations only.\n */\nexport const LAYERSWAP_DEPOSITORY_CHAINS: readonly number[] = Object.freeze([\n 1, 10, 56, 100, 130, 137, 143, 146, 169, 196, 204, 252, 324, 360, 480, 988, 999, 1329, 1868, 2020, 2741, 2818, 4217,\n 4326, 4663, 5000, 5042, 8217, 8453, 9745, 13371, 42161, 42220, 42793, 43114, 48900, 57073, 59144, 60808, 80094, 99901,\n 167000, 534352, 747474, 7777777,\n]);\n\n/** Every EVM chain Layerswap listed on 2026-12-01 (`GET /networks`, type `evm`), as a destination. */\nexport const LAYERSWAP_EVM_CHAINS: readonly number[] = Object.freeze([\n ...LAYERSWAP_DEPOSITORY_CHAINS, 14, 25, 30, 40, 122, 747, 4114, 16661, 34443,\n].sort((a, b) => a - b));\n\n/** The non-EVM chains this module serves, by our CAIP-2 id → Layerswap's network name. */\nexport const LAYERSWAP_NON_EVM: Readonly<Record<string, string>> = Object.freeze({\n \"solana:mainnet\": \"SOLANA_MAINNET\",\n \"ton:-239\": \"TON_MAINNET\",\n \"tron:728126428\": \"TRON_MAINNET\",\n \"bitcoin:mainnet\": \"BITCOIN_MAINNET\",\n});\n\n/**\n * How the source leg is funded, per source family:\n * - EVM: the Depository (`use_depository`), pinned above.\n * - Solana: the wallet flow — Layerswap's serialized transfer with the swap's sequence number as a top-level memo.\n * The deposit-address flow costs a sweep (≈ $0.36 on 100 USDC, 2026-12-01).\n * - TON: the wallet flow — a transfer (or jetton transfer) with the swap's comment. TON has no deposit address.\n * - Tron: the wallet flow — a TRC-20 transfer with the memo in `raw_data.data`. The deposit-address flow costs\n * ≈ $4 a swap (2026-12-01).\n * - Bitcoin: a deposit address minted for the swap (`use_deposit_address`): the wallet flow needs an OP_RETURN\n * output the Bitcoin account does not write; the address costs ≈ 0.03 % (2026-12-01).\n */\nexport type LayerswapFunding = \"depository\" | \"wallet\" | \"deposit_address\";\n\nexport function fundingFor(sourceChain: string): LayerswapFunding | null {\n const ns = namespace(sourceChain);\n if (ns === \"eip155\") return LAYERSWAP_DEPOSITORY_CHAINS.includes(evmChainId(sourceChain) ?? -1) ? \"depository\" : null;\n if (ns === \"solana\" || ns === \"ton\" || ns === \"tron\") return sourceChain in LAYERSWAP_NON_EVM ? \"wallet\" : null;\n if (ns === \"bitcoin\") return sourceChain in LAYERSWAP_NON_EVM ? \"deposit_address\" : null;\n return null;\n}\n\n/** `eip155:<id>` → id, else null. */\nexport function evmChainId(caip2: string): number | null {\n const m = /^eip155:([1-9]\\d{0,9})$/.exec(caip2);\n return m ? Number(m[1]) : null;\n}\n\n/**\n * Whether this module names the chain, and how: the numeric chain id for EVM (matched against `chain_id` in\n * Layerswap's network list), the network name otherwise; null for a chain this module does not serve. Requests carry\n * the `name` from Layerswap's list for either.\n */\nexport function layerswapNetwork(caip2: string): string | null {\n const id = evmChainId(caip2);\n if (id !== null) return LAYERSWAP_EVM_CHAINS.includes(id) ? String(id) : null;\n return Object.prototype.hasOwnProperty.call(LAYERSWAP_NON_EVM, caip2) ? LAYERSWAP_NON_EVM[caip2]! : null;\n}\n\n/** Layerswap's network name for a chain as its responses name it (EVM by chain id). */\nexport function sameNetwork(caip2: string, network: {name?: unknown; chain_id?: unknown} | null | undefined): boolean {\n if (!network) return false;\n const id = evmChainId(caip2);\n if (id !== null) return String(network.chain_id ?? \"\") === String(id);\n return network.name === LAYERSWAP_NON_EVM[caip2];\n}\n\nexport const layerswap = {\n supportsChain(chain: string): boolean {\n return layerswapNetwork(chain) !== null;\n },\n /** A route this module can try: a source with a funding method, any served destination, never the same chain. */\n supports(from: string, to: string): boolean {\n return from !== to && fundingFor(from) !== null && layerswapNetwork(to) !== null;\n },\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,sBAAwD;;;ACTxD,kBAAwB;AAwBjB,IAAM,uBAAuB;AAQ7B,IAAM,sBAAyC,OAAO,OAAO;AAAA,EAClE;AAAA,EACA;AACF,CAAC;AAGM,IAAM,0BAA0B;AAChC,IAAM,yBAAyB;AAO/B,IAAM,8BAAiD,OAAO,OAAO;AAAA,EAC1E;AAAA,EAAG;AAAA,EAAI;AAAA,EAAI;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAK;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAC/G;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAM;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAAO;AAAA,EAChH;AAAA,EAAQ;AAAA,EAAQ;AAAA,EAAQ;AAC1B,CAAC;AAGM,IAAM,uBAA0C,OAAO,OAAO;AAAA,EACnE,GAAG;AAAA,EAA6B;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAI;AAAA,EAAK;AAAA,EAAK;AAAA,EAAM;AAAA,EAAO;AACzE,EAAE,KAAK,CAAC,GAAG,MAAM,IAAI,CAAC,CAAC;AAGhB,IAAM,oBAAsD,OAAO,OAAO;AAAA,EAC/E,kBAAkB;AAAA,EAClB,YAAY;AAAA,EACZ,kBAAkB;AAAA,EAClB,mBAAmB;AACrB,CAAC;AAeM,SAAS,WAAW,aAA8C;AACvE,QAAM,SAAK,uBAAU,WAAW;AAChC,MAAI,OAAO,SAAU,QAAO,4BAA4B,SAAS,WAAW,WAAW,KAAK,EAAE,IAAI,eAAe;AACjH,MAAI,OAAO,YAAY,OAAO,SAAS,OAAO,OAAQ,QAAO,eAAe,oBAAoB,WAAW;AAC3G,MAAI,OAAO,UAAW,QAAO,eAAe,oBAAoB,oBAAoB;AACpF,SAAO;AACT;AAGO,SAAS,WAAW,OAA8B;AACvD,QAAM,IAAI,0BAA0B,KAAK,KAAK;AAC9C,SAAO,IAAI,OAAO,EAAE,CAAC,CAAC,IAAI;AAC5B;;;AD9EO,IAAM,mBAAmB;AAEzB,SAAS,0BAA0B,IAAa,KAAmD;AACxG,MAAI,WAAW,GAAG,KAAK,MAAM,aAAc,QAAO;AAClD,MAAI,KAAC,6BAAY,IAAI,CAAC,oBAAoB,GAAG,CAAC,yBAAyB,sBAAsB,CAAC,EAAG,QAAO;AACxG,aAAO,kCAAiB,IAAI,KAAK,EAAC,UAAU,kBAAkB,UAAU,sBAAe,4BAAW,GAAG,KAAK,CAAC,IAAI,MAAM,UAAU,SAAS,UAAS,CAAC;AACpJ;","names":[]}
@@ -0,0 +1,15 @@
1
+ import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity recognition for Layerswap on every EVM chain with the pinned Depository: `depositNative` /
5
+ * `depositERC20` on it is our source leg ("Bridged USDC").
6
+ *
7
+ * The other legs are not claimed. A Solana / TON / Tron / Bitcoin deposit is a plain transfer to an address Layerswap
8
+ * names per swap, and the payout is an ordinary transfer from a Layerswap solver account: nothing on chain a stranger
9
+ * could not imitate. The swap id the engine journals ties them back to the swap.
10
+ */
11
+
12
+ declare const LAYERSWAP_MODULE = "@anywalletkit/protocol-swap2-layerswap";
13
+ declare function describeLayerswapActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
14
+
15
+ export { LAYERSWAP_MODULE, describeLayerswapActivity };
@@ -0,0 +1,15 @@
1
+ import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity recognition for Layerswap on every EVM chain with the pinned Depository: `depositNative` /
5
+ * `depositERC20` on it is our source leg ("Bridged USDC").
6
+ *
7
+ * The other legs are not claimed. A Solana / TON / Tron / Bitcoin deposit is a plain transfer to an address Layerswap
8
+ * names per swap, and the payout is an ordinary transfer from a Layerswap solver account: nothing on chain a stranger
9
+ * could not imitate. The swap id the engine journals ties them back to the swap.
10
+ */
11
+
12
+ declare const LAYERSWAP_MODULE = "@anywalletkit/protocol-swap2-layerswap";
13
+ declare function describeLayerswapActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
14
+
15
+ export { LAYERSWAP_MODULE, describeLayerswapActivity };
@@ -0,0 +1,10 @@
1
+ import {
2
+ LAYERSWAP_MODULE,
3
+ describeLayerswapActivity
4
+ } from "./chunk-WEMNS3LY.js";
5
+ import "./chunk-ZKT24QPJ.js";
6
+ export {
7
+ LAYERSWAP_MODULE,
8
+ describeLayerswapActivity
9
+ };
10
+ //# sourceMappingURL=activity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,99 @@
1
+ import {
2
+ checkBitcoinDeposit,
3
+ checkEvmDeposit,
4
+ checkSolanaDeposit,
5
+ checkTonDeposit,
6
+ checkTronDeposit
7
+ } from "./chunk-TEL62A5J.js";
8
+ import {
9
+ LAYERSWAP_DEPOSITORY,
10
+ fundingFor
11
+ } from "./chunk-ZKT24QPJ.js";
12
+
13
+ // src/pins.ts
14
+ import { resolveAsset } from "@anywalletkit/swap2-assets";
15
+ import { sourceAssetOf } from "@anywalletkit/protocol-swap2-core/util";
16
+ import { refusalOf } from "@anywalletkit/protocol-swap2-core/errors";
17
+ var reasons = /* @__PURE__ */ new Map();
18
+ function noted(e) {
19
+ const text = e instanceof Error ? e.message : String(e);
20
+ const info = refusalOf(e);
21
+ if (info) {
22
+ reasons.delete(text);
23
+ reasons.set(text, info);
24
+ if (reasons.size > 256) reasons.delete(reasons.keys().next().value);
25
+ }
26
+ return text;
27
+ }
28
+ function layerswapVerifyQuote(params, quote) {
29
+ try {
30
+ const funding = fundingFor(params.sourceChain);
31
+ if (!funding) return "layerswap: the source chain has no funding method";
32
+ const source = sourceAssetOf(params);
33
+ if (!source) return `layerswap: unknown source token ${params.sourceToken}`;
34
+ const dest = resolveAsset(params.destChain, params.destToken);
35
+ const sender = params.sender ?? params.refundAddress ?? "";
36
+ const request = {
37
+ sourceChain: params.sourceChain,
38
+ destChain: params.destChain,
39
+ sourceContract: source.contract ?? null,
40
+ sourceDecimals: source.decimals,
41
+ destContract: dest ? dest.contract ?? null : params.destToken || null,
42
+ amount: BigInt(params.amountIn),
43
+ sender,
44
+ recipient: params.destAddress,
45
+ funding
46
+ };
47
+ const seq = quote.providerData?.sequence ?? "";
48
+ if (!/^[1-9]\d{0,15}$/.test(seq)) return "layerswap: the quote names no swap sequence number";
49
+ const record = { id: quote.intentId.replace(/^layerswap:/, ""), sequence: BigInt(seq), status: "user_transfer_pending" };
50
+ const action = (over) => ({
51
+ type: "transfer",
52
+ step: "deposit",
53
+ toAddress: "",
54
+ amountInBaseUnits: request.amount,
55
+ callData: null,
56
+ gasLimit: null,
57
+ network: { name: params.sourceChain.startsWith("eip155:") ? void 0 : { "solana:mainnet": "SOLANA_MAINNET", "ton:-239": "TON_MAINNET", "tron:728126428": "TRON_MAINNET", "bitcoin:mainnet": "BITCOIN_MAINNET" }[params.sourceChain], chain_id: params.sourceChain.startsWith("eip155:") ? params.sourceChain.slice(7) : void 0 },
58
+ tokenContract: request.sourceContract,
59
+ ...over
60
+ });
61
+ const tx = quote.txRequest;
62
+ if (funding === "depository") {
63
+ if (!tx?.to || !tx.data) return "layerswap: the quote carries no Depository call";
64
+ const e = checkEvmDeposit(request, record, action({ toAddress: tx.to, callData: tx.data, amountInBaseUnits: BigInt(tx.value ?? "0") }));
65
+ if (tx.data.toLowerCase() !== e.data.toLowerCase() || (tx.approvalAddress ?? "").toLowerCase() !== (e.approvalAddress ?? "")) return "layerswap: the quote's Depository call is not the one rebuilt";
66
+ return null;
67
+ }
68
+ if (params.sourceChain.startsWith("solana:")) {
69
+ if (!tx?.serializedTx) return "layerswap: the quote carries no Solana transaction";
70
+ checkSolanaDeposit(request, record, action({ toAddress: quote.providerData?.depositTo ?? "", callData: tx.serializedTx }));
71
+ return null;
72
+ }
73
+ if (tx) return "layerswap: a TON / Tron / Bitcoin deposit is a transfer to an address, not a transaction";
74
+ const memoAction = action({ toAddress: quote.depositAddress, callData: quote.depositMemo, type: funding === "deposit_address" ? "manual_transfer" : "transfer" });
75
+ if (params.sourceChain.startsWith("ton:")) {
76
+ checkTonDeposit(request, record, { ...memoAction, callData: JSON.stringify({ amount: String(request.amount), comment: quote.depositMemo }) });
77
+ } else if (params.sourceChain.startsWith("tron:")) {
78
+ checkTronDeposit(request, record, memoAction);
79
+ } else {
80
+ checkBitcoinDeposit(request, memoAction);
81
+ }
82
+ return null;
83
+ } catch (e) {
84
+ return noted(e);
85
+ }
86
+ }
87
+ var layerswapPins = Object.freeze({
88
+ callTargets: (chain) => fundingFor(chain) === "depository" ? [LAYERSWAP_DEPOSITORY] : [],
89
+ spenders: (chain) => fundingFor(chain) === "depository" ? [LAYERSWAP_DEPOSITORY] : [],
90
+ depositAddressRoutes: true,
91
+ verifyQuote: layerswapVerifyQuote,
92
+ reasonOf: (text) => reasons.get(text)
93
+ });
94
+
95
+ export {
96
+ layerswapVerifyQuote,
97
+ layerswapPins
98
+ };
99
+ //# sourceMappingURL=chunk-5QTIHCE4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/pins.ts"],"sourcesContent":["import {resolveAsset} from \"@anywalletkit/swap2-assets\";\nimport {sourceAssetOf} from \"@anywalletkit/protocol-swap2-core/util\";\nimport type {Quote, QuoteParams, RemotePins} from \"@anywalletkit/protocol-swap2-core/types\";\nimport {refusalOf, type Swap2RefusalInfo} from \"@anywalletkit/protocol-swap2-core/errors\";\nimport {LAYERSWAP_DEPOSITORY, fundingFor} from \"./config.js\";\nimport {checkBitcoinDeposit, checkEvmDeposit, checkSolanaDeposit, checkTonDeposit, checkTronDeposit, type LayerswapAction, type LayerswapRequest, type LayerswapSwapRecord} from \"./verify.js\";\n\n/**\n * The app's side of a remote Layerswap stub: `remoteProvider({name: \"layerswap\", baseUrl, ...layerswapPins})`. A\n * backend's quote is checked here against the app's own request, never against itself: the EVM Depository call is\n * rebuilt (pinned target and receiver, the input token and amount, the swap's sequence number), the Solana\n * transaction read instruction by instruction, the TON / Tron memo held to the swap's sequence number, the Bitcoin\n * send held to the input. What the backend still decides is which swap the deposit names, and Layerswap's record of\n * it — run the backend you trust.\n */\n// The reason behind each text the pins return (`layerswapPins.reasonOf`), bounded.\nconst reasons = new Map<string, Swap2RefusalInfo>();\nfunction noted(e: unknown): string {\n const text = e instanceof Error ? e.message : String(e);\n const info = refusalOf(e);\n if (info) {\n reasons.delete(text);\n reasons.set(text, info);\n if (reasons.size > 256) reasons.delete(reasons.keys().next().value as string);\n }\n return text;\n}\n\nexport function layerswapVerifyQuote(params: QuoteParams, quote: Quote): string | null {\n try {\n const funding = fundingFor(params.sourceChain);\n if (!funding) return \"layerswap: the source chain has no funding method\";\n const source = sourceAssetOf(params);\n if (!source) return `layerswap: unknown source token ${params.sourceToken}`;\n const dest = resolveAsset(params.destChain, params.destToken);\n const sender = params.sender ?? params.refundAddress ?? \"\";\n const request: LayerswapRequest = {\n sourceChain: params.sourceChain, destChain: params.destChain, sourceContract: source.contract ?? null, sourceDecimals: source.decimals,\n destContract: dest ? (dest.contract ?? null) : params.destToken || null, amount: BigInt(params.amountIn), sender, recipient: params.destAddress, funding,\n };\n const seq = quote.providerData?.sequence ?? \"\";\n if (!/^[1-9]\\d{0,15}$/.test(seq)) return \"layerswap: the quote names no swap sequence number\";\n const record: LayerswapSwapRecord = {id: quote.intentId.replace(/^layerswap:/, \"\"), sequence: BigInt(seq), status: \"user_transfer_pending\"};\n // The action as the quote carries it, on the request's own network and token: only its target and payload are the backend's.\n const action = (over: Partial<LayerswapAction>): LayerswapAction => ({\n type: \"transfer\", step: \"deposit\", toAddress: \"\", amountInBaseUnits: request.amount, callData: null, gasLimit: null,\n network: {name: params.sourceChain.startsWith(\"eip155:\") ? undefined : ({\"solana:mainnet\": \"SOLANA_MAINNET\", \"ton:-239\": \"TON_MAINNET\", \"tron:728126428\": \"TRON_MAINNET\", \"bitcoin:mainnet\": \"BITCOIN_MAINNET\"} as Record<string, string>)[params.sourceChain], chain_id: params.sourceChain.startsWith(\"eip155:\") ? params.sourceChain.slice(7) : undefined},\n tokenContract: request.sourceContract, ...over,\n });\n const tx = quote.txRequest;\n if (funding === \"depository\") {\n if (!tx?.to || !tx.data) return \"layerswap: the quote carries no Depository call\";\n const e = checkEvmDeposit(request, record, action({toAddress: tx.to, callData: tx.data, amountInBaseUnits: BigInt(tx.value ?? \"0\")}));\n if (tx.data.toLowerCase() !== e.data.toLowerCase() || (tx.approvalAddress ?? \"\").toLowerCase() !== (e.approvalAddress ?? \"\")) return \"layerswap: the quote's Depository call is not the one rebuilt\";\n return null;\n }\n if (params.sourceChain.startsWith(\"solana:\")) {\n if (!tx?.serializedTx) return \"layerswap: the quote carries no Solana transaction\";\n checkSolanaDeposit(request, record, action({toAddress: quote.providerData?.depositTo ?? \"\", callData: tx.serializedTx}));\n return null;\n }\n if (tx) return \"layerswap: a TON / Tron / Bitcoin deposit is a transfer to an address, not a transaction\";\n const memoAction = action({toAddress: quote.depositAddress, callData: quote.depositMemo, type: funding === \"deposit_address\" ? \"manual_transfer\" : \"transfer\"});\n if (params.sourceChain.startsWith(\"ton:\")) {\n checkTonDeposit(request, record, {...memoAction, callData: JSON.stringify({amount: String(request.amount), comment: quote.depositMemo})});\n } else if (params.sourceChain.startsWith(\"tron:\")) {\n checkTronDeposit(request, record, memoAction);\n } else {\n checkBitcoinDeposit(request, memoAction);\n }\n return null;\n } catch (e) {\n return noted(e);\n }\n}\n\nexport const layerswapPins: RemotePins = Object.freeze({\n callTargets: (chain: string): readonly string[] => (fundingFor(chain) === \"depository\" ? [LAYERSWAP_DEPOSITORY] : []),\n spenders: (chain: string): readonly string[] => (fundingFor(chain) === \"depository\" ? [LAYERSWAP_DEPOSITORY] : []),\n depositAddressRoutes: true,\n verifyQuote: layerswapVerifyQuote,\n reasonOf: (text: string) => reasons.get(text),\n});\n"],"mappings":"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","names":[]}
@@ -0,0 +1,27 @@
1
+ import {
2
+ layerswapProvider
3
+ } from "./chunk-ZTFJO6AI.js";
4
+ import {
5
+ layerswap
6
+ } from "./chunk-ZKT24QPJ.js";
7
+
8
+ // src/protocol.ts
9
+ import { SingleProviderSwap2 } from "@anywalletkit/protocol-swap2-core/swap2/single";
10
+ var LayerswapSwap2Protocol = class extends SingleProviderSwap2 {
11
+ provider;
12
+ constructor(account, config) {
13
+ super(account, config);
14
+ this.provider = layerswapProvider(config);
15
+ }
16
+ chainSupported(caip2) {
17
+ return layerswap.supportsChain(caip2);
18
+ }
19
+ pairSupported(fromChain, toChain) {
20
+ return layerswap.supports(fromChain, toChain);
21
+ }
22
+ };
23
+
24
+ export {
25
+ LayerswapSwap2Protocol
26
+ };
27
+ //# sourceMappingURL=chunk-KCAZCR4I.js.map