@anywalletkit/protocol-swap2-symbiosis 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 +231 -2
  3. package/dist/activity.cjs +140 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +17 -0
  6. package/dist/activity.d.ts +17 -0
  7. package/dist/activity.js +12 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/chunk-4OE47QPO.js +27 -0
  10. package/dist/chunk-4OE47QPO.js.map +1 -0
  11. package/dist/chunk-A2PIAMFC.js +134 -0
  12. package/dist/chunk-A2PIAMFC.js.map +1 -0
  13. package/dist/chunk-BVFMCR2O.js +513 -0
  14. package/dist/chunk-BVFMCR2O.js.map +1 -0
  15. package/dist/chunk-SAPQ6CWV.js +42 -0
  16. package/dist/chunk-SAPQ6CWV.js.map +1 -0
  17. package/dist/chunk-UCHTN275.js +683 -0
  18. package/dist/chunk-UCHTN275.js.map +1 -0
  19. package/dist/chunk-XO25P6PK.js +155 -0
  20. package/dist/chunk-XO25P6PK.js.map +1 -0
  21. package/dist/config.cjs +175 -0
  22. package/dist/config.cjs.map +1 -0
  23. package/dist/config.d.cts +115 -0
  24. package/dist/config.d.ts +115 -0
  25. package/dist/config.js +49 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/index.cjs +1504 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +10 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.js +108 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/pools.cjs +154 -0
  34. package/dist/pools.cjs.map +1 -0
  35. package/dist/pools.d.cts +24 -0
  36. package/dist/pools.d.ts +24 -0
  37. package/dist/pools.js +13 -0
  38. package/dist/pools.js.map +1 -0
  39. package/dist/protocol.cjs +1439 -0
  40. package/dist/protocol.cjs.map +1 -0
  41. package/dist/protocol.d.cts +16 -0
  42. package/dist/protocol.d.ts +16 -0
  43. package/dist/protocol.js +12 -0
  44. package/dist/protocol.js.map +1 -0
  45. package/dist/provider.cjs +1443 -0
  46. package/dist/provider.cjs.map +1 -0
  47. package/dist/provider.d.cts +143 -0
  48. package/dist/provider.d.ts +143 -0
  49. package/dist/provider.js +17 -0
  50. package/dist/provider.js.map +1 -0
  51. package/dist/verify.cjs +934 -0
  52. package/dist/verify.cjs.map +1 -0
  53. package/dist/verify.d.cts +109 -0
  54. package/dist/verify.d.ts +109 -0
  55. package/dist/verify.js +31 -0
  56. package/dist/verify.js.map +1 -0
  57. package/module.json +22 -0
  58. package/package.json +102 -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,232 @@
