feat(quoter-bot): add ethereum mainnet support - #173
Draft
julien-devatom wants to merge 1 commit into
Draft
Conversation
Thread the configured chain through every client, address lookup, and
Morpho API query so CHAIN_ID accepts 1 (Ethereum mainnet) alongside 8453
(Base). Previously the chain was pinned by a BASE_CHAIN_ID constant,
viem/chains `base` imports, and hardcoded `chain_ids=8453` filters.
Per-chain deployment facts now live in one seam,
config/supported-chains.utils.ts:
- Midnight mainnet addresses are registered through the SDK's own
registerCustomAddresses, because the pinned morpho-ts registry carries
Midnight entries for Base only (verified unchanged in latest 2.9.0).
Registration merges rather than replaces, so chain 1 keeps its upstream
Morpho Blue entries, and is driven from the accessors instead of module
evaluation so no call site depends on import order.
- Ratifier runtime-bytecode hashes become chain-keyed. Ratifier runtime
embeds its immutable Midnight target, so the previously pinned Base
hashes would have failed every mainnet setup check. Mainnet hashes were
read from live bytecode with the Base hashes recomputed as a control,
reproducing the existing constants exactly.
supportedChain() also installs the address shim: the SDK's
morpho.midnight(chainId) extension stores only { client, chainId } and
resolves addresses lazily per call, so it would otherwise bypass the
chainAddress wrapper.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Blocked on mainnet API support — do not merge yet
This is intentionally a draft. The code is complete and verified, but the bot cannot actually
run on mainnet until the Morpho API serves chain 1.
api.morpho.orgcurrently rejects mainnet on every/v0/midnight/*endpoint:The quoter bot reads four Morpho API endpoint families — markets, offer-groups, books
takeable-offers, and prospective-offer validation — so correct contract addresses alone are not
enough. With
CHAIN_ID=1against the public API, the bot passes its on-chain checks and then failsat the books/markets stage.
MORPHO_API_BASE_URLis configurable, so an origin that serves chain-1Midnight data unblocks this without further code changes.
Why
Midnight is deployed on Ethereum mainnet, but the bot was pinned to Base in three ways: a
BASE_CHAIN_IDconstant,viem/chainsbaseimports, and hardcodedchain_ids=8453API filters.This threads the configured chain through every client, address lookup, and API query so
CHAIN_IDaccepts
1alongside8453.Two upstream sources still know only about Base, and this PR works around both:
@morpho-org/morpho-tscarries Midnight entries for Base only —confirmed unchanged in the latest 2.9.0, not just our pinned 2.8.0. Mainnet addresses are
registered through the SDK's own
registerCustomAddresses. That call merges rather thanreplaces, so chain 1 keeps its upstream Morpho Blue entries (42 → 46 keys); there is a regression
test pinning this, because a replacing registration would silently break the reference-rate reads.
The non-obvious bug this avoids
viem-setup-state.utils.tspinned keccak256 hashes of the Base ratifier bytecode as a safetygate. Ratifier runtime embeds its immutable Midnight target, so mainnet's hashes necessarily differ
— the old constants would have failed every mainnet setup check. These are now chain-keyed, and
live beside the addresses so they get updated together.
The mainnet hashes were read from live bytecode with the Base hashes recomputed in the same pass as
a control, reproducing the existing pinned constants byte-for-byte.
Separately,
supportedChain()installs the address shim rather than leaving it tochainAddress():the SDK's
morpho.midnight(chainId)extension stores only{ client, chainId }and resolvesaddresses lazily per call, so it would otherwise bypass the wrapper entirely.
Address provenance
Mainnet addresses were supplied by @julien-devatom and verified before being committed:
MIDNIGHT()returns exactly the singleton in this PR (same-deployment proof),with Base checked the same way as a passing control;
configuratoris the same address on both chains.ecrecoverAuthorizerwas also supplied but is deliberately not registered — the quoter bot neverreads it.
Verification
jsdoc:checkandjsdoc:buildexit 0ratifier-rejection tests
CHAIN_ID=1resolves the mainnet mempool while keeping chain-1 Blueintact,
8453is unchanged,10is rejectedPre-existing and untouched: the quoter-bot and midnight-liquidation e2e fork suites need
RPC_URL_8453and remain Base-pinned. Porting them needs a mainnet fork URL, so they were leftalone rather than half-converted.
🤖 Generated with Claude Code