Reference
JS engine and client
The same rules in plain JavaScript, and the instruction builders.
src/engine/guard-engine.mjs has no dependency. It mirrors End so that a wallet, a site or a test can predict and explain a verdict. The program is the authority; the differential test proves they agree.
Judging a state
import { judge, check, explain } from './guard-engine.mjs';
const before = [wallet, usdc]; // what Begin stored
const after = [wallet2, usdc2]; // the accounts at the end
const v = judge(before, after, [check.sol(0, -50_000_000), check.token(1, 148_500_000)]);
v.ok ? v.deltas : explain(v.error, names, ['Your wallet', 'USDC']);
Building a guarded transaction
import { wrap, describe, decodeGuard, spl } from './chain/client.mjs';
const ixs = wrap(owner, [owner, usdcAccount], appInstructions, [check.sol(0, -50_000_000)]);
// [ Begin, ...appInstructions, End ] - sign and send as usual
src/chain/client.mjs also has ixInit, ixClose, guardAddress, describeSim (read the accounts simulateTransaction returns), and hand-encoded SPL Token instructions used by the tests.
Previewing
To explain a refusal with numbers, simulate [Begin, ...instructions] asking for the watched accounts, read the guard account for the "before" and the returned accounts for the "after", then call judge. A null account in the response means it was not written to (unchanged).