Asset Modeling in DAML (Tutorial-7 Deep Dive Part 1)

Overview

DAML is the smart contract language modeling digital assets, which can then be deployed in a variety of environments, from databases to distributed ledger platforms such as Hyperledger Fabric and Corda. Their documentation comes with a 10-module tutorial. In my previous articles I talked about the concept of template and contract, and a very common proposal-acceptance model on DAML. They are good for us to get into Tutorial 7, a more comprehensive and well-structured modeling for asset trading. This article is a deep-dive into the Tutorial 7.

  • A role contract (asset holder) exists for each asset owner, facilitating some handling some operations on the assets.
  • The asset is fungible.
  • The asset is transferable.
  • The asset is tradeable, where trading here is an atomic transaction of assets between two parties.

Setup

Like my previous works, our focus is on the modeling language itself. We are using DAML Studio with our test script for real-life example simulation If you wish to follow the guide, what you need is to install the DAML SDK (v1.9.0+). Follow the installation instruction here. After installation you can get the code for Tutorial 7 here.

Creation of Asset: Asset Contract and Asset Holder Contract

We first begin with the Asset contract template, from which Asset contracts are created in DAML ledger.

Asset Contract

Here is the template details about Asset contract (choices are not shown yet).

Asset template (Asset.daml)

Asset Holder Contracts

In Tutorial 7 a role contract is created for each party by an issuer. We can consider the existence of such contracts as a status of a party, who is an authorized holder of assets issued by an issuer. They are implemented as AssetHolder contracts.

AssetHolder template (Asset/Role.daml)
AssetHolderInvite template (Asset/Role.daml)

Asset Contract Creation

As mentioned before, Asset contract requires both issuer and owner as signatory. We see how it can be created through the propose-accept model in Tutorial 6. Here we place the creation of Asset contract as a choice under AssetHolder contract. As AssetHolder bears both issuer and owner as signatory, the newly created Asset contract also obtains authorization from both issuer and owner.

Issuer creates Asset contract through exercising in AssetHolder contract.
Choice Issue_Asset in AssetHolder template (Asset/Role.daml)

Fungibility of Asset

Overview

Asset fungibility means that each unit of an asset is indistinguishable from other units. In real life banknotes are fungible, as this one-dollar banknote is of no difference from another one-dollar banknote, as both bear the same value. Real estate is non-fungible assets, as this house is different from another house.

Split

Choice Split in Asset template (Asset.daml)

Merge

Now the Merge choice.

Choice Merge in Asset template (Asset.daml)

Asset Transfer

If you have walked through Tutorial 6, you probably see how the transfer of assets is implemented in the propose-accept model. Tutorial 7 follows this model and involves AssetHolder contracts.

Proposal Stage

The sender, the asset owner, exercises the choice ProposeTransfer in Asset contract template.

Choice ProposeTransfer in Asset template (Asset.daml)
TransferProposal template (Asset.daml)

Acceptance Stage

For acceptance, we see that both asset.issuer and newOwner authority needed to exercise the choice TransferProposal_Accept. As a result, the receiver cannot exercise this choice directly, as the authorization asset.issuer is missing.

Choice Accept_Transfer in AssetHolder contract (Asset/Role.daml)
TransferProposal template (Asset.daml)

Test Script

We saw the error above. Here we simulate the correct one in test5, We first create Bob’s AssetHolder contract (line 76–82). Then let Bob accept the proposal by exercising Accept_Transfer choice in his AssetHolder contract (line 93–95).

Summary

We have walked through quite a large portion of the code for Tutorial 7. We saw how asset is created through asset holder contracts and how fungible asset is being split and merged. With the help of asset holder contracts we also observed how assets are transferred.

Visit http://www.ledgertech.biz/kcarticles.html for all my works. Reach me on https://www.linkedin.com/in/ktam1/ or follow me @kctheservant in Twitter.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store