M2 #24: Crank service: Monitor and execute matching#64
Merged
Conversation
- Create new crank crate with core components: - config.rs: CrankConfig with priority fees, poll interval, retries - detector.rs: CrossDetector for detecting bid >= ask conditions - builder.rs: TransactionBuilder for MatchOrders/ConsumeEvents - submitter.rs: TransactionSubmitter with retries and backoff - service.rs: CrankService orchestrating the full workflow - metrics.rs: CrankMetrics for monitoring - Cross detection: - Monitor best bid/ask from BookBuilder - Detect crossing condition (bid >= ask) - Estimate number of matches possible - Transaction building: - Build MatchOrders instruction with configurable limit - Build ConsumeEvents instruction for settlement - Build bundled transactions when possible - Estimate compute units per transaction - Priority fee management: - Dynamic fee calculation based on estimated matches - Configurable min/max priority fee range - Profitability check (fees earned > tx cost) - Transaction submission: - Send with configurable retries - Exponential backoff on failures - Confirmation tracking - SubmitResult enum (Confirmed/Failed/Dropped) - CrankMetrics tracking: - Matches executed - Transactions submitted/success/failed/dropped - Fees paid - Crosses detected - Poll cycles - Success rate and matches/sec - CrankService: - Configurable poll interval - Multiple markets support - Graceful stop mechanism - poll_once() for single cycle execution - 50+ unit tests for all components
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
Implements the crank service that monitors order books for crossing orders and submits MatchOrders transactions. This is a permissionless service that earns priority fees for executing matches.
Changes
New Crate:
crank/Cargo.tomlsrc/lib.rssrc/config.rssrc/detector.rssrc/builder.rssrc/submitter.rssrc/service.rssrc/metrics.rsCross Detection
CrossInfostruct with market, prices, estimated matchesTransaction Building
BuiltTransactionstruct with data, priority fee, compute unitsPriority Fee Management
Transaction Submission
SubmitResultenum: Confirmed, Failed, DroppedCrankMetrics Tracking
CrankService
run()for continuous operationpoll_once()for single cycle executionTechnical Decisions
Testing
Checklist
.internalDoc/09-rust-guidelines.mdcargo clippycargo fmtpassesCloses #24