Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contracts/teachlink/src/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use crate::storage::{BRIDGE_METRICS, CHAIN_METRICS, DAILY_VOLUMES};
use crate::types::{BridgeMetrics, ChainMetrics};
use soroban_sdk::{Address, Bytes, Env, Map, Vec};

/// Metrics update interval (1 hour)
pub const METRICS_UPDATE_INTERVAL: u64 = 3_600;
/// Metrics update interval — re-exported from config for backward compatibility.
pub use crate::config::METRICS_UPDATE_INTERVAL;

/// Analytics Manager
pub struct AnalyticsManager;
Expand Down
14 changes: 6 additions & 8 deletions contracts/teachlink/src/atomic_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ use crate::storage::{ATOMIC_SWAPS, SWAP_COUNTER, SWAP_GUARD, SWAP_TIMELOCK_SEQ};
use crate::types::{AtomicSwap, SwapStatus};
use soroban_sdk::{symbol_short, vec, Address, Bytes, Env, IntoVal, Map, Vec};

/// Minimum timelock duration (1 hour)
pub const MIN_TIMELOCK: u64 = 3_600;

/// Maximum timelock duration (7 days)
pub const MAX_TIMELOCK: u64 = 604_800;

/// Hash length (32 bytes for SHA256)
pub const HASH_LENGTH: u32 = 32;
/// Minimum timelock duration — re-exported from config.
pub use crate::config::SWAP_MIN_TIMELOCK as MIN_TIMELOCK;
/// Maximum timelock duration — re-exported from config.
pub use crate::config::SWAP_MAX_TIMELOCK as MAX_TIMELOCK;
/// Required hash length — re-exported from config.
pub use crate::config::SWAP_HASH_LENGTH as HASH_LENGTH;

/// Atomic Swap Manager
pub struct AtomicSwapManager;
Expand Down
9 changes: 4 additions & 5 deletions contracts/teachlink/src/audit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ use crate::storage::{AUDIT_COUNTER, AUDIT_RECORDS, COMPLIANCE_REPORTS};
use crate::types::{AuditRecord, ComplianceReport, OperationType};
use soroban_sdk::{Address, Bytes, Env, Map, Vec};

/// Maximum audit records to store
pub const MAX_AUDIT_RECORDS: u64 = 100_000;

/// Compliance report period (7 days)
pub const COMPLIANCE_PERIOD: u64 = 604_800;
/// Maximum audit records to store — re-exported from config.
pub use crate::config::AUDIT_MAX_RECORDS as MAX_AUDIT_RECORDS;
/// Compliance report period — re-exported from config.
pub use crate::config::AUDIT_COMPLIANCE_PERIOD as COMPLIANCE_PERIOD;

/// Audit Manager
pub struct AuditManager;
Expand Down
184 changes: 184 additions & 0 deletions contracts/teachlink/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
//! Centralized configuration for the TeachLink contract.
//!
//! All tunable constants live here. Modules import from this file instead of
//! defining their own `pub const` values, ensuring a single source of truth.
//!
//! # Sections
//! - [Analytics](#analytics)
//! - [Atomic Swaps](#atomic-swaps)
//! - [Audit & Compliance](#audit--compliance)
//! - [BFT Consensus](#bft-consensus)
//! - [Emergency & Circuit Breaker](#emergency--circuit-breaker)
//! - [Ledger Time](#ledger-time)
//! - [Liquidity & Fees](#liquidity--fees)
//! - [Message Passing](#message-passing)
//! - [Multichain](#multichain)
//! - [Network Recovery](#network-recovery)
//! - [Notifications](#notifications)
//! - [Performance Cache](#performance-cache)
//! - [Rate Limiting](#rate-limiting)
//! - [Slashing](#slashing)
//! - [Sustainability](#sustainability)
//! - [Upgrade](#upgrade)

// ===== Analytics =====

/// How often bridge metrics may be updated (seconds). Default: 1 hour.
pub const METRICS_UPDATE_INTERVAL: u64 = 3_600;

// ===== Atomic Swaps =====

/// Minimum timelock duration for an atomic swap (seconds). Default: 1 hour.
pub const SWAP_MIN_TIMELOCK: u64 = 3_600;

