stuntman 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -79,11 +79,11 @@ ORDER_XOCHI_URL=http://127.0.0.1:8545/xochi
79
79
 
80
80
  In code, pass `%{base_url: "http://127.0.0.1:8545/xochi", auth: ...}` as the Xochi config. Quotes go to the real Xochi API with the agent's own member token or mandate, so prices, fees and routes are real. Executes never leave your machine: Stuntman checks the signed intent the way a solver would (the right wallet, not expired, enough balance, Permit2 able to pull the input) and fills it on the practice ledger at the quoted amounts. Status polls answer from the practice record. Claims, relays and every other write are refused. Set `STUNTMAN_XOCHI_URL` to use another Xochi endpoint.
81
81
 
82
- ## Two ways to practise
82
+ ## Two ways to practice
83
83
 
84
84
  | | `init --address <wallet>` | `init --new` |
85
85
  |---|---|---|
86
- | Practises as | your real wallet, watch only | a new key with no real funds |
86
+ | Practices as | your real wallet, watch only | a new key with no real funds |
87
87
  | Starts with | your real balances | nothing, add practice funds |
88
88
  | Signing | the agent signs with its own key, Stuntman never forwards | Stuntman can sign messages and Permit2 permits |
89
89
 
@@ -93,6 +93,18 @@ npx stuntman fund ETH 2
93
93
  npx stuntman fund 0xTokenAddress 500
94
94
  ```
95
95
 
96
+ ## Witnessed practice
97
+
98
+ 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.
99
+
100
+ ```bash
101
+ stuntman witness # sign up the practice account; the MCP tools switch over
102
+ stuntman fund ETH 1 # practice money on the witness, listed on the record
103
+ stuntman witness off # back to practicing locally
104
+ ```
105
+
106
+ Agents that send their own transactions use the printed endpoint as their RPC address. Each agent's first 25 witnessed takes are free; after that each take is paid in the Stuntman token from prepaid credit, part burned and part to the treasury. See [stuntmanhq.xyz/economics](https://stuntmanhq.xyz/economics). The token is $STUNT on Robinhood Chain: `0xfadcdbb63b0326a772e18c5955028f2c23e81651`. The credits contract is in `contracts/StuntmanCredits.sol`.
107
+
96
108
  ## Commands
97
109
 
98
110
  ```
@@ -105,6 +117,7 @@ stuntman take <id> [--json]
105
117
  stuntman balances [token ...]
106
118
  stuntman fund ETH <amount> | <token> <amount>
107
119
  stuntman status Account, simulation mode, go-live checklist
120
+ stuntman witness [off] Witnessed practice on Stuntman's server
108
121
  stuntman reset --yes
109
122
  stuntman doctor What your RPC supports
