Skip to content

0xsereel/starknet-cmtat

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cairo CMTAT - Regulated Securities on Starknet

A comprehensive implementation of CMTAT (Capital Markets and Technology Association Token) standard in Cairo for Starknet, featuring full ABI compatibility with Solidity CMTAT implementation.

🎯 Features

  • βœ… 100% Solidity ABI Compatible - Exact function signatures matching Solidity CMTAT
  • βœ… Four Module Variants - Light, Allowlist, Debt, and Standard implementations
  • βœ… ERC20 Compliance with regulatory extensions
  • βœ… Role-Based Access Control with role getter functions
  • βœ… Batch Operations for efficient multi-address operations
  • βœ… Cross-Chain Support (Standard module)
  • βœ… Transfer Validation (ERC-1404 compatible)
  • βœ… Meta-Transaction Support (Allowlist & Standard modules)
  • βœ… OpenZeppelin Components for security and reliability

πŸš€ Quick Start

Prerequisites

# Install Scarb (Cairo package manager)
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh

# Install Starkli (Starknet CLI)
curl https://get.starkli.sh | sh
starkliup

Build & Test

# Build all contracts
scarb build

# Run tests
scarb test

Deploy

# Deploy complete ecosystem
./scripts/deploy.sh

πŸ“‹ Module Overview

πŸͺΆ Light CMTAT

Minimal feature set for basic CMTAT compliance

Constructor:

constructor(
    admin: ContractAddress,
    name: ByteArray,
    symbol: ByteArray,
    initial_supply: u256,
    recipient: ContractAddress
)

Features:

  • βœ… Basic ERC20 functionality
  • βœ… Minting (mint, batch_mint)
  • βœ… Burning (burn, burn_from, batch_burn, forced_burn, burn_and_mint)
  • βœ… Pause/Unpause/Deactivate
  • βœ… Address freezing (set_address_frozen, batch_set_address_frozen)
  • βœ… Information management (terms, information, token_id)
  • βœ… Batch balance queries
  • βœ… 4 Role constants (DEFAULT_ADMIN, MINTER, PAUSER, ENFORCER)

Use Cases: Standard token deployments, simple compliance requirements


βœ… Allowlist CMTAT

All Light features plus allowlist functionality

Constructor:

constructor(
    forwarder_irrevocable: ContractAddress,  // For meta-transactions
    admin: ContractAddress,
    name: ByteArray,
    symbol: ByteArray,
    initial_supply: u256,
    recipient: ContractAddress
)

Additional Features:

  • βœ… Allowlist control (enable_allowlist, set_address_allowlist, batch_set_address_allowlist)
  • βœ… Partial token freezing (freeze_partial_tokens, unfreeze_partial_tokens)
  • βœ… Active balance queries (get_active_balance_of)
  • βœ… Engine management (snapshot_engine, document_engine)
  • βœ… Meta-transaction support (is_trusted_forwarder)
  • βœ… 9 Role constants (includes ERC20ENFORCER, SNAPSHOOTER, DOCUMENT, EXTRA_INFORMATION)

Use Cases: Regulated tokens with whitelist requirements, KYC/AML compliance


πŸ’° Debt CMTAT

Specialized for debt securities

Constructor:

constructor(
    admin: ContractAddress,
    name: ByteArray,
    symbol: ByteArray,
    initial_supply: u256,
    recipient: ContractAddress
)

Debt-Specific Features:

  • βœ… Debt information management (debt, set_debt)
  • βœ… Credit events tracking (credit_events, set_credit_events)
  • βœ… Debt engine integration (debt_engine, set_debt_engine)
  • βœ… Default flagging (flag_default)
  • βœ… All Allowlist features (except allowlist-specific)
  • βœ… 10 Role constants (includes DEBT_ROLE)

Use Cases: Corporate bonds, structured debt products, fixed income securities


⭐ Standard CMTAT

Full feature set with cross-chain support

Constructor:

constructor(
    forwarder_irrevocable: ContractAddress,  // For meta-transactions
    admin: ContractAddress,
    name: ByteArray,
    symbol: ByteArray,
    initial_supply: u256,
    recipient: ContractAddress
)

Advanced Features:

  • βœ… Cross-chain operations (crosschain_mint, crosschain_burn)
  • βœ… Transfer validation (restriction_code, message_for_transfer_restriction)
  • βœ… ERC-1404 compliance
  • βœ… All core CMTAT features
  • βœ… 10 Role constants (includes CROSS_CHAIN_ROLE)

Use Cases: Multi-chain deployments, advanced compliance, institutional securities


πŸ”§ ABI Compatibility

All modules are 100% compatible with the Solidity CMTAT ABI specification:

Common Functions (All Modules)

