diff --git a/daemon/src/db.rs b/daemon/src/db.rs index b374d8c..1fd3bd3 100644 --- a/daemon/src/db.rs +++ b/daemon/src/db.rs @@ -432,7 +432,7 @@ mod tests { let cfd = Cfd::new( order.clone(), Usd(dec!(1000)), - CfdState::PendingTakeRequest { + CfdState::PendingOrderRequest { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -456,7 +456,7 @@ mod tests { let cfd = Cfd::new( order.clone(), Usd(dec!(1000)), - CfdState::PendingTakeRequest { + CfdState::PendingOrderRequest { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, @@ -481,7 +481,7 @@ mod tests { let mut cfd = Cfd::new( order.clone(), Usd(dec!(1000)), - CfdState::PendingTakeRequest { + CfdState::PendingOrderRequest { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, diff --git a/daemon/src/model/cfd.rs b/daemon/src/model/cfd.rs index a996b23..23c524d 100644 --- a/daemon/src/model/cfd.rs +++ b/daemon/src/model/cfd.rs @@ -137,14 +137,15 @@ pub enum CfdState { /// The taker has requested to take a CFD, but has not messaged the maker yet. /// /// This state only applies to the taker. + /// TODO: unused? TakeRequested { common: CfdStateCommon, }, - /// The taker sent an open request to the maker to open the CFD but don't have a response yet. + /// The taker sent an order to the maker to open the CFD but doesn't have a response yet. /// /// This state applies to taker and maker. /// Initial state for the maker. - PendingTakeRequest { + PendingOrderRequest { common: CfdStateCommon, }, /// The maker has accepted the CFD take request, but the contract is not set up on chain yet. @@ -154,7 +155,7 @@ pub enum CfdState { common: CfdStateCommon, }, - /// The maker rejected the CFD take request. + /// The maker rejected the CFD order. /// /// This state applies to taker and maker. Rejected { @@ -213,7 +214,7 @@ impl CfdState { fn get_common(&self) -> CfdStateCommon { let common = match self { CfdState::TakeRequested { common } => common, - CfdState::PendingTakeRequest { common } => common, + CfdState::PendingOrderRequest { common } => common, CfdState::Accepted { common } => common, CfdState::Rejected { common } => common, CfdState::ContractSetup { common } => common, @@ -237,10 +238,10 @@ impl Display for CfdState { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { CfdState::TakeRequested { .. } => { - write!(f, "Take Requested") + write!(f, "Order created") } - CfdState::PendingTakeRequest { .. } => { - write!(f, "Pending Take Request") + CfdState::PendingOrderRequest { .. } => { + write!(f, "Pending order") } CfdState::Accepted { .. } => { write!(f, "Accepted") diff --git a/daemon/src/routes_taker.rs b/daemon/src/routes_taker.rs index ec72de3..211978c 100644 --- a/daemon/src/routes_taker.rs +++ b/daemon/src/routes_taker.rs @@ -56,20 +56,20 @@ pub async fn feed( } #[derive(Debug, Clone, Serialize, Deserialize)] -pub struct CfdTakeRequest { +pub struct CfdOrderRequest { pub order_id: OrderId, pub quantity: Usd, } -#[rocket::post("/cfd", data = "")] -pub async fn post_cfd( - cfd_take_request: Json, +#[rocket::post("/cfd", data = "")] +pub async fn post_order_request( + cfd_order_request: Json, cfd_actor_inbox: &State>, ) { cfd_actor_inbox .send(taker_cfd_actor::Command::TakeOrder { - order_id: cfd_take_request.order_id, - quantity: cfd_take_request.quantity, + order_id: cfd_order_request.order_id, + quantity: cfd_order_request.quantity, }) .expect("actor to never disappear"); } diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index c4d1791..c448dd6 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -175,7 +175,7 @@ async fn main() -> Result<()> { "/api", rocket::routes![ routes_taker::feed, - routes_taker::post_cfd, + routes_taker::post_order_request, routes_taker::get_health_check, routes_taker::margin_calc, ], diff --git a/daemon/src/taker_cfd_actor.rs b/daemon/src/taker_cfd_actor.rs index ccd9721..aad8de3 100644 --- a/daemon/src/taker_cfd_actor.rs +++ b/daemon/src/taker_cfd_actor.rs @@ -16,6 +16,7 @@ use tokio::sync::{mpsc, watch}; #[allow(clippy::large_enum_variant)] pub enum Command { SyncWallet, + // TODO: should this be TakeOffer ? TakeOrder { order_id: OrderId, quantity: Usd }, NewOrder(Option), OrderAccepted(OrderId), @@ -62,7 +63,7 @@ pub fn new( let cfd = Cfd::new( current_order.clone(), quantity, - CfdState::PendingTakeRequest { + CfdState::PendingOrderRequest { common: CfdStateCommon { transition_timestamp: SystemTime::now(), }, diff --git a/docs/asset/mvp_maker_taker_messaging.puml b/docs/asset/mvp_maker_taker_messaging.puml index f888917..c77b938 100644 --- a/docs/asset/mvp_maker_taker_messaging.puml +++ b/docs/asset/mvp_maker_taker_messaging.puml @@ -36,17 +36,17 @@ BuyerApp -> BuyerOrderFeed: push order BuyerOrderFeed --> Buyer: order Buyer -> Buyer: Click BUY -Buyer -> BuyerApp: POST cfd_take_request -BuyerApp -> BuyerApp: Create cfd [TakeRequested] +Buyer -> BuyerApp: POST cfd_order_request +BuyerApp -> BuyerApp: Create cfd [OrderRequest] note over BuyerApp: Must include order_id BuyerApp -> BuyerCfdFeed: Push cfd -BuyerCfdFeed --> Buyer: cfd [TakeRequested] +BuyerCfdFeed --> Buyer: cfd [OrderRequest] -BuyerApp -> SellerApp: {TCP} cfd_take_request (order_id, quantity) -SellerApp -> SellerApp: Create cfd [TakeRequested] -SellerApp -> SellerCfdFeed: cfd [TakeRequested] -SellerCfdFeed --> Seller: cfd [TakeRequested] +BuyerApp -> SellerApp: {TCP} cfd_order_request (order_id, quantity) +SellerApp -> SellerApp: Create cfd [OrderRequest] +SellerApp -> SellerCfdFeed: cfd [OrderRequest] +SellerCfdFeed --> Seller: cfd [OrderRequest] Seller -> Seller: Accept cfd Seller -> SellerApp: POST cfd [Accepted] SellerApp -> BuyerApp: {TCP} cfd [Accepted] diff --git a/frontend/src/Taker.tsx b/frontend/src/Taker.tsx index 545c17a..5070839 100644 --- a/frontend/src/Taker.tsx +++ b/frontend/src/Taker.tsx @@ -11,7 +11,7 @@ import NavLink from "./components/NavLink"; import { Cfd, Order, WalletInfo } from "./components/Types"; import Wallet from "./components/Wallet"; -interface CfdTakeRequestPayload { +interface CfdOrderRequestPayload { order_id: string; quantity: number; } @@ -26,11 +26,11 @@ interface MarginResponse { margin: number; } -async function postCfdTakeRequest(payload: CfdTakeRequestPayload) { +async function postCfdOrderRequest(payload: CfdOrderRequestPayload) { let res = await fetch(`/api/cfd`, { method: "POST", body: JSON.stringify(payload) }); if (!res.status.toString().startsWith("2")) { - throw new Error("failed to create new CFD take request: " + res.status + ", " + res.statusText); + throw new Error("failed to create new CFD order request: " + res.status + ", " + res.statusText); } } @@ -38,7 +38,7 @@ async function getMargin(payload: MarginRequestPayload): Promise let res = await fetch(`/api/calculate/margin`, { method: "POST", body: JSON.stringify(payload) }); if (!res.status.toString().startsWith("2")) { - throw new Error("failed to create new CFD take request: " + res.status + ", " + res.statusText); + throw new Error("failed to create new CFD order request: " + res.status + ", " + res.statusText); } return res.json(); @@ -77,10 +77,10 @@ export default function App() { const format = (val: any) => `$` + val; const parse = (val: any) => val.replace(/^\$/, ""); - let { run: makeNewTakeRequest, isLoading: isCreatingNewTakeRequest } = useAsync({ + let { run: makeNewOrderRequest, isLoading: isCreatingNewOrderRequest } = useAsync({ deferFn: async ([payload]: any[]) => { try { - await postCfdTakeRequest(payload as CfdTakeRequestPayload); + await postCfdOrderRequest(payload as CfdOrderRequestPayload); } catch (e) { const description = typeof e === "string" ? e : JSON.stringify(e); @@ -175,15 +175,15 @@ export default function App() { {