@credit-cooperative/address-book
v0.5.0
Published
Canonical registry of Credit Cooperative deployed contract addresses for Solidity and TypeScript
Readme
Credit Cooperative Address Book
The canonical registry of Credit Cooperative deployed contract addresses, for use in both Solidity and
TypeScript/JavaScript projects. It aggregates the per-chain deployment registries that each protocol repo
commits under deployments/<chainId>.json (produced by @credit-cooperative/devkit)
and republishes them as typed, per-chain libraries.
What's inside
data/<project>/<chainId>.json— the source registries, mirrored from each protocol repo. This is the input. Everything else is generated from it.data/<project>/abis/<Contract>.json— chain-independent ABIs, exported as typedas constvalues fromts/abis.ts(@credit-cooperative/address-book/abis).data/<project>/facility-types.json—facilityType()string → ABI contract name (e.g."RCF"→"RCFFacility"), for identifying factory-created facilities at runtime.data/<project>/instances/<chainId>.json— factory-created facility/servicing instances discovered on-chain bybun scripts/sync-instances.ts(Aave-style static enumeration; only as fresh as the last sync).src/<Project><Chain>.sol— generated Solidity libraries ofaddressconstants (e.g.V3ProtocolPaymentRailsSepolia,V3ProtocolPaymentRailsBase).ts/index.ts— generated TypeScript twin (chain-keyed address maps +getAddress/getContracthelpers, plus thefacilityTypesandinstancesmaps, no runtime deps).ts/resolve.ts— hand-written runtime resolver (@credit-cooperative/address-book/resolve): identify an arbitrary address and pair it with its ABI.
src/andts/are generated and committed. Do not hand-edit them — runbun run generate. CI fails if they drift fromdata/.
Usage
Solidity (forge install)
forge install credit-cooperative/address-bookimport { V3ProtocolPaymentRailsSepolia } from "address-book/src/V3ProtocolPaymentRailsSepolia.sol";
contract MyContract {
address node = V3ProtocolPaymentRailsSepolia.NODE;
}TypeScript (npm)
bun add @credit-cooperative/address-bookimport {
v3ProtocolPaymentRails,
getAddress,
} from "@credit-cooperative/address-book";
const node = v3ProtocolPaymentRails[11155111].Node;
const cowSwap = getAddress("v3ProtocolPaymentRails", 8453, "CowSwapModule");ABIs
import { v3ProtocolDeploymentMarketplaceAbi } from "@credit-cooperative/address-book/abis";
import { getContract } from "@credit-cooperative/address-book";
const marketplace = getContract(
"v3ProtocolDeployment",
11155111,
"Marketplace",
); // { address, abi }Identifying a contract from just its address
Facilities (RCFFacility, TLAFacility, TieredFacility, DDTLFacility) and Servicing contracts are
deployed per-deal by factories, so they are not in the static address maps. Two complementary mechanisms:
- Static instance registry —
bun scripts/sync-instances.ts --chain <id>scans theOnboardingHub'sFactorySet/FacilityDeployed/ServicingCreatedevents intodata/<project>/instances/<chainId>.json(facilities, servicings, and factory addresses), whichbun run generateemits as theinstancesmap. Known deals then resolve offline. The scan stays--confirmationsblocks (default 15) behind the head so reorgs cannot commit phantom entries. - Runtime resolver — for addresses deployed since the last sync,
resolveContractprobes the contract'sfacilityType()on-chain and picks the matching ABI. Factories exposefacilityType()too, so a follow-upborrower()probe (facility-only) distinguisheskind: "facility"fromkind: "factory".
import {
resolveContract,
reverseLookup,
} from "@credit-cooperative/address-book/resolve";
// Offline (static book + synced instances only):
const known = reverseLookup(11155111, "0x…");
// Full resolution — any viem PublicClient works as the client:
const resolved = await resolveContract(publicClient, 11155111, "0x…");
// -> { kind: "singleton" | "facility" | "factory" | "servicing" | "unknown", name?, abi?, ... }The resolver has no runtime dependencies; the client just needs an EIP-1193 request supporting eth_call.
Servicing has no facilityType(), so it is detected via the Servicing-unique totalAdvancedValue() probe —
or, more strictly, pass { borrower } to confirm via OnboardingHub.servicingOf(borrower) (on chains where
the hub is not in the book, this falls back to the heuristic probe).
Two caveats:
- On-chain reverts mean "not this contract type"; transport/RPC failures are re-thrown — a rate-limited
endpoint never comes back as
kind: "unknown". abiisundefinedwhen the address book ships no ABI for that contract — check it before use. (All current projects ship ABIs; this can happen for newly onboarded projects whoseabis/dir lags.)
How it updates
- A protocol repo runs
just deploy …, which writes/updates itsdeployments/<chainId>.json, and the change is merged tomain. - The repo's
deployments.ymlworkflow dispatches adeployments-updatedevent here. dispatch-receive.ymlmirrors the changed files intodata/<project>/, regeneratessrc/+ts/, and opens a PR.- Merging + tagging publishes the npm package and updates the
forge installsource.
To regenerate locally after editing data/:
bun run generate # rewrite src/ and ts/
bun run generate:check # CI guard: fail if committed output is stale
forge test # sanity + (with --fork-url) on-chain code checks
bun test ts/ # TypeScript consumption testsMulti-chain note
Addresses are not assumed identical across chains — every entry is keyed by chainId. Always confirm you are
reading the library/map for the chain you are deploying against.
