Verified contractPartialMIT
MoistUpgradeableAccount
Address0x41ca3b5f3c613ab6178880a8f7c8d518f03451d0
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- cancun
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,443,656
- Creation transaction
- 0x294661e2c9…625f59c85b
contracts/MoistUpgradeableAccount.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IERC1271Owner {
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4);
}
interface IERC1822Proxiable {
function proxiableUUID() external view returns (bytes32);
}
/// @notice UUPS-upgradeable successor to MoistSafeOwnedAccount for deployment behind MoistAccountProxy.
/// @dev Differences from MoistSafeOwnedAccount / the legacy 0x8E351774… implementation:
/// - Upgrade authority lives here (`upgradeToAndCall`, owner only, proxy only, ERC-1822 checked).
/// - Owner may be an EOA (e.g. undelegated 311E) or a contract (Safe). ERC-1271 handles both.
/// - Ownership transfer is two-step, so a typo cannot strand an EOA-owned account.
/// - State is held in an ERC-7201 namespaced slot so future versions cannot collide.
/// MoistAccountProxy writes the ERC-1967 implementation slot once in its constructor and has no
/// admin, so every upgrade goes through this contract.
contract MoistUpgradeableAccount is IERC1822Proxiable {
/// @dev ERC-1967 implementation slot (same slot MoistAccountProxy writes).
bytes32 internal constant IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/// @dev keccak256(abi.encode(uint256(keccak256("moistly.storage.MoistUpgradeableAccount")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant STORAGE_LOCATION = 0x1958c49296883bfe41840d0916d3fb8f23f2b6c0a52de20ff912c0e2e1546d00;
uint256 private constant HALF_N = 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0;
/// @custom:storage-location erc7201:moistly.storage.MoistUpgradeableAccount
struct Layout {
address owner;
address pendingOwner;
address verifyingAccount;
bytes32 factorySalt;
bool initialized;
}
/// @dev Address of the logic contract itself; differs from `address(this)` under delegatecall.
address private immutable __self = address(this);
error Unauthorized();
error InvalidOwner();
error AlreadyInitialized();
error InvalidTarget();
error ExecutionFailed(bytes reason);
error NotProxy();
error DelegatedCall();
error InvalidImplementation();
error UpgradeCallFailed(bytes reason);
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
event Executed(address indexed target, uint256 value);
event Upgraded(address indexed implementation);
constructor() {
_layout().initialized = true; // lock the bare implementation
}
// ---------------------------------------------------------------- init
/// @notice One-shot initializer. Intended to run as the MoistAccountProxy constructor `initData`.
function initializeAccount(address initialOwner, bytes32 salt, address account) external {
Layout storage $ = _layout();
if ($.initialized || address(this).code.length != 0) revert AlreadyInitialized();
if (initialOwner == address(0) || initialOwner == address(this)) revert InvalidOwner();
$.initialized = true;
$.owner = initialOwner;
$.factorySalt = salt;
$.verifyingAccount = account == address(0) ? address(this) : account;
emit OwnershipTransferred(address(0), initialOwner);
}
// ------------------------------------------------------------- views
function owner() public view returns (address) {
return _layout().owner;
}
function pendingOwner() external view returns (address) {
return _layout().pendingOwner;
}
function factorySalt() external view returns (bytes32) {
return _layout().factorySalt;
}
function verifyingAccount() external view returns (address) {
return _layout().verifyingAccount;
}
// --------------------------------------------------------- ownership
modifier onlyOwner() {
if (msg.sender != _layout().owner) revert Unauthorized();
_;
}
/// @notice Nominates `newOwner`. They must call `acceptOwnership`. Pass address(0) to cancel.
function transferOwnership(address newOwner) external onlyOwner {
if (newOwner == address(this)) revert InvalidOwner();
_layout().pendingOwner = newOwner;
emit OwnershipTransferStarted(_layout().owner, newOwner);
}
function acceptOwnership() external {
Layout storage $ = _layout();
if (msg.sender != $.pendingOwner) revert Unauthorized();
address previous = $.owner;
$.owner = msg.sender;
$.pendingOwner = address(0);
emit OwnershipTransferred(previous, msg.sender);
}
// --------------------------------------------------------- execution
receive() external payable {}
function execute(address target, uint256 value, bytes calldata data)
external
payable
onlyOwner
returns (bytes memory result)
{
if (target == address(0)) revert InvalidTarget();
(bool ok, bytes memory returned) = target.call{value: value}(data);
if (!ok) revert ExecutionFailed(returned);
emit Executed(target, value);
return returned;
}
// ----------------------------------------------------------- upgrade
/// @notice ERC-1822 marker. Reverts under delegatecall so only the bare implementation answers.
function proxiableUUID() external view returns (bytes32) {
if (address(this) != __self) revert DelegatedCall();
return IMPLEMENTATION_SLOT;
}
/// @notice Points the proxy at `newImplementation` and optionally runs `data` via delegatecall.
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable onlyOwner {
_requireProxy();
if (newImplementation.code.length == 0) revert InvalidImplementation();
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != IMPLEMENTATION_SLOT) revert InvalidImplementation();
} catch {
revert InvalidImplementation();
}
assembly {
sstore(IMPLEMENTATION_SLOT, newImplementation)
}
emit Upgraded(newImplementation);
if (data.length != 0) {
(bool ok, bytes memory reason) = newImplementation.delegatecall(data);
if (!ok) revert UpgradeCallFailed(reason);
}
}
function _requireProxy() private view {
address impl;
assembly {
impl := sload(IMPLEMENTATION_SLOT)
}
if (address(this) == __self || impl != __self) revert NotProxy();
}
// ------------------------------------------------------------ ERC-1271
/// @notice Valid when the owner signed `hash`: ECDSA for an EOA owner, ERC-1271 for a contract owner.
function isValidSignature(bytes32 hash, bytes calldata signature) external view returns (bytes4) {
address current = _layout().owner;
if (current.code.length == 0) {
return _recover(hash, signature) == current ? bytes4(0x1626ba7e) : bytes4(0xffffffff);
}
try IERC1271Owner(current).isValidSignature(hash, signature) returns (bytes4 result) {
return result == bytes4(0x1626ba7e) ? result : bytes4(0xffffffff);
} catch {
return bytes4(0xffffffff);
}
}
function _recover(bytes32 hash, bytes calldata signature) private pure returns (address) {
if (signature.length != 65) return address(0);
bytes32 r = bytes32(signature[0:32]);
bytes32 s = bytes32(signature[32:64]);
uint8 v = uint8(signature[64]);
if (uint256(s) > HALF_N || (v != 27 && v != 28)) return address(0);
return ecrecover(hash, v, r, s);
}
// ---------------------------------------------------------- receivers
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
return 0x150b7a02;
}
function onERC1155Received(address, address, uint256, uint256, bytes calldata) external pure returns (bytes4) {
return 0xf23a6e61;
}
function onERC1155BatchReceived(address, address, uint256[] calldata, uint256[] calldata, bytes calldata)
external
pure
returns (bytes4)
{
return 0xbc197c81;
}
function supportsInterface(bytes4 id) external pure returns (bool) {
return id == 0x01ffc9a7 || id == 0x7f5828d0 || id == 0x4e2312e0;
}
function _layout() private pure returns (Layout storage $) {
assembly {
$.slot := STORAGE_LOCATION
}
}
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"bytecodeHash": "none"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "cancun",
"remappings": [
"@arbitrum/=node_modules/@arbitrum/",
"@ensdomains/=contracts/v4-core/node_modules/@ensdomains/",
"@eth-optimism/=lib/unruggable-gateways/lib/optimism/packages/",
"@layerzerolabs/lz-evm-messagelib-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/messagelib/",
"@layerzerolabs/lz-evm-protocol-v2/=lib/layerzero-v2/packages/layerzero-v2/evm/protocol/",
"@layerzerolabs/oapp-evm/=lib/devtools/packages/oapp-evm/",
"@offchainlabs/=node_modules/@offchainlabs/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@uniswap/=node_modules/@uniswap/",
"base64-sol/=node_modules/base64-sol/",
"create3-factory/=lib/create3-factory/",
"devtools/=lib/devtools/",
"ds-test/=contracts/v4-core/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"flap/=contracts/flap/",
"forge-std-1.16.2/=dependencies/forge-std-1.16.2/",
"forge-std/=lib/forge-std/src/",
"halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"hardhat/=contracts/v4-core/node_modules/hardhat/",
"interfaces/=contracts/interfaces/",
"layerzero-v2/=lib/layerzero-v2/",
"libraries/=contracts/libraries/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/",
"openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/src/",
"optimism/=lib/unruggable-gateways/lib/optimism/packages/contracts-bedrock/src/",
"solady/=node_modules/solady/",
"solidity-bytes-utils/=lib/solidity-bytes-utils/",
"solmate/=contracts/v4-core/lib/solmate/",
"splits-contracts-monorepo/=contracts/splits-contracts-monorepo/src/",
"unruggable-gateways/=lib/unruggable-gateways/contracts/",
"v4-core/=contracts/v4-core/src/",
"vault/=contracts/vault/",
"contracts/v4-core/:openzeppelin-contracts/=contracts/v4-core/lib/openzeppelin-contracts/",
"contracts/v4-core/:solmate/=contracts/v4-core/lib/solmate/",
"contracts/v4-core/lib/openzeppelin-contracts/:erc4626-tests/=contracts/v4-core/lib/openzeppelin-contracts/lib/erc4626-tests/",
"contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=contracts/v4-core/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"contracts/v4-core/lib/solmate/:ds-test/=contracts/v4-core/lib/solmate/lib/ds-test/src/",
"lib/create3-factory/:solmate/=lib/create3-factory/lib/solmate/src/",
"lib/create3-factory/lib/forge-std/:ds-test/=lib/create3-factory/lib/forge-std/lib/ds-test/src/",
"lib/create3-factory/lib/solmate/:ds-test/=lib/create3-factory/lib/solmate/lib/ds-test/src/",
"lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"lib/openzeppelin-contracts-upgradeable/:openzeppelin-contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/",
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/openzeppelin-contracts/:erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/unruggable-gateways/:openzeppelin-contracts/=lib/unruggable-gateways/lib/openzeppelin-contracts/",
"lib/unruggable-gateways/lib/openzeppelin-contracts/:erc4626-tests/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/:ds-test/=lib/unruggable-gateways/lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/",
"node_modules/@arbitrum/chain-actions/lib/forge-std/:ds-test/=node_modules/@arbitrum/chain-actions/lib/forge-std/lib/ds-test/",
"node_modules/@arbitrum/token-bridge-contracts/:@arbitrum/nitro-contracts/=node_modules/@arbitrum/token-bridge-contracts/node_modules/@arbitrum/nitro-contracts/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.