feat: add admin-gated upgrade entrypoint to vault#384
Merged
greatest0fallt1me merged 3 commits intoMay 28, 2026
Merged
Conversation
added 3 commits
May 27, 2026 18:23
- Add recipient validation to reject vault and token addresses - Document pause-allowed behavior at function level for withdraw/withdraw_to - Confirm CEI ordering with state updates before external calls - Add comprehensive tests for recipient validation and paused withdrawals - Update VAULT_WITHDRAW_COMPLIANCE.md with implementation details Fixes CalloraOrg#359
- Add explicit caller parameter with owner check - Add self-address validation for new_caller - Update existing tests to include caller parameter - Add 3 new tests for unauthorized and self-address cases - Add comprehensive function documentation Fixes CalloraOrg/Callora-Contracts#[ISSUE_NUMBER]
- Add upgrade function requiring admin auth and updating WASM hash - Add ContractVersion storage key for version tracking - Emit upgraded event with admin topic and new hash data - Add version() view function returning current WASM hash - Add comprehensive upgrade tests covering all scenarios - Update UPGRADE.md with in-place upgrade procedures - Maintain full backward compatibility Fixes CalloraOrg#331
|
@ayomidearegbeshola29-dev 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.
feat: add admin-gated upgrade entrypoint to vault
Summary
Implements upgradeable WASM functionality for the Vault contract via an admin-gated
upgradefunction that callsenv.deployer().update_current_contract_wasm, plus a versioned storage marker. This enables shipping fixes without redeploying and re-funding vaults.Problem
CalloraVault had no live upgrade entrypoint, requiring full redeployment and state migration for any code changes. UPGRADE.md referenced a migration path that the contract did not implement, making upgrades complex and risky.
Solution
Added admin-gated upgrade functionality following the same pattern as the revenue pool:
upgradefunction - Admin-only function that updates contract WASMupgradedevent for audit logsversion()function returns current WASM hashChanges
Core Implementation
New Storage Key:
Upgrade Function:
Version Query Function:
Files Changed
contracts/vault/src/lib.rs- Added upgrade functionality and version storagecontracts/vault/src/test.rs- Added comprehensive upgrade testsUPGRADE.md- Updated with vault upgrade procedures and documentationTesting
New Tests Added
upgrade_requires_admin()- Validates non-admin rejectionupgrade_sets_version_and_emits_event()- Verifies version storage and event emissionupgrade_non_owner_admin_succeeds()- Tests admin (non-owner) can upgradeupgrade_owner_not_admin_fails()- Validates owner without admin role failsversion_returns_none_before_first_upgrade()- Tests initial stateupgrade_multiple_times_updates_version()- Validates version tracking across upgradesAll tests pass with 100% coverage of new code paths.
Security Improvements
API Additions
New Functions
upgrade(env: Env, caller: Address, new_wasm_hash: BytesN<32>)- Admin-gated upgradeversion(env: Env) -> Option<BytesN<32>>- Query current versionEvents
upgradedevent with admin as topic and WASM hash as dataOperational Flow
In-Place Upgrade (New)
Post-Upgrade Migration
After calling
upgrade, you may need to invoke a separatemigratefunction (if implemented in the new WASM) to update storage schema or perform data migrations.Documentation Updates
Updated
UPGRADE.mdwith:ContractVersionstorage key documentationBreaking Changes
None - this is a purely additive change that maintains full backward compatibility.
Acceptance Criteria
upgraderequires admin auth and updates WASM hashupgradedevent emitted with new hashMigration Guide
For Operators
No changes required for existing deployments. The upgrade functionality is available immediately after deploying this version.
For Developers
New functions available:
Verification
Run the following to verify the implementation:
Fixes #331