Deprecated

This Splice documentation site is deprecated. Use the current Canton Network docs.

Open current docs

Splice.Testing.Apps.TradingAppV2

An example of how to build an OTC trading app that supports V1/V2 mixed settlements with extra privacy for V2 allocations..

Used as part of the testing infrastructure to test the V2 token standard DvP workflows.

Templates

template OTCTrade

A matched trade ready to settle.

Signatory: venue

Field

Type

Description

venue

Party

tradeLegs

[TradeLeg]

Transfers to settle.

createdAt

Time

When the matched trade was created on-ledger.

settleAt

Time

When the trade should be settled by.

settlementDeadline

Optional Time

Deadline for when the settlement should be completed.

template OTCTradeAllocationRequest

A request to a single trading account to authorize their legs to the trade.

Signatory: (DA.Internal.Record.getField @"executors" settlement)

Field

Type

Description

settlement

SettlementInfo

requestedAt

Time

settleAt

Time

allocations

[AllocationSpecification]

template TradeSettlementAgreement

An agreement to authorize the settlement of a trade by the venue, as an additional settlementAuthorizer. Used to settle V1 allocations, which require extra settlement authorizers to authorize the batch settlement.

Signatory: venue, trader

Field

Type

Description

venue

Party

trader

Party

Data Types

data AllocationWithContextV1

A V1 allocation with enough context to settle or cancel it.

AllocationWithContextV1

Field

Type

Description

allocationCid

ContractId Allocation

extraArgs

ExtraArgs

senderAgreementCid

ContractId TradeSettlementAgreement

receiverAgreementCid

ContractId TradeSettlementAgreement

instance Eq AllocationWithContextV1

instance Show AllocationWithContextV1

instance GetField "allocationCid" AllocationWithContextV1 (ContractId Allocation)

instance GetField "allocationsWithContext" SettlementBatch (TextMap AllocationWithContextV1)

instance GetField "allocationsWithContextV1" OTCTrade_Cancel [AllocationWithContextV1]

instance GetField "extraArgs" AllocationWithContextV1 ExtraArgs

instance GetField "receiverAgreementCid" AllocationWithContextV1 (ContractId TradeSettlementAgreement)

instance GetField "senderAgreementCid" AllocationWithContextV1 (ContractId TradeSettlementAgreement)

instance SetField "allocationCid" AllocationWithContextV1 (ContractId Allocation)

instance SetField "allocationsWithContext" SettlementBatch (TextMap AllocationWithContextV1)

instance SetField "allocationsWithContextV1" OTCTrade_Cancel [AllocationWithContextV1]

instance SetField "extraArgs" AllocationWithContextV1 ExtraArgs

instance SetField "receiverAgreementCid" AllocationWithContextV1 (ContractId TradeSettlementAgreement)

instance SetField "senderAgreementCid" AllocationWithContextV1 (ContractId TradeSettlementAgreement)

data MissingAllocation

MissingAllocation

Field

Type

Description

authorizerAgreementCid

Optional (ContractId TradeSettlementAgreement)

None for missing allocations of the venue itself.

factoryCid

ContractId AllocationFactory

choiceArg

AllocationFactory_Allocate

instance Eq MissingAllocation

instance Show MissingAllocation

instance GetField "authorizerAgreementCid" MissingAllocation (Optional (ContractId TradeSettlementAgreement))

instance GetField "choiceArg" MissingAllocation AllocationFactory_Allocate

instance GetField "factoryCid" MissingAllocation (ContractId AllocationFactory)

instance GetField "missingAllocations" SettlementBatch [MissingAllocation]

instance SetField "authorizerAgreementCid" MissingAllocation (Optional (ContractId TradeSettlementAgreement))

instance SetField "choiceArg" MissingAllocation AllocationFactory_Allocate

instance SetField "factoryCid" MissingAllocation (ContractId AllocationFactory)

instance SetField "missingAllocations" SettlementBatch [MissingAllocation]

data OTCTrade_CancelResult

OTCTrade_CancelResult

Field

Type

Description

resultsV1

TextMap Allocation_CancelResult

Results for V1 allocation cancellations keyed by transferLegId

resultsV2

[(Account, AllocationResult)]

instance GetField "resultsV1" OTCTrade_CancelResult (TextMap Allocation_CancelResult)

instance GetField "resultsV2" OTCTrade_CancelResult [(Account, AllocationResult)]

instance SetField "resultsV1" OTCTrade_CancelResult (TextMap Allocation_CancelResult)

instance SetField "resultsV2" OTCTrade_CancelResult [(Account, AllocationResult)]

instance HasExercise OTCTrade OTCTrade_Cancel OTCTrade_CancelResult

instance HasFromAnyChoice OTCTrade OTCTrade_Cancel OTCTrade_CancelResult

