Skip to content

SubBase V2: Auto-Charge Billing Engine#2

Merged
karinasvatk merged 14 commits into
mainfrom
draft
Dec 5, 2025
Merged

SubBase V2: Auto-Charge Billing Engine#2
karinasvatk merged 14 commits into
mainfrom
draft

Conversation

@karinasvatk

Copy link
Copy Markdown
Owner

🔄 Auto-Charge Billing Engine
The core feature V1 was missing. Subscriptions can now automatically process recurring payments.

New Functions:
-charge(subscriptionId) - Process a single subscription payment
-batchCharge(subscriptionIds[]) - Process up to 50 subscriptions in one transaction
-retryCharge(subscriptionId) - Manually retry failed payments
-reactivate(subscriptionId) - Pay outstanding balance and reactivate suspended subscriptions

Chainlink Automation Integration
SubBase is now Chainlink Automation compatible for fully automated billing.

New Functions:
-checkUpkeep(bytes) - Returns subscriptions ready for charging
-performUpkeep(bytes) - Automatically charges due subscriptions
-Batch processing up to 50 subscriptions per execution

Enhanced Subscription States
Improved lifecycle management with grace periods and retry logic.

New States:
-PastDue - Payment failed, in grace period
-Suspended - Max retries exceeded, requires manual reactivation

- Add PastDue and Suspended subscription statuses
- Add V2 storage variables for charge tracking
- Add failed attempts, last charge attempt, grace period tracking
- Add new errors and events for charge module
- Maintain storage layout compatibility with V1
- Implement charge() for processing subscription payments
- Implement batchCharge() for multiple subscriptions
- Add failed payment handling with grace periods
- Add automatic PastDue and Suspended status transitions
- Implement retry logic with configurable max attempts
- Add reactivate() for suspended subscriptions
- Add admin functions for grace period and retry configuration
- Emit events for charge success, failure, and status changes
- Implement checkUpkeep() for Chainlink Automation
- Implement performUpkeep() for automated charging
- Add batch processing with configurable limits
- Handle partial failures gracefully
- Support continuous automated billing cycles
- Inherit from SubBaseV1 and AutomationModule
- Add initializeV2() for V2-specific configuration
- Maintain UUPS upgradeability
- Add version() function returning 2
- Enable auto-charge billing engine
ChargeModule tests:
- testCharge_Success: Successful charge updates billing time
- testCharge_NotDueYet: Reverts when not due
- testCharge_InsufficientBalance: Marks PastDue on failure
- testCharge_UpdatesNextBillingTime: Verifies billing cycle
- testBatchCharge_MultipleSubscriptions: Batch processing
- testBatchCharge_PartialSuccess: Handles mixed results
- testGetChargeableSubscriptions: Returns due subscriptions
- testRetryCharge_Success: Successful retry reactivates
- testRetryCharge_MaxAttempts: Suspends after max retries
- testGracePeriod_Expiration: Grace period tracking
- testReactivate_PaysOutstanding: Pays and reactivates

AutomationModule tests:
- testCheckUpkeep_ReturnsReadySubscriptions: Chainlink integration
- testPerformUpkeep_ChargesAll: Automated batch charging
- testAutomationWorkflow_MultipleCycles: Multiple billing periods
- testPerformUpkeep_PartialSuccess: Handles failures gracefully
- Deploy SubBaseV2 implementation
- Upgrade proxy from V1 to V2
- Initialize V2 with grace period and max retries
- Support configurable parameters via environment variables
- Verify upgrade and configuration post-deployment
- Create universal deploy.yml with version selection (v1, v2, both)
- Create universal upgrade.yml for upgrading to any version
- Add configurable grace period and max retries for V2
- Remove old CI workflows: coverage, lint, slither, size-check
- Remove old deploy-v1.yml and upgrade-v1.yml
- Keep test.yml for running tests
- Remove duplicate error names (ChargeFailed, SubscriptionSuspended)
- Add onlyOwner modifier override in SubBaseV2
- Change _owner from private to internal in SubBaseV1 for inheritance
- Resolve modifier conflicts between SubBaseV1 and ChargeModule
- Add virtual to onlyOwner modifier in SubBaseV1
- Specify both contracts in override: SubBaseV1 and ChargeModule
- Replace removed SubscriptionSuspended() error with SubscriptionNotActive()
- Remove abstract onlyOwner modifier from ChargeModule
- Simplify override in SubBaseV2 to only override SubBaseV1
- Functions in ChargeModule will use onlyOwner from parent contract
- Add virtual onlyOwner modifier back to ChargeModule
- Override both SubBaseV1 and ChargeModule in SubBaseV2
- Use helper function for cleaner modifier implementation
- Replace virtual onlyOwner modifier in ChargeModule with virtual _checkOwner function
- Implement _checkOwner in SubBaseV2
- Eliminates modifier inheritance conflict between SubBaseV1 and ChargeModule
- ChargeModule admin functions now call _checkOwner() directly
Major Updates:
- ✨ New user-friendly README with Base infrastructure focus
- 📊 Add deployments.json with mainnet & testnet addresses
- 🧹 Remove old development files (ARCHITECTURE.md, contracts.json)
- 🗑️ Remove deprecated UpgradeV1.s.sol script

README Improvements:
- Professional badges and branding
- Quick start guides for creators and subscribers
- Comprehensive integration examples (Solidity + JS/TS)
- Chainlink Automation setup instructions
- Use cases, roadmap, and security info
- SEO-optimized for Base ecosystem indexing

Deployments:
- Base Mainnet: 0xfa34E4c68c77D54dD8B694c8395953465129E3c9 (V2)
- Base Sepolia: 0x8B182755Ae296e8f222Ac4E677B7Cc63dFDe7BA0 (V2)
- Grace Period: 7 days, Max Retries: 3
@karinasvatk
karinasvatk merged commit 5575903 into main Dec 5, 2025
1 check failed
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.

1 participant