Skip to content

Commit

Permalink
Merge pull request #78 from geniusyield/additional-fields-order-book-…
Browse files Browse the repository at this point in the history
…update-order-fill

feat: add additional fields to order-book endpoint and modify build f…
  • Loading branch information
brunjlar authored Jul 10, 2024
2 parents 644108e + e358dee commit 4497d21
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
5 changes: 5 additions & 0 deletions geniusyield-server-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Revision history for geniusyield-server-lib

## 0.8.0 -- 2024-07-09

* Updates `/v0/orders/fill` and `/v0/orders/tx/build-fill` endpoint to internally call `fillPartialOrder'` instead of `fillMultiplePartialOrders'` when single order is being filled.
* Updates `/v0/order-books/{market-id}` endpoint to also return for `offer_amount_in_datum`, `price_in_datum` and `version`.

## 0.7.0 -- 2024-06-26

* Updates `fotdTakerOfferedPercentFeeAmount` field of response of `/v0/orders/fill` and `/v0/orders/tx/build-fill` to now return bag of tokens in which taker fee is charged. These two endpoints now also supports filling of payment tokens where not all of them belong to same pair.
Expand Down
2 changes: 1 addition & 1 deletion geniusyield-server-lib/geniusyield-server-lib.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.6
name: geniusyield-server-lib
version: 0.7.0
version: 0.8.0
synopsis: GeniusYield server library
description: Library for GeniusYield server.
license: Apache-2.0
Expand Down
20 changes: 15 additions & 5 deletions geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import Data.Swagger.Internal.Schema qualified as Swagger
import Deriving.Aeson
import Fmt
import GHC.TypeLits (AppendSymbol, Symbol)
import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..), cancelMultiplePartialOrders', fillMultiplePartialOrders', getPartialOrdersInfos, getPartialOrdersInfos', getVersionsInOrders, orderByNft, partialOrderPrice', placePartialOrder'', preferentiallySelectLatestPocd, preferentiallySelectLatestVersion, roundFunctionForPOCVersion)
import GeniusYield.Api.Dex.PartialOrderConfig (RefPocd (..), SomeRefPocd (SomeRefPocd), fetchPartialOrderConfig, fetchPartialOrderConfigs)
import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..), cancelMultiplePartialOrders', fillMultiplePartialOrders', fillPartialOrder', getPartialOrdersInfos, getPartialOrdersInfos', getVersionsInOrders, orderByNft, partialOrderPrice', placePartialOrder'', preferentiallySelectLatestPocd, preferentiallySelectLatestVersion, roundFunctionForPOCVersion)
import GeniusYield.Api.Dex.PartialOrderConfig (RefPocd (..), SomeRefPocd (SomeRefPocd), fetchPartialOrderConfig, fetchPartialOrderConfigs, selectRefPocd)
import GeniusYield.HTTP.Errors
import GeniusYield.OrderBot.Domain.Markets (OrderAssetPair (..))
import GeniusYield.Scripts.Dex.PartialOrderConfig (PartialOrderConfigInfoF (..))
import GeniusYield.Scripts.Dex.Version (POCVersion (POCVersion1_1))
import GeniusYield.Server.Ctx
import GeniusYield.Server.Orphans ()
import GeniusYield.Server.Tx (handleTxSign, handleTxSubmit, throwNoSigningKeyError)
import GeniusYield.Server.Utils (addSwaggerDescription, addSwaggerExample, dropSymbolAndCamelToSnake, logDebug, logInfo)
import GeniusYield.Types
Expand Down Expand Up @@ -86,13 +87,16 @@ type OrderInfoPrefix = "oi"

data OrderInfo = OrderInfo
{ oiOfferAmount !GYRational,
oiOfferAmountInDatum !GYNatural,
oiPrice !GYRational,
oiPriceInDatum !Rational,
oiStart !(Maybe GYTime),
oiEnd !(Maybe GYTime),
oiOwnerAddress !GYAddressBech32,
oiOwnerKeyHash !GYPubKeyHash,
oiOutputReference !GYTxOutRef,
oiNFTToken !GYAssetClass
oiNFTToken !GYAssetClass,
oiVersion !POCVersion
}
deriving stock (Generic)
deriving
Expand All @@ -102,6 +106,7 @@ data OrderInfo = OrderInfo
instance Swagger.ToSchema OrderInfo where
declareNamedSchema =
Swagger.genericDeclareNamedSchema Swagger.defaultSchemaOptions {Swagger.fieldLabelModifier = dropSymbolAndCamelToSnake @OrderInfoPrefix}
& addSwaggerDescription "Order details given as part of order-book (bid and ask). Note that \"price_in_datum\" is the price given in datum whereas \"price\" is the rounded price in terms of currency asset per commodity asset. I.e., for a sell order, \"price\" is rounded value of \"price_in_datum\" whereas for buy order, \"price\" is rounded value of reciprocal of \"price_in_datum\". Likewise, \"offer_amount_in_datum\" is the amount given in datum whereas \"offer_amount\" is the rounded value in terms of commodity asset."

