stuntman 0.2.0 → 0.2.2
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/README.md +26 -1
- package/dist/cli.js +121 -4
- package/dist/eliza.js +131 -0
- package/dist/game.js +91 -0
- package/dist/launch.js +3 -2
- package/dist/practice.js +87 -0
- package/dist/version.js +1 -1
- package/package.json +15 -1
package/README.md
CHANGED
|
@@ -93,6 +93,30 @@ npx stuntman fund ETH 2
|
|
|
93
93
|
npx stuntman fund 0xTokenAddress 500
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
## Agent frameworks
|
|
97
|
+
|
|
98
|
+
### Virtuals GAME
|
|
99
|
+
|
|
100
|
+
Virtuals GAME agents practice two ways. Agents whose plugins send their own transactions: sign the agent wallet up with `stuntman witness --key-env WALLET_PRIVATE_KEY` and point the plugin's `RPC_PROVIDER_URL` at the endpoint it prints. TypeScript GAME agents can also add Stuntman as a worker:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
import { stuntmanWorker } from 'stuntman/game'; // npm install stuntman @virtuals-protocol/game
|
|
104
|
+
workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })]
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
`stuntman connect virtuals` prints both setups.
|
|
108
|
+
|
|
109
|
+
### ElizaOS
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { stuntmanPlugin } from 'stuntman/eliza'; // npm install stuntman
|
|
113
|
+
// character: plugins: [stuntmanPlugin], settings: { secrets: { STUNTMAN_ENDPOINT: '...' } }
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### OpenClaw
|
|
117
|
+
|
|
118
|
+
The Stuntman skill is in `skills/stuntman`. Until it is listed on ClawHub, copy that folder into `~/.openclaw/skills/`.
|
|
119
|
+
|
|
96
120
|
## Witnessed practice
|
|
97
121
|
|
|
98
122
|
Practice on your own machine is private, so nobody else can trust it. `stuntman witness` moves your agent's takes to Stuntman's server: each one is simulated at the latest block, signed by the witness and added to a public record at `stuntmanhq.xyz/a/<address>`. Takes are only ever added, never removed.
|
|
@@ -111,13 +135,14 @@ Agents that send their own transactions use the printed endpoint as their RPC ad
|
|
|
111
135
|
stuntman init --address <wallet> | --new [--rpc <url>] [--eth <amount>]
|
|
112
136
|
stuntman mcp MCP server over stdio
|
|
113
137
|
stuntman rpc [--port 8545] Practice RPC
|
|
114
|
-
stuntman connect [claude|codex|json|raxol]
|
|
138
|
+
stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw]
|
|
115
139
|
stuntman takes [--limit 20] [--json]
|
|
116
140
|
stuntman take <id> [--json]
|
|
117
141
|
stuntman balances [token ...]
|
|
118
142
|
stuntman fund ETH <amount> | <token> <amount>
|
|
119
143
|
stuntman status Account, simulation mode, go-live checklist
|
|
120
144
|
stuntman witness [off] Witnessed practice on Stuntman's server
|
|
145
|
+
stuntman send --to <address> [--value <eth>] [--data 0x...]
|
|
121
146
|
stuntman reset --yes
|
|
122
147
|
stuntman doctor What your RPC supports
|
|
123
148
|
```
|
package/dist/cli.js
CHANGED
|
@@ -7,7 +7,7 @@ import { DEFAULT_PORT, DEFAULT_RPC_URL, configPath, xochiUrl, loadConfig, requir
|
|
|
7
7
|
import { RpcClient } from './rpc.js';
|
|
8
8
|
import { checksum, fmt, isAddr, readTokenInfo, PERMIT2_ADDRESS } from './chain.js';
|
|
9
9
|
import { detectCapabilities, describeCapabilities } from './caps.js';
|
|
10
|
-
import { balances, createEngine, fund } from './engine.js';
|
|
10
|
+
import { balances, createEngine, fund, runTake, TakeRejected } from './engine.js';
|
|
11
11
|
import { readState, readTakes, resetPractice, statePath, takesPath, writeState } from './store.js';
|
|
12
12
|
import { formatTake, readiness } from './report.js';
|
|
13
13
|
import { startProxy } from './proxy.js';
|
|
@@ -56,7 +56,7 @@ Start
|
|
|
56
56
|
Connect your agent
|
|
57
57
|
stuntman mcp Practice wallet as an MCP server (stdio)
|
|
58
58
|
stuntman rpc [--port 8545] Practice RPC for agents that send their own transactions
|
|
59
|
-
stuntman connect [claude|codex|json|raxol] Print the setup line for your agent
|
|
59
|
+
stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw] Print the setup line for your agent
|
|
60
60
|
|
|
61
61
|
Watch the takes
|
|
62
62
|
stuntman takes [--limit 20] Recent takes
|
|
@@ -68,6 +68,12 @@ Witnessed practice
|
|
|
68
68
|
stuntman witness Practice on Stuntman's server: every take signed and kept
|
|
69
69
|
on a public record. The MCP tools switch over to it.
|
|
70
70
|
stuntman witness off Go back to practicing on this machine only
|
|
71
|
+
stuntman witness --key-env VAR Sign up an agent's own wallet (key read from env VAR)
|
|
72
|
+
|
|
73
|
+
Practice a transaction
|
|
74
|
+
stuntman send --to <address> [--value <eth>] [--data 0x...]
|
|
75
|
+
One practice take from the command line (witnessed when
|
|
76
|
+
witness mode is on). Nothing is broadcast.
|
|
71
77
|
|
|
72
78
|
Practice money
|
|
73
79
|
stuntman fund ETH <amount>
|
|
@@ -107,6 +113,40 @@ function connectLines(target) {
|
|
|
107
113
|
'# In code, the Xochi config raxol_payments takes:',
|
|
108
114
|
`%{base_url: "http://127.0.0.1:${DEFAULT_PORT}/xochi", auth: {:member, token}}`,
|
|
109
115
|
].join('\n');
|
|
116
|
+
case 'eliza':
|
|
117
|
+
return [
|
|
118
|
+
'# ElizaOS agents: add the Stuntman plugin and give it an endpoint.',
|
|
119
|
+
'npm install stuntman',
|
|
120
|
+
"import { stuntmanPlugin } from 'stuntman/eliza';",
|
|
121
|
+
'// character: plugins: [stuntmanPlugin],',
|
|
122
|
+
"// settings: { secrets: { STUNTMAN_ENDPOINT: '<witness endpoint or http://127.0.0.1:8545>' } }",
|
|
123
|
+
'',
|
|
124
|
+
`# Get a witness endpoint with "${installed ? 'stuntman' : 'npx stuntman'} witness" (or witness --key-env for the agent's own wallet).`,
|
|
125
|
+
].join('\n');
|
|
126
|
+
case 'openclaw':
|
|
127
|
+
return [
|
|
128
|
+
'# OpenClaw: add the Stuntman skill, then ask your agent to practice a trade first.',
|
|
129
|
+
'# Until it is listed on ClawHub, copy it from the repository:',
|
|
130
|
+
'git clone https://github.com/stuntmanhq/stuntman',
|
|
131
|
+
'cp -r stuntman/skills/stuntman ~/.openclaw/skills/',
|
|
132
|
+
'',
|
|
133
|
+
'# Or connect the MCP server directly:',
|
|
134
|
+
json,
|
|
135
|
+
].join('\n');
|
|
136
|
+
case 'virtuals':
|
|
137
|
+
return [
|
|
138
|
+
'# Virtuals GAME agents, two ways (use a witness endpoint to put takes on a public record):',
|
|
139
|
+
'',
|
|
140
|
+
'# 1. Agents whose plugins send their own transactions (RPC_PROVIDER_URL + WALLET_PRIVATE_KEY):',
|
|
141
|
+
'# register the agent wallet with the witness, then point the plugin RPC at the endpoint it prints.',
|
|
142
|
+
`${installed ? 'stuntman' : 'npx stuntman'} witness --key-env WALLET_PRIVATE_KEY`,
|
|
143
|
+
'RPC_PROVIDER_URL=<the endpoint>',
|
|
144
|
+
'',
|
|
145
|
+
'# 2. Give the agent Stuntman practice functions as a GAME worker:',
|
|
146
|
+
'npm install stuntman @virtuals-protocol/game',
|
|
147
|
+
"import { stuntmanWorker } from 'stuntman/game';",
|
|
148
|
+
'workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })]',
|
|
149
|
+
].join('\n');
|
|
110
150
|
default:
|
|
111
151
|
return [
|
|
112
152
|
`Claude Code: claude mcp add stuntman -- ${shellLine}`,
|
|
@@ -116,6 +156,7 @@ function connectLines(target) {
|
|
|
116
156
|
'',
|
|
117
157
|
`Agents that send their own transactions: run "${rpc}" and use http://127.0.0.1:${DEFAULT_PORT} as the RPC address.`,
|
|
118
158
|
`Raxol agents: run "${rpc}", then "${installed ? 'stuntman' : 'npx stuntman'} connect raxol" for the two settings.`,
|
|
159
|
+
`Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals". ElizaOS: "connect eliza". OpenClaw: "connect openclaw".`,
|
|
119
160
|
].join('\n');
|
|
120
161
|
}
|
|
121
162
|
}
|
|
@@ -321,7 +362,28 @@ async function cmdRpc(flags) {
|
|
|
321
362
|
err(`Xochi practice gateway on http://${host}:${port}/xochi (quotes from ${xochiUrl()}, executes stay here).`);
|
|
322
363
|
err('Press Ctrl+C to stop.');
|
|
323
364
|
}
|
|
324
|
-
async function cmdWitness(args) {
|
|
365
|
+
async function cmdWitness(args, flags) {
|
|
366
|
+
// An agent's own wallet (for example a Virtuals agent's WALLET_PRIVATE_KEY):
|
|
367
|
+
// register it without touching this machine's practice settings. The key is
|
|
368
|
+
// read from an environment variable so it never appears in the command line.
|
|
369
|
+
if (typeof flags['key-env'] === 'string') {
|
|
370
|
+
const name = flags['key-env'];
|
|
371
|
+
const key = process.env[name];
|
|
372
|
+
if (!key || !/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
|
|
373
|
+
throw new Error(`Set ${name} to the agent's private key first. It is only used to sign the sign-up message.`);
|
|
374
|
+
const k = (key.trim().startsWith('0x') ? key.trim() : `0x${key.trim()}`);
|
|
375
|
+
const { account, endpoint } = await registerWitness({ version: 1, rpcUrl: '', chainId: 0, account: '0x0000000000000000000000000000000000000000', mode: 'practice-key', practiceKey: k, createdAt: '' });
|
|
376
|
+
out(`Witnessed practice is on for ${account}.`);
|
|
377
|
+
out('');
|
|
378
|
+
out('Endpoint (keep it private, it is your agent\'s key to the record). Use it as the agent\'s RPC address:');
|
|
379
|
+
out(` ${endpoint}`);
|
|
380
|
+
out('Public record:');
|
|
381
|
+
out(` ${witnessBase()}/a/${account}`);
|
|
382
|
+
out('');
|
|
383
|
+
out('The agent signs as usual; Stuntman simulates every transaction it sends there and broadcasts nothing.');
|
|
384
|
+
out('Practice money for this agent: the endpoint accepts stuntman_fund, or use the GAME worker\'s add_practice_money.');
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
325
387
|
const cfg = requireConfig();
|
|
326
388
|
if (args[0] === 'off') {
|
|
327
389
|
delete cfg.witness;
|
|
@@ -351,6 +413,59 @@ async function cmdWitness(args) {
|
|
|
351
413
|
: `Witnessing is free while billing is off. Once it starts, each agent keeps ${conf.freeTakes} free takes.`);
|
|
352
414
|
}
|
|
353
415
|
}
|
|
416
|
+
async function cmdSend(flags) {
|
|
417
|
+
const cfg = requireConfig();
|
|
418
|
+
const to = typeof flags.to === 'string' ? flags.to : undefined;
|
|
419
|
+
if (to !== undefined && !/^0x[0-9a-fA-F]{40}$/.test(to))
|
|
420
|
+
throw new Error('--to must be an address: 0x followed by 40 characters.');
|
|
421
|
+
const data = typeof flags.data === 'string' ? flags.data : '0x';
|
|
422
|
+
if (!/^0x([0-9a-fA-F]{2})*$/.test(data))
|
|
423
|
+
throw new Error('--data must be hex, starting with 0x.');
|
|
424
|
+
if (to === undefined && data === '0x')
|
|
425
|
+
throw new Error('Give --to <address>, or --data with contract creation code to deploy.');
|
|
426
|
+
const value = typeof flags.value === 'string' ? parseUnits(flags.value, 18) : 0n;
|
|
427
|
+
if (cfg.witness) {
|
|
428
|
+
const tx = { from: cfg.account, data, value: `0x${value.toString(16)}` };
|
|
429
|
+
if (to)
|
|
430
|
+
tx.to = to;
|
|
431
|
+
let hash;
|
|
432
|
+
try {
|
|
433
|
+
hash = await remoteCall(cfg.witness, 'eth_sendTransaction', [tx]);
|
|
434
|
+
}
|
|
435
|
+
catch (err) {
|
|
436
|
+
const latest = (await remoteTakes(cfg.witness, 1).catch(() => []))[0];
|
|
437
|
+
if (latest?.status === 'rejected' && Date.now() - Date.parse(latest.at) < 15_000) {
|
|
438
|
+
out(formatTake(latest));
|
|
439
|
+
process.exitCode = 1;
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
throw err;
|
|
443
|
+
}
|
|
444
|
+
const take = (await remoteTakes(cfg.witness, 5)).find((t) => t.txHash.toLowerCase() === hash.toLowerCase());
|
|
445
|
+
if (take)
|
|
446
|
+
out(formatTake(take));
|
|
447
|
+
out('Witnessed by Stuntman. Nothing was broadcast.');
|
|
448
|
+
if (take && take.status !== 'filled')
|
|
449
|
+
process.exitCode = 1;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
const engine = await createEngine(cfg);
|
|
453
|
+
try {
|
|
454
|
+
const take = await runTake(engine, { from: cfg.account, to: to ?? null, data: data, value, source: 'cli' });
|
|
455
|
+
out(formatTake(take));
|
|
456
|
+
out('Nothing was broadcast.');
|
|
457
|
+
if (take.status !== 'filled')
|
|
458
|
+
process.exitCode = 1;
|
|
459
|
+
}
|
|
460
|
+
catch (err) {
|
|
461
|
+
if (err instanceof TakeRejected) {
|
|
462
|
+
out(formatTake(err.take));
|
|
463
|
+
process.exitCode = 1;
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
throw err;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
354
469
|
async function cmdMcp() {
|
|
355
470
|
const cfg = requireConfig();
|
|
356
471
|
const engine = await createEngine(cfg);
|
|
@@ -392,7 +507,9 @@ async function main() {
|
|
|
392
507
|
case 'connect':
|
|
393
508
|
return out(connectLines(args[0] ?? 'all'));
|
|
394
509
|
case 'witness':
|
|
395
|
-
return cmdWitness(args);
|
|
510
|
+
return cmdWitness(args, flags);
|
|
511
|
+
case 'send':
|
|
512
|
+
return cmdSend(flags);
|
|
396
513
|
default:
|
|
397
514
|
throw new Error(`Unknown command "${cmd}". Run "stuntman help".`);
|
|
398
515
|
}
|
package/dist/eliza.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Stuntman for ElizaOS agents.
|
|
2
|
+
//
|
|
3
|
+
// import { stuntmanPlugin } from 'stuntman/eliza';
|
|
4
|
+
// // character: plugins: [stuntmanPlugin], settings: { secrets: { STUNTMAN_ENDPOINT: '...' } }
|
|
5
|
+
//
|
|
6
|
+
// The plugin gives the agent practice actions on Robinhood Chain: every
|
|
7
|
+
// transaction is played out at the latest block with practice money and never
|
|
8
|
+
// broadcast. With a witness endpoint (from `stuntman witness`), every take is
|
|
9
|
+
// also signed and kept on the agent's public record. It needs nothing from
|
|
10
|
+
// @elizaos/core at runtime, so it works across ElizaOS versions.
|
|
11
|
+
import { practiceActions } from './practice.js';
|
|
12
|
+
function endpointFor(runtime, fallback) {
|
|
13
|
+
const s = runtime.getSetting('STUNTMAN_ENDPOINT');
|
|
14
|
+
return (typeof s === 'string' && s) || fallback || process.env.STUNTMAN_ENDPOINT || 'http://127.0.0.1:8545';
|
|
15
|
+
}
|
|
16
|
+
const ADDRESS = /0x[0-9a-fA-F]{40}(?![0-9a-fA-F])/g;
|
|
17
|
+
const DATA = /\b(0x[0-9a-fA-F]{8,})\b/g;
|
|
18
|
+
/** Read a practice transaction out of plain text: an address, an ETH amount and optional calldata. */
|
|
19
|
+
export function parseSend(text) {
|
|
20
|
+
const addresses = text.match(ADDRESS) ?? [];
|
|
21
|
+
const to = addresses[0];
|
|
22
|
+
const longHex = [...text.matchAll(DATA)].map((m) => m[1]).find((h) => h.length !== 42 && h.length > 10);
|
|
23
|
+
const eth = text.match(/(\d+(?:\.\d+)?)\s*eth\b/i);
|
|
24
|
+
let value;
|
|
25
|
+
if (eth) {
|
|
26
|
+
const [w, f = ''] = eth[1].split('.');
|
|
27
|
+
value = (BigInt(w) * 10n ** 18n + BigInt((f + '0'.repeat(18)).slice(0, 18) || '0')).toString();
|
|
28
|
+
}
|
|
29
|
+
return { to, value, data: longHex };
|
|
30
|
+
}
|
|
31
|
+
/** Read practice money out of plain text, for example "add 1 ETH" or "add 500 0x... tokens". */
|
|
32
|
+
export function parseFund(text) {
|
|
33
|
+
const eth = text.match(/(\d+(?:\.\d+)?)\s*eth\b/i);
|
|
34
|
+
if (eth)
|
|
35
|
+
return { asset: 'ETH', amount: eth[1] };
|
|
36
|
+
const token = text.match(/(\d+(?:\.\d+)?)\s*(?:of\s+)?(0x[0-9a-fA-F]{40})/) ?? null;
|
|
37
|
+
return token ? { asset: token[2], amount: token[1] } : {};
|
|
38
|
+
}
|
|
39
|
+
/** Build the ElizaOS plugin. `stuntmanPlugin` is this with default options. */
|
|
40
|
+
export function createStuntmanPlugin(options = {}) {
|
|
41
|
+
const run = (fn, name) => async (runtime, message, _state, _opts, callback) => {
|
|
42
|
+
const text = message?.content?.text ?? '';
|
|
43
|
+
try {
|
|
44
|
+
const out = await fn(practiceActions(endpointFor(runtime, options.endpoint)), text);
|
|
45
|
+
const ok = typeof out === 'string' ? true : out.ok;
|
|
46
|
+
const body = typeof out === 'string' ? out : out.text;
|
|
47
|
+
await callback?.({ text: body, actions: [name] });
|
|
48
|
+
return ok ? { success: true, text: body } : { success: false, text: body, error: body };
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const msg = err.message;
|
|
52
|
+
await callback?.({ text: `Stuntman: ${msg}`, actions: [name] });
|
|
53
|
+
return { success: false, error: msg };
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const always = async () => true;
|
|
57
|
+
const example = (user, agent, action) => [
|
|
58
|
+
{ name: '{{user}}', content: { text: user } },
|
|
59
|
+
{ name: '{{agent}}', content: { text: agent, actions: [action] } },
|
|
60
|
+
];
|
|
61
|
+
return {
|
|
62
|
+
name: 'stuntman',
|
|
63
|
+
description: 'Practice mode on Robinhood Chain: transactions are simulated at the latest block with real prices and practice money, and never broadcast. With a witness endpoint, every take goes on a public record.',
|
|
64
|
+
config: { STUNTMAN_ENDPOINT: options.endpoint ?? process.env.STUNTMAN_ENDPOINT ?? null },
|
|
65
|
+
actions: [
|
|
66
|
+
{
|
|
67
|
+
name: 'STUNTMAN_PRACTICE_TRANSACTION',
|
|
68
|
+
similes: ['PRACTICE_TRADE', 'PRACTICE_SEND', 'PAPER_TRADE', 'TEST_TRANSACTION', 'SIMULATE_TRANSACTION'],
|
|
69
|
+
description: 'Send a transaction in practice on Robinhood Chain: simulated at the latest block with practice money, never broadcast. The message must contain the target address, and may contain an ETH amount (like 0.05 ETH) and calldata (0x...).',
|
|
70
|
+
validate: async (_r, m) => /0x[0-9a-fA-F]{40}/.test(m?.content?.text ?? ''),
|
|
71
|
+
handler: run(async (a, text) => {
|
|
72
|
+
const { to, value, data } = parseSend(text);
|
|
73
|
+
return a.send(to, data, value);
|
|
74
|
+
}, 'STUNTMAN_PRACTICE_TRANSACTION'),
|
|
75
|
+
examples: [example('Practice sending 0.01 ETH to 0x000000000000000000000000000000000000bEEF', 'Running that as a practice take.', 'STUNTMAN_PRACTICE_TRANSACTION')],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'STUNTMAN_PRACTICE_BALANCES',
|
|
79
|
+
similes: ['PRACTICE_BALANCE', 'PAPER_BALANCES'],
|
|
80
|
+
description: 'Show the practice balances of ETH and tokens. These are practice money, not real funds.',
|
|
81
|
+
validate: always,
|
|
82
|
+
handler: run((a) => a.balances(), 'STUNTMAN_PRACTICE_BALANCES'),
|
|
83
|
+
examples: [example('What are my practice balances?', 'Checking the practice account.', 'STUNTMAN_PRACTICE_BALANCES')],
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'STUNTMAN_PRACTICE_TAKES',
|
|
87
|
+
similes: ['PRACTICE_HISTORY', 'PRACTICE_RECORD', 'LIST_TAKES'],
|
|
88
|
+
description: 'List recent practice takes, newest first, with results and reasons for failures.',
|
|
89
|
+
validate: always,
|
|
90
|
+
handler: run((a, text) => a.takes(Number(text.match(/\b(\d{1,2})\b/)?.[1] ?? 10)), 'STUNTMAN_PRACTICE_TAKES'),
|
|
91
|
+
examples: [example('Show my last 5 practice takes', 'Here are your recent takes.', 'STUNTMAN_PRACTICE_TAKES')],
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'STUNTMAN_PRACTICE_STATUS',
|
|
95
|
+
similes: ['PRACTICE_STATUS'],
|
|
96
|
+
description: 'Show the practice account, recent results and whether takes are witnessed on a public record.',
|
|
97
|
+
validate: always,
|
|
98
|
+
handler: run((a) => a.status(), 'STUNTMAN_PRACTICE_STATUS'),
|
|
99
|
+
examples: [example('Am I practicing?', 'Checking practice status.', 'STUNTMAN_PRACTICE_STATUS')],
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'STUNTMAN_ADD_PRACTICE_MONEY',
|
|
103
|
+
similes: ['FUND_PRACTICE', 'ADD_PAPER_MONEY'],
|
|
104
|
+
description: 'Add practice money on a witness endpoint, for example "add 1 ETH". It shows on the public record.',
|
|
105
|
+
validate: async (_r, m) => /\d\s*(eth\b|of\s+0x|0x)/i.test(m?.content?.text ?? ''),
|
|
106
|
+
handler: run(async (a, text) => {
|
|
107
|
+
const { asset, amount } = parseFund(text);
|
|
108
|
+
return a.fund(asset, amount);
|
|
109
|
+
}, 'STUNTMAN_ADD_PRACTICE_MONEY'),
|
|
110
|
+
examples: [example('Add 1 ETH of practice money', 'Adding practice money.', 'STUNTMAN_ADD_PRACTICE_MONEY')],
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
providers: [
|
|
114
|
+
{
|
|
115
|
+
name: 'STUNTMAN_PRACTICE',
|
|
116
|
+
description: 'Tells the agent it is practicing and what its practice balances are.',
|
|
117
|
+
get: async (runtime) => {
|
|
118
|
+
try {
|
|
119
|
+
const balances = await practiceActions(endpointFor(runtime, options.endpoint)).balances();
|
|
120
|
+
return { text: `You are in practice mode on Robinhood Chain (Stuntman). Nothing you send is broadcast.\nPractice balances:\n${balances}` };
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
return { text: 'You are in practice mode on Robinhood Chain (Stuntman), but the practice endpoint is not reachable right now.' };
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
],
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
export const stuntmanPlugin = createStuntmanPlugin();
|
|
131
|
+
export default stuntmanPlugin;
|
package/dist/game.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Stuntman for Virtuals GAME agents.
|
|
2
|
+
//
|
|
3
|
+
// import { GameAgent } from '@virtuals-protocol/game';
|
|
4
|
+
// import { stuntmanWorker } from 'stuntman/game';
|
|
5
|
+
//
|
|
6
|
+
// const agent = new GameAgent(process.env.GAME_API_KEY, {
|
|
7
|
+
// name: 'My trader',
|
|
8
|
+
// goal: 'Trade on Robinhood Chain',
|
|
9
|
+
// description: '...',
|
|
10
|
+
// workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })],
|
|
11
|
+
// });
|
|
12
|
+
//
|
|
13
|
+
// The worker gives the agent practice functions: every transaction it sends is
|
|
14
|
+
// played out at the latest block with practice money and never broadcast. With
|
|
15
|
+
// a witness endpoint (from `stuntman witness`), every take is also signed and
|
|
16
|
+
// kept on the agent's public record.
|
|
17
|
+
import { practiceActions } from './practice.js';
|
|
18
|
+
export { practiceActions } from './practice.js';
|
|
19
|
+
async function loadGame() {
|
|
20
|
+
const name = '@virtuals-protocol/game';
|
|
21
|
+
try {
|
|
22
|
+
return (await import(name));
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
throw new Error('stuntman/game needs the Virtuals GAME SDK. Install it with: npm install @virtuals-protocol/game');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
/** A GAME worker with Stuntman's practice functions. */
|
|
29
|
+
export async function stuntmanWorker(options = {}) {
|
|
30
|
+
const endpoint = options.endpoint ?? process.env.STUNTMAN_ENDPOINT ?? 'http://127.0.0.1:8545';
|
|
31
|
+
const game = await loadGame();
|
|
32
|
+
const actions = practiceActions(endpoint);
|
|
33
|
+
const done = (text) => new game.ExecutableGameFunctionResponse(game.ExecutableGameFunctionStatus.Done, text);
|
|
34
|
+
const failed = (text) => new game.ExecutableGameFunctionResponse(game.ExecutableGameFunctionStatus.Failed, text);
|
|
35
|
+
const safe = (fn) => async (args) => {
|
|
36
|
+
try {
|
|
37
|
+
const out = await fn(args);
|
|
38
|
+
return typeof out === 'string' ? done(out) : out.ok ? done(out.text) : failed(out.text);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return failed(err.message);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
const functions = [
|
|
45
|
+
new game.GameFunction({
|
|
46
|
+
name: 'practice_status',
|
|
47
|
+
description: 'Show the practice account, recent takes and whether takes are witnessed on a public record.',
|
|
48
|
+
args: [],
|
|
49
|
+
executable: safe(() => actions.status()),
|
|
50
|
+
}),
|
|
51
|
+
new game.GameFunction({
|
|
52
|
+
name: 'practice_balances',
|
|
53
|
+
description: 'Practice balances of ETH and tokens. These are practice money, not real funds.',
|
|
54
|
+
args: [],
|
|
55
|
+
executable: safe(() => actions.balances()),
|
|
56
|
+
}),
|
|
57
|
+
new game.GameFunction({
|
|
58
|
+
name: 'send_practice_transaction',
|
|
59
|
+
description: 'Send a transaction in practice: it is simulated at the latest block of Robinhood Chain with real prices and practice money, and never broadcast. Returns whether it filled or failed and what changed.',
|
|
60
|
+
args: [
|
|
61
|
+
{ name: 'to', description: 'Contract or wallet address. Leave empty to deploy a contract.', optional: true },
|
|
62
|
+
{ name: 'data', description: 'Calldata as 0x hex. Empty for a plain ETH send.', optional: true },
|
|
63
|
+
{ name: 'value', description: 'ETH to send, in wei as a whole number.', optional: true },
|
|
64
|
+
],
|
|
65
|
+
executable: safe((a) => actions.send(a.to, a.data, a.value)),
|
|
66
|
+
}),
|
|
67
|
+
new game.GameFunction({
|
|
68
|
+
name: 'list_practice_takes',
|
|
69
|
+
description: 'Recent practice takes, newest first, with results and reasons for failures.',
|
|
70
|
+
args: [{ name: 'limit', description: 'How many takes, up to 50. Default 10.', optional: true }],
|
|
71
|
+
executable: safe((a) => actions.takes(Number(a.limit ?? 10) || 10)),
|
|
72
|
+
}),
|
|
73
|
+
new game.GameFunction({
|
|
74
|
+
name: 'add_practice_money',
|
|
75
|
+
description: 'Add practice money (witness endpoints only). It shows on the public record.',
|
|
76
|
+
args: [
|
|
77
|
+
{ name: 'asset', description: 'ETH or a token address' },
|
|
78
|
+
{ name: 'amount', description: 'Amount in whole units, for example 1 or 250.5' },
|
|
79
|
+
],
|
|
80
|
+
executable: safe((a) => actions.fund(a.asset, a.amount)),
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
83
|
+
return new game.GameWorker({
|
|
84
|
+
id: options.id ?? 'stuntman_practice',
|
|
85
|
+
name: options.name ?? 'Stuntman practice',
|
|
86
|
+
description: options.description ??
|
|
87
|
+
'Practices trades on Robinhood Chain before they are real: transactions are simulated at the latest block with real prices and practice money, and never broadcast.',
|
|
88
|
+
functions,
|
|
89
|
+
getEnvironment: async () => ({ practice: true, endpoint: new URL(endpoint).origin }),
|
|
90
|
+
});
|
|
91
|
+
}
|
package/dist/launch.js
CHANGED
|
@@ -13,8 +13,9 @@ const addr = (v) => (v && /^0x[0-9a-fA-F]{40}$/.test(v) ? v : null);
|
|
|
13
13
|
export function launchSettings(env = process.env) {
|
|
14
14
|
return {
|
|
15
15
|
...LAUNCH,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
// "none" turns a setting off, for local runs away from Robinhood Chain.
|
|
17
|
+
token: env.STUNTMAN_TOKEN === 'none' ? null : (addr(env.STUNTMAN_TOKEN) ?? LAUNCH.token),
|
|
18
|
+
credits: env.STUNTMAN_CREDITS === 'none' ? null : (addr(env.STUNTMAN_CREDITS) ?? LAUNCH.credits),
|
|
18
19
|
freeTakes: env.STUNTMAN_FREE_TAKES !== undefined ? Number(env.STUNTMAN_FREE_TAKES) : LAUNCH.freeTakes,
|
|
19
20
|
takePriceUsd: env.STUNTMAN_TAKE_PRICE_USD !== undefined ? Number(env.STUNTMAN_TAKE_PRICE_USD) : LAUNCH.takePriceUsd,
|
|
20
21
|
};
|
package/dist/practice.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Practice functions shared by the agent-framework integrations (Virtuals
|
|
2
|
+
// GAME, ElizaOS): each one is a JSON-RPC call to a Stuntman endpoint, either a
|
|
3
|
+
// witness endpoint or a local practice RPC.
|
|
4
|
+
import { parseUnits } from 'viem';
|
|
5
|
+
import { formatTake } from './report.js';
|
|
6
|
+
import { remoteCall, RemoteError } from './remote.js';
|
|
7
|
+
export const isAddress = (s) => typeof s === 'string' && /^0x[0-9a-fA-F]{40}$/.test(s);
|
|
8
|
+
/** The practice functions as plain async functions, independent of the GAME SDK. */
|
|
9
|
+
export function practiceActions(endpoint) {
|
|
10
|
+
const call = (method, params = []) => remoteCall(endpoint, method, params);
|
|
11
|
+
let account = null;
|
|
12
|
+
const who = async () => (account ??= (await call('stuntman_status')).account);
|
|
13
|
+
return {
|
|
14
|
+
async status() {
|
|
15
|
+
const s = await call('stuntman_status');
|
|
16
|
+
const takes = await call('stuntman_takes', [200]);
|
|
17
|
+
const filled = takes.filter((t) => t.status === 'filled').length;
|
|
18
|
+
const failed = takes.filter((t) => t.status === 'reverted').length;
|
|
19
|
+
const witnessed = /\/w\/[0-9a-f]{48}$/.test(endpoint);
|
|
20
|
+
return [
|
|
21
|
+
`Practicing as ${s.account} on chain ${s.chainId}. Nothing is ever broadcast.`,
|
|
22
|
+
`Recent takes: ${takes.length} (${filled} filled, ${failed} failed).`,
|
|
23
|
+
witnessed ? `Witnessed: every take is signed and kept on the public record at ${new URL(endpoint).origin}/a/${s.account}.` : 'Local practice: takes stay on this machine.',
|
|
24
|
+
].join('\n');
|
|
25
|
+
},
|
|
26
|
+
async balances() {
|
|
27
|
+
const rows = await call('stuntman_balances');
|
|
28
|
+
return rows.map((r) => `${r.symbol}: ${r.formatted}${r.practice ? '' : ' (real balance)'}${r.token === 'ETH' ? '' : ` [${r.token}]`}`).join('\n');
|
|
29
|
+
},
|
|
30
|
+
async send(to, data, value) {
|
|
31
|
+
const from = await who();
|
|
32
|
+
const tx = { from, data: data && /^0x[0-9a-fA-F]*$/.test(data) ? data : '0x' };
|
|
33
|
+
if (to) {
|
|
34
|
+
if (!isAddress(to))
|
|
35
|
+
return { ok: false, text: 'to must be a contract or wallet address (0x followed by 40 characters), or empty to deploy a contract.' };
|
|
36
|
+
tx.to = to;
|
|
37
|
+
}
|
|
38
|
+
if (value) {
|
|
39
|
+
if (!/^[0-9]+$/.test(value))
|
|
40
|
+
return { ok: false, text: 'value must be a whole number of wei, for example 50000000000000000 for 0.05 ETH.' };
|
|
41
|
+
tx.value = `0x${BigInt(value).toString(16)}`;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
const hash = await call('eth_sendTransaction', [tx]);
|
|
45
|
+
const take = (await call('stuntman_takes', [5])).find((t) => t.txHash.toLowerCase() === hash.toLowerCase());
|
|
46
|
+
if (!take)
|
|
47
|
+
return { ok: true, text: `Practice transaction ${hash}. Nothing was broadcast.` };
|
|
48
|
+
return { ok: take.status === 'filled', text: `${formatTake(take)}\nNothing was broadcast.` };
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
const latest = (await call('stuntman_takes', [1]).catch(() => []))[0];
|
|
52
|
+
if (err instanceof RemoteError && latest?.status === 'rejected' && Date.now() - Date.parse(latest.at) < 15_000) {
|
|
53
|
+
return { ok: false, text: `${formatTake(latest)}\nNothing was broadcast.` };
|
|
54
|
+
}
|
|
55
|
+
return { ok: false, text: err.message };
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
async takes(limit = 10) {
|
|
59
|
+
const takes = await call('stuntman_takes', [Math.max(1, Math.min(50, limit))]);
|
|
60
|
+
return takes.length ? takes.map((t) => formatTake(t)).join('\n\n') : 'No takes yet.';
|
|
61
|
+
},
|
|
62
|
+
async fund(asset, amount) {
|
|
63
|
+
if (!asset || !amount)
|
|
64
|
+
return { ok: false, text: 'Give an asset (ETH or a token address) and an amount, for example ETH and 1.' };
|
|
65
|
+
const isEth = asset.toUpperCase() === 'ETH';
|
|
66
|
+
if (!isEth && !isAddress(asset))
|
|
67
|
+
return { ok: false, text: 'asset must be ETH or a token address.' };
|
|
68
|
+
let decimals = 18;
|
|
69
|
+
if (!isEth) {
|
|
70
|
+
const raw = await call('eth_call', [{ to: asset, data: '0x313ce567' }, 'latest']);
|
|
71
|
+
decimals = Number(BigInt(raw));
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
const units = parseUnits(amount, decimals);
|
|
75
|
+
const r = await call('stuntman_fund', [isEth ? 'ETH' : asset, units.toString()]);
|
|
76
|
+
return { ok: true, text: `Added ${amount} ${r.symbol} of practice money.` };
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
const msg = err.message;
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
text: /method|not found|unsupported/i.test(msg) ? 'This endpoint does not add practice money. Use "stuntman fund" on the machine running it.' : msg,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.2';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stuntman",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Practice mode for AI agents. Real apps, real prices, practice money. Every send is played out against the live chain and nothing is broadcast.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -50,7 +50,21 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"@foundry-rs/anvil": "^1.7.1",
|
|
52
52
|
"@types/node": "^26.6.11",
|
|
53
|
+
"@virtuals-protocol/game": "^0.1.14",
|
|
53
54
|
"solc": "^0.8.39",
|
|
54
55
|
"typescript": "^7.0.2"
|
|
56
|
+
},
|
|
57
|
+
"exports": {
|
|
58
|
+
"./game": "./dist/game.js",
|
|
59
|
+
"./eliza": "./dist/eliza.js",
|
|
60
|
+
"./package.json": "./package.json"
|
|
61
|
+
},
|
|
62
|
+
"peerDependencies": {
|
|
63
|
+
"@virtuals-protocol/game": ">=0.1.14"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"@virtuals-protocol/game": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
55
69
|
}
|
|
56
70
|
}
|