110
123
  ```
@@ -152,7 +165,7 @@ npm test # builds, starts a local chain, runs every backend end to end
152
165
 
153
166
  `npm run build:executor` recompiles `contracts/StuntmanExecutor.sol`.
154
167
 
155
- The website lives in `site/`: static files with no build step. Deploy it on Vercel with `site` as the root directory.
168
+ The website lives in `site/` (static files) and the witness API in `api/`. Vercel builds both from the repository root using `vercel.json`.
156
169
 
157
170
  ## License
158
171
 
package/dist/cli.js CHANGED
@@ -13,6 +13,7 @@ import { formatTake, readiness } from './report.js';
13
13
  import { startProxy } from './proxy.js';
14
14
  import { runMcp } from './mcp.js';
15
15
  import { VERSION } from './version.js';
16
+ import { registerWitness, remoteCall, remoteTakes, witnessBase } from './remote.js';
16
17
  function parseArgs(argv) {
17
18
  const args = [];
18
19
  const flags = {};
@@ -47,8 +48,8 @@ Practice mode for AI agents. Real apps, real prices, practice money.
47
48
  Every send is caught and played out against the live chain. Nothing is broadcast.
48
49
 
49
50
  Start
50
- stuntman init --address <wallet> Practise as your wallet (watch only)
51
- stuntman init --new Practise with a new key that can sign messages
51
+ stuntman init --address <wallet> Practice as your wallet (watch only)
52
+ stuntman init --new Practice with a new key that can sign messages
52
53
  --rpc <url> Node to read from (default: Robinhood Chain)
53
54
  --eth <amount> Start with this much practice ETH
54
55
 
@@ -63,6 +64,11 @@ Watch the takes
63
64
  stuntman balances [token ...] Practice balances
64
65
  stuntman status Account, simulation mode and go-live checklist
65
66
 
67
+ Witnessed practice
68
+ stuntman witness Practice on Stuntman's server: every take signed and kept
69
+ on a public record. The MCP tools switch over to it.
70
+ stuntman witness off Go back to practicing on this machine only
71
+
66
72
  Practice money
67
73
  stuntman fund ETH <amount>
68
74
  stuntman fund <token address> <amount>
@@ -128,7 +134,7 @@ async function cmdInit(flags) {
128
134
  mode = 'shadow';
129
135
  }
130
136
  else {
131
- throw new Error('Pass --address <your wallet address> to practise as your wallet, or --new for a fresh practice key.');
137
+ throw new Error('Pass --address <your wallet address> to practice as your wallet, or --new for a fresh practice key.');
132
138
  }
133
139
  const rpc = new RpcClient(rpcUrl);
134
140
  let chainId;
@@ -151,7 +157,7 @@ async function cmdInit(flags) {
151
157
  out(`Practice ETH set to ${fmt(res.balance, 18)}.`);
152
158
  }
153
159
  out(`Stuntman is set up.`);
154
- out(` Practising as ${account}${mode === 'shadow' ? ' (your wallet, watch only: nothing can be signed or sent)' : ' (new practice key, holds no real funds)'}`);
160
+ out(` Practicing as ${account}${mode === 'shadow' ? ' (your wallet, watch only: nothing can be signed or sent)' : ' (new practice key, holds no real funds)'}`);
155
161
  out(` Chain ${chainId}`);
156
162
  out(` RPC ${rpcUrl}`);
157
163
  out(` Simulation ${describeCapabilities(caps)}`);
@@ -167,9 +173,10 @@ async function cmdInit(flags) {
167
173
  async function cmdStatus() {
168
174
  const cfg = requireConfig();
169
175
  const engine = await createEngine(cfg);
170
- const state = readState(cfg.chainId, cfg.account);
171
- const r = readiness(readTakes());
172
- out(`Practising as ${checksum(cfg.account)} on chain ${cfg.chainId}`);
176
+ const r = readiness(await allTakes(cfg));
177
+ out(`Practicing as ${checksum(cfg.account)} on chain ${cfg.chainId}`);
178
+ if (cfg.witness)
179
+ out(`Witnessed: every take is simulated and signed by Stuntman. Record: ${witnessBase()}/a/${checksum(cfg.account)}`);
173
180
  out(`Simulation: ${describeCapabilities(engine.caps)}`);
174
181
  out(`Takes: ${r.total} (${r.filled} filled, ${r.bad} bad)`);
175
182
  out('');
@@ -181,15 +188,19 @@ async function cmdStatus() {
181
188
  out('To go live, swap the Stuntman wallet tool (or RPC address) back for your real one.');
182
189
  out('Your agent then does its own stunts.');
183
190
  }
184
- if (state.takeCount === 0) {
191
+ if (r.total === 0) {
185
192
  out('');
186
193
  out('No takes yet. Connect your agent with "npx stuntman connect" and let it trade.');
187
194
  }
188
195
  }
196
+ /** Takes oldest first, from the witness when witness mode is on. */
197
+ async function allTakes(cfg, limit = 500) {
198
+ return cfg.witness ? (await remoteTakes(cfg.witness, limit)).reverse() : readTakes();
199
+ }
189
200
  async function cmdTakes(flags) {
190
- requireConfig();
201
+ const cfg = requireConfig();
191
202
  const limit = Math.max(1, Number(flags.limit ?? 20));
192
- const takes = readTakes().slice(-limit).reverse();
203
+ const takes = (await allTakes(cfg, limit)).slice(-limit).reverse();
193
204
  if (flags.json) {
194
205
  out(JSON.stringify(takes, null, 2));
195
206
  return;
@@ -206,15 +217,22 @@ async function cmdTakes(flags) {
206
217
  }
207
218
  }
208
219
  async function cmdTake(args, flags) {
209
- requireConfig();
220
+ const cfg = requireConfig();
210
221
  const id = Number(args[0]);
211
- const take = readTakes().find((t) => t.id === id);
222
+ const take = (await allTakes(cfg)).find((t) => t.id === id);
212
223
  if (!take)
213
224
  throw new Error(`No take ${args[0] ?? ''}. Run "stuntman takes" to see them.`);
214
225
  out(flags.json ? JSON.stringify(take, null, 2) : formatTake(take, true));
215
226
  }
216
227
  async function cmdBalances(args) {
217
228
  const cfg = requireConfig();
229
+ if (cfg.witness) {
230
+ const rows = await remoteCall(cfg.witness, 'stuntman_balances');
231
+ out(`Practice balances for ${checksum(cfg.account)} (witnessed)`);
232
+ for (const r of rows)
233
+ out(` ${r.symbol.padEnd(10)} ${r.formatted.padStart(24)}${r.practice ? '' : ' real (untouched in practice)'}`);
234
+ return;
235
+ }
218
236
  const engine = await createEngine(cfg);
219
237
  const extra = args.filter(isAddr);
220
238
  const rows = await balances(engine, extra);
@@ -233,11 +251,19 @@ async function cmdFund(args) {
233
251
  if (!isEth && !isAddr(asset))
234
252
  throw new Error(`${asset} is not ETH or a token address.`);
235
253
  const decimals = isEth ? 18 : (await readTokenInfo(engine.rpc, asset)).decimals;
254
+ if (cfg.witness) {
255
+ const r = await remoteCall(cfg.witness, 'stuntman_fund', [isEth ? 'ETH' : asset, parseUnits(amount, decimals).toString()]);
256
+ out(`Added ${amount} ${r.symbol} on the witness. Practice balance: ${fmt(BigInt(r.balance), r.decimals)} ${r.symbol}.`);
257
+ out('Practice money added on the witness shows on your public record.');
258
+ return;
259
+ }
236
260
  const res = await fund(engine, isEth ? 'ETH' : asset, parseUnits(amount, decimals));
237
261
  out(`Added ${amount} ${res.symbol}. Practice balance: ${fmt(res.balance, res.decimals)} ${res.symbol}.`);
238
262
  }
239
263
  async function cmdReset(flags) {
240
264
  const cfg = requireConfig();
265
+ if (cfg.witness)
266
+ throw new Error('A witnessed record cannot be reset. Run "stuntman witness off" to practice on this machine again; that record is separate.');
241
267
  if (!flags.yes)
242
268
  throw new Error('This clears every practice balance and take. Run again with --yes to confirm.');
243
269
  resetPractice(cfg.chainId, cfg.account);
@@ -274,6 +300,9 @@ async function cmdDoctor() {
274
300
  }
275
301
  async function cmdRpc(flags) {
276
302
  const cfg = requireConfig();
303
+ if (cfg.witness) {
304
+ throw new Error(`Witness mode is on, so takes made through a local RPC would not be witnessed. Point your agent's RPC address at your witness endpoint instead (shown by "stuntman witness"), or run "stuntman witness off".`);
305
+ }
277
306
  const engine = await createEngine(cfg);
