Skip to content

d-agent/dagent-contract-cardano

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 DAgent Contract- Cardano

Decentralized Agent Registration & Staking Platform

License Aiken Plutus Cardano

Smart contracts for decentralized agent registration and staking on the Cardano blockchain


πŸ“‹ Table of Contents


🌟 Overview

DAgent Contractor is a decentralized platform built on Cardano that enables secure agent registration and stake management. Written in Aiken, these smart contracts provide a robust foundation for managing agent relationships and token staking with full on-chain validation.

Why DAgent?

  • βœ… Trustless Operations: All transactions validated on-chain
  • βœ… Flexible Staking: Support for multiple stake operations (create, transfer, pull)
  • βœ… Agent Registry: Decentralized agent registration and management
  • βœ… Plutus V3: Built with the latest Cardano smart contract platform
  • βœ… Type Safety: Written in Aiken for compile-time guarantees

✨ Features

πŸ” Staking System

  • Create Stakes: Add new stakes linking clients to providers
  • Transfer Stakes: Move stakes between users atomically
  • Pull Stakes: Withdraw specific amounts from stake positions
  • Batch Operations: Pull all stakes for a user in one transaction
  • Real-time Tracking: Automatic total stake and count calculations
  • State Validation: Built-in invariant checking for data integrity

πŸ‘₯ Agent Registration

  • Decentralized Registry: On-chain agent registration
  • Immutable Records: Tamper-proof agent information storage
  • Query Support: Retrieve agent details and stakes on-chain

πŸ—οΈ Architecture

dagent-contractor-cardano/
β”œβ”€β”€ validators/           # Smart contract validators
β”‚   β”œβ”€β”€ stake/           # Staking contract
β”‚   β”‚   β”œβ”€β”€ stake.ak     # Main stake validator
β”‚   β”‚   └── stake_test.ak # Test suite
β”‚   └── agents/          # Agent registration
β”‚       └── agents.ak    # Agent validator
β”œβ”€β”€ lib/                 # Supporting libraries
β”‚   └── stake/
β”‚       β”œβ”€β”€ types.ak     # Data type definitions
β”‚       β”œβ”€β”€ transition.ak # State transition logic
β”‚       └── check.ak     # Validation helpers
└── build/               # Compiled artifacts

Contract Overview

Stake Contract (validators/stake/stake.ak)

The staking contract manages stake relationships between clients and providers:

pub type Stake {
  client: ByteArray,      // Client address
  provider: ByteArray,    // Provider address
  amount: Int,            // Staked amount
  user_id: ByteArray,     // Unique user identifier
}

Supported Actions:

  • CreateStake - Add new stake entry
  • TransferStake - Move stake between users
  • PullStake - Withdraw partial stake
  • PullAllStake - Withdraw all user stakes
  • GetAddressStake - Query stake by address
  • GetTotalStake - Get total staked amount
  • GetTotalStakeCount - Get total stake count

πŸš€ Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/d-agent/dagent-contract-cardano.git
    cd dagent-contract-cardano
  2. Build the contracts

    aiken build
  3. Verify installation

    aiken check

πŸ“– Contract Specifications

Stake Datum Structure

pub type StakeDatum {
  stakes: List<Stake>,     // All stake records
  total_stake: Int,        // Sum of all stakes
  total_count: Int,        // Number of stakes
}

State Transitions

All state transitions enforce invariants:

  • Amounts must be positive
  • Total stake must equal sum of individual stakes
  • Total count must match list length
  • Stakes cannot be duplicated

Example Usage

Creating a Stake:

CreateStake {
  client: "addr_client...",
  provider: "addr_provider...",
  amount: 1000000,  // 1 ADA (in lovelace)
  user_id: "user_123"
}

Transferring Stakes:

TransferStake {
  from_user_id: "user_123",
  to_user_id: "user_456",
  amount: 500000  // 0.5 ADA
}

πŸ’» Development

Project Structure

Write validators in the validators/ folder and supporting functions in the lib/ folder using .ak as a file extension.

Configuration

Edit aiken.toml for network configuration:

[config.default]
network_id = 41  # Testnet: 41, Mainnet: 1

Building

Compile all contracts:

aiken build

Build artifacts will be generated in the build/ directory.


πŸ§ͺ Testing

Running Tests

Execute all test suites:

aiken check

Run specific test modules:

aiken check -m stake

Run tests matching a pattern:

aiken check -m transfer

Writing Tests

Tests are written inline using the test keyword:

use stake/transition

test create_stake_increases_count() {
  let initial = StakeDatum { stakes: [], total_stake: 0, total_count: 0 }
  let result = transition.create_stake(
    initial,
    CreateStake { client: "c1", provider: "p1", amount: 100, user_id: "u1" }
  )
  result.total_count == 1
}

🚒 Deployment

Generate Documentation

Create HTML documentation for the contracts:

aiken docs

Blueprint Generation

After building, contract blueprints are available in:

build/packages/dagent-dagent-contractor-cardano/

Network Deployment

  1. Build for target network (configure aiken.toml)
  2. Generate blueprint with aiken build
  3. Submit using Cardano CLI or transaction builder
  4. Reference contract hash in transactions

🀝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Write tests for your changes
  4. Ensure all tests pass (aiken check)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Code Standards

  • Follow Aiken style guidelines
  • Add tests for new functionality
  • Document public functions
  • Keep validators focused and minimal

πŸ“š Resources


Built with ❀️ using Aiken on Cardano

Report Bug Β· Request Feature

About

cardano blockchain contract for agents and payment

Topics

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •