| Crates.io | daa-economy |
| lib.rs | daa-economy |
| version | 0.2.1 |
| created_at | 2025-06-24 13:23:13.066116+00 |
| updated_at | 2025-06-25 13:49:25.52837+00 |
| description | Economic engine for DAA system with token management |
| homepage | https://github.com/ruvnet/daa |
| repository | https://github.com/ruvnet/daa |
| max_upload_size | |
| id | 1724295 |
| size | 164,235 |
π FULL IMPLEMENTATION - This is the complete, production-ready implementation of the DAA Economy module, not a placeholder.
Economic layer for the Decentralized Autonomous Agents (DAA) system, providing rUv token management, exchange operations, and economic incentives through QuDAG exchange integration.
DAA Economy manages the complete economic ecosystem for autonomous agents, including:
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β EconomySystem β β TokenManager β β ExchangeManager β
β β β β β β
β - Configuration βββββΊβ - rUv Tokens βββββΊβ - QuDAG Exchangeβ
β - Coordination β β - Balances β β - Order Book β
β - Statistics β β - Transactions β β - Trade History β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β AccountManager β β RewardSystem β β MarketManager β
β β β β β β
β - Agent Accountsβ β - Reward Calc β β - Market Data β
β - KYC/Status β β - Performance β β - Liquidity β
β - Metadata β β - Distribution β β - Price Oracle β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
use daa_economy::{EconomySystem, EconomyConfig};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create economy configuration
let config = EconomyConfig {
base_currency: CurrencyConfig {
symbol: "rUv".to_string(),
name: "Resource Units of value".to_string(),
initial_supply: Decimal::from(1_000_000_000),
max_supply: Some(Decimal::from(10_000_000_000)),
inflation_rate: Decimal::from(5) / Decimal::from(100),
..Default::default()
},
..Default::default()
};
// Initialize economy system
let mut economy = EconomySystem::new(config).await?;
economy.initialize().await?;
println!("DAA Economy System initialized");
Ok(())
}
// Create agent account
let account = economy.create_account("agent-123".to_string()).await?;
println!("Created account: {}", account.id);
// Check balance
let balance = economy.get_balance(&account.id).await?;
println!("Account balance: {} rUv", balance);
// Transfer tokens
let tx_id = economy.transfer(
&from_account,
&to_account,
Decimal::from(100), // 100 rUv
).await?;
println!("Transfer completed: {}", tx_id);
use daa_economy::rewards::RewardType;
// Distribute task completion reward
let reward_amount = economy.distribute_reward(
&account.id,
RewardType::TaskCompletion,
None, // No performance score
).await?;
// Distribute performance-based reward
let performance_reward = economy.distribute_reward(
&account.id,
RewardType::HighQualityWork,
Some(Decimal::from(95) / Decimal::from(100)), // 95% performance
).await?;
println!("Rewards distributed: {} rUv", reward_amount + performance_reward);
use qudag_exchange::OrderType;
// Place buy order
let order_id = economy.place_order(
&account.id,
OrderType::Buy,
"rUv".to_string(), // Base token
"ETH".to_string(), // Quote token
Decimal::from(1000), // Quantity
Decimal::from(100), // Price
).await?;
// Get market data
let market_data = economy.get_market_data("rUv", "ETH").await?;
println!("rUv/ETH Price: {}", market_data.last_price);
EconomyConfig {
base_currency: CurrencyConfig {
symbol: "rUv".to_string(),
name: "Resource Units of value".to_string(),
decimals: 18,
initial_supply: Decimal::from(1_000_000_000),
max_supply: Some(Decimal::from(10_000_000_000)),
inflation_rate: Decimal::from(5) / Decimal::from(100), // 5% per year
},
rewards: RewardConfig {
base_task_reward: Decimal::from(10), // 10 rUv per task
quality_multiplier: Decimal::from(2), // 2x for excellent work
failure_penalty: Decimal::from(5), // -5 rUv for failures
staking_rewards: Decimal::from(100), // 100 rUv per epoch
minimum_stake: Decimal::from(1000), // 1000 rUv minimum
},
fees: FeeConfig {
transaction_fee: Decimal::from(1) / Decimal::from(1000), // 0.1%
exchange_fee: Decimal::from(5) / Decimal::from(1000), // 0.5%
withdrawal_fee: Decimal::from(1), // 1 rUv
minimum_fee: Decimal::from(1) / Decimal::from(100), // 0.01 rUv
},
market_maker: MarketMakerConfig {
initial_liquidity: Decimal::from(100_000), // 100k rUv
spread: Decimal::from(1) / Decimal::from(100), // 1% spread
min_order_size: Decimal::from(1),
max_order_size: Decimal::from(10_000),
},
}
The crate supports several feature flags:
default: Includes exchange and tokens featuresexchange: Enables QuDAG exchange integrationtokens: Basic token management (always enabled)chain-integration: Enables blockchain transaction recordingdatabase: Adds persistent database storagefull: Includes all features[dependencies]
daa-economy = { version = "0.1.0", features = ["full"] }
#[cfg(feature = "chain-integration")]
use daa_economy::chain_bridge::ChainBridge;
// Record transactions on blockchain
let bridge = ChainBridge::new(chain_client).await?;
economy.set_chain_bridge(Some(bridge)).await?;
// Transfers will now be recorded on-chain
let tx_id = economy.transfer(&from, &to, amount).await?;
#[cfg(feature = "database")]
let config = EconomyConfig {
database_url: Some("sqlite://economy.db".to_string()),
..Default::default()
};
// All operations will be persisted to database
let mut economy = EconomySystem::new(config).await?;
economy.initialize().await?;
Main system coordinator managing all economic operations.
Key Methods:
new(config) - Create new economy systeminitialize() - Initialize all subsystemscreate_account(agent_id) - Create agent accounttransfer(from, to, amount) - Transfer tokensdistribute_reward(account, type, score) - Distribute rewardsplace_order(account, type, tokens, qty, price) - Place exchange orderget_statistics() - Get system statisticsManages rUv tokens and balances.
Key Methods:
mint(account, amount) - Create new tokensburn(account, amount) - Destroy tokenstransfer_token(from, to, token, amount, fee) - Transfer specific tokenlock_tokens(account, token, amount) - Lock tokens for staking/ordersget_balance(account) - Get account balanceIntegrates with QuDAG exchange for trading.
Key Methods:
place_order(account, type, base, quote, qty, price) - Place trading ordercancel_order(order_id) - Cancel existing orderget_order_book(base, quote) - Get current order bookRun the test suite:
# Basic tests
cargo test --package daa-economy
# All features
cargo test --package daa-economy --all-features
# Specific feature
cargo test --package daa-economy --features database
qudag-core: Core blockchain primitivesqudag-exchange: Exchange and trading functionalityrust_decimal: Precise decimal arithmetic for financial calculationschrono: Date and time handlingbigdecimal: Extended precision decimal numberssqlx: Database integration (with database feature)daa-chain: Blockchain integration (with chain-integration feature)MIT OR Apache-2.0