Skip to content

reeplace - #58

Open
Nabeelahh wants to merge 4 commits into
Kqirox:mainfrom
Nabeelahh:feat/replace-inline-require-admin
Open

reeplace#58
Nabeelahh wants to merge 4 commits into
Kqirox:mainfrom
Nabeelahh:feat/replace-inline-require-admin

Conversation

@Nabeelahh

Copy link
Copy Markdown

closes #28

Summary

This PR addresses the inconsistent and verbose admin authorization pattern across all six contracts by introducing a shared helper and standardized error handling. The changes eliminate boilerplate, ensure consistent error messages, and improve maintainability.

Changes

  • Added contracts/common/src/auth.rs with require_admin() helper
  • Added contracts/common/src/errors.rs with ContractError enum
  • Migrated all six contracts to use the new helper
  • Standardized error handling with proper Soroban error codes
  • Added comprehensive tests for edge cases

Test Plan

  • All existing contract tests pass
  • New helper unit tests added:
    • test_require_admin_success()
    • test_require_admin_failure()
    • test_require_admin_uninitialized()
    • test_error_encoding()
  • Integration tests verify consistent error behavior
  • grep -r "Unauthorized" contracts/*/src/lib.rs returns only references in error enum

Checklist

  • cargo fmt --check passes
  • cargo clippy -D warnings passes
  • cargo test passes

Impact on All Contracts

  1. Pool Factory: Admin initialization and management
  2. Pool Router: Protocol admin functions
  3. Pool: Fee and admin parameter updates
  4. Fee Distributor: Withdrawal and configuration
  5. Staking: Reward rate and admin controls
  6. Token: Mint/burn admin permissions

Migration Complete

  • ✅ All six contracts updated to use require_admin()
  • ✅ Inconsistent error messages replaced with ContractError::Unauthorized
  • expect() replaced with proper error handling
  • ✅ Tests updated to expect standardized error codes

- Create contracts-common crate with require_admin helper and ContractError enum
- Migrate all 6 contracts to use centralized require_admin helper
- Remove test snapshots from git tracking and add to .gitignore
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.

[28] Replace inline require_admin boilerplate with a shared helper

1 participant