cornerstone-autonomous-agent 1.0.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 (41) hide show
  1. package/.env.example +49 -0
  2. package/LICENSE.md +384 -0
  3. package/README.md +163 -0
  4. package/SKILL-clawdhub.md +180 -0
  5. package/adapters/anthropic/tools.json +58 -0
  6. package/adapters/local/README.md +11 -0
  7. package/adapters/openai/openapi.yaml +72 -0
  8. package/adapters/openclaw/SKILL.md +47 -0
  9. package/package.json +71 -0
  10. package/src/agent/agent.js +52 -0
  11. package/src/agent/index.js +4 -0
  12. package/src/agent/llm.js +25 -0
  13. package/src/agent/tools/localTools.js +259 -0
  14. package/src/agent/tools/mcpTools.js +69 -0
  15. package/src/balance.js +264 -0
  16. package/src/check-update.js +191 -0
  17. package/src/contract.js +390 -0
  18. package/src/credit-aptos-agent.js +103 -0
  19. package/src/lib/aptos/balance.js +32 -0
  20. package/src/lib/aptos/config.js +48 -0
  21. package/src/lib/aptos/index.js +4 -0
  22. package/src/lib/aptos/signPayment.js +94 -0
  23. package/src/lib/aptos/wallet.js +143 -0
  24. package/src/lib/chains.js +157 -0
  25. package/src/lib/evm/index.js +1 -0
  26. package/src/lib/evm/signPayment.js +91 -0
  27. package/src/lib/gas.js +186 -0
  28. package/src/lib/mcp/client.js +225 -0
  29. package/src/lib/mcp/index.js +1 -0
  30. package/src/lib/rpc.js +175 -0
  31. package/src/lib/wallet.js +255 -0
  32. package/src/lib/x402/client.js +195 -0
  33. package/src/lib/x402/index.js +7 -0
  34. package/src/lib/x402/types.js +50 -0
  35. package/src/register-aptos-agent.js +92 -0
  36. package/src/run-agent.js +65 -0
  37. package/src/setup-aptos.js +57 -0
  38. package/src/setup.js +104 -0
  39. package/src/show-agent-addresses.js +32 -0
  40. package/src/swap.js +449 -0
  41. package/src/transfer.js +326 -0
