Skip to content

Commit

Permalink
Fixes after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
squadgazzz committed Apr 28, 2024
1 parent 148073a commit e469368
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 50 deletions.
53 changes: 28 additions & 25 deletions crates/solvers-dto/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,36 +66,42 @@ pub struct Order {
#[schema(value_type = TokenAmount)]
#[serde_as(as = "HexOrDecimalU256")]
pub sell_amount: U256,
#[schema(value_type = TokenAmount)]
#[serde_as(as = "HexOrDecimalU256")]
pub full_sell_amount: U256,
#[schema(value_type = TokenAmount)]
#[serde_as(as = "HexOrDecimalU256")]
pub buy_amount: U256,
#[schema(value_type = TokenAmount)]
#[serde_as(as = "HexOrDecimalU256")]
pub full_buy_amount: U256,
pub fee_policies: Option<Vec<FeePolicy>>,
pub valid_to: u32,
pub kind: OrderKind,
#[schema(value_type = Address)]
pub receiver: Option<H160>,
#[schema(value_type = Address)]
pub owner: H160,
/// Whether or not this order can be partially filled. If this is false,
/// then the order is a "fill-or-kill" order, meaning it needs to be
/// completely filled or not at all.
pub partially_fillable: bool,
pub pre_interactions: Vec<InteractionData>,
pub pre_interactions: Vec<InteractionData>,
pub post_interactions: Vec<InteractionData>,
pub sell_token_source: SellTokenSource,
pub buy_token_destination: BuyTokenDestination,
pub class: OrderClass,
#[schema(value_type = AppData)]
pub app_data: AppDataHash,
pub signing_scheme: SigningScheme,
pub signing_scheme: LegacySigningScheme,
#[serde(with = "bytes_hex")]
#[schema(value_type = Signature)]
pub signature: Vec<u8>,
}

