Skip to content

Commit

Permalink
feat: updates markets endpoint
Browse files Browse the repository at this point in the history
Closes: #21
  • Loading branch information
sourabhxyz committed Mar 5, 2024
1 parent be90fb5 commit c81b960
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 23 deletions.
2 changes: 2 additions & 0 deletions geniusyield-orderbot/geniusyield-orderbot.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ library
, deriving-aeson
, geniusyield-dex-api
, http-api-data
, lens
, rio
, strict
, swagger2

-- Dependencies whose version is fixed by @cabal.project@ file.
build-depends:
Expand Down
23 changes: 21 additions & 2 deletions geniusyield-orderbot/src/GeniusYield/OrderBot/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ module GeniusYield.OrderBot.Types (
DexPair (..),
) where

import Data.Aeson (FromJSON (..), ToJSON, (.=))
import Control.Lens ((?~))
import Data.Aeson (FromJSON (..), ToJSON (..), (.=))
import Data.Aeson qualified as Aeson
import Data.Kind (Type)
import Data.Ratio (denominator, numerator, (%))
import Data.Swagger qualified as Swagger
import Data.Swagger.Internal.Schema qualified as Swagger
import Data.Word (Word64)
import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..))
import GeniusYield.Types (rationalToGHC)
import GeniusYield.Types.TxOutRef (GYTxOutRef)
import GeniusYield.Types.Value (GYAssetClass (..))
import Numeric.Natural (Natural)
import RIO (Text)
import RIO (Text, (&))
import RIO.Text qualified as Text
import RIO.Text.Partial qualified as Text
import Web.HttpApiData (FromHttpApiData (..), ToHttpApiData (..))
Expand Down Expand Up @@ -236,6 +239,22 @@ instance FromHttpApiData OrderAssetPair where
comAsset parseUrlPiece com
pure $ OAssetPair curAsset comAsset

instance Swagger.ToParamSchema OrderAssetPair where
toParamSchema _ =
mempty
& Swagger.type_
?~ Swagger.SwaggerString

instance Swagger.ToSchema OrderAssetPair where
declareNamedSchema p =
pure $
Swagger.named "OrderAssetPair" $
Swagger.paramSchemaToSchema p
& Swagger.example
?~ toJSON ("f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958_dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53" String)
& Swagger.description
?~ "Market pair identifier. It's an underscore delimited concatenation of offered and asked asset's \"token detail\". A token detail is given by dot delimited concatenation of policy id and token name."

{- | Two order asset pairs are considered "equivalent" (but not strictly equal, as in 'Eq'),
if they contain the same 2 assets irrespective of order.
i.e {currencyAsset = A, commodityAsset = B} and
Expand Down
18 changes: 13 additions & 5 deletions geniusyield-server-lib/src/GeniusYield/Server/Dex/Markets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import GeniusYield.HTTP.Errors (
)
import GeniusYield.Imports
import GeniusYield.OrderBot.Domain.Markets (Markets (getMarkets))
import GeniusYield.OrderBot.Types (DexPair (..), OrderAssetPair (commodityAsset, currencyAsset), TokenDisplayDetails (..))
import GeniusYield.OrderBot.Types (DexPair (..), OrderAssetPair (commodityAsset, currencyAsset), TokenDisplayDetails (..), mkOrderAssetPair)
import GeniusYield.Scripts.Dex.PartialOrderConfig (PartialOrderConfigInfoF (..))
import GeniusYield.Server.Ctx
import GeniusYield.Server.Utils (addSwaggerDescription, addSwaggerExample, dropAndCamelToSnake, logInfo)
import GeniusYield.TxBuilder.Class
import GeniusYield.Types
import Network.HTTP.Types (status400)
import RIO (Word64)
import Servant

{- $setup
Expand Down Expand Up @@ -72,9 +73,13 @@ instance Swagger.ToSchema TargetAsset where
& addSwaggerExample "GENS"

data Market = Market
{ marketId !MarketId,
baseAsset !BaseAsset,
targetAsset !TargetAsset
{ marketId !OrderAssetPair,
baseAsset !GYAssetClass,
targetAsset !GYAssetClass,
baseAssetTicker !(Maybe Text),
targetAssetTicker !(Maybe Text),
baseAssetDecimals !(Maybe Word64),
targetAssetDecimals !(Maybe Word64)
}
deriving stock (Show, Eq, Generic)
deriving
Expand Down Expand Up @@ -104,7 +109,10 @@ handleMarkets ctx = do
where
-- We assume following for now as there is no link b/w display name and actual asset name, for instance @LENFI@ token has asset name @AADA@.
fromDexPair DexPair Market
fromDexPair DexPair {..} = Market {marketId = MarketId dpMarketPairId, baseAsset = BaseAsset (tddTicker dpCurrencyToken), targetAsset = TargetAsset (tddTicker dpCommodityToken)}
fromDexPair DexPair {..} =
let baseAsset' = tddAssetClass dpCurrencyToken
targetAsset' = tddAssetClass dpCommodityToken
in Market {marketId = mkOrderAssetPair baseAsset' targetAsset', baseAsset = baseAsset', targetAsset = targetAsset', baseAssetTicker = Just $ tddTicker dpCurrencyToken, targetAssetTicker = Just $ tddTicker dpCommodityToken, baseAssetDecimals = Just $ tddDecimals dpCurrencyToken, targetAssetDecimals = Just $ tddDecimals dpCommodityToken}

-- Market
-- { marketId = MarketId dexMarketPairId,
Expand Down
16 changes: 0 additions & 16 deletions geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,6 @@ data OrderResponse = OrderResponse
(FromJSON, ToJSON)
via CustomJSON '[FieldLabelModifier '[StripPrefix OrderResPrefix, CamelToSnake]] OrderResponse

instance Swagger.ToParamSchema OrderAssetPair where
toParamSchema _ =
mempty
& Swagger.type_
?~ Swagger.SwaggerString

instance Swagger.ToSchema OrderAssetPair where
declareNamedSchema p =
pure $
Swagger.named "OrderAssetPair" $
Swagger.paramSchemaToSchema p
& Swagger.example
?~ toJSON ("f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc535.41474958_dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb.0014df1047454e53" String)
& Swagger.description
?~ "Market pair identifier. It's an underscore delimited concatenation of offered and asked asset's \"token detail\". A token detail is given by dot delimited concatenation of policy id and token name."

instance Swagger.ToSchema OrderResponse where
declareNamedSchema =
Swagger.genericDeclareNamedSchema Swagger.defaultSchemaOptions {Swagger.fieldLabelModifier = dropAndCamelToSnake @OrderResPrefix}
Expand Down

0 comments on commit c81b960

Please sign in to comment.