Skip to content

refactor: reduce PaymasterHub bytecode via library extraction#133

Merged
hudsonhrh merged 1 commit intomainfrom
hudsonhrh/testnet-rpc-update
Mar 18, 2026
Merged

refactor: reduce PaymasterHub bytecode via library extraction#133
hudsonhrh merged 1 commit intomainfrom
hudsonhrh/testnet-rpc-update

Conversation

@hudsonhrh
Copy link
Member

Summary

Extract errors, events, and business logic into four specialized libraries to reduce PaymasterHub from 25,434 bytes (858 over limit) to 24,030 bytes (546 under limit), while improving code organization and maintainability.

Changes

  • PaymasterHubErrors: All 38 errors and 22 events with full NatSpec
  • PaymasterGraceLib: Grace period checks and solidarity tier matching
  • PaymasterPostOpLib: Budget adjustments and clamped deductions
  • PaymasterCalldataLib: execute() envelope validation and selector extraction

Optimizations

  • Remove RULE_ID_EXECUTOR (identical to RULE_ID_COARSE, created SDK confusion)
  • Remove totalDeposited field from OrgFinancials (no on-chain readers, event history sufficient)
  • Move getOrgGraceStatus view function to PaymasterHubLens
  • Consolidate duplicate _validateBatchRules loop bodies
  • Extract _setRulesBatch internal helper to deduplicate rule-setting code

Test Plan

  • All 1089 tests pass
  • Contract under 24,576 byte limit
  • Production-ready

🤖 Generated with Claude Code

…solidation

Extract errors, events, and business logic into four specialized libraries to reduce PaymasterHub from 25,434 bytes (858 over limit) to 24,030 bytes (546 under limit), while improving code organization and maintainability.

Changes:
- PaymasterHubErrors: all 38 errors and 22 events with full NatSpec
- PaymasterGraceLib: grace period checks and solidarity tier matching
- PaymasterPostOpLib: budget adjustments and clamped deductions
- PaymasterCalldataLib: execute() envelope validation and selector extraction

Additional optimizations:
- Remove RULE_ID_EXECUTOR (identical to RULE_ID_COARSE, created SDK confusion)
- Remove totalDeposited field from OrgFinancials (no on-chain readers, event history sufficient)
- Move getOrgGraceStatus view function to PaymasterHubLens
- Consolidate duplicate _validateBatchRules loop bodies
- Extract _setRulesBatch internal helper to deduplicate rule-setting code

All 1089 tests pass. Contract is production-ready under size limit.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

Coverage Report

Metric Coverage
Lines 100.00% (0/0)
Statements 100.00% (0/0)
Branches 100.00% (0/0)
Functions 100.00% (0/0)
Coverage by file
File Lines Statements Branches Functions

@hudsonhrh hudsonhrh merged commit 6bfa72d into main Mar 18, 2026
8 checks passed
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