Implemented token renewal system#455
Merged
truthixify merged 3 commits intoDistinctCodes:mainfrom Jan 30, 2026
Merged
Conversation
|
@Lansa-18 is attempting to deploy a commit to the naijabuz's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Token Renewal System Implementation
Issue Reference
Closes #421
Overview
Implementation of the Token Renewal System for ManageHub membership tokens, including automatic renewal options, grace periods for expired tokens, and comprehensive renewal tracking.
Status: ✅ Complete and Tested (51/51 tests passing)
Files Modified
contracts/manage_hub/src/membership_token.rs- Renewal functions and logiccontracts/manage_hub/src/lib.rs- Renewal contract endpointscontracts/manage_hub/src/types.rs- Renewal data structurescontracts/manage_hub/src/errors.rs- Renewal-specific errorscontracts/common_types/src/types.rs- Grace period status enumcontracts/manage_hub/src/subscription.rs- Made USDC getter publiccontracts/manage_hub/src/test.rs- Comprehensive test suite (15 new tests)Acceptance Criteria Implemented
✅ 1. Add
renew_tokenfunction to membership contractrenew_token()function with tier-based pricing integrationtoken_rnwevent with payment details✅ 2. Implement grace period for expired tokens (configurable, default 7 days)
check_and_apply_grace_period()functionGracePeriodvariant toMembershipStatusenumtransfer_token()to prevent transfers during grace periodgrace_inevent when entering grace periodGracePeriodExpirederror if period has lapsed✅ 3. Add automatic renewal configuration and checking
set_renewal_config()(admin-only) andget_renewal_config()functionsRenewalConfigstruct with configurable settings:check_auto_renewal_eligibility()functionAutoRenewalSettingsstruct for user preferencesset_auto_renewal()andget_auto_renewal_settings()for user controlrnw_cfgevent on configuration updates✅ 4. Include payment validation for renewals with configurable fees
✅ 5. Add renewal history tracking
record_renewal()internal functionRenewalHistorystruct tracking:RenewalTriggerenum for tracking renewal sourceget_renewal_history()function for retrieval✅ 6. Update tests for renewal scenarios including edge cases
Implemented 15 comprehensive test cases:
All 51 tests passing successfully
✅ 7. Add renewal eligibility checking functions
check_auto_renewal_eligibility()functionprocess_auto_renewal()before processing✅ 8. Implement renewal notification events
Implemented 6 event types:
rnw_cfg- Renewal configuration updatedtoken_rnw- Token successfully renewedgrace_in- Grace period enteredgrace_ar- Grace period entered due to auto-renewal failureauto_ok- Auto-renewal successfulauto_rnw- Auto-renewal settings updatedAll events include relevant data (amounts, timestamps, status changes)
Key Implementation Details
Data Structures Added
MembershipTokenwith 5 new fields (tier_id, grace period tracking, renewal attempts)RenewalConfig,RenewalHistory,AutoRenewalSettings, andRenewalTriggertypesCore Functions Implemented
renew_token()- Manual renewal with paymentset_renewal_config()/get_renewal_config()- Configuration managementcheck_and_apply_grace_period()- Grace period handlingset_auto_renewal()/get_auto_renewal_settings()- Auto-renewal preferencescheck_auto_renewal_eligibility()- Eligibility checkingprocess_auto_renewal()- Automatic renewal processingget_renewal_history()- History retrievalrecord_renewal()- Internal history recordingError Codes Added
RenewalNotAllowed(Error 46) - Renewals disabled or conditions not metTransferNotAllowedInGracePeriod(Error 47) - Cannot transfer during grace periodGracePeriodExpired(Error 48) - Grace period has lapsedAutoRenewalFailed(Error 49) - Auto-renewal attempt failedDesign Patterns
Testing Results
Integration Points