package/.env.example ADDED
@@ -0,0 +1,49 @@
1
+ # CreditNexus autonomous agent – copy to autonomous/.env
2
+ # See demo_mcp/README.md § Configuration for full reference.
3
+
4
+ # -----------------------------------------------------------------------------
5
+ # MCP Server
6
+ # -----------------------------------------------------------------------------
7
+ # MCP server base URL (tool calls, 402 payment flow)
8
+ MCP_SERVER_URL=http://localhost:4023
9
+
10
+ # -----------------------------------------------------------------------------
11
+ # x402 Facilitator
12
+ # -----------------------------------------------------------------------------
13
+ # Aptos: run_prediction, run_backtest. Use public for full demo including open_bank_account.
14
+ # Use x402-navy.vercel.app; facilitator.x402.org may not resolve (DNS ENOTFOUND).
15
+ X402_FACILITATOR_URL=https://x402-navy.vercel.app/facilitator
16
+ # EVM: open_bank_account. Defaults to X402_FACILITATOR_URL when using local Aptos facilitator
17
+ # X402_EVM_FACILITATOR_URL=https://x402-navy.vercel.app/facilitator
18
+
19
+ # -----------------------------------------------------------------------------
20
+ # LLM (OpenAI-compatible)
21
+ # -----------------------------------------------------------------------------
22
+ # e.g. Hugging Face router
23
+ LLM_BASE_URL=https://router.huggingface.co/v1
24
+ # Hugging Face token for inference
25
+ HUGGINGFACE_API_KEY=
26
+ # or HF_TOKEN=
27
+
28
+ LLM_MODEL=deepseek-ai/DeepSeek-V3.2-Exp:novita
29
+
30
+ # -----------------------------------------------------------------------------
31
+ # Wallets
32
+ # -----------------------------------------------------------------------------
33
+ # Paths to wallet JSON files (create with node src/setup-aptos.js and node src/setup.js)
34
+ APTOS_WALLET_PATH=~/.aptos-agent-wallet.json
35
+ EVM_WALLET_PATH=~/.evm-wallet.json
36
+ # Optional: use env key instead of file (e.g. MetaMask export). Whitelist that address at flow.html
37
+ # EVM_PRIVATE_KEY=0x...
38
+
39
+ # -----------------------------------------------------------------------------
40
+ # Aptos crediting (credit_aptos_wallet tool)
41
+ # -----------------------------------------------------------------------------
42
+ # devnet = programmatic faucet; testnet = instructions only (demo MCP uses testnet)
43
+ # APTOS_FAUCET_NETWORK=testnet
44
+
45
+ # -----------------------------------------------------------------------------
46
+ # EVM / Base Sepolia (open_bank_account)
47
+ # -----------------------------------------------------------------------------
48
+ BASE_SEPOLIA_RPC=https://sepolia.base.org
49
+ # BASE_SEPOLIA_USDC=0x036CbD53842c5426634e7929541eC2318f3dCF7e
package/LICENSE.md ADDED
@@ -0,0 +1,384 @@
1
+ # License (demo_mcp)
2
+
3
+ Use of this software is also subject to the [Responsible AI License (RAIL)](https://www.licenses.ai/). See [RAIL](https://www.licenses.ai/) for behavioral-use terms.
4
+
5
+ ---
6
+
7
+ # GNU GENERAL PUBLIC LICENSE
8
+
9
+ Version 2, June 1991
10
+
11
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
12
+ <https://fsf.org/>
13
+
14
+ Everyone is permitted to copy and distribute verbatim copies
15
+ of this license document, but changing it is not allowed.
16
+
17
+ ## Preamble
18
+
19
+ The licenses for most software are designed to take away your freedom
20
+ to share and change it. By contrast, the GNU General Public License is
21
+ intended to guarantee your freedom to share and change free
22
+ software--to make sure the software is free for all its users. This
23
+ General Public License applies to most of the Free Software
24
+ Foundation's software and to any other program whose authors commit to
25
+ using it. (Some other Free Software Foundation software is covered by
26
+ the GNU Lesser General Public License instead.) You can apply it to
27
+ your programs, too.
28
+
29
+ When we speak of free software, we are referring to freedom, not
30
+ price. Our General Public Licenses are designed to make sure that you
31
+ have the freedom to distribute copies of free software (and charge for
32
+ this service if you wish), that you receive source code or can get it
33
+ if you want it, that you can change the software or use pieces of it
34
+ in new free programs; and that you know you can do these things.
35
+
36
+ To protect your rights, we need to make restrictions that forbid
37
+ anyone to deny you these rights or to ask you to surrender the rights.
38
+ These restrictions translate to certain responsibilities for you if
39
+ you distribute copies of the software, or if you modify it.
40
+
41
+ For example, if you distribute copies of such a program, whether
42
+ gratis or for a fee, you must give the recipients all the rights that
43
+ you have. You must make sure that they, too, receive or can get the
44
+ source code. And you must show them these terms so they know their
45
+ rights.
46
+
47
+ We protect your rights with two steps: (1) copyright the software, and
48
+ (2) offer you this license which gives you legal permission to copy,
49
+ distribute and/or modify the software.
50
+
51
+ Also, for each author's protection and ours, we want to make certain
52
+ that everyone understands that there is no warranty for this free
53
+ software. If the software is modified by someone else and passed on,
54
+ we want its recipients to know that what they have is not the
55
+ original, so that any problems introduced by others will not reflect
56
+ on the original authors' reputations.
57
+
58
+ Finally, any free program is threatened constantly by software
59
+ patents. We wish to avoid the danger that redistributors of a free
60
+ program will individually obtain patent licenses, in effect making the
61
+ program proprietary. To prevent this, we have made it clear that any
62
+ patent must be licensed for everyone's free use or not licensed at
63
+ all.
64
+
65
+ The precise terms and conditions for copying, distribution and
66
+ modification follow.
67
+
68
+ ## TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
69
+
70
+ **0.** This License applies to any program or other work which
71
+ contains a notice placed by the copyright holder saying it may be
72
+ distributed under the terms of this General Public License. The
73
+ "Program", below, refers to any such program or work, and a "work
74
+ based on the Program" means either the Program or any derivative work
75
+ under copyright law: that is to say, a work containing the Program or
76
+ a portion of it, either verbatim or with modifications and/or
77
+ translated into another language. (Hereinafter, translation is
78
+ included without limitation in the term "modification".) Each licensee
79
+ is addressed as "you".
80
+
81
+ Activities other than copying, distribution and modification are not
82
+ covered by this License; they are outside its scope. The act of
83
+ running the Program is not restricted, and the output from the Program
84
+ is covered only if its contents constitute a work based on the Program
85
+ (independent of having been made by running the Program). Whether that
86
+ is true depends on what the Program does.
87
+
88
+ **1.** You may copy and distribute verbatim copies of the Program's
89
+ source code as you receive it, in any medium, provided that you
90
+ conspicuously and appropriately publish on each copy an appropriate
91
+ copyright notice and disclaimer of warranty; keep intact all the
92
+ notices that refer to this License and to the absence of any warranty;
93
+ and give any other recipients of the Program a copy of this License
94
+ along with the Program.
95
+
96
+ You may charge a fee for the physical act of transferring a copy, and
97
+ you may at your option offer warranty protection in exchange for a
98
+ fee.
99
+
100
+ **2.** You may modify your copy or copies of the Program or any
101
+ portion of it, thus forming a work based on the Program, and copy and
102
+ distribute such modifications or work under the terms of Section 1
103
+ above, provided that you also meet all of these conditions:
104
+
105
+
106
+ **a)** You must cause the modified files to carry prominent notices
107
+ stating that you changed the files and the date of any change.
108
+
109
+
110
+ **b)** You must cause any work that you distribute or publish, that in
111
+ whole or in part contains or is derived from the Program or any part
112
+ thereof, to be licensed as a whole at no charge to all third parties
113
+ under the terms of this License.
114
+
115
+
116
+ **c)** If the modified program normally reads commands interactively
117
+ when run, you must cause it, when started running for such interactive
118
+ use in the most ordinary way, to print or display an announcement
119
+ including an appropriate copyright notice and a notice that there is
120
+ no warranty (or else, saying that you provide a warranty) and that
121
+ users may redistribute the program under these conditions, and telling
122
+ the user how to view a copy of this License. (Exception: if the
123
+ Program itself is interactive but does not normally print such an
124
+ announcement, your work based on the Program is not required to print
125
+ an announcement.)
126
+
127
+ These requirements apply to the modified work as a whole. If
128
+ identifiable sections of that work are not derived from the Program,
129
+ and can be reasonably considered independent and separate works in
130
+ themselves, then this License, and its terms, do not apply to those
131
+ sections when you distribute them as separate works. But when you
132
+ distribute the same sections as part of a whole which is a work based
133
+ on the Program, the distribution of the whole must be on the terms of
134
+ this License, whose permissions for other licensees extend to the
135
+ entire whole, and thus to each and every part regardless of who wrote
136
+ it.
137
+
138
+ Thus, it is not the intent of this section to claim rights or contest
139
+ your rights to work written entirely by you; rather, the intent is to
140
+ exercise the right to control the distribution of derivative or
141
+ collective works based on the Program.
142
+
143
+ In addition, mere aggregation of another work not based on the Program
144
+ with the Program (or with a work based on the Program) on a volume of
145
+ a storage or distribution medium does not bring the other work under
146
+ the scope of this License.
147
+
148
+ **3.** You may copy and distribute the Program (or a work based on it,
149
+ under Section 2) in object code or executable form under the terms of
150
+ Sections 1 and 2 above provided that you also do one of the following:
151
+
152
+
153
+ **a)** Accompany it with the complete corresponding machine-readable
154
+ source code, which must be distributed under the terms of Sections 1
155
+ and 2 above on a medium customarily used for software interchange; or,
156
+
157
+
158
+ **b)** Accompany it with a written offer, valid for at least three
159
+ years, to give any third party, for a charge no more than your cost of
160
+ physically performing source distribution, a complete machine-readable
161
+ copy of the corresponding source code, to be distributed under the
162
+ terms of Sections 1 and 2 above on a medium customarily used for
163
+ software interchange; or,
164
+
165
+
166
+ **c)** Accompany it with the information you received as to the offer
167
+ to distribute corresponding source code. (This alternative is allowed
168
+ only for noncommercial distribution and only if you received the
169
+ program in object code or executable form with such an offer, in
170
+ accord with Subsection b above.)
171
+
172
+ The source code for a work means the preferred form of the work for
173
+ making modifications to it. For an executable work, complete source
174
+ code means all the source code for all modules it contains, plus any
175
+ associated interface definition files, plus the scripts used to
176
+ control compilation and installation of the executable. However, as a
177
+ special exception, the source code distributed need not include
178
+ anything that is normally distributed (in either source or binary
179
+ form) with the major components (compiler, kernel, and so on) of the
180
+ operating system on which the executable runs, unless that component
181
+ itself accompanies the executable.
182
+
183
+ If distribution of executable or object code is made by offering
184
+ access to copy from a designated place, then offering equivalent
185
+ access to copy the source code from the same place counts as
186
+ distribution of the source code, even though third parties are not
187
+ compelled to copy the source along with the object code.
188
+
189
+ **4.** You may not copy, modify, sublicense, or distribute the Program
190
+ except as expressly provided under this License. Any attempt otherwise
191
+ to copy, modify, sublicense or distribute the Program is void, and
192
+ will automatically terminate your rights under this License. However,
193
+ parties who have received copies, or rights, from you under this
194
+ License will not have their licenses terminated so long as such
195
+ parties remain in full compliance.
196
+
197
+ **5.** You are not required to accept this License, since you have not
198
+ signed it. However, nothing else grants you permission to modify or
199
+ distribute the Program or its derivative works. These actions are
200
+ prohibited by law if you do not accept this License. Therefore, by
201
+ modifying or distributing the Program (or any work based on the
202
+ Program), you indicate your acceptance of this License to do so, and
203
+ all its terms and conditions for copying, distributing or modifying
204
+ the Program or works based on it.
205
+
206
+ **6.** Each time you redistribute the Program (or any work based on
207
+ the Program), the recipient automatically receives a license from the
208
+ original licensor to copy, distribute or modify the Program subject to
209
+ these terms and conditions. You may not impose any further
210
+ restrictions on the recipients' exercise of the rights granted herein.
211
+ You are not responsible for enforcing compliance by third parties to
212
+ this License.
213
+
214
+ **7.** If, as a consequence of a court judgment or allegation of
215
+ patent infringement or for any other reason (not limited to patent
216
+ issues), conditions are imposed on you (whether by court order,
217
+ agreement or otherwise) that contradict the conditions of this
218
+ License, they do not excuse you from the conditions of this License.
219
+ If you cannot distribute so as to satisfy simultaneously your
220
+ obligations under this License and any other pertinent obligations,
221
+ then as a consequence you may not distribute the Program at all. For
222
+ example, if a patent license would not permit royalty-free
223
+ redistribution of the Program by all those who receive copies directly
224
+ or indirectly through you, then the only way you could satisfy both it
225
+ and this License would be to refrain entirely from distribution of the
226
+ Program.
227
+
228
+ If any portion of this section is held invalid or unenforceable under
229
+ any particular circumstance, the balance of the section is intended to
230
+ apply and the section as a whole is intended to apply in other
231
+ circumstances.
232
+
233
+ It is not the purpose of this section to induce you to infringe any
234
+ patents or other property right claims or to contest validity of any
235
+ such claims; this section has the sole purpose of protecting the
236
+ integrity of the free software distribution system, which is
237
+ implemented by public license practices. Many people have made
238
+ generous contributions to the wide range of software distributed
239
+ through that system in reliance on consistent application of that
240
+ system; it is up to the author/donor to decide if he or she is willing
241
+ to distribute software through any other system and a licensee cannot
242
+ impose that choice.
243
+
244
+ This section is intended to make thoroughly clear what is believed to
245
+ be a consequence of the rest of this License.
246
+
247
+ **8.** If the distribution and/or use of the Program is restricted in
248
+ certain countries either by patents or by copyrighted interfaces, the
249
+ original copyright holder who places the Program under this License
250
+ may add an explicit geographical distribution limitation excluding
251
+ those countries, so that distribution is permitted only in or among
252
+ countries not thus excluded. In such case, this License incorporates
253
+ the limitation as if written in the body of this License.
254
+
255
+ **9.** The Free Software Foundation may publish revised and/or new
256
+ versions of the General Public License from time to time. Such new
257
+ versions will be similar in spirit to the present version, but may
258
+ differ in detail to address new problems or concerns.
259
+
260
+ Each version is given a distinguishing version number. If the Program
261
+ specifies a version number of this License which applies to it and
262
+ "any later version", you have the option of following the terms and
263
+ conditions either of that version or of any later version published by
264
+ the Free Software Foundation. If the Program does not specify a
265
+ version number of this License, you may choose any version ever
266
+ published by the Free Software Foundation.
267
+
268
+ **10.** If you wish to incorporate parts of the Program into other
269
+ free programs whose distribution conditions are different, write to
270
+ the author to ask for permission. For software which is copyrighted by
271
+ the Free Software Foundation, write to the Free Software Foundation;
272
+ we sometimes make exceptions for this. Our decision will be guided by
273
+ the two goals of preserving the free status of all derivatives of our
274
+ free software and of promoting the sharing and reuse of software
275
+ generally.
276
+
277
+ **NO WARRANTY**
278
+
279
+ **11.** BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
280
+ WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
281
+ EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
282
+ OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
283
+ KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
284
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
285
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
286
+ PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
287
+ THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
288
+
289
+ **12.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
290
+ WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
291
+ AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
292
+ FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
293
+ CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
294
+ PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
295
+ RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
296
+ FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
297
+ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
298
+ DAMAGES.
299
+
300
+ END OF TERMS AND CONDITIONS
301
+
302
+ ## How to Apply These Terms to Your New Programs
303
+
304
+ If you develop a new program, and you want it to be of the greatest
305
+ possible use to the public, the best way to achieve this is to make it
306
+ free software which everyone can redistribute and change under these
307
+ terms.
308
+
309
+ To do so, attach the following notices to the program. It is safest to
310
+ attach them to the start of each source file to most effectively
311
+ convey the exclusion of warranty; and each file should have at least
312
+ the "copyright" line and a pointer to where the full notice is found.
313
+
314
+ one line to give the program's name and an idea of what it does.
315
+ Copyright (C) yyyy name of author
316
+
317
+ This program is free software; you can redistribute it and/or
318
+ modify it under the terms of the GNU General Public License
319
+ as published by the Free Software Foundation; either version 2
320
+ of the License, or (at your option) any later version.
321
+
322
+ This program is distributed in the hope that it will be useful,
323
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
324
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325
+ GNU General Public License for more details.
326
+
327
+ You should have received a copy of the GNU General Public License
328
+ along with this program; if not, see <https://www.gnu.org/licenses/>.
329
+
330
+ Also add information on how to contact you by electronic and paper
331
+ mail.
332
+
333
+ If the program is interactive, make it output a short notice like this
334
+ when it starts in an interactive mode:
335
+
336
+ Gnomovision version 69, Copyright (C) year name of author
337
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details
338
+ type `show w'. This is free software, and you are welcome
339
+ to redistribute it under certain conditions; type `show c'
340
+ for details.
341
+
342
+ The hypothetical commands \`show w' and \`show c' should show the
343
+ appropriate parts of the General Public License. Of course, the
344
+ commands you use may be called something other than \`show w' and
345
+ \`show c'; they could even be mouse-clicks or menu items--whatever
346
+ suits your program.
347
+
348
+ You should also get your employer (if you work as a programmer) or
349
+ your school, if any, to sign a "copyright disclaimer" for the program,
350
+ if necessary. Here is a sample; alter the names:
351
+
352
+ Yoyodyne, Inc., hereby disclaims all copyright
353
+ interest in the program `Gnomovision'
354
+ (which makes passes at compilers) written
355
+ by James Hacker.
356
+
357
+ signature of Moe Ghoul, 1 April 1989
358
+ Moe Ghoul, President of Vice
359
+
360
+ This General Public License does not permit incorporating your program
361
+ into proprietary programs. If your program is a subroutine library,
362
+ you may consider it more useful to permit linking proprietary
363
+ applications with the library. If this is what you want to do, use the
364
+ [GNU Lesser General Public
365
+ License](https://www.gnu.org/licenses/lgpl.html) instead of this
366
+ License.
367
+
368
+ ## Third-Party Licenses
369
+
370
+ This software includes third-party components that are subject to their own licenses:
371
+
372
+ - **OpenAI GPT-4o**: Subject to OpenAI's Terms of Service
373
+ - **LangChain**: Apache License 2.0
374
+ - **React**: MIT License
375
+ - **FastAPI**: MIT License
376
+ - **PostgreSQL**: PostgreSQL License
377
+ - **TorchGeo**: MIT License
378
+
379
+ Please refer to the respective license files for each component for full license terms.
380
+
381
+ ## Commercial Use
382
+
383
+ This software may be used for commercial purposes in accordance with the terms above.
384
+ For commercial licensing inquiries, please contact: contact@creditnexus.com
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # Autonomous Agent – x402 MCP + LangChain.js
2
+
3
+ Autonomous AI agent for **x402-paid MCP tools**: predict tickers, backtest strategies, open bank accounts. Pays with **Aptos** or **EVM** via the x402 facilitator—no OpenAI key; uses **Hugging Face** for the LLM. Built for Cursor, OpenClaw/Moltbot, and headless runs.
4
+
5
+ ## Why?
6
+
7
+ Most agent demos need a full backend and separate API keys. This agent talks to an **x402 MCP server**, pays with its own Aptos and EVM wallets (verify → settle), and uses an OpenAI-compatible LLM (e.g. Hugging Face). You get **run_prediction**, **run_backtest**, and **open_bank_account** with minimal setup—whitelist your agent, fund wallets, run.
8
+
9
+ ## Install
10
+
11
+ ### From npm (recommended)
12
+
13
+ ```bash
14
+ npm install cornerstone-autonomous-agent
15
+ ```
16
+
17
+ Copy the package’s `.env.example` into your project and set `MCP_SERVER_URL`, `X402_FACILITATOR_URL`, `HUGGINGFACE_API_KEY`, `LLM_MODEL`, and wallet paths. See [Config](#config).
18
+
19
+ ### From source
20
+
21
+ ```bash
22
+ git clone <your-repo> && cd <repo>/demo_mcp/autonomous
23
+ # or cd demo_mcp/autonomous if already in repo
24
+ npm install
25
+ ```
26
+
27
+ **OpenClaw / Moltbot:** See [adapters/openclaw/SKILL.md](adapters/openclaw/SKILL.md) or use your platform’s skill install (e.g. ClawHub). Then point `MCP_SERVER_URL` at your MCP server.
28
+
29
+ ## Quick Start
30
+
31
+ ```bash
32
+ # Generate Aptos wallet (for prediction/backtest)
33
+ node src/setup-aptos.js
34
+
35
+ # Generate EVM wallet (for open_bank_account)
36
+ node src/setup.js
37
+
38
+ # Whitelist your agent at the onboarding flow (e.g. http://localhost:4024/flow.html)
39
+ node src/show-agent-addresses.js
40
+
41
+ # Run the agent (demo: balance + AAPL prediction)
42
+ npx cornerstone-agent "Run a 30-day prediction for AAPL"
43
+ # or from source:
44
+ node src/run-agent.js "Run a 30-day prediction for AAPL"
45
+ ```
46
+
47
+ ## Config
48
+
49
+ Copy `.env.example` to `.env` and set:
50
+
51
+ | Variable | Description |
52
+ |----------|-------------|
53
+ | `MCP_SERVER_URL` | x402 MCP server base URL (e.g. http://localhost:4023 or Replit MCP URL) |
54
+ | `X402_FACILITATOR_URL` | Facilitator base URL for Aptos (verify/settle). Use public (e.g. https://x402-navy.vercel.app/facilitator) for open_bank_account. |
55
+ | `X402_EVM_FACILITATOR_URL` | Optional. EVM facilitator; defaults to X402_FACILITATOR_URL. Set to public when using local Aptos facilitator. |
56
+ | `LLM_BASE_URL` | OpenAI-compatible base URL (default https://router.huggingface.co/v1) |
57
+ | `HUGGINGFACE_API_KEY` or `HF_TOKEN` | Hugging Face API key |
58
+ | `LLM_MODEL` | Model ID (e.g. meta-llama/Llama-3.2-3B-Instruct) |
59
+ | `APTOS_WALLET_PATH` | Aptos wallet JSON path. Multi-wallet: ~/.aptos-agent-wallets.json. |
60
+ | `EVM_WALLET_PATH` | EVM wallet path. Multi-wallet: ~/.evm-wallets.json. Or set EVM_PRIVATE_KEY. |
61
+ | `BASE_SEPOLIA_RPC` | Optional; Base Sepolia RPC for open_bank_account |
62
+
63
+ ## Commands
64
+
65
+ | Command | Description |
66
+ |---------|-------------|
67
+ | `node src/setup.js` | Generate EVM wallet (single; for multi use agent tool create_evm_wallet) |
68
+ | `node src/setup-aptos.js` | Generate Aptos wallet (single; for multi use create_aptos_wallet) |
69
+ | `node src/show-agent-addresses.js` | Print all Aptos and EVM addresses for whitelisting at flow.html |
70
+ | `npm run credit:aptos` | Credit Aptos agent (devnet: programmatic; testnet: instructions) |
71
+ | `node src/balance.js <chain>` | EVM balance |
72
+ | `node src/run-agent.js [message]` | Run agent (or `npx cornerstone-agent [message]` when installed from npm) |
73
+ | `npm run agent` | Same as run-agent.js |
74
+
75
+ **Crediting Aptos:** Testnet has no programmatic faucet—use [Aptos testnet faucet](https://aptos.dev/network/faucet). Devnet: `APTOS_FAUCET_NETWORK=devnet npm run credit:aptos`. See [Canteen – Aptos x402](https://canteenapp-aptos-x402.notion.site/).
76
+
77
+ ## MCP Tools
78
+
79
+ | Tool | Description | Cost |
80
+ |------|-------------|------|
81
+ | `run_prediction` | Stock prediction (symbol, horizon, strategy) | ~6¢ (Aptos) |
82
+ | `run_backtest` | Backtest trading strategy | ~6¢ (Aptos) |
83
+ | `open_bank_account` | CornerStone bank link / open bank account | ~$3.65 (Ethereum/Base) |
84
+
85
+ ## Supported Networks
86
+
87
+ | Network | Use | Cost |
88
+ |---------|-----|------|
89
+ | Aptos testnet | run_prediction, run_backtest | ~6¢ USDC |
90
+ | Base Sepolia | open_bank_account (testnet) | ~$3.65 |
91
+ | Base (mainnet) | open_bank_account (production) | ~$3.65 |
92
+
93
+ ## x402 Flow
94
+
95
+ ```
96
+ Agent calls MCP tool
97
+ → Server returns 402 + payment requirements
98
+ → Agent builds payment (Aptos or EVM), calls facilitator /verify then /settle
99
+ → Agent retries request with PAYMENT-SIGNATURE header
100
+ → Server returns result + request_payload, response_payload, payment_receipt
101
+ ```
102
+
103
+ ## Architecture
104
+
105
+ ```
106
+ autonomous/
107
+ ├── src/
108
+ │ ├── agent/ # ReAct agent, LLM, tool wiring
109
+ │ ├── lib/
110
+ │ │ ├── mcp/ # MCP client + 402 handle/retry
111
+ │ │ ├── aptos/ # Aptos wallet, balance, signPayment
112
+ │ │ ├── evm/ # EVM wallet, signPayment (Base)
113
+ │ │ └── x402/ # Payment types, verify/settle flow
114
+ │ ├── run-agent.js # Entrypoint
115
+ │ ├── setup.js # EVM wallet generation
116
+ │ ├── setup-aptos.js # Aptos wallet generation
117
+ │ └── show-agent-addresses.js
118
+ ├── adapters/ # OpenClaw, OpenAI, Anthropic, local
119
+ ├── .env.example
120
+ └── package.json
121
+ ```
122
+
123
+ **Core pieces:** `lib/mcp` — MCP client and 402 retry; `lib/aptos` / `lib/evm` — wallets and payment signing; `lib/x402` — verify/settle; `agent/` — LangChain.js ReAct agent and tools.
124
+
125
+ ## Tech Stack
126
+
127
+ - **Runtime:** Node.js 18+
128
+ - **Agent:** LangChain.js (ReAct), OpenAI-compatible LLM (e.g. Hugging Face)
129
+ - **MCP:** [Model Context Protocol](https://modelcontextprotocol.io) + x402 payment flow
130
+ - **Chains:** Aptos (viem-style + @aptos-labs/ts-sdk), EVM (viem) for Base Sepolia/Base
131
+ - **Payments:** x402 facilitator (verify/settle), local wallet storage
132
+
133
+ ## Security
134
+
135
+ - **Wallets:** Stored locally (e.g. `~/.aptos-agent-wallets.json`, `~/.evm-wallets.json`); private keys not logged or sent except as signed payloads to the facilitator.
136
+ - **Payments:** Only verify/settle go to the facilitator; no custody of funds by the MCP server.
137
+ - **Whitelist:** Agent addresses must be allowlisted at the onboarding flow before paid tools succeed.
138
+
139
+ ## Capability + adapters
140
+
141
+ - **Capability:** Core (`src/`) — MCP client, x402 flow, local tools. No OpenAI/Claw/Anthropic logic in code.
142
+ - **Adapters:** `adapters/` — how each platform uses the capability:
143
+ - [adapters/openclaw/SKILL.md](adapters/openclaw/SKILL.md) — OpenClaw / Moltbot
144
+ - [adapters/openai/openapi.yaml](adapters/openai/openapi.yaml) — Custom GPTs / Assistants
145
+ - [adapters/anthropic/tools.json](adapters/anthropic/tools.json) — Claude tools
146
+ - [adapters/local/README.md](adapters/local/README.md) — LM Studio, AutoGen, CrewAI
147
+
148
+ ## Deployment order
149
+
150
+ 1. **x402 facilitator** — Use public (e.g. https://x402-navy.vercel.app/facilitator) for full demo; or run local and set X402_EVM_FACILITATOR_URL to public for open_bank_account.
151
+ 2. **MCP server** — x402-enabled (run locally or use Replit MCP URL).
152
+ 3. **Agent** — `node src/run-agent.js` or PM2 (`pm2 start ecosystem.config.cjs --only agent-autonomous` from repo root).
153
+
154
+ ## References
155
+
156
+ - [Canteen App – Aptos x402](https://canteenapp-aptos-x402.notion.site/) — wallet hydration and crediting
157
+ - [LangChain.js MCP](https://js.langchain.com/docs/integrations/toolkits/mcp_toolbox)
158
+ - [Hugging Face Inference – OpenAI-compatible](https://huggingface.co/docs/api-inference/en/index)
159
+ - [evm-wallet-skill](https://github.com/surfer77/evm-wallet-skill) — self-sovereign EVM wallet pattern for agents
160
+
161
+ ## License
162
+
163
+ GPL-2.0-only. Use of this software is also subject to the [Responsible AI License (RAIL)](https://www.licenses.ai/). See [LICENSE.md](../LICENSE.md) (GPL-2) and [RAIL](https://www.licenses.ai/).