Skip to content

Wallet Invariant: Phase 1 + Invariant Strengthening + Mypy Fixes#4

Merged
qCanoe merged 5 commits intomainfrom
feat/phase1-invariants
Mar 16, 2026
Merged

Wallet Invariant: Phase 1 + Invariant Strengthening + Mypy Fixes#4
qCanoe merged 5 commits intomainfrom
feat/phase1-invariants

Conversation

@qCanoe
Copy link
Copy Markdown
Owner

@qCanoe qCanoe commented Mar 16, 2026

Wallet Invariant: Phase 1 + Invariant Strengthening + Mypy Fixes

Summary

This PR merges the recovered codex/fix-mypy-type-errors branch into main, bringing in project roadmap, Phase 1 infrastructure, invariant strengthening (I1–I4), documentation updates, and mypy/lint fixes.

Commits Included

  1. docs: Add project roadmap (v0.1.0 → v1.0.0)
  2. feat: Implement near-term action items (Phase 1 infrastructure)
  3. feat: Strengthen I1–I4 invariants with dual-threshold, dust filter, and new tests
  4. docs: Update README and README_CN to reflect invariant strengthening
  5. fix: Fix mypy return types and clean lint issues

Changes

Type & Lint Fixes

  • classifier.py: Remove unused type annotations / fix return type hints
  • cli.py: Fix type annotations for CLI handlers
  • config.py: Correct config loading return types
  • delta_extractor.py: Refactor for proper mypy compliance (32 lines changed)
  • evaluation.py: Fix evaluation function return types
  • gate.py: Correct gate logic type hints
  • invariants.py: Remove redundant type annotations
  • simulator.py: Improve simulator return types and add proper type hints
  • types.py: Clean up type definitions

Test Updates

  • test_classifier.py: Remove obsolete type-related workarounds
  • test_integration.py: Fix type assertions in integration tests
  • test_invariants.py: Clean up invariant test type handling
  • test_types.py: Remove redundant type tests

Other Changes (from earlier commits)

  • ROADMAP.md: Project roadmap v0.1.0 → v1.0.0
  • .github/workflows/ci.yml: CI pipeline (pytest, mypy, ruff)
  • invariants.py: Dual-threshold, dust filter for I1–I4
  • README.md / README_CN.md: Updated documentation
  • config.example.json, pyproject.toml, requirements.txt: Config and deps
  • tests/: New fixtures, integration tests, invariant tests

Testing

  • pytest passes
  • mypy passes with no type errors
  • ruff lint passes

Checklist

  • Code follows project style (ruff)
  • Type hints are correct (mypy)
  • No breaking changes to public API
  • Tests updated where needed

claude and others added 5 commits March 16, 2026 12:42
5-phase roadmap covering dataset validation, invariant enhancement,
production hardening, multi-chain support, and research publication.

https://claude.ai/code/session_011QpXPYzuppRtSHFqDKWtQt
- constants.py: add Permit2 permitBatch/permitSingle/permitAndTransferFrom
  selectors to PERMISSION_OP_SELECTORS so I2 correctly skips them

- tests/conftest.py: shared gate_config fixture for offline tests
- tests/fixtures/rpc_responses.py: JSON-RPC mock response builders
  (eth_call, receipt, Transfer/Approval/ApprovalForAll logs)
- tests/test_integration.py: 10 end-to-end scenarios covering I1–I3,
  fail-open, and classifier correctness; runs fully offline via
  pytest-httpx mocking of httpx.AsyncClient

- pyproject.toml / requirements.txt: add pytest-httpx>=0.30.0, ruff;
  add [tool.ruff] config (line-length=100, target-version=py39)

- .github/workflows/ci.yml: GitHub Actions CI with test+mypy job and
  separate lint (ruff) job

- README_CN.md: new 快速上手 section with CLI example output, 3-line
  Python API example, and updated project structure tree

All 43 tests pass (33 existing + 10 new integration tests).

https://claude.ai/code/session_011QpXPYzuppRtSHFqDKWtQt
…nd new tests

- constants.py: add increaseAllowance/decreaseAllowance to PERMISSION_OP_SELECTORS;
  add 5 DEX swap selectors (1inch, Curve, Balancer, Paraswap, 0x) to ASSET_OP_SELECTORS
- classifier.py: extend is_likely_swap() with new DEX selectors
- config.py: add critical_call_depth_threshold(15), critical_delegate_call_threshold(10),
  dust_threshold_wei(1000), fail_open_on_timeout(True) to InvariantConfig
- invariants.py:
  - I2: activate allowance_balance_multiplier relative-balance check
  - I3: dust filter for unexpected token outflows; doubled limit for composite ops (multicall)
  - I4: unconditional REJECT at critical thresholds regardless of enable_path_rejection
  - Engine: configurable reject-on-timeout via fail_open_on_timeout
- tests: add 14 new unit tests and 2 integration tests covering all strengthened logic
- config.example.json: document the 4 new invariant config parameters

https://claude.ai/code/session_011QpXPYzuppRtSHFqDKWtQt
…thening

- Document I2 relative balance check (allowance_balance_multiplier) and
  increaseAllowance/decreaseAllowance PERMISSION_OP classification fix
- Document I3 dust filter (dust_threshold_wei) and composite-op doubled limit
- Document I4 dual-threshold strategy with critical REJECT table
- Document fail_open_on_timeout configurable behavior
- Add new config parameters table with all 10 invariant settings
- Update test count (57 cases) and test coverage table
- Update project structure tree (ROADMAP.md, CI workflow, fixtures/)
- Add Roadmap section linking to ROADMAP.md

https://claude.ai/code/session_011QpXPYzuppRtSHFqDKWtQt
@qCanoe qCanoe merged commit 2e12e56 into main Mar 16, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants