Skip to content

Commit

Permalink
feat: code refactor, abstract out common path
Browse files Browse the repository at this point in the history
Closes: #21
  • Loading branch information
sourabhxyz committed Mar 6, 2024
1 parent a5fbaa5 commit 5e082a6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
12 changes: 7 additions & 5 deletions geniusyield-server-lib/src/GeniusYield/Server/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ instance Swagger.ToSchema Settings where
-------------------------------------------------------------------------------

type GeniusYieldAPI =
"settings" :> Get '[JSON] Settings
:<|> DEXPartialOrderAPI
:<|> MarketsAPI
:<|> TxAPI
"v1"
:> ( "settings" :> Get '[JSON] Settings
:<|> DEXPartialOrderAPI
:<|> MarketsAPI
:<|> TxAPI
)

geniusYieldAPI Proxy GeniusYieldAPI
geniusYieldAPI = Proxy
Expand All @@ -72,7 +74,7 @@ geniusYieldAPISwagger =
.~ "1.0"
& info
. description
?~ "This API is used for building and submitting transactions."
?~ "This API is used to interact with GeniusYield DEX."

geniusYieldServer Ctx ServerT GeniusYieldAPI IO
geniusYieldServer ctx =
Expand Down
31 changes: 15 additions & 16 deletions geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,20 @@ type DEXPartialOrderAPI =
"trading_fees"
:> Get '[JSON] TradingFees
:<|> "orders"
:> "open"
:> "tx"
:> "generate"
:> ReqBody '[JSON] PlaceOrderParameters
:> Post '[JSON] PlaceOrderTransactionDetails
:<|> "orders"
:> "cancel"
:> "tx"
:> "generate"
:> ReqBody '[JSON] CancelOrderParameters
:> Post '[JSON] CancelOrderTransactionDetails
:<|> "orders"
:> Capture "market_id" OrderAssetPair
:> QueryParam "address" GYAddressBech32
:> Get '[JSON] OrderBookInfo
:> ( "open"
:> "tx"
:> "generate"
:> ReqBody '[JSON] PlaceOrderParameters
:> Post '[JSON] PlaceOrderTransactionDetails
:<|> "cancel"
:> "tx"
:> "generate"
:> ReqBody '[JSON] CancelOrderParameters
:> Post '[JSON] CancelOrderTransactionDetails
:<|> Capture "market_id" OrderAssetPair
:> QueryParam "address" GYAddressBech32
:> Get '[JSON] OrderBookInfo
)

handleDEXPartialOrder Ctx ServerT DEXPartialOrderAPI IO
handleDEXPartialOrder ctx =
Expand Down Expand Up @@ -293,7 +292,7 @@ handleOrders ctx@Ctx {..} orderAssetPair mownAddress = do
os
-- TODO: Make it strict, likely there is memory leak here.
-- TODO: Check if it's implementation is correct.
(bids, asks) =
(!bids, !asks) =
Map.foldl'
( \(!accBids, !accAsks) poi@PartialOrderInfo {..}
let buyAP = mkOrderAssetPair poiOfferedAsset poiAskedAsset
Expand Down
20 changes: 10 additions & 10 deletions web/swagger/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,12 +342,12 @@
}
},
"info": {
"description": "This API is used for building and submitting transactions.",
"description": "This API is used to interact with GeniusYield DEX.",
"title": "Genius Yield Haskell Server API",
"version": "1.0"
},
"paths": {
"/markets": {
"/v1/markets": {
"get": {
"produces": [
"application/json;charset=utf-8"
Expand All @@ -365,7 +365,7 @@
}
}
},
"/orders/cancel/tx/generate": {
"/v1/orders/cancel/tx/generate": {
"post": {
"consumes": [
"application/json;charset=utf-8"
Expand Down Expand Up @@ -396,7 +396,7 @@
}
}
},
"/orders/open/tx/generate": {
"/v1/orders/open/tx/generate": {
"post": {
"consumes": [
"application/json;charset=utf-8"
Expand Down Expand Up @@ -427,7 +427,7 @@
}
}
},
"/orders/{market_id}": {
"/v1/orders/{market_id}": {
"get": {
"parameters": [
{
Expand Down Expand Up @@ -460,7 +460,7 @@
}
}
},
"/settings": {
"/v1/settings": {
"get": {
"produces": [
"application/json;charset=utf-8"
Expand All @@ -475,7 +475,7 @@
}
}
},
"/trading_fees": {
"/v1/trading_fees": {
"get": {
"produces": [
"application/json;charset=utf-8"
Expand All @@ -490,7 +490,7 @@
}
}
},
"/tx/sign": {
"/v1/tx/sign": {
"post": {
"consumes": [
"application/json;charset=utf-8"
Expand Down Expand Up @@ -521,7 +521,7 @@
}
}
},
"/tx/sign_and_submit": {
"/v1/tx/sign_and_submit": {
"post": {
"consumes": [
"application/json;charset=utf-8"
Expand Down Expand Up @@ -552,7 +552,7 @@
}
}
},
"/tx/submit": {
"/v1/tx/submit": {
"post": {
"consumes": [
"application/json;charset=utf-8"
Expand Down

0 comments on commit 5e082a6

Please sign in to comment.