Information Management:

fn terms(self: @ContractState) -> ByteArray
fn set_terms(ref self: ContractState, new_terms: ByteArray) -> bool
fn information(self: @ContractState) -> ByteArray
fn set_information(ref self: ContractState, new_information: ByteArray) -> bool
fn token_id(self: @ContractState) -> ByteArray
fn set_token_id(ref self: ContractState, new_token_id: ByteArray) -> bool

Batch Operations:

fn batch_balance_of(self: @ContractState, accounts: Span<ContractAddress>) -> Array<u256>
fn batch_mint(ref self: ContractState, tos: Span<ContractAddress>, values: Span<u256>) -> bool
fn batch_burn(ref self: ContractState, accounts: Span<ContractAddress>, values: Span<u256>) -> bool

Role Getters:

fn get_default_admin_role(self: @ContractState) -> felt252
fn get_minter_role(self: @ContractState) -> felt252
fn get_pauser_role(self: @ContractState) -> felt252
// ... all role getters

Minting & Burning:

fn mint(ref self: ContractState, to: ContractAddress, value: u256) -> bool
fn burn(ref self: ContractState, value: u256) -> bool
fn burn_from(ref self: ContractState, from: ContractAddress, value: u256) -> bool
fn burn_and_mint(ref self: ContractState, from: ContractAddress, to: ContractAddress, value: u256) -> bool

Pause & Freeze:

fn paused(self: @ContractState) -> bool
fn pause(ref self: ContractState) -> bool
fn unpause(ref self: ContractState) -> bool
fn deactivated(self: @ContractState) -> bool
fn deactivate_contract(ref self: ContractState) -> bool
fn set_address_frozen(ref self: ContractState, account: ContractAddress, is_frozen: bool) -> bool
fn batch_set_address_frozen(ref self: ContractState, accounts: Span<ContractAddress>, frozen: Span<bool>) -> bool
fn is_frozen(self: @ContractState, account: ContractAddress) -> bool

Module-Specific Functions

Allowlist Module:

fn enable_allowlist(ref self: ContractState, status: bool) -> bool
fn is_allowlist_enabled(self: @ContractState) -> bool
fn set_address_allowlist(ref self: ContractState, account: ContractAddress, status: bool) -> bool
fn batch_set_address_allowlist(ref self: ContractState, accounts: Span<ContractAddress>, statuses: Span<bool>) -> bool
fn is_allowlisted(self: @ContractState, account: ContractAddress) -> bool

Debt Module:

fn debt(self: @ContractState) -> ByteArray
fn set_debt(ref self: ContractState, debt_: ByteArray) -> bool
fn credit_events(self: @ContractState) -> ByteArray
fn set_credit_events(ref self: ContractState, credit_events_: ByteArray) -> bool
fn debt_engine(self: @ContractState) -> ContractAddress
fn set_debt_engine(ref self: ContractState, debt_engine_: ContractAddress) -> bool
fn flag_default(ref self: ContractState) -> bool

Standard Module:

fn crosschain_mint(ref self: ContractState, to: ContractAddress, value: u256) -> bool
fn crosschain_burn(ref self: ContractState, from: ContractAddress, value: u256) -> bool
fn restriction_code(self: @ContractState, from: ContractAddress, to: ContractAddress, value: u256) -> u8
fn message_for_transfer_restriction(self: @ContractState, restriction_code: u8) -> ByteArray

πŸ“Š Feature Comparison Matrix

Feature Light Allowlist Debt Standard
Basic ERC20 βœ… βœ… βœ… βœ…
Minting βœ… βœ… βœ… βœ…
Burning βœ… βœ… βœ… βœ…
Forced Burn βœ… ❌ ❌ ❌
Pause/Unpause βœ… βœ… βœ… βœ…
Deactivation βœ… βœ… βœ… βœ…
Address Freezing βœ… βœ… βœ… βœ…
Partial Token Freezing ❌ βœ… βœ… βœ…
Batch Operations βœ… βœ… βœ… βœ…
Information Management βœ… βœ… βœ… βœ…
Allowlist ❌ βœ… ❌ ❌
Debt Management ❌ ❌ βœ… ❌
Cross-Chain ❌ ❌ ❌ βœ…
Transfer Validation ❌ ❌ ❌ βœ…
Meta-Transactions ❌ βœ… ❌ βœ…
Engine Integration ❌ βœ… βœ… βœ…
Role Count 4 9 10 10

πŸ—οΈ Architecture

