use crate::asset::Asset; use crate::basis_points::BasisPoints; use near_contract_standards::fungible_token::metadata::FungibleTokenMetadata; use near_sdk::{json_types::U128, AccountId, Promise}; /// Configuration for vault operations /// This type alias points to the actual VaultConfig in vault_config module pub type VaultConfig = crate::vault_config::VaultConfig; /// Interface that all Dew Vaults must implement for Dew Kernel integration /// /// This trait defines the standard API that Dew Kernel uses to manage vault operations. /// All vault implementations should implement this trait to ensure compatibility /// with the Dew Finance protocol. pub trait DewVaultInterface { /// Update share prices for accepted assets /// /// Only authorized Dew Kernel contracts can call this method. /// Share prices determine how many shares are minted per asset deposited /// and how many assets are returned per share redeemed. /// /// # Arguments /// * `rates` - Vector of (Asset, share_price) tuples where share_price /// represents shares per asset with configured decimal precision /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If any asset in rates is not accepted by the vault /// * If any share price is zero or negative fn dew_vault_update_share_prices(&mut self, rates: Vec<(Asset, U128)>); /// Update vault configuration /// /// Only authorized Dew Kernel contracts can update vault configuration. /// This includes operational parameters like sync limits, minimum amounts, /// and timing controls. /// /// # Arguments /// * `new_config` - New vault configuration to apply /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If the new configuration is invalid fn dew_vault_update_config(&mut self, new_config: VaultConfig); /// Confirm pending redeem requests with locked share prices /// /// This is phase 1 of the two-phase async redeem system. Dew Kernel provides /// locked share prices for pending redeems, which provides slippage protection /// for users while allowing time for cross-chain operations. /// /// # Arguments /// * `requests` - Vector of (operation_id, locked_share_price) tuples /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If any operation_id does not exist or is already confirmed /// * If locked share price would violate user's min_assets slippage protection fn dew_vault_confirm_pending_redeems(&mut self, requests: Vec<(u64, U128)>); /// Process pending deposits with provided share prices /// /// Completes async deposit operations by minting shares at the provided /// share prices. This enables fresh rate updates between deposit request /// and processing. /// /// # Arguments /// * `requests` - Vector of (operation_id, share_price) tuples /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If any operation_id does not exist /// * If share price would violate user's min_shares slippage protection fn dew_vault_process_pending_deposits(&mut self, requests: Vec<(u64, U128)>); /// Transfer assets from vault to specified receiver /// /// Enables Dew Kernel to move vault assets for cross-chain operations, /// yield strategies, or other protocol functions. Assets are deducted /// from available vault balance. /// /// # Arguments /// * `asset` - Asset to transfer /// * `amount` - Amount to transfer /// * `receiver_id` - Account to receive the assets /// * `memo` - Optional memo for the transfer /// * `message` - Optional message for transfer_call (if provided, uses transfer_call) /// /// # Returns /// Promise for the asset transfer operation /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If asset is not accepted by vault /// * If insufficient available assets for transfer fn dew_vault_asset_transfer( &mut self, asset: Asset, amount: U128, receiver_id: AccountId, memo: Option, ) -> Promise; /// Update vault share token metadata /// /// Allows Dew Kernel to update the NEP-141 metadata for vault shares, /// including name, symbol, and other display information. /// /// # Arguments /// * `new_metadata` - New metadata to apply to vault shares /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If metadata is invalid (empty name/symbol, wrong spec version) fn dew_vault_update_metadata(&mut self, new_metadata: FungibleTokenMetadata); /// Add account to vault whitelist /// /// Adds an account to the vault's whitelist, allowing them to perform /// vault operations when whitelist mode is enabled. Only authorized /// Dew Kernel contracts can modify whitelist membership. /// /// # Arguments /// * `account_id` - Account to add to whitelist /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If account is already whitelisted fn dew_vault_add_to_whitelist(&mut self, account_id: AccountId); /// Remove account from vault whitelist /// /// Removes an account from the vault's whitelist, preventing them from /// performing vault operations when whitelist mode is enabled. Only /// authorized Dew Kernel contracts can modify whitelist membership. /// /// # Arguments /// * `account_id` - Account to remove from whitelist /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If account is not currently whitelisted fn dew_vault_remove_from_whitelist(&mut self, account_id: AccountId); /// Add account to vault blacklist /// /// Adds an account to the vault's blacklist, permanently preventing them /// from performing any vault operations. Only authorized Dew Kernel contracts /// can modify blacklist membership. /// /// # Arguments /// * `account_id` - Account to add to blacklist /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If account is already blacklisted fn dew_vault_add_to_blacklist(&mut self, account_id: AccountId); /// Remove account from vault blacklist /// /// Removes an account from the vault's blacklist, allowing them to perform /// vault operations again. Only authorized Dew Kernel contracts can modify /// blacklist membership. /// /// # Arguments /// * `account_id` - Account to remove from blacklist /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If account is not currently blacklisted fn dew_vault_remove_from_blacklist(&mut self, account_id: AccountId); fn dew_vault_emergency_pause(&mut self); fn dew_vault_emergency_unpause(&mut self); /// Reject pending deposit requests /// /// Rejects specific deposit requests and provides a reason for rejection. /// Assets are moved to claimable balance for deposit owners to claim later. /// Only authorized Dew Kernel contracts can reject pending deposits. /// /// # Arguments /// * `request_ids` - Vector of deposit request IDs to reject /// * `reason` - Reason for rejection (for logging/audit purposes) /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If any request ID is invalid or already processed fn dew_vault_reject_pending_deposits(&mut self, request_ids: Vec, reason: String); /// Reject pending redeem requests /// /// Rejects specific redeem requests and provides a reason for rejection. /// Only authorized Dew Kernel contracts can reject pending redeems. /// /// # Arguments /// * `request_ids` - Vector of redeem request IDs to reject /// * `reason` - Reason for rejection (for logging/audit purposes) /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If any request ID is invalid or already processed fn dew_vault_reject_pending_redeems(&mut self, request_ids: Vec, reason: String); /// Force reset flow control caps /// /// Emergency function to reset flow control caps on the vault. /// This bypasses normal flow control mechanisms and should only be used /// in emergency situations. Only authorized Dew Kernel contracts can /// perform this operation. /// /// # Arguments /// * `is_deposit` - true to reset deposit flow cap, false to reset withdrawal flow cap /// /// # Panics /// * If caller is not the authorized Dew Kernel contract fn dew_vault_force_reset_flow_cap(&mut self, is_deposit: bool); /// Set per-asset deposit and withdrawal fees /// /// Allows Dew Kernel to configure fee percentages for specific assets. /// Fees are optional - passing None leaves the existing fee unchanged. /// Passing 0 removes the fee for that asset. /// /// # Arguments /// * `asset` - Asset to configure fees for /// * `deposit_fee_bps` - Optional deposit fee in basis points (max 2000 = 20%) /// * `withdrawal_fee_bps` - Optional withdrawal fee in basis points (max 2000 = 20%) /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If asset is not accepted by the vault /// * If fee exceeds 20% (2000 bps) fn dew_vault_set_asset_fees( &mut self, asset: Asset, deposit_fee_bps: Option, withdrawal_fee_bps: Option, ); /// Set protocol fee cuts for per-asset fees /// /// Configures what percentage of vault fees go to the protocol vs vault creator. /// Protocol cuts are optional - passing None leaves the existing cut unchanged. /// Passing 0 removes the protocol cut for that asset. /// /// # Arguments /// * `asset` - Asset to configure protocol cuts for /// * `deposit_cut_bps` - Optional protocol cut of deposit fees in basis points (max 10000 = 100%) /// * `withdrawal_cut_bps` - Optional protocol cut of withdrawal fees in basis points (max 10000 = 100%) /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If asset is not accepted by the vault /// * If cut exceeds 100% (10000 bps) fn dew_vault_set_protocol_fee_cuts( &mut self, asset: Asset, deposit_cut_bps: Option, withdrawal_cut_bps: Option, ); /// Set fee recipient for vault fees /// /// Updates the account that receives vault entry/exit fees. /// Only authorized Dew Kernel contracts can modify the fee recipient. /// /// # Arguments /// * `fee_recipient` - Account to receive entry/exit fees /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If account ID is invalid fn dew_vault_set_fee_recipient(&mut self, fee_recipient: AccountId); /// Claim accumulated vault fees for a specific asset /// /// Transfers accumulated vault entry/exit fees to the fee recipient. /// Only authorized Dew Kernel contracts can claim fees. /// /// # Arguments /// * `asset` - Asset to claim fees for /// /// # Returns /// Promise for the fee transfer operation /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If asset is not accepted by the vault /// * If no fees are available to claim /// * If insufficient available assets to transfer fees fn dew_vault_claim_fees(&mut self, asset: Asset) -> Promise; /// Claim accumulated protocol fees for a specific asset /// /// Transfers accumulated protocol entry/exit fees to the protocol fee recipient. /// Only authorized Dew Kernel contracts can claim protocol fees. /// /// # Arguments /// * `asset` - Asset to claim protocol fees for /// /// # Returns /// Promise for the fee transfer operation /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If asset is not accepted by the vault /// * If no protocol fees are available to claim /// * If insufficient available assets to transfer protocol fees fn dew_vault_claim_protocol_fees(&mut self, asset: Asset) -> Promise; /// Unpause the accountant module /// /// Resumes share price updates and fee calculations after the accountant /// has been paused. The accountant can be paused automatically when exchange /// rate validation constraints are violated, or manually for safety. /// Only authorized Dew Kernel contracts can unpause the accountant. /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If accountant is not currently paused fn dew_vault_unpause_accountant(&mut self); /// Crystallize performance fees with hurdle-based calculation /// /// Manually triggers performance fee crystallization when a performance hurdle /// is configured. This calculates annualized returns, compares them to the /// configured hurdle rate, and only charges fees on gains above both the /// hurdle AND the high water mark. Only authorized Dew Kernel contracts /// can trigger crystallization. /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If vault is not live /// * If performance hurdle is not configured /// * If insufficient time has elapsed since last crystallization fn dew_vault_crystallize_performance_fee(&mut self); /// Start the vault and enable fee calculations /// /// Activates the vault by setting the live timestamp and initializing /// fee-related state (high water mark, crystallization timestamps). /// Once started, the vault begins calculating management and performance fees. /// Only authorized Dew Kernel contracts can start the vault. /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If vault is already live /// * If any asset has zero or missing share price fn dew_vault_start_vault(&mut self); /// Transfer vault ownership to a new owner /// /// Transfers ownership (typically kernel contract) to a new account. /// This is critical for vault migration to new kernel versions or /// protocol governance changes. Only the current owner can initiate /// the transfer. /// /// # Arguments /// * `new_owner` - Account to transfer ownership to /// /// # Panics /// * If caller is not the current owner /// * If new_owner is the same as current owner /// * If new_owner is an invalid account ID fn dew_vault_transfer_ownership(&mut self, new_owner: AccountId); /// Set codehash of new contract code for upgrade /// /// Sets the codehash of WASM code for a future contract upgrade. /// This enables upload of WASM code to the vault contract /// Only authorized Dew Kernel contracts can upload new code. /// /// # Returns /// Base58 encoded hash of the uploaded contract code /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If previous contract code is not deleted yet fn dew_vault_set_code_hash(&mut self, code_hash: String); /// Delete code_hash of contract code /// /// Removes previously staged contract code to clean up storage or cancel an upgrade. /// Only authorized Dew Kernel contracts can delete staged code. /// /// # Arguments /// * `code_hash` - Hash of the staged code to delete (for verification) /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If provided code hash does not match staged code hash fn dew_vault_delete_code_hash(&mut self, code_hash: String); /// Deploy staged contract code and run migrate /// /// Deploys the previously staged WASM code and calls the `migrate` function. /// This performs the actual contract upgrade. /// Only authorized Dew Kernel contracts can deploy upgrades. /// /// # Arguments /// * `code_hash` - Hash of the staged code to deploy (for verification) /// /// # Returns /// Promise for the deployment and migration call /// /// # Panics /// * If caller is not the authorized Dew Kernel contract /// * If no uploaded contract code exists /// * If provided code hash does not match staged code hash fn dew_vault_deploy_uploaded_contract(&mut self, code_hash: String) -> Promise; }