/// Destination for which the buyAmount should be transferred to order's
/// receiver to upon fulfillment
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum BuyTokenDestination {
/// Pay trade proceeds as an ERC20 token transfer
Expand All @@ -105,7 +111,7 @@ pub enum BuyTokenDestination {
}

/// Source from which the sellAmount should be drawn upon order fulfillment
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "snake_case")]
pub enum SellTokenSource {
/// Direct ERC20 allowances to the Vault relayer contract
Expand All @@ -117,19 +123,25 @@ pub enum SellTokenSource {
}

#[serde_as]
#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "camelCase")]
pub struct InteractionData {
#[schema(value_type = Address)]
pub target: H160,
#[schema(value_type = TokenAmount)]
#[serde_as(as = "HexOrDecimalU256")]
pub value: U256,
#[schema(value_type = String, example = "0x01020304")]
#[serde(with = "bytes_hex")]
pub call_data: Vec<u8>,
}

#[derive(Debug, Deserialize)]
// todo: There is a conflict between solution's SigningScheme which is in
// camelCase. There is no way to keep 2 object with the same name in the OpenAPI
// schema. Temporarily renamed the struct. Must be migrated to the camelCase.
#[derive(Debug, Deserialize, ToSchema)]
#[serde(rename_all = "lowercase")]
pub enum SigningScheme {
pub enum LegacySigningScheme {
Eip712,
EthSign,
Eip1271,
Expand Down Expand Up @@ -695,6 +707,7 @@ pub struct ForeignLimitOrder {
#[serde_as(as = "HexOrDecimalU256")]
pub gas_estimate: U256,
#[serde_as(as = "serialize::Hex")]
// todo: not used/not a part of the API schema for some reason
pub hash: [u8; 32],
pub maker_token: H160,
pub taker_token: H160,
Expand Down Expand Up @@ -746,24 +759,12 @@ impl ToSchema<'static> for ForeignLimitOrder {
#[allow(dead_code)]
pub struct NativePrice(String);

/// Amount of an ERC20 token. 256 bit unsigned integer in decimal notation.
#[derive(ToSchema)]
#[schema(example = "1234567890")]
#[allow(dead_code)]
pub struct TokenAmount(String);

/// An ISO-8601 formatted date-time.
#[derive(ToSchema)]
#[schema(example = "1970-01-01T00:00:00.000Z")]
#[allow(dead_code)]
pub struct DateTime(String);

/// An Ethereum public address.
#[derive(ToSchema)]
#[schema(example = "0x0000000000000000000000000000000000000000")]
#[allow(dead_code)]
pub struct Address(String);

/// An arbitrary-precision integer value.
#[derive(ToSchema)]
#[schema(example = "1234567890")]
Expand All @@ -783,12 +784,6 @@ pub struct Decimal(String);
#[allow(dead_code)]
pub struct BalancerPoolId(String);

/// An ERC20 token address.
#[derive(ToSchema)]
#[schema(example = "0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB")]
#[allow(dead_code)]
pub struct Token(String);

#[serde_as]
#[derive(ToSchema, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
Expand Down Expand Up @@ -832,6 +827,14 @@ pub struct I32(String);
#[allow(dead_code)]
pub struct OrderUid(String);

/// Signature bytes.
#[derive(ToSchema)]
#[schema(
example = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)]
#[allow(dead_code)]
pub struct Signature(String);

/// If the order receives more than limit price, pay the protocol a factor of
/// the difference.
pub struct SurplusFee {
Expand Down
37 changes: 37 additions & 0 deletions crates/solvers-dto/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use utoipa::ToSchema;

// Structs for the utoipa OpenAPI schema generator.

/// Signature bytes.
#[derive(ToSchema)]
#[schema(
example = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)]
#[allow(dead_code)]
pub struct Signature(String);

/// 32 bytes of arbitrary application specific data that can be added to an
/// order. This can also be used to ensure uniqueness between two orders with
/// otherwise the exact same parameters.
#[derive(ToSchema)]
#[schema(example = "0x0000000000000000000000000000000000000000000000000000000000000000")]
#[allow(dead_code)]
pub struct AppData(String);

/// Amount of an ERC20 token. 256 bit unsigned integer in decimal notation.
#[derive(ToSchema)]
#[schema(example = "1234567890")]
#[allow(dead_code)]
pub struct TokenAmount(String);

/// An Ethereum public address.
#[derive(ToSchema)]
#[schema(example = "0x0000000000000000000000000000000000000000")]
#[allow(dead_code)]
pub struct Address(String);

/// An ERC20 token address.
#[derive(ToSchema)]
#[schema(example = "0xDEf1CA1fb7FBcDC777520aa7f396b4E015F497aB")]
#[allow(dead_code)]
pub struct Token(String);
1 change: 1 addition & 0 deletions crates/solvers-dto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//! communicate with the driver.

pub mod auction;
pub mod common;
pub mod notification;
pub mod solution;

Expand Down
16 changes: 0 additions & 16 deletions crates/solvers-dto/src/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,19 +528,3 @@ impl ToSchema<'static> for SigningScheme {
)
}
}

/// Signature bytes.
#[derive(ToSchema)]
#[schema(
example = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
)]
#[allow(dead_code)]
pub struct Signature(String);