/// Maximum timelock duration for an atomic swap (seconds). Default: 7 days.
pub const SWAP_MAX_TIMELOCK: u64 = 604_800;

/// Required byte length of a hashlock preimage hash.
pub const SWAP_HASH_LENGTH: u32 = 32;

// ===== Audit & Compliance =====

/// Maximum number of audit records retained before circular-buffer wrap.
pub const AUDIT_MAX_RECORDS: u64 = 100_000;

/// Default compliance report period (seconds). Default: 7 days.
pub const AUDIT_COMPLIANCE_PERIOD: u64 = 604_800;

// ===== BFT Consensus =====

/// Minimum validator stake (stroops, 6-decimal). Default: 100 tokens.
pub const BFT_MIN_VALIDATOR_STAKE: i128 = 100_000_000;

/// Proposal expiry window (seconds). Default: 24 hours.
pub const BFT_PROPOSAL_TIMEOUT: u64 = 86_400;

/// Number of consensus rounds per validator rotation epoch.
pub const BFT_ROTATION_EPOCH_ROUNDS: u64 = 100;

/// Minimum reputation score for a validator to remain active (0-100).
pub const BFT_MIN_ACTIVE_REPUTATION: u32 = 40;

// ===== Emergency & Circuit Breaker =====

/// Number of seats on the security council.
pub const EMERGENCY_SECURITY_COUNCIL_SIZE: u32 = 5;

/// Daily volume tracking window (seconds). Default: 24 hours.
pub const EMERGENCY_DAILY_VOLUME_RESET: u64 = 86_400;

// ===== Ledger Time =====

/// Estimated seconds per Stellar ledger (used for lag calculations).
pub const LEDGER_EST_SECS: u64 = 5;

// ===== Liquidity & Fees =====

/// Base bridge fee in basis points. Default: 0.10%.
pub const LIQUIDITY_BASE_FEE_BPS: i128 = 10;

/// Maximum bridge fee in basis points. Default: 5%.
pub const LIQUIDITY_MAX_FEE_BPS: i128 = 500;

/// Minimum bridge fee in basis points. Default: 0.01%.
pub const LIQUIDITY_MIN_FEE_BPS: i128 = 1;

/// Pool utilization threshold (basis points) above which dynamic fees apply.
pub const LIQUIDITY_UTILIZATION_THRESHOLD: u32 = 8_000;

// ===== Message Passing =====

/// Default cross-chain packet timeout (seconds). Default: 24 hours.
pub const MSG_DEFAULT_PACKET_TIMEOUT: u64 = 86_400;

/// Maximum packet delivery retry attempts.
pub const MSG_MAX_RETRY_ATTEMPTS: u32 = 5;

/// Base delay between packet retries (seconds). Default: 5 minutes.
pub const MSG_RETRY_DELAY_BASE: u64 = 300;

// ===== Multichain =====

/// Maximum number of supported external chains.
pub const MULTICHAIN_MAX_CHAINS: u32 = 100;

/// Maximum number of registered multi-chain assets.
pub const MULTICHAIN_MAX_ASSETS: u32 = 1_000;

// ===== Network Recovery =====

/// Maximum automatic retry attempts for a failed operation.
pub const RECOVERY_MAX_RETRY_ATTEMPTS: u32 = 5;

/// Initial exponential-backoff delay (seconds). Default: 1 minute.
pub const RECOVERY_INITIAL_BACKOFF_SECS: u64 = 60;

/// Maximum backoff delay (seconds). Default: 1 hour.
pub const RECOVERY_MAX_BACKOFF_SECS: u64 = 3_600;

/// Backoff multiplier applied on each retry.
pub const RECOVERY_BACKOFF_MULTIPLIER: u64 = 2;

// ===== Notifications =====

/// Sentinel value indicating immediate (non-scheduled) delivery.
pub const NOTIF_IMMEDIATE_DELIVERY: u64 = 0;

/// Minimum scheduling delay for a notification (seconds). Default: 1 minute.
pub const NOTIF_MIN_DELAY_SECS: u64 = 60;

