Skip to content

feat: add sealed bid auction example#115

Open
dhruvja wants to merge 2 commits into
mainfrom
dhruvja/feat/sealed-bid-auction
Open

feat: add sealed bid auction example#115
dhruvja wants to merge 2 commits into
mainfrom
dhruvja/feat/sealed-bid-auction

Conversation

@dhruvja

@dhruvja dhruvja commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Closes: #114

Summary

  • Add a private sealed-bid auction Anchor example using MagicBlock private ER/PER and SPL Token escrow.
  • Keep the seller's Token A lot on L1 while delegating auction-owned Token B escrow for ER-side bids, settlement, and refunds.
  • Add private per-bid PDAs, count-checked winner selection, cleanup-gated auction undelegation, example docs, root README listing, and local runner support.

Testing

  • anchor build
  • ./node_modules/.bin/tsc --noEmit -p tsconfig.json
  • yarn lint
  • yarn test:local
  • RUN_SEALED_AUCTION_LIVE=1 NO_DNA=1 EXACT_MATCH=1 ./scripts/test-locally.sh sealed-auction

Breaking Changes

None.

Summary by CodeRabbit

  • New Features

    • Added a new sealed-bid auction example with private bidding, escrowed token handling, and full auction lifecycle support.
    • Included the new example in the project listings and documentation index.
  • Bug Fixes

    • Improved auction state checks and refund safeguards for more reliable bid settlement.
    • Added clearer error messages for invalid auction, bid, and escrow conditions.
  • Documentation

    • Added setup and workflow documentation for running and testing the new auction example.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@dhruvja, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 18 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: af58f12a-b440-405e-bb1e-ed19b276eaf5

📥 Commits

Reviewing files that changed from the base of the PR and between 0ded29c and 28a0a9f.

⛔ Files ignored due to path filters (2)
  • sealed-auction/anchor/tests/fixtures/dlp.so is excluded by !**/*.so
  • sealed-auction/anchor/tests/fixtures/ephemeral_token_program.so is excluded by !**/*.so
📒 Files selected for processing (5)
  • sealed-auction/anchor/Anchor.toml
  • sealed-auction/anchor/programs/sealed-auction/src/error.rs
  • sealed-auction/anchor/programs/sealed-auction/src/lib.rs
  • sealed-auction/anchor/programs/sealed-auction/src/state.rs
  • sealed-auction/anchor/tests/sealed-auction.ts

Walkthrough

Adds a new "sealed-auction" Anchor program example implementing a private first-price sealed-bid auction with SPL Token escrow on ephemeral rollups, including on-chain program logic, state/error definitions, an extensive test suite, build configuration, documentation, and registration in repository scripts/README.

Changes

Sealed Auction Example

Layer / File(s) Summary
Project registration and docs
scripts/projects.sh, README.md, sealed-auction/README.md
Registers sealed-auction as a TEE project with its directory mapping, adds a README example card, and documents the auction design/flow/tests.
Build/workspace configuration
sealed-auction/anchor/Anchor.toml, sealed-auction/anchor/Cargo.toml, sealed-auction/anchor/package.json, sealed-auction/anchor/programs/sealed-auction/Cargo.toml, sealed-auction/anchor/tsconfig.json
Adds Anchor, Cargo workspace/crate, npm, and TypeScript configuration for the new package.
State and error definitions
sealed-auction/anchor/programs/sealed-auction/src/state.rs, .../src/error.rs
Defines Auction/Bid account structs, AuctionStatus enum, MAX_BIDDERS, and a 14-variant ErrorCode enum.
Core program logic and account contexts
sealed-auction/anchor/programs/sealed-auction/src/lib.rs
Implements instruction handlers for initialize/delegate/bid/end/settle/refund/finalize, internal permission and ephemeral token helpers, PDA derivation, and all #[derive(Accounts)] structs.
Test suite
sealed-auction/anchor/tests/sealed-auction.ts
Adds helpers, fixtures, and unit/functional/e2e tests covering PDA derivation, IDL surface checks, initialization, error paths, live ER settlement flow, and TEE authentication probes.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • magicblock-labs/magicblock-engine-examples#84: Both PRs add Anchor examples implementing the same ephemeral rollups permission flow (create/update/close permissions, delegate/commit/undelegate) via ephemeral-rollups-sdk CPI handlers.

