Skip to content

Commit

Permalink
feat: update to latest erc version
Browse files Browse the repository at this point in the history
  • Loading branch information
kopy-kat committed Feb 23, 2024
1 parent d291b05 commit 100d124
Show file tree
Hide file tree
Showing 41 changed files with 245 additions and 314 deletions.
4 changes: 1 addition & 3 deletions accounts/safe7579/test/mocks/MockExecutor.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IExecutor, EncodedModuleTypes } from "erc7579/interfaces/IERC7579Module.sol";
import { IExecutor } from "erc7579/interfaces/IERC7579Module.sol";
import { IERC7579Account, Execution } from "erc7579/interfaces/IERC7579Account.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
Expand Down Expand Up @@ -41,8 +41,6 @@ contract MockExecutor is IExecutor {
return typeID == 2;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions accounts/safe7579/test/mocks/MockFallback.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IFallback, EncodedModuleTypes } from "erc7579/interfaces/IERC7579Module.sol";
import { IFallback } from "erc7579/interfaces/IERC7579Module.sol";
import { IERC7579Account, Execution } from "erc7579/interfaces/IERC7579Account.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
Expand All @@ -25,8 +25,6 @@ contract MockFallback is IFallback, HandlerContext {
return typeID == 3;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
Expand Down
4 changes: 1 addition & 3 deletions accounts/safe7579/test/mocks/MockHook.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import { IHook, EncodedModuleTypes } from "erc7579/interfaces/IERC7579Module.sol";
import { IHook } from "erc7579/interfaces/IERC7579Module.sol";

contract MockHook is IHook {
function onInstall(bytes calldata data) external override { }
Expand All @@ -21,8 +21,6 @@ contract MockHook is IHook {
return typeID == 4;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
Expand Down
5 changes: 1 addition & 4 deletions accounts/safe7579/test/mocks/MockValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ pragma solidity ^0.8.23;
import {
IValidator,
PackedUserOperation,
VALIDATION_SUCCESS,
EncodedModuleTypes
VALIDATION_SUCCESS
} from "erc7579/interfaces/IERC7579Module.sol";

contract MockValidator is IValidator {
Expand Down Expand Up @@ -41,8 +40,6 @@ contract MockValidator is IValidator {
return typeID == 1;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return false;
}
Expand Down
3 changes: 0 additions & 3 deletions examples/src/ColdStorage-SubAccount/ColdStorageExecutor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { IERC7579Account } from "@rhinestone/modulekit/src/Accounts.sol";
import { ERC7579ExecutorBase } from "@rhinestone/modulekit/src/Modules.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

contract ColdStorageExecutor is ERC7579ExecutorBase {
error UnauthorizedAccess();
Expand Down Expand Up @@ -33,8 +32,6 @@ contract ColdStorageExecutor is ERC7579ExecutorBase {
return typeID == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return _subAccountOwner[smartAccount] != address(0);
}
Expand Down
6 changes: 2 additions & 4 deletions examples/src/ColdStorage-SubAccount/ColdStorageHook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { EnumerableMap } from "@openzeppelin/contracts/utils/structs/EnumerableMap.sol";
import { ERC7579HookDestruct } from "@rhinestone/modulekit/src/modules/ERC7579HookDestruct.sol";
import { Execution } from "@rhinestone/modulekit/src/Accounts.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

contract ColdStorageHook is ERC7579HookDestruct {
error UnsupportedExecution();
Expand Down Expand Up @@ -210,7 +209,8 @@ contract ColdStorageHook is ERC7579HookDestruct {
if (target == address(this) && functionSig == this.requestTimelockedExecution.selector) {
return abi.encode(this.requestTimelockedExecution.selector);
} else {
bytes32 executionHash = _execDigestMemory(target, value, callData);
bytes32 executionHash =
_execDigestMemory(target, value, callData[0:callData.length - 8]);
(bool success, bytes32 entry) = executions[msg.sender].tryGet(executionHash);

if (!success) revert InvalidExecutionHash(executionHash);
Expand Down Expand Up @@ -280,7 +280,5 @@ contract ColdStorageHook is ERC7579HookDestruct {
return isType == TYPE_HOOK;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }
}
3 changes: 0 additions & 3 deletions examples/src/ColdStorage-SubAccount/FlashloanCallback.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { IFallbackMethod } from "@rhinestone/modulekit/src/core/ExtensibleFallba

import { ERC7579ExecutorBase } from "@rhinestone/modulekit/src/Modules.sol";
import "./interfaces/Flashloan.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

contract FlashloanCallback is IFallbackMethod, ERC7579ExecutorBase {
address immutable FALLBACK_HANDLER;
Expand Down Expand Up @@ -90,7 +89,5 @@ contract FlashloanCallback is IFallbackMethod, ERC7579ExecutorBase {
return isType == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }
}
3 changes: 0 additions & 3 deletions examples/src/ColdStorage-SubAccount/FlashloanLender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import "forge-std/interfaces/IERC721.sol";
import { IFallbackMethod } from "@rhinestone/modulekit/src/core/ExtensibleFallbackHandler.sol";
import { ERC7579ExecutorBase } from "@rhinestone/modulekit/src/Modules.sol";
import "./interfaces/Flashloan.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

pragma solidity ^0.8.20;

Expand Down Expand Up @@ -183,7 +182,5 @@ contract FlashloanLender is IFallbackMethod, ERC7579ExecutorBase {
return isType == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }
}
28 changes: 2 additions & 26 deletions examples/src/DollarCostAverage/DollarCostAverage.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import "@rhinestone/sessionkeymanager/src/ISessionValidationModule.sol";
import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { UniswapV3Integration } from "@rhinestone/modulekit/src/integrations/uniswap/v3/Uniswap.sol";
import { Execution, IERC7579Account } from "@rhinestone/modulekit/src/Accounts.sol";
import { ERC7579ExecutorBase } from "@rhinestone/modulekit/src/Modules.sol";
import { ERC7579ExecutorBase, SessionKeyBase } from "@rhinestone/modulekit/src/Modules.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

contract DollarCostAverage is ERC7579ExecutorBase, ISessionValidationModule {
contract DollarCostAverage is ERC7579ExecutorBase, SessionKeyBase {
struct ScopedAccess {
address sessionKeySigner;
address onlyTokenIn;
Expand All @@ -29,11 +27,6 @@ contract DollarCostAverage is ERC7579ExecutorBase, ISessionValidationModule {
uint128 amount;
}

error InvalidMethod(bytes4);
error InvalidValue();
error InvalidAmount();
error InvalidTarget();
error InvalidRecipient();
error InvalidParams();

mapping(address account => mapping(address token => SpentLog)) internal _log;
Expand Down Expand Up @@ -91,21 +84,6 @@ contract DollarCostAverage is ERC7579ExecutorBase, ISessionValidationModule {

function onUninstall(bytes calldata data) external override { }

modifier onlyThis(address destinationContract) {
if (destinationContract != address(this)) revert InvalidTarget();
_;
}

modifier onlyFunctionSig(bytes4 allowed, bytes4 received) {
if (allowed != received) revert InvalidMethod(received);
_;
}

modifier onlyZeroValue(uint256 callValue) {
if (callValue != 0) revert InvalidValue();
_;
}

function encode(ScopedAccess memory transaction) public pure returns (bytes memory) {
return abi.encode(transaction);
}
Expand All @@ -118,8 +96,6 @@ contract DollarCostAverage is ERC7579ExecutorBase, ISessionValidationModule {
return typeID == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }

function name() external pure virtual returns (string memory) {
Expand Down
2 changes: 1 addition & 1 deletion examples/src/SmartActions/ScheduledOrders.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";

abstract contract ScheduledOrders is SchedulingBase {
contract ScheduledOrders is SchedulingBase {
function executeOrder(uint256 jobId) external override canExecute(jobId) {
ExecutionConfig storage executionConfig = _executionLog[msg.sender][jobId];

Expand Down
2 changes: 1 addition & 1 deletion examples/src/SmartActions/ScheduledTransfers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SchedulingBase } from "./SchedulingBase.sol";
import { ModeLib } from "erc7579/lib/ModeLib.sol";
import { ExecutionLib } from "erc7579/lib/ExecutionLib.sol";

abstract contract ScheduledTransfers is SchedulingBase {
contract ScheduledTransfers is SchedulingBase {
function executeOrder(uint256 jobId) external override canExecute(jobId) {
ExecutionConfig storage executionConfig = _executionLog[msg.sender][jobId];

Expand Down
43 changes: 22 additions & 21 deletions examples/src/SmartActions/SchedulingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,17 @@ pragma solidity ^0.8.23;

import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { IERC7579Account } from "@rhinestone/modulekit/src/Accounts.sol";
import { ERC7579ExecutorBase } from "@rhinestone/modulekit/src/Modules.sol";
import "@rhinestone/sessionkeymanager/src/ISessionValidationModule.sol";
import { EncodedModuleTypes } from "erc7579/lib/ModuleTypeLib.sol";
import { ERC7579ExecutorBase, SessionKeyBase } from "@rhinestone/modulekit/src/Modules.sol";

abstract contract SchedulingBase is ERC7579ExecutorBase, ISessionValidationModule {
abstract contract SchedulingBase is ERC7579ExecutorBase, SessionKeyBase {
error InvalidExecution();
error InvalidMethod(bytes4);
error InvalidValue();
error InvalidAmount();
error InvalidTarget();
error InvalidRecipient();

error InvalidInstall();

error InvalidJob();

event ExecutionAdded(address indexed smartAccount, uint256 indexed jobId);

event ExecutionTriggered(address indexed smartAccount, uint256 indexed jobId);

event ExecutionStatusUpdated(address indexed smartAccount, uint256 indexed jobId);
event ExecutionsCancelled(address indexed smartAccount);

mapping(address smartAccount => mapping(uint256 jobId => ExecutionConfig)) internal
_executionLog;
Expand Down Expand Up @@ -140,7 +130,12 @@ abstract contract SchedulingBase is ERC7579ExecutorBase, ISessionValidationModul
revert InvalidInstall();
}

ExecutionConfig memory executionConfig = abi.decode(data, (ExecutionConfig));
(
uint48 executeInterval,
uint16 numberOfExecutions,
uint48 startDate,
bytes memory executionData
) = abi.decode(data, (uint48, uint16, uint48, bytes));

uint256 jobId = _accountJobCount[msg.sender] + 1;
_accountJobCount[msg.sender]++;
Expand All @@ -149,11 +144,13 @@ abstract contract SchedulingBase is ERC7579ExecutorBase, ISessionValidationModul
numberOfExecutionsCompleted: 0,
isEnabled: true,
lastExecutionTime: 0,
executeInterval: executionConfig.executeInterval,
numberOfExecutions: executionConfig.numberOfExecutions,
startDate: executionConfig.startDate,
executionData: executionConfig.executionData
executeInterval: executeInterval,
numberOfExecutions: numberOfExecutions,
startDate: startDate,
executionData: executionData
});

emit ExecutionAdded(msg.sender, jobId);
}

function getAccountJobDetails(
Expand All @@ -167,20 +164,24 @@ abstract contract SchedulingBase is ERC7579ExecutorBase, ISessionValidationModul
return _executionLog[smartAccount][jobId];
}

function onUninstall() external {
function getAccountJobCount(address smartAccount) external view returns (uint256) {
return _accountJobCount[smartAccount];
}

function onUninstall(bytes calldata) external {
uint256 count = _accountJobCount[msg.sender];
for (uint256 i = 1; i <= count; i++) {
delete _executionLog[msg.sender][i];
}
_accountJobCount[msg.sender] = 0;

emit ExecutionsCancelled(msg.sender);
}

function isModuleType(uint256 typeID) external pure override returns (bool) {
return typeID == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) {
return _accountJobCount[smartAccount] != 0;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {
ERC20Integration,
ERC4626Integration,
UniswapV3Integration
} from "@rhinestone/modulekit/src/Integrations.sol";
import { ERC20Integration, ERC4626Integration } from "@rhinestone/modulekit/src/Integrations.sol";
import { IERC20 } from "forge-std/interfaces/IERC20.sol";
import { IERC4626 } from "forge-std/interfaces/IERC4626.sol";
import { UniswapV3Integration } from "@rhinestone/modulekit/src/Integrations.sol";
import { Execution } from "@rhinestone/modulekit/src/Accounts.sol";
import { ERC7579ExecutorBase, SessionKeyBase } from "@rhinestone/modulekit/src/Modules.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

import "forge-std/console2.sol";

Expand Down Expand Up @@ -141,8 +137,6 @@ contract AutoSavingToVault is ERC7579ExecutorBase, SessionKeyBase {
return typeID == TYPE_EXECUTOR;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }

function name() external pure virtual returns (string memory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ERC7579ValidatorBase, ERC7579HookBase } from "@rhinestone/modulekit/src
import { PackedUserOperation } from "@rhinestone/modulekit/src/ModuleKit.sol";
import { SignatureCheckerLib } from "solady/src/utils/SignatureCheckerLib.sol";
import { ECDSA } from "solady/src/utils/ECDSA.sol";
import { EncodedModuleTypes, ModuleTypeLib, ModuleType } from "erc7579/lib/ModuleTypeLib.sol";

contract DeadmanSwitch is ERC7579HookBase, ERC7579ValidatorBase {
using SignatureCheckerLib for address;
Expand Down Expand Up @@ -52,8 +51,6 @@ contract DeadmanSwitch is ERC7579HookBase, ERC7579ValidatorBase {
return typeID == TYPE_HOOK;
}

function getModuleTypes() external view returns (EncodedModuleTypes) { }

function isInitialized(address smartAccount) external view returns (bool) { }

function preCheck(address, bytes calldata) external returns (bytes memory) {
Expand Down
Loading

0 comments on commit 100d124

Please sign in to comment.