type OrderInfoDetailedPrefix Symbol
type OrderInfoDetailedPrefix = "oid"
Expand Down Expand Up @@ -136,13 +141,16 @@ poiToOrderInfo PartialOrderInfo {..} oap =
poiOfferedAmount' = fromIntegral poiOfferedAmount
in OrderInfo
{ oiOfferAmount = if isSell then poiOfferedAmount' else poiOfferedAmount' * poiPrice,
oiOfferAmountInDatum = naturalFromGHC poiOfferedAmount,
oiPrice = if isSell then poiPrice else 1 / poiPrice,
oiPriceInDatum = rationalToGHC poiPrice,
oiStart = poiStart,
oiEnd = poiEnd,
oiOwnerAddress = addressToBech32 poiOwnerAddr,
oiOwnerKeyHash = poiOwnerKey,
oiOutputReference = poiRef,
oiNFTToken = GYToken poiNFTCS poiNFT
oiNFTToken = GYToken poiNFTCS poiNFT,
oiVersion = poiVersion
}
:!: isSell

Expand Down Expand Up @@ -534,7 +542,9 @@ handleFillOrders ctx@Ctx {..} fops@FillOrderParameters {..} = do
fopAddresses' = addressFromBech32 <$> fopAddresses
changeAddr = maybe (NonEmpty.head fopAddresses') (\(ChangeAddress addr) addressFromBech32 addr) fopChangeAddress
txBody runSkeletonI ctx (NonEmpty.toList fopAddresses') changeAddr fopCollateral $ do
fillMultiplePartialOrders' porefs ordersWithTokenBuyAmount (Just refPocds) takerFee
case ordersWithTokenBuyAmount of
[(oi, amt)] fillPartialOrder' porefs oi amt (Just $ selectRefPocd refPocds overallPocVersion) (fromIntegral $ valueAssetClass takerFee (poiAskedAsset oi))
_ fillMultiplePartialOrders' porefs ordersWithTokenBuyAmount (Just refPocds) takerFee
pure
FillOrderTransactionDetails
{ fotdTransaction = unsignedTx txBody,
Expand Down
16 changes: 16 additions & 0 deletions geniusyield-server-lib/src/GeniusYield/Server/Orphans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,28 @@ module GeniusYield.Server.Orphans () where
import Control.Lens (at, (?~))
import Data.HashMap.Strict.InsOrd qualified as IOHM
import Data.OpenApi
import Data.Swagger qualified as Swagger
import Data.Swagger.Internal.Schema qualified as Swagger
import GeniusYield.Server.Auth (APIKeyAuthProtect, apiKeyHeaderText)
import RIO
import Servant
import Servant.Foreign
import Servant.OpenApi

instance Swagger.ToSchema Rational where
declareNamedSchema _ = do
integerSchema Swagger.declareSchemaRef @Integer Proxy
return $
Swagger.named "Rational" $
mempty
& Swagger.type_ ?~ Swagger.SwaggerObject
& Swagger.properties
.~ IOHM.fromList
[ ("numerator", integerSchema),
("denominator", integerSchema)
]
& Swagger.required .~ ["numerator", "denominator"]

instance HasOpenApi api HasOpenApi (APIKeyAuthProtect :> api) where
toOpenApi _ =
toOpenApi (Proxy Proxy api)
Expand Down
33 changes: 33 additions & 0 deletions web/openapi/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,13 @@ components:
- asks
type: object
OrderInfo:
description: Order details given as part of order-book (bid and ask). Note that
"price_in_datum" is the price given in datum whereas "price" is the rounded
price in terms of currency asset per commodity asset. I.e., for a sell order,
"price" is rounded value of "price_in_datum" whereas for buy order, "price"
is rounded value of reciprocal of "price_in_datum". Likewise, "offer_amount_in_datum"
is the amount given in datum whereas "offer_amount" is the rounded value in
terms of commodity asset.
properties:
end:
description: This is the posix time in ISO8601 format.
Expand All @@ -342,6 +349,8 @@ components:
example: '0.125'
format: float
type: string
offer_amount_in_datum:
$ref: '#/components/schemas/GYNatural'
output_reference:
$ref: '#/components/schemas/GYTxOutRef'
owner_address:
Expand All @@ -352,18 +361,25 @@ components:
example: '0.125'
format: float
type: string
price_in_datum:
$ref: '#/components/schemas/Rational'
start:
description: This is the posix time in ISO8601 format.
example: 1970-01-01T00:00:00Z
format: ISO8601
type: string
version:
$ref: '#/components/schemas/POCVersion'
required:
- offer_amount
- offer_amount_in_datum
- price
- price_in_datum
- owner_address
- owner_key_hash
- output_reference
- nft_token
- version
type: object
OrderInfoDetailed:
properties:
Expand Down Expand Up @@ -414,6 +430,13 @@ components:
- output_reference
- nft_token
type: object
POCVersion:
description: Version of the family of partial order contracts
enum:
- POCVersion1
- POCVersion1_1
example: POCVersion1
type: string
PlaceOrderParameters:
description: Place order request parameters.
properties:
Expand Down Expand Up @@ -489,6 +512,16 @@ components:
enum:
- PodOrderNotFound
type: string
Rational:
properties:
denominator:
type: integer
numerator:
type: integer
required:
- numerator
- denominator
type: object
Settings:
description: Genius Yield Server settings.
properties:
Expand Down

0 comments on commit 4497d21

Please sign in to comment.