编译器
0.8.22+commit.4fc1097e
文件 1 的 8:Address.sol
pragma solidity ^0.8.20;
library Address {
error AddressInsufficientBalance(address account);
error AddressEmptyCode(address target);
error FailedInnerCall();
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
function _revert(bytes memory returndata) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
文件 2 的 8:Command.sol
pragma solidity 0.8.22;
import {CommandLibrary} from "contracts/libraries/CommandLibrary.sol";
struct Command {
address target;
uint256 value;
bytes payload;
}
using CommandLibrary for Command global;
文件 3 的 8:CommandLibrary.sol
pragma solidity 0.8.22;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Command} from "contracts/interfaces/accountAbstraction/interpreter/Command.sol";
import {SafeCall} from "contracts/libraries/SafeCall.sol";
library CommandPresets {
function approve(
address _token,
address _to,
uint256 _amount
) internal pure returns (Command memory cmd_) {
cmd_.target = _token;
cmd_.payload = abi.encodeCall(IERC20.approve, (_to, _amount));
}
function transfer(
address _token,
address _to,
uint256 _amount
) internal pure returns (Command memory cmd_) {
cmd_.target = _token;
cmd_.payload = abi.encodeCall(IERC20.transfer, (_to, _amount));
}
}
library CommandExecutor {
using SafeCall for Command[];
function execute(Command[] calldata _cmds) external {
_cmds.safeCallAll();
}
}
library CommandLibrary {
using CommandLibrary for Command[];
function last(Command[] memory _self) internal pure returns (Command memory) {
return _self[_self.length - 1];
}
function asArray(Command memory _self) internal pure returns (Command[] memory result_) {
result_ = new Command[](1);
result_[0] = _self;
}
function concat(
Command memory _self,
Command memory _cmd
) internal pure returns (Command[] memory result_) {
result_ = new Command[](2);
result_[0] = _self;
result_[1] = _cmd;
}
function concat(
Command memory _self,
Command[] memory _cmds
) internal pure returns (Command[] memory result_) {
result_ = new Command[](_cmds.length + 1);
result_[0] = _self;
for (uint256 i = 1; i < result_.length; i++) {
result_[i] = _cmds[i - 1];
}
}
function append(
Command[] memory _self,
Command[] memory _cmds
) internal pure returns (Command[] memory result_) {
result_ = new Command[](_self.length + _cmds.length);
uint256 i;
for (; i < _self.length; i++) {
result_[i] = _self[i];
}
for (; i < result_.length; i++) {
result_[i] = _cmds[i - _self.length];
}
}
function push(
Command[] memory _self,
Command memory _cmd
) internal pure returns (Command[] memory result_) {
result_ = new Command[](_self.length + 1);
for (uint256 i; i < _self.length; i++) {
result_[i] = _self[i];
}
result_[_self.length] = _cmd;
}
function unshift(
Command[] memory _self,
Command memory _cmd
) internal pure returns (Command[] memory result_) {
result_ = new Command[](1 + _self.length);
result_[0] = _cmd;
for (uint256 i = 1; i < result_.length; i++) {
result_[i] = _self[i - 1];
}
}
function unshift(
Command[] memory _self,
Command[] memory _cmds
) internal pure returns (Command[] memory result_) {
result_ = new Command[](_cmds.length + _self.length);
uint256 i;
for (; i < _cmds.length; i++) {
result_[i] = _cmds[i];
}
for (; i < result_.length; i++) {
result_[i] = _self[i - _cmds.length];
}
}
function populateWithApprove(
Command memory _self,
address _token,
uint256 _amount
) internal pure returns (Command[] memory result_) {
if (_amount != 0) {
result_ = CommandPresets.approve(_token, _self.target, _amount).concat(_self);
} else {
result_ = _self.asArray();
}
}
function populateWithRevokeAndApprove(
Command memory _self,
address _token,
uint256 _amount
) internal pure returns (Command[] memory result_) {
return
CommandPresets.approve(_token, _self.target, 0).concat(
_self.populateWithApprove(_token, _amount)
);
}
function populateWithApprove(
Command[] memory _self,
address _token,
uint256 _amount
) internal pure returns (Command[] memory result_) {
if (_amount != 0) {
result_ = _self.unshift(
CommandPresets.approve(_token, _self[_self.length - 1].target, _amount)
);
} else {
result_ = _self;
}
}
function populateWithApprove(
Command memory _self,
address[2] memory _tokens,
uint256[2] memory _amounts
) internal pure returns (Command[] memory result_) {
if (_amounts[0] != 0 && _amounts[1] != 0) {
result_ = CommandPresets
.approve(_tokens[0], _self.target, _amounts[0])
.concat(CommandPresets.approve(_tokens[1], _self.target, _amounts[1]))
.push(_self);
} else {
if (_amounts[0] != 0) {
result_ = populateWithApprove(_self, _tokens[0], _amounts[0]);
} else {
result_ = populateWithApprove(_self, _tokens[1], _amounts[1]);
}
}
}
function populateWithApprove(
Command memory _self,
address[3] memory _tokens,
uint256[3] memory _amounts
) internal pure returns (Command[] memory result_) {
if (_amounts[0] != 0 && _amounts[1] != 0 && _amounts[2] != 0) {
result_ = CommandPresets
.approve(_tokens[0], _self.target, _amounts[0])
.concat(CommandPresets.approve(_tokens[1], _self.target, _amounts[1]))
.push(CommandPresets.approve(_tokens[2], _self.target, _amounts[2]))
.push(_self);
} else {
if (_amounts[0] == 0) {
result_ = populateWithApprove(
_self,
[_tokens[1], _tokens[2]],
[_amounts[1], _amounts[2]]
);
} else if (_amounts[1] == 0) {
result_ = populateWithApprove(
_self,
[_tokens[0], _tokens[2]],
[_amounts[0], _amounts[2]]
);
} else {
result_ = populateWithApprove(
_self,
[_tokens[0], _tokens[1]],
[_amounts[0], _amounts[1]]
);
}
}
}
function populateWithApprove(
Command memory _self,
address[4] memory _tokens,
uint256[4] memory _amounts
) internal pure returns (Command[] memory result_) {
if (_amounts[0] != 0 && _amounts[1] != 0 && _amounts[2] != 0 && _amounts[3] != 0) {
result_ = CommandPresets
.approve(_tokens[0], _self.target, _amounts[0])
.concat(CommandPresets.approve(_tokens[1], _self.target, _amounts[1]))
.push(CommandPresets.approve(_tokens[2], _self.target, _amounts[2]))
.push(CommandPresets.approve(_tokens[3], _self.target, _amounts[3]))
.push(_self);
} else {
if (_amounts[0] == 0) {
result_ = populateWithApprove(
_self,
[_tokens[1], _tokens[2], _tokens[3]],
[_amounts[1], _amounts[2], _amounts[3]]
);
} else if (_amounts[1] == 0) {
result_ = populateWithApprove(
_self,
[_tokens[0], _tokens[2], _tokens[3]],
[_amounts[0], _amounts[2], _amounts[3]]
);
} else if (_amounts[2] == 0) {
result_ = populateWithApprove(
_self,
[_tokens[0], _tokens[1], _tokens[3]],
[_amounts[0], _amounts[1], _amounts[3]]
);
} else {
result_ = populateWithApprove(
_self,
[_tokens[0], _tokens[1], _tokens[2]],
[_amounts[0], _amounts[1], _amounts[2]]
);
}
}
}
}
文件 4 的 8:IBeacon.sol
pragma solidity 0.8.22;
interface IBeacon {
error ImplementationAddressIsZero();
function upgradeTo(address newImplementation) external;
function implementation() external view returns (address);
}
文件 5 的 8:IERC20.sol
pragma solidity ^0.8.20;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 6 的 8:ImmutableBeaconProxy.sol
pragma solidity 0.8.22;
import {Proxy} from "@openzeppelin/contracts/proxy/Proxy.sol";
import {IBeacon} from "contracts/interfaces/base/proxy/IBeacon.sol";
import {SafeCall} from "contracts/libraries/SafeCall.sol";
contract ImmutableBeaconProxy is Proxy {
using {SafeCall.safeDelegateCall} for address;
address private immutable beacon;
error BeaconCallFailed();
error BeaconReturnedUnexpectedNumberOfBytes(uint256);
error BeaconReturnedAddressZero();
constructor(bytes memory initDataWithSelector) {
beacon = msg.sender;
if (initDataWithSelector.length > 0) {
_implementation().safeDelegateCall(initDataWithSelector);
} else {
_implementation();
}
}
function _implementation() internal view override returns (address impl) {
(bool success, bytes memory result) = beacon.staticcall(
abi.encodeCall(IBeacon.implementation, ())
);
if (!success) revert BeaconCallFailed();
if (result.length != 32) revert BeaconReturnedUnexpectedNumberOfBytes(result.length);
impl = abi.decode(result, (address));
if (impl == address(0)) revert BeaconReturnedAddressZero();
}
}
文件 7 的 8:Proxy.sol
pragma solidity ^0.8.20;
abstract contract Proxy {
function _delegate(address implementation) internal virtual {
assembly {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), implementation, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
function _implementation() internal view virtual returns (address);
function _fallback() internal virtual {
_delegate(_implementation());
}
fallback() external payable virtual {
_fallback();
}
}
文件 8 的 8:SafeCall.sol
pragma solidity 0.8.22;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {Command} from "contracts/interfaces/accountAbstraction/interpreter/Command.sol";
library SafeCall {
using Address for address;
function safeCallAll(Command[] memory _cmds) internal {
for (uint256 i; i < _cmds.length; i++) {
safeCall(_cmds[i]);
}
}
function safeCall(Command memory _cmd) internal returns (bytes memory result_) {
result_ = safeCall(_cmd.target, _cmd.value, _cmd.payload);
}
function safeCall(address _target, bytes memory _data) internal returns (bytes memory result_) {
result_ = safeCall(_target, 0, _data);
}
function safeCall(
address _target,
uint256 _value,
bytes memory _data
) internal returns (bytes memory result_) {
result_ = _target.functionCallWithValue(_data, _value);
}
function safeDelegateCall(
address _target,
bytes memory _data
) internal returns (bytes memory result_) {
result_ = _target.functionDelegateCall(_data);
}
}
{
"compilationTarget": {
"contracts/base/proxy/ImmutableBeaconProxy.sol": "ImmutableBeaconProxy"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 1000000
},
"remappings": []
}
[{"inputs":[{"internalType":"bytes","name":"initDataWithSelector","type":"bytes"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"BeaconCallFailed","type":"error"},{"inputs":[],"name":"BeaconReturnedAddressZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"BeaconReturnedUnexpectedNumberOfBytes","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"stateMutability":"payable","type":"fallback"}]