/// Maximum scheduling delay for a notification (seconds). Default: 30 days.
pub const NOTIF_MAX_DELAY_SECS: u64 = 86_400 * 30;

/// Maximum notifications processed per batch.
pub const NOTIF_BATCH_SIZE: u32 = 100;

/// Default TTL for notification event storage (seconds). Default: 7 days.
pub const NOTIF_DEFAULT_EVENT_TTL_SECS: u64 = 86_400 * 7;

// ===== Performance Cache =====

/// Bridge summary cache TTL (seconds). Default: 1 hour.
pub const PERF_CACHE_TTL_SECS: u64 = 3_600;

/// Maximum chains included in the cached top-by-volume list.
pub const PERF_MAX_TOP_CHAINS: u32 = 20;

// ===== Rate Limiting =====

/// Default maximum calls allowed per rate-limit window.
pub const RATE_LIMIT_DEFAULT_MAX_CALLS: u32 = 100;

/// Default rate-limit window size in ledgers.
pub const RATE_LIMIT_DEFAULT_WINDOW_LEDGERS: u32 = 600;

// ===== Slashing =====

/// Slash percentage for double-vote offence (basis points). Default: 50%.
pub const SLASH_DOUBLE_VOTE_BPS: u32 = 5_000;

/// Slash percentage for invalid-signature offence (basis points). Default: 10%.
pub const SLASH_INVALID_SIGNATURE_BPS: u32 = 1_000;

/// Slash percentage for inactivity offence (basis points). Default: 5%.
pub const SLASH_INACTIVITY_BPS: u32 = 500;

/// Slash percentage for byzantine behaviour (basis points). Default: 100%.
pub const SLASH_BYZANTINE_BPS: u32 = 10_000;

/// Slash percentage for malicious behaviour (basis points). Default: 100%.
pub const SLASH_MALICIOUS_BPS: u32 = 10_000;

// ===== Sustainability =====

/// Minimum content tokens minted to reach full content-creation score.
pub const SUSTAIN_CONTENT_SCORE_CAP: u64 = 1_000;

/// Minimum active users to reach full user-adoption score.
pub const SUSTAIN_USER_SCORE_CAP: u64 = 1_000;

// ===== Upgrade =====

