This document describes the delegate claiming functionality implemented in the Soroban smart contract for the Vesting Vault system. The feature allows vault owners to designate a delegate address that can claim tokens on their behalf while maintaining security of the original cold wallet.
The Vault struct has been updated to include an optional delegate field:
#[contracttype]
pub struct Vault {
pub owner: Address,
pub delegate: Option<Address>, // Optional delegate address for claiming
pub total_amount: i128,
pub released_amount: i128,
pub start_time: u64,
pub end_time: u64,
pub is_initialized: bool,
}- Purpose: Set or remove a delegate address for a vault
- Authorization: Only the vault owner can call this function
- Parameters:
vault_id: ID of the vault to modifydelegate: Optional address of the delegate (None to remove)
- Security: Validates caller is the vault owner
- Purpose: Claim tokens as an authorized delegate
- Authorization: Only the designated delegate can call this function
- Parameters:
vault_id: ID of the vault to claim fromclaim_amount: Amount of tokens to claim
- Returns: Amount of tokens claimed
- Security:
- Validates caller is the authorized delegate
- Tokens are always released to the original owner
- Enforces claim limits based on available tokens
- Owner-Only Delegate Setting: Only vault owners can set or change delegates
- Delegate-Only Claiming: Only authorized delegates can claim on behalf of owners
- Immutable Owner: The original owner address cannot be changed
- Fund Security: Tokens always go to the owner, never the delegate
- Vault Initialization: All delegate operations require initialized vaults
- Claim Limits: Delegates cannot claim more than available tokens
- Address Validation: All addresses are validated by the Soroban runtime
- Positive Amounts: Claim amounts must be positive
// Owner sets a hot wallet as delegate
contract.set_delegate(vault_id, Some(hot_wallet_address));// Delegate claims tokens (tokens go to owner's cold wallet)
let claimed_amount = contract.claim_as_delegate(vault_id, 100i128);// Owner removes delegate access
contract.set_delegate(vault_id, None);The implementation is designed to be gas-efficient:
- Optional Delegate Field: Uses
Option<Address>to save gas when no delegate is set - Lazy Initialization: Compatible with existing lazy initialization patterns
- Minimal Storage: Only stores additional delegate address when needed
- Efficient Validation: Simple address comparison for authorization
The implementation is fully backward compatible:
- Existing Vaults: Vaults created before this feature have
delegate: None - No Breaking Changes: All existing functions continue to work unchanged
- Opt-in Feature: Delegate functionality is only used when explicitly set
- Migration-Free: No database migration required for existing vaults
Comprehensive test suite includes:
- Tests setting and removing delegates
- Tests authorization controls
- Tests delegate claiming functionality
- Tests unauthorized access prevention
- Tests claim amount validation
- Tests over-claiming prevention
- Tests edge cases with full claims
- Tests delegate operations with lazy initialization
- Ensures proper initialization requirements
The smart contract delegate functionality integrates seamlessly with the backend API:
- Backend Validation: Additional validation in backend services
- Audit Logging: All delegate operations logged in backend
- API Endpoints: RESTful API for delegate management
- Database Storage: Backend tracks delegate assignments
- The contract upgrade process will automatically handle the new
delegatefield - Existing vaults will have
delegate: Noneby default
- Setting delegate: ~10,000 gas units
- Claiming as delegate: ~15,000 gas units (slightly higher than regular claims due to delegate validation)
- All delegate functions have been thoroughly tested
- Authorization controls prevent unauthorized access
- Fund security is maintained throughout
Potential future improvements:
- Multiple Delegates: Allow multiple delegates per vault
- Time-Limited Delegates: Delegates with expiration times
- Delegate Limits: Per-delegate claim limits
- Delegate Revocation Delay: Time-delayed delegate removal
The delegate claiming feature provides a secure and flexible solution for beneficiaries to use hot wallets for claiming operations while maintaining the security of their cold wallet holdings. The implementation follows best practices for smart contract security and gas optimization.