/
Distribution.daml
51 lines (45 loc) · 2.06 KB
/
Distribution.daml
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
-- Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
module Daml.Finance.Lifecycle.Rule.Distribution where
import Daml.Finance.Interface.Lifecycle.Rule.Lifecycle qualified as Lifecycle (Evolve(..), HasImplementation, I, View(..))
import Daml.Finance.Interface.Types.Common.Types (Id(..), Parties)
import Daml.Finance.Lifecycle.Effect (Effect(..))
import Daml.Finance.Lifecycle.Event.Distribution qualified as Distribution (Event)
-- | Type synonym for `Rule`.
type T = Rule
instance Lifecycle.HasImplementation Rule
-- | Rule contract that defines the distribution of units of an instrument for each unit of a target
-- instrument (e.g. share or cash dividends).
template Rule
with
providers : Parties
-- ^ Providers of the distribution rule.
lifecycler : Party
-- ^ Party performing the lifecycling.
observers : Parties
-- ^ Observers of the distribution rule.
id : Id
-- ^ Identifier for the rule contract.
description : Text
-- ^ Textual description.
where
signatory providers
observer observers, lifecycler
interface instance Lifecycle.I for Rule where
view = Lifecycle.View with lifecycler; id; description
evolve Lifecycle.Evolve{eventCid; instrument} = do
distribution <- fetch $ fromInterfaceContractId @Distribution.Event eventCid
assertMsg "The input instrument does not match the distribution's target instrument" $
instrument == distribution.targetInstrument
effectCid <- toInterfaceContractId <$>
create Effect with
providers
id = distribution.id
description = distribution.description
targetInstrument = distribution.targetInstrument
producedInstrument = Some distribution.newInstrument
otherConsumed = []
otherProduced = distribution.perUnitDistribution
settlementTime = Some distribution.effectiveTime
observers
pure (Some distribution.newInstrument, [effectCid])