UNPKG

@owlprotocol/contracts-account-abstraction

Version:

ERC4337 Account Abstraction support for deploying relevant smart contracts and interacting with UserOps.

678 lines (650 loc) 19.5 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var StakeManager_exports = {}; __export(StakeManager_exports, { StakeManager: () => StakeManager }); module.exports = __toCommonJS(StakeManager_exports); const StakeManager = { compiler: { version: "0.8.23+commit.f704f362" }, language: "Solidity", output: { abi: [ { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: false, internalType: "uint256", name: "totalDeposit", type: "uint256" } ], name: "Deposited", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: false, internalType: "uint256", name: "totalStaked", type: "uint256" }, { indexed: false, internalType: "uint256", name: "unstakeDelaySec", type: "uint256" } ], name: "StakeLocked", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: false, internalType: "uint256", name: "withdrawTime", type: "uint256" } ], name: "StakeUnlocked", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: false, internalType: "address", name: "withdrawAddress", type: "address" }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256" } ], name: "StakeWithdrawn", type: "event" }, { anonymous: false, inputs: [ { indexed: true, internalType: "address", name: "account", type: "address" }, { indexed: false, internalType: "address", name: "withdrawAddress", type: "address" }, { indexed: false, internalType: "uint256", name: "amount", type: "uint256" } ], name: "Withdrawn", type: "event" }, { inputs: [ { internalType: "uint32", name: "unstakeDelaySec", type: "uint32" } ], name: "addStake", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "address", name: "account", type: "address" } ], name: "balanceOf", outputs: [ { internalType: "uint256", name: "", type: "uint256" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "account", type: "address" } ], name: "depositTo", outputs: [], stateMutability: "payable", type: "function" }, { inputs: [ { internalType: "address", name: "", type: "address" } ], name: "deposits", outputs: [ { internalType: "uint256", name: "deposit", type: "uint256" }, { internalType: "bool", name: "staked", type: "bool" }, { internalType: "uint112", name: "stake", type: "uint112" }, { internalType: "uint32", name: "unstakeDelaySec", type: "uint32" }, { internalType: "uint48", name: "withdrawTime", type: "uint48" } ], stateMutability: "view", type: "function" }, { inputs: [ { internalType: "address", name: "account", type: "address" } ], name: "getDepositInfo", outputs: [ { components: [ { internalType: "uint256", name: "deposit", type: "uint256" }, { internalType: "bool", name: "staked", type: "bool" }, { internalType: "uint112", name: "stake", type: "uint112" }, { internalType: "uint32", name: "unstakeDelaySec", type: "uint32" }, { internalType: "uint48", name: "withdrawTime", type: "uint48" } ], internalType: "struct IStakeManager.DepositInfo", name: "info", type: "tuple" } ], stateMutability: "view", type: "function" }, { inputs: [], name: "unlockStake", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address payable", name: "withdrawAddress", type: "address" } ], name: "withdrawStake", outputs: [], stateMutability: "nonpayable", type: "function" }, { inputs: [ { internalType: "address payable", name: "withdrawAddress", type: "address" }, { internalType: "uint256", name: "withdrawAmount", type: "uint256" } ], name: "withdrawTo", outputs: [], stateMutability: "nonpayable", type: "function" }, { stateMutability: "payable", type: "receive" } ], devdoc: { kind: "dev", methods: { "addStake(uint32)": { params: { unstakeDelaySec: "The new lock duration before the deposit can be withdrawn." } }, "balanceOf(address)": { params: { account: "- The account to query." }, returns: { _0: "- The deposit (for gas payment) of the account." } }, "depositTo(address)": { params: { account: "- The account to add to." } }, "getDepositInfo(address)": { params: { account: "- The account to query." }, returns: { info: " - Full deposit information of given account." } }, "withdrawStake(address)": { params: { withdrawAddress: "- The address to send withdrawn value." } }, "withdrawTo(address,uint256)": { params: { withdrawAddress: "- The address to send withdrawn value.", withdrawAmount: "- The amount to withdraw." } } }, version: 1 }, userdoc: { kind: "user", methods: { "addStake(uint32)": { notice: "Add to the account's stake - amount and delay any pending unstake is first cancelled." }, "balanceOf(address)": { notice: "Get account balance." }, "depositTo(address)": { notice: "Add to the deposit of the given account." }, "deposits(address)": { notice: "maps paymaster to their deposits and stakes" }, "getDepositInfo(address)": { notice: "Get deposit info." }, "unlockStake()": { notice: "Attempt to unlock the stake. The value can be withdrawn (using withdrawStake) after the unstake delay." }, "withdrawStake(address)": { notice: "Withdraw from the (unlocked) stake. Must first call unlockStake and wait for the unstakeDelay to pass." }, "withdrawTo(address,uint256)": { notice: "Withdraw from the deposit." } }, notice: 'Manage deposits and stakes. Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account). Stake is value locked for at least "unstakeDelay" by a paymaster.', version: 1 } }, settings: { compilationTarget: { "@account-abstraction/contracts/core/StakeManager.sol": "StakeManager" }, evmVersion: "paris", libraries: {}, metadata: { bytecodeHash: "ipfs", useLiteralContent: true }, optimizer: { enabled: true, runs: 1e6 }, remappings: [], viaIR: true }, sources: { "@account-abstraction/contracts/core/StakeManager.sol": { content: `// SPDX-License-Identifier: GPL-3.0-only pragma solidity ^0.8.23; import "../interfaces/IStakeManager.sol"; /* solhint-disable avoid-low-level-calls */ /* solhint-disable not-rely-on-time */ /** * Manage deposits and stakes. * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account). * Stake is value locked for at least "unstakeDelay" by a paymaster. */ abstract contract StakeManager is IStakeManager { /// maps paymaster to their deposits and stakes mapping(address => DepositInfo) public deposits; /// @inheritdoc IStakeManager function getDepositInfo( address account ) public view returns (DepositInfo memory info) { return deposits[account]; } /** * Internal method to return just the stake info. * @param addr - The account to query. */ function _getStakeInfo( address addr ) internal view returns (StakeInfo memory info) { DepositInfo storage depositInfo = deposits[addr]; info.stake = depositInfo.stake; info.unstakeDelaySec = depositInfo.unstakeDelaySec; } /// @inheritdoc IStakeManager function balanceOf(address account) public view returns (uint256) { return deposits[account].deposit; } receive() external payable { depositTo(msg.sender); } /** * Increments an account's deposit. * @param account - The account to increment. * @param amount - The amount to increment by. * @return the updated deposit of this account */ function _incrementDeposit(address account, uint256 amount) internal returns (uint256) { DepositInfo storage info = deposits[account]; uint256 newAmount = info.deposit + amount; info.deposit = newAmount; return newAmount; } /** * Add to the deposit of the given account. * @param account - The account to add to. */ function depositTo(address account) public virtual payable { uint256 newDeposit = _incrementDeposit(account, msg.value); emit Deposited(account, newDeposit); } /** * Add to the account's stake - amount and delay * any pending unstake is first cancelled. * @param unstakeDelaySec The new lock duration before the deposit can be withdrawn. */ function addStake(uint32 unstakeDelaySec) public payable { DepositInfo storage info = deposits[msg.sender]; require(unstakeDelaySec > 0, "must specify unstake delay"); require( unstakeDelaySec >= info.unstakeDelaySec, "cannot decrease unstake time" ); uint256 stake = info.stake + msg.value; require(stake > 0, "no stake specified"); require(stake <= type(uint112).max, "stake overflow"); deposits[msg.sender] = DepositInfo( info.deposit, true, uint112(stake), unstakeDelaySec, 0 ); emit StakeLocked(msg.sender, stake, unstakeDelaySec); } /** * Attempt to unlock the stake. * The value can be withdrawn (using withdrawStake) after the unstake delay. */ function unlockStake() external { DepositInfo storage info = deposits[msg.sender]; require(info.unstakeDelaySec != 0, "not staked"); require(info.staked, "already unstaking"); uint48 withdrawTime = uint48(block.timestamp) + info.unstakeDelaySec; info.withdrawTime = withdrawTime; info.staked = false; emit StakeUnlocked(msg.sender, withdrawTime); } /** * Withdraw from the (unlocked) stake. * Must first call unlockStake and wait for the unstakeDelay to pass. * @param withdrawAddress - The address to send withdrawn value. */ function withdrawStake(address payable withdrawAddress) external { DepositInfo storage info = deposits[msg.sender]; uint256 stake = info.stake; require(stake > 0, "No stake to withdraw"); require(info.withdrawTime > 0, "must call unlockStake() first"); require( info.withdrawTime <= block.timestamp, "Stake withdrawal is not due" ); info.unstakeDelaySec = 0; info.withdrawTime = 0; info.stake = 0; emit StakeWithdrawn(msg.sender, withdrawAddress, stake); (bool success,) = withdrawAddress.call{value: stake}(""); require(success, "failed to withdraw stake"); } /** * Withdraw from the deposit. * @param withdrawAddress - The address to send withdrawn value. * @param withdrawAmount - The amount to withdraw. */ function withdrawTo( address payable withdrawAddress, uint256 withdrawAmount ) external { DepositInfo storage info = deposits[msg.sender]; require(withdrawAmount <= info.deposit, "Withdraw amount too large"); info.deposit = info.deposit - withdrawAmount; emit Withdrawn(msg.sender, withdrawAddress, withdrawAmount); (bool success,) = withdrawAddress.call{value: withdrawAmount}(""); require(success, "failed to withdraw"); } } `, keccak256: "0x673eb19600058d8642605ca409c9e1d4cab13735564b856270b92c330ffb1b8d", license: "GPL-3.0-only" }, "@account-abstraction/contracts/interfaces/IStakeManager.sol": { content: `// SPDX-License-Identifier: GPL-3.0-only pragma solidity >=0.7.5; /** * Manage deposits and stakes. * Deposit is just a balance used to pay for UserOperations (either by a paymaster or an account). * Stake is value locked for at least "unstakeDelay" by the staked entity. */ interface IStakeManager { event Deposited(address indexed account, uint256 totalDeposit); event Withdrawn( address indexed account, address withdrawAddress, uint256 amount ); // Emitted when stake or unstake delay are modified. event StakeLocked( address indexed account, uint256 totalStaked, uint256 unstakeDelaySec ); // Emitted once a stake is scheduled for withdrawal. event StakeUnlocked(address indexed account, uint256 withdrawTime); event StakeWithdrawn( address indexed account, address withdrawAddress, uint256 amount ); /** * @param deposit - The entity's deposit. * @param staked - True if this entity is staked. * @param stake - Actual amount of ether staked for this entity. * @param unstakeDelaySec - Minimum delay to withdraw the stake. * @param withdrawTime - First block timestamp where 'withdrawStake' will be callable, or zero if already locked. * @dev Sizes were chosen so that deposit fits into one cell (used during handleOp) * and the rest fit into a 2nd cell (used during stake/unstake) * - 112 bit allows for 10^15 eth * - 48 bit for full timestamp * - 32 bit allows 150 years for unstake delay */ struct DepositInfo { uint256 deposit; bool staked; uint112 stake; uint32 unstakeDelaySec; uint48 withdrawTime; } // API struct used by getStakeInfo and simulateValidation. struct StakeInfo { uint256 stake; uint256 unstakeDelaySec; } /** * Get deposit info. * @param account - The account to query. * @return info - Full deposit information of given account. */ function getDepositInfo( address account ) external view returns (DepositInfo memory info); /** * Get account balance. * @param account - The account to query. * @return - The deposit (for gas payment) of the account. */ function balanceOf(address account) external view returns (uint256); /** * Add to the deposit of the given account. * @param account - The account to add to. */ function depositTo(address account) external payable; /** * Add to the account's stake - amount and delay * any pending unstake is first cancelled. * @param _unstakeDelaySec - The new lock duration before the deposit can be withdrawn. */ function addStake(uint32 _unstakeDelaySec) external payable; /** * Attempt to unlock the stake. * The value can be withdrawn (using withdrawStake) after the unstake delay. */ function unlockStake() external; /** * Withdraw from the (unlocked) stake. * Must first call unlockStake and wait for the unstakeDelay to pass. * @param withdrawAddress - The address to send withdrawn value. */ function withdrawStake(address payable withdrawAddress) external; /** * Withdraw from the deposit. * @param withdrawAddress - The address to send withdrawn value. * @param withdrawAmount - The amount to withdraw. */ function withdrawTo( address payable withdrawAddress, uint256 withdrawAmount ) external; } `, keccak256: "0xbe5ca9e7f254d031687419e7b96ef48c9c63e9398bbe992dc72ffc6dc14e0a04", license: "GPL-3.0-only" } }, version: 1 };