278
307
  const port = Number(flags.port ?? process.env.STUNTMAN_PORT ?? DEFAULT_PORT);
279
308
  const host = typeof flags.host === 'string' ? flags.host : '127.0.0.1';
@@ -287,11 +316,41 @@ async function cmdRpc(flags) {
287
316
  onError: (m) => err(`Error: ${m}`),
288
317
  });
289
318
  err(`Stuntman practice RPC on http://${host}:${port}`);
290
- err(`Practising as ${checksum(cfg.account)} on chain ${cfg.chainId}, reads from ${cfg.rpcUrl}`);
319
+ err(`Practicing as ${checksum(cfg.account)} on chain ${cfg.chainId}, reads from ${cfg.rpcUrl}`);
291
320
  err(`Simulation: ${describeCapabilities(engine.caps)}. Nothing sent here is ever broadcast.`);
292
321
  err(`Xochi practice gateway on http://${host}:${port}/xochi (quotes from ${xochiUrl()}, executes stay here).`);
293
322
  err('Press Ctrl+C to stop.');
294
323
  }
324
+ async function cmdWitness(args) {
325
+ const cfg = requireConfig();
326
+ if (args[0] === 'off') {
327
+ delete cfg.witness;
328
+ saveConfig(cfg);
329
+ out('Witness mode is off. Takes are simulated on this machine again. Your witnessed record stays online.');
330
+ return;
331
+ }
332
+ const { account, endpoint } = await registerWitness(cfg);
333
+ cfg.witness = endpoint;
334
+ saveConfig(cfg);
335
+ const base = witnessBase();
336
+ const conf = (await fetch(`${base}/api/witness/config`).then((r) => r.json()).catch(() => null));
337
+ out(`Witnessed practice is on for ${account}.`);
338
+ out('');
339
+ out(`Endpoint (keep it private, it is your agent's key to the record):`);
340
+ out(` ${endpoint}`);
341
+ out(`Public record:`);
342
+ out(` ${base}/a/${account}`);
343
+ out('');
344
+ out('The Stuntman MCP tools now send through the witness. Agents that send their own');
345
+ out('transactions: use the endpoint above as the RPC address.');
346
+ out('Practice money on the witness is separate: add some with "stuntman fund ETH 1".');
347
+ if (conf?.freeTakes !== undefined) {
348
+ out('');
349
+ out(conf.billing
350
+ ? `The first ${conf.freeTakes} witnessed takes are free. After that each take costs $${conf.takePriceUsd} in ${conf.symbol ?? 'the Stuntman token'}; top up at ${base}/witness.`
351
+ : `Witnessing is free while billing is off. Once it starts, each agent keeps ${conf.freeTakes} free takes.`);
352
+ }
353
+ }
295
354
  async function cmdMcp() {
296
355
  const cfg = requireConfig();
297
356
  const engine = await createEngine(cfg);
@@ -332,6 +391,8 @@ async function main() {
332
391
  return cmdMcp();
333
392
  case 'connect':
334
393
  return out(connectLines(args[0] ?? 'all'));
394
+ case 'witness':
395
+ return cmdWitness(args);
335
396
  default:
336
397
  throw new Error(`Unknown command "${cmd}". Run "stuntman help".`);
337
398
  }
@@ -0,0 +1,4 @@
1
+ // Generated by scripts/build-credits.mjs from contracts/StuntmanCredits.sol. Do not edit.
2
+ // Compiled with solc 0.8.39+commit.ce47f2c8.Emscripten.clang, optimizer on (200 runs), evmVersion paris.
3
+ export const CREDITS_ABI = [{ "inputs": [{ "internalType": "address", "name": "token_", "type": "address" }, { "internalType": "address", "name": "owner_", "type": "address" }, { "internalType": "address", "name": "treasury_", "type": "address" }, { "internalType": "address", "name": "operator_", "type": "address" }, { "internalType": "uint16", "name": "burnBps_", "type": "uint16" }], "stateMutability": "nonpayable", "type": "constructor" }, { "inputs": [], "name": "BadShare", "type": "error" }, { "inputs": [], "name": "LengthMismatch", "type": "error" }, { "inputs": [], "name": "NotOperator", "type": "error" }, { "inputs": [], "name": "NotOwner", "type": "error" }, { "inputs": [], "name": "NothingToWithdraw", "type": "error" }, { "inputs": [{ "internalType": "uint256", "name": "availableAt", "type": "uint256" }], "name": "TooEarly", "type": "error" }, { "inputs": [], "name": "TransferFailed", "type": "error" }, { "inputs": [], "name": "ZeroAddress", "type": "error" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint16", "name": "burnBps", "type": "uint16" }], "name": "BurnShareChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "settlement", "type": "uint256" }, { "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Charged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": true, "internalType": "address", "name": "from", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Deposited", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "operator", "type": "address" }], "name": "OperatorChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "owner", "type": "address" }], "name": "OwnerChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "uint256", "name": "settlement", "type": "uint256" }, { "indexed": false, "internalType": "bytes32", "name": "root", "type": "bytes32" }, { "indexed": false, "internalType": "uint256", "name": "takes", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "charged", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "burned", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "toTreasury", "type": "uint256" }], "name": "Settled", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "address", "name": "treasury", "type": "address" }], "name": "TreasuryChanged", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }, { "indexed": false, "internalType": "uint256", "name": "availableAt", "type": "uint256" }], "name": "WithdrawRequested", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "account", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Withdrawn", "type": "event" }, { "inputs": [], "name": "BURN", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "MAX_BPS", "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "WITHDRAW_DELAY", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "burnBps", "outputs": [{ "internalType": "uint16", "name": "", "type": "uint16" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "credits", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "account", "type": "address" }, { "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "deposit", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "lastRoot", "outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "operator", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "requestWithdraw", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "uint16", "name": "burnBps_", "type": "uint16" }], "name": "setBurnShare", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "operator_", "type": "address" }], "name": "setOperator", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "treasury_", "type": "address" }], "name": "setTreasury", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "bytes32", "name": "root", "type": "bytes32" }, { "internalType": "uint256", "name": "takes", "type": "uint256" }, { "internalType": "address[]", "name": "accounts", "type": "address[]" }, { "internalType": "uint256[]", "name": "amounts", "type": "uint256[]" }], "name": "settle", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "settlements", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "token", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalBurned", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalCharged", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalTakes", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "totalToTreasury", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "owner_", "type": "address" }], "name": "transferOwnership", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [], "name": "treasury", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "withdraw", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "withdrawAmount", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "withdrawAt", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }];
4
+ export const CREDITS_BYTECODE = '0x60a060405234801561001057600080fd5b5060405161136838038061136883398101604081905261002f91610215565b6001600160a01b038516158061004c57506001600160a01b038416155b8061005e57506001600160a01b038316155b8061007057506001600160a01b038216155b1561008e5760405163d92e233d60e01b815260040160405180910390fd5b61271061ffff821611156100b5576040516311c56c8960e01b815260040160405180910390fd5b6001600160a01b03858116608052600080546001600160a01b03199081168784169081179092556002805460018054909316878616179092559286166001600160b01b031990911617600160a01b61ffff851602179091556040519081527fa2ea9883a321a3e97b8266c2b078bfeec6d50c711ed71f874a90d500ae2eaf369060200160405180910390a16040516001600160a01b03831681527f4721129e0e676ed6a92909bb24e853ccdd63ad72280cc2e974e38e480e0e6e549060200160405180910390a16040516001600160a01b03841681527fc714d22a2f08b695f81e7c707058db484aa5b4d6b4c9fd64beb10fe85832f6089060200160405180910390a160405161ffff821681527fe955937e62509fdebf0600fcf6a767397f1dd2bd02efdcc41253e35314fe839d9060200160405180910390a15050505050610285565b80516001600160a01b038116811461021057600080fd5b919050565b600080600080600060a0868803121561022d57600080fd5b610236866101f9565b9450610244602087016101f9565b9350610252604087016101f9565b9250610260606087016101f9565b9150608086015161ffff8116811461027757600080fd5b809150509295509295909350565b6080516110ba6102ae6000396000818161032101528181610c2a0152610d3801526110ba6000f3fe608060405234801561001057600080fd5b50600436106101735760003560e01c8063b3ab15fb116100de578063d89135cd11610097578063f2fde38b11610071578063f2fde38b14610309578063fc0c546a1461031c578063fd967f4714610343578063fe5ff4681461034c57600080fd5b8063d89135cd146102e4578063e4fcee29146102ed578063f0f44260146102f657600080fd5b8063b3ab15fb1461029a578063b58166f2146102ad578063c0a2526c146102b6578063c1b57edb146102bf578063ce459a29146102c8578063d3be603b146102db57600080fd5b8063570ca73511610130578063570ca7351461020d57806361d027b314610238578063745400c91461024b57806375cbda241461025e5780638da5cb5b1461027e578063a6f55d771461029157600080fd5b80630d5e5fff146101785780633ccfd60b1461019557806347e7ef241461019f5780634f420151146101b257806352153dfb146101d257806353deb3d6146101e5575b600080fd5b6101826202a30081565b6040519081526020015b60405180910390f35b61019d61036c565b005b61019d6101ad366004610e13565b6104e1565b6101826101c0366004610e3d565b60046020526000908152604090205481565b61019d6101e0366004610eab565b6105ca565b6002546101fa90600160a01b900461ffff1681565b60405161ffff909116815260200161018c565b600154610220906001600160a01b031681565b6040516001600160a01b03909116815260200161018c565b600254610220906001600160a01b031681565b61019d610259366004610f33565b61090d565b61018261026c366004610e3d565b60056020526000908152604090205481565b600054610220906001600160a01b031681565b61018260085481565b61019d6102a8366004610e3d565b61099c565b610182600b5481565b61022061dead81565b610182600a5481565b61019d6102d6366004610f4c565b610a43565b61018260065481565b61018260095481565b61018260075481565b61019d610304366004610e3d565b610ae5565b61019d610317366004610e3d565b610b85565b6102207f000000000000000000000000000000000000000000000000000000000000000081565b6101fa61271081565b61018261035a366004610e3d565b60036020526000908152604090205481565b336000908152600460205260408120549081900361039d57604051630686827b60e51b815260040160405180910390fd5b33600090815260056020526040902054428111156103d557604051630a8d68c960e21b81526004810182905260240160405180910390fd5b33600090815260036020526040812054908184106103f357816103f5565b835b3360009081526004602090815260408083208390556005909152812081905590915081900361043757604051630686827b60e51b815260040160405180910390fd5b6104418183610f86565b33600081815260036020526040908190209290925590516024810191909152604481018290526104a69063a9059cbb906064015b6040516020818303038152906040529060e01b6020820180516001600160e01b038381831617835250505050610c25565b60405181815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d59060200160405180910390a250505050565b6001600160a01b0382166105085760405163d92e233d60e01b815260040160405180910390fd5b6000610512610cf4565b6040513360248201523060448201526064810184905290915061053d906323b872dd90608401610475565b600081610548610cf4565b6105529190610f86565b6001600160a01b03851660009081526003602052604081208054929350839290919061057f908490610f9f565b909155505060405181815233906001600160a01b038616907f8752a472e571a816aea92eec8dae9baf628e840f4929fbcc2d155e6233ff68a79060200160405180910390a350505050565b6001546001600160a01b031633146105f557604051631f0853c160e21b815260040160405180910390fd5b828114610618576040516001621398b960e31b0319815260040160405180910390fd5b600060066000815461062990610fb2565b918290555090506000805b858110156107ae5760006003600089898581811061065457610654610fcb565b90506020020160208101906106699190610e3d565b6001600160a01b03166001600160a01b031681526020019081526020016000205490506000818787858181106106a1576106a1610fcb565b90506020020135106106b357816106cd565b8686848181106106c5576106c5610fcb565b905060200201355b9050806000036106de5750506107a6565b6106e88183610f86565b600360008b8b878181106106fe576106fe610fcb565b90506020020160208101906107139190610e3d565b6001600160a01b031681526020810191909152604001600020556107378185610f9f565b935088888481811061074b5761074b610fcb565b90506020020160208101906107609190610e3d565b6001600160a01b0316857f40860d6197dabef1dcfdd4f0d5a0833e741eb44abc0fc815485f24b3dddf7d6b8360405161079b91815260200190565b60405180910390a350505b600101610634565b50600254600090612710906107ce90600160a01b900461ffff1684610fe1565b6107d89190610ff8565b905060006107e68284610f86565b905081156108125760405161dead6024820152604481018390526108129063a9059cbb90606401610475565b8015610847576002546040516001600160a01b039091166024820152604481018290526108479063a9059cbb90606401610475565b89600b8190555088600760008282546108609190610f9f565b9250508190555082600860008282546108799190610f9f565b9250508190555081600960008282546108929190610f9f565b9250508190555080600a60008282546108ab9190610f9f565b9091555050604080518b8152602081018b9052908101849052606081018390526080810182905284907faee91e9c15012f01da6d452913dc294269e1af2c8bb74f16d7a89f44286b3ff49060a00160405180910390a250505050505050505050565b8060000361092e57604051630686827b60e51b815260040160405180910390fd5b600061093d6202a30042610f9f565b3360008181526004602090815260408083208790556005825291829020849055815186815290810184905292935090917fd72eb5d043f24a0168ae744d5c44f9596fd673a26bf74d9646bff4b844882d14910160405180910390a25050565b6000546001600160a01b031633146109c7576040516330cd747160e01b815260040160405180910390fd5b6001600160a01b0381166109ee5760405163d92e233d60e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0383169081179091556040519081527f4721129e0e676ed6a92909bb24e853ccdd63ad72280cc2e974e38e480e0e6e54906020015b60405180910390a150565b6000546001600160a01b03163314610a6e576040516330cd747160e01b815260040160405180910390fd5b61271061ffff82161115610a95576040516311c56c8960e01b815260040160405180910390fd5b6002805461ffff60a01b1916600160a01b61ffff8416908102919091179091556040519081527fe955937e62509fdebf0600fcf6a767397f1dd2bd02efdcc41253e35314fe839d90602001610a38565b6000546001600160a01b03163314610b10576040516330cd747160e01b815260040160405180910390fd5b6001600160a01b038116610b375760405163d92e233d60e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0383169081179091556040519081527fc714d22a2f08b695f81e7c707058db484aa5b4d6b4c9fd64beb10fe85832f60890602001610a38565b6000546001600160a01b03163314610bb0576040516330cd747160e01b815260040160405180910390fd5b6001600160a01b038116610bd75760405163d92e233d60e01b815260040160405180910390fd5b600080546001600160a01b0319166001600160a01b0383169081179091556040519081527fa2ea9883a321a3e97b8266c2b078bfeec6d50c711ed71f874a90d500ae2eaf3690602001610a38565b6000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031683604051610c60919061101a565b6000604051808303816000865af19150503d8060008114610c9d576040519150601f19603f3d011682016040523d82523d6000602084013e610ca2565b606091505b5091509150811580610cd1575060008151118015610cd1575080806020019051810190610ccf9190611049565b155b15610cef576040516312171d8360e31b815260040160405180910390fd5b505050565b604080513060248083019190915282518083039091018152604490910182526020810180516001600160e01b03166370a0823160e01b1790529051600091829182917f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031691610d6b919061101a565b600060405180830381855afa9150503d8060008114610da6576040519150601f19603f3d011682016040523d82523d6000602084013e610dab565b606091505b5091509150811580610dbe575060208151105b15610ddc576040516312171d8360e31b815260040160405180910390fd5b80806020019051810190610df0919061106b565b9250505090565b80356001600160a01b0381168114610e0e57600080fd5b919050565b60008060408385031215610e2657600080fd5b610e2f83610df7565b946020939093013593505050565b600060208284031215610e4f57600080fd5b610e5882610df7565b9392505050565b60008083601f840112610e7157600080fd5b50813567ffffffffffffffff811115610e8957600080fd5b6020830191508360208260051b8501011115610ea457600080fd5b9250929050565b60008060008060008060808789031215610ec457600080fd5b8635955060208701359450604087013567ffffffffffffffff811115610ee957600080fd5b610ef589828a01610e5f565b909550935050606087013567ffffffffffffffff811115610f1557600080fd5b610f2189828a01610e5f565b979a9699509497509295939492505050565b600060208284031215610f4557600080fd5b5035919050565b600060208284031215610f5e57600080fd5b813561ffff81168114610e5857600080fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610f9957610f99610f70565b92915050565b80820180821115610f9957610f99610f70565b600060018201610fc457610fc4610f70565b5060010190565b634e487b7160e01b600052603260045260246000fd5b8082028115828204841417610f9957610f99610f70565b60008261101557634e487b7160e01b600052601260045260246000fd5b500490565b6000825160005b8181101561103b5760208186018101518583015201611021565b506000920191825250919050565b60006020828403121561105b57600080fd5b81518015158114610e5857600080fd5b60006020828403121561107d57600080fd5b505191905056fea26469706673582212208a7113491b5aa91aee0ca50d9f28b1df0c45cd80a419a84c698ef64bfaab4bb464736f6c63430008270033';
package/dist/engine.js CHANGED
@@ -106,9 +106,22 @@ async function ensureBalanceSlot(engine, state, token, notes) {
106
106
  state.slots[key] = slot;
107
107
  if (!slot) {
108
108
  const info = state.tokens[lower(token)];
109
- notes.push(`${info?.symbol ?? shortAddr(token)} uses storage Stuntman could not map, so other apps will still see your real ${info?.symbol ?? 'token'} balance. Practice keeps tracking it.`);
109
+ notes.push(`${info?.symbol ?? shortAddr(token)} uses storage Stuntman could not map, so apps will still see your real ${info?.symbol ?? 'token'} balance and transactions that spend practice ${info?.symbol ?? 'tokens'} will fail. Practice keeps tracking it.`);
110
110
  }
111
111
  }