/// 32 bytes of arbitrary application specific data that can be added to an
/// order. This can also be used to ensure uniqueness between two orders with
/// otherwise the exact same parameters.
#[derive(ToSchema)]
#[schema(example = "0x0000000000000000000000000000000000000000000000000000000000000000")]
#[allow(dead_code)]
pub struct AppData(String);
82 changes: 78 additions & 4 deletions crates/solvers/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ components:
description: A map of token addresses to token information.
additionalProperties:
$ref: '#/components/schemas/TokenInfo'
additionalProperties: false
BalancerPoolId:
type: string
description: |-
Expand All @@ -173,6 +172,14 @@ components:
enum:
- erc20
- internal
BuyTokenDestination:
type: string
description: |-
Destination for which the buyAmount should be transferred to order's
receiver to upon fulfillment
enum:
- erc20
- internal
ConcentratedLiquidityPool:
type: object
description: A Uniswap V3-like concentrated liquidity pool.
Expand Down Expand Up @@ -346,6 +353,20 @@ components:
- $ref: '#/components/schemas/LiquidityInteraction'
- $ref: '#/components/schemas/CustomInteraction'
description: An interaction to execute as part of a settlement.
InteractionData:
type: object
required:
- target
- value
- callData
properties:
callData:
type: string
example: '0x01020304'
target:
$ref: '#/components/schemas/Address'
value:
$ref: '#/components/schemas/TokenAmount'
JitOrder:
type: object
description: A just-in-time liquidity order included in a settlement.
Expand Down Expand Up @@ -415,6 +436,13 @@ components:
allOf:
- $ref: '#/components/schemas/JitOrder'
description: The just-in-time liquidity order to execute in a solution.
LegacySigningScheme:
type: string
enum:
- eip712
- ethsign
- eip1271
- presign
Liquidity:
allOf:
- $ref: '#/components/schemas/LiquidityParameters'
Expand Down Expand Up @@ -483,38 +511,78 @@ components:
- sellToken
- buyToken
- sellAmount
- fullSellAmount
- buyAmount
- fullBuyAmount
- validTo
- kind
- receiver
- owner
- partiallyFillable
- preInteractions
- postInteractions
- sellTokenSource
- buyTokenDestination
- class
- appData
- signingScheme
- signature
properties:
appData:
$ref: '#/components/schemas/AppData'
buyAmount:
$ref: '#/components/schemas/TokenAmount'
buyToken:
$ref: '#/components/schemas/Token'
buyTokenDestination:
$ref: '#/components/schemas/BuyTokenDestination'
class:
$ref: '#/components/schemas/OrderClass'
feePolicies:
type: array
items:
$ref: '#/components/schemas/FeePolicy'
description: Any protocol fee policies that apply to the order.
nullable: true
fullBuyAmount:
$ref: '#/components/schemas/TokenAmount'
fullSellAmount:
$ref: '#/components/schemas/TokenAmount'
kind:
$ref: '#/components/schemas/OrderKind'
owner:
$ref: '#/components/schemas/Address'
partiallyFillable:
type: boolean
description: |-
Whether or not this order can be partially filled. If this is false,
then the order is a "fill-or-kill" order, meaning it needs to be
completely filled or not at all.
postInteractions:
type: array
items:
$ref: '#/components/schemas/InteractionData'
preInteractions:
type: array
items:
$ref: '#/components/schemas/InteractionData'
receiver:
$ref: '#/components/schemas/Address'
sellAmount:
$ref: '#/components/schemas/TokenAmount'
sellToken:
$ref: '#/components/schemas/Token'
sellTokenSource:
$ref: '#/components/schemas/SellTokenSource'
signature:
$ref: '#/components/schemas/Signature'
signingScheme:
$ref: '#/components/schemas/LegacySigningScheme'
uid:
$ref: '#/components/schemas/OrderUid'
additionalProperties: false
validTo:
type: integer
format: int32
minimum: 0
OrderClass:
type: string
description: How the CoW Protocol order was classified.
Expand Down Expand Up @@ -569,14 +637,20 @@ components:
$ref: '#/components/schemas/TokenAmount'
sellAmount:
$ref: '#/components/schemas/TokenAmount'
additionalProperties: false
SellTokenBalance:
type: string
description: Where should the sell token be drawn from?
enum:
- erc20
- internal
- external
SellTokenSource:
type: string
description: Source from which the sellAmount should be drawn upon order fulfillment
enum:
- erc20
- external
- internal
Signature:
type: string
description: Signature bytes.
Expand Down
Loading

0 comments on commit e469368

Please sign in to comment.