|
| 1 | +# Chainlink Local - Agents Guide |
| 2 | + |
| 3 | +Guide for AI coding agents working in `smartcontractkit/chainlink-local`. |
| 4 | + |
| 5 | +## What this library does |
| 6 | + |
| 7 | +Chainlink Local is a developer-focused testing package that simulates Chainlink services (especially CCIP) in local and forked environments. |
| 8 | + |
| 9 | +- Local mode (`CCIPLocalSimulator`, `DataStreamsLocalSimulator`) lets developers test app logic quickly without waiting for live offchain systems. |
| 10 | +- Fork mode (`CCIPLocalSimulatorFork`, `DataStreamsLocalSimulatorFork`) runs against forked networks so integrations behave closer to real testnet conditions. |
| 11 | +- The intent is parity of user app behavior between local/fork testing and testnet deployment (minus environment-specific addresses/config). |
| 12 | +- It is available for usage in Foundry, Hardhat 3, Hardhat 2 and Remix IDE environments. |
| 13 | +- Official documentation is available at: https://docs.chain.link/chainlink-local |
| 14 | + |
| 15 | +## Goal |
| 16 | +- Make minimal, correct changes that preserve simulator behavior and test ergonomics. |
| 17 | +- Prefer targeted edits and targeted tests over broad refactors. |
| 18 | + |
| 19 | +## Context Budget First |
| 20 | +Load files in this order and stop as soon as you have enough context: |
| 21 | +1. `package.json` (scripts, versions, docs/release commands) |
| 22 | +2. `foundry.toml` and `hardhat.config.ts` (tooling layout) |
| 23 | +3. Only the relevant `src/**` files and matching tests in `test/**` |
| 24 | +4. If docs task: `helper_doc/*.mjs` and `api_reference/**` |
| 25 | +5. If release/publish task: `.github/workflows/publish.yml` |
| 26 | + |
| 27 | +Avoid loading large/unnecessary trees unless explicitly required: |
| 28 | +- `lib/**`, `out/**`, `cache/**`, `artifacts/**`, `node_modules/**` |
| 29 | + |
| 30 | +## Directory layout |
| 31 | +- `src/`: production contracts by service (`ccip`, `data-feeds`, `data-streams`) |
| 32 | +- `src/test/`: helper/example contracts used by tests |
| 33 | +- `test/smoke/`: local-mode tests |
| 34 | +- `test/e2e/`: fork-mode tests |
| 35 | +- `test/unit/`: unit-level tests |
| 36 | +- `scripts/`: helpers for Hardhat users that write tests using JavaScript or TypeScript |
| 37 | +- `helper_doc/`: docs generation scripts (you shouldn't touch these) |
| 38 | +- `api_reference/`: generated docs output (read only; do not edit directly) |
| 39 | + |
| 40 | +## Hard Rules |
| 41 | +- Never edit `lib/**`. If user explicitly asks, use forge for dependency management. |
| 42 | +- Never edit `node_modules/**`. If user explicitly asks, use npm for dependency management. |
| 43 | +- Keep changes surgical; do not refactor unrelated code. |
| 44 | +- Preserve test placement conventions: |
| 45 | + - local mode -> `test/smoke/**` |
| 46 | + - fork mode -> `test/e2e/**` |
| 47 | +- Do not hand-edit generated docs in `api_reference/**`; regenerate via scripts. |
| 48 | +- If a command fails after deleting generated docs, restore state before continuing. |
| 49 | + |
| 50 | +## Common Commands |
| 51 | +- Compile: |
| 52 | + - `npm run forge-compile` |
| 53 | + - `npm run hardhat-compile` |
| 54 | +- Test: |
| 55 | + - `npm run forge-test` |
| 56 | + - `npm run hardhat-test` |
| 57 | + - `forge test <path-to-test>` |
| 58 | +- Docs: |
| 59 | + - `npm run generate-docs` (deterministic; does not fetch Register data) |
| 60 | + - `npm run update-register` (networked; updates `src/ccip/Register.sol`) |
| 61 | + |
| 62 | +## Release and Publish |
| 63 | +For the full release workflow (beta, stable, branch policy, CHANGELOG requirements), see [`.agent/playbooks/RELEASE_PLAYBOOK.md`](.agent/playbooks/RELEASE_PLAYBOOK.md). |
| 64 | + |
| 65 | +## Dependency Policy |
| 66 | +- Keep `@chainlink/contracts` and `@chainlink/contracts-ccip` as direct `dependencies`. |
| 67 | +- Avoid introducing new tooling dependencies unless there is a clear maintenance win. |
| 68 | +- If bumping Chainlink packages, do not move them to `devDependencies` or `peerDependencies`. |
| 69 | + |
| 70 | +### Current core npm dependency versions |
| 71 | +| Package | Version | |
| 72 | +| --- | --- | |
| 73 | +| `@chainlink/contracts-ccip` | `1.6.2` | |
| 74 | +| `@chainlink/contracts` | `1.5.0` | |
| 75 | + |
| 76 | +## Dependency Update Playbook |
| 77 | +Use these commands unless a maintainer requests something different. |
| 78 | + |
| 79 | +### npm / Hardhat dependencies |
| 80 | +- Add runtime dependency: |
| 81 | + - `npm install <package>@<version>` |
| 82 | +- Add dev dependency: |
| 83 | + - `npm install --save-dev <package>@<version>` |
| 84 | +- Update existing dependency: |
| 85 | + - `npm install <package>@<new-version>` |
| 86 | +- Verify: |
| 87 | + - check `package.json` (`dependencies` vs `devDependencies` placement) |
| 88 | + - run the smallest relevant compile/test command |
| 89 | +- Example (`@chainlink/contracts` -> `1.2.0`): |
| 90 | + - `npm install @chainlink/contracts@1.2.0` |
| 91 | + |
| 92 | +### Foundry dependencies |
| 93 | +- Optional: pull latest submodule state first (all or specific): |
| 94 | + - `forge update` |
| 95 | + - `forge update lib/chainlink-evm lib/chainlink-ccip` |
| 96 | +- Install/update with pinned tag: |
| 97 | + - `forge install <org>/<repo>@<tag>` |
| 98 | +- For direct dependencies: |
| 99 | + - `@chainlink/contracts` equivalent: |
| 100 | + - `forge install smartcontractkit/chainlink-evm@contracts-v<version>` |
| 101 | + - `@chainlink/contracts-ccip` equivalent: |
| 102 | + - `forge install smartcontractkit/chainlink-ccip@contracts-ccip-v<version>` |
| 103 | +- Historical note: |
| 104 | + - older docs may reference `chainlink-brownie-contracts`; this repo uses `chainlink-evm`. |
| 105 | +- After install: |
| 106 | + - verify `lib/` points to the expected tag/commit |
| 107 | + - verify npm versions in `package.json` |
| 108 | + - run `forge build` and relevant tests |
| 109 | + - never edit vendored files manually inside `lib/**` or `node_modules/**` |
| 110 | + |
| 111 | +## Change Checklist |
| 112 | +Before finishing: |
| 113 | +1. Run the smallest relevant compile/test command(s). |
| 114 | +2. Regenerate docs if your change affects docs sources. |
| 115 | +3. Confirm no accidental edits in unrelated files. |
| 116 | +4. Summarize: |
| 117 | + - what changed |
| 118 | + - what was intentionally not touched |
| 119 | + - any residual risk or follow-up |
| 120 | + |
| 121 | +## Known Good Defaults |
| 122 | +- Node.js `22.x` is the safe default for workflow parity. |
| 123 | +- Prefer `rg` for search. |
| 124 | +- Prefer explicit, boring solutions over abstraction-heavy changes. |
0 commit comments