@anywalletkit/protocol-swap2-fynd 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +55 -2
- package/dist/activity.cjs +72 -0
- package/dist/activity.cjs.map +1 -0
- package/dist/activity.d.cts +12 -0
- package/dist/activity.d.ts +12 -0
- package/dist/activity.js +10 -0
- package/dist/activity.js.map +1 -0
- package/dist/chunk-CLS6UJ7V.js +228 -0
- package/dist/chunk-CLS6UJ7V.js.map +1 -0
- package/dist/chunk-F5P3PLJN.js +95 -0
- package/dist/chunk-F5P3PLJN.js.map +1 -0
- package/dist/chunk-MS3I524D.js +32 -0
- package/dist/chunk-MS3I524D.js.map +1 -0
- package/dist/chunk-WVX55NNY.js +22 -0
- package/dist/chunk-WVX55NNY.js.map +1 -0
- package/dist/index.cjs +375 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/protocol.cjs +364 -0
- package/dist/protocol.cjs.map +1 -0
- package/dist/protocol.d.cts +17 -0
- package/dist/protocol.d.ts +17 -0
- package/dist/protocol.js +10 -0
- package/dist/protocol.js.map +1 -0
- package/dist/provider.cjs +342 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.cts +29 -0
- package/dist/provider.d.ts +29 -0
- package/dist/provider.js +11 -0
- package/dist/provider.js.map +1 -0
- package/dist/router.cjs +115 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +185 -0
- package/dist/router.d.ts +185 -0
- package/dist/router.js +17 -0
- package/dist/router.js.map +1 -0
- package/module.json +22 -0
- package/package.json +83 -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,56 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @anywalletkit/protocol-swap2-fynd
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Fynd](https://docs.fynd.xyz) — Propeller Heads' DEX aggregator — as a same-chain swap2 provider for Any Wallet Kit. Exact-input swaps on Ethereum, Base, Arbitrum, BNB Chain, Polygon, Unichain and Robinhood Chain, routed over the pools Tycho indexes.
|
|
4
|
+
|
|
5
|
+
> **Fynd License.** Quotes, routes and transactions produced by Fynd are licensed under the [Fynd License](https://github.com/propeller-heads/fynd/blob/main/LICENSE.md). In short:
|
|
6
|
+
> - every swap built from a Fynd quote must settle through the Tycho router for its chain (the [router registry](https://docs.propellerheads.xyz/tycho/for-solvers/execution/contract-addresses)), with its fees intact, and must not be re-routed around it;
|
|
7
|
+
> - the router may take a platform fee and keeps positive slippage;
|
|
8
|
+
> - if you earn revenue on such swaps (your own fees, spreads), Propeller Heads is owed a share of it, with reporting.
|
|
9
|
+
>
|
|
10
|
+
> This module only ever sends the router transaction Fynd encoded. Read the license before you ship it.
|
|
11
|
+
|
|
12
|
+
## What the module checks
|
|
13
|
+
|
|
14
|
+
Before anything is approved or signed, the encoded transaction is decoded and checked against the request:
|
|
15
|
+
- it targets the pinned TychoRouterV3 for that chain;
|
|
16
|
+
- the method is a plain `singleSwap`, `sequentialSwap` or `splitSwap` (no Permit2, no vault funds);
|
|
17
|
+
- it spends exactly the requested amount of the requested token, for the requested output token;
|
|
18
|
+
- it pays the user, not anyone else;
|
|
19
|
+
- the expected output and the minimum match the quote, and Fynd's fee breakdown adds up;
|
|
20
|
+
- it carries no client fee.
|
|
21
|
+
|
|
22
|
+
The router reverts below the minimum. With `rpcUrls` set, the exact transaction is also simulated: at quote time for native input (no allowance needed), and right before broadcast for every swap.
|
|
23
|
+
|
|
24
|
+
**Why `uniswap_v4_hooks` is excluded by default.** On 2026-10-24 every Ethereum route the hosted API built through Uniswap v4 hook pools was quoted about 0.6–1% above the market and reverted when simulated (4 of 4 native-input pairs, and USDT → USDC). The same pairs without those pools executed (8 of 8 across Ethereum, Base and Arbitrum). A route through an excluded family is refused even if the server returns one. The hosted API has neither its own simulation nor its price guard enabled, so these checks are the wallet's.
|
|
25
|
+
|
|
26
|
+
## Configure
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { fyndProvider } from '@anywalletkit/protocol-swap2-fynd'
|
|
30
|
+
|
|
31
|
+
const fynd = fyndProvider({
|
|
32
|
+
apiKey: process.env.FYND_API_KEY, // hosted API; keep it on your server (remoteProvider)
|
|
33
|
+
// selfHosted: { 8453: 'https://fynd-base.internal' }, // or your own `fynd serve` per chain
|
|
34
|
+
rpcUrls: { 8453: ['https://base.example/rpc'] }, // optional: pre-broadcast simulation + receipts
|
|
35
|
+
})
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
| Option | Default | Meaning |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| `apiKey` | none | Hosted API key from Propeller Heads, sent as the raw `Authorization` header. |
|
|
41
|
+
| `baseUrl` | `https://fynd-api.propellerheads.xyz` | Hosted API; requests go to `{baseUrl}/v1/{chain}/quote`. |
|
|
42
|
+
| `selfHosted` | none | `{ chainId: url }` — your own Fynd servers; requests go to `{url}/v1/quote`, without a key. |
|
|
43
|
+
| `rpcUrls` | none | `{ chainId: [url…] }` for simulation and receipts. |
|
|
44
|
+
| `defaultSlippageBps` | `50` | Used when the caller passes none. |
|
|
45
|
+
| `quoteTtlMs` | `30000` | Fynd prices at one block; the engine re-checks this before broadcast. |
|
|
46
|
+
| `excludeProtocols` | `["uniswap_v4_hooks"]` | Liquidity Fynd must not route through (names, or family prefixes ending in `:`). |
|
|
47
|
+
|
|
48
|
+
A chain is served when it has a self-hosted server or the hosted API key is set.
|
|
49
|
+
|
|
50
|
+
## Not supported (yet)
|
|
51
|
+
|
|
52
|
+
- Exact-output swaps — Fynd only sells an exact input.
|
|
53
|
+
- A swap deadline. The router enforces a deadline only through a signed client-fee message; this module sends no client-fee parameters, so the on-chain protection is the minimum output.
|
|
54
|
+
- Integrator fees.
|
|
55
|
+
|
|
56
|
+
Apache-2.0 (this module's code). Fynd outputs: the Fynd License.
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
FYND_MODULE: () => FYND_MODULE,
|
|
24
|
+
describeFyndActivity: () => describeFyndActivity
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(activity_exports);
|
|
27
|
+
var import_activity = require("@anywalletkit/protocol-swap2-core/activity");
|
|
28
|
+
var import_util = require("@anywalletkit/protocol-swap2-core/util");
|
|
29
|
+
|
|
30
|
+
// src/router.ts
|
|
31
|
+
var import_viem = require("viem");
|
|
32
|
+
var FYND_CHAINS = Object.freeze({
|
|
33
|
+
1: { slug: "ethereum", name: "Ethereum", router: "0x1644D2477f809cc2C71bCCFd6Dc9497E3F83210d" },
|
|
34
|
+
8453: { slug: "base", name: "Base", router: "0xAbA5B53b03eAfaD1C5fc8BD5Fc765fC85Bb3de67" },
|
|
35
|
+
42161: { slug: "arbitrum", name: "Arbitrum", router: "0x924F147c50eA59f5180a26031A8b65B2aA1e81Cd" },
|
|
36
|
+
56: { slug: "bsc", name: "BNB Smart Chain", router: "0x7f3D12BBaFb8955E51B3ab9588b34c8ad95BDA4e" },
|
|
37
|
+
137: { slug: "polygon", name: "Polygon", router: "0xbd4e6011F03355C2A377Fd9Af939322A7d0A1bC1" },
|
|
38
|
+
130: { slug: "unichain", name: "Unichain", router: "0xCba5574597Ad00EA250Fd106DAB4Fc7461949635" },
|
|
39
|
+
4663: { slug: "robinhood", name: "Robinhood Chain", router: "0x09215a470bD585E59EB3F4B612fBD2678131fF9e" }
|
|
40
|
+
});
|
|
41
|
+
var PARAMS = "uint256 amountIn, address tokenIn, address tokenOut, uint256 expectedAmountOut, uint256 minAmountOut";
|
|
42
|
+
var FEE = "(uint32 clientFeeBps, address clientFeeReceiver, uint256 maxClientContribution, uint256 deadline, bytes clientSignature) clientFeeParams";
|
|
43
|
+
var PERMIT = "((address token, uint160 amount, uint48 expiration, uint48 nonce) details, address spender, uint256 sigDeadline) permitSingle, bytes signature";
|
|
44
|
+
var TYCHO_ROUTER_ABI = (0, import_viem.parseAbi)([
|
|
45
|
+
`function singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData) payable returns (uint256)`,
|
|
46
|
+
`function sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`,
|
|
47
|
+
`function splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`
|
|
48
|
+
]);
|
|
49
|
+
var TYCHO_ROUTER_SELECTORS = new Set(
|
|
50
|
+
[
|
|
51
|
+
`singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,
|
|
52
|
+
`sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,
|
|
53
|
+
`splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,
|
|
54
|
+
`singleSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,
|
|
55
|
+
`sequentialSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,
|
|
56
|
+
`splitSwapUsingVault(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,
|
|
57
|
+
`singleSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swapData)`,
|
|
58
|
+
`sequentialSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`,
|
|
59
|
+
`splitSwapPermit2(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`
|
|
60
|
+
].map((sig) => (0, import_viem.toFunctionSelector)(`function ${sig}`))
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// src/activity.ts
|
|
64
|
+
var FYND_MODULE = "@anywalletkit/protocol-swap2-fynd";
|
|
65
|
+
function describeFyndActivity(tx, ctx) {
|
|
66
|
+
if (!(0, import_util.isEvm)(tx.chain)) return null;
|
|
67
|
+
const chain = FYND_CHAINS[(0, import_util.evmRef)(tx.chain)];
|
|
68
|
+
if (!chain) return null;
|
|
69
|
+
if (!(0, import_activity.matchesCall)(tx, [chain.router], TYCHO_ROUTER_SELECTORS)) return null;
|
|
70
|
+
return (0, import_activity.describeSwapLike)(tx, ctx, { protocol: FYND_MODULE, subtitle: `Fynd \xB7 ${(0, import_activity.chainLabel)(tx.chain)}`, kind: "swap" });
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=activity.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/activity.ts","../src/router.ts"],"sourcesContent":["/**\n * Activity recognition for Fynd: a swap entry point of the pinned\n * TychoRouterV3 on a chain the module serves → `swap`, \"Swapped A → B\" from\n * the owner's net transfers.\n */\nimport type {ActivityItem, ChainTx, DescribeActivityContext} from \"@anywalletkit/core\";\nimport {chainLabel, describeSwapLike, matchesCall} from \"@anywalletkit/protocol-swap2-core/activity\";\nimport {evmRef, isEvm} from \"@anywalletkit/protocol-swap2-core/util\";\nimport {FYND_CHAINS, TYCHO_ROUTER_SELECTORS} from \"./router.js\";\n\nexport const FYND_MODULE = \"@anywalletkit/protocol-swap2-fynd\";\n\nexport function describeFyndActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null {\n if (!isEvm(tx.chain)) return null;\n const chain = FYND_CHAINS[evmRef(tx.chain)];\n if (!chain) return null;\n if (!matchesCall(tx, [chain.router], TYCHO_ROUTER_SELECTORS)) return null;\n return describeSwapLike(tx, ctx, {protocol: FYND_MODULE, subtitle: `Fynd · ${chainLabel(tx.chain)}`, kind: \"swap\"});\n}\n","/**\n * TychoRouterV3 — the only contract a Fynd quote may settle through (Fynd\n * License §3: every settlement of a Fynd output goes through the router in\n * Propeller Heads' registry). This file pins the router per chain and checks\n * Fynd's encoded transaction against the request before anything is approved\n * or sent: right contract, right method, the exact input, the requested\n * tokens, the user as receiver, the quoted output and minimum, and no client\n * fee. The route inside `swaps` is opaque and is not inspected here — the\n * router itself reverts below `minAmountOut`.\n */\nimport {decodeFunctionData, getAddress, parseAbi, toFunctionSelector, type Hex} from \"viem\";\n\n/** Router registry: github.com/propeller-heads/tycho crates/tycho-execution/config/deployment_registry.json (TychoRouterV3, effective 2026-09-01). */\nexport const FYND_CHAINS: Readonly<Record<number, {slug: string; name: string; router: `0x${string}`}>> = Object.freeze({\n 1: {slug: \"ethereum\", name: \"Ethereum\", router: \"0x1644D2477f809cc2C71bCCFd6Dc9497E3F83210d\"},\n 8453: {slug: \"base\", name: \"Base\", router: \"0xAbA5B53b03eAfaD1C5fc8BD5Fc765fC85Bb3de67\"},\n 42161: {slug: \"arbitrum\", name: \"Arbitrum\", router: \"0x924F147c50eA59f5180a26031A8b65B2aA1e81Cd\"},\n 56: {slug: \"bsc\", name: \"BNB Smart Chain\", router: \"0x7f3D12BBaFb8955E51B3ab9588b34c8ad95BDA4e\"},\n 137: {slug: \"polygon\", name: \"Polygon\", router: \"0xbd4e6011F03355C2A377Fd9Af939322A7d0A1bC1\"},\n 130: {slug: \"unichain\", name: \"Unichain\", router: \"0xCba5574597Ad00EA250Fd106DAB4Fc7461949635\"},\n 4663: {slug: \"robinhood\", name: \"Robinhood Chain\", router: \"0x09215a470bD585E59EB3F4B612fBD2678131fF9e\"},\n});\n\n/** The router's native-coin sentinel (lib/NativeETH.sol); Fynd's API uses the zero address instead. */\nexport const ROUTER_NATIVE = \"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE\";\nconst ZERO = \"0x0000000000000000000000000000000000000000\";\n\nconst PARAMS = \"uint256 amountIn, address tokenIn, address tokenOut, uint256 expectedAmountOut, uint256 minAmountOut\";\nconst FEE = \"(uint32 clientFeeBps, address clientFeeReceiver, uint256 maxClientContribution, uint256 deadline, bytes clientSignature) clientFeeParams\";\nconst PERMIT = \"((address token, uint160 amount, uint48 expiration, uint48 nonce) details, address spender, uint256 sigDeadline) permitSingle, bytes signature\";\n\n/** The three entry points a wallet swap uses (plain `transferFrom` from the user). */\nexport const TYCHO_ROUTER_ABI = parseAbi([\n `function singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData) payable returns (uint256)`,\n `function sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`,\n `function splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps) payable returns (uint256)`,\n]);\n\n/** Every swap entry point of the router (Permit2 and vault variants included) — for recognizing history. */\nexport const TYCHO_ROUTER_SELECTORS: ReadonlySet<string> = new Set(\n [\n `singleSwap(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,\n `sequentialSwap(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,\n `splitSwap(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,\n `singleSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swapData)`,\n `sequentialSwapUsingVault(${PARAMS}, address receiver, ${FEE}, bytes swaps)`,\n `splitSwapUsingVault(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, bytes swaps)`,\n `singleSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swapData)`,\n `sequentialSwapPermit2(${PARAMS}, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`,\n `splitSwapPermit2(${PARAMS}, uint256 nTokens, address receiver, ${FEE}, ${PERMIT}, bytes swaps)`,\n ].map((sig) => toFunctionSelector(`function ${sig}`)),\n);\n\nexport class FyndTransactionError extends Error {\n constructor(message: string) {\n super(`fynd: ${message}`);\n this.name = \"FyndTransactionError\";\n }\n}\n\nexport interface ExpectedSwap {\n chainId: number;\n /** ERC-20 address, or the zero address for the native coin. */\n tokenIn: string;\n tokenOut: string;\n amountIn: bigint;\n receiver: string;\n /** Fynd's gross `amount_out` (before the router fee and slippage). */\n expectedAmountOut: bigint;\n /** Fynd's `min_amount_received` — what the router enforces on-chain. */\n minAmountOut: bigint;\n}\n\nexport interface EncodedTx {\n to: string;\n value: bigint;\n data: string;\n}\n\nconst sameAddress = (a: string, b: string) => {\n try {\n return getAddress(a) === getAddress(b);\n } catch {\n return false;\n }\n};\nconst routerToken = (t: string) => (sameAddress(t, ZERO) ? ROUTER_NATIVE : t);\n\n/** Refuses (throws {@link FyndTransactionError}) unless `tx` is exactly the swap the wallet asked for. */\nexport function checkFyndTransaction(tx: EncodedTx, expected: ExpectedSwap): {method: \"singleSwap\" | \"sequentialSwap\" | \"splitSwap\"} {\n const chain = FYND_CHAINS[expected.chainId];\n if (!chain) throw new FyndTransactionError(`chain ${expected.chainId} has no pinned Tycho router`);\n if (!sameAddress(tx.to, chain.router)) throw new FyndTransactionError(`the transaction targets ${tx.to}, not the Tycho router on ${chain.name}`);\n if (sameAddress(expected.receiver, ZERO) || sameAddress(expected.receiver, chain.router)) throw new FyndTransactionError(\"invalid receiver\");\n if (expected.amountIn <= 0n || expected.minAmountOut <= 0n || expected.minAmountOut > expected.expectedAmountOut) {\n throw new FyndTransactionError(\"invalid quote amounts\");\n }\n const nativeIn = sameAddress(expected.tokenIn, ZERO);\n if (tx.value !== (nativeIn ? expected.amountIn : 0n)) throw new FyndTransactionError(\"native value does not match the input\");\n if (!/^0x(?:[0-9a-fA-F]{2}){4,}$/.test(tx.data)) throw new FyndTransactionError(\"malformed calldata\");\n\n let call: ReturnType<typeof decodeFunctionData<typeof TYCHO_ROUTER_ABI>>;\n try {\n call = decodeFunctionData({abi: TYCHO_ROUTER_ABI, data: tx.data as Hex});\n } catch {\n throw new FyndTransactionError(\"not a plain singleSwap / sequentialSwap / splitSwap call (Permit2 and vault variants are not used)\");\n }\n const a = call.args;\n const [amountIn, tokenIn, tokenOut, expectedAmountOut, minAmountOut] = a;\n const isSplit = call.functionName === \"splitSwap\";\n const receiver = (isSplit ? a[6] : a[5]) as string;\n const fee = (isSplit ? a[7] : a[6]) as {clientFeeBps: number; clientFeeReceiver: string; maxClientContribution: bigint; deadline: bigint; clientSignature: string};\n const swaps = (isSplit ? a[8] : a[7]) as string;\n if (amountIn !== expected.amountIn) throw new FyndTransactionError(`calldata spends ${amountIn}, not ${expected.amountIn}`);\n if (!sameAddress(tokenIn, routerToken(expected.tokenIn)) || !sameAddress(tokenOut, routerToken(expected.tokenOut))) {\n throw new FyndTransactionError(\"calldata swaps other tokens than requested\");\n }\n if (!sameAddress(receiver, expected.receiver)) throw new FyndTransactionError(`calldata pays ${receiver}, not ${expected.receiver}`);\n if (expectedAmountOut !== expected.expectedAmountOut || minAmountOut !== expected.minAmountOut) {\n throw new FyndTransactionError(\"calldata amounts do not match the quote\");\n }\n if (fee.clientFeeBps !== 0 || fee.maxClientContribution !== 0n || !sameAddress(fee.clientFeeReceiver, ZERO)) {\n throw new FyndTransactionError(\"calldata carries client-fee parameters — this module charges none\");\n }\n if (swaps === \"0x\" || (isSplit && (a[5] as bigint) < 2n)) throw new FyndTransactionError(\"empty or invalid route\");\n return {method: call.functionName};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,sBAAwD;AACxD,kBAA4B;;;ACG5B,kBAAqF;AAG9E,IAAM,cAA6F,OAAO,OAAO;AAAA,EACtH,GAAG,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAC5F,MAAM,EAAC,MAAM,QAAQ,MAAM,QAAQ,QAAQ,6CAA4C;AAAA,EACvF,OAAO,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAChG,IAAI,EAAC,MAAM,OAAO,MAAM,mBAAmB,QAAQ,6CAA4C;AAAA,EAC/F,KAAK,EAAC,MAAM,WAAW,MAAM,WAAW,QAAQ,6CAA4C;AAAA,EAC5F,KAAK,EAAC,MAAM,YAAY,MAAM,YAAY,QAAQ,6CAA4C;AAAA,EAC9F,MAAM,EAAC,MAAM,aAAa,MAAM,mBAAmB,QAAQ,6CAA4C;AACzG,CAAC;AAMD,IAAM,SAAS;AACf,IAAM,MAAM;AACZ,IAAM,SAAS;AAGR,IAAM,uBAAmB,sBAAS;AAAA,EACvC,uBAAuB,MAAM,uBAAuB,GAAG;AAAA,EACvD,2BAA2B,MAAM,uBAAuB,GAAG;AAAA,EAC3D,sBAAsB,MAAM,wCAAwC,GAAG;AACzE,CAAC;AAGM,IAAM,yBAA8C,IAAI;AAAA,EAC7D;AAAA,IACE,cAAc,MAAM,uBAAuB,GAAG;AAAA,IAC9C,kBAAkB,MAAM,uBAAuB,GAAG;AAAA,IAClD,aAAa,MAAM,wCAAwC,GAAG;AAAA,IAC9D,wBAAwB,MAAM,uBAAuB,GAAG;AAAA,IACxD,4BAA4B,MAAM,uBAAuB,GAAG;AAAA,IAC5D,uBAAuB,MAAM,wCAAwC,GAAG;AAAA,IACxE,qBAAqB,MAAM,uBAAuB,GAAG,KAAK,MAAM;AAAA,IAChE,yBAAyB,MAAM,uBAAuB,GAAG,KAAK,MAAM;AAAA,IACpE,oBAAoB,MAAM,wCAAwC,GAAG,KAAK,MAAM;AAAA,EAClF,EAAE,IAAI,CAAC,YAAQ,gCAAmB,YAAY,GAAG,EAAE,CAAC;AACtD;;;ADzCO,IAAM,cAAc;AAEpB,SAAS,qBAAqB,IAAa,KAAmD;AACnG,MAAI,KAAC,mBAAM,GAAG,KAAK,EAAG,QAAO;AAC7B,QAAM,QAAQ,gBAAY,oBAAO,GAAG,KAAK,CAAC;AAC1C,MAAI,CAAC,MAAO,QAAO;AACnB,MAAI,KAAC,6BAAY,IAAI,CAAC,MAAM,MAAM,GAAG,sBAAsB,EAAG,QAAO;AACrE,aAAO,kCAAiB,IAAI,KAAK,EAAC,UAAU,aAAa,UAAU,iBAAU,4BAAW,GAAG,KAAK,CAAC,IAAI,MAAM,OAAM,CAAC;AACpH;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Activity recognition for Fynd: a swap entry point of the pinned
|
|
5
|
+
* TychoRouterV3 on a chain the module serves → `swap`, "Swapped A → B" from
|
|
6
|
+
* the owner's net transfers.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const FYND_MODULE = "@anywalletkit/protocol-swap2-fynd";
|
|
10
|
+
declare function describeFyndActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
|
|
11
|
+
|
|
12
|
+
export { FYND_MODULE, describeFyndActivity };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChainTx, DescribeActivityContext, ActivityItem } from '@anywalletkit/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Activity recognition for Fynd: a swap entry point of the pinned
|
|
5
|
+
* TychoRouterV3 on a chain the module serves → `swap`, "Swapped A → B" from
|
|
6
|
+
* the owner's net transfers.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare const FYND_MODULE = "@anywalletkit/protocol-swap2-fynd";
|
|
10
|
+
declare function describeFyndActivity(tx: ChainTx, ctx: DescribeActivityContext): ActivityItem | null;
|
|
11
|
+
|
|
12
|
+
export { FYND_MODULE, describeFyndActivity };
|
package/dist/activity.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
describeFyndActivity
|
|
3
|
+
} from "./chunk-WVX55NNY.js";
|
|
4
|
+
import {
|
|
5
|
+
FYND_CHAINS,
|
|
6
|
+
checkFyndTransaction
|
|
7
|
+
} from "./chunk-F5P3PLJN.js";
|
|
8
|
+
|
|
9
|
+
// src/provider.ts
|
|
10
|
+
import { getAddress } from "viem";
|
|
11
|
+
import { ccAsset } from "@anywalletkit/swap2-assets";
|
|
12
|
+
import { evmRef, isEvm, timeoutSignal } from "@anywalletkit/protocol-swap2-core/util";
|
|
13
|
+
var ZERO = "0x0000000000000000000000000000000000000000";
|
|
14
|
+
var DEFAULT_BASE_URL = "https://fynd-api.propellerheads.xyz";
|
|
15
|
+
var DEFAULT_SLIPPAGE_BPS = 50;
|
|
16
|
+
var DEFAULT_TTL_MS = 3e4;
|
|
17
|
+
var FYND_DEFAULT_EXCLUDED_PROTOCOLS = Object.freeze(["uniswap_v4_hooks"]);
|
|
18
|
+
var QUOTE_FAILURES = {
|
|
19
|
+
no_route_found: "no route for this pair",
|
|
20
|
+
insufficient_liquidity: "not enough liquidity for this amount",
|
|
21
|
+
timeout: "the solver timed out",
|
|
22
|
+
not_ready: "the solver is still syncing",
|
|
23
|
+
price_check_failed: "the price guard rejected the route",
|
|
24
|
+
encoding_failed: "could not encode the swap (fees + slippage leave nothing)"
|
|
25
|
+
};
|
|
26
|
+
var uint = (v) => typeof v === "string" && /^\d+$/.test(v) ? BigInt(v) : null;
|
|
27
|
+
function fyndProvider(config) {
|
|
28
|
+
const baseUrl = (config.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
29
|
+
const slippageDefault = config.defaultSlippageBps ?? DEFAULT_SLIPPAGE_BPS;
|
|
30
|
+
const ttl = config.quoteTtlMs ?? DEFAULT_TTL_MS;
|
|
31
|
+
const timeoutMs = config.timeoutMs ?? 1e4;
|
|
32
|
+
const excluded = [...config.excludeProtocols ?? FYND_DEFAULT_EXCLUDED_PROTOCOLS];
|
|
33
|
+
const isExcluded = (protocol) => excluded.some((x) => x.endsWith(":") ? protocol.startsWith(x) : protocol === x);
|
|
34
|
+
const endpoint = (chainId) => {
|
|
35
|
+
const chain = FYND_CHAINS[chainId];
|
|
36
|
+
if (!chain) return null;
|
|
37
|
+
const own = config.selfHosted?.[chainId];
|
|
38
|
+
if (own) return { url: `${own.replace(/\/+$/, "")}/v1/quote`, headers: {} };
|
|
39
|
+
if (!config.apiKey) return null;
|
|
40
|
+
return { url: `${baseUrl}/v1/${chain.slug}/quote`, headers: { authorization: config.apiKey } };
|
|
41
|
+
};
|
|
42
|
+
const chainIdOf = (caip2) => {
|
|
43
|
+
if (!isEvm(caip2)) return null;
|
|
44
|
+
const id = evmRef(caip2);
|
|
45
|
+
return endpoint(id) ? id : null;
|
|
46
|
+
};
|
|
47
|
+
async function rpc(chainId, method, params) {
|
|
48
|
+
let lastErr;
|
|
49
|
+
for (const url of config.rpcUrls?.[chainId] ?? []) {
|
|
50
|
+
try {
|
|
51
|
+
const res = await fetch(url, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method, params }), signal: timeoutSignal(12e3) });
|
|
52
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
53
|
+
const body = await res.json();
|
|
54
|
+
if (body.error) throw Object.assign(new Error(body.error.message ?? "rpc error"), { rpc: true });
|
|
55
|
+
return body.result ?? null;
|
|
56
|
+
} catch (e) {
|
|
57
|
+
if (e.rpc) throw e;
|
|
58
|
+
lastErr = e;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
throw new Error(`fynd: no RPC answered on chain ${chainId} (${lastErr instanceof Error ? lastErr.message : String(lastErr)})`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name: "fynd",
|
|
65
|
+
describeActivity: describeFyndActivity,
|
|
66
|
+
supportsSameChain: true,
|
|
67
|
+
enabled: () => config.enabled ?? true,
|
|
68
|
+
supportsChain: (caip2) => chainIdOf(caip2) !== null,
|
|
69
|
+
supportsChainPair: (from, to) => from === to && chainIdOf(from) !== null,
|
|
70
|
+
supportsRoute: (from, to) => from.chain === to.chain && chainIdOf(from.chain) !== null,
|
|
71
|
+
async getQuote(params, signal) {
|
|
72
|
+
const refuse = (why) => {
|
|
73
|
+
params.onRefusal?.(`fynd: ${why}`);
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
if (params.flex) return refuse("amount-flexible deposits are not supported");
|
|
77
|
+
if (params.sourceChain !== params.destChain) return refuse("same-chain swaps only");
|
|
78
|
+
const chainId = chainIdOf(params.sourceChain);
|
|
79
|
+
if (chainId === null) return refuse(`Fynd is not configured for ${params.sourceChain}`);
|
|
80
|
+
const ep = endpoint(chainId);
|
|
81
|
+
const src = ccAsset(params.sourceChain, params.sourceToken);
|
|
82
|
+
if (!src) return refuse(`unknown source token ${params.sourceToken}`);
|
|
83
|
+
const tokenIn = src.contract ? getAddress(src.contract) : ZERO;
|
|
84
|
+
const nativeOut = /^0x0+$/.test(params.destToken);
|
|
85
|
+
if (!nativeOut && !/^0x[0-9a-fA-F]{40}$/.test(params.destToken)) return refuse("destination token must be an EVM address");
|
|
86
|
+
const tokenOut = nativeOut ? ZERO : getAddress(params.destToken);
|
|
87
|
+
if (tokenIn === tokenOut) return refuse("same token in and out");
|
|
88
|
+
if (!/^0x[0-9a-fA-F]{40}$/.test(params.destAddress)) return refuse("recipient must be an EVM address");
|
|
89
|
+
const receiver = getAddress(params.destAddress);
|
|
90
|
+
const sender = getAddress(params.refundAddress && /^0x[0-9a-fA-F]{40}$/.test(params.refundAddress) ? params.refundAddress : params.destAddress);
|
|
91
|
+
let amountIn;
|
|
92
|
+
try {
|
|
93
|
+
amountIn = BigInt(params.amountIn);
|
|
94
|
+
} catch {
|
|
95
|
+
return refuse("amount is not an integer");
|
|
96
|
+
}
|
|
97
|
+
if (amountIn <= 0n) return refuse("amount must be positive");
|
|
98
|
+
const bps = params.slippageBps ?? slippageDefault;
|
|
99
|
+
if (!Number.isInteger(bps) || bps <= 0 || bps >= 1e4) return refuse("invalid slippage");
|
|
100
|
+
const body = {
|
|
101
|
+
orders: [{ token_in: tokenIn, token_out: tokenOut, amount: amountIn.toString(), side: "sell", sender, receiver }],
|
|
102
|
+
options: {
|
|
103
|
+
timeout_ms: Math.min(timeoutMs, 8e3),
|
|
104
|
+
encoding_options: { slippage: (bps / 1e4).toString(), transfer_type: "transfer_from" },
|
|
105
|
+
...excluded.length ? { route_filter: { exclude_protocols: excluded } } : {}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
let res;
|
|
109
|
+
try {
|
|
110
|
+
res = await fetch(ep.url, { method: "POST", headers: { "content-type": "application/json", ...ep.headers }, body: JSON.stringify(body), signal: signal ?? timeoutSignal(timeoutMs) });
|
|
111
|
+
} catch (e) {
|
|
112
|
+
return refuse(`API unreachable (${e instanceof Error ? e.name : "error"})`);
|
|
113
|
+
}
|
|
114
|
+
if (res.status === 401 || res.status === 403) return refuse(`API key rejected (HTTP ${res.status})`);
|
|
115
|
+
if (res.status === 429) return refuse("rate limited (HTTP 429)");
|
|
116
|
+
if (res.status === 422) return refuse("no route for this pair");
|
|
117
|
+
if (!res.ok) return refuse(`API answered HTTP ${res.status}`);
|
|
118
|
+
let parsed;
|
|
119
|
+
try {
|
|
120
|
+
parsed = await res.json();
|
|
121
|
+
} catch {
|
|
122
|
+
return refuse("malformed API response");
|
|
123
|
+
}
|
|
124
|
+
if (!Array.isArray(parsed.orders) || parsed.orders.length !== 1) return refuse("malformed API response (order count)");
|
|
125
|
+
const q = parsed.orders[0];
|
|
126
|
+
if (q.status !== "success") return refuse(QUOTE_FAILURES[q.status ?? ""] ?? `quote status ${String(q.status).slice(0, 40)}`);
|
|
127
|
+
const quotedIn = uint(q.amount_in);
|
|
128
|
+
const gross = uint(q.amount_out);
|
|
129
|
+
const routerFee = uint(q.fee_breakdown?.router_fee);
|
|
130
|
+
const clientFee = uint(q.fee_breakdown?.client_fee);
|
|
131
|
+
const maxSlippage = uint(q.fee_breakdown?.max_slippage);
|
|
132
|
+
const minOut = uint(q.fee_breakdown?.min_amount_received);
|
|
133
|
+
const value = uint(q.transaction?.value ?? "");
|
|
134
|
+
if (quotedIn === null || gross === null || routerFee === null || clientFee === null || maxSlippage === null || minOut === null || value === null) {
|
|
135
|
+
return refuse("malformed quote amounts");
|
|
136
|
+
}
|
|
137
|
+
if (quotedIn !== amountIn) return refuse(`quoted ${quotedIn}, not the requested ${amountIn}`);
|
|
138
|
+
if (clientFee !== 0n) return refuse("the quote carries a client fee");
|
|
139
|
+
if (routerFee + clientFee + maxSlippage + minOut !== gross) return refuse("fee breakdown does not add up to the output");
|
|
140
|
+
if (params.minAmountOut !== void 0 && minOut < BigInt(params.minAmountOut)) return refuse(`floor breach (min=${minOut} < floor=${params.minAmountOut})`);
|
|
141
|
+
const tx = { to: q.transaction?.to ?? "", value, data: q.transaction?.data ?? "" };
|
|
142
|
+
try {
|
|
143
|
+
checkFyndTransaction(tx, { chainId, tokenIn, tokenOut, amountIn, receiver, expectedAmountOut: gross, minAmountOut: minOut });
|
|
144
|
+
} catch (e) {
|
|
145
|
+
return refuse(e instanceof Error ? e.message.replace(/^fynd: /, "") : String(e));
|
|
146
|
+
}
|
|
147
|
+
const allProtocols = [...new Set((q.route?.swaps ?? []).map((s) => s.protocol).filter((p) => typeof p === "string"))];
|
|
148
|
+
const banned = allProtocols.find(isExcluded);
|
|
149
|
+
if (banned) return refuse(`the route goes through ${banned}, which this wallet excludes`);
|
|
150
|
+
if (tokenIn === ZERO && config.rpcUrls?.[chainId]?.length) {
|
|
151
|
+
try {
|
|
152
|
+
await rpc(chainId, "eth_call", [{ from: sender, to: tx.to, data: tx.data, value: `0x${value.toString(16)}` }, "latest", { [sender]: { balance: `0x${(value + 10n ** 18n).toString(16)}` } }]);
|
|
153
|
+
} catch (e) {
|
|
154
|
+
if (e.rpc) return refuse(`the route does not execute on-chain right now (simulation reverted via ${allProtocols.join(", ") || "?"})`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const gas = uint(q.gas_estimate) ?? 0n;
|
|
158
|
+
const protocols = allProtocols.slice(0, 6);
|
|
159
|
+
return {
|
|
160
|
+
provider: "fynd",
|
|
161
|
+
intentId: `fynd:${chainId}`,
|
|
162
|
+
depositAddress: "",
|
|
163
|
+
depositMemo: null,
|
|
164
|
+
txRequest: {
|
|
165
|
+
to: getAddress(tx.to),
|
|
166
|
+
data: tx.data,
|
|
167
|
+
value: value.toString(),
|
|
168
|
+
chainId,
|
|
169
|
+
// the router's own overhead on top of Fynd's route estimate
|
|
170
|
+
gasLimit: (gas * 13n / 10n + 80000n).toString(),
|
|
171
|
+
...tokenIn === ZERO ? {} : { approvalAddress: getAddress(tx.to) }
|
|
172
|
+
},
|
|
173
|
+
sourceAmount: amountIn.toString(),
|
|
174
|
+
// what the receiver gets at the quoted price: gross minus the router fee
|
|
175
|
+
destAmount: (gross - routerFee).toString(),
|
|
176
|
+
minDestAmount: minOut.toString(),
|
|
177
|
+
feeUsd: 0,
|
|
178
|
+
etaSeconds: 15,
|
|
179
|
+
reliability: 0.96,
|
|
180
|
+
validUntilMs: Date.now() + ttl,
|
|
181
|
+
providerData: {
|
|
182
|
+
minOut: minOut.toString(),
|
|
183
|
+
sender,
|
|
184
|
+
routerFee: routerFee.toString(),
|
|
185
|
+
gross: gross.toString(),
|
|
186
|
+
protocols: protocols.join(","),
|
|
187
|
+
...typeof q.price_impact_bps === "number" ? { priceImpactBps: String(q.price_impact_bps) } : {}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
},
|
|
191
|
+
/** Simulate the exact transaction at the latest block (allowance already in place); refuse when it would revert. */
|
|
192
|
+
async preflightDeposit(quote, tx) {
|
|
193
|
+
const chainId = Number(quote.intentId.split(":")[1]);
|
|
194
|
+
const sender = quote.providerData?.sender;
|
|
195
|
+
if (!FYND_CHAINS[chainId] || !config.rpcUrls?.[chainId]?.length || !tx.data || !sender) return;
|
|
196
|
+
try {
|
|
197
|
+
await rpc(chainId, "eth_call", [{ from: sender, to: tx.to, data: tx.data, value: `0x${BigInt(tx.value || "0").toString(16)}` }, "latest"]);
|
|
198
|
+
} catch (e) {
|
|
199
|
+
if (e.rpc) {
|
|
200
|
+
throw new Error(`fynd: the swap would revert now (${e instanceof Error ? e.message.slice(0, 120) : "revert"}) \u2014 the price moved past your minimum. Nothing was sent; refresh the quote.`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
async buildDeposit(quote) {
|
|
205
|
+
const tx = quote.txRequest;
|
|
206
|
+
if (!tx?.to || !tx.data) throw new Error("swap2: Fynd quote has no transaction request");
|
|
207
|
+
return { chain: "", to: tx.to, value: tx.value ?? "0", data: tx.data, ...tx.chainId !== void 0 ? { chainId: tx.chainId } : {}, ...tx.gasLimit ? { gasLimit: tx.gasLimit } : {}, ...tx.approvalAddress ? { approvalAddress: tx.approvalAddress } : {} };
|
|
208
|
+
},
|
|
209
|
+
async trackIntent(ref) {
|
|
210
|
+
if (!ref.sourceTxHash) return { state: "pending" };
|
|
211
|
+
const chainId = Number(ref.intentId.split(":")[1]);
|
|
212
|
+
if (!FYND_CHAINS[chainId] || !config.rpcUrls?.[chainId]?.length) return { state: "pending" };
|
|
213
|
+
try {
|
|
214
|
+
const receipt = await rpc(chainId, "eth_getTransactionReceipt", [ref.sourceTxHash]);
|
|
215
|
+
if (!receipt) return { state: "pending" };
|
|
216
|
+
return receipt.status === "0x1" ? { state: "completed", destTxHash: ref.sourceTxHash } : { state: "failed" };
|
|
217
|
+
} catch {
|
|
218
|
+
return { state: "pending" };
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export {
|
|
225
|
+
FYND_DEFAULT_EXCLUDED_PROTOCOLS,
|
|
226
|
+
fyndProvider
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=chunk-CLS6UJ7V.js.map
|