Skip to content

Commit

Permalink
Merge pull request #8 from gnosis/expect-fee-policies
Browse files Browse the repository at this point in the history
Expect feePolicies
  • Loading branch information
MartinquaXD authored Mar 28, 2024
2 parents 1740937 + bf391f9 commit f4ba5ee
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
67 changes: 67 additions & 0 deletions openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,74 @@ components:
$ref: "#/components/schemas/SigningScheme"
signature:
$ref: "#/components/schemas/Signature"
feePolicies:
description: |
Any protocol fee policies that apply to the order.
type: array
items:
$ref: "#/components/schemas/FeePolicy"

FeePolicy:
description: |
A fee policy that applies to an order.
type: object
oneOf:
- $ref: "#/components/schemas/SurplusFee"
- $ref: "#/components/schemas/PriceImprovement"
- $ref: "#/components/schemas/VolumeFee"
SurplusFee:
description: |
If the order receives more than limit price, pay the protocol a factor of the difference.
type: object
properties:
kind:
type: string
enum: ["surplus"]
maxVolumeFactor:
description: Never charge more than that percentage of the order volume.
type: number
minimum: 0.0
maximum: 0.99999
example: 0.05
factor:
description: The factor of the user surplus that the protocol will request from the solver after settling the order
type: number
example: 0.5
PriceImprovement:
description: |
A cut from the price improvement over the best quote is taken as a protocol fee.
type: object
properties:
kind:
type: string
enum: [ "priceImprovement" ]
maxVolumeFactor:
description: Never charge more than that percentage of the order volume.
type: number
example: 0.01
factor:
description: The factor of the user surplus that the protocol will request from the solver after settling the order
type: number
example: 0.5
quote:
$ref: "#/components/schemas/Quote"
VolumeFee:
type: object
properties:
kind:
type: string
enum: ["volume"]
factor:
description: The fraction of the order's volume that the protocol will request from the solver after settling the order.
type: number
example: 0.5
Quote:
type: object
properties:
sell_amount:
$ref: "#/components/schemas/TokenAmount"
buy_amount:
$ref: "#/components/schemas/TokenAmount"
Fulfillment:
description: |
A trade which fulfills an order from the auction.
Expand Down
29 changes: 29 additions & 0 deletions src/api/routes/solve/dto/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,35 @@ struct Order {
kind: Kind,
partially_fillable: bool,
class: Class,
fee_policies: Option<Vec<FeePolicy>>,
}

#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum FeePolicy {
#[serde(rename_all = "camelCase")]
Surplus { factor: f64, max_volume_factor: f64 },
#[serde(rename_all = "camelCase")]
PriceImprovement {
factor: f64,
max_volume_factor: f64,
quote: Quote,
},
#[serde(rename_all = "camelCase")]
Volume { factor: f64 },
}

#[serde_as]
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Quote {
#[serde_as(as = "serialize::U256")]
pub sell_amount: eth::U256,
#[serde_as(as = "serialize::U256")]
pub buy_amount: eth::U256,
#[serde_as(as = "serialize::U256")]
pub fee: eth::U256,
}

#[derive(Debug, Deserialize)]
Expand Down

0 comments on commit f4ba5ee

Please sign in to comment.