-
Notifications
You must be signed in to change notification settings - Fork 66
feat: Add get_redemption_request view functions and user query support #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -507,6 +507,16 @@ impl SingleRWAVault { | |
| get_redemption_request(e, request_id) | ||
| } | ||
|
|
||
| /// Returns the current redemption request counter (total number of requests ever made). | ||
| pub fn redemption_counter(e: &Env) -> u32 { | ||
| get_redemption_counter(e) | ||
| } | ||
|
|
||
| /// Returns all redemption request IDs for a given user. | ||
| pub fn get_user_redemption_requests(e: &Env, user: Address) -> Vec<u32> { | ||
| get_user_redemption_requests(e, &user) | ||
| } | ||
|
Comment on lines
+510
to
+518
|
||
|
|
||
| // ───────────────────────────────────────────────────────────────── | ||
| // ERC-4626 max helpers | ||
| // ───────────────────────────────────────────────────────────────── | ||
|
|
@@ -1211,12 +1221,14 @@ impl SingleRWAVault { | |
| e, | ||
| id, | ||
| RedemptionRequest { | ||
| user: caller, | ||
| user: caller.clone(), | ||
| shares, | ||
| request_time: e.ledger().timestamp(), | ||
| processed: false, | ||
| }, | ||
| ); | ||
| // Track the request ID in the user's list for queryability | ||
| push_user_redemption_request(e, &user, id); | ||
|
|
||
|
Comment on lines
1228
to
1232
|
||
| emit_early_redemption_requested(e, user, id, shares); | ||
| bump_instance(e); | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,7 @@ | |||||||||||
| //! INSTANCE_BUMP_AMOUNT ≈ 30 days | ||||||||||||
| //! BALANCE_BUMP_AMOUNT ≈ 60 days | ||||||||||||
|
|
||||||||||||
| use soroban_sdk::{contracttype, panic_with_error, Address, Env, String}; | ||||||||||||
| use soroban_sdk::{contracttype, panic_with_error, Address, Env, String, Vec}; | ||||||||||||
|
|
||||||||||||
| use crate::errors::Error; | ||||||||||||
| use crate::types::{RedemptionRequest, Role, VaultState}; | ||||||||||||
|
|
@@ -112,6 +112,7 @@ pub enum DataKey { | |||||||||||
| RedemptionCounter, | ||||||||||||
| RedemptionRequest(u32), | ||||||||||||
| EscrowedShares(Address), | ||||||||||||
| // UserRedemptionRequests(Address) - removed due to contracttype size limits | ||||||||||||
|
||||||||||||
| // UserRedemptionRequests(Address) - removed due to contracttype size limits | |
| /// Per-user redemption requests are tracked via `RedemptionRequest(u32)` IDs | |
| /// and `EscrowedShares(Address)`, instead of a dedicated | |
| /// `UserRedemptionRequests(Address)` enum variant, to keep this `contracttype` | |
| /// within Soroban’s data layout / size limits (see Soroban contract data docs). |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a #[contracttype] struct-as-key with a single user field serializes as a map and has no explicit namespace/prefix, which is more storage/CPU heavy than necessary and can collide with other similarly-shaped keys in the future. Consider using a small namespaced key (e.g., a tuple with a fixed tag + Address) or adding a discriminant field to the struct to ensure uniqueness and reduce overhead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New query surface (
redemption_counter/get_user_redemption_requests) and the per-user tracking added inrequest_early_redemptiondon’t appear to have direct test coverage. Please add tests that (1) multiple requests by the same user produce an ordered ID list, (2) different users don’t leak IDs, and (3)redemption_countermatches the highest issued ID.