stuntman 0.1.1 → 0.1.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 +2 -2
- package/dist/cli.js +6 -6
- package/dist/engine.js +31 -5
- package/dist/mcp.js +3 -3
- package/dist/overlay.js +17 -8
- package/dist/report.js +3 -2
- package/dist/slots.js +74 -23
- package/dist/store.js +9 -0
- package/dist/version.js +1 -1
- package/dist/xochi.js +1 -1
- package/package.json +1 -1
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
|
|
82
|
+
## Two ways to practice
|
|
83
83
|
|
|
84
84
|
| | `init --address <wallet>` | `init --new` |
|
|
85
85
|
|---|---|---|
|
|
86
|
-
|
|
|
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
|
|
package/dist/cli.js
CHANGED
|
@@ -47,8 +47,8 @@ Practice mode for AI agents. Real apps, real prices, practice money.
|
|
|
47
47
|
Every send is caught and played out against the live chain. Nothing is broadcast.
|
|
48
48
|
|
|
49
49
|
Start
|
|
50
|
-
stuntman init --address <wallet>
|
|
51
|
-
stuntman init --new
|
|
50
|
+
stuntman init --address <wallet> Practice as your wallet (watch only)
|
|
51
|
+
stuntman init --new Practice with a new key that can sign messages
|
|
52
52
|
--rpc <url> Node to read from (default: Robinhood Chain)
|
|
53
53
|
--eth <amount> Start with this much practice ETH
|
|
54
54
|
|
|
@@ -128,7 +128,7 @@ async function cmdInit(flags) {
|
|
|
128
128
|
mode = 'shadow';
|
|
129
129
|
}
|
|
130
130
|
else {
|
|
131
|
-
throw new Error('Pass --address <your wallet address> to
|
|
131
|
+
throw new Error('Pass --address <your wallet address> to practice as your wallet, or --new for a fresh practice key.');
|
|
132
132
|
}
|
|
133
133
|
const rpc = new RpcClient(rpcUrl);
|
|
134
134
|
let chainId;
|
|
@@ -151,7 +151,7 @@ async function cmdInit(flags) {
|
|
|
151
151
|
out(`Practice ETH set to ${fmt(res.balance, 18)}.`);
|
|
152
152
|
}
|
|
153
153
|
out(`Stuntman is set up.`);
|
|
154
|
-
out(`
|
|
154
|
+
out(` Practicing as ${account}${mode === 'shadow' ? ' (your wallet, watch only: nothing can be signed or sent)' : ' (new practice key, holds no real funds)'}`);
|
|
155
155
|
out(` Chain ${chainId}`);
|
|
156
156
|
out(` RPC ${rpcUrl}`);
|
|
157
157
|
out(` Simulation ${describeCapabilities(caps)}`);
|
|
@@ -169,7 +169,7 @@ async function cmdStatus() {
|
|
|
169
169
|
const engine = await createEngine(cfg);
|
|
170
170
|
const state = readState(cfg.chainId, cfg.account);
|
|
171
171
|
const r = readiness(readTakes());
|
|
172
|
-
out(`
|
|
172
|
+
out(`Practicing as ${checksum(cfg.account)} on chain ${cfg.chainId}`);
|
|
173
173
|
out(`Simulation: ${describeCapabilities(engine.caps)}`);
|
|
174
174
|
out(`Takes: ${r.total} (${r.filled} filled, ${r.bad} bad)`);
|
|
175
175
|
out('');
|
|
@@ -287,7 +287,7 @@ async function cmdRpc(flags) {
|
|
|
287
287
|
onError: (m) => err(`Error: ${m}`),
|
|
288
288
|
});
|
|
289
289
|
err(`Stuntman practice RPC on http://${host}:${port}`);
|
|
290
|
-
err(`
|
|
290
|
+
err(`Practicing as ${checksum(cfg.account)} on chain ${cfg.chainId}, reads from ${cfg.rpcUrl}`);
|
|
291
291
|
err(`Simulation: ${describeCapabilities(engine.caps)}. Nothing sent here is ever broadcast.`);
|
|
292
292
|
err(`Xochi practice gateway on http://${host}:${port}/xochi (quotes from ${xochiUrl()}, executes stay here).`);
|
|
293
293
|
err('Press Ctrl+C to stop.');
|
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
|
|
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
|
|
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,
|
|
543
|
-
|
|
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
|
|
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/mcp.js
CHANGED
|
@@ -25,7 +25,7 @@ export function buildMcpServer(engine) {
|
|
|
25
25
|
const { cfg } = engine;
|
|
26
26
|
server.registerTool('wallet_address', {
|
|
27
27
|
title: 'Practice wallet address',
|
|
28
|
-
description: 'Returns the address this agent is
|
|
28
|
+
description: 'Returns the address this agent is practicing as and the chain it is on. Use it wherever an app asks for your wallet address.',
|
|
29
29
|
inputSchema: {},
|
|
30
30
|
annotations: { readOnlyHint: true },
|
|
31
31
|
}, async () => text(JSON.stringify({ address: checksum(cfg.account), chainId: cfg.chainId, practice: true, mode: cfg.mode })));
|
|
@@ -86,7 +86,7 @@ export function buildMcpServer(engine) {
|
|
|
86
86
|
}, async ({ limit }) => {
|
|
87
87
|
const takes = readTakes().slice(-(limit ?? 10)).reverse();
|
|
88
88
|
if (!takes.length)
|
|
89
|
-
return text('No takes yet. Send a transaction to start
|
|
89
|
+
return text('No takes yet. Send a transaction to start practicing.');
|
|
90
90
|
return text(takes.map((t) => `Take ${t.id} ${t.status.padEnd(8)} ${t.summary}`).join('\n'));
|
|
91
91
|
});
|
|
92
92
|
server.registerTool('get_take', {
|
|
@@ -156,7 +156,7 @@ export function buildMcpServer(engine) {
|
|
|
156
156
|
}, async () => {
|
|
157
157
|
const r = readiness(readTakes());
|
|
158
158
|
return text([
|
|
159
|
-
`
|
|
159
|
+
`Practicing as ${checksum(cfg.account)} (${cfg.mode === 'shadow' ? 'your wallet, watch only' : 'practice key'}) on chain ${cfg.chainId}.`,
|
|
160
160
|
`Simulation: ${describeCapabilities(engine.caps)}.`,
|
|
161
161
|
`Takes: ${r.total} (${r.filled} filled, ${r.bad} bad).`,
|
|
162
162
|
`Ready to go live: ${r.ready ? 'yes' : 'not yet'}.`,
|
package/dist/overlay.js
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
// chain "looks" like the practice balances wherever the agent or an app reads it.
|
|
3
3
|
import { numberToHex } from 'viem';
|
|
4
4
|
import { PERMIT2_ADDRESS, lower, word } from './chain.js';
|
|
5
|
-
import { packPermit2 } from './slots.js';
|
|
5
|
+
import { encodeField, packPermit2 } from './slots.js';
|
|
6
6
|
export function slotKey(kind, token, holder, spender) {
|
|
7
7
|
return [kind, lower(token), lower(holder), spender ? lower(spender) : ''].filter(Boolean).join(':');
|
|
8
8
|
}
|
|
9
|
+
/** The slot and word that store `value` where `stored` says it lives. */
|
|
10
|
+
export function slotWrite(stored, value) {
|
|
11
|
+
if (!stored)
|
|
12
|
+
return null;
|
|
13
|
+
if (typeof stored === 'string')
|
|
14
|
+
return [stored, word(value)];
|
|
15
|
+
const encoded = encodeField(stored, value);
|
|
16
|
+
return encoded ? [stored.slot, encoded] : null;
|
|
17
|
+
}
|
|
9
18
|
export function buildOverrides(state) {
|
|
10
19
|
const out = {};
|
|
11
20
|
const account = state.account;
|
|
@@ -20,15 +29,15 @@ export function buildOverrides(state) {
|
|
|
20
29
|
out[lower(account)] = { ...(out[lower(account)] ?? {}), balance: numberToHex(BigInt(acc.eth)) };
|
|
21
30
|
}
|
|
22
31
|
for (const [token, amount] of Object.entries(acc.tokens)) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
add(token,
|
|
32
|
+
const w = slotWrite(state.slots[slotKey('balance', token, account)], BigInt(amount));
|
|
33
|
+
if (w)
|
|
34
|
+
add(token, w[0], w[1]);
|
|
26
35
|
}
|
|
27
36
|
for (const [token, spenders] of Object.entries(acc.allowances)) {
|
|
28
37
|
for (const [spender, amount] of Object.entries(spenders)) {
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
add(token,
|
|
38
|
+
const w = slotWrite(state.slots[slotKey('allowance', token, account, spender)], BigInt(amount));
|
|
39
|
+
if (w)
|
|
40
|
+
add(token, w[0], w[1]);
|
|
32
41
|
}
|
|
33
42
|
}
|
|
34
43
|
// Contracts deployed in practice exist only here: their code and storage.
|
|
@@ -40,7 +49,7 @@ export function buildOverrides(state) {
|
|
|
40
49
|
for (const [token, spenders] of Object.entries(acc.permit2)) {
|
|
41
50
|
for (const [spender, a] of Object.entries(spenders)) {
|
|
42
51
|
const slot = state.slots[slotKey('permit2', token, account, spender)];
|
|
43
|
-
if (slot)
|
|
52
|
+
if (typeof slot === 'string')
|
|
44
53
|
add(PERMIT2_ADDRESS, slot, packPermit2(BigInt(a.amount), BigInt(a.expiration), BigInt(a.nonce)));
|
|
45
54
|
}
|
|
46
55
|
}
|
package/dist/report.js
CHANGED
|
@@ -27,7 +27,8 @@ export function formatTake(take, detailed = false) {
|
|
|
27
27
|
else if (take.gasCostWei) {
|
|
28
28
|
lines.push(` Gas: ${Number(take.gasUsed ?? 0).toLocaleString('en-US')} units, ${fmt(BigInt(take.gasCostWei), 18, 9)} ETH`);
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
// A rejected take's summary already says why.
|
|
31
|
+
if (take.reason && take.status === 'reverted')
|
|
31
32
|
lines.push(` Why: ${take.reason}`);
|
|
32
33
|
if (detailed) {
|
|
33
34
|
if (take.intent)
|
|
@@ -38,7 +39,7 @@ export function formatTake(take, detailed = false) {
|
|
|
38
39
|
lines.push(` Contract: ${take.contractAddress}`);
|
|
39
40
|
if (take.request.value !== '0')
|
|
40
41
|
lines.push(` Value: ${fmt(BigInt(take.request.value), 18)} ETH`);
|
|
41
|
-
lines.push(` Block: ${BigInt(take.blockNumber).toString()} Simulated with: ${take.backend}`);
|
|
42
|
+
lines.push(` Block: ${BigInt(take.blockNumber).toString()}${take.backend === 'none' ? '' : ` Simulated with: ${take.backend}`}`);
|
|
42
43
|
lines.push(` Practice hash: ${take.txHash}`);
|
|
43
44
|
lines.push(` At: ${take.at}`);
|
|
44
45
|
}
|
package/dist/slots.js
CHANGED
|
@@ -7,14 +7,38 @@
|
|
|
7
7
|
// 2. Otherwise try the common layouts (Solidity and Vyper mappings at slots
|
|
8
8
|
// 0..63, OpenZeppelin v5 namespaced storage, Solady).
|
|
9
9
|
// Every candidate is confirmed by overriding it with a probe value and checking
|
|
10
|
-
// that the read returns that value
|
|
10
|
+
// that the read returns that value, or a byte range of it: some tokens pack the
|
|
11
|
+
// balance into part of a slot (Paxos USDG keeps a uint64 balance beside
|
|
12
|
+
// rewards data). Nothing unconfirmed is ever used.
|
|
11
13
|
import { concat, encodeAbiParameters, encodeFunctionData, decodeFunctionResult, keccak256, pad } from 'viem';
|
|
12
14
|
import { RpcError } from './rpc.js';
|
|
13
15
|
import { ERC20_ABI, PERMIT2_ABI, PERMIT2_ADDRESS, checksum, word } from './chain.js';
|
|
14
|
-
const PROBE = 0x5354554e544d414e000000000000002an; // "STUNTMAN" ... 42
|
|
15
16
|
const PERMIT2_PROBE_AMOUNT = 0x5354554e544d414e0000002an;
|
|
16
17
|
const PERMIT2_PROBE_EXPIRATION = 0x5354554en;
|
|
17
18
|
const PERMIT2_PROBE_NONCE = 0x2an;
|
|
19
|
+
// 32 bytes with no zero byte and no repeats, so any byte range of it is unique.
|
|
20
|
+
const FIELD_PROBE = 0x53a4c7e1f29b6d0e8f71c3a5d2b94e67a1f8c3e5b7d9f2a4c6e8b1d3f5a7c9e2n;
|
|
21
|
+
const MIN_FIELD_BYTES = 4;
|
|
22
|
+
/** The byte range of FIELD_PROBE that a read returned, if any. Full width first. */
|
|
23
|
+
export function fieldOf(returned) {
|
|
24
|
+
for (let bytes = 32; bytes >= MIN_FIELD_BYTES; bytes--) {
|
|
25
|
+
for (let offset = 0; offset + bytes <= 32; offset++) {
|
|
26
|
+
const mask = (1n << BigInt(bytes * 8)) - 1n;
|
|
27
|
+
if (((FIELD_PROBE >> BigInt(offset * 8)) & mask) === returned)
|
|
28
|
+
return { offset, bytes };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
/** The slot word that stores `value` in `field`, keeping the slot's other bits. */
|
|
34
|
+
export function encodeField(field, value) {
|
|
35
|
+
const width = BigInt(field.bytes * 8);
|
|
36
|
+
if (value < 0n || value >= 1n << width)
|
|
37
|
+
return null;
|
|
38
|
+
const shift = BigInt(field.offset * 8);
|
|
39
|
+
const mask = ((1n << width) - 1n) << shift;
|
|
40
|
+
return word((BigInt(field.rest) & ~mask) | (value << shift));
|
|
41
|
+
}
|
|
18
42
|
const OZ_ERC20_NAMESPACE = 0x52c63247e1f47db19d5ce0460030c497f067ca4cebf71ba98eeadabe20bace00n;
|
|
19
43
|
const SOLADY_BALANCE_SEED = '0x87a211a2';
|
|
20
44
|
const SOLADY_ALLOWANCE_SEED = '0x7f5e9f20';
|
|
@@ -108,39 +132,66 @@ async function confirm(rpc, target, data, candidates, probe, matches) {
|
|
|
108
132
|
}
|
|
109
133
|
return null;
|
|
110
134
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
135
|
+
/** Like confirm, but also finds a value packed into part of a slot. */
|
|
136
|
+
async function confirmField(rpc, target, data, candidates) {
|
|
137
|
+
const probe = word(FIELD_PROBE);
|
|
138
|
+
for (let i = 0; i < candidates.length; i += 32) {
|
|
139
|
+
const chunk = candidates.slice(i, i + 32);
|
|
140
|
+
const results = await rpc.batch(chunk.map((slot) => ({
|
|
141
|
+
method: 'eth_call',
|
|
142
|
+
params: [{ to: target, data }, 'latest', { [target]: { stateDiff: { [slot]: probe } } }],
|
|
143
|
+
})));
|
|
144
|
+
for (let j = 0; j < chunk.length; j++) {
|
|
145
|
+
const r = results[j];
|
|
146
|
+
if (r instanceof RpcError || typeof r !== 'string' || r.length < 66)
|
|
147
|
+
continue;
|
|
148
|
+
const field = fieldOf(BigInt(r.slice(0, 66)));
|
|
149
|
+
if (!field)
|
|
150
|
+
continue;
|
|
151
|
+
const slot = chunk[j];
|
|
152
|
+
const rest = field.bytes === 32 ? word(0n) : ((await rpc.request('eth_getStorageAt', [target, slot, 'latest']).catch(() => null)) ?? null);
|
|
153
|
+
if (rest === null)
|
|
154
|
+
continue;
|
|
155
|
+
// Confirm the encoding round-trips with a second, ordinary value.
|
|
156
|
+
const check = 123456789n;
|
|
157
|
+
const encoded = encodeField({ ...field, rest }, check);
|
|
158
|
+
if (!encoded)
|
|
159
|
+
continue;
|
|
160
|
+
const back = await rpc
|
|
161
|
+
.request('eth_call', [{ to: target, data }, 'latest', { [target]: { stateDiff: { [slot]: encoded } } }])
|
|
162
|
+
.catch(() => null);
|
|
163
|
+
if (!back || back.length < 66 || BigInt(back.slice(0, 66)) !== check)
|
|
164
|
+
continue;
|
|
165
|
+
return { slot, offset: field.offset, bytes: field.bytes, rest: pad(rest, { size: 32 }) };
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
function ordered(traced, candidates) {
|
|
118
171
|
const seen = new Set();
|
|
119
|
-
|
|
120
|
-
|
|
172
|
+
return [...traced, ...candidates]
|
|
173
|
+
.map((s) => pad(s, { size: 32 }))
|
|
174
|
+
.filter((s) => {
|
|
175
|
+
const k = s.toLowerCase();
|
|
121
176
|
if (seen.has(k))
|
|
122
177
|
return false;
|
|
123
178
|
seen.add(k);
|
|
124
179
|
return true;
|
|
125
180
|
});
|
|
126
|
-
|
|
181
|
+
}
|
|
182
|
+
export async function findBalanceSlot(rpc, caps, token, holder) {
|
|
183
|
+
if (!caps.stateOverride)
|
|
184
|
+
return null;
|
|
185
|
+
const data = encodeFunctionData({ abi: ERC20_ABI, functionName: 'balanceOf', args: [checksum(holder)] });
|
|
186
|
+
const traced = caps.debugTraceCall ? await tracedSlots(rpc, token, data) : [];
|
|
187
|
+
return confirmField(rpc, token, data, ordered(traced, balanceCandidates(holder)));
|
|
127
188
|
}
|
|
128
189
|
export async function findAllowanceSlot(rpc, caps, token, owner, spender) {
|
|
129
190
|
if (!caps.stateOverride)
|
|
130
191
|
return null;
|
|
131
192
|
const data = encodeFunctionData({ abi: ERC20_ABI, functionName: 'allowance', args: [checksum(owner), checksum(spender)] });
|
|
132
|
-
const probe = word(PROBE);
|
|
133
|
-
const isProbe = (ret) => decodeFunctionResult({ abi: ERC20_ABI, functionName: 'allowance', data: ret }) === PROBE;
|
|
134
193
|
const traced = caps.debugTraceCall ? await tracedSlots(rpc, token, data) : [];
|
|
135
|
-
|
|
136
|
-
const ordered = [...traced, ...allowanceCandidates(owner, spender)].filter((s) => {
|
|
137
|
-
const k = pad(s, { size: 32 }).toLowerCase();
|
|
138
|
-
if (seen.has(k))
|
|
139
|
-
return false;
|
|
140
|
-
seen.add(k);
|
|
141
|
-
return true;
|
|
142
|
-
});
|
|
143
|
-
return confirm(rpc, token, data, ordered.map((s) => pad(s, { size: 32 })), probe, isProbe);
|
|
194
|
+
return confirmField(rpc, token, data, ordered(traced, allowanceCandidates(owner, spender)));
|
|
144
195
|
}
|
|
145
196
|
export async function confirmPermit2Slot(rpc, caps, owner, token, spender) {
|
|
146
197
|
if (!caps.stateOverride)
|
package/dist/store.js
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
import { join } from 'node:path';
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, writeFileSync, renameSync, rmSync, statSync, appendFileSync } from 'node:fs';
|
|
6
6
|
import { ensureHome } from './config.js';
|
|
7
|
+
/** Bumped when slot search learns new layouts, so earlier misses are tried again. */
|
|
8
|
+
export const SLOT_SEARCH_VERSION = 2;
|
|
7
9
|
function emptyAccount() {
|
|
8
10
|
return { tokens: {}, allowances: {}, permit2: {} };
|
|
9
11
|
}
|
|
@@ -15,6 +17,7 @@ export function freshState(chainId, account) {
|
|
|
15
17
|
accountState: emptyAccount(),
|
|
16
18
|
tokens: {},
|
|
17
19
|
slots: {},
|
|
20
|
+
slotSearch: SLOT_SEARCH_VERSION,
|
|
18
21
|
takeCount: 0,
|
|
19
22
|
hashes: {},
|
|
20
23
|
contracts: {},
|
|
@@ -79,6 +82,12 @@ export function readState(chainId, account) {
|
|
|
79
82
|
parsed.accountState.permit2 ??= {};
|
|
80
83
|
parsed.tokens ??= {};
|
|
81
84
|
parsed.slots ??= {};
|
|
85
|
+
if ((parsed.slotSearch ?? 1) < SLOT_SEARCH_VERSION) {
|
|
86
|
+
for (const [k, v] of Object.entries(parsed.slots))
|
|
87
|
+
if (v === null)
|
|
88
|
+
delete parsed.slots[k];
|
|
89
|
+
parsed.slotSearch = SLOT_SEARCH_VERSION;
|
|
90
|
+
}
|
|
82
91
|
parsed.hashes ??= {};
|
|
83
92
|
parsed.contracts ??= {};
|
|
84
93
|
parsed.known ??= [];
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.1.
|
|
1
|
+
export const VERSION = '0.1.2';
|
package/dist/xochi.js
CHANGED
|
@@ -280,7 +280,7 @@ async function execute(engine, body) {
|
|
|
280
280
|
const account = checksum(engine.cfg.account);
|
|
281
281
|
const wallet = String(message.wallet ?? pick(rec.request, ['wallet']) ?? '');
|
|
282
282
|
if (lower(wallet) !== lower(account)) {
|
|
283
|
-
return fail(422, 'wrong_wallet', `Stuntman is
|
|
283
|
+
return fail(422, 'wrong_wallet', `Stuntman is practicing as ${account}, but this intent is for ${wallet || 'another wallet'}. Nothing was executed.`);
|
|
284
284
|
}
|
|
285
285
|
const notes = ['Quoted by Xochi, filled in practice at the quoted amounts. Nothing was executed.'];
|
|
286
286
|
if (eip712 && !(await signedBy(eip712, signature, account, [RAXOL_INTENT_TYPES, CONFORMANCE_INTENT_TYPES]))) {
|
package/package.json
CHANGED