Utilities Overview
Crane’s contracts/utils/ libraries are shared building blocks for Repos, Services, tests, and protocol ports. Prefer these over reimplementing sets, AMM math, or hashing in every port — that is part of reuse already deployed and verified code at the library level.
What to read first
| Topic | Page |
|---|---|
| Address/Bytes/String sets + Repo pattern | Sets and Set Repos |
| Constant-product AMM math | ConstProdUtils & Math |
| Architecture map | Codebase Map |
Collections
- Sets:
AddressSet,Bytes32Set,Bytes4Set,StringSet,UInt256Setunderutils/collections/sets/— storage-oriented, 1-indexed Repo APIs. - Arrays / helpers:
BetterArraysand related Better* helpers.
Used heavily in ERC2535Repo, registry Repos, handlers, and comparators.
Math
- ConstProdUtils: shared constant-product quotes, reserve sorting, LP mint/burn helpers (DEX ports + parity tests).
- Other:
BetterMath, fixed-point helpers,SafeCastvariants.
Protocol-specific quoters (Uniswap V3/V4, Slipstream, Aerodrome, Camelot) live with those ports but often share ConstProdUtils for V2-style math.
Cryptography & metatx
- EIP-712 / ECDSA helpers under
utils/cryptography/ ERC2771Contextfor trusted forwarders- Message hash utilities
Tokens & safety
SafeERC20and related transfer helpers- Nonces / short strings where used by token facets
Deployment helpers
- CREATE2/CREATE3-oriented helpers (
Creation, etc.) used by factories BetterEfficientHashLibfor deterministic salts:abi.encode(type(X).name)._hash()
Testing helpers
- Comparators and behavior logging live under
contracts/test/(see Testing Patterns) - Transient slot / reentrancy utilities used by access patterns