-
Notifications
You must be signed in to change notification settings - Fork 93
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
Define protocol fee params and forward to driver #2098
Changes from all commits
8f96168
2ce7191
53d450a
a999ef1
448d867
4cd02a2
2dd0134
6f26b5c
9c573c6
f783d68
1e79009
5ef6d5d
88e0152
b6ff257
a65d537
1164bf2
484ca6b
900aa34
723a4bf
7557415
b655bec
f3974c2
ac5ddac
cb3e54f
87743ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ pub mod quote { | |
|
||
pub mod solve { | ||
use { | ||
crate::arguments, | ||
chrono::{DateTime, Utc}, | ||
model::{ | ||
app_data::AppDataHash, | ||
|
@@ -87,7 +88,7 @@ pub mod solve { | |
} | ||
|
||
#[serde_as] | ||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
#[derive(Clone, Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct Order { | ||
pub uid: OrderUid, | ||
|
@@ -116,6 +117,9 @@ pub mod solve { | |
pub app_data: AppDataHash, | ||
#[serde(flatten)] | ||
pub signature: Signature, | ||
/// The types of fees that will be collected by the protocol. | ||
/// Multiple fees are applied in the order they are listed | ||
pub fee_policies: Vec<FeePolicy>, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize, Deserialize)] | ||
|
@@ -137,6 +141,51 @@ pub mod solve { | |
pub call_data: Vec<u8>, | ||
} | ||
|
||
#[derive(Clone, Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub enum FeePolicy { | ||
/// If the order receives more than expected (positive deviation from | ||
/// quoted amounts) pay the protocol a factor of the achieved | ||
/// improvement. The fee is taken in `sell` token for `buy` | ||
/// orders and in `buy` token for `sell` orders. | ||
#[serde(rename_all = "camelCase")] | ||
PriceImprovement { | ||
sunce86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Factor of price improvement the protocol charges as a fee. | ||
/// Price improvement is the difference between executed price and | ||
/// limit price or quoted price (whichever is better) | ||
/// | ||
/// E.g. if a user received 2000USDC for 1ETH while having been | ||
/// quoted 1990USDC, their price improvement is 10USDC. | ||
/// A factor of 0.5 requires the solver to pay 5USDC to | ||
/// the protocol for settling this order. | ||
factor: f64, | ||
/// Cap protocol fee with a percentage of the order's volume. | ||
max_volume_factor: f64, | ||
}, | ||
/// How much of the order's volume should be taken as a protocol fee. | ||
/// The fee is taken in `sell` token for `sell` orders and in `buy` | ||
/// token for `buy` orders. | ||
Comment on lines
+166
to
+167
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. ditto - what currency does the protocol charge solvers the fee in? 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. As you mentioned in the comment ☝️ , the protocol collects the protocol fees in different tokens. The question is, whether the conversion to ETH/COW/else should be done in the autopilot or later in the script for accounting. 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. The conversion will be done in the script similarly to how we do it in solver rewards script, using the 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. Sure, but it will still be charged in some currency right? Solvers will receive a bill from us at the end of the week saying: order x got 100 USDT price improvement, please pay us
Comment on lines
+166
to
+167
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. The fees get taken in the opposite token (compared to surplus fee). This is because it would allow us to easily implement the fee model in the driver without solvers having to know about it, right? 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. My initial idea was that we need to take the fee as some percent of the |
||
#[serde(rename_all = "camelCase")] | ||
Volume { | ||
sunce86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// Percentage of the order's volume should be taken as a protocol | ||
/// fee. | ||
factor: f64, | ||
}, | ||
} | ||
|
||
pub fn fee_policy_to_dto(fee_policy: &arguments::FeePolicy) -> FeePolicy { | ||
match fee_policy.fee_policy_kind { | ||
arguments::FeePolicyKind::PriceImprovement { | ||
factor: price_improvement_factor, | ||
max_volume_factor, | ||
} => FeePolicy::PriceImprovement { | ||
factor: price_improvement_factor, | ||
max_volume_factor, | ||
}, | ||
arguments::FeePolicyKind::Volume { factor } => FeePolicy::Volume { factor }, | ||
} | ||
} | ||
|
||
#[serde_as] | ||
#[derive(Clone, Debug, Default, Deserialize)] | ||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#[derive(Clone, Debug)] | ||
pub enum FeePolicy { | ||
/// If the order receives more than expected (positive deviation from quoted | ||
/// amounts) pay the protocol a factor of the achieved improvement. | ||
/// The fee is taken in `sell` token for `buy` orders and in `buy` | ||
/// token for `sell` orders. | ||
PriceImprovement { | ||
/// Factor of price improvement the protocol charges as a fee. | ||
/// Price improvement is the difference between executed price and | ||
/// limit price or quoted price (whichever is better) | ||
/// | ||
/// E.g. if a user received 2000USDC for 1ETH while having been quoted | ||
/// 1990USDC, their price improvement is 10USDC. A factor of 0.5 | ||
/// requires the solver to pay 5USDC to the protocol for | ||
/// settling this order. | ||
factor: f64, | ||
/// Cap protocol fee with a percentage of the order's volume. | ||
max_volume_factor: f64, | ||
}, | ||
/// How much of the order's volume should be taken as a protocol fee. | ||
/// The fee is taken in `sell` token for `sell` orders and in `buy` | ||
/// token for `buy` orders. | ||
Volume { | ||
/// Percentage of the order's volume should be taken as a protocol | ||
/// fee. | ||
factor: f64, | ||
}, | ||
} |
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.
@fhenneke, @olgafetisova is this comment true? I think protocol fees should be collected in CoW using some exchange rate (either the pre auction prices, post auction price, tbd)?
Note, that here we are documenting the semantics from the protocol's perspective (our driver implementation may collect the required amounts in buy or sell token, but that's an implementation detail of the driver). In what currency will the protocol later request the quote deviation from the solvers that receive the auction?
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.
Note that we also save external prices for these tokens for each auctions so it is easy to convert.