Skip to content

refactor: decompose rule decoders, and refactor permission decoding#8730

Merged
jeffsmale90 merged 9 commits into
mainfrom
refactor/decompose-rule-decoders
May 18, 2026
Merged

refactor: decompose rule decoders, and refactor permission decoding#8730
jeffsmale90 merged 9 commits into
mainfrom
refactor/decompose-rule-decoders

Conversation

@jeffsmale90
Copy link
Copy Markdown
Contributor

@jeffsmale90 jeffsmale90 commented May 7, 2026

Explanation

Refactor of permission decoding logic in order to:

  • clarify terminology (decoders rather than rules - rule is a highly overloaded term)
  • make rule (as in 7155 rules) more composable, rather than inherently part of the decoding process
  • prepare the permission decoders for potential decomposition into a separate package
    no functional change, therefore no changelog required

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Refactors the core permission identification/decoding path (rule matching, validation, and reconstructed output), so subtle mismatches in enforcer selection or rule extraction could change which permission type is detected or what rules/expiry are returned.

Overview
Refactors permission decoding to use permission decoders (terminology change from “rules”) and removes the old decodePermission/rules implementation, including findRuleWithMatchingCaveatAddresses.

Decoding is now driven by createPermissionDecodersForContracts + findDecodersWithMatchingCaveatAddresses and disambiguation via selectUniqueDecoderAndDecodedPermission, with rule extraction split into composable RuleDecoders (new expiry, redeemer, and native/ERC20 payee decoders).

Adds EXECUTION_PERMISSION_EXPIRY_RULE_TYPE and updates tests to reflect the new decoder APIs and to assert the new rule decoding behavior (including emitting an expiry rule and hoisting its timestamp to top-level expiry).

Reviewed by Cursor Bugbot for commit f097d31. Bugbot is set up for automated code reviews on this repo. Configure here.

@jeffsmale90 jeffsmale90 force-pushed the refactor/decompose-rule-decoders branch from 71e997b to 4d784ae Compare May 7, 2026 23:22
@jeffsmale90 jeffsmale90 force-pushed the refactor/decompose-rule-decoders branch from 4d784ae to 98adc20 Compare May 7, 2026 23:25
@jeffsmale90 jeffsmale90 changed the title Rename PermissionRule to PermissionDecoder. Decompose rule decoders f… refactor: decompose rule decoders, and refactor permission decoding May 7, 2026
@jeffsmale90 jeffsmale90 marked this pull request as ready for review May 7, 2026 23:40
@jeffsmale90 jeffsmale90 requested a review from a team as a code owner May 7, 2026 23:40
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit f94844b. Configure here.

mj-kiwi
mj-kiwi previously approved these changes May 18, 2026
Copy link
Copy Markdown
Contributor

@mj-kiwi mj-kiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only minor comment tweaks, otherwise LGTM.

* @param args - The arguments to this function.
* @param args.contractAddresses - Checksummed enforcer addresses for the chain.
* @param args.caveats - Checksummed caveats from the delegation.
* @returns A `{ rule }` result containing the redeemer addresses when a
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return type should be Rule | null

* @param args.contractAddresses - Checksummed enforcer addresses for the chain.
* @param args.caveats - Checksummed caveats from the delegation.
* @param args.requiredEnforcers - Required enforcer counts for the permission.
* @returns A `{ rule }` result containing the payee address when an
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return type should be Rule | null

* @param args.contractAddresses - Checksummed enforcer addresses for the chain.
* @param args.caveats - Checksummed caveats from the delegation.
* @param args.requiredEnforcers - Required enforcer counts for the permission.
* @returns A `{ rule }` result containing the payee addresses when an
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the return type should be Rule | null

Comment on lines 162 to 163
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the address and signer fields that don't exist — the actual output uses from and to. Also omits origin and rules fields.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I removed that entire section of the comment as I think it's unnecessary, given we document the return type

* - All of its required enforcers are present in the provided list; and
* - No provided enforcer falls outside the union of the rule's required and
* - No provided enforcer falls outside the union of the decoder's required and
* optional enforcers (currently only `TimestampEnforcer` is allowed extra).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RedeemerEnforcer, AllowedCalldataEnforcer, and AllowedTargetsEnforcer are also optional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing this function in it's entirety as it's no longer used.

- Update comments on rule decoders to specify correct Rule | null return type
- Remove unused findDecoderWithMatchingCaveatAddresses, and rewrite existing tests to cover plural findDecodersWithMatchingCaveatAddresses
@jeffsmale90 jeffsmale90 requested a review from mj-kiwi May 18, 2026 22:30
@jeffsmale90 jeffsmale90 enabled auto-merge May 18, 2026 22:30
Copy link
Copy Markdown
Contributor

@mj-kiwi mj-kiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just wondering if we should note this breaking change in the changelog.

@jeffsmale90 jeffsmale90 added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit b7c2567 May 18, 2026
370 checks passed
@jeffsmale90 jeffsmale90 deleted the refactor/decompose-rule-decoders branch May 18, 2026 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants