Skip to content

Commit

Permalink
add canSpendNativeToken support in code
Browse files Browse the repository at this point in the history
  • Loading branch information
fangting-alchemy committed Nov 29, 2023
1 parent 590c686 commit 2ee5992
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/account/PluginManagerInternals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ abstract contract PluginManagerInternals is IPluginManager {

// Update components according to the manifest.
// All conflicts should revert.

// Mark whether or not this plugin may spend native token amounts
if (manifest.canSpendNativeToken) {
_storage.pluginData[plugin].canSpendNativeToken = true;
}

length = manifest.executionFunctions.length;
for (uint256 i = 0; i < length;) {
_setExecutionFunction(manifest.executionFunctions[i], plugin);
Expand Down
6 changes: 6 additions & 0 deletions src/account/UpgradeableModularAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ contract UpgradeableModularAccount is
error ExecFromPluginNotPermitted(address plugin, bytes4 selector);
error ExecFromPluginExternalNotPermitted(address plugin, address target, uint256 value, bytes data);
error InvalidConfiguration();
error NativeTokenSpendingNotPermitted(address plugin);
error PostExecHookReverted(address plugin, uint8 functionId, bytes revertReason);
error PreExecHookReverted(address plugin, uint8 functionId, bytes revertReason);
error PreRuntimeValidationHookFailed(address plugin, uint8 functionId, bytes revertReason);
Expand Down Expand Up @@ -235,6 +236,11 @@ contract UpgradeableModularAccount is
bytes4 selector = bytes4(data);
AccountStorage storage _storage = getAccountStorage();

// Make sure plugin is allowed to spend native token.
if (value > 0 && value > msg.value && !_storage.pluginData[msg.sender].canSpendNativeToken) {
revert NativeTokenSpendingNotPermitted(msg.sender);
}

// Check the caller plugin's permission to make this call

// Check the target contract permission.
Expand Down
3 changes: 3 additions & 0 deletions src/libraries/AccountStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ bytes32 constant _ACCOUNT_STORAGE_SLOT = 0x9f09680beaa4e5c9f38841db2460c40149916

struct PluginData {
bool anyExternalExecPermitted;
// boolean to indicate if the plugin can spend native tokens, if any of the execution function can spend
// native tokens, a plugin is considered to be able to spend native tokens of the accounts
bool canSpendNativeToken;
bytes32 manifestHash;
FunctionReference[] dependencies;
// Tracks the number of times this plugin has been used as a dependency function
Expand Down

0 comments on commit 2ee5992

Please sign in to comment.