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.
No Contract Keys in LF 2.x
Dualis targets Ledger Format 2.1, which does not support contract keys or maintainers. All contract lookups use contract IDs rather than key-based queries. This is a deliberate design change in the Canton runtime to improve performance and simplify the privacy 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.

DomainModulePurpose
CoreDualis.TypesShared type definitions: CreditTier, InterestRateModel, CollateralParams, AccrualState
Dualis.Core.ConfigProtocol-wide configuration contract
LendingDualis.Lending.PoolLendingPool and SupplyPosition templates with index-based accrual
Dualis.Lending.BorrowBorrowPosition lifecycle: open, repay, accrue
Dualis.Lending.CollateralCollateral deposit, withdrawal, and valuation
Dualis.Lending.MathOn-chain interest rate calculations using Taylor series approximation
CreditDualis.Credit.AttestationCredit attestation issuance and verification
Dualis.Credit.CompositeScoreComposite credit scoring from multiple data sources
LiquidationDualis.Liquidation.EngineFour-tier liquidation cascade and incentive distribution
OracleDualis.Oracle.PriceFeedMulti-source price feed aggregation with staleness checks
GovernanceDualis.Governance.ConfigGovernance parameter configuration
Dualis.Governance.ProposalProposal creation, voting period, and execution
Dualis.Governance.VoteVote casting and tally computation
Dualis.Governance.DelegationVote delegation and power transfer
Dualis.Governance.TimelockTime-locked execution of approved proposals
Dualis.Governance.TokenDUAL governance token contract
TokenDualis.Token.DUALDUAL token minting, transfer, and burn
InstitutionalDualis.Institutional.CoreInstitutional onboarding and securities lending workflows
SecLendingDualis.SecLending.AdvancedAdvanced securities lending with netting and recall
PrivacyDualis.Privacy.ConfigPrivacy domain configuration and observer policies
ProductiveDualis.Productive.CoreProductive collateral and yield-bearing position management
TriggersDualis.Trigger.InterestAccrualAutomated interest accrual trigger
Dualis.Trigger.LiquidationScannerContinuous health factor monitoring and liquidation initiation
Dualis.Trigger.OracleAggregatorOracle price feed aggregation and update trigger
Dualis.Trigger.StalenessCheckerPrice 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:

Dualis/Lending/Pool.daml
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.newAccrualState

Build and Test

The DAML contracts are built and tested using the Daml SDK CLI. From the canton package directory:

Terminal
# 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.dar

The 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.