instance HasToAnyChoice OTCTrade OTCTrade_Cancel OTCTrade_CancelResult

data OTCTrade_SettleResult

OTCTrade_SettleResult

Field

Type

Description

resultsByAdminV1

Map Party (TextMap Allocation_ExecuteTransferResult)

Results for V1-only admins

resultsByAdminV2

Map Party SettlementFactory_SettleBatchResult

Result for admins that support V2

instance GetField "resultsByAdminV1" OTCTrade_SettleResult (Map Party (TextMap Allocation_ExecuteTransferResult))

instance GetField "resultsByAdminV2" OTCTrade_SettleResult (Map Party SettlementFactory_SettleBatchResult)

instance SetField "resultsByAdminV1" OTCTrade_SettleResult (Map Party (TextMap Allocation_ExecuteTransferResult))

instance SetField "resultsByAdminV2" OTCTrade_SettleResult (Map Party SettlementFactory_SettleBatchResult)

instance HasExercise OTCTrade OTCTrade_Settle OTCTrade_SettleResult

instance HasFromAnyChoice OTCTrade OTCTrade_Settle OTCTrade_SettleResult

instance HasToAnyChoice OTCTrade OTCTrade_Settle OTCTrade_SettleResult

data SettlementBatch

A batch of allocations for the same admin together with the extra arguments required to settle them.

SettlementBatchV1

Batch for V1-only admins

Field

Type

Description

allocationsWithContext

TextMap AllocationWithContextV1

SettlementBatchV2

Field

Type

Description

allocationCids

[ContractId Allocation]

missingAllocations

[MissingAllocation]

Allocations that should be created as part of settlement. These are: * the allocation(s) of the venue to receive fees * the allocations for the receipt of V2 assets for traders that use V1 wallets, which do not create receipt allocations on their own

factoryCid

ContractId SettlementFactory

extraArgs

ExtraArgs

instance Eq SettlementBatch

instance Show SettlementBatch

instance GetField "allocationCids" SettlementBatch [ContractId Allocation]

instance GetField "allocationsWithContext" SettlementBatch (TextMap AllocationWithContextV1)

instance GetField "batchesByAdmin" OTCTrade_Settle (Map Party SettlementBatch)

instance GetField "extraArgs" SettlementBatch ExtraArgs

instance GetField "factoryCid" SettlementBatch (ContractId SettlementFactory)

instance GetField "missingAllocations" SettlementBatch [MissingAllocation]

instance SetField "allocationCids" SettlementBatch [ContractId Allocation]

instance SetField "allocationsWithContext" SettlementBatch (TextMap AllocationWithContextV1)

instance SetField "batchesByAdmin" OTCTrade_Settle (Map Party SettlementBatch)

instance SetField "extraArgs" SettlementBatch ExtraArgs

instance SetField "factoryCid" SettlementBatch (ContractId SettlementFactory)

instance SetField "missingAllocations" SettlementBatch [MissingAllocation]

data TradeLeg

Leg of a trade.

TradeLeg

Field

Type

Description

admin

Party

Admin party of the instrument being transferred.

leg

TransferLeg

The transfer details.

instance Eq TradeLeg

instance Show TradeLeg

instance GetField "admin" TradeLeg Party

instance GetField "leg" TradeLeg TransferLeg

instance GetField "tradeLegs" OTCTrade [TradeLeg]

instance SetField "admin" TradeLeg Party

instance SetField "leg" TradeLeg TransferLeg

instance SetField "tradeLegs" OTCTrade [TradeLeg]

Functions

affectedAccountParties

: OTCTradeAllocationRequest -> [Party]

splitLegsBy

: Ord k => (leg -> k) -> [leg] -> Map k [leg]

splitTradeLegsByAuthorizer

: [TradeLeg] -> Map Account [(Party, TransferLegSide)]

Group transfer legs by the account that needs to authorize them.

mkOtcTradeSettlementInfoV2

: ContractId OTCTrade -> OTCTrade -> SettlementInfo

mkOtcTradeSettlementInfoV1

: ContractId OTCTrade -> OTCTrade -> SettlementInfo

expectedTradeAllocationsV1

: SettlementInfo -> [TradeLeg] -> TextMap AllocationSpecification

The expected allocations for a trade that involves an asset implementing the V1 token standard only. There we expect exactly one allocation per transfer leg. That allocation is created by the sender, and settled with the authority of sender and receiver

extractAllocationCidFromResult

: AllocationInstructionResult -> Update (ContractId Allocation)

validateAllocationAsSender

: TradeSettlementAgreement -> ContractId TradeSettlementAgreement -> ContractId Allocation -> Update ()

validateAllocationAsReceiver

: TradeSettlementAgreement -> Party -> ContractId Allocation -> Update ()

Comments