Skip to content

feat: add decoding rules for erc20-token-allowance and native-token-allowance#8553

Merged
jeffsmale90 merged 10 commits intomainfrom
feat/allowance-permissions
May 3, 2026
Merged

feat: add decoding rules for erc20-token-allowance and native-token-allowance#8553
jeffsmale90 merged 10 commits intomainfrom
feat/allowance-permissions

Conversation

@jeffsmale90
Copy link
Copy Markdown
Contributor

@jeffsmale90 jeffsmale90 commented Apr 23, 2026

Explanation

Adds Advanced Permission type decoding rules for new permission types:

  • erc20-token-allowance - grants a fixed allowance of a specified ERC20 token
  • native-token-allowance - grants a fixed allowance of the native token

Previous to this change, the decoding logic required a single permission type to match the caveat types included in the delegation. Because these new permissions use the same caveats as the periodic permission types, the decoding logic is updated to filter permission types where the rules match, and require a single matching permission type to successfully validate and decode. erc20-token-periodic and native-token-periodic rules were updated to require periodDuration be less than the maximum allowed by the snap (10 years).

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
Updates permission-type identification to handle multiple candidate rules sharing the same enforcer set, which can change how delegations are classified and surfaced to the UI. While well-covered by new unit tests, decoding/validation logic changes can impact permission interpretation across supported chains.

Overview
Adds decoding support for new advanced permission types native-token-allowance and erc20-token-allowance, including strict term validation/decoding (e.g., UINT256_MAX period duration, non-zero amounts, positive start times) and corresponding test coverage.

Refactors permission-type selection during decodePermissionFromPermissionContextForOrigin to first gather all rules matching the caveat enforcer addresses and then disambiguate by validating caveat terms via selectUniqueRuleAndDecodedPermission, with clearer error cases for no match, no valid candidate, or ambiguous validation.

Tightens decoding constraints for existing native-token-periodic/erc20-token-periodic by enforcing periodDuration <= MAX_PERIOD_DURATION (10 years) and bumps @metamask/7715-permission-types to ^0.6.0.

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

@jeffsmale90 jeffsmale90 requested a review from a team as a code owner April 23, 2026 04:39
@jeffsmale90 jeffsmale90 requested a review from a team as a code owner April 23, 2026 04:40
@jeffsmale90 jeffsmale90 changed the title Feat/allowance permissions feat: add decoding rules for erc20-token-allowance and native-token-allowance Apr 23, 2026
@jeffsmale90 jeffsmale90 marked this pull request as draft April 23, 2026 04:41
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 23, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updated@​metamask/​7715-permission-types@​0.5.0 ⏵ 0.6.010010072 +191 +1100

View full report

@jeffsmale90 jeffsmale90 force-pushed the feat/allowance-permissions branch from 82e535e to ad34e77 Compare April 23, 2026 22:54
@jeffsmale90 jeffsmale90 marked this pull request as ready for review April 23, 2026 22:54
@jeffsmale90 jeffsmale90 marked this pull request as draft April 29, 2026 01:37
@jeffsmale90 jeffsmale90 force-pushed the feat/allowance-permissions branch from c633a82 to fe6301c Compare April 30, 2026 21:58
@jeffsmale90 jeffsmale90 marked this pull request as ready for review April 30, 2026 22:01
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 925b27f. Configure here.

@jeffsmale90 jeffsmale90 force-pushed the feat/allowance-permissions branch from 8d4e794 to a9868cb Compare April 30, 2026 23:14
@jeffsmale90 jeffsmale90 added this pull request to the merge queue May 3, 2026
Merged via the queue into main with commit 2570a55 May 3, 2026
366 checks passed
@jeffsmale90 jeffsmale90 deleted the feat/allowance-permissions branch May 3, 2026 20:00
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.

2 participants