1
- # Temporary Holding Version
1
+ # @anywalletkit/protocol-swap2-symbiosis
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
+ [![npm](https://img.shields.io/npm/v/@anywalletkit/protocol-swap2-symbiosis?label=npm)](https://www.npmjs.com/package/@anywalletkit/protocol-swap2-symbiosis)
4
+
5
+ [Symbiosis](https://docs.symbiosis.finance) as a swap2 provider: any-to-any
6
+ cross-chain swaps between Ethereum, BNB Chain, Avalanche, Polygon, Arbitrum,
7
+ Optimism, Base, Tron and TON, with Tron and TON as **sources** too. Quotes and
8
+ calldata come from Symbiosis' public REST API
9
+ (`api.symbiosis.finance/crosschain`); the transaction is decoded and bound to
10
+ the request on the device before a quote is shown and again before anything is
11
+ signed. No API key is needed, no partner id is set, and this module adds no fee
12
+ of its own.
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install @anywalletkit/protocol-swap2-symbiosis @anywalletkit/core
18
+ # or: pnpm add @anywalletkit/protocol-swap2-symbiosis @anywalletkit/core · yarn add @anywalletkit/protocol-swap2-symbiosis @anywalletkit/core
19
+ ```
20
+
21
+ On npm: [@anywalletkit/protocol-swap2-symbiosis](https://www.npmjs.com/package/@anywalletkit/protocol-swap2-symbiosis), published from the [release workflow](https://github.com/ultratestbro/anywalletkit/blob/main/RELEASING.md) with provenance.
22
+
23
+ ```ts
24
+ import {symbiosisProvider} from "@anywalletkit/protocol-swap2-symbiosis/provider";
25
+ import {RouterSwap2Protocol} from "@anywalletkit/protocol-swap2-router/swap2/router";
26
+
27
+ const swap2 = new RouterSwap2Protocol(bscAccount, {fromChain: "eip155:56", providers: [symbiosisProvider()]});
28
+ const res = await swap2.swap2({fromToken: "USDC", toToken: "USDT", toChain: "ton:-239", recipient: tonAddress, fromTokenAmount: 1_500n * 10n ** 18n});
29
+ const status = await swap2.getSwap2Status(res.id); // pending → completed | partial | refund-pending → refunded
30
+ ```
31
+
32
+ | From (sources) | How the swap is sent | Default |
33
+ |---|---|---|
34
+ | Ethereum, BNB Chain, Avalanche, Polygon, Arbitrum, Optimism, Base | one `metaRoute` call on the chain's MetaRouterGateway; a token sale gets an exact approval to the same gateway first | on |
35
+ | TON (jettons) | one jetton transfer to Symbiosis' TON Portal with the bridge request in the forward payload | on |
36
+ | Tron (TRC-20) | one `metaRoute` call on the Tron MetaRouterGateway (`TPuaJ6gnYfE9gLUDFrbWbPx3tMnjG8max1`) | **off** — `tronSource: true` |
37
+ | Bitcoin | a deposit address the API names | **off** — `btcSource: true` |
38
+
39
+ Destinations: every chain above except Bitcoin. Tokens are the ones the shared
40
+ catalog (`@anywalletkit/swap2-assets`) knows on those chains; which pairs get a
41
+ route is Symbiosis' answer at that moment.
42
+
43
+ Not served: TON's native coin as a source (Symbiosis sends it through a partner
44
+ exchange), TRX as a source (no swap router is allow-listed on Tron), same-chain
45
+ swaps, and any route labelled `partner-swap`, `semi-centralized` or `intent`,
46
+ where a third party holds the funds (ChangeNOW-style legs, THORChain and
47
+ Chainflip bridges inside Symbiosis).
48
+
49
+ ## What is checked before signing
50
+
51
+ `getQuote` never forwards the API's transaction blindly. It decodes every level
52
+ of it, requires each level to re-encode to exactly the same bytes, and refuses
53
+ the quote unless all of the following hold. `preflightDeposit` and the pins'
54
+ `verifyQuote` / `verifyBuild` run the same code again on the device right before
55
+ signing, so a server-side instance of this provider is trusted no more than the
56
+ API is.
57
+
58
+ **EVM and Tron source**
59
+
60
+ - the contract called is the chain's pinned MetaRouterGateway, the function is
61
+ `metaRoute`, the chain id is the source chain, `amount` is the sell amount, the
62
+ transaction value is the sell amount for a native sale and 0 for a token sale,
63
+ the first approved token is the sell token, and an approval names only that
64
+ gateway;
65
+ - before the bridge there is nothing, the wrap of the native coin, or **one**
66
+ swap on an allow-listed router (below) decoded to: sell token and amount in,
67
+ the bridged token out to the chain's pinned MetaRouter, no partial fill;
68
+ - the relay recipient is the chain's pinned Portal, and it gets
69
+ `metaSynthesize` naming the pinned host-chain Synthesis and Bridge, the host
70
+ chain id, the user as `syntCaller`, and only the user's own addresses — or
71
+ Symbiosis' revert service, see below — as `chain2address` /
72
+ `revertableAddress`;
73
+ - the swap on Symbiosis' host chain is `multicall` on the pinned
74
+ MulticallRouter; every step is `swap(tokenIndexFrom, tokenIndexTo, dx, minDy,
75
+ to, deadline)` on a **pinned Symbiosis pool**, between that pool's pinned
76
+ tokens, paid to the MulticallRouter, with the running amount written into
77
+ `dx` and nowhere else; the path is the swap token list and the result goes to
78
+ the pinned host-chain MetaRouter;
79
+ - the token burned on the host chain is the one the pools pay out, and it is
80
+ the **pinned synthetic of a token on the destination chain** (`pools.ts`,
81
+ read from the host chain's SyntFabric); the burn names the destination chain
82
+ id, its pinned Portal and Bridge, and the user's address as receiver;
83
+ - after the bridge there is either nothing — then the released token is the
84
+ quoted token and the last pool minimum less the relayers' fee is not below
85
+ the quote's minimum — or Symbiosis' pinned Unwrapper `unwrap(amount, to)`
86
+ paying the recipient, or **one** swap on an allow-listed router decoded to:
87
+ the released token in, the quoted token out to the recipient, a minimum not
88
+ below the quote's minimum. Anything else is refused;
89
+ - every place a contract writes a running amount into the next call
90
+ (`finalOffset`, the multicall `offsets[]`) is the amount word of the function
91
+ it patches.
92
+
93
+ **Tron source, additionally.** The call is the same `metaRoute` ABI on the
94
+ pinned Tron gateway; the fee limit the API asks for is capped
95
+ (`tronFeeLimitCap`, default 300 TRX). The engine does not execute contract
96
+ calls on Tron yet, so `tronSource` is off by default. With it on, an app builds
97
+ the transaction itself: `symbiosisTronCall(quote)` returns the node request and
98
+ the exact `expected` transaction for `@anywalletkit/wallet-tron`'s
99
+ `assertNodeBuild` — txID = sha256(raw_data_hex), one `TriggerSmartContract`,
100
+ owner = the user, contract = the pinned gateway, calldata = the checked bytes,
101
+ call value and fee limit as checked.
102
+
103
+ **TON source.** The message body is parsed (BOC) as a jetton transfer of
104
+ exactly the sell amount to the pinned TON Portal, excess back to the sender, no
105
+ custom payload, forwarding less TON than the message attaches (itself capped at
106
+ 1 TON); the forward payload is Symbiosis' bridge request, and its host-chain and
107
+ destination legs go through the same checks as above. The message is addressed
108
+ to the sender's own jetton wallet; that address is derived and checked by the
109
+ wallet engine (`wallet-ton`), not by this module.
110
+
111
+ **Allow-listed swap routers.** 1inch AggregationRouterV6 and KyberSwap
112
+ MetaAggregationRouterV2 (same address on every EVM chain here, non-upgradable,
113
+ source-verified), and a Uniswap-V2-style router on BNB Chain (PancakeSwap),
114
+ Polygon (QuickSwap) and Base. A leg on any other venue (0x, OpenOcean, Bitget,
115
+ …) is not read: the provider asks the API again with that venue switched off,
116
+ up to four requests a second apart, and refuses if nothing readable comes back.
117
+ 1inch calls carry a tracking tag after their arguments, which is not the
118
+ canonical encoding of one swap; such an answer is asked for again without
119
+ 1inch.
120
+
121
+ ## What is still trusted
122
+
123
+ - **Symbiosis itself**: its contracts, relayers (an MPC group signs the
124
+ cross-chain messages), pools and the relayers' fee (`stableBridgingFee`,
125
+ bound only to "the minimum still holds after it").
126
+ - **The revert path.** On every route the API writes Symbiosis' own revert
127
+ service (`0x67f9…851D`) as `revertableAddress` of the bridge request, and a
128
+ request cannot change that. A stuck swap is reverted by that service, not by
129
+ the user's key. The quote carries `providerData.serviceReverts = "1"` so an
130
+ app can say so.
131
+ - **Inside an aggregator swap**: which venues the executor trades on. What
132
+ holds is the router's own guarantee: it reverts unless the receiver got at
133
+ least the decoded minimum of the decoded token.
134
+ - **The price of a swap before the bridge.** Its minimum is tied to the amounts
135
+ the API states and to the route's final minimum, not to a market price. A
136
+ route can be poor value and still pass (live 2026-11-10: Tron USDT → Base
137
+ USDC through the Base V2 router lost about 3 %). Showing that is the app's
138
+ job; `providerData.priceImpact` carries the API's figure.
139
+ - **The minimum itself** comes from the quote (`minDestAmount`); the checks
140
+ hold the route to it, they do not judge it.
141
+ - **The pinned tables** (`config.ts`, `pools.ts`). They were read from
142
+ Symbiosis' published configuration **and** from the chains; the public
143
+ configuration alone is not enough (parts of it trail the live deployment).
144
+ `scripts/build-pins.mjs --check` re-derives the pool and synthetic-token
145
+ tables from the host chain, `scripts/verify-live.mjs` re-reads every pinned
146
+ contract, and `watch.json` puts the EVM and host-chain ones (code, proxy
147
+ implementations, pool token counts, the Unwrappers' `wrapper()`) under the
148
+ module watch. The Tron contracts are not under the watch (it has no Tron
149
+ reader); `verify-live.mjs` checks them.
150
+ - **Bitcoin source.** The deposit address is assigned by the API and cannot be
151
+ verified on the device. It is off by default, quoted with
152
+ `providerData.depositAddressAssigned = "1"`, and the pins open it only as
153
+ `depositAddressRoutes` when `btcSource` is set. Whether to offer such a route
154
+ is the app's policy. Symbiosis currently serves Bitcoin sources only through
155
+ the partner routes this module switches off, so no real Bitcoin quote has
156
+ been seen (2026-11-10).
157
+
158
+ ## Fees and limits
159
+
160
+ Every fee the API reports is on the quote (`fees[]`, token, amount, where it is
161
+ taken) and summed into `feeUsd`; a response without readable fees, or with a
162
+ fee that has no price, is refused. All fees are included in the quoted output.
163
+ Observed 2026-11-10: about $0.50 between EVM chains and from Tron, $0.60 to
164
+ TON, $3 to Tron, plus pool fees inside the amount.
165
+
166
+ `GET /v1/swap-limits` is cached for five minutes and enforced locally: a sell
167
+ amount below the source token's minimum, or a result above the destination
168
+ token's maximum, is refused before a quote is asked for. On 2026-11-10 that was
169
+ 0.3 – 200 000 for the bridged stablecoins and 0.0001 – 50 for ETH.
170
+
171
+ Slippage is the caller's `slippageBps`, else the config's, else
172
+ `suggestSlippage` from swap2-core for the pair. It is sent to the API as is.
173
+
174
+ ## Status
175
+
176
+ `trackIntent` reads `GET /v2/tx/{chainId}/{hash}` (`SYMBIOSIS_STATUS`):
177
+
178
+ | API | State | What it means |
179
+ |---|---|---|
180
+ | not found | `pending` | the source transaction is not indexed yet |
181
+ | Pending | `pending`, or `refund-pending` when the hash is on `/v1/stucked/{address}` | in flight, or stuck |
182
+ | Success | `completed`; `partial` if another token or chain was paid | a failed destination swap delivers the bridged token instead |
183
+ | Stuck | `refund-pending` | Symbiosis reverts it itself, usually within an hour |
184
+ | Reverted | `refunded` **only with the revert transaction in the answer**, else `refund-pending` | the revert pays the token that crossed the bridge to the sender on the source chain, less the bridge fee — not always the token sold |
185
+
186
+ When neither side is an EVM chain (Tron ↔ TON) a failed last leg leaves
187
+ synthetic tokens on Symbiosis' host chain at `fallbackReceiver`, which must be
188
+ the user's own EVM address; the provider refuses such a route without it.
189
+
190
+ ## Behind `remoteProvider`
191
+
192
+ When the provider runs on your server, spread its pins into the app's stub:
193
+ `remoteProvider({name: "symbiosis", baseUrl, ...symbiosisPinsFor({fallbackReceiver})})`.
194
+ The engine then lets an EVM route call and approve only the pinned
195
+ MetaRouterGateways, and `verifyQuote` / `verifyBuild` run the full decode above
196
+ on the device.
197
+
198
+ ## Config
199
+
200
+ ```ts
201
+ symbiosisProvider({
202
+ enabled: true, // default
203
+ apiUrl: "https://api.symbiosis.finance/crosschain",
204
+ tronSource: false, // quote Tron sources (the app signs them through symbiosisTronCall)
205
+ btcSource: false, // quote Bitcoin sources (API-assigned deposit address)
206
+ boundSourceOnly: false, // true: refuse routes that swap on the source chain before bridging
207
+ fallbackReceiver, // the user's EVM address; required for Tron ↔ TON
208
+ slippageBps, // default when the caller names none
209
+ quoteTtlMs: 60_000,
210
+ tronFeeLimitCap: 300_000_000n,
211
+ partnerAddress, partnerId, apiKey, // optional, never set by default; keep a key on your proxy, not in the app
212
+ })
213
+ ```
214
+
215
+ The API serves about one quote per second per client.
216
+
217
+ ## Activity
218
+
219
+ `describeActivity` (`./activity`) names a wallet's `metaRoute` transactions and
220
+ TON bridge transfers as swaps from their own bytes, with the destination chain
221
+ and recipient.
222
+
223
+ ## Tests
224
+
225
+ ```sh
226
+ pnpm --filter @anywalletkit/protocol-swap2-symbiosis test # 300 tests over recorded API answers
227
+ pnpm --filter @anywalletkit/protocol-swap2-symbiosis verify:live # read-only: pins on-chain, live quotes through the provider, eth_call / Tron node builds
228
+ ```
229
+
230
+ `verify:live` signs and sends nothing. Fixtures are real answers recorded by
231
+ `scripts/record-fixtures.mjs`; the Bitcoin build tests use synthetic answers
232
+ and say so.
@@ -0,0 +1,140 @@
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
+ SYMBIOSIS_META_ROUTE: () => SYMBIOSIS_META_ROUTE,
24
+ SYMBIOSIS_MODULE: () => SYMBIOSIS_MODULE,
25
+ describeSymbiosisActivity: () => describeSymbiosisActivity
26
+ });
27
+ module.exports = __toCommonJS(activity_exports);
28
+ var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
29
+ var import_util2 = require("@anywalletkit/protocol-swap2-core/util");
30
+
31
+ // src/config.ts
32
+ var import_base = require("@scure/base");
33
+ var import_sha2 = require("@noble/hashes/sha2.js");
34
+ var import_viem = require("viem");
35
+ var import_swap2_assets = require("@anywalletkit/swap2-assets");
36
+ var import_util = require("@anywalletkit/protocol-swap2-core/util");
37
+ var SYMBIOSIS_HOST = Object.freeze({
38
+ synthesis: "0x45CFd6FB7999328F189aaD2739Fba4Be6C45E5bf",
39
+ bridge: "0x1a039cE63AE35a67Bf0E9F6DbFaE969639D59eC8",
40
+ /** MulticallRouter: the only contract a route's host-chain pool swaps may call. */
41
+ multicallRouter: "0xBbAD2fe9558e55EbfA04b3B5Bff0b6c4E2ffDD2C"
42
+ });
43
+ var SYMBIOSIS_AGGREGATORS = Object.freeze({
44
+ oneInchV6: "0x111111125421cA6dc452d289314280a0f8842A65",
45
+ kyberV2: "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5"
46
+ });
47
+ var SYMBIOSIS_V2_ROUTERS = Object.freeze({
48
+ 56: "0x10ED43C718714eb63d5aA57B78B54704E256024E",
49
+ 137: "0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff",
50
+ 8453: "0x327Df1E6de05895d2ab08513aaDD9313Fe505d86"
51
+ });
52
+ var SYMBIOSIS_UNWRAPPERS = Object.freeze({
53
+ 1: { unwrapper: "0x5ad095DE83693ba063941f2f2C5A0dF02383B651", wrapped: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2" },
54
+ 10: { unwrapper: "0x88139ad1199e8c78a0804d4bEBF4FbAD89EF9D89", wrapped: "0x4200000000000000000000000000000000000006" },
55
+ 42161: { unwrapper: "0x5Eb4ED9F745531221FAE41906e11d37642B15da6", wrapped: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1" },
56
+ 8453: { unwrapper: "0x8e1d36F9da8CFe842bCf8670A12ACd51c26d195D", wrapped: "0x4200000000000000000000000000000000000006" }
57
+ });
58
+ var SYMBIOSIS_TON_PORTAL_RAW = "0:5987d0a92d9c8d97023b6a6d0f1e9572f13f33749c408651b79b7c4c8b406855";
59
+ var SYMBIOSIS_TRON_CHAIN_ID = 728126428;
60
+ var SYMBIOSIS_TON_CHAIN_ID = 85918;
61
+ var SYMBIOSIS_BTC_CHAIN_ID = 3652501241;
62
+ var evm = (id, name, gateway, executor, portal, bridge) => Object.freeze({ caip2: `eip155:${id}`, family: "evm", id, name, gateway, executor, portal, bridge });
63
+ var LIST = [
64
+ evm(1, "Ethereum", "0xB4769e9c5bE31199a25ecD1B0C6609183fa72521", "0xc227b3a439EE6ae3A22500757125f4dE91d8008E", "0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8", "0x5523985926Aa12BA58DC5Ad00DDca99678D7227E"),
65
+ evm(56, "BNB Chain", "0x851B43189de721dD94AbA767AAd9E6F6d6a95CCA", "0x980447DdcEf79A7499Da4538Da8FC59BAcAD6997", "0x5Aa5f7f84eD0E5db0a4a85C3947eA16B53352FD4", "0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8"),
66
+ evm(43114, "Avalanche", "0xfeC09BE39F82b13471D2e0E7d72e6ee589c631c6", "0x4494b8cBC69c794d82Bd2d820A6ff6f62D7D841A", "0xE75C7E85FE6ADd07077467064aD15847E6ba9877", "0x292fC50e4eB66C3f6514b9E402dBc25961824D62"),
67
+ evm(137, "Polygon", "0x2eE9559387b806E88fd46b9DA160D64A29CE7Da0", "0x7a73a0bA4919778C5442f026bd01795b4f2A4cB8", "0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8", "0x5523985926Aa12BA58DC5Ad00DDca99678D7227E"),
68
+ evm(42161, "Arbitrum", "0x3743c756b64ECd0770f1d4f47696A73d2A46dcbe", "0xf37E321e1c275d249B7A9c825aE802A9f464Eb94", "0x01A3c8E513B758EBB011F7AFaf6C37616c9C24d9", "0x5523985926Aa12BA58DC5Ad00DDca99678D7227E"),
69
+ evm(10, "Optimism", "0xA9A96Ee51dD54B9f51d46b1fbD2A19c1295Ec75b", "0x356d322BF762d4022D8c241428770565f236c2EA", "0x292fC50e4eB66C3f6514b9E402dBc25961824D62", "0x5523985926Aa12BA58DC5Ad00DDca99678D7227E"),
70
+ evm(8453, "Base", "0xa18348e793E77239EC68CAa51b74c5Cdc82c8a9d", "0xCbFD5DcaD860f49D0BD2fDaD78d9d943CAeBedef", "0xEE981B2459331AD268cc63CE6167b446AF4161f8", "0x8097f0B9f06C27AF9579F75762F971D745bb222F"),
71
+ Object.freeze({
72
+ caip2: "tron:728126428",
73
+ family: "tron",
74
+ id: SYMBIOSIS_TRON_CHAIN_ID,
75
+ name: "Tron",
76
+ gateway: "0x98e1df4e3200e1001610365e2eb133a953bbe3e0",
77
+ // TPuaJ6gnYfE9gLUDFrbWbPx3tMnjG8max1
78
+ executor: "0xd076ab0d4b74aef1aec7b1d4f106787e0d5f9163",
79
+ portal: "0x21fb7f70b95d119f7594267a79e2897290a21caf",
80
+ // TD4tamFrCq7KvQEB1LArNXr9sKFC6GaAmt
81
+ bridge: "0x9c4C6918f9d4CfC4B7C9cF080ce3C4D50B948323"
82
+ }),
83
+ Object.freeze({ caip2: "ton:-239", family: "ton", id: SYMBIOSIS_TON_CHAIN_ID, name: "TON" }),
84
+ Object.freeze({ caip2: "bitcoin:mainnet", family: "bitcoin", id: SYMBIOSIS_BTC_CHAIN_ID, name: "Bitcoin" })
85
+ ];
86
+ var SYMBIOSIS_CHAINS = Object.freeze(Object.fromEntries(LIST.map((c) => [c.caip2, c])));
87
+ var SYMBIOSIS_BY_ID = Object.freeze(Object.fromEntries(LIST.map((c) => [c.id, c])));
88
+ function symbiosisChain(caip2) {
89
+ return SYMBIOSIS_CHAINS[(0, import_swap2_assets.catalogChainId)(caip2)];
90
+ }
91
+ function evmToTron(address) {
92
+ if (!(0, import_viem.isAddress)(address, { strict: false })) throw new Error(`symbiosis: not a 20-byte address: ${address}`);
93
+ const body = new Uint8Array(21);
94
+ body[0] = 65;
95
+ const raw = address.slice(2);
96
+ for (let i = 0; i < 20; i++) body[i + 1] = parseInt(raw.slice(i * 2, i * 2 + 2), 16);
97
+ const out = new Uint8Array(25);
98
+ out.set(body);
99
+ out.set((0, import_sha2.sha256)((0, import_sha2.sha256)(body)).subarray(0, 4), 21);
100
+ return import_base.base58.encode(out);
101
+ }
102
+ var symbiosis = Object.freeze({
103
+ /** A chain this module knows (as a source or a destination). */
104
+ supportsChain: (caip2) => symbiosisChain(caip2) !== void 0,
105
+ /** Two different chains this module knows; Bitcoin is never a destination. */
106
+ supports(fromChain, toChain) {
107
+ const a = symbiosisChain(fromChain);
108
+ const b = symbiosisChain(toChain);
109
+ return !!a && !!b && a !== b && b.family !== "bitcoin";
110
+ }
111
+ });
112
+
113
+ // src/activity.ts
114
+ var SYMBIOSIS_MODULE = "@anywalletkit/protocol-swap2-symbiosis";
115
+ var SYMBIOSIS_META_ROUTE = "0xa11b1198";
116
+ function describeSymbiosisActivity(tx, ctx) {
117
+ const chain = symbiosisChain(tx.chain);
118
+ if (!chain) return null;
119
+ const subtitle = `Symbiosis \xB7 ${(0, import_activity.chainLabel)(chain.caip2)}`;
120
+ if (chain.family === "evm" && chain.gateway) {
121
+ if (!(0, import_activity.matchesCall)(tx, [chain.gateway], [SYMBIOSIS_META_ROUTE])) return null;
122
+ return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: SYMBIOSIS_MODULE, subtitle, kind: "bridge", outVerb: "Bridged" });
123
+ }
124
+ if (chain.family === "tron" && chain.gateway) {
125
+ if (!(0, import_activity.matchesCall)(tx, [evmToTron(chain.gateway), chain.gateway, `0x41${chain.gateway.slice(2)}`], [SYMBIOSIS_META_ROUTE])) return null;
126
+ return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: SYMBIOSIS_MODULE, subtitle, kind: "bridge", outVerb: "Bridged", counterparty: evmToTron(chain.gateway) });
127
+ }
128
+ if (chain.family === "ton") {
129
+ const own = /* @__PURE__ */ new Set();
130
+ for (const a of ctx.own) {
131
+ const raw = (0, import_util2.tonRawAddress)(a);
132
+ if (raw) own.add(raw);
133
+ }
134
+ const sent = tx.transfers.some((t) => t.token !== null && (0, import_util2.tonRawAddress)(t.to) === SYMBIOSIS_TON_PORTAL_RAW && own.has((0, import_util2.tonRawAddress)(t.from) ?? ""));
135
+ if (!sent) return null;
136
+ return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: SYMBIOSIS_MODULE, subtitle, kind: "bridge", outVerb: "Bridged" });
137
+ }
138
+ return null;
139
+ }
140
+ //# sourceMappingURL=activity.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/activity.ts","../src/config.ts"],"sourcesContent":["/**\n * Activity recognition for Symbiosis source transactions:\n * - EVM and Tron: `metaRoute` on the chain's pinned MetaRouterGateway — the one call every source\n * transaction of this module is (\"Bridged USDT\");\n * - TON: a jetton transfer from the owner to the pinned TON Portal.\n * The delivery on the destination chain is a relayer's transaction the user signs nothing in; it is\n * left to the wallet's plain \"received\" item.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {tonRawAddress} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {SYMBIOSIS_TON_PORTAL_RAW, evmToTron, symbiosisChain} from \"./config.js\";\n\nexport const SYMBIOSIS_MODULE = \"@anywalletkit/protocol-swap2-symbiosis\";\n/** `metaRoute((bytes,bytes,address[],address,address,uint256,bool,address,bytes))` — MetaRouterGateway. */\nexport const SYMBIOSIS_META_ROUTE = \"0xa11b1198\";\n\nexport function describeSymbiosisActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n const chain = symbiosisChain(tx.chain);\n if (!chain) return null;\n const subtitle = `Symbiosis · ${chainLabel(chain.caip2)}`;\n if (chain.family === \"evm\" && chain.gateway) {\n if (!matchesCall(tx, [chain.gateway], [SYMBIOSIS_META_ROUTE])) return null;\n return describeSwapLike(tx, ctx, {protocol: SYMBIOSIS_MODULE, subtitle, kind: \"bridge\", outVerb: \"Bridged\"});\n }\n if (chain.family === \"tron\" && chain.gateway) {\n // A Tron history source names the contract in base58 or in 20-byte hex, depending on the indexer.\n if (!matchesCall(tx, [evmToTron(chain.gateway), chain.gateway, `0x41${chain.gateway.slice(2)}`], [SYMBIOSIS_META_ROUTE])) return null;\n return describeSwapLike(tx, ctx, {protocol: SYMBIOSIS_MODULE, subtitle, kind: \"bridge\", outVerb: \"Bridged\", counterparty: evmToTron(chain.gateway)});\n }\n if (chain.family === \"ton\") {\n const own = new Set<string>();\n for (const a of ctx.own) { const raw = tonRawAddress(a); if (raw) own.add(raw); }\n const sent = tx.transfers.some((t) => t.token !== null && tonRawAddress(t.to) === SYMBIOSIS_TON_PORTAL_RAW && own.has(tonRawAddress(t.from) ?? \"\"));\n if (!sent) return null;\n return describeSwapLike(tx, ctx, {protocol: SYMBIOSIS_MODULE, subtitle, kind: \"bridge\", outVerb: \"Bridged\"});\n }\n return null;\n}\n","import {base58} from \"@scure/base\";\nimport {sha256} from \"@noble/hashes/sha2.js\";\nimport {getAddress, isAddress} from \"viem\";\nimport {catalogChainId} from \"@anywalletkit/swap2-assets\";\nimport {tonRawAddress} from \"@anywalletkit/protocol-swap2-core/util\";\n\n/**\n * Symbiosis deployments this module is bound to. Every address below is taken from\n * Symbiosis' own published configuration and re-read on-chain (`scripts/verify-live.mjs`):\n *\n * - `gateway` — MetaRouterGateway: the ONLY contract a source transaction calls and the\n * ONLY spender an ERC-20 / TRC-20 approval may name. It pulls the sell amount and hands\n * it to the chain's MetaRouter (`executor`), which is never approved by a user.\n * - `portal` / `bridge` — the chain's Portal (locks and releases real tokens) and the\n * relayers' Bridge entry; the calldata names both for the destination leg.\n * - host chain — Symbiosis' own chain (id 13863860) where every swap is routed through the\n * stable pools (\"octopool\"): its Synthesis and Bridge are named in every source call. Its pools,\n * their token indexes and the synthetic-token map are pinned in `pools.ts`.\n *\n * Chains Symbiosis serves that are not listed here are simply not offered by this module.\n */\n\nexport const SYMBIOSIS_API = \"https://api.symbiosis.finance/crosschain\";\n/** Symbiosis' host chain (where synthetic tokens are minted, swapped and burned). */\nexport const SYMBIOSIS_HOST_CHAIN_ID = 13863860;\nexport const SYMBIOSIS_HOST = Object.freeze({\n synthesis: \"0x45CFd6FB7999328F189aaD2739Fba4Be6C45E5bf\",\n bridge: \"0x1a039cE63AE35a67Bf0E9F6DbFaE969639D59eC8\",\n /** MulticallRouter: the only contract a route's host-chain pool swaps may call. */\n multicallRouter: \"0xBbAD2fe9558e55EbfA04b3B5Bff0b6c4E2ffDD2C\",\n});\n/**\n * The aggregator routers a route may swap on before or after the bridge. Together with the V2\n * routers below they are the only third-party contracts this module lets a route approve. Both are non-upgradable, deployed at the same address\n * on every EVM chain listed below, and source-verified there (Sourcify: AggregationRouterV6,\n * MetaAggregationRouterV2). Tron has neither, so a Tron leg never swaps.\n */\nexport const SYMBIOSIS_AGGREGATORS = Object.freeze({\n oneInchV6: \"0x111111125421cA6dc452d289314280a0f8842A65\",\n kyberV2: \"0x6131B5fae19EA4f9D964eAc0408E4408b66337b5\",\n});\n/**\n * Uniswap-V2-style routers a route may swap on (Symbiosis' own configuration names one per chain):\n * only the ones that are source-verified as a plain V2 `Router02` (Sourcify: PancakeRouter on\n * BNB Chain and Base, UniswapV2Router02 on Polygon) and non-upgradable. Their two exact-input\n * functions are fully decodable: path, receiver and minimum are plain arguments.\n */\nexport const SYMBIOSIS_V2_ROUTERS: Readonly<Record<number, string>> = Object.freeze({\n 56: \"0x10ED43C718714eb63d5aA57B78B54704E256024E\",\n 137: \"0xa5E0829CaCEd8fFDD4De3c43696c57F7D7A678ff\",\n 8453: \"0x327Df1E6de05895d2ab08513aaDD9313Fe505d86\",\n});\n/**\n * Symbiosis' Unwrapper per chain — `unwrap(amount, to)` pulls the wrapped native token from the\n * caller, unwraps it and sends the coin to `to` — and the wrapped token it is set to (`wrapper()`),\n * read on-chain. Source-verified (Sourcify: Unwrapper); its owner can repoint `wrapper`, which is\n * why the watch list re-reads it.\n */\nexport const SYMBIOSIS_UNWRAPPERS: Readonly<Record<number, {unwrapper: string; wrapped: string}>> = Object.freeze({\n 1: {unwrapper: \"0x5ad095DE83693ba063941f2f2C5A0dF02383B651\", wrapped: \"0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2\"},\n 10: {unwrapper: \"0x88139ad1199e8c78a0804d4bEBF4FbAD89EF9D89\", wrapped: \"0x4200000000000000000000000000000000000006\"},\n 42161: {unwrapper: \"0x5Eb4ED9F745531221FAE41906e11d37642B15da6\", wrapped: \"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1\"},\n 8453: {unwrapper: \"0x8e1d36F9da8CFe842bCf8670A12ACd51c26d195D\", wrapped: \"0x4200000000000000000000000000000000000006\"},\n});\n/**\n * Symbiosis' own address the API writes as `revertableAddress` whenever a leg touches Tron or\n * TON, and as the default `fallbackReceiver`: their service that reverts a stuck swap. A request\n * cannot replace it on those routes — see the README (\"What is still trusted\").\n */\nexport const SYMBIOSIS_REVERTER = \"0x67f9b3E561383493B3f874fEAE0c53c2cD23851D\";\n/** Symbiosis' Portal on TON: the only destination a TON-source jetton transfer may name. */\nexport const SYMBIOSIS_TON_PORTAL = \"EQBZh9CpLZyNlwI7am0PHpVy8T8zdJxAhlG3m3xMi0BoVaUh\";\nexport const SYMBIOSIS_TON_PORTAL_RAW = \"0:5987d0a92d9c8d97023b6a6d0f1e9572f13f33749c408651b79b7c4c8b406855\";\n\nexport const SYMBIOSIS_TRON_CHAIN_ID = 728126428;\nexport const SYMBIOSIS_TON_CHAIN_ID = 85918;\nexport const SYMBIOSIS_BTC_CHAIN_ID = 3652501241;\n\nexport type SymbiosisFamily = \"evm\" | \"tron\" | \"ton\" | \"bitcoin\";\n\nexport interface SymbiosisChain {\n /** Catalog CAIP-2 id. */\n caip2: string;\n family: SymbiosisFamily;\n /** The chain id Symbiosis' API and contracts use. */\n id: number;\n name: string;\n /** MetaRouterGateway (EVM form; Tron: the 20 bytes of the base58 address). */\n gateway?: string;\n /** MetaRouter the gateway forwards to — read from `gateway.metaRouterExecutorDontApprove()` on-chain, never approved by a user. */\n executor?: string;\n portal?: string;\n bridge?: string;\n}\n\nconst evm = (id: number, name: string, gateway: string, executor: string, portal: string, bridge: string): SymbiosisChain =>\n Object.freeze({caip2: `eip155:${id}`, family: \"evm\" as const, id, name, gateway, executor, portal, bridge});\n\nconst LIST: readonly SymbiosisChain[] = [\n evm(1, \"Ethereum\", \"0xB4769e9c5bE31199a25ecD1B0C6609183fa72521\", \"0xc227b3a439EE6ae3A22500757125f4dE91d8008E\", \"0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8\", \"0x5523985926Aa12BA58DC5Ad00DDca99678D7227E\"),\n evm(56, \"BNB Chain\", \"0x851B43189de721dD94AbA767AAd9E6F6d6a95CCA\", \"0x980447DdcEf79A7499Da4538Da8FC59BAcAD6997\", \"0x5Aa5f7f84eD0E5db0a4a85C3947eA16B53352FD4\", \"0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8\"),\n evm(43114, \"Avalanche\", \"0xfeC09BE39F82b13471D2e0E7d72e6ee589c631c6\", \"0x4494b8cBC69c794d82Bd2d820A6ff6f62D7D841A\", \"0xE75C7E85FE6ADd07077467064aD15847E6ba9877\", \"0x292fC50e4eB66C3f6514b9E402dBc25961824D62\"),\n evm(137, \"Polygon\", \"0x2eE9559387b806E88fd46b9DA160D64A29CE7Da0\", \"0x7a73a0bA4919778C5442f026bd01795b4f2A4cB8\", \"0xb8f275fBf7A959F4BCE59999A2EF122A099e81A8\", \"0x5523985926Aa12BA58DC5Ad00DDca99678D7227E\"),\n evm(42161, \"Arbitrum\", \"0x3743c756b64ECd0770f1d4f47696A73d2A46dcbe\", \"0xf37E321e1c275d249B7A9c825aE802A9f464Eb94\", \"0x01A3c8E513B758EBB011F7AFaf6C37616c9C24d9\", \"0x5523985926Aa12BA58DC5Ad00DDca99678D7227E\"),\n evm(10, \"Optimism\", \"0xA9A96Ee51dD54B9f51d46b1fbD2A19c1295Ec75b\", \"0x356d322BF762d4022D8c241428770565f236c2EA\", \"0x292fC50e4eB66C3f6514b9E402dBc25961824D62\", \"0x5523985926Aa12BA58DC5Ad00DDca99678D7227E\"),\n evm(8453, \"Base\", \"0xa18348e793E77239EC68CAa51b74c5Cdc82c8a9d\", \"0xCbFD5DcaD860f49D0BD2fDaD78d9d943CAeBedef\", \"0xEE981B2459331AD268cc63CE6167b446AF4161f8\", \"0x8097f0B9f06C27AF9579F75762F971D745bb222F\"),\n Object.freeze({\n caip2: \"tron:728126428\", family: \"tron\" as const, id: SYMBIOSIS_TRON_CHAIN_ID, name: \"Tron\",\n gateway: \"0x98e1df4e3200e1001610365e2eb133a953bbe3e0\", // TPuaJ6gnYfE9gLUDFrbWbPx3tMnjG8max1\n executor: \"0xd076ab0d4b74aef1aec7b1d4f106787e0d5f9163\",\n portal: \"0x21fb7f70b95d119f7594267a79e2897290a21caf\", // TD4tamFrCq7KvQEB1LArNXr9sKFC6GaAmt\n bridge: \"0x9c4C6918f9d4CfC4B7C9cF080ce3C4D50B948323\",\n }),\n Object.freeze({caip2: \"ton:-239\", family: \"ton\" as const, id: SYMBIOSIS_TON_CHAIN_ID, name: \"TON\"}),\n Object.freeze({caip2: \"bitcoin:mainnet\", family: \"bitcoin\" as const, id: SYMBIOSIS_BTC_CHAIN_ID, name: \"Bitcoin\"}),\n];\n\n/** By catalog CAIP-2 id. */\nexport const SYMBIOSIS_CHAINS: Readonly<Record<string, SymbiosisChain>> = Object.freeze(Object.fromEntries(LIST.map((c) => [c.caip2, c])));\n/** By Symbiosis chain id. */\nexport const SYMBIOSIS_BY_ID: Readonly<Record<number, SymbiosisChain>> = Object.freeze(Object.fromEntries(LIST.map((c) => [c.id, c])));\n\n/** The chain entry for a CAIP-2 id an account or the catalog uses (`tron:0x2b6653dc` and `tron:728126428` are one chain). */\nexport function symbiosisChain(caip2: string): SymbiosisChain | undefined {\n return SYMBIOSIS_CHAINS[catalogChainId(caip2)];\n}\n\n// ── Addresses ────────────────────────────────────────────────────────────────\n\nconst hex = (b: Uint8Array): string => Array.from(b, (x) => x.toString(16).padStart(2, \"0\")).join(\"\");\n\n/** A Tron base58check address (`T…`) as the 20-byte EVM form the contracts and the API use; null for anything else. */\nexport function tronToEvm(address: string): string | null {\n if (typeof address !== \"string\" || !/^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(address)) return null;\n let b: Uint8Array;\n try { b = base58.decode(address); } catch { return null; }\n if (b.length !== 25 || b[0] !== 0x41) return null;\n const check = sha256(sha256(b.subarray(0, 21))).subarray(0, 4);\n if (hex(check) !== hex(b.subarray(21))) return null;\n return getAddress(`0x${hex(b.subarray(1, 21))}`);\n}\n\n/** The base58check spelling (`T…`) of a 20-byte address. */\nexport function evmToTron(address: string): string {\n if (!isAddress(address, {strict: false})) throw new Error(`symbiosis: not a 20-byte address: ${address}`);\n const body = new Uint8Array(21);\n body[0] = 0x41;\n const raw = address.slice(2);\n for (let i = 0; i < 20; i++) body[i + 1] = parseInt(raw.slice(i * 2, i * 2 + 2), 16);\n const out = new Uint8Array(25);\n out.set(body);\n out.set(sha256(sha256(body)).subarray(0, 4), 21);\n return base58.encode(out);\n}\n\n/**\n * The 20 bytes an account or contract is named by inside Symbiosis calldata, lowercase hex with\n * `0x`: an EVM address as it is, a Tron address without its 0x41 prefix. Null for another family\n * or a malformed address.\n */\nexport function account20(chain: SymbiosisChain, address: string): string | null {\n if (chain.family === \"evm\") return typeof address === \"string\" && isAddress(address) ? address.toLowerCase() : null;\n if (chain.family === \"tron\") return tronToEvm(address)?.toLowerCase() ?? null;\n return null;\n}\n\n/** Whether `address` is a well-formed address of the chain's family (EVM hex with a valid checksum, Tron base58check, TON workchain 0). */\nexport function validAddress(chain: SymbiosisChain, address: string): boolean {\n if (typeof address !== \"string\" || address.length === 0 || address.length > 128) return false;\n if (chain.family === \"evm\") return isAddress(address) && !/^0x0{40}$/i.test(address);\n if (chain.family === \"tron\") return tronToEvm(address) !== null;\n if (chain.family === \"ton\") return (tonRawAddress(address) ?? \"\").startsWith(\"0:\");\n // bech32 / bech32m / base58 — only the shape; a Bitcoin address is never a destination here.\n return /^(bc1[02-9ac-hj-np-z]{11,71}|[13][1-9A-HJ-NP-Za-km-z]{25,34})$/.test(address);\n}\n\n/**\n * How Symbiosis names a token: EVM contracts as they are, Tron contracts in 20-byte form, a TON\n * jetton by the last 20 bytes of its master's hash plus the master itself in `attributes.ton`\n * (the rule their token list follows for every TON entry), the native coin as an empty string.\n */\nexport function symbiosisToken(chain: SymbiosisChain, contract: string | null | undefined): {address: string; ton?: string} | null {\n if (!contract) return {address: \"\"};\n if (chain.family === \"evm\") return isAddress(contract) ? {address: getAddress(contract)} : null;\n if (chain.family === \"tron\") { const a = tronToEvm(contract); return a ? {address: a.toLowerCase()} : null; }\n if (chain.family === \"ton\") {\n const raw = tonRawAddress(contract);\n if (!raw || !raw.startsWith(\"0:\")) return null;\n return {address: getAddress(`0x${raw.slice(-40)}`), ton: contract};\n }\n return null;\n}\n\nexport const symbiosis = Object.freeze({\n /** A chain this module knows (as a source or a destination). */\n supportsChain: (caip2: string): boolean => symbiosisChain(caip2) !== undefined,\n /** Two different chains this module knows; Bitcoin is never a destination. */\n supports(fromChain: string, toChain: string): boolean {\n const a = symbiosisChain(fromChain);\n const b = symbiosisChain(toChain);\n return !!a && !!b && a !== b && b.family !== \"bitcoin\";\n },\n});\n\n/** The gateway of a chain in the spelling a wallet of that family uses (EVM checksum / Tron base58). */\nexport function gatewayAddress(chain: SymbiosisChain): string | null {\n if (!chain.gateway) return null;\n return chain.family === \"tron\" ? evmToTron(chain.gateway) : getAddress(chain.gateway);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,sBA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W,KAAK,IAAI,KAAK;AAAE,YAAM,UAAM,4BAAc,CAAC;AAAG,UAAI,IAAK,KAAI,IAAI,GAAG;AAAA,IAAG;AAChF,UAAM,OAAO,GAAG,UAAU,KAAK,CAAC,MAAM,EAAE,UAAU,YAAQ,4BAAc,EAAE,EAAE,MAAM,4BAA4B,IAAI,QAAI,4BAAc,EAAE,IAAI,KAAK,EAAE,CAAC;AAClJ,QAAI,CAAC,KAAM,QAAO;AAClB,eAAO,kCAAiB,IAAI,KAAK,EAAC,UAAU,kBAAkB,UAAU,MAAM,UAAU,SAAS,UAAS,CAAC;AAAA,EAC7G;AACA,SAAO;AACT;","names":["import_util"]}
@@ -0,0 +1,17 @@
1
+ import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
2
+
3
+ /**
4
+ * Activity recognition for Symbiosis source transactions:
5
+ * - EVM and Tron: `metaRoute` on the chain's pinned MetaRouterGateway — the one call every source
6
+ * transaction of this module is ("Bridged USDT");
7
+ * - TON: a jetton transfer from the owner to the pinned TON Portal.
8
+ * The delivery on the destination chain is a relayer's transaction the user signs nothing in; it is
9
+ * left to the wallet's plain "received" item.
10
+ */
11
+
12
+ declare const SYMBIOSIS_MODULE = "@anywalletkit/protocol-swap2-symbiosis";
13
+ /** `metaRoute((bytes,bytes,address[],address,address,uint256,bool,address,bytes))` — MetaRouterGateway. */
14
+ declare const SYMBIOSIS_META_ROUTE = "0xa11b1198";
15
+ declare function describeSymbiosisActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
16
+
17
+ export { SYMBIOSIS_META_ROUTE, SYMBIOSIS_MODULE, describeSymbiosisActivity };