feature/827-snapshot-token - #553
Open
benedictworks-home wants to merge 4 commits into
Open
Conversation
…ests Co-authored-by: benedictworks-home <277016530+benedictworks-home@users.noreply.github.com>
Implement Balance Snapshot Token Contract
…references Wires the notification preferences toggles in NotificationSettings to settingsStore. Implements useFundingReminder and useRepaymentReminder hooks to complement useMaturityReminder. Ensures all reminder hooks respect user preferences globally, with immediate dismissal of active toasts when toggled off. Fully localizes labels across English, Spanish, Portuguese, and Arabic, and adds unit tests. Co-authored-by: benedictworks-home <277016530+benedictworks-home@users.noreply.github.com>
…-wiring Wire NotificationSettings to maturity and funding reminder prefs
|
@benedictworks-home 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This pull request implements Issue #827 — [Cookbook] Create Snapshot Token, establishing a robust, production-grade Soroban fungible token with point-of-time balance snapshotting capabilities. It is located at
examples/tokens/04-snapshot-token/and registered inside the tokens category.Features Implemented
initialize,mint(restricted to admin),transfer, and standard metadata queries (name,symbol,decimals,total_supply,balance).create_snapshot(caller)restricted to the token administrator usingcaller.require_auth(). Returns a monotonically incrementing ID and publishes snapshot events.balance_at_snapshot(account, snapshot_id). Includes highly robust resolution that perfectly addresses critical edge cases:0(and not an error) for valid snapshot IDs if the account has no transaction history.SnapshotTokenError::SnapshotNotFoundif querying snapshot IDs that were never created.Test Suite (13 robust tests in
src/test.rs)test_initialization— Verifies correct contract metadata, admin, zero supply, and initial snapshot counter.test_mint_admin— Verifies admin can mint and receiver's balance updates correctly.test_mint_invalid_amount— Verifies negative/zero mint amounts fail.test_transfer_success— Verifies standard balance transfer correctness and sender auth.test_transfer_insufficient_balance— Verifies transfer fails when balance is too low.test_snapshot_id_incrementing— Verifies monotonically incrementing snapshot IDs on successive admin creations.test_create_snapshot_not_authorized— Verifies non-admin caller receivesNotAuthorizedoncreate_snapshot.test_balance_at_snapshot_no_activity— Verifies the critical "no-activity" edge case returns the correct snapshot-time balance.test_balance_at_snapshot_change_before— Verifies balance at snapshot includes changes occurring prior to creation.test_balance_at_snapshot_unaffected_by_subsequent— Verifies balance at snapshot remains completely unaffected by transfers occurring after creation.test_multi_snapshot_complex— Comprehensive multi-snapshot, multi-account, multi-transfer scenario verifying correct independent historical records.test_query_non_existent_snapshot— Verifies querying invalid snapshot IDs returnsSnapshotNotFound.test_query_user_with_no_history— Verifies querying valid snapshot balance for a new address returns0.Documentation & Category Index
04-snapshot-token/README.mdincluding the contract interface, the sparse-snapshot mechanism design details, step-by-step build & test guide, concrete DAO governance walkthrough, and design notes.examples/tokens/README.mdto reference this new snapshot token cookbook recipe.Verification Commands Run
All tests run, format checks, lints, and optimized WASM contract compilation are 100% green:
cargo fmt --check --manifest-path examples/tokens/04-snapshot-token/Cargo.toml-> Passedcargo clippy --manifest-path examples/tokens/04-snapshot-token/Cargo.toml --all-targets -- -D warnings-> Passed (0 warnings/errors)cargo test --manifest-path examples/tokens/04-snapshot-token/Cargo.toml-> Passed (13 passed, 0 failed)cargo build --target wasm32v1-none --release --manifest-path examples/tokens/04-snapshot-token/Cargo.toml-> Passed (Successfully compiled optimized contract WASM)Implementation & Design Detail Review
Crate Location: Exactly at examples/tokens/04-snapshot-token/ containing Cargo.toml, README.md, src/lib.rs, and src/test.rs.
Existing Token Sibling Examples: No sibling token examples (01-03) existed inside examples/tokens/ yet when I started. Therefore, this crate was implemented as a fully complete and standalone SEP-41-style token with governance-focused snapshot functionality.
Access-Control Decision: Restricted to admin-only via caller.require_auth(). Allowing arbitrary callers to take snapshots would facilitate contract state griefing (arbitrary creation of snapshot boundaries, bloating maps and storage).
No-Activity Edge-Case Behavior: Resolved by searching the sorted snapshot history Map<u32, i128>. We search for the smallest key k such that k >= snapshot_id. If such an entry exists, its value is the correct historical balance at snapshot_id. If no entry exists, the user has had no transactions since snapshot_id, so their historical balance at snapshot_id equals their current balance. Tested explicitly in test_balance_at_snapshot_no_activity.
Modern Compilation Target: For modern soroban-sdk versions inside Rust 1.82+, compiling for standard wasm32-unknown-unknown raises issues due to unsupported default reference-types and multi-value features. Thus, the crate was successfully built for release using the recommended wasm32v1-none target (cargo build --target wasm32v1-none --release).
Closes #518