Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/modular-etherspot-wallet/interfaces/IAggregatorV3Interface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// solhint-disable-next-line interface-starts-with-i
interface IAggregatorV3Interface {
function decimals() external view returns (uint8);

function description() external view returns (string memory);

function version() external view returns (uint256);

function getRoundData(
uint80 _roundId
) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);

function latestRoundData()
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
93 changes: 93 additions & 0 deletions src/modular-etherspot-wallet/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;

/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);

/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);

/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);

/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() external view returns (uint8);

/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);

/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);

/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);

/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);

/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.23;

import {IValidator} from "../../../src/modular-etherspot-wallet/erc7579-ref-impl/interfaces/IERC7579Module.sol";
import {IERC7579Account} from "../../../src/modular-etherspot-wallet/erc7579-ref-impl/interfaces/IERC7579Account.sol";
import {PackedUserOperation} from "../../../account-abstraction/contracts/interfaces/PackedUserOperation.sol";

/// @title MultiTokenSessionKeyValidator Interface
/// @author Etherspot
/// @notice This interface defines the functions and events of the MultiTokenSessionKeyValidator contract.
interface IMultiTokenSessionKeyValidator is IValidator {
/// @notice Emitted when the MultiToken Session Key Validator module is installed for a wallet.
/// @param wallet The address of the wallet for which the module is installed.
event MTSKV_ModuleInstalled(address wallet);

/// @notice Emitted when the MultiToken Session Key Validator module is uninstalled from a wallet.
/// @param wallet The address of the wallet from which the module is uninstalled.
event MTSKV_ModuleUninstalled(address wallet);

/// @notice Emitted when a new session key is enabled for a wallet.
/// @param sessionKey The address of the session key.
/// @param wallet The address of the wallet for which the session key is enabled.
event MTSKV_SessionKeyEnabled(address sessionKey, address wallet);

/// @notice Emitted when a session key is disabled for a wallet.
/// @param sessionKey The address of the session key.
/// @param wallet The address of the wallet for which the session key is disabled.
event MTSKV_SessionKeyDisabled(address sessionKey, address wallet);

/// @notice Emitted when a session key is paused for a wallet.
/// @param sessionKey The address of the session key.
/// @param wallet The address of the wallet for which the session key is paused.
event MTSKV_SessionKeyPaused(address sessionKey, address wallet);

/// @notice Emitted when a session key is unpaused for a wallet.
/// @param sessionKey The address of the session key.
/// @param wallet The address of the wallet for which the session key is unpaused.
event MTSKV_SessionKeyUnpaused(address sessionKey, address wallet);

/// @notice Struct representing the data associated with a session key.
struct MultiTokenSessionData {
address[] tokens;
bytes4 funcSelector; // The function selector for the allowed operation (e.g., transfer, transferFrom).
uint256 cumulativeSpendingLimitInUsd; // The total spending limit in USD.
uint48 validAfter; // The timestamp after which the session key is valid.
uint48 validUntil; // The timestamp until which the session key is valid.
bool live; // Flag indicating whether the session key is paused or not.
}

/// @notice Enables a new session key for the caller's wallet.
/// @param _sessionData The encoded session data containing the session key address, token address, interface ID, function selector, spending limit, valid after timestamp, and valid until timestamp.
function enableSessionKey(bytes calldata _sessionData) external;

/// @notice Disables a session key for the caller's wallet.
/// @param _session The address of the session key to disable.
function disableSessionKey(address _session) external;

/// @notice Rotates a session key by disabling the old one and enabling a new one.
/// @param _oldSessionKey The address of the old session key to disable.
/// @param _newSessionData The encoded session data for the new session key.
function rotateSessionKey(
address _oldSessionKey,
bytes calldata _newSessionData
) external;

/// @notice Toggles the pause state of a session key for the caller's wallet.
/// @param _sessionKey The address of the session key to toggle the pause state for.
function toggleSessionKeyPause(address _sessionKey) external;

/// @notice Checks if a session key is paused for the caller's wallet.
/// @param _sessionKey The address of the session key to check.
/// @return paused True if the session key is paused, false otherwise.
function isSessionKeyLive(
address _sessionKey
) external view returns (bool paused);

/// @notice Validates the parameters of a session key for a given user operation.
/// @param _sessionKey The address of the session key.
/// @param userOp The packed user operation containing the call data.
/// @return True if the session key parameters are valid for the user operation, false otherwise.
function validateSessionKeyParams(
address _sessionKey,
PackedUserOperation calldata userOp
) external returns (bool);

/// @notice Returns the list of associated session keys for the caller's wallet.
/// @return keys The array of associated session key addresses.
function getAssociatedSessionKeys()
external
view
returns (address[] memory keys);

/// @notice Returns the session data for a given session key and the caller's wallet.
/// @param _sessionKey The address of the session key.
/// @return data The session data struct.
function getSessionKeyData(
address _sessionKey
) external view returns (MultiTokenSessionData memory data);

/// @notice Validates a user operation using a session key.
/// @param userOp The packed user operation.
/// @param userOpHash The hash of the user operation.
/// @return validationData The validation data containing the expiration time and valid after timestamp of the session key.
function validateUserOp(
PackedUserOperation calldata userOp,
bytes32 userOpHash
) external returns (uint256 validationData);

/// @notice Checks if the module type matches the validator module type.
/// @param moduleTypeId The module type ID to check.
/// @return True if the module type matches the validator module type, false otherwise.
function isModuleType(uint256 moduleTypeId) external pure returns (bool);

/// @notice Placeholder function for module installation.
/// @param data The data to pass during installation.
function onInstall(bytes calldata data) external;

/// @notice Placeholder function for module uninstallation.
/// @param data The data to pass during uninstallation.
function onUninstall(bytes calldata data) external;

/// @notice Reverts with a "NotImplemented" error.
/// @param sender The address of the sender.
/// @param hash The hash of the message.
/// @param data The data associated with the message.
/// @return A bytes4 value indicating the function is not implemented.
function isValidSignatureWithSender(
address sender,
bytes32 hash,
bytes calldata data
) external view returns (bytes4);

/// @notice Reverts with a "NotImplemented" error.
/// @param smartAccount The address of the smart account.
/// @return True if the smart account is initialized, false otherwise.
function isInitialized(address smartAccount) external view returns (bool);

function addAllowedTokens(address[] memory _tokens, address[] memory _priceFeeds) external;

function removeAllowedTokens(address[] memory _tokens) external;

function updatePriceFeeds(address[] memory _tokens, address[] memory _priceFeeds) external;

function estimateTotalSpentAmountInUsd(address sessionKey, address token, uint256 amount) external view returns (uint256);

function isEstimatedTotalUsdSpentWithInLimits(address sessionKey, address user, address token, uint256 amount) external view returns (bool);
}
Loading