Swap contracts¶
The canonical 420 Swap stack is split between governance/registry surfaces and the executable liquidity venue.
Canonical execution path¶
CanonicalSwapExecutor420— trusted execution boundary. Resolves the canonical market through Registry, requires the shared operational/safety checks, validates settlement-asset identity and market health, and enforces no-overspend / minimum-delivery postconditions.CanonicalConstantProductPool420— production-candidate ERC20/ERC20 constant-product liquidity implementation. Only its immutable executor may callexecuteCanonicalSwap. It uses exact balance-delta checks, reentrancy protection, locked minimum liquidity and caller-provided minimum output. It also maintains cumulative token0/token1 reserve-price state for canonical TWAP derivation.CanonicalMarketRegistry— governance-controlled canonical market-to-pool and pair mapping.ApprovedQuoteAssetRegistry— approved/canonical quote-asset assignment by currency.
Market formation and supporting services¶
GenesisDEXFactory— registration-only governance surface for Genesis-qualified canonical pool instances. It does not deploy pools with CREATE/CREATE2. Canonical pool instances are deployed by the qualified deployment process and then registered by Genesis governance under a one-shotpoolId.poolImplementationis the approved implementation/provenance reference used by deployment governance; the frozen Genesis predeploy starts with this reference unset because no concrete pool address is frozen. Governance must bind a qualified code-bearing implementation reference before any canonical pool registration. It is not a runtime-codehash equality gate because canonical pools may embed immutable market/executor parameters in runtime code.PermissionlessDEXFactory— registration-only permissionless tier. Anyone may deploy a compatible pool externally and register that existing instance while Swap is operational. Registration does not confer canonical status, oracle eligibility, Wallet-default eligibility or protocol endorsement.TWAPOracle— canonical Swap TWAP surface. It resolves the active canonical market, derives time-weighted price from pool cumulative state, enforces configured observation-window/freshness policy, commits source provenance and exposes the ExchangereferencePriceboundary. Governance configures policy but cannot inject arbitrary price observations.PublicBatchAuction— native-$420 public-distribution batch auction. Governance opens pre-funded inventory and sets the clearing price; bidders escrow the canonical quote asset permissionlessly; fills/refunds/claims are deterministic and pull-based.SwapIds420— canonical component and action identifiers.
GenesisDEXFactory lifecycle¶
The frozen GenesisDEXFactory address is a protocol registry boundary, not a pool bytecode factory. The canonical lifecycle is:
- predeploy
GenesisDEXFactoryat its frozen address withpoolImplementation == address(0); no unfrozen pool address is invented as Genesis constructor state; - qualify the approved pool implementation and deployment inputs;
- deploy a concrete pool instance through the retained deployment process;
- governance binds a code-bearing
poolImplementationprovenance reference; - verify the concrete pool instance matches the intended market/executor parameters;
- Genesis governance registers the exact deployed address under a previously unused
poolId; - separately register/activate the market through
CanonicalMarketRegistryas required by canonical market policy.
Registration fails closed when poolImplementation is still unset, when shared operational safety is not normal, and when a poolId already exists. Changing poolImplementation does not mutate or replace previously registered pools.
This distinction is intentional. Introducing an on-chain CREATE/CREATE2 path would create new deployment, salt, initialization, provenance and upgrade semantics that are not defined by the frozen Swap architecture and therefore require a separate canonical decision rather than being inferred from the contract name.
PermissionlessDEXFactory lifecycle¶
The frozen permissionless policy keeps creation: ANYONE, but repository authority defines that as an open market-formation policy rather than an on-chain bytecode deployment primitive. The lifecycle is:
- any user deploys a pool outside
PermissionlessDEXFactory; - the pool must be code-bearing and expose
token0()/token1()that exactly match the pair submitted for registration; - the registrant supplies the pool's current runtime code hash, which the factory re-derives from
EXTCODEHASHand stores as provenance; - the
poolIdmust be unused and the exact pool address must not already be registered under another ID; - registration runs through the shared operational, pause, chain-version and resident-lifecycle gates;
- distinct pools for the same pair remain permitted because permissionless fee/strategy variants are not canonically restricted here.
The factory retains a reference poolImplementation and its deployment-time code hash for discovery/provenance, but it does not treat that reference as a protocol endorsement of every registered pool and does not require runtime-codehash equality with it. Concrete pools can embed immutable pair/executor/fee parameters in runtime bytecode, and the permissionless tier is explicitly not asset-qualified or protocol-oracle-eligible.
Registration records are immutable. There is no governance promotion path from this registry into the canonical tier; canonical status requires a separate CanonicalMarketRegistry action under canonical market policy.
TWAPOracle lifecycle¶
The TWAP path is canonical-pool-derived:
- governance configures a market's minimum observation window, maximum observation window, maximum staleness and enabled state;
- any caller may invoke
checkpoint(marketId)while Swap is operational; - the oracle resolves
CanonicalMarketRegistrythrough ProtocolRegistry and requires an active canonical market; - the pool's token pair must exactly match the canonical market pair;
- the oracle reads the pool's cumulative token0/token1 price state and commits the market/pool/code/pair/metadata identity into
sourceHash; - the first checkpoint seeds a baseline only;
- a later checkpoint derives TWAP from the cumulative delta divided by elapsed time, provided the interval is within the configured window;
- the resulting raw price is normalized for token decimals and stored as quote-per-base Q96;
readObservationandreferencePricefail closed after configured staleness;- a source identity change or overlong window clears the old observation and requires a new baseline/window.
latest(marketId) remains only as a raw compatibility getter. Security-sensitive integrations must use readObservation or referencePrice, which enforce window, freshness and current-source identity. TWAPOracleSourceAdapter420 now uses readObservation and therefore cannot bypass those checks.
The Swap TWAP publishes confidence 0 because a single canonical-pool time average is not a statistical confidence estimate. 420Oracle may combine it with independent sources and apply confidence/quorum/deviation policy without turning external data into executable pricing authority.
PublicBatchAuction lifecycle¶
The frozen PublicBatchAuction address is the execution-layer sale mechanism for native-$420 public distribution. The corresponding PublicDistributionVault remains the inventory authority and enforces its immutable tranche schedule plus the 100,000-420 daily release cap.
The auction itself does not mint native 420. It must be pre-funded before an auction is opened, reserves that exact native balance against concurrent auctions, and caps each opened inventory at the same 100,000-420 bound.
The quote side is restricted to an asset currently marked CANONICAL by ApprovedQuoteAssetRegistry, matching the frozen architecture rule that public distribution uses the canonical gateway-backed stable settlement asset.
Lifecycle:
- governance pre-funds the auction from the distribution path and opens a bounded inventory window with the canonical quote asset and an explicit proceeds recipient;
- any user may escrow quote currency through
bidwhile the auction is open; - exact balance-delta checks reject fee-on-transfer/rebasing behavior that would corrupt custody accounting;
- governance settles after close using the contract's long-standing clearing-price authority, expressed as normalized quote units per one native 420;
- if demand is below inventory, only demanded native 420 remains reserved and unsold inventory is released immediately;
- if demand exceeds inventory, fills are pro-rata by escrowed quote amount;
- each bidder independently claims native fill, while the contract sends exact quote proceeds to the declared recipient and refunds unspent quote;
- claims are replay-protected and unbounded settlement loops are avoided;
- governance may cancel an unsettled auction during incident recovery; inventory is immediately unreserved and every bidder retains a full quote refund;
- once all bidders have claimed, any native rounding remainder is released back to free auction inventory.
The repository does not define a canonical on-chain price-ladder or autonomous clearing algorithm. SWAP-AUDIT-5 therefore preserves the original governance-set clearing-price boundary instead of inventing a new economic policy. Production operations must retain the clearing-price decision/evidence and may additionally constrain it operationally against the canonical TWAP/market policy without changing the executable auction contract silently.
The obsolete CanonicalPool420 source scaffold was retired during the 420Swap repository audit after CanonicalConstantProductPool420 became the executable production candidate. It is not a deployable or registry-authoritative component.
420 Swap does not own a frozen system address for the executor. The canonical Swap executor is registry-resolved under the Genesis address policy. Consumers must resolve current deployment metadata through 420Registry rather than hard-coding an implementation address.
Generated ABI/NatSpec belongs in DOC-10.