Problem Statement
Every contract repeats the same five-line pattern in admin-only functions:
admin.require_auth();
let stored_admin: Address = env.storage().instance().get(&DataKey::Admin).expect("...");
assert!(admin == stored_admin, "Unauthorized");
// ... business logic
This is verbose, prone to copy/paste error (the auth check is sometimes assert!, sometimes panic!("Unauthorized"), with random string variations), and lacks a structured ContractError::Unauthorized enum value.
Why It Matters
- Inconsistent error strings across contracts (some say
"Unauthorized", others "Unauthorized: Caller is not the protocol admin", others "Contract not initialized", others "Not initialized") make off-chain error handling fragile.
- Boilerplate crowding obscures business logic.
Expected Outcome
- A shared helper
contracts_common::auth::require_admin(env, expected: &Address).
- A
ContractError enum with explicit variants.
- Migration of all six contracts.
Acceptance Criteria
grep -r "Unauthorized" contracts/*/src/lib.rs returns only references inside the (now centralized) error enum.
- All tests still pass.
- New tests for the helper edge cases.
Implementation Notes
Files / Modules Affected
All six contracts; new contracts/common/src/auth.rs and errors.rs.
Dependencies
Issue #7.
Difficulty
Medium.
Estimated Effort
1–2 days.
Suggested Labels
quality, refactor, P2, tech-debt
Problem Statement
Every contract repeats the same five-line pattern in admin-only functions:
This is verbose, prone to copy/paste error (the auth check is sometimes
assert!, sometimespanic!("Unauthorized"), with random string variations), and lacks a structuredContractError::Unauthorizedenum value.Why It Matters
"Unauthorized", others"Unauthorized: Caller is not the protocol admin", others"Contract not initialized", others"Not initialized") make off-chain error handling fragile.Expected Outcome
contracts_common::auth::require_admin(env, expected: &Address).ContractErrorenum with explicit variants.Acceptance Criteria
grep -r "Unauthorized" contracts/*/src/lib.rsreturns only references inside the (now centralized) error enum.Implementation Notes
contracterror!macro fromsoroban-sdkfor proper error encoding.create_contracts_commonshared crate — eliminate duplicated types and patterns #7 (common crate).Files / Modules Affected
All six contracts; new
contracts/common/src/auth.rsanderrors.rs.Dependencies
Issue #7.
Difficulty
Medium.
Estimated Effort
1–2 days.
Suggested Labels
quality,refactor,P2,tech-debt