stuntman 0.2.1 → 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 CHANGED
@@ -93,7 +93,9 @@ npx stuntman fund ETH 2
93
93
  npx stuntman fund 0xTokenAddress 500
94
94
  ```
95
95
 
96
- ## Virtuals agents
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,17 @@ 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
+ ### OpenClaw
117
+
118
+ The Stuntman skill is in `skills/stuntman`. Until it is listed on ClawHub, copy that folder into `~/.openclaw/skills/`.
119
+
107
120
  ## Witnessed practice
108
121
 
109
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.
@@ -122,13 +135,14 @@ Agents that send their own transactions use the printed endpoint as their RPC ad
122
135
  stuntman init --address <wallet> | --new [--rpc <url>] [--eth <amount>]
123
136
  stuntman mcp MCP server over stdio
124
137
  stuntman rpc [--port 8545] Practice RPC
125
- stuntman connect [claude|codex|json|raxol|virtuals]
138
+ stuntman connect [claude|codex|json|raxol|virtuals|eliza|openclaw]
126
139
  stuntman takes [--limit 20] [--json]
127
140
  stuntman take <id> [--json]
128
141
  stuntman balances [token ...]
129
142
  stuntman fund ETH <amount> | <token> <amount>
130
143
  stuntman status Account, simulation mode, go-live checklist
131
144
  stuntman witness [off] Witnessed practice on Stuntman's server
145
+ stuntman send --to <address> [--value <eth>] [--data 0x...]
132
146
  stuntman reset --yes
133
147
  stuntman doctor What your RPC supports
134
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|virtuals] 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
@@ -70,6 +70,11 @@ Witnessed practice
70
70
  stuntman witness off Go back to practicing on this machine only
71
71
  stuntman witness --key-env VAR Sign up an agent's own wallet (key read from env VAR)
72
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.
77
+
73
78
  Practice money
74
79
  stuntman fund ETH <amount>
75
80
  stuntman fund <token address> <amount>
@@ -108,6 +113,26 @@ function connectLines(target) {
108
113
  '# In code, the Xochi config raxol_payments takes:',
109
114
  `%{base_url: "http://127.0.0.1:${DEFAULT_PORT}/xochi", auth: {:member, token}}`,
110
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');
111
136
  case 'virtuals':
112
137
  return [
113
138
  '# Virtuals GAME agents, two ways (use a witness endpoint to put takes on a public record):',
@@ -131,7 +156,7 @@ function connectLines(target) {
131
156
  '',
132
157
  `Agents that send their own transactions: run "${rpc}" and use http://127.0.0.1:${DEFAULT_PORT} as the RPC address.`,
133
158
  `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".`,
159
+ `Virtuals GAME agents: "${installed ? 'stuntman' : 'npx stuntman'} connect virtuals". ElizaOS: "connect eliza". OpenClaw: "connect openclaw".`,
135
160
  ].join('\n');
136
161
  }
137
162
  }
@@ -388,6 +413,59 @@ async function cmdWitness(args, flags) {
388
413
  : `Witnessing is free while billing is off. Once it starts, each agent keeps ${conf.freeTakes} free takes.`);
389
414
  }
390
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
+ }
391
469
  async function cmdMcp() {
392
470
  const cfg = requireConfig();
393
471
  const engine = await createEngine(cfg);
@@ -430,6 +508,8 @@ async function main() {
430
508
  return out(connectLines(args[0] ?? 'all'));
431
509
  case 'witness':
432
510
  return cmdWitness(args, flags);
511
+ case 'send':
512
+ return cmdSend(flags);
433
513
  default:
434
514
  throw new Error(`Unknown command "${cmd}". Run "stuntman help".`);
435
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 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 { parseUnits } from 'viem';
18
- import { formatTake } from './report.js';
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';
@@ -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';
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.1",
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": {
@@ -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": {