feat(protocol-core): add version-discriminated deployment addresses to ChainConfig - #30
Draft
henrypalacios wants to merge 3 commits into
Draft
Conversation
henrypalacios
marked this pull request as draft
August 25, 2026 18:00
…lookup Chain configs describe chain identity but carry no contract addresses, so every consumer maintains its own address maps and its own assumptions about which contracts each protocol family deploys. Add an optional `deployments` list to `ChainConfig`, modelled as a union discriminated by protocol version, together with `getDeployment(chainId, version)` whose result narrows to the requested family. Required fields follow the contracts a family actually deploys: V2 pairs are fungible ERC20 tokens priced by closed-form constant-product math and therefore have no quoter and no position manager, while only the Algebra families derive pool addresses from a pool deployer instead of the factory. Modelling this as a union makes those asymmetries compile errors rather than conventions. Add an optional chain-level `multicall` address, which is version-agnostic. Enable vitest type-checking over `*.test-d.ts` files so the type-level assertions covering these rules are enforced, and keep that glob disjoint from the runtime suite so no spec is collected twice. Document the new surface in the package README. Every added field is optional, so existing chain configs and every published export keep their current shape.
Deployment data has to agree with the chain that declares it: every entry targets a protocol version that chain actually lists, each version appears at most once, and every address slot — the chain-level multicall included — holds a real contract address. Those are registry-level rules, so they belong in the same pass that already guards address format before publish. Add `checkDeploymentCoherence` and run it for every chain inside the existing validation loop, reporting through the same error list, the same exit code and the same path grammar. The publish gate now guarantees that every deployment entry reaching consumers is coherent with the protocols its chain declares. Keeping the rules in a pure function leaves the script responsible only for whole-registry wiring, so each rule is covered directly by unit tests.
… and IMX Give the deployment schema real data on three chains. Polygon carries the Algebra v3 and v2 entries; Manta Pacific and Immutable zkEVM each carry a Uniswap-V3 fork entry. Together they cover both concentrated-liquidity families, so a lookup returning the family it was asked for is exercised across chains: the Algebra and Uniswap-V3 fork quoters expose different ABIs, and resolving them by version is what stops a caller reaching for the wrong one. The Uniswap-V3 fork entries carry no pool deployer, since that family derives pool addresses from the factory. Manta Pacific and Immutable zkEVM share a factory and a position manager address; both are confirmed against the deployed contracts. All three chains also gain their multicall address. Every value is stored in EIP-55 checksum form.
henrypalacios
force-pushed
the
feat/protocol-core-deployments-schema
branch
from
August 26, 2026 21:51
7a714a1 to
8c76fd1
Compare
3 tasks
henrypalacios
changed the base branch from
main
to
refactor/protocol-core-drop-dead-chains
August 27, 2026 18:59
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deploymentslist toChainConfig, modelled as a union discriminated by protocol version, plus agetDeployment(chainId, version)lookup whose result narrows to the requested family.multicalladdress, which is version-agnostic.checkDeploymentCoherence, run for every chain inside the existing pre-publish address validation, so each deployment entry targets a version its chain declares, appears once, and holds a real contract address.Why
ChainConfigdescribes chain identity — chain id, name, native and wrapped native, the protocol versions the chain runs, its stablecoins — but it has never carried contract addresses. There is no canonical home for them in the package, so every consumer keeps its own address map and its own assumptions about which contracts each protocol family deploys. Those maps drift, and nothing in the SDK can tell a caller which factory or quoter belongs to which version on a given chain.This change puts the addresses next to the chain identity that already exists, and encodes the differences between protocol families in the type system:
Modelling
deploymentsas a discriminated union makes those asymmetries compile errors instead of conventions a reader has to know, andgetDeploymentreturns the family it was asked for.Polygon zkEVM is the case that exercises this fully: it runs Algebra v3 alongside a Uniswap-V3 fork, and those two quoters expose different ABIs. Resolving them by version is what stops a caller reaching for the wrong one.
Size
The diff is large — 495 added lines — and roughly two thirds of it is tests. Source and script changes are 165 lines across 8 files; the remaining 330 lines are test coverage, including type-level assertions now enforced by vitest type-checking.
Changes
src/chains/types.tsProtocolDeploymentunion discriminated byversion; optionaldeploymentsandmulticallonChainConfigsrc/chains/deployments.tsgetDeployment(chainId, version)with a narrowing return typesrc/chains/deploymentCoherence.tscheckDeploymentCoherence(chain)— pure function returning one message per violationsrc/chains/polygon.tssrc/chains/zkevm.tssrc/index.tsscripts/validate-addresses.tsvitest.config.tssrc/__tests__/**Every added field is optional, so existing chain configs and every published export keep their current shape. Every address is stored in EIP-55 checksum form.
Test plan
pnpm --filter @quickswap-defi/protocol-core test— 323 tests across 22 files pass, no type errorspnpm --filter @quickswap-defi/protocol-core build— CJS, ESM and declaration builds succeedpnpm --filter @quickswap-defi/protocol-core validate:addresses— 62 addresses validated, coherence check clean