-
Notifications
You must be signed in to change notification settings - Fork 185
feat(solana-driver): Solver interaction #4749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e075a77
solver interaction
tilacog 2955218
remove low value tests and the `solve-all` fn
tilacog 1be45fa
move timeout to Auction level
tilacog 827e641
source timeline from env (optionally)
tilacog 0b7f4e6
simplify: remove serde traits for OrderUid
tilacog a4f0ef9
simplify base64 serialization
tilacog 3a02112
improve dull test for ATA derivation
tilacog 34ff1f3
doc: clarify clarify into_domain comment on unknown order UIDs
tilacog f95991d
fix: compute request timeout after acquiring a permit
tilacog d6bb454
feat(serde-ext): normalize URLs with a trailing slash on deserialize
tilacog 177cd6d
Merge remote-tracking branch 'origin/main' into solana-driver-solver-…
tilacog e5d3764
doc: trim comment
tilacog 6024107
remove unused accessor methods
tilacog 188b53d
chore(deps): bump h2 to 0.4.16 to fix RUSTSEC-2026-0258
tilacog 0bd6114
refactor(solana-driver): drop unused `fee` field from domain Trade
tilacog 1a12165
refactor(solana-driver, solana-solvers): use i64 for auction id
tilacog 973e713
reject trades that over-execute the order amount
tilacog 72f9104
add TODO for splitting the deadline budget
tilacog bfdcbd6
return DeadlineExceeded error when the auction deadline expires
tilacog b6e7ff0
assert semaphore is never closed on acquire
tilacog 00bbb80
solana-driver,solana-solvers: add deadline to the auction DTO
tilacog cf9e2c9
fmt
tilacog f7bf3e9
pin solver DTO wire format with serde shape tests
tilacog 533dc4a
add todo comment on token-2022 support
tilacog 3690b1a
test(solana-driver): cover solver deadline-exceeded path
tilacog c4eae2b
Merge branch 'main' into solana-driver-solver-client
tilacog 2ee22ef
Merge branch 'main' into solana-driver-solver-client
tilacog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| use { | ||
| serde::{Deserialize, Deserializer}, | ||
| url::Url, | ||
| }; | ||
|
|
||
| /// Deserialize a URL and make sure its path ends with a slash. | ||
| pub fn deserialize_url_with_trailing_slash<'de, D>(deserializer: D) -> Result<Url, D::Error> | ||
| where | ||
| D: Deserializer<'de>, | ||
| { | ||
| let mut url = Url::deserialize(deserializer)?; | ||
| if !url.path().ends_with('/') { | ||
| url.set_path(&format!("{}/", url.path())); | ||
| } | ||
| Ok(url) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use { | ||
| super::*, | ||
| serde::de::value::{Error, StrDeserializer}, | ||
| }; | ||
|
|
||
| #[test] | ||
| fn appends_trailing_slash_when_missing() { | ||
| let de = StrDeserializer::<Error>::new("http://localhost:8001/api"); | ||
| let url: Url = deserialize_url_with_trailing_slash(de).unwrap(); | ||
| assert_eq!(url.as_str(), "http://localhost:8001/api/"); | ||
| assert_eq!( | ||
| url.join("solve").unwrap().as_str(), | ||
| "http://localhost:8001/api/solve" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn keeps_existing_trailing_slash() { | ||
| let de = StrDeserializer::<Error>::new("http://localhost:8001/api/"); | ||
| let url: Url = deserialize_url_with_trailing_slash(de).unwrap(); | ||
| assert_eq!(url.as_str(), "http://localhost:8001/api/"); | ||
| } | ||
| } | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| //! Domain model of an auction the driver asks solver engines to fill. | ||
|
|
||
| use {super::order_uid::OrderUid, serde::Serialize, solana_sdk::pubkey::Pubkey}; | ||
|
|
||
| /// A collection of orders the driver wants solvers to fill. | ||
| #[derive(Clone, Debug)] | ||
| pub struct Auction { | ||
| pub id: i64, | ||
| pub orders: Vec<Order>, | ||
| /// Absolute deadline by which solver engines must return solutions. The | ||
| /// driver derives each request's timeout as the time remaining until this | ||
| /// instant, and skips the request entirely if the deadline has passed. | ||
| pub deadline: chrono::DateTime<chrono::Utc>, | ||
| } | ||
|
|
||
| /// One order available for solvers to fill. | ||
| #[derive(Clone, Debug)] | ||
| pub struct Order { | ||
| pub uid: OrderUid, | ||
| pub sell_mint: Pubkey, | ||
| pub buy_mint: Pubkey, | ||
| /// Sell amount for sells, buy amount for buys. | ||
| pub amount: u64, | ||
| pub side: Side, | ||
| } | ||
|
|
||
| /// Direction of the trade. | ||
| #[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)] | ||
| #[serde(rename_all = "camelCase")] | ||
| pub enum Side { | ||
| Sell, | ||
| Buy, | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| //! Domain model of the Solana driver. | ||
| //! | ||
| //! These types describe the concepts the driver works with — auctions and | ||
| //! solutions — independent of any wire format or RPC representation. | ||
|
|
||
| pub mod auction; | ||
| pub mod order_uid; | ||
| pub mod solution; | ||
|
|
||
| pub use self::{ | ||
| auction::{Auction, Order, Side}, | ||
| solution::{Solution, Trade}, | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //! CoW Protocol order identifier. | ||
|
|
||
| use std::{fmt, str::FromStr}; | ||
|
|
||
| /// A 32-byte CoW Protocol order identifier, equal to `hash(intent)`, serialized | ||
| /// as a `0x`-prefixed hex string on the wire. | ||
| #[derive(Clone, Copy, PartialEq, Eq, Hash)] | ||
| pub struct OrderUid(pub [u8; 32]); | ||
|
|
||
| impl fmt::Display for OrderUid { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| let mut buffer = const_hex::Buffer::<32, true>::new(); | ||
| f.write_str(buffer.format(&self.0)) | ||
| } | ||
| } | ||
|
|
||
| impl fmt::Debug for OrderUid { | ||
| fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
| write!(f, "{self}") | ||
| } | ||
| } | ||
|
|
||
| impl FromStr for OrderUid { | ||
| type Err = const_hex::FromHexError; | ||
|
|
||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let mut bytes = [0u8; 32]; | ||
| const_hex::decode_to_slice(s.strip_prefix("0x").unwrap_or(s), &mut bytes)?; | ||
| Ok(Self(bytes)) | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn order_uid_roundtrip() { | ||
| let uid = OrderUid([0xab; 32]); | ||
| let text = uid.to_string(); | ||
| assert_eq!(text, format!("0x{}", "ab".repeat(32))); | ||
| assert_eq!(OrderUid::from_str(&text).unwrap(), uid); | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| //! Domain model of a solver engine's solution. | ||
|
|
||
| use { | ||
| super::order_uid::OrderUid, | ||
| solana_sdk::{instruction::Instruction, pubkey::Pubkey}, | ||
| }; | ||
|
|
||
| /// A single solver engine's response to one auction. | ||
| #[derive(Clone, Debug)] | ||
| pub struct Solution { | ||
| pub id: u64, | ||
| /// The on-chain identity of the solver that produced this solution. | ||
| pub solver: Pubkey, | ||
| pub trades: Vec<Trade>, | ||
| /// Solana instructions to execute as part of the settlement. | ||
| pub interactions: Vec<Instruction>, | ||
| /// Address lookup tables the interactions assume. | ||
| pub address_lookup_tables: Vec<Pubkey>, | ||
| /// Optional solver estimate of total settlement compute units. | ||
| pub cu_estimate: Option<u64>, | ||
| } | ||
|
|
||
| /// A fulfillment of one auction order. | ||
| #[derive(Clone, Debug)] | ||
| pub struct Trade { | ||
| pub order_uid: OrderUid, | ||
| /// Sell-token units for sell orders, buy-token units for buy orders. | ||
| pub executed_amount: u64, | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.