hood-traders 0.1.0 → 0.2.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 +15 -196
- package/README.md +33 -8
- package/dist/{chunk-NXL2F7EP.js → chunk-YZJCP67J.js} +328 -1
- package/dist/chunk-YZJCP67J.js.map +1 -0
- package/dist/index.d.ts +111 -1
- package/dist/index.js +11 -1
- package/dist/main.js +20 -3
- package/dist/main.js.map +1 -1
- package/package.json +73 -73
- package/dist/chunk-NXL2F7EP.js.map +0 -1
package/LICENSE
CHANGED
|
@@ -1,201 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
1
|
+
Copyright 2026 nirholas
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
All rights reserved.
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
This software is proprietary and may not be used, copied, modified, distributed,
|
|
6
|
+
translated, or made available to any third party without the express written
|
|
7
|
+
permission of the copyright owner.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
No rights are granted by implication, estoppel, or otherwise. Use of this
|
|
10
|
+
software is subject to the terms of a separate license agreement with the
|
|
11
|
+
copyright owner.
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the
|
|
44
|
-
purposes of this License, Derivative Works shall not include works
|
|
45
|
-
that remain separable from, or merely link (or bind by name) to the
|
|
46
|
-
interfaces of, the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including the
|
|
49
|
-
original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|
|
177
|
-
|
|
178
|
-
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
-
|
|
180
|
-
To apply the Apache License to your work, attach the following
|
|
181
|
-
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
-
replaced with your own identifying information. (Don't include
|
|
183
|
-
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
-
comment syntax for the file format. We also recommend that a
|
|
185
|
-
file or class name and description of purpose be included on the
|
|
186
|
-
same "printed page" as the copyright notice for easier
|
|
187
|
-
identification within third-party archives.
|
|
188
|
-
|
|
189
|
-
Copyright 2026 nirholas
|
|
190
|
-
|
|
191
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
-
you may not use this file except in compliance with the License.
|
|
193
|
-
You may obtain a copy of the License at
|
|
194
|
-
|
|
195
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
-
|
|
197
|
-
Unless required by applicable law or agreed to in writing, software
|
|
198
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
-
See the License for the specific language governing permissions and
|
|
201
|
-
limitations under the License.
|
|
17
|
+
IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY CLAIM, DAMAGES, OR
|
|
18
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR OTHERWISE,
|
|
19
|
+
ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
20
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -26,8 +26,11 @@ drop-in change confined to `src/framework/market.ts`.
|
|
|
26
26
|
- **Framework** (`src/framework/`): agent = strategy + wallet + risk budget + journal. Every tick
|
|
27
27
|
runs observe → decide → simulate (a real Uniswap v3 `eth_call`) → risk-check (fail-closed) →
|
|
28
28
|
execute → journal.
|
|
29
|
-
- **
|
|
30
|
-
with an honestly documented edge hypothesis and failure modes (see
|
|
29
|
+
- **Four strategies** (`src/strategies/`): `launch-sniper`, `momentum`, `premium-watch`, and
|
|
30
|
+
`llm-strategist` — each with an honestly documented edge hypothesis and failure modes (see
|
|
31
|
+
[Strategies](#strategies)). `llm-strategist` is optional and bring-your-own-key: point it at
|
|
32
|
+
Claude, OpenAI, Groq, or OpenRouter and it judges launches the other strategies discover, using
|
|
33
|
+
the same real on-chain signals, subject to the exact same risk engine as everything else.
|
|
31
34
|
- **Live dashboard** (`dashboard/`): fleet overview, per-agent equity curve, open positions, the
|
|
32
35
|
full decision journal (why each trade fired — or didn't), and a kill button.
|
|
33
36
|
- **Risk layer** (`src/framework/risk.ts`): per-agent position cap, daily spend cap, fleet-wide
|
|
@@ -92,7 +95,7 @@ these tokenized debt securities (issuer: Robinhood Assets (Jersey) Ltd). Without
|
|
|
92
95
|
## Architecture
|
|
93
96
|
|
|
94
97
|
See [`docs/architecture.html`](docs/architecture.html) for the full observe → decide → simulate →
|
|
95
|
-
risk-check → execute → journal diagram, and how the
|
|
98
|
+
risk-check → execute → journal diagram, and how the four strategies plug into it. Short version:
|
|
96
99
|
|
|
97
100
|
```
|
|
98
101
|
Market (hoodchain SDK, live RPC)
|
|
@@ -122,10 +125,31 @@ Full docs with live examples: [`docs/strategies.html`](docs/strategies.html). Su
|
|
|
122
125
|
| `launch-sniper` | Opening-minutes volatility on new launches is real; discipline (round-trip + deployer-concentration filters, mechanical exits) harvests a slice of it. | Most new launches go to zero — the stop loss fires often; this is negative-carry unless winners cover losers. |
|
|
123
126
|
| `momentum` | Tokens that survive to graduation and then break out on price reflect real demand, not launch-day noise. | Breakouts on thin pools are trivially fakeable by one wallet; price-only signal has no depth check. |
|
|
124
127
|
| `premium-watch` | Stock Token pools are thin and drift from the Chainlink oracle; buying the discount captures reversion. **Alerts-only by default** — trading requires explicit eligibility + opt-in. | A premium/discount can be *correct* (DEX reacting to news the ≤24h Chainlink heartbeat hasn't caught yet); fading it loses on purpose. No shorting primitive exists. |
|
|
128
|
+
| `llm-strategist` | An LLM (bring your own key) weighs the same round-trip-retention and deployer-concentration signals `launch-sniper` checks mechanically, holistically instead of against fixed cutoffs, and only trades above a confidence threshold. **Disabled unless configured** — see below. | LLM confidence is not calibrated probability; a confidently wrong verdict trades identically to a confidently right one. On-chain data reaching the prompt is attacker-controlled, so the brief is numbers-only by design. One provider, no fallback. |
|
|
125
129
|
|
|
126
130
|
Every strategy exposes its `meta.edge` / `meta.failureModes` at runtime (`strategy.meta`) — the
|
|
127
131
|
dashboard and docs pull the live values, not a stale copy.
|
|
128
132
|
|
|
133
|
+
### `llm-strategist` setup
|
|
134
|
+
|
|
135
|
+
Disabled by default — the fleet runs the other three strategies with zero LLM config. To enable it,
|
|
136
|
+
set exactly one provider in `.env`:
|
|
137
|
+
|
|
138
|
+
```sh
|
|
139
|
+
# any ONE of:
|
|
140
|
+
HOOD_LLM_PROVIDER=anthropic HOOD_LLM_API_KEY=sk-ant-...
|
|
141
|
+
HOOD_LLM_PROVIDER=openai HOOD_LLM_API_KEY=sk-...
|
|
142
|
+
HOOD_LLM_PROVIDER=groq HOOD_LLM_API_KEY=gsk_...
|
|
143
|
+
HOOD_LLM_PROVIDER=openrouter HOOD_LLM_API_KEY=sk-or-...
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
`HOOD_LLM_MODEL` is optional — each provider has a sane default (see
|
|
147
|
+
[`src/framework/llm.ts`](src/framework/llm.ts)); set it if a default ever goes stale or you want a
|
|
148
|
+
stronger/cheaper model. `HOOD_LLM_MIN_CONFIDENCE` (default `0.6`) is the minimum LLM-stated
|
|
149
|
+
confidence required to actually place a trade — everything below that is logged to the decision
|
|
150
|
+
journal as an alert, not a trade. Every LLM API call costs money regardless of verdict; a launch
|
|
151
|
+
storm inflates spend with nothing to show for it if you set the confidence bar too low.
|
|
152
|
+
|
|
129
153
|
## Configuration
|
|
130
154
|
|
|
131
155
|
All of `.env.example` is optional for paper mode. Key knobs:
|
|
@@ -143,6 +167,11 @@ All of `.env.example` is optional for paper mode. Key knobs:
|
|
|
143
167
|
| `AGENT_COOLDOWN_SECONDS` | `60` | Minimum gap between an agent's trades |
|
|
144
168
|
| `KILL_FILE` | `./KILL` | Drop a file here to halt the fleet immediately |
|
|
145
169
|
| `DASHBOARD_PORT` | `4670` | Dashboard + API port |
|
|
170
|
+
| `HOOD_LLM_PROVIDER` | *(unset)* | `anthropic`\|`openai`\|`groq`\|`openrouter` — enables `llm-strategist` when set with `HOOD_LLM_API_KEY` |
|
|
171
|
+
| `HOOD_LLM_API_KEY` | *(unset)* | Your own key for the chosen provider |
|
|
172
|
+
| `HOOD_LLM_MODEL` | *(per-provider default)* | Override the model id |
|
|
173
|
+
| `HOOD_LLM_MIN_CONFIDENCE` | `0.6` | Minimum LLM confidence to trade, else it's alert-only |
|
|
174
|
+
| `HOOD_LLM_TIMEOUT_MS` | `9000` | Per-call timeout before the judge is treated as failed |
|
|
146
175
|
|
|
147
176
|
## Kill switch
|
|
148
177
|
|
|
@@ -207,8 +236,4 @@ always-on container host instead.
|
|
|
207
236
|
|
|
208
237
|
## License
|
|
209
238
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
---
|
|
213
|
-
|
|
214
|
-
Built by [nirholas](https://x.com/nichxbt) · [three.ws](https://three.ws)
|
|
239
|
+
All rights reserved. See [LICENSE](LICENSE).
|
|
@@ -891,6 +891,29 @@ function loadFleetConfig(env = process.env) {
|
|
|
891
891
|
}
|
|
892
892
|
};
|
|
893
893
|
}
|
|
894
|
+
var LLM_PROVIDERS = ["anthropic", "openai", "groq", "openrouter"];
|
|
895
|
+
function loadLlmConfig(env = process.env) {
|
|
896
|
+
const provider = env.HOOD_LLM_PROVIDER;
|
|
897
|
+
const apiKey = env.HOOD_LLM_API_KEY;
|
|
898
|
+
if (!provider && !apiKey) return null;
|
|
899
|
+
if (!provider || !apiKey) {
|
|
900
|
+
throw new Error(
|
|
901
|
+
"hood-traders config.ts: HOOD_LLM_PROVIDER and HOOD_LLM_API_KEY must both be set to enable llm-strategist (or both left unset to disable it)."
|
|
902
|
+
);
|
|
903
|
+
}
|
|
904
|
+
if (!LLM_PROVIDERS.includes(provider)) {
|
|
905
|
+
throw new Error(`hood-traders config.ts: HOOD_LLM_PROVIDER="${provider}" is not one of ${LLM_PROVIDERS.join(", ")}`);
|
|
906
|
+
}
|
|
907
|
+
return {
|
|
908
|
+
provider,
|
|
909
|
+
apiKey,
|
|
910
|
+
model: env.HOOD_LLM_MODEL || void 0,
|
|
911
|
+
timeoutMs: num("HOOD_LLM_TIMEOUT_MS", 9e3)
|
|
912
|
+
};
|
|
913
|
+
}
|
|
914
|
+
function loadLlmMinConfidence(env = process.env) {
|
|
915
|
+
return num("HOOD_LLM_MIN_CONFIDENCE", 0.6);
|
|
916
|
+
}
|
|
894
917
|
|
|
895
918
|
// src/strategies/launch-sniper.ts
|
|
896
919
|
import { erc20Abi, watchLaunches } from "hoodchain";
|
|
@@ -1287,6 +1310,305 @@ var PremiumWatch = class {
|
|
|
1287
1310
|
}
|
|
1288
1311
|
};
|
|
1289
1312
|
|
|
1313
|
+
// src/framework/llm.ts
|
|
1314
|
+
var DEFAULT_MODELS = {
|
|
1315
|
+
anthropic: "claude-haiku-4-5-20251001",
|
|
1316
|
+
openai: "gpt-4o-mini",
|
|
1317
|
+
groq: "llama-3.3-70b-versatile",
|
|
1318
|
+
openrouter: "openrouter/auto"
|
|
1319
|
+
};
|
|
1320
|
+
var SYSTEM_PROMPT = [
|
|
1321
|
+
"You are a risk-averse trading analyst judging a brand-new token launch on Robinhood Chain,",
|
|
1322
|
+
"a 24/7 permissionless DEX environment where most launches are worthless or scams.",
|
|
1323
|
+
"You will be given real on-chain facts about one launch: its launchpad, whether a buy-then-sell",
|
|
1324
|
+
"round trip retains value (a honeypot signal), and what fraction of supply the deployer wallet",
|
|
1325
|
+
"still holds (a rug-risk signal). You have no access to socials, team identity, or any off-chain",
|
|
1326
|
+
"information \u2014 judge only from what is given.",
|
|
1327
|
+
"",
|
|
1328
|
+
"Reply with ONLY a single JSON object, no prose before or after it, matching exactly:",
|
|
1329
|
+
'{"buy": boolean, "confidence": number between 0 and 1, "thesis": "one sentence"}',
|
|
1330
|
+
"",
|
|
1331
|
+
'"buy" should be true only when the facts given suggest this is unusually clean for a brand-new',
|
|
1332
|
+
"launch (high retention, low deployer concentration) \u2014 most launches should get buy:false.",
|
|
1333
|
+
'"confidence" reflects how sure you are in that judgment given how thin the available signal is.'
|
|
1334
|
+
].join("\n");
|
|
1335
|
+
async function judgeLaunch(cfg, brief) {
|
|
1336
|
+
const model = cfg.model || DEFAULT_MODELS[cfg.provider];
|
|
1337
|
+
const timeoutMs = cfg.timeoutMs ?? 9e3;
|
|
1338
|
+
const controller = new AbortController();
|
|
1339
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
1340
|
+
try {
|
|
1341
|
+
const text = await callProvider(cfg.provider, cfg.apiKey, model, brief, controller.signal);
|
|
1342
|
+
return parseVerdict(text);
|
|
1343
|
+
} catch (err) {
|
|
1344
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
1345
|
+
throw new Error(`hood-traders llm.ts: ${cfg.provider} request timed out after ${timeoutMs}ms`);
|
|
1346
|
+
}
|
|
1347
|
+
throw err;
|
|
1348
|
+
} finally {
|
|
1349
|
+
clearTimeout(timer);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
async function callProvider(provider, apiKey, model, brief, signal) {
|
|
1353
|
+
if (provider === "anthropic") {
|
|
1354
|
+
const res2 = await fetch("https://api.anthropic.com/v1/messages", {
|
|
1355
|
+
method: "POST",
|
|
1356
|
+
signal,
|
|
1357
|
+
headers: {
|
|
1358
|
+
"content-type": "application/json",
|
|
1359
|
+
"x-api-key": apiKey,
|
|
1360
|
+
"anthropic-version": "2023-06-01"
|
|
1361
|
+
},
|
|
1362
|
+
body: JSON.stringify({
|
|
1363
|
+
model,
|
|
1364
|
+
max_tokens: 300,
|
|
1365
|
+
system: SYSTEM_PROMPT,
|
|
1366
|
+
messages: [{ role: "user", content: brief }]
|
|
1367
|
+
})
|
|
1368
|
+
});
|
|
1369
|
+
const body2 = await res2.text();
|
|
1370
|
+
if (!res2.ok) throw providerError("anthropic", model, res2.status, body2);
|
|
1371
|
+
const data2 = JSON.parse(body2);
|
|
1372
|
+
const text2 = data2.content?.[0]?.text;
|
|
1373
|
+
if (!text2) throw new Error(`hood-traders llm.ts: anthropic response had no content text: ${body2.slice(0, 300)}`);
|
|
1374
|
+
return text2;
|
|
1375
|
+
}
|
|
1376
|
+
const { url, extraHeaders } = openAiCompatibleEndpoint(provider);
|
|
1377
|
+
const res = await fetch(url, {
|
|
1378
|
+
method: "POST",
|
|
1379
|
+
signal,
|
|
1380
|
+
headers: {
|
|
1381
|
+
"content-type": "application/json",
|
|
1382
|
+
authorization: `Bearer ${apiKey}`,
|
|
1383
|
+
...extraHeaders
|
|
1384
|
+
},
|
|
1385
|
+
body: JSON.stringify({
|
|
1386
|
+
model,
|
|
1387
|
+
max_tokens: 300,
|
|
1388
|
+
messages: [
|
|
1389
|
+
{ role: "system", content: SYSTEM_PROMPT },
|
|
1390
|
+
{ role: "user", content: brief }
|
|
1391
|
+
]
|
|
1392
|
+
})
|
|
1393
|
+
});
|
|
1394
|
+
const body = await res.text();
|
|
1395
|
+
if (!res.ok) throw providerError(provider, model, res.status, body);
|
|
1396
|
+
const data = JSON.parse(body);
|
|
1397
|
+
const text = data.choices?.[0]?.message?.content;
|
|
1398
|
+
if (!text) throw new Error(`hood-traders llm.ts: ${provider} response had no message content: ${body.slice(0, 300)}`);
|
|
1399
|
+
return text;
|
|
1400
|
+
}
|
|
1401
|
+
function openAiCompatibleEndpoint(provider) {
|
|
1402
|
+
switch (provider) {
|
|
1403
|
+
case "openai":
|
|
1404
|
+
return { url: "https://api.openai.com/v1/chat/completions", extraHeaders: {} };
|
|
1405
|
+
case "groq":
|
|
1406
|
+
return { url: "https://api.groq.com/openai/v1/chat/completions", extraHeaders: {} };
|
|
1407
|
+
case "openrouter":
|
|
1408
|
+
return {
|
|
1409
|
+
url: "https://openrouter.ai/api/v1/chat/completions",
|
|
1410
|
+
extraHeaders: {
|
|
1411
|
+
"HTTP-Referer": "https://github.com/nirholas/hood-traders",
|
|
1412
|
+
"X-Title": "hood-traders"
|
|
1413
|
+
}
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
function providerError(provider, model, status, body) {
|
|
1418
|
+
return new Error(
|
|
1419
|
+
`hood-traders llm.ts: ${provider} rejected request (HTTP ${status}, model="${model}"). If this is a model-not-found error, set HOOD_LLM_MODEL to a current model id for this provider. Response: ${body.slice(0, 300)}`
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
function parseVerdict(text) {
|
|
1423
|
+
const match = text.match(/\{[\s\S]*\}/);
|
|
1424
|
+
if (!match) throw new Error(`hood-traders llm.ts: no JSON object found in LLM response: ${text.slice(0, 300)}`);
|
|
1425
|
+
let raw;
|
|
1426
|
+
try {
|
|
1427
|
+
raw = JSON.parse(match[0]);
|
|
1428
|
+
} catch (err) {
|
|
1429
|
+
throw new Error(`hood-traders llm.ts: LLM response JSON did not parse: ${err.message}`);
|
|
1430
|
+
}
|
|
1431
|
+
if (typeof raw !== "object" || raw === null) {
|
|
1432
|
+
throw new Error("hood-traders llm.ts: LLM verdict was not a JSON object");
|
|
1433
|
+
}
|
|
1434
|
+
const v = raw;
|
|
1435
|
+
if (typeof v.buy !== "boolean") {
|
|
1436
|
+
throw new Error(`hood-traders llm.ts: LLM verdict missing boolean "buy": ${JSON.stringify(v)}`);
|
|
1437
|
+
}
|
|
1438
|
+
if (typeof v.thesis !== "string" || v.thesis.trim().length === 0) {
|
|
1439
|
+
throw new Error(`hood-traders llm.ts: LLM verdict missing non-empty "thesis": ${JSON.stringify(v)}`);
|
|
1440
|
+
}
|
|
1441
|
+
const confidenceRaw = typeof v.confidence === "number" ? v.confidence : Number(v.confidence);
|
|
1442
|
+
if (!Number.isFinite(confidenceRaw)) {
|
|
1443
|
+
throw new Error(`hood-traders llm.ts: LLM verdict has non-numeric "confidence": ${JSON.stringify(v)}`);
|
|
1444
|
+
}
|
|
1445
|
+
const confidence = Math.min(1, Math.max(0, confidenceRaw));
|
|
1446
|
+
return { buy: v.buy, confidence, thesis: v.thesis.trim() };
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
// src/strategies/llm-strategist.ts
|
|
1450
|
+
import { erc20Abi as erc20Abi2, watchLaunches as watchLaunches2 } from "hoodchain";
|
|
1451
|
+
import { formatUnits as formatUnits4, parseEther as parseEther2 } from "viem";
|
|
1452
|
+
var DEFAULTS4 = {
|
|
1453
|
+
entryWeth: 0.01,
|
|
1454
|
+
takeProfitPct: 0.6,
|
|
1455
|
+
stopLossPct: 0.35,
|
|
1456
|
+
maxHoldSeconds: 30 * 60,
|
|
1457
|
+
minConfidence: 0.6,
|
|
1458
|
+
maxLaunchAgeSeconds: 5 * 60
|
|
1459
|
+
};
|
|
1460
|
+
var LlmStrategist = class {
|
|
1461
|
+
id = "llm-strategist";
|
|
1462
|
+
title = "LLM Strategist";
|
|
1463
|
+
quote = "weth";
|
|
1464
|
+
p;
|
|
1465
|
+
queue = [];
|
|
1466
|
+
seen = /* @__PURE__ */ new Set();
|
|
1467
|
+
judged = /* @__PURE__ */ new Set();
|
|
1468
|
+
unwatch = null;
|
|
1469
|
+
constructor(params) {
|
|
1470
|
+
this.p = { ...DEFAULTS4, ...params };
|
|
1471
|
+
}
|
|
1472
|
+
get meta() {
|
|
1473
|
+
return {
|
|
1474
|
+
edge: "An LLM (bring your own key) weighs the same real on-chain launch signals launch-sniper checks mechanically \u2014 buy/sell round-trip retention and deployer supply concentration \u2014 holistically instead of against fixed cutoffs, and only trades when its stated confidence clears a threshold.",
|
|
1475
|
+
failureModes: [
|
|
1476
|
+
"LLM confidence is not calibrated probability \u2014 a confidently wrong verdict trades exactly like a confidently right one.",
|
|
1477
|
+
"On-chain data reaching the prompt is attacker-controlled; only numeric signals are included today specifically to limit prompt-injection surface.",
|
|
1478
|
+
"LLM round-trip latency means this strategy reacts to a launch after launch-sniper already has (or hasn\u2019t).",
|
|
1479
|
+
"Every judged launch costs a real LLM API call regardless of verdict \u2014 a launch storm inflates spend with nothing to show for it.",
|
|
1480
|
+
"One configured provider, no fallback chain \u2014 a provider outage means zero coverage until it recovers."
|
|
1481
|
+
],
|
|
1482
|
+
params: { ...this.p, llm: { ...this.p.llm, apiKey: this.p.llm.apiKey ? "<redacted>" : "" } }
|
|
1483
|
+
};
|
|
1484
|
+
}
|
|
1485
|
+
start(ctx) {
|
|
1486
|
+
this.unwatch = watchLaunches2(
|
|
1487
|
+
ctx.market.client,
|
|
1488
|
+
(launch) => {
|
|
1489
|
+
const key = launch.token.toLowerCase();
|
|
1490
|
+
if (this.seen.has(key)) return;
|
|
1491
|
+
this.seen.add(key);
|
|
1492
|
+
this.queue.push({ launch, seenAt: Date.now() });
|
|
1493
|
+
ctx.log(`llm-strategist: new launch queued: ${launch.launchpad} ${launch.token}`, { creator: launch.creator });
|
|
1494
|
+
},
|
|
1495
|
+
{ onError: (e) => ctx.log(`llm-strategist: launch watcher error: ${e.message}`) }
|
|
1496
|
+
);
|
|
1497
|
+
}
|
|
1498
|
+
stop() {
|
|
1499
|
+
this.unwatch?.();
|
|
1500
|
+
this.unwatch = null;
|
|
1501
|
+
}
|
|
1502
|
+
async tick(ctx) {
|
|
1503
|
+
const intents = [];
|
|
1504
|
+
const alerts = [];
|
|
1505
|
+
for (const pos of ctx.positions) {
|
|
1506
|
+
const ageSec = (ctx.now - pos.openedAt) / 1e3;
|
|
1507
|
+
const pnlPct = pos.markUsd !== null && pos.investedUsd > 0 ? pos.markUsd / pos.investedUsd - 1 : null;
|
|
1508
|
+
let exitReason = null;
|
|
1509
|
+
if (pnlPct !== null && pnlPct >= this.p.takeProfitPct) exitReason = `take-profit ${(pnlPct * 100).toFixed(1)}%`;
|
|
1510
|
+
else if (pnlPct !== null && pnlPct <= -this.p.stopLossPct) exitReason = `stop-loss ${(pnlPct * 100).toFixed(1)}%`;
|
|
1511
|
+
else if (ageSec >= this.p.maxHoldSeconds) exitReason = `time-exit ${Math.round(ageSec)}s held`;
|
|
1512
|
+
if (exitReason) {
|
|
1513
|
+
intents.push({
|
|
1514
|
+
side: "sell",
|
|
1515
|
+
token: pos.token,
|
|
1516
|
+
tokenSymbol: pos.tokenSymbol,
|
|
1517
|
+
amountIn: pos.amount,
|
|
1518
|
+
quoteToken: pos.quoteToken,
|
|
1519
|
+
quoteSymbol: pos.quoteSymbol,
|
|
1520
|
+
reason: exitReason,
|
|
1521
|
+
meta: { pnlPct }
|
|
1522
|
+
});
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
const candidate = this.queue.shift();
|
|
1526
|
+
if (candidate) {
|
|
1527
|
+
const key = candidate.launch.token.toLowerCase();
|
|
1528
|
+
if (!this.judged.has(key)) {
|
|
1529
|
+
this.judged.add(key);
|
|
1530
|
+
const result = await this.evaluate(ctx, candidate);
|
|
1531
|
+
if (result.intent) intents.push(result.intent);
|
|
1532
|
+
if (result.alert) alerts.push(result.alert);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
return { intents, alerts };
|
|
1536
|
+
}
|
|
1537
|
+
async evaluate(ctx, candidate) {
|
|
1538
|
+
const { launch } = candidate;
|
|
1539
|
+
const ageSec = (ctx.now - candidate.seenAt) / 1e3;
|
|
1540
|
+
if (ageSec > this.p.maxLaunchAgeSeconds) {
|
|
1541
|
+
return { alert: { level: "info", message: `llm-strategist: skip ${launch.token}: stale (${Math.round(ageSec)}s old)`, meta: {} } };
|
|
1542
|
+
}
|
|
1543
|
+
if (ctx.positions.some((p) => p.token.toLowerCase() === launch.token.toLowerCase())) return {};
|
|
1544
|
+
const amountIn = parseEther2(String(this.p.entryWeth));
|
|
1545
|
+
const buyQuote = await ctx.market.quoteBuy(ctx.quoteToken, launch.token, amountIn);
|
|
1546
|
+
if (!buyQuote || buyQuote.amountOut <= 0n) {
|
|
1547
|
+
return { alert: { level: "info", message: `llm-strategist: skip ${launch.token}: no liquid Uniswap route`, meta: { launchpad: launch.launchpad } } };
|
|
1548
|
+
}
|
|
1549
|
+
const sellQuote = await ctx.market.quoteSell(launch.token, ctx.quoteToken, buyQuote.amountOut);
|
|
1550
|
+
const retention = sellQuote && sellQuote.amountOut > 0n ? Number(sellQuote.amountOut) / Number(amountIn) : 0;
|
|
1551
|
+
const deployerPct = await this.deployerConcentration(ctx, launch);
|
|
1552
|
+
const brief = [
|
|
1553
|
+
`Launchpad: ${launch.launchpad}`,
|
|
1554
|
+
`Round-trip retention (buy then immediately sell back): ${(retention * 100).toFixed(1)}% of input value returned.`,
|
|
1555
|
+
`Deployer wallet holds: ${deployerPct === null ? "unknown (could not read on-chain balance)" : (deployerPct * 100).toFixed(1) + "% of total supply"}.`,
|
|
1556
|
+
`Age since first seen: ${Math.round(ageSec)} seconds.`
|
|
1557
|
+
].join("\n");
|
|
1558
|
+
let verdict;
|
|
1559
|
+
try {
|
|
1560
|
+
verdict = await judgeLaunch(this.p.llm, brief);
|
|
1561
|
+
} catch (err) {
|
|
1562
|
+
return {
|
|
1563
|
+
alert: {
|
|
1564
|
+
level: "warn",
|
|
1565
|
+
message: `llm-strategist: skip ${launch.token}: LLM judge failed \u2014 ${err.message}`,
|
|
1566
|
+
meta: { launchpad: launch.launchpad }
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
if (!verdict.buy || verdict.confidence < this.p.minConfidence) {
|
|
1571
|
+
return {
|
|
1572
|
+
alert: {
|
|
1573
|
+
level: "info",
|
|
1574
|
+
message: `llm-strategist: skip ${launch.token}: verdict buy=${verdict.buy} confidence=${verdict.confidence.toFixed(2)} \u2014 ${verdict.thesis}`,
|
|
1575
|
+
meta: { retention, deployerPct, verdict }
|
|
1576
|
+
}
|
|
1577
|
+
};
|
|
1578
|
+
}
|
|
1579
|
+
return {
|
|
1580
|
+
intent: {
|
|
1581
|
+
side: "buy",
|
|
1582
|
+
token: launch.token,
|
|
1583
|
+
tokenSymbol: shortToken3(launch.token),
|
|
1584
|
+
amountIn,
|
|
1585
|
+
quoteToken: ctx.quoteToken,
|
|
1586
|
+
quoteSymbol: ctx.quoteSymbol,
|
|
1587
|
+
reason: `LLM (${this.p.llm.provider}, confidence ${verdict.confidence.toFixed(2)}): ${verdict.thesis}`,
|
|
1588
|
+
meta: { launchpad: launch.launchpad, deployerPct, retention, llmProvider: this.p.llm.provider, confidence: verdict.confidence }
|
|
1589
|
+
}
|
|
1590
|
+
};
|
|
1591
|
+
}
|
|
1592
|
+
async deployerConcentration(ctx, launch) {
|
|
1593
|
+
try {
|
|
1594
|
+
const [supply, bal] = await ctx.market.client.public.multicall({
|
|
1595
|
+
contracts: [
|
|
1596
|
+
{ address: launch.token, abi: erc20Abi2, functionName: "totalSupply" },
|
|
1597
|
+
{ address: launch.token, abi: erc20Abi2, functionName: "balanceOf", args: [launch.creator] }
|
|
1598
|
+
],
|
|
1599
|
+
allowFailure: false
|
|
1600
|
+
});
|
|
1601
|
+
if (supply === 0n) return null;
|
|
1602
|
+
return Number(formatUnits4(bal * 10000n / supply, 4));
|
|
1603
|
+
} catch {
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
};
|
|
1608
|
+
function shortToken3(addr) {
|
|
1609
|
+
return `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1290
1612
|
// src/server/dashboard.ts
|
|
1291
1613
|
import { createServer } from "http";
|
|
1292
1614
|
import { readFile } from "fs/promises";
|
|
@@ -1363,9 +1685,14 @@ export {
|
|
|
1363
1685
|
Market,
|
|
1364
1686
|
Fleet,
|
|
1365
1687
|
loadFleetConfig,
|
|
1688
|
+
loadLlmConfig,
|
|
1689
|
+
loadLlmMinConfidence,
|
|
1366
1690
|
LaunchSniper,
|
|
1367
1691
|
Momentum,
|
|
1368
1692
|
PremiumWatch,
|
|
1693
|
+
judgeLaunch,
|
|
1694
|
+
parseVerdict,
|
|
1695
|
+
LlmStrategist,
|
|
1369
1696
|
createDashboardServer
|
|
1370
1697
|
};
|
|
1371
|
-
//# sourceMappingURL=chunk-
|
|
1698
|
+
//# sourceMappingURL=chunk-YZJCP67J.js.map
|