feat: add asset restore function (#524)#580
Open
Amas-01 wants to merge 1 commit into
Open
Conversation
Add deactivate_asset and restore_asset functions to Asset Registry contract - Add Deactivated status to AssetStatus enum - Add deactivate_asset function to transition Active assets to Deactivated state - Add restore_asset function to transition Deactivated assets back to Active state - Add AssetAlreadyActive (code 21) and AssetNotDeactivated (code 22) error variants - All historical metadata, compliance records, and associations are preserved during deactivation/restoration - Update lifecycle transition rules to include Active <-> Deactivated transitions - Add 11 comprehensive test cases covering happy path, error conditions, authorization, idempotency, and state continuity - Emit asset_deact and asset_rest events with admin as data payload - Include full documentation with state continuity guarantees Fixes StellaBridge#524
|
@Amas-01 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.
PR #524: Add Asset Restore Function for Soroban Asset Registry Contract
Overview
This PR implements the
deactivate_assetandrestore_assetfunctions for the Bridge-Watch Soroban Asset Registry contract, enabling reversible asset lifecycle management with complete state preservation.Closes #524
Problem Statement
The Bridge-Watch contract previously provided no path to temporarily suspend asset monitoring without permanent deletion. Administrators needed a reversible deactivation mechanism that preserves all accumulated state (metadata, compliance records, chain links, oracle feeds, pool associations, version history) while preventing active operations on suspended assets.
Solution
Implemented two complementary functions:
deactivate_asset— Transitions an Active asset to Deactivated state, preserving all historical datarestore_asset— Transitions a Deactivated asset back to Active state, recovering all preserved data intactBoth functions enforce admin-only access, record all transitions in versioned history, emit audit events, and maintain transactional consistency through the existing storage patterns.
Changes Made
1. Asset Status Lifecycle Enhancement
File:
contracts/soroban/src/asset_registry.rsAdded Status Variant
Updated Lifecycle Transitions
The
update_statusfunction now permits:Active → DeactivatedPaused → DeactivatedRestoration is handled exclusively by the dedicated
restore_assetfunction (not viaupdate_status) to ensure proper audit logging and version tracking.2. Error Variants
Added two new error codes following the existing numbering sequence:
3. Implementation: deactivate_asset Function
Authorization: Requires admin permission via
require_auth()State Transitions:
Active→ error ifAssetAlreadyActive(symbol_short!("asset_deact"), asset_code)with admin dataOk(())State Continuity: All fields except
status,version, andupdated_atare preserved.Events Emitted:
(asset_deact, asset_code) → admin_address4. Implementation: restore_asset Function
Authorization: Requires admin permission via
require_auth()State Transitions:
Deactivated→ error ifAssetNotDeactivated(symbol_short!("asset_rest"), asset_code)with admin dataOk(())State Continuity: All fields except
status,version, andupdated_atare preserved and restored unchanged.Events Emitted:
(asset_rest, asset_code) → admin_addressTesting
Test Coverage
Implemented 11 comprehensive test cases in the asset_registry tests module:
test_deactivate_asset_happy_path ✓
test_restore_asset_happy_path ✓
test_deactivate_non_active_asset_fails ✓
AssetAlreadyActiveerror returnedtest_restore_non_deactivated_asset_fails ✓
AssetNotDeactivatederror returnedtest_deactivate_nonexistent_asset_fails ✓
AssetNotFounderror returnedtest_restore_nonexistent_asset_fails ✓
AssetNotFounderror returnedtest_deactivate_unauthorized_fails ✓
test_restore_unauthorized_fails ✓
test_deactivate_restore_idempotency ✓
test_state_continuity_deactivate_restore ✓
test_version_history_tracks_deactivation ✓
Test Results Summary
Verification & Quality Checks
Code Quality
cargo fmt --all -- --check— All files properly formattedcargo clippy -- -D warnings— Zero clippy warningsInvariant Checks (Vacuousness Tests)
All error paths verified to produce zero storage mutations:
Storage Pattern Compliance
env.storage().persistent()patternsave_with_versionState Continuity Audit
Preserved Fields (Unchanged During Deactivation/Restoration)
Modified Fields (Transitioned)
Permission Model
require_auth())freeze_asset,update_status)Event Audit Trail
Deactivation Event
Restoration Event
Both events include admin address for compliance auditing and enable monitoring systems to track all asset lifecycle transitions.
Documentation
Backward Compatibility
Risk Assessment
Mitigated Risks
require_auth()called before all state access