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.
Status: mainnet API is live — unblocked
The earlier blocker is cleared.
api.morpho.orgnow serves chain 1 across every endpoint familythis bot uses, verified against live data:
/v0/midnight/markets?chain_ids=1200— 1 market (USDC, maturity 1787929200)/v0/midnight/users/{maker}/offer-groups?chain_ids=1200/v0/midnight/books/{id}/asks/takeable-offers200— live offers,chain_id: 1/v0/midnight/books/{id}/bids/takeable-offers200— live offers,chain_id: 1The returned offers carry
midnight: 0x471686c4…2045f, matching the singleton registered here.One operational caveat, not a code issue: that market is not
listed=trueyet(
markets?chain_ids=1&listed=truereturns an empty set).getBookgates on the listing allowlist,so until it is listed,
setup-checkwill reportnot allowlistedfor it. Nothing to change in thisPR — it just needs the market listed API-side before a mainnet run goes green.
Follow-up: the local address shim is now redundant
@morpho-org/morpho-ts@2.10.0ships mainnet Midnight addresses, and all four match this PRexactly (it also adds
ecrecoverAuthorizer,midnightBundles, andmidnightBlueBuyCallbackFactory). TheregisterCustomAddressesshim insupported-chains.utils.tscan therefore be deleted — its own JSDoc says as much.I deliberately did not do it here, because bumping
morpho-tsalone is not safe:morpho-ts2.8.0; bumping only that pin resolves quoter-bot andblue-sdkto2.10.0while
morpho-sdk@5.4.1stays on2.8.0— two instances;getChainAddressreads a module-level registry, andmorpho.midnight(chainId)resolvesaddresses lazily through morpho-sdk's own instance, so it would read the copy with no mainnet
Midnight entries and throw
UnknownAddressErrorat runtime — a silent mainnet break that thecurrent single-instance
2.8.0setup does not have;pnpm dedupeand anoverridesentry both failed to collapse the two.The real fix is a coordinated stack bump —
morpho-sdk@5.7.0(which requiresmorpho-ts ^2.10.0),blue-sdk ^6.6.0,blue-sdk-viem ^5.4.0— which touches all six bots and is exactly the kind ofchange
pnpm-workspace.yamlsays should be "a separate, deliberate bump". Worth its own PR; thisone stays on the pinned stack and keeps working either way.
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.Mainnet Midnight addresses are registered through the SDK's own
registerCustomAddresses, becausethe pinned registry carries Midnight entries for Base only. That call merges rather than
replaces, 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 independently verified before being
committed — and have since been confirmed against
morpho-ts@2.10.0: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.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