DAML Smart Contracts
DAML is the smart contract language of the Canton Network, created by Digital Asset. It is a type-safe, functional language purpose-built for modeling multi-party financial workflows. Dualis Finance uses DAML SDK 3.4.11 targeting Ledger Format 2.1, with 38 contract templates across 25 modules.
What Is DAML
DAML (Digital Asset Modeling Language) is a high-level, Haskell-derived language for writing smart contracts that execute on the Canton Network. Unlike Solidity, which operates on a shared global state machine, DAML models workflows as contracts between identified parties. Each contract has explicit signatories (parties who must authorize its creation) and observers (parties who can see it). This model maps directly to how real financial agreements work.
DAML contracts are compiled to Ledger Format (LF), a platform-independent intermediate representation that runs on any DAML-compatible ledger. Dualis targets LF 2.1, the current standard for Canton's production runtime.
Why DAML
The choice of DAML over Solidity, Move, or Rust-based smart contract languages is driven by several technical and structural advantages:
- Formal type system: DAML's Haskell-derived type system catches errors at compile time. There is no
null, no implicit type coercion, and no unchecked arithmetic overflow. - Signatory/observer model: Every contract explicitly declares who must authorize it and who can see it. No contract can move assets without the owner's explicit consent, eliminating unauthorized transfer vulnerabilities.
- No reentrancy: DAML's execution model is fundamentally different from the EVM. Choices (the DAML equivalent of function calls) execute atomically within a transaction. There is no external call pattern that enables reentrancy attacks.
- Built-in privacy: The signatory/observer model integrates directly with Canton's sub-transaction privacy. Contract visibility is enforced at the protocol level, not bolted on after the fact.
- Deterministic execution: DAML contracts produce the same result regardless of which participant executes them, enabling Canton's consensus model.
Dualis DAML Modules
The Dualis smart contract suite comprises 25 modules organized into logical domains. Together they define 38 contract templates that encode the full protocol lifecycle.
| Domain | Module | Purpose |
|---|---|---|
| Core | Dualis.Types | Shared type definitions: CreditTier, InterestRateModel, CollateralParams, AccrualState |
Dualis.Core.Config | Protocol-wide configuration contract | |
| Lending | Dualis.Lending.Pool | LendingPool and SupplyPosition templates with index-based accrual |
Dualis.Lending.Borrow | BorrowPosition lifecycle: open, repay, accrue | |
Dualis.Lending.Collateral | Collateral deposit, withdrawal, and valuation | |
Dualis.Lending.Math | On-chain interest rate calculations using Taylor series approximation | |
| Credit | Dualis.Credit.Attestation | Credit attestation issuance and verification |
Dualis.Credit.CompositeScore | Composite credit scoring from multiple data sources | |
| Liquidation | Dualis.Liquidation.Engine | Four-tier liquidation cascade and incentive distribution |
| Oracle | Dualis.Oracle.PriceFeed | Multi-source price feed aggregation with staleness checks |
| Governance | Dualis.Governance.Config | Governance parameter configuration |
Dualis.Governance.Proposal | Proposal creation, voting period, and execution | |
Dualis.Governance.Vote | Vote casting and tally computation | |
Dualis.Governance.Delegation | Vote delegation and power transfer | |
Dualis.Governance.Timelock | Time-locked execution of approved proposals | |
Dualis.Governance.Token | DUAL governance token contract | |
| Token | Dualis.Token.DUAL | DUAL token minting, transfer, and burn |
| Institutional | Dualis.Institutional.Core | Institutional onboarding and securities lending workflows |
| SecLending | Dualis.SecLending.Advanced | Advanced securities lending with netting and recall |
| Privacy | Dualis.Privacy.Config | Privacy domain configuration and observer policies |
| Productive | Dualis.Productive.Core | Productive collateral and yield-bearing position management |
| Triggers | Dualis.Trigger.InterestAccrual | Automated interest accrual trigger |
Dualis.Trigger.LiquidationScanner | Continuous health factor monitoring and liquidation initiation | |
Dualis.Trigger.OracleAggregator | Oracle price feed aggregation and update trigger | |
Dualis.Trigger.StalenessChecker | Price feed staleness detection and circuit breaker |
Code Example
The following excerpt from Dualis.Lending.Pool shows the core structure of a DAML contract template. Note the explicit signatory declaration and the typed choice that exercises interest accrual:
template LendingPool
with
operator : Party
poolId : PoolId
asset : AssetInfo
rateModel : InterestRateModel
totalSupply : Decimal
totalBorrow : Decimal
totalReserves : Decimal
accrual : AccrualState
isActive : Bool
where
signatory operator
choice AccrueInterest : ContractId LendingPool
with
currentTs : Int
controller operator
do
let result = accrueInterest
this.rateModel
this.totalBorrow
this.totalSupply
this.totalReserves
this.accrual.borrowIndex
this.accrual.supplyIndex
this.accrual.lastAccrualTs
currentTs
create this with
totalBorrow = result.newTotalBorrow
totalReserves = result.newReserves
accrual = result.newAccrualStateBuild and Test
The DAML contracts are built and tested using the Daml SDK CLI. From the canton package directory:
# Build the DAR (DAML Archive)
cd packages/canton/daml
~/.daml/bin/daml build
# Run all DAML test scripts
~/.daml/bin/daml test
# Output DAR location
# .daml/dist/dualis-finance-2.0.0.darThe build produces a DAR file containing all 25 modules. This archive is uploaded to the Canton participant node for deployment. The test suite includes 8 test modules covering pool operations, borrowing, liquidation, credit scoring, governance, oracle feeds, token operations, and configuration management.