Description:
Multi-signature wallet contract requiring multiple confirmations for transaction execution.
Blockchain: Ethereum
Source Code: View Code On The Blockchain
Solidity Source Code:
{{
"language": "Solidity",
"sources": {
"lib/predicate-contracts/src/examples/inheritance/MetaCoin.sol": {
"content": "// SPDX-License-Identifier: MIT
// Tells the Solidity compiler to compile only from v0.8.13 to v0.9.0
pragma solidity ^0.8.12;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {PredicateClient} from "../../mixins/PredicateClient.sol";
import {PredicateMessage} from "../../interfaces/IPredicateClient.sol";
import {IPredicateManager} from "../../interfaces/IPredicateManager.sol";
contract MetaCoin is PredicateClient, Ownable {
mapping(address => uint256) public balances;
event Transfer(address indexed _from, address indexed _to, uint256 _value);
constructor(address _owner, address _serviceManager, string memory _policyID) Ownable(_owner) {
balances[_owner] = 10_000_000_000_000;
_initPredicateClient(_serviceManager, _policyID);
}
function sendCoin(address _receiver, uint256 _amount, PredicateMessage calldata _message) external payable {
bytes memory encodedSigAndArgs = abi.encodeWithSignature("_sendCoin(address,uint256)", _receiver, _amount);
require(
_authorizeTransaction(_message, encodedSigAndArgs, msg.sender, msg.value),
"MetaCoin: unauthorized transaction"
);
// business logic function that is protected
_sendCoin(_receiver, _amount);
}
function setPolicy(
string memory _policyID
) external onlyOwner {
_setPolicy(_policyID);
}
function setPredicateManager(
address _predicateManager
) public onlyOwner {
_setPredicateManager(_predicateManager);
}
function _sendCoin(address _receiver, uint256 _amount) internal {
require(balances[msg.sender] >= _amount, "MetaCoin: insufficient balance");
balances[msg.sender] -= _amount;
balances[_receiver] += _amount;
emit Transfer(msg.sender, _receiver, _amount);
}
function getBalance(
address _addr
) public view returns (uint256) {
return balances[_addr];
}
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/access/Ownable.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(
address initialOwner
) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(
address newOwner
) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(
address newOwner
) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
"
},
"lib/predicate-contracts/src/mixins/PredicateClient.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import {IPredicateManager, Task} from "../interfaces/IPredicateManager.sol";
import "../interfaces/IPredicateClient.sol";
abstract contract PredicateClient is IPredicateClient {
/// @notice Struct to contain stateful values for PredicateClient-type contracts
/// @custom:storage-location erc7201:predicate.storage.PredicateClient
struct PredicateClientStorage {
IPredicateManager serviceManager;
string policyID;
}
/// @notice the storage slot for the PredicateClientStorage struct
/// @dev keccak256(abi.encode(uint256(keccak256("predicate.storage.PredicateClient")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant _PREDICATE_CLIENT_STORAGE_SLOT =
0x804776a84f3d03ad8442127b1451e2fbbb6a715c681d6a83c9e9fca787b99300;
function _getPredicateClientStorage() private pure returns (PredicateClientStorage storage $) {
assembly {
$.slot := _PREDICATE_CLIENT_STORAGE_SLOT
}
}
function _initPredicateClient(address _serviceManagerAddress, string memory _policyID) internal {
PredicateClientStorage storage $ = _getPredicateClientStorage();
$.serviceManager = IPredicateManager(_serviceManagerAddress);
_setPolicy(_policyID);
}
function _setPolicy(
string memory _policyID
) internal {
PredicateClientStorage storage $ = _getPredicateClientStorage();
$.policyID = _policyID;
$.serviceManager.setPolicy(_policyID);
}
function getPolicy() external view override returns (string memory) {
return _getPolicy();
}
function _getPolicy() internal view returns (string memory) {
return _getPredicateClientStorage().policyID;
}
function _setPredicateManager(
address _predicateManager
) internal {
PredicateClientStorage storage $ = _getPredicateClientStorage();
$.serviceManager = IPredicateManager(_predicateManager);
}
function getPredicateManager() external view override returns (address) {
return _getPredicateManager();
}
function _getPredicateManager() internal view returns (address) {
return address(_getPredicateClientStorage().serviceManager);
}
modifier onlyPredicateServiceManager() {
if (msg.sender != address(_getPredicateClientStorage().serviceManager)) {
revert PredicateClient__Unauthorized();
}
_;
}
/**
*
* @notice Validates the transaction by checking the signatures of the operators.
*/
function _authorizeTransaction(
PredicateMessage memory _predicateMessage,
bytes memory _encodedSigAndArgs,
address _msgSender,
uint256 _value
) internal returns (bool) {
PredicateClientStorage storage $ = _getPredicateClientStorage();
Task memory task = Task({
msgSender: _msgSender,
target: address(this),
value: _value,
encodedSigAndArgs: _encodedSigAndArgs,
policyID: $.policyID,
quorumThresholdCount: uint32(_predicateMessage.signerAddresses.length),
taskId: _predicateMessage.taskId,
expireByTime: _predicateMessage.expireByTime
});
return
$.serviceManager.validateSignatures(task, _predicateMessage.signerAddresses, _predicateMessage.signatures);
}
}
"
},
"lib/predicate-contracts/src/interfaces/IPredicateClient.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import {IPredicateManager} from "../interfaces/IPredicateManager.sol";
/// @notice Struct that bundles together a task's parameters for validation
struct PredicateMessage {
// the unique identifier for the task
string taskId;
// the Timestamp expiry for the task
uint256 expireByTime;
// the operators that have signed the task
address[] signerAddresses;
// the signatures of the operators that have signed the task
bytes[] signatures;
}
/// @notice error type for unauthorized access
error PredicateClient__Unauthorized();
/// @notice Interface for a PredicateClient-type contract that enables clients to define execution rules or parameters for tasks they submit
interface IPredicateClient {
/**
* @notice Sets a policy for the calling address, associating it with a policy document stored on IPFS.
* @param _policyID A string representing the policyID from on chain.
* @dev This function enables clients to define execution rules or parameters for tasks they submit.
* The policy governs how tasks submitted by the caller are executed, ensuring compliance with predefined rules.
*/
function setPolicy(
string memory _policyID
) external;
/**
* @notice Retrieves the policy for the calling address.
* @return The policyID associated with the calling address.
*/
function getPolicy() external view returns (string memory);
/**
* @notice Function for setting the Predicate ServiceManager
* @param _predicateManager address of the service manager
*/
function setPredicateManager(
address _predicateManager
) external;
/**
* @notice Function for getting the Predicate ServiceManager
* @return address of the service manager
*/
function getPredicateManager() external view returns (address);
}
"
},
"lib/predicate-contracts/src/interfaces/IPredicateManager.sol": {
"content": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
/// @notice Struct that bundles together a task's parameters for validation
struct Task {
// the unique identifier for the task
string taskId;
// the address of the sender of the task
address msgSender;
// the address of the target contract for the task
address target;
// the value to send with the task
uint256 value;
// the encoded signature and arguments for the task
bytes encodedSigAndArgs;
// the policy ID associated with the task
string policyID;
// the number of signatures required to authorize the task
uint32 quorumThresholdCount;
// the timestamp by which the task must be executed
uint256 expireByTime;
}
/// @notice Struct that bundles together a signature, a salt for uniqueness, and an expiration time for the signature. Used primarily for stack management.
struct SignatureWithSaltAndExpiry {
// the signature itself, formatted as a single bytes object
bytes signature;
// the salt used to generate the signature
bytes32 salt;
// the expiration timestamp (UTC) of the signature
uint256 expiry;
}
/**
* @title Minimal interface for a ServiceManager-type contract that forms the single point for an AVS to push updates to EigenLayer
* @author Predicate Labs, Inc
*/
interface IPredicateManager {
/**
* @notice Sets the metadata URI for the AVS
* @param _metadataURI is the metadata URI for the AVS
*/
function setMetadataURI(
string memory _metadataURI
) external;
/**
* @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator registration with the AVS
* @param operatorSigningKey The address of the operator's signing key.
* @param operatorSignature The signature, salt, and expiry of the operator's signature.
*/
function registerOperatorToAVS(
address operatorSigningKey,
SignatureWithSaltAndExpiry memory operatorSignature
) external;
/**
* @notice Forwards a call to EigenLayer's DelegationManager contract to confirm operator deregistration from the AVS
* @param operator The address of the operator to deregister.
*/
function deregisterOperatorFromAVS(
address operator
) external;
/**
* @notice Returns the list of strategies that the operator has potentially restaked on the AVS
* @param operator The address of the operator to get restaked strategies for
* @dev This function is intended to be called off-chain
* @dev No guarantee is made on whether the operator has shares for a strategy in a quorum or uniqueness
* of each element in the returned array. The off-chain service should do that validation separately
*/
function getOperatorRestakedStrategies(
address operator
) external view returns (address[] memory);
/**
* @notice Returns the list of strategies that the AVS supports for restaking
* @dev This function is intended to be called off-chain
* @dev No guarantee is made on uniqueness of each element in the returned array.
* The off-chain service should do that validation separately
*/
function getRestakeableStrategies() external view returns (address[] memory);
/**
* @notice Sets a policy ID for the sender, defining execution rules or parameters for tasks
* @param policyID string pointing to the policy details
* @dev Only callable by client contracts or EOAs to associate a policy with their address
* @dev Emits a SetPolicy event upon successful association
*/
function setPolicy(
string memory policyID
) external;
/**
* @notice Deploys a policy with ID with execution rules or parameters for tasks
* @param _policyID string pointing to the policy details
* @param _policy string containing the policy details
* @param _quorumThreshold The number of signatures required to authorize a task
* @dev Only callable by service manager deployer
* @dev Emits a DeployedPolicy event upon successful deployment
*/
function deployPolicy(string memory _policyID, string memory _policy, uint256 _quorumThreshold) external;
/**
* @notice Gets array of deployed policies
*/
function getDeployedPolicies() external view returns (string[] memory);
/**
* @notice Verifies if a task is authorized by the required number of operators
* @param _task Parameters of the task including sender, target, function signature, arguments, quorum count, and expiry block
* @param signerAddresses Array of addresses of the operators who signed the task
* @param signatures Array of signatures from the operators authorizing the task
* @return isVerified Boolean indicating if the task has been verified by the required number of operators
* @dev This function checks the signatures against the hash of the task parameters to ensure task authenticity and authorization
*/
function validateSignatures(
Task memory _task,
address[] memory signerAddresses,
bytes[] memory signatures
) external returns (bool isVerified);
/**
* @notice Adds a new strategy to the Service Manager
* @dev Only callable by the contract owner. Adds a strategy that operators can stake on.
* @param _strategy The address of the strategy contract to add
* @param quorumNumber The quorum number associated with the strategy
* @param index The index of the strategy within the quorum
* @dev Emits a StrategyAdded event upon successful addition of the strategy
* @dev Reverts if the strategy does not exist or is already added
*/
function addStrategy(address _strategy, uint8 quorumNumber, uint256 index) external;
/**
* @notice Removes an existing strategy from the Service Manager
* @dev Only callable by the contract owner. Removes a strategy that operators are currently able to stake on.
* @param _strategy The address of the strategy contract to remove
* @dev Emits a StrategyRemoved event upon successful removal of the strategy
* @dev Reverts if the strategy is not currently added or if the address is invalid
*/
function removeStrategy(
address _strategy
) external;
/**
* @notice Enables the rotation of Predicate Signing Key for an operator
* @param _oldSigningKey address of the old signing key to remove
* @param _newSigningKey address of the new signing key to add
*/
function rotatePredicateSigningKey(address _oldSigningKey, address _newSigningKey) external;
}
"
},
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Context.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
"
}
},
"settings": {
"remappings": [
"@predicate-contracts-v2/=lib/predicate-contracts-v2/",
"@predicate-contracts/=lib/predicate-contracts/",
"forge-std/=lib/forge-std/src/",
"foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin-upgrades-v4.9.0/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/",
"@openzeppelin-upgrades/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable/",
"@openzeppelin-v4.9.0/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-v4.9.0/",
"ds-test/=lib/predicate-contracts/lib/forge-std/lib/ds-test/src/",
"eigenlayer-contracts/=lib/predicate-contracts/lib/eigenlayer-contracts/",
"eigenlayer-middleware/=lib/predicate-contracts/lib/eigenlayer-middleware/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable-v4.9.0/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts-v4.9.0/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-v4.9.0/",
"openzeppelin-contracts/=lib/predicate-contracts/lib/openzeppelin-contracts/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"openzeppelin-upgradeable/=lib/predicate-contracts/lib/openzeppelin-contracts-upgradeable/contracts/",
"openzeppelin/=lib/predicate-contracts/lib/eigenlayer-contracts/lib/openzeppelin-contracts-upgradeable-v4.9.0/contracts/",
"predicate-contracts-v2/=lib/predicate-contracts-v2/src/",
"predicate-contracts/=lib/predicate-contracts/src/",
"solmate/=lib/predicate-contracts/lib/solmate/src/",
"utils/=lib/predicate-contracts/lib/utils/"
],
"optimizer": {
"enabled": false,
"runs": 200
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "prague",
"viaIR": false
}
}}
Submitted on: 2025-10-21 10:03:04
Comments
Log in to comment.
No comments yet.