Skip to content

Commit c15f8f4

Browse files
Merge pull request #277 from ChukwuemekaP1/test/vault-routing-views
chore(contracts): add and view docs + tests closes #262
2 parents 15ff212 + f0d7383 commit c15f8f4

6 files changed

Lines changed: 916 additions & 636 deletions

File tree

contracts/settlement/src/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ mod settlement_tests {
1313
env.mock_all_auths();
1414
let admin = Address::generate(&env);
1515
let vault = Address::generate(&env);
16-
let third_party = Address::generate(&env);
1716
let addr = env.register(CalloraSettlement, ());
1817
let client = CalloraSettlementClient::new(&env, &addr);
1918
client.init(&admin, &vault);

contracts/vault/STORAGE.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ pub enum StorageKey {
3232
| `AllowedDepositors` | `Vec<Address>` | List of addresses allowed to deposit into the vault | Access control for deposits | `set_allowed_depositor()`, readable via `is_authorized_depositor()` |
3333
| `Admin` | `Address` | Administrator address authorized to call `distribute()` and `set_admin()` | Access control for distributions | `get_admin()`, `set_admin()` (admin-only) |
3434
| `UsdcToken` | `Address` | USDC token contract address | Token transfers for deposits, deducts, distributions | Set during `init()`, used by token operations |
35-
| `Settlement` | `Option<Address>` | Settlement contract address; receives USDC on deduct operations | Deduct routing (priority over RevenuePool) | `set_settlement()`, `get_settlement()` (admin-only) |
36-
| `RevenuePool` | `Option<Address>` | Revenue pool contract address; receives USDC on deduct if Settlement is not set | Deduct routing (fallback) | Set during `init()`, used if Settlement not configured |
35+
| `Settlement` | `Option<Address>` | Settlement contract address; receives USDC on deduct operations | Deduct routing (priority over RevenuePool) | `set_settlement()`, `get_settlement()` (admin-only write, public read) |
36+
| `RevenuePool` | `Option<Address>` | Revenue pool contract address; receives USDC on deduct if Settlement is not set | Deduct routing (fallback) | `set_revenue_pool()`, `get_revenue_pool()` (admin-only write, public read) |
3737
| `MaxDeduct` | `i128` | Maximum USDC amount per single deduct operation | Deduct limit enforcement | Set during `init()`, read by `deduct()` and `batch_deduct()` |
3838
| `Metadata(offering_id)` | `String` | Off-chain metadata reference (IPFS CID or URI) for a specific offering | Offering metadata | `set_metadata()`, `get_metadata()`, `update_metadata()` (owner-only) |
3939

@@ -116,13 +116,22 @@ Sets up the vault with initial state:
116116
| Operation | Reads | Writes | Authorization |
117117
|-----------|-------|--------|-----------------|
118118
| `set_settlement(settlement_address)` | Admin | Settlement | Admin only |
119-
| `get_settlement()` | Settlement || Public read |
119+
| `get_settlement()` | Settlement || Public read (view-only, no mutation) |
120+
| `set_revenue_pool(revenue_pool)` | Admin | RevenuePool | Admin only |
121+
| `get_revenue_pool()` | RevenuePool || Public read (view-only, no mutation) |
120122

121123
**Deduct Routing Logic:**
122124
1. If `StorageKey::Settlement` is set: transfer USDC to settlement
123125
2. Else if `StorageKey::RevenuePool` is set: transfer USDC to revenue pool
124126
3. Else: USDC remains in vault
125127

128+
**View Function Safety:**
129+
- Both `get_settlement()` and `get_revenue_pool()` are read-only operations
130+
- They return only final committed state, never intermediate or pending values
131+
- Safe for external indexers and off-chain queries
132+
- Deterministic: identical state inputs always produce identical outputs
133+
- `get_settlement()` panics if not configured; `get_revenue_pool()` returns `None` gracefully
134+
126135
### Metadata Operations
127136

128137
| Operation | Reads | Writes | Authorization |
@@ -216,8 +225,8 @@ env.storage().instance().set(&StorageKey::Meta, &new_meta);
216225
### Access Control
217226

218227
- **Owner-Only Operations:** `set_allowed_depositor()`, `set_authorized_caller()`, `transfer_ownership()`, `withdraw()`, `withdraw_to()`, metadata operations
219-
- **Admin-Only Operations:** `distribute()`, `set_admin()`, `set_settlement()`
220-
- **Public Operations:** `balance()`, `get_meta()`, `get_metadata()`, `is_authorized_depositor()`, `get_settlement()` (read-only)
228+
- **Admin-Only Operations:** `distribute()`, `set_admin()`, `set_settlement()`, `set_revenue_pool()`
229+
- **Public Operations:** `balance()`, `get_meta()`, `get_metadata()`, `is_authorized_depositor()`, `get_settlement()`, `get_revenue_pool()` (all read-only)
221230
- **Depositor Operations:** `deposit()` (owner or allowed depositor); `deduct()` and `batch_deduct()` (owner or authorized_caller)
222231

223232
### Data Integrity

0 commit comments

Comments
 (0)