cairo-cmtat/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ contracts/
β”‚   β”‚   β”œβ”€β”€ light_cmtat.cairo       # Minimal CMTAT (4 roles)
β”‚   β”‚   β”œβ”€β”€ allowlist_cmtat.cairo   # With allowlist (9 roles)
β”‚   β”‚   β”œβ”€β”€ debt_cmtat.cairo        # For debt securities (10 roles)
β”‚   β”‚   └── standard_cmtat.cairo    # Full feature set (10 roles)
β”‚   β”œβ”€β”€ engines/
β”‚   β”‚   β”œβ”€β”€ rule_engine.cairo       # Transfer restrictions
β”‚   β”‚   └── snapshot_engine.cairo   # Balance snapshots
β”‚   └── interfaces/
β”‚       └── icmtat.cairo            # Interface definitions
β”œβ”€β”€ tests/
β”‚   └── cmtat_tests.cairo           # Comprehensive tests
└── scripts/
    └── deploy.sh                    # Deployment automation

πŸ’Ό Use Cases & Examples

Regulatory Compliant Token

// Deploy Allowlist CMTAT for KYC/AML compliance
let allowlist_cmtat = deploy_allowlist_cmtat(
    forwarder,
    admin,
    "Regulated Security Token",
    "RST",
    1000000 * 10^18,
    treasury
);

// Enable allowlist
allowlist_cmtat.enable_allowlist(true);

// Add approved addresses
let kyc_addresses = array![addr1, addr2, addr3];
let statuses = array![true, true, true];
allowlist_cmtat.batch_set_address_allowlist(kyc_addresses, statuses);

Corporate Bond Token

// Deploy Debt CMTAT for bond issuance
let bond_token = deploy_debt_cmtat(
    admin,
    "Corporate Bond 2025",
    "BOND25",
    10000000 * 10^18,
    issuer
);

// Set debt information
bond_token.set_debt("5% Senior Notes due 2025");
bond_token.set_credit_events("Investment Grade BBB+");

// Integrate debt calculation engine
bond_token.set_debt_engine(debt_calculation_engine);

Multi-Chain Security Token

// Deploy Standard CMTAT with cross-chain support
let standard_cmtat = deploy_standard_cmtat(
    forwarder,
    admin,
    "Global Security Token",
    "GST",
    5000000 * 10^18,
    treasury
);

// Enable cross-chain operations
standard_cmtat.grant_role(CROSS_CHAIN_ROLE, bridge_operator);

// Bridge tokens to another chain
standard_cmtat.crosschain_burn(user, 1000 * 10^18);

πŸ” Security Features

Role-Based Access Control

  • DEFAULT_ADMIN_ROLE: Master administrator, can grant/revoke all roles
  • MINTER_ROLE: Can create new tokens
  • BURNER_ROLE: Can destroy tokens
  • PAUSER_ROLE: Can pause/unpause contract
  • ENFORCER_ROLE: Can freeze/unfreeze addresses
  • ERC20ENFORCER_ROLE: Can freeze partial tokens
  • SNAPSHOOTER_ROLE: Can create snapshots
  • DOCUMENT_ROLE: Can manage documents
  • EXTRA_INFORMATION_ROLE: Can update token metadata
  • DEBT_ROLE: Can manage debt parameters
  • CROSS_CHAIN_ROLE: Can execute cross-chain operations

Transfer Restrictions

All modules implement transfer restrictions via ERC20 hooks:

  • Pause state check
  • Sender/recipient freeze check
  • Active balance validation (for partial freezing)
  • Custom validation (via transfer validation in Standard)

πŸ“ Deployment Guide

Step 1: Build Contracts

scarb build

Step 2: Configure Environment

cp .env.example .env
# Edit .env with your configuration

Step 3: Deploy

./scripts/deploy.sh

The script will:

  1. Deploy all four CMTAT modules
  2. Set up proper role assignments
  3. Configure engine integrations
  4. Output all contract addresses

πŸ§ͺ Testing

# Run all tests
scarb test

# Run specific test
scarb test test_name

# Run with verbose output
scarb test --verbose

πŸ“š Documentation

Technical Specifications

API Reference

Full API documentation for all modules available in-code documentation.


πŸ› οΈ Development

Prerequisites

  • Cairo 2.6.3+
  • Scarb 2.6.4+
  • OpenZeppelin Cairo 0.13.0

Project Structure

src/contracts/     # Token implementations
src/engines/       # Compliance engines
src/interfaces/    # Contract interfaces
tests/            # Test suite
scripts/          # Deployment scripts

🀝 Contributing

Contributions are welcome! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

πŸ“œ License

Mozilla Public License 2.0 (MPL-2.0)


πŸ”— Links


Built for compliant securities on Starknet πŸš€

Version 2.0.0 - ABI Compatible Implementation

About

The Sereel Implementation of CMTAT including a factory for our api service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Cairo 79.2%
  • Shell 20.8%