Daml finance tutorial - Transfer workflow

I have been going through the code-example in Daml Finance docs tutorials. In the Transfer workflow, the cashInstrument is created but never used.

Code for cashInstrument:

cashInstrumentCid <- toInterfaceContractId @Instrument.I <$> submit bank do
    createCmd Instrument with
      depository = bank
      issuer = bank
      id = instrumentId
      version = instrumentVersion
      description = "Instrument representing units of USD"
      validAsOf = now
      observers = empty

But somewhere below, it creates cashInstrument variable and uses that for transfer.

let
    cashInstrument = InstrumentKey with
      issuer = bank
      depository = bank
      id = instrumentId
      version = instrumentVersion

  transferRequestCid <- submit bob do
    createCmd Transfer.Request with
      receiverAccount = bobAccount
      instrument = cashInstrument
      amount = 1000.0
      currentOwner = alice

Commenting out the first definition makes no difference and the script still runs.

So is that just an oversight or am I missing something?

Hi @Neelam_Dwivedi,

Thanks for your feedback.

In Daml Finance, we distinguish between

  • Holding contracts, which are records of ownership
  • Instrument contracts, which define the economic terms (rights and obligations) of a financial instrument

This is explained in more details in the Daml Finance documentation.

A Holding references a certain Instrument via an InstrumentKey identifier, which is what is created in the second code block above.

However, as you correctly point out, in order to create a Holding and then Transfer it to a new party, there is no need for the actual Instrument contract to be on the ledger. The Instrument contract will need to be on the ledger once we want to perform lifecycling, which is a topic covered in a subsequent tutorial.

The reason why we create the cashInstrumentCid contract in the Transfer tutorial is because it conceptually makes sense to

  • first define the economic terms of a financial instrument
  • then register records of ownership on such an instrument

but from a Daml Finance perspective the first step is not required.

I hope this helps!
Matteo

Thanks @Matteo_Limberto

So what I understand is that the first code-block demonstrates how to create an instrument before it can be used in a Holding.

However, in this example, the relationship between the instrument created in the first block and the one created and used in the second block is missing.

Hi @Neelam_Dwivedi,

The first code block demonstrates how to create an instrument.

The second code block does not create an Instrument, but it creates an InstrumentKey, which is just a label / identifier for an instrument.

The latter is needed in order to create a Holding, whereas the former is not needed.

Matteo

1 Like