Suggested reviewers: GabrielePicco, jonasXchen

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.44% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and directly describes the new sealed-bid auction example.
Linked Issues check ✅ Passed The PR implements the requested private sealed-bid auction example with private ER and Ephemeral SPL Token escrow.
Out of Scope Changes check ✅ Passed The added files and script updates all support the sealed-bid auction example and its tests/documentation.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dhruvja/feat/sealed-bid-auction

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
binary-prediction-demo Ready Ready Preview, Comment Jul 9, 2026 7:35am
counter-session-keys Ready Ready Preview, Comment Jul 9, 2026 7:35am
er-rolldice Ready Ready Preview, Comment Jul 9, 2026 7:35am
magicblock-counter-example Ready Ready Preview, Comment Jul 9, 2026 7:35am
magicblock-engine-examples Ready Ready Preview, Comment Jul 9, 2026 7:35am
magicblock-rewards-dashboard Ready Ready Preview, Comment Jul 9, 2026 7:35am
rps-example Ready Ready Preview, Comment Jul 9, 2026 7:35am
spl-tokens Ready Ready Preview, Comment Jul 9, 2026 7:35am

Request Review

@dhruvja

dhruvja commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 9

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@sealed-auction/anchor/Anchor.toml`:
- Around line 21-29: The test genesis entries in Anchor.toml are depending on
fixtures from the binary-prediction example, unlike the rest of the project’s
local fixture usage. Update the [[test.genesis]] program paths so sealed-auction
uses its own fixture binaries, or move the shared .so files into a common
fixture location if they are meant to be reused. Keep the existing genesis
addresses and adjust only the fixture source references in Anchor.toml.

In `@sealed-auction/anchor/package.json`:
- Line 11: The Anchor TypeScript client version in package.json is out of sync
with the Anchor CLI/toolchain pinned in Anchor.toml. Update the
sealed-auction/anchor dependency on `@coral-xyz/anchor` from the 0.32.x line to
the 1.0.x client line, or otherwise make the CLI and TS client versions match,
so the generated IDL and instruction serialization remain compatible.

In `@sealed-auction/anchor/programs/sealed-auction/src/error.rs`:
- Around line 7-8: The `DeadlineInPast` error in `error.rs` is being reused by
`end_auction` for the opposite condition (`now < deadline_ts`), so its meaning
and message are misleading. Add a separate error variant with a name that
matches the “auction still open / deadline not passed” case, update the
`end_auction` check in `lib.rs` to use that variant, and keep `DeadlineInPast`
reserved for actual past-deadline validation.

In `@sealed-auction/anchor/programs/sealed-auction/src/lib.rs`:
- Around line 600-678: The ephemeral SPL token instruction discriminators are
hardcoded in init_ephemeral_ata and delegate_ephemeral_ata, which makes the
intent opaque and easy to mistype. Introduce named constants for the
discriminators used by these helpers, then replace the raw vec![0] and vec![4]
values with those constants in the instruction data construction. Keep the
change localized to the init_ephemeral_ata and delegate_ephemeral_ata functions
so the instruction encoding remains explicit and maintainable.
- Around line 365-401: The finalize flow in finalize currently moves the auction
to Settled too early, which prevents settle_winning_bid and claim_refund from
running because they still expect Ended. Update finalize to only allow lot
claiming after all bids are closed, following the same pattern used by
undelegate_auction, and keep the auction in the correct pre-settlement state
until the seller’s bid settlement and refunds can complete. Use the existing
symbols finalize, settle_winning_bid, claim_refund, and AuctionStatus to locate
and adjust the state transition guard.

In `@sealed-auction/anchor/programs/sealed-auction/src/state.rs`:
- Around line 27-35: The Bid.refunded field is currently dead because it is only
read in claim_refund via require! but never written anywhere; update the refund
flow around claim_refund and close_ephemeral_bid to either remove refunded and
its check entirely, or set bid.refunded to true before the account is closed if
you want an explicit guard. Use the Bid struct in state.rs and the
claim_refund/close_ephemeral_bid handlers to keep the state model consistent.

In `@sealed-auction/anchor/tests/sealed-auction.ts`:
- Around line 122-127: The deadline-based tests are using local wall-clock time
in `sleepUntilUnixTimestamp` and fixture setup, which can drift from Solana
`Clock` and make the on-chain deadline assertions flaky. Update the test helpers
to derive waiting/deadline values from validator block time instead of
`Date.now()`, and adjust `createBaseAuctionFixture` so `deadlineTs` comes from
the chain clock rather than the runner clock. Keep the fix centered around the
`sleepUntilUnixTimestamp` helper and the deadline initialization/assertions in
the sealed auction tests, including the empty-auction path.
- Around line 308-316: Update requireLocalE2e in sealed-auction tests so live ER
runs do not fall back to ctx.skip() when explicitly requested. The current logic
only throws localE2eSkipReason when RUN_E2E is set, but RUN_SEALED_AUCTION_LIVE
should also be treated as an explicit request and fail fast if localE2eAvailable
is false. Check the existing RUN_E2E / live-test gating in requireLocalE2e and
make the skip path unreachable for explicitly requested live coverage.
- Around line 755-826: The bid submission loop is using the
auctioneer-authenticated ER connection for both `placeBid` transactions, so
bidder isolation is not actually being tested. Update the logic around
`authenticatedErConnection`, `privateErProvider`, `privateErProgram`, and the
`placeBid` loop to create and use a bidder-specific authenticated connection for
each bidder inside the loop, then submit each bid through that bidder’s own
provider/program instance instead of reusing the auctioneer connection.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 31c0d387-c7ed-4326-bdd4-b24225c63629

📥 Commits

Reviewing files that changed from the base of the PR and between 13b561f and 0ded29c.

⛔ Files ignored due to path filters (2)
  • sealed-auction/anchor/Cargo.lock is excluded by !**/*.lock
  • sealed-auction/anchor/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (12)
  • README.md
  • scripts/projects.sh
  • sealed-auction/README.md
  • sealed-auction/anchor/Anchor.toml
  • sealed-auction/anchor/Cargo.toml
  • sealed-auction/anchor/package.json
  • sealed-auction/anchor/programs/sealed-auction/Cargo.toml
  • sealed-auction/anchor/programs/sealed-auction/src/error.rs
  • sealed-auction/anchor/programs/sealed-auction/src/lib.rs
  • sealed-auction/anchor/programs/sealed-auction/src/state.rs
  • sealed-auction/anchor/tests/sealed-auction.ts
  • sealed-auction/anchor/tsconfig.json

Comment thread sealed-auction/anchor/Anchor.toml
Comment thread sealed-auction/anchor/package.json
Comment thread sealed-auction/anchor/programs/sealed-auction/src/error.rs
Comment thread sealed-auction/anchor/programs/sealed-auction/src/lib.rs
Comment thread sealed-auction/anchor/programs/sealed-auction/src/lib.rs
Comment thread sealed-auction/anchor/programs/sealed-auction/src/state.rs
Comment thread sealed-auction/anchor/tests/sealed-auction.ts Outdated
Comment thread sealed-auction/anchor/tests/sealed-auction.ts
Comment thread sealed-auction/anchor/tests/sealed-auction.ts
@jonasXchen

jonasXchen commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

lgtm!

only thing is the test for rps is failing.

@dhruvja

dhruvja commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

lgtm!

only thing is the test for rps is failing.

great, thanks. sometimes the tests fail due to failure in installing the solana platform tools. i just restarted it so that should make it work

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.

Add private sealed-bid auction example

2 participants