Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move token receiver functions into account #124

Merged

Conversation

jaypaik
Copy link
Collaborator

@jaypaik jaypaik commented Jan 26, 2024

Motivation

Opening this to collect feedback and consensus around merging the token receiver functions into the account as native functions vs. installing them from a plugin. Motivation is to decrease the amount of gas spent on account creation.

Solution

  • Removed TokenReceiverPlugin.
  • Removed MultiOwnerTokenReceiverMSCAFactory.
  • Added tokensReceived, onERC721Received, onERC1155Received, onERC1155BatchReceived to UpgradeableModularAccount.
    • These bypass runtime validation functions, but they do run execution hooks to still allow for custom automations.
  • Added support for token receiver interface IDs in supportsInterface.
  • Added function selectors for tokensReceived, onERC721Received, onERC1155Received, onERC1155BatchReceived to KnownSelectors.isNativeFunction.
  • Updated tests and README.
  • Reduced optimizer runs to 900 (UpgradeableModularAccount: 24.309 kB)

Tests in #126

@jaypaik jaypaik requested review from adam-alchemy and howydev and removed request for adam-alchemy January 26, 2024 21:31
README.md Outdated Show resolved Hide resolved
@jaypaik jaypaik force-pushed the 01-26-feat_move_token_receiver_functions_into_account branch 4 times, most recently from 7b02860 to e58f45c Compare January 27, 2024 06:19
@jaypaik jaypaik force-pushed the 01-26-feat_move_token_receiver_functions_into_account branch 2 times, most recently from b79fb5e to 4593415 Compare January 27, 2024 06:57
- [Modular Account implementation](src/account)
- [Modular Account factory](src/factory)
- 2 ERC-6900 compatible plugins:
- [MultiOwnerPlugin](src/plugins/owner) is a plugin supporting 1+ ECDSA owners.
Copy link
Contributor

Choose a reason for hiding this comment

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

probably not the PR for it, but we do support contract owners too.

src/account/PluginManagerInternals.sol Outdated Show resolved Hide resolved
@jaypaik jaypaik force-pushed the 01-26-feat_move_token_receiver_functions_into_account branch from 2d3c9c8 to f4ed920 Compare January 29, 2024 21:55
Copy link
Contributor

@adam-alchemy adam-alchemy left a comment

Choose a reason for hiding this comment

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

Looks good, tests reviewed in the stacked PR

@jaypaik jaypaik merged commit 9355395 into develop Jan 29, 2024
3 checks passed
@jaypaik jaypaik deleted the 01-26-feat_move_token_receiver_functions_into_account branch January 29, 2024 22:22
if (interfaceId == type(IPlugin).interfaceId) {
revert IPluginInterfaceNotAllowed();
if (interfaceId == type(IPlugin).interfaceId || interfaceId == _INVALID_INTERFACE_ID) {
revert InterfaceNotAllowed();
Copy link
Collaborator

Choose a reason for hiding this comment

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

The following interface types are also not relevant, although it doesn't really hurt to add them

  • type(IERC721Receiver).interfaceId
  • type(IERC777Recipient).interfaceId
  • type(IERC1155Receiver).interfaceId

Copy link
Collaborator Author

@jaypaik jaypaik Jan 30, 2024

Choose a reason for hiding this comment

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

True. I'll probably leave this one as is since it doesn't hurt, and adding this in will increase contract size.

Copy link
Collaborator

Choose a reason for hiding this comment

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

If you want to reduce the contract size || interfaceId == _INVALID_INTERFACE_ID
is also not really neccesary as it also checked in supportsInterface

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed! But I think this is ever so slightly different, which may justify this one.

  • Without this check, a plugin wanting to add _INVALID_INTERFACE_ID will successfully install but always fail when supportsInterface(_INVALID_INTERFACE_ID) is called, which could be unexpected.
  • Without the token receiver interface checks here, a plugin wanting to add type(IERC721Receiver).interfaceId will successfully install, and supportsInterface(type(IERC721Receiver).interfaceId) will return true as expected.

_doPreExecHooks(_getAccountStorage().selectorData[msg.sig], "");
selector = IERC721Receiver.onERC721Received.selector;
_postNativeFunction(postExecHooks, postHookArgs);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In order to override onERC721Received(), while still keeping the hooks, it might be useful
that onERC721Received() calls another function (which is initially empty), that can be overriden

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea. Addressed in #127 !

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.

4 participants