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": {
"contracts/permanStorageF.sol": {
"content": "// SPDX-License-Identifier: MIT\r
pragma solidity ^0.8.20;\r
\r
import "@openzeppelin/contracts/access/Ownable.sol";\r
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";\r
\r
contract PermanStorageF is Ownable {\r
// ========== Configurable Parameters ==========\r
uint256 public fee = 0.0005 ether;\r
uint256 public deployFeeParam = 100;\r
uint256 public nextId = 1;\r
uint256 public contractQt = 1;\r
uint256 public blockUpdate=0;\r
bool public updateAllowed = true;\r
\r
\r
bytes public TARGET_BYTECODE;\r
IERC20 public immutable CHAIN_GALLERY_TOKEN;\r
uint256 public constant CHAIN_GALLERY_DEPLOY_AMOUNT = 100 * 10**18;\r
\r
// ========== Constants ==========\r
uint256 private constant OWNER_WITHDRAW_TRIGGER = 0.000001 ether;\r
\r
// ========== Events ==========\r
event ContractDeployed(address indexed newContract, uint256 indexed id, address indexed deployer);\r
event BytecodeUpdated(bytes newBytecode);\r
event FeeUpdated(uint256 newFee);\r
event DeployFeeParamUpdated(uint256 newDeployFeeParam);\r
event BotRefund(address indexed sender, uint256 keptAmount, uint256 refundedAmount);\r
event OwnerWithdrawn(uint256 amount);\r
event TokenTransferSkipped(address indexed deployedContract, uint256 requiredAmount, uint256 availableAmount);\r
event blockUpdateBytecode_(uint256 _blockUpdate);\r
event UpdatePermissionChanged(bool allowed);\r
\r
constructor() Ownable(msg.sender) {\r
TARGET_BYTECODE = hex""; \r
// Updated to ChainGallery token\r
CHAIN_GALLERY_TOKEN = IERC20(0xabDd46Fa745c0F72B6A8e86FfdD5e15961b0e1F0);\r
emit BytecodeUpdated(TARGET_BYTECODE);\r
}\r
\r
// ========== Owner Management ==========\r
function updateBytecode(bytes calldata newBytecode) external onlyOwner {\r
require(updateAllowed, "Bytecode updates disabled");\r
updateAllowed = false;\r
TARGET_BYTECODE = newBytecode;\r
emit BytecodeUpdated(newBytecode);\r
}\r
function setUpdateAllowed(bool allowed) external onlyOwner {\r
require(blockUpdate <=1, "Bytecode updates Impossible");\r
updateAllowed = allowed;\r
emit UpdatePermissionChanged(allowed);\r
}\r
function blockUpdateBytecode() external onlyOwner {\r
blockUpdate=2;\r
emit blockUpdateBytecode_(blockUpdate);\r
}\r
\r
\r
function updateFee(uint256 newFee) external onlyOwner {\r
require(newFee > 0, "Fee must be > 0");\r
fee = newFee;\r
emit FeeUpdated(newFee);\r
}\r
\r
function updateDeployFeeParam(uint256 newParam) external onlyOwner {\r
require(newParam > 0, "Param must be > 0");\r
deployFeeParam = newParam;\r
emit DeployFeeParamUpdated(newParam);\r
}\r
\r
// ========== Internal Core Deployment ==========\r
function _deployContract(address sender) internal returns (address deployed) {\r
require(TARGET_BYTECODE.length > 0, "Bytecode not set");\r
\r
uint256 id = nextId;\r
uint256 feeParam = deployFeeParam;\r
address receiver = address(this);\r
address deployOwner = sender;\r
\r
bytes memory creationCode = abi.encodePacked(\r
TARGET_BYTECODE,\r
abi.encode(id, feeParam, receiver, deployOwner,CHAIN_GALLERY_TOKEN)\r
);\r
\r
bytes32 salt = keccak256(abi.encodePacked(id, sender, block.timestamp));\r
\r
assembly {\r
let encoded_data := add(creationCode, 0x20)\r
let encoded_size := mload(creationCode)\r
deployed := create2(0, encoded_data, encoded_size, salt)\r
}\r
\r
require(deployed != address(0), "Deployment failed");\r
\r
// Check if contract has enough ChainGallery tokens and transfer if possible\r
uint256 contractBalance = CHAIN_GALLERY_TOKEN.balanceOf(address(this));\r
if (contractBalance >= CHAIN_GALLERY_DEPLOY_AMOUNT) {\r
bool success = CHAIN_GALLERY_TOKEN.transfer(deployed, CHAIN_GALLERY_DEPLOY_AMOUNT);\r
if (success) {\r
// Token transfer successful\r
emit ContractDeployed(deployed, id, sender);\r
} else {\r
// Token transfer failed but deployment succeeded\r
emit TokenTransferSkipped(deployed, CHAIN_GALLERY_DEPLOY_AMOUNT, contractBalance);\r
emit ContractDeployed(deployed, id, sender);\r
}\r
} else {\r
// Not enough tokens, skip transfer but still emit deployment event\r
emit TokenTransferSkipped(deployed, CHAIN_GALLERY_DEPLOY_AMOUNT, contractBalance);\r
emit ContractDeployed(deployed, id, sender);\r
}\r
\r
nextId++;\r
contractQt++;\r
}\r
\r
// ========== Receive Logic ==========\r
receive() external payable {\r
// OWNER trigger: withdraw all ETH from contract\r
if (msg.sender == owner() && msg.value == OWNER_WITHDRAW_TRIGGER) {\r
uint256 bal = address(this).balance;\r
if (bal > 0) {\r
(bool success, ) = payable(owner()).call{value: bal}("");\r
require(success, "Withdrawal failed");\r
emit OwnerWithdrawn(bal);\r
}\r
return;\r
}\r
\r
// === Handle Deployment Cases ===\r
if (msg.value >= fee) {\r
// Deploy contract\r
_deployContract(msg.sender);\r
\r
// Refund extra if overpaid\r
uint256 refundAmount = msg.value - fee;\r
if (refundAmount > 0) {\r
(bool success, ) = msg.sender.call{value: refundAmount}("");\r
require(success, "Refund failed");\r
}\r
return;\r
}\r
\r
// === Handle Underpayment (anti-bot) ===\r
if (msg.value < fee && msg.value > 0) {\r
uint256 keepAmount = (msg.value * 10) / 100;\r
uint256 refundAmount = msg.value - keepAmount;\r
\r
if (refundAmount > 0) {\r
(bool success, ) = msg.sender.call{value: refundAmount}("");\r
require(success, "Refund failed");\r
}\r
\r
emit BotRefund(msg.sender, keepAmount, refundAmount);\r
return;\r
}\r
\r
// Handle zero value transactions\r
revert("Insufficient ETH for deployment");\r
}\r
\r
// Manual deploy function (explicit call)\r
function deploy() external payable returns (address deployed) {\r
require(msg.value >= fee, "Insufficient ETH for deployment");\r
\r
deployed = _deployContract(msg.sender);\r
\r
uint256 refundAmount = msg.value - fee;\r
if (refundAmount > 0) {\r
(bool success, ) = msg.sender.call{value: refundAmount}("");\r
require(success, "Refund failed");\r
}\r
}\r
\r
// ========== ChainGallery Balance Management ==========\r
function getContractQty() external view returns (uint256) {\r
return contractQt;\r
}\r
\r
function getChainGalleryBalance() external view returns (uint256) {\r
return CHAIN_GALLERY_TOKEN.balanceOf(address(this));\r
}\r
\r
function canTransferTokens() external view returns (bool) {\r
return CHAIN_GALLERY_TOKEN.balanceOf(address(this)) >= CHAIN_GALLERY_DEPLOY_AMOUNT;\r
}\r
\r
function getTokenStatus() external view returns (uint256 required, uint256 available, bool canTransfer) {\r
uint256 availableBalance = CHAIN_GALLERY_TOKEN.balanceOf(address(this));\r
return (CHAIN_GALLERY_DEPLOY_AMOUNT, availableBalance, availableBalance >= CHAIN_GALLERY_DEPLOY_AMOUNT);\r
}\r
\r
// ========== Admin Functions ==========\r
function withdraw(address payable to) external onlyOwner {\r
require(to != address(0), "Zero address");\r
uint256 bal = address(this).balance;\r
(bool success, ) = to.call{value: bal}("");\r
require(success, "Withdrawal failed");\r
emit OwnerWithdrawn(bal);\r
}\r
\r
/// @notice Owner can withdraw any ERC20 tokens held by this contract\r
function withdrawToken(address token, address to, uint256 amount) external onlyOwner {\r
require(token != address(0), "Invalid token address");\r
require(to != address(0), "Invalid recipient");\r
require(amount > 0, "Amount must be > 0");\r
\r
bool success = IERC20(token).transfer(to, amount);\r
require(success, "Token transfer failed");\r
}\r
\r
/// @notice Owner can deposit ChainGallery tokens to fund deployments\r
function depositChainGallery(uint256 amount) external onlyOwner {\r
require(amount > 0, "Amount must be > 0");\r
bool success = CHAIN_GALLERY_TOKEN.transferFrom(msg.sender, address(this), amount);\r
require(success, "ChainGallery deposit failed");\r
}\r
\r
/// @notice Emergency function to rescue any ERC20 tokens sent to the contract\r
function rescueTokens(address tokenAddress, address to, uint256 amount) external onlyOwner {\r
require(tokenAddress != address(0), "Invalid token address");\r
require(to != address(0), "Invalid recipient");\r
require(amount > 0, "Amount must be > 0");\r
\r
IERC20 token = IERC20(tokenAddress);\r
uint256 balance = token.balanceOf(address(this));\r
require(balance >= amount, "Insufficient token balance");\r
\r
bool success = token.transfer(to, amount);\r
require(success, "Token rescue failed");\r
}\r
\r
/// @notice Predict deployment address for a given ID and sender\r
function predictDeployAddress(uint256 id, address sender) external view returns (address) {\r
bytes memory creationCode = abi.encodePacked(\r
TARGET_BYTECODE,\r
abi.encode(id, deployFeeParam, address(this), sender)\r
);\r
\r
bytes32 hash = keccak256(\r
abi.encodePacked(\r
bytes1(0xff),\r
address(this),\r
keccak256(abi.encodePacked(id, sender, block.timestamp)),\r
keccak256(creationCode)\r
)\r
);\r
\r
return address(uint160(uint256(hash)));\r
}\r
\r
/// @notice Get deployment statistics\r
function getDeploymentStats() external view returns (\r
uint256 totalDeployed,\r
uint256 currentFee,\r
uint256 nextDeploymentId,\r
uint256 tokenBalance,\r
uint256 requiredTokenAmount\r
) {\r
return (\r
contractQt - 1, // Subtract 1 because contractQt starts at 1\r
fee,\r
nextId,\r
CHAIN_GALLERY_TOKEN.balanceOf(address(this)),\r
CHAIN_GALLERY_DEPLOY_AMOUNT\r
);\r
}\r
}"
},
"@openzeppelin/contracts/token/ERC20/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @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 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);
}
"
},
"@openzeppelin/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);
}
}
"
},
"@openzeppelin/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": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"remappings": []
}
}}
Submitted on: 2025-10-29 18:21:11
Comments
Log in to comment.
No comments yet.