Skip to content
This repository was archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Fee&Quote Endpoint: Implemention with legacy logic. (#1155)
Browse files Browse the repository at this point in the history
* introducing legacy logic to the new fee and quote endpoint
* testing calculate_quote
* update the return type of legacy fee endpoint
* use u32::MAX to validity for {Buy/Sell}Resuest -> OrderQuoteRequest so legacy endpoint doesn't fail order validation

Co-authored-by: Nicholas Rodrigues Lordello <[email protected]>
  • Loading branch information
bh2smith and nlordell authored Oct 13, 2021
1 parent e78f16f commit 7c82182
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 282 deletions.
15 changes: 10 additions & 5 deletions e2e/tests/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use ethcontract::{prelude::U256, H160};
use model::DomainSeparator;
use orderbook::{
account_balances::Web3BalanceFetcher, api::order_validation::OrderValidator,
database::Postgres, event_updater::EventUpdater, fee::EthAwareMinFeeCalculator,
metrics::Metrics, orderbook::Orderbook, solvable_orders::SolvableOrdersCache,
api::post_quote::OrderQuoter, database::Postgres, event_updater::EventUpdater,
fee::EthAwareMinFeeCalculator, metrics::Metrics, orderbook::Orderbook,
solvable_orders::SolvableOrdersCache,
};
use reqwest::Client;
use shared::{
Expand Down Expand Up @@ -232,16 +233,20 @@ impl OrderbookServices {
true,
solvable_orders_cache.clone(),
Duration::from_secs(600),
order_validator,
order_validator.clone(),
));
let maintenance = ServiceMaintenance {
maintainers: vec![db.clone(), event_updater],
};
let quoter = Arc::new(OrderQuoter::new(
fee_calculator,
price_estimator.clone(),
order_validator,
));
orderbook::serve_api(
db.clone(),
orderbook,
fee_calculator,
price_estimator.clone(),
quoter,
API_HOST[7..].parse().expect("Couldn't parse API address"),
pending(),
);
Expand Down
28 changes: 17 additions & 11 deletions orderbook/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/OrderQuote"
$ref: "#/components/schemas/OrderQuoteResponse"
400:
description: Error quoting order.
content:
Expand Down Expand Up @@ -925,22 +925,28 @@ components:
buyTokenBalance:
$ref: "#/components/schemas/BuyTokenDestination"
default: "erc20"
from:
$ref: "#/components/schemas/Address"
required:
- sellToken
- buyToken
- validTo
- appData
- partiallyFillable
OrderQuote:
- from
OrderQuoteResponse:
description: |
An order quoted by the back end that can be directly signed and
submitted to the order creation backend.
allOf:
- $ref: "#/components/schemas/OrderParameters"
- type: object
properties:
from:
description: The expected address of the signer
$ref: "#/components/schemas/Address"
required:
- from
type: object
properties:
quote:
$ref: "#/components/schemas/OrderParameters"
from:
$ref: "#/components/schemas/Address"
expirationDate:
description: |
Expiration date of the offered fee. Order service might not accept
the fee after this expiration date. Encoded as ISO 8601 UTC.
type: string
example: "1985-03-10T18:35:18.814523Z"
29 changes: 12 additions & 17 deletions orderbook/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ mod get_solvable_orders_v2;
mod get_trades;
mod get_user_orders;
pub mod order_validation;
mod post_quote;
pub mod post_quote;

use crate::{
database::trades::TradeRetrieving, fee::EthAwareMinFeeCalculator, orderbook::Orderbook,
api::post_quote::OrderQuoter, database::trades::TradeRetrieving, orderbook::Orderbook,
};
use anyhow::Error as anyhowError;
use serde::de::DeserializeOwned;
use serde::Serialize;
use shared::metrics::get_metric_storage_registry;
use shared::price_estimation::{PriceEstimating, PriceEstimationError};
use serde::{de::DeserializeOwned, Serialize};
use shared::{metrics::get_metric_storage_registry, price_estimation::PriceEstimationError};
use std::{convert::Infallible, sync::Arc};
use warp::{
hyper::StatusCode,
Expand All @@ -31,26 +29,23 @@ use warp::{
pub fn handle_all_routes(
database: Arc<dyn TradeRetrieving>,
orderbook: Arc<Orderbook>,
fee_calculator: Arc<EthAwareMinFeeCalculator>,
price_estimator: Arc<dyn PriceEstimating>,
quoter: Arc<OrderQuoter>,
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone {
let create_order = create_order::create_order(orderbook.clone());
let get_orders = get_orders::get_orders(orderbook.clone());
let legacy_fee_info = get_fee_info::legacy_get_fee_info(fee_calculator.clone());
let fee_info = get_fee_info::get_fee_info(fee_calculator.clone());
let legacy_fee_info = get_fee_info::legacy_get_fee_info(quoter.fee_calculator.clone());
let fee_info = get_fee_info::get_fee_info(quoter.fee_calculator.clone());
let get_order = get_order_by_uid::get_order_by_uid(orderbook.clone());
let get_solvable_orders = get_solvable_orders::get_solvable_orders(orderbook.clone());
let get_solvable_orders_v2 = get_solvable_orders_v2::get_solvable_orders(orderbook.clone());
let get_trades = get_trades::get_trades(database);
let cancel_order = cancel_order::cancel_order(orderbook.clone());
let get_amount_estimate = get_markets::get_amount_estimate(price_estimator.clone());
let get_fee_and_quote_sell =
get_fee_and_quote::get_fee_and_quote_sell(fee_calculator.clone(), price_estimator.clone());
let get_fee_and_quote_buy =
get_fee_and_quote::get_fee_and_quote_buy(fee_calculator, price_estimator.clone());
let get_amount_estimate = get_markets::get_amount_estimate(quoter.price_estimator.clone());
let get_fee_and_quote_sell = get_fee_and_quote::get_fee_and_quote_sell(quoter.clone());
let get_fee_and_quote_buy = get_fee_and_quote::get_fee_and_quote_buy(quoter.clone());
let get_user_orders = get_user_orders::get_user_orders(orderbook.clone());
let get_orders_by_tx = get_orders_by_tx::get_orders_by_tx(orderbook);
let post_quote = post_quote::post_quote();
let post_quote = post_quote::post_quote(quoter);
let cors = warp::cors()
.allow_any_origin()
.allow_methods(vec!["GET", "POST", "DELETE", "OPTIONS", "PUT", "PATCH"])
Expand Down Expand Up @@ -132,7 +127,7 @@ fn internal_error() -> Json {
}

pub trait WarpReplyConverting {
fn to_warp_reply(&self) -> (Json, StatusCode);
fn into_warp_reply(self) -> (Json, StatusCode);
}

pub fn convert_get_orders_error_to_reply(err: anyhowError) -> WithStatus<Json> {
Expand Down
2 changes: 1 addition & 1 deletion orderbook/src/api/create_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn create_order_request(
pub fn create_order_response(result: Result<AddOrderResult>) -> impl Reply {
let (body, status_code) = match result {
Ok(AddOrderResult::Added(uid)) => (warp::reply::json(&uid), StatusCode::CREATED),
Ok(AddOrderResult::OrderValidation(err)) => err.to_warp_reply(),
Ok(AddOrderResult::OrderValidation(err)) => err.into_warp_reply(),
Ok(AddOrderResult::UnsupportedSignature) => (
super::error("UnsupportedSignature", "signing scheme is not supported"),
StatusCode::BAD_REQUEST,
Expand Down
Loading

0 comments on commit 7c82182

Please sign in to comment.