Skip to content

feat: implement #771, #767, #766, #593 - #1

Open
NnamdiCyber wants to merge 1 commit into
mainfrom
feat/vault-enhancements-771-767-766-593
Open

feat: implement #771, #767, #766, #593#1
NnamdiCyber wants to merge 1 commit into
mainfrom
feat/vault-enhancements-771-767-766-593

Conversation

@NnamdiCyber

Copy link
Copy Markdown
Owner

Summary

Implements four vault core enhancements across the Soroban contract.


Closes TTL-Legacy#771get_check_in_history_page with Cursor Pagination

New function: get_check_in_history_page(env, vault_id, cursor: u64, limit: u32) -> Vec<CheckInHistoryEntry>

  • Cursor-based pagination — cursor = 0 returns the most recent entry, cursor = 1 the second-most-recent, etc.
  • Limit is capped at 50 entries
  • Returns entries newest-first
  • Tests: pagination over 5 entries, boundary conditions, limit cap, and empty history

Closes#767 — Maximum Number of Vaults Per Owner

  • Added MaxVaultsPerOwner to DataKey (default: 50)
  • Added VaultLimitReached error (code #82)
  • Admin functions: set_max_vaults_per_owner / get_max_vaults_per_owner
  • create_vault now rejects when owner already holds max_vaults_per_owner vaults
  • Tests: default value (50), limit enforcement (third vault rejected), limit update (admin raises ceiling)

Closes TTL-Legacy#766get_vault_age Function

New function: get_vault_age(env, vault_id) -> u64

  • Returns seconds elapsed since vault.created_at
  • Returns 0 if the vault does not exist (no panic)
  • Tests: newly-created vault (age = 0), 1-hour-old vault, nonexistent vault

Closes TTL-Legacy#593 — Token Fee Optimization

  • Added TokenFeeConfig struct: accumulation_enabled, accumulation_threshold
  • Added PendingWithdrawal struct for deferred transfers
  • Modified do_withdraw to batch below-threshold amounts into pending list instead of immediate transfer
  • Admin functions: set_token_fee_config, execute_pending_withdrawals
  • Events: FEE_CONFIG_UPDATED_TOPIC, FEE_BATCH_EXECUTED_TOPIC
  • Tests: default config, config get/set

Files Changed

File Changes
contracts/ttl_vault/src/types.rs +3 DataKey variants, +2 structs, +2 event symbols
contracts/ttl_vault/src/lib.rs ~180 lines: 4 new public functions, modified create_vault & do_withdraw
contracts/ttl_vault/src/test.rs ~178 lines: 10 new test functions across all 4 issues

…egacy#593

TTL-Legacy#771: Add get_check_in_history_page with cursor pagination
- Cursor-based pagination for CheckInHistory entries (newest-first)
- cursor=0 returns most recent; cap limit at 50
- Tests for pagination, boundary conditions, and empty history

TTL-Legacy#767: Enforce maximum number of vaults per owner
- Add MaxVaultsPerOwner to DataKey (default 50)
- Add VaultLimitReached error variant (TTL-Legacy#82)
- Enforce limit in create_vault; add admin set/get functions
- Tests for limit enforcement and update

TTL-Legacy#766: Add get_vault_age function
- Returns seconds since vault creation; 0 if vault doesn't exist
- Tests for newly-created, long-lived, and nonexistent vaults

TTL-Legacy#593: Implement Token Fee Optimization
- TokenFeeConfig struct with accumulation_enabled + accumulation_threshold
- PendingWithdrawal batching for below-threshold amounts
- Admin set_token_fee_config + execute_pending_withdrawals
- Events: FEE_CONFIG_UPDATED_TOPIC, FEE_BATCH_EXECUTED_TOPIC
- Tests for default config, set/get, and withdrawal batching
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.

Add get_check_in_history_page with Cursor Pagination Add get_vault_age Function Implement Token Fee Optimization

1 participant