|
| 1 | +## AGENTS.md – Bloxchain Protocol |
| 2 | + |
| 3 | +This file is a **briefing document for AI agents** working on this repo. It complements `README.md` and the docs under `sdk/typescript/docs`. |
| 4 | + |
| 5 | +Focus areas: |
| 6 | +- Core Solidity contracts under `contracts/core` |
| 7 | +- TypeScript SDK under `sdk/typescript` |
| 8 | + |
| 9 | +--- |
| 10 | + |
| 11 | +## 1. Tech Stack & Targets |
| 12 | + |
| 13 | +- **Language / Runtime** |
| 14 | + - Solidity `0.8.34` (upgradeable, OZ upgradeable patterns) |
| 15 | + - TypeScript (Viem‑based SDK) |
| 16 | +- **Core Domains** |
| 17 | + - `contracts/core` – source of truth for all protocol behavior |
| 18 | + - `sdk/typescript` – thin, type‑safe wrappers and helpers for the core contracts |
| 19 | +- **Do not treat** `contracts/` and `sdk/typescript/` as independent systems: the SDK is an integration layer over the Solidity core. |
| 20 | + |
| 21 | +When in doubt, **derive behavior from Solidity first**, then align the SDK and docs. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## 2. Project Structure (for Agents) |
| 26 | + |
| 27 | +Key paths you should care about: |
| 28 | + |
| 29 | +- `contracts/core/` |
| 30 | + - `lib/EngineBlox.sol` – central state machine library (`SecureOperationState`, tx lifecycle, RBAC, function schemas, meta‑tx, whitelists). |
| 31 | + - `base/BaseStateMachine.sol` – upgrade‑safe wrapper that owns `_secureState` and exposes shared queries and helpers. |
| 32 | + - `security/SecureOwnable.sol` – owner / broadcaster / recovery roles, timelock configuration. |
| 33 | + - `access/RuntimeRBAC.sol` – dynamic, non‑protected roles and function permissions, batch config. |
| 34 | + - `execution/GuardController.sol` – guarded execution, time‑lock workflows, target whitelists. |
| 35 | + - `pattern/Account.sol` – abstract pattern that **combines all three components**; basis for account‑style contracts (e.g. `AccountBlox`). |
| 36 | + - `lib/utils/SharedValidation.sol` – common validation helpers and custom errors. |
| 37 | + - `*/lib/definitions/*.sol` – definition libraries with function schemas, operation types, and default permissions. |
| 38 | + |
| 39 | +- `sdk/typescript/` |
| 40 | + - `contracts/core/*.tsx` – class wrappers for core contracts (`SecureOwnable`, `RuntimeRBAC`, `GuardController`, `BaseStateMachine`). |
| 41 | + - `lib/EngineBlox.tsx` – TS mirror of `EngineBlox` pure helpers and constants. |
| 42 | + - `utils/metaTx/metaTransaction.tsx` – EIP‑712 + meta‑tx helpers that must match the Solidity domain / struct hashes. |
| 43 | + - `utils/*` – error handling, validation, interface IDs, ERC‑20 helpers. |
| 44 | + - `docs/` – SDK and architecture docs (up‑to‑date; treat as user‑facing source of truth). |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +## 3. Commands for Agents |
| 49 | + |
| 50 | +When you need to **build, test, or regenerate docs**, prefer these: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Compile & size‑check contracts (Truffle / Foundry flows may coexist) |
| 54 | +npm run compile:foundry |
| 55 | +npm run compile:truffle:size |
| 56 | + |
| 57 | +# Run protocol & sanity tests |
| 58 | +npm run test:foundry |
| 59 | +npm run test:sanity-sdk:core |
| 60 | + |
| 61 | +# Regenerate Solidity‑based docs (NatSpec) |
| 62 | +npm run docgen |
| 63 | +``` |
| 64 | + |
| 65 | +Always keep changes compatible with existing tests; if you modify core behavior, update the relevant sanity scripts under `scripts/sanity-sdk`. |
| 66 | + |
| 67 | +--- |
| 68 | + |
| 69 | +## 4. Documentation & Alignment Rules |
| 70 | + |
| 71 | +For **any change to core behavior**: |
| 72 | + |
| 73 | +1. **Solidity first** |
| 74 | + - Update the relevant file under `contracts/core`. |
| 75 | + - Maintain or improve NatSpec; it is the canonical machine‑readable spec. |
| 76 | +2. **SDK second** |
| 77 | + - Update the corresponding wrapper under `sdk/typescript/contracts/core`. |
| 78 | + - Ensure types in `sdk/typescript/types` and interfaces in `sdk/typescript/interfaces` stay consistent. |
| 79 | +3. **Docs third** |
| 80 | + - Update or add markdown under `sdk/typescript/docs`, especially: |
| 81 | + - `api-reference.md` |
| 82 | + - Component guides: `secure-ownable.md`, `runtime-rbac.md`, `guard-controller.md` |
| 83 | + - Architecture docs: `bloxchain-architecture.md`, `state-machine-engine.md`, `core-contract-graph.md`, `account-pattern.md`, `getting-started.md` |
| 84 | + |
| 85 | +Agents should **never** introduce new public methods or change signatures without: |
| 86 | +- Updating NatSpec |
| 87 | +- Updating TS types/wrappers |
| 88 | +- Updating affected docs |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## 5. Code Style & Safety Constraints |
| 93 | + |
| 94 | +High‑level rules for agents: |
| 95 | + |
| 96 | +- **Security first** |
| 97 | + - Preserve and extend reentrancy protections (`nonReentrant`, CEI). |
| 98 | + - Never weaken input validation or access control (`SharedValidation`, role checks, whitelist checks). |
| 99 | + - Do not bypass state‑machine entrypoints with “shortcut” external functions. |
| 100 | +- **Upgradeability** |
| 101 | + - Core components use OZ upgradeable patterns – **no constructors** on upgradeable contracts. |
| 102 | + - Keep storage layout stable; use gaps as already defined. |
| 103 | +- **Custom errors over strings** |
| 104 | + - Prefer existing custom errors in `SharedValidation` and related libraries. |
| 105 | + |
| 106 | +TypeScript: |
| 107 | +- Use existing helpers (e.g. `EngineBlox`, meta‑tx utils, validation helpers) before adding new ad‑hoc logic. |
| 108 | +- Keep Viem types (`PublicClient`, `WalletClient`, `Address`, `Hex`) accurate and explicit. |
| 109 | + |
| 110 | +--- |
| 111 | + |
| 112 | +## 6. Boundaries & Things Agents Must Not Do |
| 113 | + |
| 114 | +Agents **must not**: |
| 115 | + |
| 116 | +- Commit secrets or modify: |
| 117 | + - `.env` |
| 118 | + - Deployment keys or secret configs |
| 119 | +- Hard‑code private keys, RPC URLs, or production contract addresses in source; use envs or `deployed-addresses.json`. |
| 120 | +- Change CI / security enforcement to “work around” tests or linters (e.g. disabling checks, lowering coverage, skipping Slither/Semgrep). |
| 121 | +- Remove or weaken timelock, RBAC, or whitelist checks to “simplify” flows. |
| 122 | + |
| 123 | +If an operation requires touching live deployments or production infra, stop and request explicit instructions. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 7. Guidance for Different Agent Types |
| 128 | + |
| 129 | +- **AI audit agents** |
| 130 | + - Start from: |
| 131 | + - `contracts/core/lib/EngineBlox.sol` |
| 132 | + - `contracts/core/base/BaseStateMachine.sol` |
| 133 | + - `contracts/core/security/SecureOwnable.sol` |
| 134 | + - `contracts/core/access/RuntimeRBAC.sol` |
| 135 | + - `contracts/core/execution/GuardController.sol` |
| 136 | + - Cross‑reference: |
| 137 | + - `sdk/typescript/docs/core-contract-graph.md` |
| 138 | + - `sdk/typescript/docs/bloxchain-architecture.md` |
| 139 | + - `sdk/typescript/docs/state-machine-engine.md` |
| 140 | + - Focus on invariants: role separation, timelock enforcement, meta‑tx replay protection, whitelist enforcement, upgrade safety. |
| 141 | + |
| 142 | +- **AI builder agents** |
| 143 | + - Prefer building on **Account‑based contracts** (`contracts/core/pattern/Account.sol` and its implementations). |
| 144 | + - Use SDK entrypoints: |
| 145 | + - `SecureOwnable`, `RuntimeRBAC`, `GuardController`, `BaseStateMachine` wrappers |
| 146 | + - `lib/EngineBlox.tsx` and `utils/metaTx/metaTransaction.tsx` |
| 147 | + - Follow examples from: |
| 148 | + - `scripts/sanity-sdk/*` |
| 149 | + - `sdk/typescript/docs/examples-basic.md` |
| 150 | + - `sdk/typescript/docs/getting-started.md` |
| 151 | + |
| 152 | +- **AI operational agents** |
| 153 | + - When wiring flows (role config, guard config, meta‑tx ops), follow the same ordering and constraints as the definition libraries: |
| 154 | + - `contracts/core/access/lib/definitions/RuntimeRBACDefinitions.sol` |
| 155 | + - `contracts/core/execution/lib/definitions/GuardControllerDefinitions.sol` |
| 156 | + - Use `deployed-addresses.json` as the canonical source for contract addresses per network. |
| 157 | + |
| 158 | +--- |
| 159 | + |
| 160 | +## 8. How to Ask the Repo for Help |
| 161 | + |
| 162 | +When you need more context: |
| 163 | + |
| 164 | +- Read: |
| 165 | + - `README.md` |
| 166 | + - `sdk/typescript/docs/index.md` |
| 167 | + - `sdk/typescript/docs/getting-started.md` |
| 168 | + - `sdk/typescript/docs/account-pattern.md` |
| 169 | +- Look at: |
| 170 | + - Existing tests under `scripts/sanity-sdk` |
| 171 | + - NatSpec in the relevant Solidity files |
| 172 | + |
| 173 | +Prefer **deriving intent from tests and NatSpec** over guessing new behaviors. If required behavior is unclear or ambiguous, surface a question to a human rather than inventing protocol‑level semantics. |
| 174 | + |
0 commit comments