NAC_Blockchain/nac-udm/src/dividend_ai/mod.rs

133 lines
3.4 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! # 收益AI自动触发系统
//!
//! 实现RWA资产的自动收益分配系统包括
//! - GNACS收益扩展编码解析
//! - AI收益计算引擎
//! - 宪法执行引擎验证
//! - 链上分配合约ACC-1594
//!
//! ## 核心流程
//! 1. 收益数据源层:预言机采集收益数据
//! 2. AI计算引擎解析GNACS、计算分配金额
//! 3. 宪法验证CEE验证合规性
//! 4. 链上分配:执行代币转账
pub mod gnacs_extension;
pub mod ai_engine;
pub mod oracle;
pub mod distribution;
pub mod constitutional_validation;
use crate::primitives::{Address, Hash, Timestamp};
use serde::{Deserialize, Serialize};
/// 分红策略类型
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DividendPolicy {
/// 无分红
None = 0,
/// 固定比例分红
FixedRate = 1,
/// 剩余收益分红
ResidualIncome = 2,
/// 优先/普通股分层分红
PreferredCommon = 3,
/// 业绩提成分红
PerformanceFee = 4,
}
impl From<u8> for DividendPolicy {
fn from(value: u8) -> Self {
match value {
0 => DividendPolicy::None,
1 => DividendPolicy::FixedRate,
2 => DividendPolicy::ResidualIncome,
3 => DividendPolicy::PreferredCommon,
4 => DividendPolicy::PerformanceFee,
_ => DividendPolicy::None,
}
}
}
/// 分红周期类型
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DividendPeriod {
/// 无固定周期
None = 0,
/// 月度
Monthly = 1,
/// 季度
Quarterly = 2,
/// 半年度
SemiAnnual = 3,
/// 年度
Annual = 4,
/// 不定期
Irregular = 5,
}
impl From<u8> for DividendPeriod {
fn from(value: u8) -> Self {
match value {
0 => DividendPeriod::None,
1 => DividendPeriod::Monthly,
2 => DividendPeriod::Quarterly,
3 => DividendPeriod::SemiAnnual,
4 => DividendPeriod::Annual,
5 => DividendPeriod::Irregular,
_ => DividendPeriod::None,
}
}
}
/// 收益分配结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DividendDistribution {
/// 资产ID
pub asset_id: Hash,
/// 分配周期
pub period: String,
/// 总分配金额XTZH
pub total_amount: u128,
/// 每份收益
pub per_share: u128,
/// 持有者列表
pub holders: Vec<HolderShare>,
/// 分配时间戳
pub timestamp: Timestamp,
/// 宪法收据哈希
pub constitutional_receipt: Hash,
}
/// 持有者份额
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HolderShare {
/// 持有者地址
pub address: Address,
/// 持有份额
pub shares: u128,
/// 应得收益
pub dividend: u128,
/// 持有天数
pub holding_days: u32,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_dividend_policy_conversion() {
assert_eq!(DividendPolicy::from(0), DividendPolicy::None);
assert_eq!(DividendPolicy::from(1), DividendPolicy::FixedRate);
assert_eq!(DividendPolicy::from(3), DividendPolicy::PreferredCommon);
}
#[test]
fn test_dividend_period_conversion() {
assert_eq!(DividendPeriod::from(1), DividendPeriod::Monthly);
assert_eq!(DividendPeriod::from(2), DividendPeriod::Quarterly);
assert_eq!(DividendPeriod::from(4), DividendPeriod::Annual);
}
}