Skip to content

Improve @metamask/delegation-abis tree-shakability#131

Merged
jeffsmale90 merged 6 commits intomainfrom
feat/delegation-abis-architecture
Jan 20, 2026
Merged

Improve @metamask/delegation-abis tree-shakability#131
jeffsmale90 merged 6 commits intomainfrom
feat/delegation-abis-architecture

Conversation

@jeffsmale90
Copy link
Collaborator

@jeffsmale90 jeffsmale90 commented Jan 19, 2026

📝 Description

This PR improves the tree-shakability of @metamask/delegation-abis, so that bundled apps aren't bloated by unnecessary abi and bytecode data.

Note: this PR contains generated code - view by individual changes to see the file updates vs generated

🔄 What Changed?

Various changes to improve tree-shakability of @metamask/delegation-abis:

  • removes bytecode from default package export of @metamask/delegation-abis
  • adds new package export @metamask/delegation-abis/bytecode for each contract
  • shuffle @metamask/delegation-abi source files into src/abis, src/bytecode and src/artifacts
  • updates @metamask/delegation-abi scripts/format-abis.js to ESM
  • disable bundling in tsup to avoid large chunks - this requires an esbuild plugin to rewrite relative imports to include the appropriate file extension

deploySmartAccountsEnvironment is still included as part of @metamask/smart-accounts-kit, which introduces all of the bytecodes. We may wish to decouple that in a separate PR.

🚀 Why?

The @metamask/delegation-abi package includes all typescript ABI declarations for Delegation Framework. It also includes bytecode for each contract, to facilitate deploySmartAccountsEnvironment utility function. Dapp bundles depending on @metamask/smart-accounts-kit are unnecessarily bundling all ABI files, including bytecode. This change ensures that only the ABIs necessary for a bundled dapp are included.

🧪 How to Test?

Describe how to test these changes:

  • Ensure all functionality behaves the same.
  • Compare bundle size and visualisation of dapp depending on @metamask/smart-accounts-kit to ensure that no unnecessary artifacts from @metamask/delegation-abis is bundled

I've validated that both abis and bytecode can be included both via cjs and esm.

⚠️ Breaking Changes

  • No breaking changes

  • Breaking changes (describe below):

  • NarrowAbiToFunction utility type is removed

  • @metamask/delegation-abis previously exported an object { abi, bytecode } for each contract, and now exports the abi directly (no bytecode, no top-level object)

📋 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:


Note

Makes @metamask/delegation-abis more tree‑shakable by decoupling ABIs from bytecode and restructuring build outputs.

  • Removes bytecode from all ABI modules; ABIs live in src/abis/* and bytecode in src/bytecode/*
  • Adds package export @metamask/delegation-abis/bytecode and generates dist/bytecode.* via updated scripts/format-abis.js (now ESM) and scripts/generate.sh
  • Generates clean src/index.ts (ABIs) and src/bytecode.ts (bytecodes) with sorted named exports
  • Introduces scripts/fixExtensionsPlugin.ts to rewrite relative imports for non-bundled tsup builds
  • Moves artifacts input to src/artifacts/ and updates generation pipeline

Breaking change: default exports now expose abi only (previous { abi, bytecode } removed).

Written by Cursor Bugbot for commit eff4692. This will update automatically on new commits. Configure here.

@jeffsmale90 jeffsmale90 force-pushed the feat/delegation-abis-architecture branch from 0e3f7eb to e64392b Compare January 19, 2026 02:56
@jeffsmale90 jeffsmale90 force-pushed the feat/delegation-abis-architecture branch 2 times, most recently from 930b7d3 to 98c41e4 Compare January 19, 2026 22:24
@jeffsmale90 jeffsmale90 force-pushed the feat/delegation-abis-architecture branch 2 times, most recently from 4979884 to 9c336c9 Compare January 19, 2026 22:43
@jeffsmale90 jeffsmale90 marked this pull request as ready for review January 19, 2026 22:59
@jeffsmale90 jeffsmale90 requested a review from a team as a code owner January 19, 2026 22:59
Copy link

@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 2 potential issues.

…t_ update generated files

 - remove bytecodes from default export @metamask/delegation-abis
 - add new export @metamask/delegation-abis/bytecode
 - shuffle src files into src/abis, src/bytecode and src/artifacts
 - updates scripts/format-abis.js to ESM
 - disable bundling in tsup to avoid large chunks
 - adds plugin to rewrite relative import file extensions
@jeffsmale90 jeffsmale90 force-pushed the feat/delegation-abis-architecture branch from 9c336c9 to eff4692 Compare January 20, 2026 00:36
@jeffsmale90 jeffsmale90 merged commit a8bd99a into main Jan 20, 2026
17 checks passed
@jeffsmale90 jeffsmale90 deleted the feat/delegation-abis-architecture branch January 20, 2026 18:51
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