Skip to content

Add createERC20TokenPeriodTransferTerms for @metamask/delegation-core#15

Merged
jeffsmale90 merged 2 commits into
mainfrom
feat/erc20PeriodTransfer
Jul 1, 2025
Merged

Add createERC20TokenPeriodTransferTerms for @metamask/delegation-core#15
jeffsmale90 merged 2 commits into
mainfrom
feat/erc20PeriodTransfer

Conversation

@jeffsmale90

@jeffsmale90 jeffsmale90 commented Jul 1, 2025

Copy link
Copy Markdown
Collaborator

📝 Description

Adds terms builder to @metamask/delegation-core for the ERC20 Token Periodic Transfer caveat builder.

🔄 What Changed?

List the specific changes made:

  • Adds createERC20TokenPeriodTransferTerms function to @metamask/delegation-core
  • Updates erc20PeriodTransferBuilder to consume this new terms builder
  • Simplifies createERC20StreamingTerms, by using the prefixed token address, instead of stripping the prefix, and re-adding later.

🚀 Why?

This caveat is now used within the readable permissions gator snaps, so building the terms must be performed within @metamask/delegation-core, so as to not require @metamask/delegation-toolkit dependency within the snaps.

🧪 How to Test?

Existing unit tests for erc20PeriodTransferBuilder, and e2e integration tests cover this functionality, as well as new unit tests covering the new createERC20TokenPeriodTransferTerms function.

⚠️ Breaking Changes

List any breaking changes:

  • No breaking changes
  • Breaking changes (describe below):

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes #
Related to #

📚 Additional Notes

Any additional information, concerns, or context:

@jeffsmale90 jeffsmale90 changed the title Add erc20TokenPeriodicTransfer terms builder Add createERC20TokenPeriodTransferTerms for @metamask/delegation-core Jul 1, 2025
@jeffsmale90 jeffsmale90 force-pushed the feat/erc20PeriodTransfer branch 2 times, most recently from 779e02e to 9ab2e58 Compare July 1, 2025 02:16
@jeffsmale90 jeffsmale90 marked this pull request as ready for review July 1, 2025 02:17
@jeffsmale90 jeffsmale90 requested a review from a team as a code owner July 1, 2025 02:17
@jeffsmale90 jeffsmale90 force-pushed the feat/erc20PeriodTransfer branch from 9ab2e58 to 7e2f727 Compare July 1, 2025 03:01
@jeffsmale90 jeffsmale90 requested a review from Copilot July 1, 2025 04:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a new terms builder for periodic ERC20 token transfers in @metamask/delegation-core and updates related builders to use prefixed addresses.

  • Introduce createERC20TokenPeriodTransferTerms in the core package.
  • Update erc20PeriodTransferBuilder in the toolkit to call the new core function.
  • Simplify ERC20 streaming builder to include the full 0x-prefixed address.
  • Export and document the new terms builder in the core README.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/delegation-toolkit/src/caveatBuilder/erc20PeriodTransferBuilder.ts Replace manual term concatenation and validation with core’s createERC20TokenPeriodTransferTerms.
packages/delegation-core/src/index.ts Export createERC20TokenPeriodTransferTerms.
packages/delegation-core/src/caveats/index.ts Add export for the new caveat terms builder.
packages/delegation-core/src/caveats/erc20TokenPeriodTransfer.ts Implement new terms builder with validation and encoding logic.
packages/delegation-core/src/caveats/erc20Streaming.ts Rename tokenAddressHex to prefixedTokenAddressHex and include full 0x prefix.
packages/delegation-core/README.md Document the new createERC20TokenPeriodTransferTerms API.
Comments suppressed due to low confidence (2)

packages/delegation-core/README.md:199

  • The documentation states the terms are 128 bytes (32 bytes per parameter), but the implementation uses a 20-byte address plus three 32-byte values (116 bytes total). Please update the description to match the actual encoding or pad the address to 32 bytes.
**Returns:** `Hex | Uint8Array` - 128-byte encoded terms (32 bytes per parameter)

packages/delegation-core/src/caveats/erc20Streaming.ts:74

  • [nitpick] Consider renaming prefixedTokenAddressHex to a more concise or descriptive name such as tokenAddressWithPrefix, or revert to tokenAddressHex if the prefixing behavior is consistent across builders.
  let prefixedTokenAddressHex: string;

Comment thread packages/delegation-core/src/caveats/erc20TokenPeriodTransfer.ts
@jeffsmale90 jeffsmale90 merged commit a84f872 into main Jul 1, 2025
15 checks passed
@jeffsmale90 jeffsmale90 deleted the feat/erc20PeriodTransfer branch July 1, 2025 21:32
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.

3 participants