112
+ /** Symbols of practice tokens named by a transaction that apps can't see. */
113
+ function unmappedHeld(state, account, addresses) {
114
+ const out = [];
115
+ for (const a of new Set(addresses.map(lower))) {
116
+ const held = state.accountState.tokens[a];
117
+ if (held === undefined || BigInt(held) === 0n)
118
+ continue;
119
+ if (state.slots[slotKey('balance', a, account)] !== null)
120
+ continue;
121
+ out.push(state.tokens[a]?.symbol ?? shortAddr(a));
122
+ }
123
+ return out;
124
+ }
112
125
  async function ensureAllowanceSlot(engine, state, token, spender) {
113
126
  // A contract deployed in practice keeps its whole storage in the ledger.
114
127
  if (state.contracts?.[lower(token)])
@@ -277,7 +290,7 @@ export async function runTake(engine, req) {
277
290
  throw new TakeRejected(reason, take, code);
278
291
  };
279
292
  if (lower(req.from) !== lower(account)) {
280
- reject(`Stuntman is practising as ${account}, but this transaction is from ${checksum(req.from)}. It was not sent anywhere.`, -32602);
293
+ reject(`Stuntman is practicing as ${account}, but this transaction is from ${checksum(req.from)}. It was not sent anywhere.`, -32602);
281
294
  }
282
295
  if (req.chainId !== undefined && req.chainId !== cfg.chainId) {
283
296
  reject(`Transaction is signed for chain ${req.chainId}, but this is chain ${cfg.chainId}. It was not sent anywhere.`, -32602);
@@ -539,8 +552,17 @@ export async function runTake(engine, req) {
539
552
  const ethAfter = effects.ethAfter - gasCost;
540
553
  state.accountState.eth = ethAfter.toString();
541
554
  changes.push({ token: 'ETH', symbol: 'ETH', decimals: 18, before: ethBefore.toString(), after: ethAfter.toString(), delta: (ethAfter - ethBefore).toString() });
542
- for (const [token, after] of effects.tokensAfter) {
543
- const before = effects.tokensBefore.get(token) ?? 0n;
555
+ for (const [token, chainAfter] of effects.tokensAfter) {
556
+ let before = effects.tokensBefore.get(token) ?? 0n;
557
+ let after = chainAfter;
558
+ // A token Stuntman can't map is read from chain at its real balance, so
559
+ // only the change the transaction made applies to the practice amount.
560
+ const tracked = state.accountState.tokens[token];
561
+ if (tracked !== undefined && state.slots[slotKey('balance', token, account)] === null) {
562
+ const delta = chainAfter - before;
563
+ before = BigInt(tracked);
564
+ after = before + delta;
565
+ }
544
566
  if (before === after && !(token in state.accountState.tokens))
545
567
  continue;
546
568
  const info = await tokenInfo(engine, state, token);
@@ -583,6 +605,10 @@ export async function runTake(engine, req) {
583
605
  else {
584
606
  status = 'reverted';
585
607
  reason = revertReason(outcome.returnData) ?? cleanError(outcome.error) ?? 'execution reverted';
608
+ const unmapped = unmappedHeld(state, account, [to, ...addressesInCalldata(req.data)]);
609
+ if (unmapped.length) {
610
+ notes.push(`This may have failed because Stuntman can't show your practice ${unmapped.join(', ')} to apps yet, so apps see your real balance. Spending practice ${unmapped.length > 1 ? 'tokens' : unmapped[0]} isn't supported for this token.`);
611
+ }
586
612
  const ethAfter = ethBefore - gasCost;
587
613
  state.accountState.eth = ethAfter.toString();
588
614
  changes.push({ token: 'ETH', symbol: 'ETH', decimals: 18, before: ethBefore.toString(), after: ethAfter.toString(), delta: (-gasCost).toString() });
@@ -822,7 +848,7 @@ export async function settleIntent(engine, s) {
822
848
  throw new TakeRejected(reason, bad, -32000);
823
849
  };
824
850
  if (s.fromChainId !== cfg.chainId) {
825
- reject(`this intent spends on chain ${s.fromChainId}, and Stuntman practises on chain ${cfg.chainId}. Nothing was executed.`);
851
+ reject(`this intent spends on chain ${s.fromChainId}, and Stuntman practices on chain ${cfg.chainId}. Nothing was executed.`);
826
852
  }
827
853
  const overrides = buildOverrides(state);
828
854
  const from = lower(s.fromToken);
package/dist/kv.js ADDED
@@ -0,0 +1,153 @@
1
+ // A tiny Redis client for the hosted witness: Upstash's REST API in
2
+ // production, an in-memory stand-in for tests. Only the commands the witness
3
+ // uses are supported.
4
+ /** Upstash Redis over REST. Reads the env vars Vercel's Upstash integration sets. */
5
+ export function upstashFromEnv(env = process.env) {
6
+ const url = env.KV_REST_API_URL ?? env.UPSTASH_REDIS_REST_URL;
7
+ const token = env.KV_REST_API_TOKEN ?? env.UPSTASH_REDIS_REST_TOKEN;
8
+ if (!url || !token)
9
+ return null;
10
+ const post = async (path, body) => {
11
+ const res = await fetch(url.replace(/\/$/, '') + path, {
12
+ method: 'POST',
13
+ headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
14
+ body: JSON.stringify(body),
15
+ });
16
+ if (!res.ok)
17
+ throw new Error(`database: HTTP ${res.status}`);
18
+ return res.json();
19
+ };
20
+ return {
21
+ async cmd(...args) {
22
+ const out = (await post('', args.map(String)));
23
+ if (out.error)
24
+ throw new Error(`database: ${out.error}`);
25
+ return out.result;
26
+ },
27
+ async pipeline(cmds) {
28
+ if (!cmds.length)
29
+ return [];
30
+ const out = (await post('/pipeline', cmds.map((c) => c.map(String))));
31
+ return out.map((r) => {
32
+ if (r.error)
33
+ throw new Error(`database: ${r.error}`);
34
+ return r.result;
35
+ });
36
+ },
37
+ };
38
+ }
39
+ /** In-memory stand-in with Redis semantics, for tests and local runs. */
40
+ export function memoryKV() {
41
+ const strings = new Map();
42
+ const hashes = new Map();
43
+ const lists = new Map();
44
+ const sets = new Map();
45
+ const live = (k) => {
46
+ const e = strings.get(k);
47
+ if (e?.exp !== undefined && Date.now() > e.exp) {
48
+ strings.delete(k);
49
+ return undefined;
50
+ }
51
+ return e;
52
+ };
53
+ const hash = (k) => hashes.get(k) ?? (hashes.set(k, new Map()), hashes.get(k));
54
+ const list = (k) => lists.get(k) ?? (lists.set(k, []), lists.get(k));
55
+ const set = (k) => sets.get(k) ?? (sets.set(k, new Set()), sets.get(k));
56
+ const range = (len, a, b) => {
57
+ const s = a < 0 ? Math.max(len + a, 0) : a;
58
+ const e = b < 0 ? len + b : Math.min(b, len - 1);
59
+ return [s, e];
60
+ };
61
+ const run = (args) => {
62
+ const [name, ...rest] = args.map(String);
63
+ const k = rest[0];
64
+ switch (name.toUpperCase()) {
65
+ case 'GET':
66
+ return live(k)?.v ?? null;
67
+ case 'SET': {
68
+ const opts = rest.slice(2).map((o) => o.toUpperCase());
69
+ if (opts.includes('NX') && live(k))
70
+ return null;
71
+ const px = opts.indexOf('PX');
72
+ const ex = opts.indexOf('EX');
73
+ const exp = px >= 0 ? Date.now() + Number(rest[2 + px + 1]) : ex >= 0 ? Date.now() + 1000 * Number(rest[2 + ex + 1]) : undefined;
74
+ strings.set(k, { v: rest[1], exp });
75
+ return 'OK';
76
+ }
77
+ case 'DEL': {
78
+ let n = 0;
79
+ for (const key of rest)
80
+ n += [strings, hashes, lists, sets].some((m) => m.delete(key)) ? 1 : 0;
81
+ return n;
82
+ }
83
+ case 'INCRBY': {
84
+ const v = BigInt(live(k)?.v ?? '0') + BigInt(rest[1]);
85
+ strings.set(k, { v: v.toString() });
86
+ return Number(v);
87
+ }
88
+ case 'HINCRBY': {
89
+ const h = hash(k);
90
+ const v = BigInt(h.get(rest[1]) ?? '0') + BigInt(rest[2]);
91
+ h.set(rest[1], v.toString());
92
+ return Number(v);
93
+ }
94
+ case 'HSET': {
95
+ const h = hash(k);
96
+ for (let i = 1; i < rest.length; i += 2)
97
+ h.set(rest[i], rest[i + 1]);
98
+ return (rest.length - 1) / 2;
99
+ }
100
+ case 'HGET':
101
+ return hashes.get(k)?.get(rest[1]) ?? null;
102
+ case 'HGETALL':
103
+ return [...(hashes.get(k) ?? new Map()).entries()].flat();
104
+ case 'RPUSH':
105
+ list(k).push(...rest.slice(1));
106
+ return list(k).length;
107
+ case 'LLEN':
108
+ return lists.get(k)?.length ?? 0;
109
+ case 'LRANGE': {
110
+ const l = lists.get(k) ?? [];
111
+ const [s, e] = range(l.length, Number(rest[1]), Number(rest[2]));
112
+ return l.slice(s, e + 1);
113
+ }
114
+ case 'LTRIM': {
115
+ const l = lists.get(k) ?? [];
116
+ const [s, e] = range(l.length, Number(rest[1]), Number(rest[2]));
117
+ lists.set(k, l.slice(s, e + 1));
118
+ return 'OK';
119
+ }
120
+ case 'SADD': {
121
+ const s = set(k);
122
+ let n = 0;
123
+ for (const m of rest.slice(1))
124
+ if (!s.has(m))
125
+ (s.add(m), n++);
126
+ return n;
127
+ }
128
+ case 'SMEMBERS':
129
+ return [...(sets.get(k) ?? [])];
130
+ case 'SCARD':
131
+ return sets.get(k)?.size ?? 0;
132
+ default:
133
+ throw new Error(`memoryKV: ${name} is not supported`);
134
+ }
135
+ };
136
+ return {
137
+ async cmd(...args) {
138
+ return run(args);
139
+ },
140
+ async pipeline(cmds) {
141
+ return cmds.map(run);
142
+ },
143
+ };
144
+ }
145
+ /** Turn an HGETALL reply into an object. */
146
+ export function hashToObject(reply) {
147
+ if (!Array.isArray(reply))
148
+ return reply ?? {};
149
+ const out = {};
150
+ for (let i = 0; i < reply.length; i += 2)
151
+ out[String(reply[i])] = String(reply[i + 1]);
152
+ return out;
153
+ }
package/dist/launch.js ADDED
@@ -0,0 +1,21 @@
1
+ export const LAUNCH = {
2
+ /** $STUNT */
3
+ token: '0xfadcdbb63b0326a772e18c5955028f2c23e81651',
4
+ /** StuntmanCredits on Robinhood Chain */
5
+ credits: '0xA9846E958f65D2A0f9Cc69A27650c793a5E9A529',
6
+ freeTakes: 25,
7
+ takePriceUsd: 0.01,
8
+ fallbackTakePriceTokens: '10',
9
+ burnBps: 5000,
10
+ };
11
+ const addr = (v) => (v && /^0x[0-9a-fA-F]{40}$/.test(v) ? v : null);
12
+ /** Launch settings with any environment overrides applied. */
13
+ export function launchSettings(env = process.env) {
14
+ return {
15
+ ...LAUNCH,
16
+ token: addr(env.STUNTMAN_TOKEN) ?? LAUNCH.token,
17
+ credits: addr(env.STUNTMAN_CREDITS) ?? LAUNCH.credits,
18
+ freeTakes: env.STUNTMAN_FREE_TAKES !== undefined ? Number(env.STUNTMAN_FREE_TAKES) : LAUNCH.freeTakes,
19
+ takePriceUsd: env.STUNTMAN_TAKE_PRICE_USD !== undefined ? Number(env.STUNTMAN_TAKE_PRICE_USD) : LAUNCH.takePriceUsd,
20
+ };
21
+ }