Skip to content

feat(bots): add monitored market making and offer invalidation - #114

Draft
julien-devatom wants to merge 10 commits into
mainfrom
fix/market-making-bootstrap-monitor
Draft

feat(bots): add monitored market making and offer invalidation#114
julien-devatom wants to merge 10 commits into
mainfrom
fix/market-making-bootstrap-monitor

Conversation

@julien-devatom

@julien-devatom julien-devatom commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • add fail-loud monitored setup checks and monitored market bootstrap with safe verbose diagnostics, submitted transaction hashes, and owned-offer cleanup on shutdown
  • add production ladder reconciliation with fresh inventory, reference-rate, and capacity reads; nearest-rung funding; a 101 USDC floor; correct reduce-only lower and lend-side higher offers; durable ownership; transaction validation; signing and broadcast; replacement; and cleanup
  • make ladder read-only mode exercise the same tree construction, spread guard, and unsigned Mempool validation as live publication
  • harden local signing, pending-aware nonce allocation, fresh group IDs, cleanup against current on-chain consumption, cross-strategy cash-reservation accounting, bounded monitor timers, independent transaction-confirmation deadlines, and durable retirement of confirmed canceled groups
  • add invalidate [group-id]: invalidate every active maker group by default or one explicit group, with exact transaction policy checks, receipt confirmation, partial-failure reporting, durable cleanup, and read-only preview
  • document every supported environment variable and every BOOTSTRAP_MARKETS and LADDER_MARKETS field, including units, defaults, constraints, and ladder-side semantics

Operator commands

bun run start -- setup-check --monitor
bun run start -- bootstrap --monitor --verbose
bun run start -- ladder --monitor --verbose
bun run start -- invalidate
bun run start -- invalidate 0x<64-hex-group-id>

Add --readonly to bootstrap, ladder, or invalidate to inspect and validate the intended action without signing or broadcasting.

Verification

  • Node.js 24.14.1 and pinned Bun 1.3.12
  • bun install --frozen-lockfile
  • bun run --filter @morpho-org/market-making-bot typecheck
  • bun lint — 0 warnings, 0 errors across 332 files
  • bun format
  • bun knip
  • bun run --filter @morpho-org/market-making-bot jsdoc:build — 320 declarations, including the checker and ladder signature utility
  • bun test --dots — 1,309 passed, 3 skipped, 0 failed, 7,304 assertions across 121 files
  • anti-vacuity verification: deliberately broke the read-only ladder validation assertion and the confirmed invalidation transaction-hash assertion, observed both focused tests fail, restored them, and reran green
  • live read-only ladder recenter exercised the exact tree, Mempool, and spread validation path without signing or broadcasting
  • live read-only ladder inspection encoded the lower reduce-only offer near 4.02% APR and the higher lend offer near 4.53% APR; neither encoded 0%
  • live read-only invalidation inspection covered both all-groups discovery and direct group targeting without signing or broadcasting

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 43a33a7e3f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bots/market-making/src/infrastructure/ladder/ladder-offer.utils.ts Outdated
Comment thread bots/market-making/src/infrastructure/ladder/production-ladder.ts Outdated
Comment thread bots/market-making/src/application/ladder/ladder-market-maker.service.ts Outdated
Comment thread bots/market-making/src/infrastructure/cli/cli.ts Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3abf2e35eb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bots/market-making/src/infrastructure/ladder/ladder-offer.utils.ts Outdated
Comment thread bots/market-making/src/infrastructure/ladder/ladder-group-ownership.utils.ts Outdated
Comment thread bots/market-making/src/application/ladder/ladder-market-maker.service.ts Outdated

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

export const inspectJSDocSource = (file: string, source: string): JSDocInspection => {

P3 Badge Document the exported JSDoc inspection helper

This exported helper is part of the script's TypeScript surface (the tests import it), but it has no substantive JSDoc and the checker does not include scripts/check-jsdoc.ts in its own enforced inventory. That lets the new documentation gate pass while one of its own exported APIs violates the repository’s public-surface documentation rule; add JSDoc for this helper and include the script in the inventory.

AGENTS.md reference: AGENTS.md:L32-L36

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bots/market-making/src/infrastructure/bootstrap/production-bootstrap.ts Outdated
@julien-devatom julien-devatom changed the title feat(bots): add monitored market bootstrap and ladder feat(bots): add monitored market making and offer invalidation Jul 30, 2026
@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

async reconcile(parameters: Parameters<LadderMakeService['reconcile']>[0]) {
this.write(formatReadOnlyMakeEvent('ladder', 'reconcile', parameters))
return 'logged' as const

P2 Badge Validate ladder dry-runs before logging them

When an operator uses ladder --readonly or its monitor as a preflight, this adapter logs every reconcile request without invoking the production tree builder, spread guard, or unsigned Mempool validation. Live publication still performs those checks, so cases such as a market that matures after the initial setup gate or an SDK/Mempool policy rejection are reported as logged in dry-run but halt in write mode; add a validation seam like bootstrap read-only uses before emitting the readonly.make record.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bots/market-making/src/application/invalidation/offer-invalidation.service.ts Outdated
Comment thread bots/market-making/typedoc.json
@julien-devatom

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c042128a0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

this.safeObserver(parameters.onTransactionSubmitted)
)
if (txHash) submittedTransactions.push({ operation: 'cancel', txHash })
await this.transport.forgetGroups?.([groupId])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't retry a confirmed bootstrap cancel

When the local ownership write fails here after invalidate() has already returned a confirmed cancel during a normal replace/target-reached/no-capacity reconciliation, this shared catch treats the cleanup failure as an invalidation failure. The application can then hard-halt with the unchanged ownership file and submit another cancel for the same already-consumed group, while the failure report also loses the confirmed tx hash; record the cancellation before attempting forgetGroups and report ownership cleanup separately.

Useful? React with 👍 / 👎.

this.safeObserver(parameters.onTransactionSubmitted)
)
if (txHash) submittedTransactions.push({ operation: 'cancel', txHash })
await this.transport.forgetGroups([groupId])

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Don't retry confirmed ladder cancels

When invalidate() has already confirmed a ladder replacement cancellation but this ownership cleanup write fails, the catch below reports the whole reconciliation as failed and leaves the canceled group in durable ownership. The next cycle or cleanup can then submit another cancel for the already-consumed group, and the structured result loses the confirmed cancellation hash; record the confirmed cancel before forgetGroups and surface ownership cleanup as its own failure.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant