//! Centralized constants for the Dew Finance contracts //! //! This module contains all magic numbers used throughout the codebase, //! organized by category for better maintainability and documentation. use near_sdk::Gas; // ============================================================================ // BASIS POINTS CONSTANTS // ============================================================================ /// Basis points divisor (10,000 = 100%) pub const BASIS_POINTS_DIVISOR: u128 = 10_000; /// Basis points divisor as u16 (10,000 = 100%) pub const BASIS_POINTS_DIVISOR_U16: u16 = 10_000; /// 100% in basis points pub const PERCENT_100_BPS: u16 = 10_000; // ============================================================================ // MICRO PERCENT CONSTANTS // ============================================================================ /// Nano percent divisor (100,000,000,000 = 100%) /// Used for higher precision measurements like price deviations pub const NANO_PERCENT_DIVISOR: u64 = 100_000_000_000; /// 100% in nano percent pub const PERCENT_100_NANO: u64 = 100_000_000_000; // ============================================================================ // FEE LIMIT CONSTANTS // ============================================================================ /// Maximum deposit fee in basis points (20%) pub const MAX_DEPOSIT_FEE_BPS: u16 = 2_000; /// Maximum withdrawal fee in basis points (20%) pub const MAX_WITHDRAWAL_FEE_BPS: u16 = 2_000; /// Maximum protocol cut in basis points (100%) pub const MAX_PROTOCOL_CUT_BPS: u16 = 10_000; // ============================================================================ // TIME CONSTANTS (NANOSECONDS) // ============================================================================ /// Nanoseconds per second pub const NANOSECONDS_PER_SECOND: u128 = 1_000_000_000; /// Nanoseconds per minute pub const NANOSECONDS_PER_MINUTE: u128 = 60 * NANOSECONDS_PER_SECOND; /// Nanoseconds per hour pub const NANOSECONDS_PER_HOUR: u128 = 3600 * NANOSECONDS_PER_SECOND; /// Nanoseconds per day pub const NANOSECONDS_PER_DAY: u128 = 24 * NANOSECONDS_PER_HOUR; /// Nanoseconds per year (365 days) pub const NANOSECONDS_PER_YEAR: u128 = 365 * NANOSECONDS_PER_DAY; /// Nanoseconds per year (365.25 days for leap year calculations) pub const NANOSECONDS_PER_YEAR_LEAP: u128 = 365_25 * NANOSECONDS_PER_DAY / 100; /// Nanoseconds in one week pub const NANOSECONDS_PER_WEEK: u128 = 7 * NANOSECONDS_PER_DAY; /// Default proposal expiry time (24 hours in nanoseconds) pub const DEFAULT_PROPOSAL_EXPIRY_TIME_NS: u128 = NANOSECONDS_PER_DAY; // ============================================================================ // PRECISION CONSTANTS // ============================================================================ /// High precision constant for annualized return calculations (10^8) pub const HIGH_PRECISION: u128 = 100_000_000; // ============================================================================ // DECIMAL LIMITS // ============================================================================ /// Maximum share price decimals pub const MAX_SHARE_PRICE_DECIMALS: u8 = 30; /// Maximum extra decimals pub const MAX_EXTRA_DECIMALS: u8 = 30; /// Maximum combined decimals (U256 limit) pub const MAX_COMBINED_DECIMALS: u8 = 38; /// Minimum share price decimals pub const MIN_SHARE_PRICE_DECIMALS: u8 = 6; /// Maximum share price decimals for kernel config pub const MAX_SHARE_PRICE_DECIMALS_KERNEL: u8 = 18; // ============================================================================ // DEFAULT CONFIGURATION VALUES // ============================================================================ /// Default maximum sync deposit amount (100,000 tokens with 6 decimals) pub const DEFAULT_MAX_SYNC_DEPOSIT: u128 = 100_000 * 1_000_000; /// Maximum sync redeem ratio in basis points (100%) pub const MAX_SYNC_REDEEM_RATIO_BPS: u16 = 10_000; /// Default share price decimals pub const DEFAULT_SHARE_PRICE_DECIMALS: u8 = 8; /// Default extra decimals pub const DEFAULT_EXTRA_DECIMALS: u8 = 18; /// Default crystallization interval (1 week) pub const DEFAULT_CRYSTALLIZATION_INTERVAL_NS: u128 = NANOSECONDS_PER_WEEK; // ============================================================================ // GAS CONSTANTS // ============================================================================ /// Gas for callback operations (20 TGas) pub const GAS_FOR_CALLBACK: Gas = Gas::from_tgas(20); /// Gas for token transfer operations (10 TGas) pub const GAS_FOR_TOKEN_TRANSFER: Gas = Gas::from_tgas(10); /// Gas for token transfer_call operations (30 TGas) /// Transfer_call requires more gas as it involves cross-contract callbacks pub const GAS_FOR_TOKEN_TRANSFER_CALL: Gas = Gas::from_tgas(30); // ============================================================================ // SHARE PRICE STALENESS CONSTANTS // ============================================================================ /// Default maximum share price staleness (1 hour in nanoseconds) pub const DEFAULT_MAX_SHARE_PRICE_STALENESS_NS: u128 = NANOSECONDS_PER_HOUR; /// Minimum share price staleness (1 minute) pub const MIN_SHARE_PRICE_STALENESS_NS: u128 = NANOSECONDS_PER_MINUTE; /// Maximum share price staleness (1 day) pub const MAX_SHARE_PRICE_STALENESS_NS: u128 = NANOSECONDS_PER_WEEK;