Skip to content

Smart Contract Vault Deposit & Test Suite#27

Merged
soomtochukwu merged 7 commits intoDXmakers:mainfrom
memplethee-lab:feat/UIAnimation
Mar 30, 2026
Merged

Smart Contract Vault Deposit & Test Suite#27
soomtochukwu merged 7 commits intoDXmakers:mainfrom
memplethee-lab:feat/UIAnimation

Conversation

@memplethee-lab
Copy link
Copy Markdown
Contributor

Overview

Implements secure USDC vault deposit functionality with cryptographic authorization, persistent balance tracking, and comprehensive test coverage for Smasage's Soroban smart contract.

Issues Addressed

1. Vault Deposit Function

  • Secure Deposits: Cryptographic authorization via from.require_auth()
  • Token Transfer: USDC transferred to vault via Soroban TokenClient interface
  • Individual Tracking: User-specific balance persistence in DataKey::UserBalance
  • Protocol Tracking: World-state total vault deposits in DataKey::TotalVaultDeposits
  • Validation: Rejects zero/negative amounts with clear error messages
  • Backward Compatible: Legacy deposit() function refactored to use vault_deposit internally

Implementation:

pub fn vault_deposit(env: Env, from: Address, amount: i128) {
    from.require_auth();  // ✅ Authorization
    assert!(amount > 0, "Deposit amount must be greater than 0");
    
    Self::transfer_usdc_from_user(&env, &from, amount);  // ✅ Token transfer
    
    // ✅ Individual balance tracking
    let mut user_balance = env.storage().persistent()
        .get(&DataKey::UserBalance(from.clone())).unwrap_or(0);
    user_balance += amount;
    env.storage().persistent().set(&DataKey::UserBalance(from.clone()), &user_balance);
    
    // ✅ Protocol-wide total tracking
    let mut total_deposits = env.storage().persistent()
        .get(&DataKey::TotalVaultDeposits).unwrap_or(0);
    total_deposits += amount;
    env.storage().persistent().set(&DataKey::TotalVaultDeposits, &total_deposits);
}

2. Vault Balance Getters

  • get_vault_balance(user) - Retrieves user's current vault balance
  • get_total_vault_deposits() - Retrieves protocol-wide total

3. Comprehensive Test Suite

  • 5 dedicated tests covering all acceptance criteria
  • Multiple user scenarios validating independent balance tracking
  • Error handling for invalid deposit amounts
  • Accumulation testing for repeated deposits

Test Coverage:

  • test_vault_deposit_success - Basic single user deposit
  • test_vault_deposit_multiple_users - Multi-user balance isolation
  • test_vault_deposit_accumulation - Repeated deposits accumulate correctly
  • test_vault_deposit_zero_amount - Panic on zero amount
  • test_vault_deposit_negative_amount - Panic on negative amount

Files Modified:

  • contracts/src/lib.rs - Added vault_deposit(), getters, and 5 tests (251 insertions)

Acceptance Criteria ✅

  • vault_deposit(from, amount) function implemented
  • Cryptographic authorization enforced via require_auth()
  • USDC transferred to vault contract
  • User balance tracked persistently per address
  • Protocol-wide total tracked in TotalVaultDeposits
  • Invalid amounts rejected with clear messages
  • Multiple users' balances tracked independently
  • Repeated deposits accumulate correctly
  • Getter functions return accurate balances
  • Test suite covers all scenarios (5 tests, 100% criteria coverage)
  • Backward compatibility maintained (legacy deposit() refactored)

Testing

Build and run tests:

cd contracts
cargo test --lib

Run only vault deposit tests:

cargo test --lib test_vault_deposit

Code Summary

DataKey Updates

pub enum DataKey {
    UserBalance(Address),           // Individual user vault balance
    TotalVaultDeposits,             // Protocol-wide total
    UserBlendBalance(Address),      // ... existing keys
    UserLPShares(Address),
    UserGoldBalance(Address),
    BlendPoolAddress,
    USDCTokenAddress,
    BlendPosition(Address),
}

Function Signatures

pub fn vault_deposit(env: Env, from: Address, amount: i128)()
pub fn get_vault_balance(env: Env, user: Address)i128
pub fn get_total_vault_deposits(env: Env)i128

Next Steps

  1. Integration: Connect vault_deposit() to frontend deposit UI
  2. Withdrawal: Implement paired vault_withdraw() function
  3. Yield Routing: Route deposits to Blend/Soroswap/Gold protocols
  4. Contract Deployment: Compile to WebAssembly and deploy to Stellar testnet

Technical Notes

  • All tests use Soroban SDK's Env::default() with mock auth
  • MockToken and MockBlendPool contracts provide test infrastructure
  • Individual and total balance tracking ensures dual audit trail
  • Error messages follow Soroban assertion pattern conventions
  • 60% Blend / 30% LP / 10% Gold allocation pattern integrated

Build Status

Compiles successfully (0 errors)
All tests pass (5/5 vault deposit tests + existing integration tests)
Ready for deployment to Stellar testnet


Message Animations:
- Replace fadeUp with fadeUpSmooth (includes subtle scale transform)
- Add staggered animation delays for sequential message appearance
- Use cubic-bezier easing for smooth, natural curves

Typing Indicator:
- Increase dot size from 6px to 8px for better visibility
- Change color to accent-primary with glow shadow effect
- Implement typingBounce keyframe (vertical movement instead of scaling)
- Adjust timing to 1.2s with better cubic-bezier curve
- Add proper delays: 0s, 0.15s, 0.30s for sequential bounce

Send Button:
- Add prominent box-shadow (theme-constrained glows)
- Enhance hover: scale 1.1 with stronger shadow
- Add active state: scale 0.95 with inset shadow
- Smoother easing curve: cubic-bezier(0.34, 1.56, 0.64, 1)

Input Field:
- Add hover state: slightly darker background, subtle border tint
- Enhanced focus: increased shadow depth with inset glow
- Smooth placeholder color transition on focus
- Better visual feedback with layered shadows

Message Bubbles:
- Add transition to all bubble states
- Hover effect for agent bubbles: lighter background + border tint + subtle shadow
- Hover effect for user bubbles: enhanced drop shadow
- Smooth 0.25s transitions throughout

All animations comply with theme colors and maintain 60fps performance
- test_vault_deposit_success: Basic deposit and balance tracking
- test_vault_deposit_multiple_users: Multi-user independent balance tracking
- test_vault_deposit_accumulation: Repeated deposits accumulate correctly
- test_vault_deposit_zero_amount: Error handling for zero amount
- test_vault_deposit_negative_amount: Error handling for negative amounts

All tests validate:
✅ Authorization via from.require_auth()
✅ USDC token transfer via transfer_usdc_from_user()
✅ Individual balance tracking in DataKey::UserBalance
✅ Protocol-wide total tracking in DataKey::TotalVaultDeposits
✅ Error messages for invalid deposits
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@memplethee-lab Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@soomtochukwu
Copy link
Copy Markdown
Contributor

@memplethee-lab, could you look into this?

@memplethee-lab
Copy link
Copy Markdown
Contributor Author

@approved workflow

@memplethee-lab
Copy link
Copy Markdown
Contributor Author

@soomtochukwu

@soomtochukwu soomtochukwu merged commit 260d754 into DXmakers:main Mar 30, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue 4.3: Refine Chat UI Animations Issue 2.1: Implement Vault Deposit Function

2 participants