-
Notifications
You must be signed in to change notification settings - Fork 10
/
MatchingStrategy.hs
57 lines (54 loc) · 1.78 KB
/
MatchingStrategy.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
{- |
Module : GeniusYield.OrderBot.MatchingStrategy
Copyright : (c) 2023 GYELD GMBH
License : Apache 2.0
Maintainer : [email protected]
Stability : develop
-}
module GeniusYield.OrderBot.MatchingStrategy (
IndependentStrategy,
FillType (..),
MatchExecutionInfo (..),
MatchResult,
completeFill,
partialFill,
executionSkeleton,
matchExecutionInfoUtxoRef,
) where
import Data.Maybe (fromJust)
import GeniusYield.Api.Dex.PartialOrder (
PORefs,
PartialOrderInfo (poiOfferedAmount),
fillMultiplePartialOrders',
)
import GeniusYield.Api.Dex.Types (GYDexApiMonad)
import GeniusYield.OrderBot.Strategies (
IndependentStrategy,
MatchResult,
)
import GeniusYield.OrderBot.Types
import GeniusYield.TxBuilder (GYTxSkeleton)
import GeniusYield.Types.PlutusVersion (PlutusVersion (PlutusV2))
import GeniusYield.Types.TxOutRef (GYTxOutRef)
executionSkeleton ::
GYDexApiMonad m a =>
PORefs ->
MatchResult ->
m (GYTxSkeleton 'PlutusV2)
executionSkeleton pors mr = fillMultiplePartialOrders' pors (map f mr) Nothing mempty
where
f (OrderExecutionInfo ft o) =
let oi = fromJust $ mPoi o -- It's always under `Just` constructor in our code, but we aren't able to get rid of `Maybe` type for now since that would require significant changes in the test-suite.
in ( oi
, case ft of
CompleteFill -> poiOfferedAmount oi
PartialFill n ->
if isBuyOrder o
then
floor $ fromIntegral n * getPrice (price o)
else
n
)
matchExecutionInfoUtxoRef :: MatchExecutionInfo -> GYTxOutRef
matchExecutionInfoUtxoRef (OrderExecutionInfo CompleteFill OrderInfo {orderRef}) = orderRef
matchExecutionInfoUtxoRef (OrderExecutionInfo (PartialFill _) OrderInfo {orderRef}) = orderRef