feat: add terms builders to @metamask/delegation-core #139
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.
📝 Description
This adds terms builder utilities to @metamask/delegation-core for all of the caveats that are currently covered by Caveat Builders in @metamask/smart-accounts-kit, ensuring a consistent pattern for all caveat builders.
🔄 What Changed?
🚀 Why?
Previously terms builders were only implemented for caveat enforcers that were needed in lower level consumers, while all other caveat enforcers had encoding logic implemented directly in the caveat builder. This made it more difficult for consumers building lower level applications to leverage @metamask/delegation-core as it was likely that they would need to add the terms builders first.
🧪 How to Test?
Describe how to test these changes:
All existing test automation for Caveat Builders is unchanged - this validates that existing functionality has not changed.
Test automation has been added for all new terms builders.
Manual testing could import each of the terms builders and ensure that the interface is ergonomic and works as expected.
List any breaking changes:
📋 Checklist
Check off completed items:
🔗 Related Issues
Link to related issues:
Closes #
Related to #
📚 Additional Notes
Any additional information, concerns, or context:
Note
Medium Risk
Adds many new encoding helpers and rewires Smart Accounts Kit builders to depend on them; while mostly deterministic encoding/validation, any mismatch in address normalization or ABI packing could subtly change on-chain terms and break redeems.
Overview
Adds missing caveat terms builders to
@metamask/delegation-core(e.g., allowed methods/targets, block/ID/limited calls, exact execution + batch encodings, token balance/transfer/payment/period limits, deployed/ownership/redeemer, and specific action ERC20 batch), each supportinghexorbytesoutput and input validation.Centralizes encoding utilities by introducing
internalUtils(toHexString, address/hex normalization,concatHex), updating existing caveats to use it, and removing the oldutils.ts.Tightens/clarifies behavior with an explicit required check for
createExactCalldataTermsand adds extensive unit tests for all new builders/utilities. Smart Accounts Kit caveat builders are refactored to call the new delegation-core terms builders instead of duplicating encoding logic (viemconcat/encodePacked/encodeAbiParameters).Written by Cursor Bugbot for commit eac9eb7. This will update automatically on new commits. Configure here.