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

Pre-Order Validation #1169

Merged
merged 2 commits into from
Sep 30, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions e2e/tests/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use contracts::{
};
use ethcontract::{prelude::U256, H160};
use model::DomainSeparator;
use orderbook::api::validation::PreOrderValidator;
use orderbook::{
account_balances::Web3BalanceFetcher, database::Postgres, event_updater::EventUpdater,
fee::EthAwareMinFeeCalculator, metrics::Metrics, orderbook::Orderbook,
Expand Down Expand Up @@ -208,20 +209,23 @@ impl OrderbookServices {
bad_token_detector.clone(),
current_block_stream.clone(),
);
let pre_order_validator = Arc::new(PreOrderValidator::new(
Box::new(web3.clone()),
gpv2.native_token.clone(),
vec![],
Duration::from_secs(120),
));
let orderbook = Arc::new(Orderbook::new(
gpv2.domain_separator,
gpv2.settlement.address(),
db.clone(),
balance_fetcher,
fee_calculator.clone(),
Duration::from_secs(120),
bad_token_detector,
Box::new(web3.clone()),
gpv2.native_token.clone(),
vec![],
true,
solvable_orders_cache.clone(),
Duration::from_secs(600),
pre_order_validator,
));
let maintenance = ServiceMaintenance {
maintainers: vec![db.clone(), event_updater],
Expand Down
1 change: 1 addition & 0 deletions orderbook/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod get_solvable_orders;
mod get_trades;
mod get_user_orders;
mod post_quote;
pub mod validation;

use crate::{
database::trades::TradeRetrieving, fee::EthAwareMinFeeCalculator, orderbook::Orderbook,
Expand Down
35 changes: 1 addition & 34 deletions orderbook/src/api/create_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,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::UnsupportedBuyTokenDestination(dest)) => (
super::error("UnsupportedBuyTokenDestination", format!("Type {:?}", dest)),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::UnsupportedSellTokenSource(source)) => (
super::error("UnsupportedSellTokenSource", format!("Type {:?}", source)),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::PreValidationError(err)) => err.to_warp_reply(),
Ok(AddOrderResult::UnsupportedToken(token)) => (
super::error("UnsupportedToken", format!("Token address {}", token)),
StatusCode::BAD_REQUEST,
Expand All @@ -49,17 +42,6 @@ pub fn create_order_response(result: Result<AddOrderResult>) -> impl Reply {
super::error("UnsupportedSignature", "signing scheme is not supported"),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::Forbidden) => (
super::error("Forbidden", "Forbidden, your account is deny-listed"),
StatusCode::FORBIDDEN,
),
Ok(AddOrderResult::InsufficientValidTo) => (
super::error(
"InsufficientValidTo",
"validTo is not far enough in the future",
),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::MissingOrderData) => (
super::error(
"MissingOrderData",
Expand All @@ -78,21 +60,6 @@ pub fn create_order_response(result: Result<AddOrderResult>) -> impl Reply {
super::error("InsufficientFee", "Order does not include sufficient fee"),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::TransferEthToContract) => (
super::error(
"TransferEthToContract",
"Sending Ether to a smart contract wallets is currently not \
supported",
),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::SameBuyAndSellToken) => (
super::error(
"SameBuyAndSellToken",
"Buy token is the same as the sell token.",
),
StatusCode::BAD_REQUEST,
),
Ok(AddOrderResult::ZeroAmount) => (
super::error("ZeroAmount", "Buy or sell amount is zero."),
StatusCode::BAD_REQUEST,
Expand Down
Loading