Skip to content

Commit 4497d21

Browse files
authored
Merge pull request #78 from geniusyield/additional-fields-order-book-update-order-fill
feat: add additional fields to order-book endpoint and modify build f…
2 parents 644108e + e358dee commit 4497d21

File tree

5 files changed

+70
-6
lines changed

5 files changed

+70
-6
lines changed

geniusyield-server-lib/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Revision history for geniusyield-server-lib
22

3+
## 0.8.0 -- 2024-07-09
4+
5+
* Updates `/v0/orders/fill` and `/v0/orders/tx/build-fill` endpoint to internally call `fillPartialOrder'` instead of `fillMultiplePartialOrders'` when single order is being filled.
6+
* Updates `/v0/order-books/{market-id}` endpoint to also return for `offer_amount_in_datum`, `price_in_datum` and `version`.
7+
38
## 0.7.0 -- 2024-06-26
49

510
* 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.

geniusyield-server-lib/geniusyield-server-lib.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 3.6
22
name: geniusyield-server-lib
3-
version: 0.7.0
3+
version: 0.8.0
44
synopsis: GeniusYield server library
55
description: Library for GeniusYield server.
66
license: Apache-2.0

geniusyield-server-lib/src/GeniusYield/Server/Dex/PartialOrder.hs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ import Data.Swagger.Internal.Schema qualified as Swagger
1616
import Deriving.Aeson
1717
import Fmt
1818
import GHC.TypeLits (AppendSymbol, Symbol)
19-
import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..), cancelMultiplePartialOrders', fillMultiplePartialOrders', getPartialOrdersInfos, getPartialOrdersInfos', getVersionsInOrders, orderByNft, partialOrderPrice', placePartialOrder'', preferentiallySelectLatestPocd, preferentiallySelectLatestVersion, roundFunctionForPOCVersion)
20-
import GeniusYield.Api.Dex.PartialOrderConfig (RefPocd (..), SomeRefPocd (SomeRefPocd), fetchPartialOrderConfig, fetchPartialOrderConfigs)
19+
import GeniusYield.Api.Dex.PartialOrder (PartialOrderInfo (..), cancelMultiplePartialOrders', fillMultiplePartialOrders', fillPartialOrder', getPartialOrdersInfos, getPartialOrdersInfos', getVersionsInOrders, orderByNft, partialOrderPrice', placePartialOrder'', preferentiallySelectLatestPocd, preferentiallySelectLatestVersion, roundFunctionForPOCVersion)
20+
import GeniusYield.Api.Dex.PartialOrderConfig (RefPocd (..), SomeRefPocd (SomeRefPocd), fetchPartialOrderConfig, fetchPartialOrderConfigs, selectRefPocd)
2121
import GeniusYield.HTTP.Errors
2222
import GeniusYield.OrderBot.Domain.Markets (OrderAssetPair (..))
2323
import GeniusYield.Scripts.Dex.PartialOrderConfig (PartialOrderConfigInfoF (..))
2424
import GeniusYield.Scripts.Dex.Version (POCVersion (POCVersion1_1))
2525
import GeniusYield.Server.Ctx
26+
import GeniusYield.Server.Orphans ()
2627
import GeniusYield.Server.Tx (handleTxSign, handleTxSubmit, throwNoSigningKeyError)
2728
import GeniusYield.Server.Utils (addSwaggerDescription, addSwaggerExample, dropSymbolAndCamelToSnake, logDebug, logInfo)
2829
import GeniusYield.Types
@@ -86,13 +87,16 @@ type OrderInfoPrefix = "oi"
8687

8788
data OrderInfo = OrderInfo
8889
{ oiOfferAmount !GYRational,
90+
oiOfferAmountInDatum !GYNatural,
8991
oiPrice !GYRational,
92+
oiPriceInDatum !Rational,
9093
oiStart !(Maybe GYTime),
9194
oiEnd !(Maybe GYTime),
9295
oiOwnerAddress !GYAddressBech32,
9396
oiOwnerKeyHash !GYPubKeyHash,
9497
oiOutputReference !GYTxOutRef,
95-
oiNFTToken !GYAssetClass
98+
oiNFTToken !GYAssetClass,
99+
oiVersion !POCVersion
96100
}
97101
deriving stock (Generic)
98102
deriving
@@ -102,6 +106,7 @@ data OrderInfo = OrderInfo
102106
instance Swagger.ToSchema OrderInfo where
103107
declareNamedSchema =
104108
Swagger.genericDeclareNamedSchema Swagger.defaultSchemaOptions {Swagger.fieldLabelModifier = dropSymbolAndCamelToSnake @OrderInfoPrefix}
109+
& 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."
105110

106111
type OrderInfoDetailedPrefix Symbol
107112
type OrderInfoDetailedPrefix = "oid"
@@ -136,13 +141,16 @@ poiToOrderInfo PartialOrderInfo {..} oap =
136141
poiOfferedAmount' = fromIntegral poiOfferedAmount
137142
in OrderInfo
138143
{ oiOfferAmount = if isSell then poiOfferedAmount' else poiOfferedAmount' * poiPrice,
144+
oiOfferAmountInDatum = naturalFromGHC poiOfferedAmount,
139145
oiPrice = if isSell then poiPrice else 1 / poiPrice,
146+
oiPriceInDatum = rationalToGHC poiPrice,
140147
oiStart = poiStart,
141148
oiEnd = poiEnd,
142149
oiOwnerAddress = addressToBech32 poiOwnerAddr,
143150
oiOwnerKeyHash = poiOwnerKey,
144151
oiOutputReference = poiRef,
145-
oiNFTToken = GYToken poiNFTCS poiNFT
152+
oiNFTToken = GYToken poiNFTCS poiNFT,
153+
oiVersion = poiVersion
146154
}
147155
:!: isSell
148156

@@ -534,7 +542,9 @@ handleFillOrders ctx@Ctx {..} fops@FillOrderParameters {..} = do
534542
fopAddresses' = addressFromBech32 <$> fopAddresses
535543
changeAddr = maybe (NonEmpty.head fopAddresses') (\(ChangeAddress addr) addressFromBech32 addr) fopChangeAddress
536544
txBody runSkeletonI ctx (NonEmpty.toList fopAddresses') changeAddr fopCollateral $ do
537-
fillMultiplePartialOrders' porefs ordersWithTokenBuyAmount (Just refPocds) takerFee
545+
case ordersWithTokenBuyAmount of
546+
[(oi, amt)] fillPartialOrder' porefs oi amt (Just $ selectRefPocd refPocds overallPocVersion) (fromIntegral $ valueAssetClass takerFee (poiAskedAsset oi))
547+
_ fillMultiplePartialOrders' porefs ordersWithTokenBuyAmount (Just refPocds) takerFee
538548
pure
539549
FillOrderTransactionDetails
540550
{ fotdTransaction = unsignedTx txBody,

geniusyield-server-lib/src/GeniusYield/Server/Orphans.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@ module GeniusYield.Server.Orphans () where
55
import Control.Lens (at, (?~))
66
import Data.HashMap.Strict.InsOrd qualified as IOHM
77
import Data.OpenApi
8+
import Data.Swagger qualified as Swagger
9+
import Data.Swagger.Internal.Schema qualified as Swagger
810
import GeniusYield.Server.Auth (APIKeyAuthProtect, apiKeyHeaderText)
911
import RIO
1012
import Servant
1113
import Servant.Foreign
1214
import Servant.OpenApi
1315

16+
instance Swagger.ToSchema Rational where
17+
declareNamedSchema _ = do
18+
integerSchema Swagger.declareSchemaRef @Integer Proxy
19+
return $
20+
Swagger.named "Rational" $
21+
mempty
22+
& Swagger.type_ ?~ Swagger.SwaggerObject
23+
& Swagger.properties
24+
.~ IOHM.fromList
25+
[ ("numerator", integerSchema),
26+
("denominator", integerSchema)
27+
]
28+
& Swagger.required .~ ["numerator", "denominator"]
29+
1430
instance HasOpenApi api HasOpenApi (APIKeyAuthProtect :> api) where
1531
toOpenApi _ =
1632
toOpenApi (Proxy Proxy api)

web/openapi/api.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,13 @@ components:
330330
- asks
331331
type: object
332332
OrderInfo:
333+
description: Order details given as part of order-book (bid and ask). Note that
334+
"price_in_datum" is the price given in datum whereas "price" is the rounded
335+
price in terms of currency asset per commodity asset. I.e., for a sell order,
336+
"price" is rounded value of "price_in_datum" whereas for buy order, "price"
337+
is rounded value of reciprocal of "price_in_datum". Likewise, "offer_amount_in_datum"
338+
is the amount given in datum whereas "offer_amount" is the rounded value in
339+
terms of commodity asset.
333340
properties:
334341
end:
335342
description: This is the posix time in ISO8601 format.
@@ -342,6 +349,8 @@ components:
342349
example: '0.125'
343350
format: float
344351
type: string
352+
offer_amount_in_datum:
353+
$ref: '#/components/schemas/GYNatural'
345354
output_reference:
346355
$ref: '#/components/schemas/GYTxOutRef'
347356
owner_address:
@@ -352,18 +361,25 @@ components:
352361
example: '0.125'
353362
format: float
354363
type: string
364+
price_in_datum:
365+
$ref: '#/components/schemas/Rational'
355366
start:
356367
description: This is the posix time in ISO8601 format.
357368
example: 1970-01-01T00:00:00Z
358369
format: ISO8601
359370
type: string
371+
version:
372+
$ref: '#/components/schemas/POCVersion'
360373
required:
361374
- offer_amount
375+
- offer_amount_in_datum
362376
- price
377+
- price_in_datum
363378
- owner_address
364379
- owner_key_hash
365380
- output_reference
366381
- nft_token
382+
- version
367383
type: object
368384
OrderInfoDetailed:
369385
properties:
@@ -414,6 +430,13 @@ components:
414430
- output_reference
415431
- nft_token
416432
type: object
433+
POCVersion:
434+
description: Version of the family of partial order contracts
435+
enum:
436+
- POCVersion1
437+
- POCVersion1_1
438+
example: POCVersion1
439+
type: string
417440
PlaceOrderParameters:
418441
description: Place order request parameters.
419442
properties:
@@ -489,6 +512,16 @@ components:
489512
enum:
490513
- PodOrderNotFound
491514
type: string
515+
Rational:
516+
properties:
517+
denominator:
518+
type: integer
519+
numerator:
520+
type: integer
521+
required:
522+
- numerator
523+
- denominator
524+
type: object
492525
Settings:
493526
description: Genius Yield Server settings.
494527
properties:

0 commit comments

Comments
 (0)