Repository navigation
feat: batch-auction DEX contract - #169
Open
SIDDHANTCOOKIE wants to merge 1 commit into
Open
SIDDHANTCOOKIE wants to merge 1 commit into
SIDDHANTCOOKIE wants to merge 1 commit into
Conversation
examples/batch_auction.py runs one market as a contract: orders escrow their funds, and clear settles every crossing order at a single uniform price (the one that trades the most), filling by price then age and refunding the rest. Orders per batch are capped so every call has bounded gas. The sandbox now allows int and sorted.
Contributor
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. 🗂️ Base branches to auto review: 2
Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
SIDDHANTCOOKIE
added this pull request to stack #158
October 21, 2026 06:58
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.
Summary
Phase 3, PR 1 (stacked on #168). This adds a DEX as a Python contract, using a batch auction instead of an AMM or a continuous order book. Orders collect in a batch, and
clearsettles every crossing order at one uniform price. Everyone in the batch trades at that same price, so the order in which orders arrived, or were placed in a block, doesn't change what anyone gets.There are no consensus changes. It uses the existing multi-asset
msg['value']andtransfer_out.Contract (
examples/batch_auction.py)init:<base_asset>:<quote_asset>sets up one market, once. The native coin is"".buy:<amount>:<price>requires sending exactlyamount × priceof the quote asset.sell:<amount>:<price>requires sending exactlyamountof the base asset. Prices are integers: quote units per one base unit.cancel:<order_id>is owner only, and refunds the escrow.clearcan be called by anyone:filled × pricequote plus any unsold baseMAX_ORDERS = 100per batch keeps every call's gas bounded.Sandbox (
minichain/contract.py)intandsortedto the allowed builtins. Both are pure and add nothing new:range/sum/listalready run in C without gas metering.*,**and@, so the contract multiplies integers with a small doubling helper (O(log n) additions).Measurements
A full batch of 100 random orders:
clearused 46,137 gas and left a zero balance in the contractKnown limits
clearchooses when the batch ends, and can add their own orders before calling it. Uniform pricing limits what that can gain, but a fixed batch schedule needs block height inmsg, which would be a separate change.Test Plan
tests/test_batch_auction.py(12 tests, all run end to end throughState.apply_transaction):