Skip to content

Commit

Permalink
Id removal from listing (#404)
Browse files Browse the repository at this point in the history
* Remove outdated integrationTest directory

* Change listingId type from Id to Text

* Change order id type to Text

* Formatting

* Add auto eol setting to prettier config
  • Loading branch information
GeorgSchneider committed Jul 20, 2021
1 parent 11ac762 commit 32af4eb
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 323 deletions.
6 changes: 3 additions & 3 deletions daml/Marketplace/Clearing/Market/Model.daml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ template FairValueCalculationRequest
operator : Party
provider : Party
customer : Party
optListingIds : Optional [Id]
optListingIds : Optional [Text]
currency : Id
upTo : Time
where
Expand All @@ -22,7 +22,7 @@ template ManualFairValueCalculation
operator : Party
provider : Party
customer : Party
listingId : Id
listingId : Text
currency : Id
upTo : Time
observers : Set Party
Expand All @@ -43,7 +43,7 @@ template FairValue
operator : Party
provider : Party
customer : Party
listingId : Id
listingId : Text
price : Decimal
currency : Id
timestamp : Time
Expand Down
6 changes: 3 additions & 3 deletions daml/Marketplace/Clearing/Market/Service.daml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template Service
nonconsuming choice RequestFairValues : ContractId FairValueCalculationRequest
with
party : Party
listingIds : [Id]
listingIds : [Text]
currency : Id
controller party
do
Expand All @@ -44,7 +44,7 @@ template Service
controller provider can
nonconsuming CreateFairValue : ContractId FairValue
with
listingId : Id
listingId : Text
price : Decimal
currency : Id
timestamp : Time
Expand All @@ -55,7 +55,7 @@ template Service

nonconsuming CreateManualFairValueRequest : ContractId ManualFairValueCalculation
with
listingId : Id
listingId : Text
currency : Id
upTo : Time
observers : Set Party
Expand Down
6 changes: 3 additions & 3 deletions daml/Marketplace/Listing/Model.daml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ template Listing
provider : Party
customer : Party
listingType : ListingType
listingId : Id
listingId : Text
calendarId : Text
description : Text
tradedAssetId : Id
Expand All @@ -44,8 +44,8 @@ template Listing
(Cleared p _) -> [p]; _ -> []

-- TODO: Should we key by traded and quoted asset instead? listing id could be opaque / random
key listingId : Id
maintainer key.signatories
key (operator, provider, listingId) : (Party, Party, Text)
maintainer key._1, key._2

template ClearedListingApproval
with
Expand Down
3 changes: 1 addition & 2 deletions daml/Marketplace/Listing/Service.daml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ template Service
do
CreateListingRequest{..} <- fetch createListingRequestCid
archive createListingRequestCid
let id = Id with signatories = fromList [provider, customer]; label = symbol; version = 0
create Listing with listingId = id; ..
create Listing with listingId = symbol; ..

nonconsuming ListingFailure : ContractId FailedListingCreation
with
Expand Down
6 changes: 3 additions & 3 deletions daml/Marketplace/Trading/Model.daml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ data TimeInForce
deriving (Eq, Show)

data Details = Details with
id : Id
listingId : Id
id : Text
listingId : Text
asset : Asset
side : Side
orderType : OrderType
Expand Down Expand Up @@ -92,7 +92,7 @@ template Order
(Cleared ch) -> [ch]
_ -> []

key (provider, details.id.label) : (Party, Text)
key (provider, details.id) : (Party, Text)
maintainer key._1

data Fee = Fee with
Expand Down
14 changes: 7 additions & 7 deletions daml/Marketplace/Trading/Service.daml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ template Service
providerOrderId : Text
do
CreateOrderRequest{..} <- fetchAndArchive createOrderRequestCid
(orderCid, order) <- fetchByKey (provider, details.id.label)
(orderCid, order) <- fetchByKey (provider, details.id)

-- TODO: Confirm what to do with this business ACK when received out of the expected order.
-- Should we set the providerOrderId but leave the status as is ? Should we check if this value is already set ? What to do if it's already set ? etc.
Expand All @@ -128,7 +128,7 @@ template Service
errorMessage : Text
do
CreateOrderRequest{details, collateral} <- fetch createOrderRequestCid
(orderCid, order) <- fetchByKey (provider, details.id.label)
(orderCid, order) <- fetchByKey (provider, details.id)
archive orderCid

let reason = Error with code = show errorCode; message = errorMessage
Expand All @@ -145,7 +145,7 @@ template Service
cancelledQuantity : Decimal
do
CreateOrderRequest{details} <- fetch createOrderRequestCid
(orderCid, order) <- fetchByKey (provider, details.id.label)
(orderCid, order) <- fetchByKey (provider, details.id)

let isFullCancellation = cancelledQuantity >= order.details.asset.quantity
isWaitingExecution = order.status `elem` [Order.New, Order.PendingExecution]
Expand All @@ -165,7 +165,7 @@ template Service
cancelOrderRequestCid : ContractId CancelOrderRequest
do
CancelOrderRequest{..} <- fetchAndArchive cancelOrderRequestCid
(orderCid, order@Order.Order{..}) <- fetchByKey (provider, details.id.label)
(orderCid, order@Order.Order{..}) <- fetchByKey (provider, details.id)
archive orderCid

orderCid <- create order with status = Order.Cancelled
Expand All @@ -181,7 +181,7 @@ template Service
errorMessage : Text
do
CancelOrderRequest{..} <- fetchAndArchive cancelOrderRequestCid
(orderCid, order) <- fetchByKey (provider, details.id.label)
(orderCid, order) <- fetchByKey (provider, details.id)
archive orderCid

let reason = Error with code = show errorCode; message = errorMessage
Expand Down Expand Up @@ -271,7 +271,7 @@ template CreateOrderRequest
where
signatory provider, customer

key (provider, details.id.label) : (Party, Text)
key (provider, details.id) : (Party, Text)
maintainer key._1

let serviceKey = (operator, provider, customer)
Expand Down Expand Up @@ -306,7 +306,7 @@ template CancelOrderRequest
where
signatory provider, customer

key (provider, details.id.label) : (Party, Text)
key (provider, details.id) : (Party, Text)
maintainer key._1

let serviceKey = (operator, provider, customer)
Expand Down
16 changes: 7 additions & 9 deletions daml/Tests/Clearing/Setup.daml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import Marketplace.Issuance.AssetDescription as AssetDescription
import Marketplace.Issuance.CFI qualified as CFI
import Tests.Utils (future)

import DA.Set qualified as Set

checkOrderStatusMatches : ContractId Order.T -> Party -> Order.Status -> Script ()
checkOrderStatusMatches orderCid party status = do
Some order <- queryContractId @Order.T party orderCid
Expand Down Expand Up @@ -85,7 +83,7 @@ clearedTradingTest = do
-- List a Security to trade
Some (listingServiceCid, _) <- queryContractKey @Listing.Service exchange (operator, exchange, exchange)

let mkMarket : Id -> Id -> Script Id
let mkMarket : Id -> Id -> Script Text
mkMarket quoteId tradedId = do
let
symbol = quoteId.label <> tradedId.label
Expand Down Expand Up @@ -118,11 +116,11 @@ clearedTradingTest = do

return ()

makeTrade : Providers -> Id -> Customer -> Customer -> Decimal -> Decimal -> Int -> Script ()
makeTrade : Providers -> Text -> Customer -> Customer -> Decimal -> Decimal -> Int -> Script ()
makeTrade Providers{..} listingId buyer seller price qty currentId = do
(Some (_,listing)) <- queryContractKey @Listing.T exchange listingId
(Some (_,listing)) <- queryContractKey @Listing.T exchange (operator, exchange, listingId)
-- Create orders
let sellerOrderId = Id with signatories = Set.fromList [ seller.customer ], label = show currentId, version = 0
let sellerOrderId = show currentId
Right (sellerOrderCid, sellerCreateOrderRequestCid, _) <- seller.customer `submit` do
exerciseCmd seller.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand All @@ -135,7 +133,7 @@ makeTrade Providers{..} listingId buyer seller price qty currentId = do
timeInForce = Order.GTC
orderType = Order.Limit with price

let buyerOrderId = Id with signatories = Set.fromList [ buyer.customer ], label = show (currentId + 1), version = 0
let buyerOrderId = show (currentId + 1)
Right (buyerOrderCid, buyerCreateOrderRequestCid, _) <- submitMulti [buyer.customer] [public] $ do
exerciseCmd buyer.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand Down Expand Up @@ -164,8 +162,8 @@ makeTrade Providers{..} listingId buyer seller price qty currentId = do
-- Confirm order matches
let execution = Order.Execution with
matchId = show currentId
makerOrderId = sellerOrderId.label
takerOrderId = buyerOrderId.label
makerOrderId = sellerOrderId
takerOrderId = buyerOrderId
quantity = 200.0
price = 100.0
timestamp = "123456"
Expand Down
16 changes: 7 additions & 9 deletions daml/Tests/ExchangeTrade.daml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ module Tests.ExchangeTrade where

import Common
import Daml.Script
import DA.Finance.Types (Id(..))
import DA.Finance.Asset (AssetDeposit_Split(..))
import DA.Set
import DA.Foldable (forA_)
import qualified Marketplace.Settlement.Model as Settlement
import qualified Marketplace.Trading.Matching.Service as Matching
Expand Down Expand Up @@ -58,7 +56,7 @@ setup = do
exerciseByKeyCmd @TradingService.T (operator, exchange, alice.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ alice.customer ]; label = "123"; version = 0
id = "123"
listingId
asset = shareAsset
optExchangeFee = None
Expand All @@ -73,7 +71,7 @@ setup = do
exerciseByKeyCmd @TradingService.T (operator, exchange, bob.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ bob.customer ]; label = "456"; version = 0
id = "456"
listingId
asset = shareAsset
optExchangeFee = None
Expand Down Expand Up @@ -143,7 +141,7 @@ partialExecutionsTest = do
exerciseByKeyCmd @TradingService.T (operator, exchange, alice.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ alice.customer ]; label = "001"; version = 0
id = "001"
listingId
asset = shareAsset
orderType = Order.Limit with price = 100.0
Expand All @@ -158,7 +156,7 @@ partialExecutionsTest = do
exerciseByKeyCmd @TradingService.T (operator, exchange, bob.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ bob.customer ]; label = "100"; version = 0
id = "100"
listingId
asset = shareAsset with quantity = 50.0
orderType = Order.Limit with price = 100.0
Expand All @@ -172,7 +170,7 @@ partialExecutionsTest = do
exerciseByKeyCmd @TradingService.T (operator, exchange, bob.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ bob.customer ]; label = "101"; version = 0
id = "101"
listingId
asset = shareAsset with quantity = 50.0
orderType = Order.Limit with price = 100.0
Expand All @@ -186,7 +184,7 @@ partialExecutionsTest = do
exerciseByKeyCmd @TradingService.T (operator, exchange, bob.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ bob.customer ]; label = "102"; version = 0
id = "102"
listingId
asset = shareAsset with quantity = 50.0
orderType = Order.Limit with price = 100.0
Expand All @@ -200,7 +198,7 @@ partialExecutionsTest = do
exerciseByKeyCmd @TradingService.T (operator, exchange, bob.customer) TradingService.RequestCreateOrder
with
details = Order.Details with
id = Id with signatories = fromList [ bob.customer ]; label = "103"; version = 0
id = "103"
listingId
asset = shareAsset with quantity = 50.0
orderType = Order.Limit with price = 100.0
Expand Down
11 changes: 3 additions & 8 deletions daml/Tests/Locking.daml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module Tests.Locking where

import Daml.Script
import DA.Assert ((===))
import DA.Finance.Types (Id(..))
import DA.Set
import Marketplace.Trading.Service qualified as Trading
import Marketplace.Trading.Model qualified as Order
import Marketplace.Rule.AllocationAccount (AllocationAccountRule, Transfer(..), Withdraw(..))
Expand All @@ -28,14 +26,11 @@ traderCannotMoveAllocatedAsset = do

aliceDepositCid <- depositAsset providers alice shareAsset alice.mainAccount.id
bobDepositCid <- depositAsset providers bob cashAsset bob.mainAccount.id
let listingId = Id with signatories = fromList [exchange]; label = "TSLAUSD"; version = 0
let listingId = "TSLAUSD"

-- Create orders
let aliceOrderId = Id with signatories = fromList [ alice.customer ], label = "1", version = 0
Right (aliceOrderCid, aliceCreateOrderRequestCid, aliceAssetDepositCid) <- submit alice.customer do exerciseCmd alice.tradingServiceCid Trading.RequestCreateOrder with collateral = Order.Collateral aliceDepositCid; details = Order.Details with optExchangeFee = None, id = aliceOrderId, listingId, asset = shareAsset, side = Order.Sell, timeInForce = Order.GTC, orderType = Order.Limit with price = 100.0

let bobOrderId = Id with signatories = fromList [ bob.customer ], label = "2", version = 0
Right (bobOrderCid, bobCreateOrderRequestCid, bobAssetDepositCid) <- submit bob.customer do exerciseCmd bob.tradingServiceCid Trading.RequestCreateOrder with collateral = Order.Collateral bobDepositCid; details = Order.Details with optExchangeFee = None, id = bobOrderId, listingId, asset = shareAsset, side = Order.Buy, timeInForce = Order.GTC, orderType = Order.Limit with price = 100.0
Right (aliceOrderCid, aliceCreateOrderRequestCid, aliceAssetDepositCid) <- submit alice.customer do exerciseCmd alice.tradingServiceCid Trading.RequestCreateOrder with collateral = Order.Collateral aliceDepositCid; details = Order.Details with optExchangeFee = None, id = "1", listingId, asset = shareAsset, side = Order.Sell, timeInForce = Order.GTC, orderType = Order.Limit with price = 100.0
Right (bobOrderCid, bobCreateOrderRequestCid, bobAssetDepositCid) <- submit bob.customer do exerciseCmd bob.tradingServiceCid Trading.RequestCreateOrder with collateral = Order.Collateral bobDepositCid; details = Order.Details with optExchangeFee = None, id = "2", listingId, asset = shareAsset, side = Order.Buy, timeInForce = Order.GTC, orderType = Order.Limit with price = 100.0

-- Account owners can't move asset pledged as order collateral
submitMustFail alice.customer do exerciseByKeyCmd @AllocationAccountRule alice.exchangeLockedAccount.id Transfer with depositCid = aliceDepositCid; transferTo = alice.mainAccount
Expand Down
17 changes: 7 additions & 10 deletions daml/Tests/Trading/Cleared.daml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Daml.Script
import Common
import DA.Assert ((===))
import DA.Either
import DA.List (head)
import Marketplace.Trading.Service qualified as Trading
import Marketplace.Trading.Model qualified as Order
import Marketplace.Clearing.Role qualified as Clearing
Expand All @@ -14,10 +15,6 @@ import Marketplace.Trading.Matching.Service qualified as Matching
import Marketplace.Listing.Service qualified as Listing
import Marketplace.Listing.Model qualified as Listing

import DA.Finance.Types
import DA.Set qualified as Set
import DA.List (head)

checkOrderStatusMatches : ContractId Order.T -> Party -> Order.Status -> Script ()
checkOrderStatusMatches orderCid party status = do
Some order <- queryContractId @Order.T party orderCid
Expand Down Expand Up @@ -70,7 +67,7 @@ clearedTradingTest = do
(Some Listing.Listing{listingId}) <- queryContractId @Listing.Listing exchange listingCid

-- Create orders
let aliceOrderId = Id with signatories = Set.fromList [ alice.customer ], label = "1", version = 0
let aliceOrderId = "1"
Right (aliceOrderCid, aliceCreateOrderRequestCid, _) <- alice.customer `submit` do
exerciseCmd alice.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand All @@ -84,7 +81,7 @@ clearedTradingTest = do
orderType = Order.Limit with price = 100.0
checkOrderStatusMatches aliceOrderCid alice.customer Order.New

let bobOrderId = Id with signatories = Set.fromList [ bob.customer ], label = "2", version = 0
let bobOrderId = "2"
Right (bobOrderCid, bobCreateOrderRequestCid, _) <- submitMulti [bob.customer] [public] $ do
exerciseCmd bob.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand Down Expand Up @@ -114,8 +111,8 @@ clearedTradingTest = do
-- Confirm order matches
let execution = Order.Execution with
matchId = "1"
makerOrderId = aliceOrderId.label
takerOrderId = bobOrderId.label
makerOrderId = aliceOrderId
takerOrderId = bobOrderId
quantity = 200.0
price = 100.0
timestamp = "123456"
Expand All @@ -141,7 +138,7 @@ clearedTradingTest = do
with depositCids = []; marginDepositCids = []; ..

-- !! Bob is in bad standing, so the new order should fail
let bobOrderId2 = Id with signatories = Set.fromList [ bob.customer ], label = "3", version = 0
let bobOrderId2 = "3"
bobOrderResult <- bob.customer `submit` do
exerciseCmd bob.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand All @@ -159,7 +156,7 @@ clearedTradingTest = do
submit charlie.customer $ exerciseCmd charlie.clearingServiceCid Clearing.Terminate with ctrl = charlie.customer

-- !! Charlie is not a member of the clearinghouse, so Charlie should not be able to place an order
let charlieOrderId = Id with signatories = Set.fromList [ charlie.customer ], label = "4", version = 0
let charlieOrderId = "4"
charlieOrderResult <- charlie.customer `submit` do
exerciseCmd charlie.tradingServiceCid Trading.RequestCreateOrder with
collateral = Order.Cleared clearinghouse
Expand Down
Loading

0 comments on commit 32af4eb

Please sign in to comment.