/// Window within which a contract upgrade may be rolled back (seconds).
/// Default: 30 days.
pub const UPGRADE_ROLLBACK_WINDOW_SECS: u64 = 86_400 * 30;
9 changes: 4 additions & 5 deletions contracts/teachlink/src/emergency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use crate::storage::{CIRCUIT_BREAKERS, CIRCUIT_RESET_SEQ, EMERGENCY_STATE, PAUSE
use crate::types::{CircuitBreaker, EmergencyState};
use soroban_sdk::{Address, Bytes, Env, Map, Vec};

/// Authorized pausers (admin + security council)
pub const SECURITY_COUNCIL_SIZE: u32 = 5;

/// Daily volume reset period (24 hours)
pub const DAILY_VOLUME_RESET: u64 = 86_400;
/// Authorized pausers (admin + security council) — re-exported from config.
pub use crate::config::EMERGENCY_SECURITY_COUNCIL_SIZE as SECURITY_COUNCIL_SIZE;
/// Daily volume reset period — re-exported from config.
pub use crate::config::EMERGENCY_DAILY_VOLUME_RESET as DAILY_VOLUME_RESET;

/// Emergency Manager
pub struct EmergencyManager;
Expand Down
7 changes: 2 additions & 5 deletions contracts/teachlink/src/ledger_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@

use soroban_sdk::Env;

/// Conservative estimate of seconds per ledger close on Stellar.
///
/// Used only to derive a *fallback* ledger-sequence deadline when code is otherwise
/// timestamp-gated.
pub const EST_SECS_PER_LEDGER: u64 = 5;
/// Conservative estimate of seconds per ledger close on Stellar — re-exported from config.
pub use crate::config::LEDGER_EST_SECS as EST_SECS_PER_LEDGER;

pub fn seconds_to_ledger_delta(seconds: u64) -> u32 {
// Ceil division to avoid shortening timeouts.
Expand Down
19 changes: 8 additions & 11 deletions contracts/teachlink/src/liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ use crate::types::{BridgeFeeStructure, LPPosition, LiquidityPool};
use crate::validation::NumberValidator;
use soroban_sdk::{Address, Env, Map, Vec};

/// Base fee in basis points (0.1%)
pub const BASE_FEE_BPS: i128 = 10;

/// Maximum fee in basis points (5%)
pub const MAX_FEE_BPS: i128 = 500;

/// Minimum fee in basis points (0.01%)
pub const MIN_FEE_BPS: i128 = 1;

/// Liquidity utilization threshold for dynamic pricing (80%)
pub const UTILIZATION_THRESHOLD: u32 = 8000;
/// Base fee in basis points — re-exported from config.
pub use crate::config::LIQUIDITY_BASE_FEE_BPS as BASE_FEE_BPS;
/// Maximum fee in basis points — re-exported from config.
pub use crate::config::LIQUIDITY_MAX_FEE_BPS as MAX_FEE_BPS;
/// Minimum fee in basis points — re-exported from config.
pub use crate::config::LIQUIDITY_MIN_FEE_BPS as MIN_FEE_BPS;
/// Utilization threshold for dynamic pricing — re-exported from config.
pub use crate::config::LIQUIDITY_UTILIZATION_THRESHOLD as UTILIZATION_THRESHOLD;

/// Congestion multiplier steps
pub const CONGESTION_STEP_1: u32 = 5000; // 50% utilization
Expand Down
14 changes: 6 additions & 8 deletions contracts/teachlink/src/message_passing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ use crate::types::{CrossChainPacket, MessageReceipt, PacketStatus};
use crate::validation::NumberValidator;
use soroban_sdk::{Bytes, Env, Map, Vec};

/// Default packet timeout (24 hours)
pub const DEFAULT_PACKET_TIMEOUT: u64 = 86_400;

/// Maximum retry attempts
pub const MAX_RETRY_ATTEMPTS: u32 = 5;

/// Retry delay in seconds (exponential backoff)
pub const RETRY_DELAY_BASE: u64 = 300; // 5 minutes
/// Default packet timeout — re-exported from config.
pub use crate::config::MSG_DEFAULT_PACKET_TIMEOUT as DEFAULT_PACKET_TIMEOUT;
/// Maximum retry attempts — re-exported from config.
pub use crate::config::MSG_MAX_RETRY_ATTEMPTS as MAX_RETRY_ATTEMPTS;
/// Retry delay base — re-exported from config.
pub use crate::config::MSG_RETRY_DELAY_BASE as RETRY_DELAY_BASE;

/// Message Passing Manager
pub struct MessagePassing;
Expand Down
9 changes: 4 additions & 5 deletions contracts/teachlink/src/multichain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ use crate::types::{ChainAssetInfo, ChainConfig, MultiChainAsset};
use crate::validation::NumberValidator;
use soroban_sdk::{Address, Bytes, Env, Map, Vec};

/// Maximum number of supported chains
pub const MAX_SUPPORTED_CHAINS: u32 = 100;

/// Maximum number of multi-chain assets
pub const MAX_MULTI_CHAIN_ASSETS: u32 = 1000;
/// Maximum number of supported chains — re-exported from config.
pub use crate::config::MULTICHAIN_MAX_CHAINS as MAX_SUPPORTED_CHAINS;
/// Maximum number of multi-chain assets — re-exported from config.
pub use crate::config::MULTICHAIN_MAX_ASSETS as MAX_MULTI_CHAIN_ASSETS;

/// Multi-Chain Manager
pub struct MultiChainManager;
Expand Down
10 changes: 5 additions & 5 deletions contracts/teachlink/src/network_recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ pub const RECOVERY_STATE: Symbol = soroban_sdk::symbol_short!("rec_state");
pub const RECOVERY_NOTIFICATIONS: Symbol = soroban_sdk::symbol_short!("rec_notif");
pub const FALLBACK_ACTIVE: Symbol = soroban_sdk::symbol_short!("fb_active");

/// Retry configuration constants
pub const MAX_RETRY_ATTEMPTS: u32 = 5;
pub const INITIAL_BACKOFF_SECONDS: u64 = 60; // 1 minute
pub const MAX_BACKOFF_SECONDS: u64 = 3600; // 1 hour
pub const BACKOFF_MULTIPLIER: u64 = 2;
/// Retry configuration constants — re-exported from config.
pub use crate::config::RECOVERY_MAX_RETRY_ATTEMPTS as MAX_RETRY_ATTEMPTS;
pub use crate::config::RECOVERY_INITIAL_BACKOFF_SECS as INITIAL_BACKOFF_SECONDS;
pub use crate::config::RECOVERY_MAX_BACKOFF_SECS as MAX_BACKOFF_SECONDS;
pub use crate::config::RECOVERY_BACKOFF_MULTIPLIER as BACKOFF_MULTIPLIER;

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
Expand Down
15 changes: 7 additions & 8 deletions contracts/teachlink/src/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ use crate::types::{
};
use soroban_sdk::{contracttype, vec, Address, Bytes, Env, IntoVal, Map, String, Vec};

/// Notification delivery intervals (in seconds)
pub const IMMEDIATE_DELIVERY: u64 = 0;
pub const MIN_DELAY_SECONDS: u64 = 60; // 1 minute
pub const MAX_DELAY_SECONDS: u64 = 86400 * 30; // 30 days
pub const BATCH_SIZE: u32 = 100;

/// Event queue cleanup configuration
pub const DEFAULT_EVENT_TTL_SECONDS: u64 = 86400 * 7; // 7 days
/// Notification delivery intervals — re-exported from config.
pub use crate::config::NOTIF_IMMEDIATE_DELIVERY as IMMEDIATE_DELIVERY;
pub use crate::config::NOTIF_MIN_DELAY_SECS as MIN_DELAY_SECONDS;
pub use crate::config::NOTIF_MAX_DELAY_SECS as MAX_DELAY_SECONDS;
pub use crate::config::NOTIF_BATCH_SIZE as BATCH_SIZE;
/// Event queue cleanup configuration — re-exported from config.
pub use crate::config::NOTIF_DEFAULT_EVENT_TTL_SECS as DEFAULT_EVENT_TTL_SECONDS;
pub const DEFAULT_MAX_QUEUE_SIZE: u32 = 10000;
pub const CLEANUP_INTERVAL_SECONDS: u64 = 3600; // 1 hour

Expand Down
9 changes: 4 additions & 5 deletions contracts/teachlink/src/performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use crate::storage::{PERF_CACHE, PERF_TS};
use crate::types::CachedBridgeSummary;
use soroban_sdk::{Address, Env};

/// Cache TTL in ledger seconds (1 hour).
pub const CACHE_TTL_SECS: u64 = 3_600;

/// Max chains to include in cached top-by-volume (bounds gas).
pub const MAX_TOP_CHAINS: u32 = 20;
/// Cache TTL in ledger seconds — re-exported from config.
pub use crate::config::PERF_CACHE_TTL_SECS as CACHE_TTL_SECS;
/// Max chains to include in cached top-by-volume — re-exported from config.
pub use crate::config::PERF_MAX_TOP_CHAINS as MAX_TOP_CHAINS;

/// Performance cache manager.
pub struct PerformanceManager;
Expand Down
6 changes: 3 additions & 3 deletions contracts/teachlink/src/rate_limiting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ pub struct RateLimitState {
pub call_count: u32,
}

/// Default per-user limit: 100 calls per ~600 ledgers (~1 hour at 6 s/ledger).
pub const DEFAULT_MAX_CALLS: u32 = 100;
pub const DEFAULT_WINDOW_LEDGERS: u32 = 600;
/// Default per-user limit — re-exported from config.
pub use crate::config::RATE_LIMIT_DEFAULT_MAX_CALLS as DEFAULT_MAX_CALLS;
pub use crate::config::RATE_LIMIT_DEFAULT_WINDOW_LEDGERS as DEFAULT_WINDOW_LEDGERS;

pub struct RateLimiter;

Expand Down
Loading
Loading