stuntman 0.2.1 → 0.2.3
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 +20 -2
- package/dist/cli.js +119 -9
- package/dist/eliza.js +131 -0
- package/dist/game.js +2 -84
- package/dist/practice.js +87 -0
- package/dist/version.js +1 -1
- package/dist/witness.js +53 -0
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -93,7 +93,9 @@ npx stuntman fund ETH 2
|
|
|
93
93
|
npx stuntman fund 0xTokenAddress 500
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
##
|
|
96
|
+
## Agent frameworks
|
|
97
|
+
|
|
98
|
+
### Virtuals GAME
|
|
97
99
|
|
|
98
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:
|
|
99
101
|
|
|
@@ -104,6 +106,21 @@ workers: [await stuntmanWorker({ endpoint: process.env.STUNTMAN_ENDPOINT })]
|
|
|
104
106
|
|
|
105
107
|
`stuntman connect virtuals` prints both setups.
|
|
106
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
|
+
### Priors
|
|
117
|
+
|
|
118
|
+
Point Priors' MCP server at a Stuntman endpoint and its on-chain transactions (borrows, stock trades) are practiced, never broadcast. Keep `PRIORS_MAX_SPEND_USD=0` while practicing: `pay_url` pays over HTTPS, outside any RPC. Repaying a practice loan isn't carried forward yet. `stuntman connect priors` prints the setup, and every Stuntman record also shows the agent's Priors credit record.
|
|
119
|
+
|
|
120
|
+
### OpenClaw
|
|
121
|
+
|
|
122
|
+
The Stuntman skill is in `skills/stuntman`. Until it is listed on ClawHub, copy that folder into `~/.openclaw/skills/`.
|
|
123
|
+
|
|
107
124
|
## Witnessed practice
|
|
108
125
|
|
|
109
126
|
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.
|
|
@@ -122,13 +139,14 @@ Agents that send their own transactions use the printed endpoint as their RPC ad
|
|
|
122
139
|
stuntman init --address <wallet> | --new [--rpc <url>] [--eth <amount>]
|
|
123
140
|
stuntman mcp MCP server over stdio
|
|
124
141
|
stuntman rpc [--port 8545] Practice RPC
|
|
125
|
-
stuntman connect [claude|codex|json|raxol|virtuals]
|
|
142
|
+
stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw|priors]
|
|
126
143
|
stuntman takes [--limit 20] [--json]
|
|
127
144
|
stuntman take <id> [--json]
|
|
128
145
|
stuntman balances [token ...]
|
|
129
146
|
stuntman fund ETH <amount> | <token> <amount>
|
|
130
147
|
stuntman status Account, simulation mode, go-live checklist
|
|
131
148
|
stuntman witness [off] Witnessed practice on Stuntman's server
|
|
149
|
+
stuntman send --to <address> [--value <eth>] [--data 0x...]
|
|
132
150
|
stuntman reset --yes
|
|
133
151
|
stuntman doctor What your RPC supports
|
|
134
152
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Stuntman command line. `npx stuntman` with no arguments shows where you are.
|
|
3
|
-
import { existsSync } from 'node:fs';
|
|
3
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
4
5
|
import { parseUnits } from 'viem';
|
|
5
6
|
import { generatePrivateKey, privateKeyToAccount } from 'viem/accounts';
|
|
6
7
|
import { DEFAULT_PORT, DEFAULT_RPC_URL, configPath, xochiUrl, loadConfig, requireConfig, saveConfig, stuntmanHome, } from './config.js';
|
|
7
8
|
import { RpcClient } from './rpc.js';
|
|
8
9
|
import { checksum, fmt, isAddr, readTokenInfo, PERMIT2_ADDRESS } from './chain.js';
|
|
9
10
|
import { detectCapabilities, describeCapabilities } from './caps.js';
|
|
10
|
-
import { balances, createEngine, fund } from './engine.js';
|
|
11
|
+
import { balances, createEngine, fund, runTake, TakeRejected } from './engine.js';
|
|
11
12
|
import { readState, readTakes, resetPractice, statePath, takesPath, writeState } from './store.js';
|
|
12
13
|
import { formatTake, readiness } from './report.js';
|
|
13
14
|
import { startProxy } from './proxy.js';
|
|
@@ -56,7 +57,7 @@ Start
|
|
|
56
57
|
Connect your agent
|
|
57
58
|
stuntman mcp Practice wallet as an MCP server (stdio)
|
|
58
59
|
stuntman rpc [--port 8545] Practice RPC for agents that send their own transactions
|
|
59
|
-
stuntman connect [claude|codex|json|raxol|virtuals] Print the setup line for your agent
|
|
60
|
+
stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw|priors] Print the setup line for your agent
|
|
60
61
|
|
|
61
62
|
Watch the takes
|
|
62
63
|
stuntman takes [--limit 20] Recent takes
|
|
@@ -69,6 +70,12 @@ Witnessed practice
|
|
|
69
70
|
on a public record. The MCP tools switch over to it.
|
|
70
71
|
stuntman witness off Go back to practicing on this machine only
|
|
71
72
|
stuntman witness --key-env VAR Sign up an agent's own wallet (key read from env VAR)
|
|
73
|
+
stuntman witness --key-file PATH The same, with the key read from a file
|
|
74
|
+
|
|
75
|
+
Practice a transaction
|
|
76
|
+
stuntman send --to <address> [--value <eth>] [--data 0x...]
|
|
77
|
+
One practice take from the command line (witnessed when
|
|
78
|
+
witness mode is on). Nothing is broadcast.
|
|
72
79
|
|
|
73
80
|
Practice money
|
|
74
81
|
stuntman fund ETH <amount>
|
|
@@ -108,6 +115,40 @@ function connectLines(target) {
|
|
|
108
115
|
'# In code, the Xochi config raxol_payments takes:',
|
|
109
116
|
`%{base_url: "http://127.0.0.1:${DEFAULT_PORT}/xochi", auth: {:member, token}}`,
|
|
110
117
|
].join('\n');
|
|
118
|
+
case 'priors':
|
|
119
|
+
return [
|
|
120
|
+
'# Priors agents: rehearse borrows, repays and stock trades before they are real.',
|
|
121
|
+
'# 1. Sign the agent wallet up for witnessed practice (key read from the file, never printed):',
|
|
122
|
+
`${installed ? 'stuntman' : 'npx stuntman'} witness --key-file ~/.priors/agent.key`,
|
|
123
|
+
'',
|
|
124
|
+
'# 2. Run the Priors MCP server against the endpoint it prints, with payments switched off:',
|
|
125
|
+
'PRIORS_RPC=<the endpoint>',
|
|
126
|
+
'PRIORS_MAX_SPEND_USD=0',
|
|
127
|
+
'',
|
|
128
|
+
'# PRIORS_MAX_SPEND_USD=0 matters: pay_url pays x402 APIs over HTTPS, outside any RPC,',
|
|
129
|
+
'# so Stuntman cannot catch it. Every on-chain transaction the server sends is practiced.',
|
|
130
|
+
`# For local practice instead of witnessed, run "${installed ? 'stuntman' : 'npx stuntman'} rpc" and use http://127.0.0.1:8545.`,
|
|
131
|
+
].join('\n');
|
|
132
|
+
case 'eliza':
|
|
133
|
+
return [
|
|
134
|
+
'# ElizaOS agents: add the Stuntman plugin and give it an endpoint.',
|
|
135
|
+
'npm install stuntman',
|
|
136
|
+
"import { stuntmanPlugin } from 'stuntman/eliza';",
|
|
137
|
+
'// character: plugins: [stuntmanPlugin],',
|
|
138
|
+
"// settings: { secrets: { STUNTMAN_ENDPOINT: '<witness endpoint or http://127.0.0.1:8545>' } }",
|
|
139
|
+
'',
|
|
140
|
+
`# Get a witness endpoint with "${installed ? 'stuntman' : 'npx stuntman'} witness" (or witness --key-env for the agent's own wallet).`,
|
|
141
|
+
].join('\n');
|
|
142
|
+
case 'openclaw':
|
|
143
|
+
return [
|
|
144
|
+
'# OpenClaw: add the Stuntman skill, then ask your agent to practice a trade first.',
|
|
145
|
+
'# Until it is listed on ClawHub, copy it from the repository:',
|
|
146
|
+
'git clone https://github.com/stuntmanhq/stuntman',
|
|
147
|
+
'cp -r stuntman/skills/stuntman ~/.openclaw/skills/',
|
|
148
|
+
'',
|
|
149
|
+
'# Or connect the MCP server directly:',
|
|
150
|
+
json,
|
|
151
|
+
].join('\n');
|
|
111
152
|
case 'virtuals':
|
|
112
153
|
return [
|
|
113
154
|
'# Virtuals GAME agents, two ways (use a witness endpoint to put takes on a public record):',
|
|
@@ -131,7 +172,7 @@ function connectLines(target) {
|
|
|
131
172
|
'',
|
|
132
173
|
`Agents that send their own transactions: run "${rpc}" and use http://127.0.0.1:${DEFAULT_PORT} as the RPC address.`,
|
|
133
174
|
`Raxol agents: run "${rpc}", then "${installed ? 'stuntman' : 'npx stuntman'} connect raxol" for the two settings.`,
|
|
134
|
-
`Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals".`,
|
|
175
|
+
`Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals". ElizaOS: "connect eliza". OpenClaw: "connect openclaw". Priors: "connect priors".`,
|
|
135
176
|
].join('\n');
|
|
136
177
|
}
|
|
137
178
|
}
|
|
@@ -341,11 +382,25 @@ async function cmdWitness(args, flags) {
|
|
|
341
382
|
// An agent's own wallet (for example a Virtuals agent's WALLET_PRIVATE_KEY):
|
|
342
383
|
// register it without touching this machine's practice settings. The key is
|
|
343
384
|
// read from an environment variable so it never appears in the command line.
|
|
344
|
-
if (typeof flags['key-env'] === 'string') {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
385
|
+
if (typeof flags['key-env'] === 'string' || typeof flags['key-file'] === 'string') {
|
|
386
|
+
let key;
|
|
387
|
+
if (typeof flags['key-file'] === 'string') {
|
|
388
|
+
const path = flags['key-file'].replace(/^~(?=$|[\\/])/, homedir());
|
|
389
|
+
try {
|
|
390
|
+
key = readFileSync(path, 'utf8');
|
|
391
|
+
}
|
|
392
|
+
catch {
|
|
393
|
+
throw new Error(`Could not read the key file ${path}.`);
|
|
394
|
+
}
|
|
395
|
+
if (!/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
|
|
396
|
+
throw new Error(`${path} does not hold a private key (64 hex characters).`);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
const name = flags['key-env'];
|
|
400
|
+
key = process.env[name];
|
|
401
|
+
if (!key || !/^(0x)?[0-9a-fA-F]{64}$/.test(key.trim()))
|
|
402
|
+
throw new Error(`Set ${name} to the agent's private key first. It is only used to sign the sign-up message.`);
|
|
403
|
+
}
|
|
349
404
|
const k = (key.trim().startsWith('0x') ? key.trim() : `0x${key.trim()}`);
|
|
350
405
|
const { account, endpoint } = await registerWitness({ version: 1, rpcUrl: '', chainId: 0, account: '0x0000000000000000000000000000000000000000', mode: 'practice-key', practiceKey: k, createdAt: '' });
|
|
351
406
|
out(`Witnessed practice is on for ${account}.`);
|
|
@@ -388,6 +443,59 @@ async function cmdWitness(args, flags) {
|
|
|
388
443
|
: `Witnessing is free while billing is off. Once it starts, each agent keeps ${conf.freeTakes} free takes.`);
|
|
389
444
|
}
|
|
390
445
|
}
|
|
446
|
+
async function cmdSend(flags) {
|
|
447
|
+
const cfg = requireConfig();
|
|
448
|
+
const to = typeof flags.to === 'string' ? flags.to : undefined;
|
|
449
|
+
if (to !== undefined && !/^0x[0-9a-fA-F]{40}$/.test(to))
|
|
450
|
+
throw new Error('--to must be an address: 0x followed by 40 characters.');
|
|
451
|
+
const data = typeof flags.data === 'string' ? flags.data : '0x';
|
|
452
|
+
if (!/^0x([0-9a-fA-F]{2})*$/.test(data))
|
|
453
|
+
throw new Error('--data must be hex, starting with 0x.');
|
|
454
|
+
if (to === undefined && data === '0x')
|
|
455
|
+
throw new Error('Give --to <address>, or --data with contract creation code to deploy.');
|
|
456
|
+
const value = typeof flags.value === 'string' ? parseUnits(flags.value, 18) : 0n;
|
|
457
|
+
if (cfg.witness) {
|
|
458
|
+
const tx = { from: cfg.account, data, value: `0x${value.toString(16)}` };
|
|
459
|
+
if (to)
|
|
460
|
+
tx.to = to;
|
|
461
|
+
let hash;
|
|
462
|
+
try {
|
|
463
|
+
hash = await remoteCall(cfg.witness, 'eth_sendTransaction', [tx]);
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
const latest = (await remoteTakes(cfg.witness, 1).catch(() => []))[0];
|
|
467
|
+
if (latest?.status === 'rejected' && Date.now() - Date.parse(latest.at) < 15_000) {
|
|
468
|
+
out(formatTake(latest));
|
|
469
|
+
process.exitCode = 1;
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
throw err;
|
|
473
|
+
}
|
|
474
|
+
const take = (await remoteTakes(cfg.witness, 5)).find((t) => t.txHash.toLowerCase() === hash.toLowerCase());
|
|
475
|
+
if (take)
|
|
476
|
+
out(formatTake(take));
|
|
477
|
+
out('Witnessed by Stuntman. Nothing was broadcast.');
|
|
478
|
+
if (take && take.status !== 'filled')
|
|
479
|
+
process.exitCode = 1;
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
const engine = await createEngine(cfg);
|
|
483
|
+
try {
|
|
484
|
+
const take = await runTake(engine, { from: cfg.account, to: to ?? null, data: data, value, source: 'cli' });
|
|
485
|
+
out(formatTake(take));
|
|
486
|
+
out('Nothing was broadcast.');
|
|
487
|
+
if (take.status !== 'filled')
|
|
488
|
+
process.exitCode = 1;
|
|
489
|
+
}
|
|
490
|
+
catch (err) {
|
|
491
|
+
if (err instanceof TakeRejected) {
|
|
492
|
+
out(formatTake(err.take));
|
|
493
|
+
process.exitCode = 1;
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
throw err;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
391
499
|
async function cmdMcp() {
|
|
392
500
|
const cfg = requireConfig();
|
|
393
501
|
const engine = await createEngine(cfg);
|
|
@@ -430,6 +538,8 @@ async function main() {
|
|
|
430
538
|
return out(connectLines(args[0] ?? 'all'));
|
|
431
539
|
case 'witness':
|
|
432
540
|
return cmdWitness(args, flags);
|
|
541
|
+
case 'send':
|
|
542
|
+
return cmdSend(flags);
|
|
433
543
|
default:
|
|
434
544
|
throw new Error(`Unknown command "${cmd}". Run "stuntman help".`);
|
|
435
545
|
}
|
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
CHANGED
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
// played out at the latest block with practice money and never broadcast. With
|
|
15
15
|
// a witness endpoint (from `stuntman witness`), every take is also signed and
|
|
16
16
|
// kept on the agent's public record.
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
import { remoteCall, RemoteError } from './remote.js';
|
|
17
|
+
import { practiceActions } from './practice.js';
|
|
18
|
+
export { practiceActions } from './practice.js';
|
|
20
19
|
async function loadGame() {
|
|
21
20
|
const name = '@virtuals-protocol/game';
|
|
22
21
|
try {
|
|
@@ -26,87 +25,6 @@ async function loadGame() {
|
|
|
26
25
|
throw new Error('stuntman/game needs the Virtuals GAME SDK. Install it with: npm install @virtuals-protocol/game');
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
const isAddress = (s) => typeof s === 'string' && /^0x[0-9a-fA-F]{40}$/.test(s);
|
|
30
|
-
/** The practice functions as plain async functions, independent of the GAME SDK. */
|
|
31
|
-
export function practiceActions(endpoint) {
|
|
32
|
-
const call = (method, params = []) => remoteCall(endpoint, method, params);
|
|
33
|
-
let account = null;
|
|
34
|
-
const who = async () => (account ??= (await call('stuntman_status')).account);
|
|
35
|
-
return {
|
|
36
|
-
async status() {
|
|
37
|
-
const s = await call('stuntman_status');
|
|
38
|
-
const takes = await call('stuntman_takes', [200]);
|
|
39
|
-
const filled = takes.filter((t) => t.status === 'filled').length;
|
|
40
|
-
const failed = takes.filter((t) => t.status === 'reverted').length;
|
|
41
|
-
const witnessed = /\/w\/[0-9a-f]{48}$/.test(endpoint);
|
|
42
|
-
return [
|
|
43
|
-
`Practicing as ${s.account} on chain ${s.chainId}. Nothing is ever broadcast.`,
|
|
44
|
-
`Recent takes: ${takes.length} (${filled} filled, ${failed} failed).`,
|
|
45
|
-
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.',
|
|
46
|
-
].join('\n');
|
|
47
|
-
},
|
|
48
|
-
async balances() {
|
|
49
|
-
const rows = await call('stuntman_balances');
|
|
50
|
-
return rows.map((r) => `${r.symbol}: ${r.formatted}${r.practice ? '' : ' (real balance)'}${r.token === 'ETH' ? '' : ` [${r.token}]`}`).join('\n');
|
|
51
|
-
},
|
|
52
|
-
async send(to, data, value) {
|
|
53
|
-
const from = await who();
|
|
54
|
-
const tx = { from, data: data && /^0x[0-9a-fA-F]*$/.test(data) ? data : '0x' };
|
|
55
|
-
if (to) {
|
|
56
|
-
if (!isAddress(to))
|
|
57
|
-
return { ok: false, text: 'to must be a contract or wallet address (0x followed by 40 characters), or empty to deploy a contract.' };
|
|
58
|
-
tx.to = to;
|
|
59
|
-
}
|
|
60
|
-
if (value) {
|
|
61
|
-
if (!/^[0-9]+$/.test(value))
|
|
62
|
-
return { ok: false, text: 'value must be a whole number of wei, for example 50000000000000000 for 0.05 ETH.' };
|
|
63
|
-
tx.value = `0x${BigInt(value).toString(16)}`;
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
const hash = await call('eth_sendTransaction', [tx]);
|
|
67
|
-
const take = (await call('stuntman_takes', [5])).find((t) => t.txHash.toLowerCase() === hash.toLowerCase());
|
|
68
|
-
if (!take)
|
|
69
|
-
return { ok: true, text: `Practice transaction ${hash}. Nothing was broadcast.` };
|
|
70
|
-
return { ok: take.status === 'filled', text: `${formatTake(take)}\nNothing was broadcast.` };
|
|
71
|
-
}
|
|
72
|
-
catch (err) {
|
|
73
|
-
const latest = (await call('stuntman_takes', [1]).catch(() => []))[0];
|
|
74
|
-
if (err instanceof RemoteError && latest?.status === 'rejected' && Date.now() - Date.parse(latest.at) < 15_000) {
|
|
75
|
-
return { ok: false, text: `${formatTake(latest)}\nNothing was broadcast.` };
|
|
76
|
-
}
|
|
77
|
-
return { ok: false, text: err.message };
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
async takes(limit = 10) {
|
|
81
|
-
const takes = await call('stuntman_takes', [Math.max(1, Math.min(50, limit))]);
|
|
82
|
-
return takes.length ? takes.map((t) => formatTake(t)).join('\n\n') : 'No takes yet.';
|
|
83
|
-
},
|
|
84
|
-
async fund(asset, amount) {
|
|
85
|
-
if (!asset || !amount)
|
|
86
|
-
return { ok: false, text: 'Give an asset (ETH or a token address) and an amount, for example ETH and 1.' };
|
|
87
|
-
const isEth = asset.toUpperCase() === 'ETH';
|
|
88
|
-
if (!isEth && !isAddress(asset))
|
|
89
|
-
return { ok: false, text: 'asset must be ETH or a token address.' };
|
|
90
|
-
let decimals = 18;
|
|
91
|
-
if (!isEth) {
|
|
92
|
-
const raw = await call('eth_call', [{ to: asset, data: '0x313ce567' }, 'latest']);
|
|
93
|
-
decimals = Number(BigInt(raw));
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
const units = parseUnits(amount, decimals);
|
|
97
|
-
const r = await call('stuntman_fund', [isEth ? 'ETH' : asset, units.toString()]);
|
|
98
|
-
return { ok: true, text: `Added ${amount} ${r.symbol} of practice money.` };
|
|
99
|
-
}
|
|
100
|
-
catch (err) {
|
|
101
|
-
const msg = err.message;
|
|
102
|
-
return {
|
|
103
|
-
ok: false,
|
|
104
|
-
text: /method|not found|unsupported/i.test(msg) ? 'This endpoint does not add practice money. Use "stuntman fund" on the machine running it.' : msg,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
28
|
/** A GAME worker with Stuntman's practice functions. */
|
|
111
29
|
export async function stuntmanWorker(options = {}) {
|
|
112
30
|
const endpoint = options.endpoint ?? process.env.STUNTMAN_ENDPOINT ?? 'http://127.0.0.1:8545';
|
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.3';
|
package/dist/witness.js
CHANGED
|
@@ -377,6 +377,58 @@ async function runBatch(env, account, requests, batch) {
|
|
|
377
377
|
await kv.pipeline(cmds);
|
|
378
378
|
return batch ? out : out[0];
|
|
379
379
|
}
|
|
380
|
+
const howOf = (matchedAs) => {
|
|
381
|
+
const as = Array.isArray(matchedAs) ? matchedAs : [];
|
|
382
|
+
const w = as.includes('declared wallet');
|
|
383
|
+
const o = as.includes('owner');
|
|
384
|
+
return w && o ? 'both' : w ? 'wallet' : o ? 'owner' : null;
|
|
385
|
+
};
|
|
386
|
+
/** Read Priors' check API answer the way Priors itself does (no score, no amounts). */
|
|
387
|
+
export function readPriors(body) {
|
|
388
|
+
const agents = body?.agents;
|
|
389
|
+
if (!Array.isArray(agents))
|
|
390
|
+
return null;
|
|
391
|
+
if (agents.some((x) => x && Number.isInteger(x.agentId) && !howOf(x.matchedAs)))
|
|
392
|
+
return null;
|
|
393
|
+
const seen = new Set();
|
|
394
|
+
const found = [];
|
|
395
|
+
for (const x of agents) {
|
|
396
|
+
if (!x || !Number.isInteger(x.agentId) || seen.has(x.agentId))
|
|
397
|
+
continue;
|
|
398
|
+
seen.add(x.agentId);
|
|
399
|
+
const n = Number(x.record?.loansRepaid);
|
|
400
|
+
found.push({
|
|
401
|
+
agentId: x.agentId,
|
|
402
|
+
page: `https://priors.trade/agent?id=${x.agentId}`,
|
|
403
|
+
how: howOf(x.matchedAs),
|
|
404
|
+
loansRepaid: Number.isSafeInteger(n) && n >= 0 ? n : 0,
|
|
405
|
+
defaulted: !!x.record?.defaulted,
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
if (!found.length)
|
|
409
|
+
return { none: true };
|
|
410
|
+
return { agents: found.slice(0, 3), more: Math.max(found.length - 3, 0) };
|
|
411
|
+
}
|
|
412
|
+
/** Priors' credit record for an address, cached for ten minutes. */
|
|
413
|
+
export async function priorsRecord(env, address, fetcher = fetch) {
|
|
414
|
+
const key = `w:priors:${lower(address)}`;
|
|
415
|
+
const cached = await env.kv.cmd('GET', key);
|
|
416
|
+
if (cached)
|
|
417
|
+
return JSON.parse(cached);
|
|
418
|
+
let reading = null;
|
|
419
|
+
try {
|
|
420
|
+
const res = await fetcher(`https://priors.trade/api/check?address=${lower(address)}`, { signal: AbortSignal.timeout(4000) });
|
|
421
|
+
if (res.ok)
|
|
422
|
+
reading = readPriors(await res.json());
|
|
423
|
+
}
|
|
424
|
+
catch {
|
|
425
|
+
reading = null;
|
|
426
|
+
}
|
|
427
|
+
// A failed read is not cached, so it is tried again next time.
|
|
428
|
+
if (reading)
|
|
429
|
+
await env.kv.cmd('SET', key, JSON.stringify(reading), 'EX', 600);
|
|
430
|
+
return reading;
|
|
431
|
+
}
|
|
380
432
|
export async function agentRecord(env, address, limit = 50) {
|
|
381
433
|
if (!isAddress(address))
|
|
382
434
|
throw new WitnessError(400, 'address must be an address');
|
|
@@ -399,6 +451,7 @@ export async function agentRecord(env, address, limit = 50) {
|
|
|
399
451
|
counts: { simulated: n('simulated'), filled: n('filled'), reverted: n('reverted'), rejected: n('rejected') },
|
|
400
452
|
charged: (BigInt(agent.charged ?? '0') * scale).toString(),
|
|
401
453
|
witness: witnessAddress(env),
|
|
454
|
+
priors: await priorsRecord(env, a, env.fetcher),
|
|
402
455
|
funds: (fundsRaw ?? []).map((f) => JSON.parse(f)),
|
|
403
456
|
takes: (recentRaw ?? [])
|
|
404
457
|
.map((r) => JSON.parse(r))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stuntman",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"exports": {
|
|
58
58
|
"./game": "./dist/game.js",
|
|
59
|
+
"./eliza": "./dist/eliza.js",
|
|
59
60
|
"./package.json": "./package.json"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|