-
Notifications
You must be signed in to change notification settings - Fork 13
Improved Priority bidding strategy #62
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
base: main
Are you sure you want to change the base?
Changes from all commits
267d66f
b027af6
4a13787
2dd35b3
14497bd
d6dbe11
3aa4e49
a33a373
b1128f1
89a3cf8
28ffdda
f7566be
d29dbf5
64bf027
609790a
bd313ed
File filter
Filter by extension
Conversations
Jump to
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ use alloy_primitives::I256; | |
use alloy_primitives::U256; | ||
use alloy_sol_types::sol; | ||
use anyhow::Result; | ||
use serde::Serialize; | ||
|
||
use crate::sol_math::MulDiv; | ||
|
||
|
@@ -151,6 +152,15 @@ pub enum Order { | |
V3DutchOrder(V3DutchOrder), | ||
} | ||
|
||
#[derive(Serialize, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | ||
#[allow(dead_code)] | ||
pub enum TradeType { | ||
#[serde(rename = "exactIn")] | ||
ExactIn, | ||
#[serde(rename = "exactOut")] | ||
ExactOut, | ||
} | ||
|
||
impl Order { | ||
pub fn encode(&self) -> Vec<u8> { | ||
match self { | ||
|
@@ -159,6 +169,36 @@ impl Order { | |
Order::V3DutchOrder(order) => order.encode_inner(), | ||
} | ||
} | ||
|
||
pub fn trade_type(&self) -> TradeType { | ||
match self { | ||
Order::V2DutchOrder(order) => { | ||
if order.baseOutputs.iter().any(|o| o.startAmount == o.endAmount) { | ||
TradeType::ExactOut | ||
} else { | ||
TradeType::ExactIn | ||
} | ||
} | ||
Order::PriorityOrder(order) => { | ||
if order.outputs.iter().any(|o| o.mpsPerPriorityFeeWei == U256::from(0)) { | ||
TradeType::ExactOut | ||
} else { | ||
TradeType::ExactIn | ||
} | ||
} | ||
Order::V3DutchOrder(order) => { | ||
if order.baseOutputs.iter().any(|o| o.curve.relativeAmounts.len() == 0 || *o.curve.relativeAmounts.last().unwrap() == I256::ZERO) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there might be an edge case when there's a series of relative amounts (non-linear) and the last one happens to be 0 |
||
TradeType::ExactOut | ||
} else { | ||
TradeType::ExactIn | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn is_exact_output(&self) -> bool { | ||
matches!(self.trade_type(), TradeType::ExactOut) | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
|
@@ -268,7 +308,7 @@ impl PriorityOrder { | |
PriorityOrder::abi_encode(self) | ||
} | ||
|
||
pub fn resolve(&self, block_number: u64, block_timestamp: u64, block_time_ms: u64, priority_fee: U256, ) -> OrderResolution { | ||
pub fn resolve(&self, block_number: u64, block_timestamp: u64, block_time_ms: u64, priority_fee: U256, min_block_percentage_buffer: u64) -> OrderResolution { | ||
let block_time = block_time_ms / 1000; | ||
let next_block_timestamp = U256::from(block_timestamp) + U256::from(block_time); | ||
|
||
|
@@ -294,7 +334,7 @@ impl PriorityOrder { | |
block_timestamp, | ||
block_time_ms | ||
); | ||
let time_buffer_ms = block_time_ms * 1300 / 1000; // TODO: fine tune | ||
let time_buffer_ms = block_time_ms * min_block_percentage_buffer / 100; | ||
if U256::from(current_timestamp_ms() + time_buffer_ms).lt(&target_block_ms) { | ||
return OrderResolution::NotFillableYet(ResolvedOrder { input, outputs }); | ||
} | ||
|
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this removable?