Skip to content
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

Flashloans sent back to driver #113

Merged
merged 5 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ pub fn to_domain(auction: &Auction) -> Result<auction::Auction, Error> {
Class::Limit => order::Class::Limit,
},
partially_fillable: order.partially_fillable,
flashloan_hint: order
.flashloan_hint
.clone()
.map(|hint| order::FlashloanHint {
lender: eth::Address(hint.lender),
borrower: eth::Address(hint.borrower),
token: eth::TokenAddress(hint.token),
amount: hint.amount,
}),
})
.collect(),
liquidity: auction
Expand Down
10 changes: 10 additions & 0 deletions src/api/routes/solve/dto/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ pub fn from_domain(solutions: &[solution::Solution]) -> super::Solutions {
})
.collect(),
gas: solution.gas.map(|gas| gas.0.as_u64()),
flashloans: solution
.flashloans
.iter()
.map(|loan| Flashloan {
lender: loan.lender.0,
borrower: loan.borrower.0,
token: loan.token.0,
amount: loan.amount,
})
.collect(),
})
.collect(),
}
Expand Down
10 changes: 10 additions & 0 deletions src/domain/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct Order {
pub side: Side,
pub class: Class,
pub partially_fillable: bool,
pub flashloan_hint: Option<FlashloanHint>,
}

impl Order {
Expand All @@ -31,6 +32,15 @@ impl Order {
}
}

/// A hint for the solver to use a flashloan for this order.
#[derive(Debug, Clone)]
pub struct FlashloanHint {
pub lender: eth::Address,
pub borrower: eth::Address,
pub token: eth::TokenAddress,
pub amount: eth::U256,
}

/// UID of an order.
#[derive(Clone, Copy, Eq, Hash, PartialEq)]
pub struct Uid(pub [u8; 56]);
Expand Down
23 changes: 22 additions & 1 deletion src/domain/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub struct Solution {
pub interactions: Vec<Interaction>,
pub post_interactions: Vec<eth::Interaction>,
pub gas: Option<eth::Gas>,
pub flashloans: Vec<Flashloan>,
}

impl Solution {
Expand Down Expand Up @@ -196,11 +197,22 @@ impl Single {
(order.sell.token, buy),
(order.buy.token, sell.checked_sub(surplus_fee)?),
]),
trades: vec![Trade::Fulfillment(Fulfillment::new(order, executed, fee)?)],
pre_interactions: Default::default(),
interactions,
post_interactions: Default::default(),
gas: Some(gas_offset + self.gas),
flashloans: order
.flashloan_hint
.clone()
.map(|hint| Flashloan {
lender: hint.lender,
borrower: hint.borrower,
token: hint.token,
amount: hint.amount,
})
.into_iter()
.collect(),
trades: vec![Trade::Fulfillment(Fulfillment::new(order, executed, fee)?)],
})
}
}
Expand Down Expand Up @@ -385,3 +397,12 @@ pub const SETTLEMENT: u64 = 7365;
/// Value was computed by taking 52 percentile median of `transfer()` costs
/// of the 90% most traded tokens by volume in the month of Oct. 2021.
pub const ERC20_TRANSFER: u64 = 27_513;

/// A flashloan that is required to execute a solution.
#[derive(Debug, Clone)]
pub struct Flashloan {
pub lender: eth::Address,
pub borrower: eth::Address,
pub token: eth::TokenAddress,
pub amount: eth::U256,
}
Loading