Verified contractExactUNLICENSED
Eip7702BatchCaller
Address0x63ccfbf8d83a920c814bef93ea44c668a5a264ce
- Balance
0 ETH
- Transactions
12
- Compiler
solc 0.8.28
- Same code
Only this contract
Details
- Compiler
- solc 0.8.28+commit.7893614a
- Language
- solidity
- Optimization
- No
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,205,233
- Creation transaction
- 0xf35beb23ca…643a4bce8f
test.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.28;
contract Eip7702BatchCaller {
// EIP-7702 delegated code prefix: 0xEF0100 || address(20 bytes)
bytes3 public constant DELEGATION_PREFIX = 0xef0100;
uint256 public constant DELEGATED_CODE_LENGTH = 23; // 3 prefix + 20 address
// ---------- Events (replace the former custom errors) ----------
event EmptyWalletArray();
event ArrayLengthMismatch(
uint256 wallets,
uint256 delegatedAddresses,
uint256 data
);
event InvalidAddress(uint256 index, address wallet, address expectedDelegation);
event WalletNotDelegated(uint256 index, address wallet);
event DelegationMismatch(
uint256 index,
address wallet,
address expectedDelegation,
address actualDelegation
);
event CallFailed(uint256 index, address wallet, bytes result);
event CallSucceeded(uint256 index, address wallet, bytes result);
event RefundFailed(address recipient, uint256 amount);
/// @notice Reads the delegation target from an EIP-7702 wallet's code
/// @dev Returns address(0) if the account has no delegation set
function getDelegatedAddress(address _wallet) public view returns (address) {
bytes memory code;
assembly {
code := mload(0x40)
let size := extcodesize(_wallet)
mstore(code, size)
// bounds check: delegation code is exactly 23 bytes
switch eq(size, 23)
case 0 {
mstore(0x40, add(code, add(32, size)))
mstore(code, 0) // signal "not a delegation"
}
default {
extcodecopy(_wallet, add(code, 32), 0, size)
mstore(0x40, add(code, add(32, size)))
}
}
if (code.length != DELEGATED_CODE_LENGTH) return address(0);
bytes3 prefix;
address delegated;
assembly {
// first 3 bytes of the code
prefix := and(mload(add(code, 32)), 0xffffff0000000000000000000000000000000000000000000000000000000000)
// shift right by 3 bytes, then take lowest 20 bytes as address
delegated := shr(72, mload(add(code, 32)))
}
if (prefix != DELEGATION_PREFIX) return address(0);
return delegated;
}
/// @notice Batch-call EIP-7702 wallets, but only if each wallet is
/// delegated to the expected delegation contract
/// @dev Nothing reverts: invalid entries and failed calls emit an event and
/// the loop moves on to the next wallet. msg.value is forwarded to the
/// first call that is actually attempted; if that call fails, or no call
/// is made, the unused value is refunded to msg.sender.
/// @param _walletAddresses The EOA wallets (with 7702 delegation set)
/// @param _delegatedAddresses The delegation contract each wallet must point to
/// @param _data Encoded calls to the delegation contract (e.g. abi.encodeCall(Eip_7702_Wallet.call, (...)))
function callDelegatedWallets(
address[] calldata _walletAddresses,
address[] calldata _delegatedAddresses,
bytes[] calldata _data
) external payable {
// ---------- 1. Validate details ----------
uint256 length = _walletAddresses.length;
if (length == 0) {
emit EmptyWalletArray();
_refund(msg.value);
return;
}
if (_delegatedAddresses.length != length || _data.length != length) {
emit ArrayLengthMismatch(
length,
_delegatedAddresses.length,
_data.length
);
_refund(msg.value);
return;
}
uint256 pendingValue = msg.value;
// ---------- 2. Loop ----------
for (uint256 i; i < length; ++i) {
address wallet = _walletAddresses[i];
address expected = _delegatedAddresses[i];
if (wallet == address(0) || expected == address(0)) {
emit InvalidAddress(i, wallet, expected);
continue;
}
// ---------- 3. Verify wallet is delegated to expected address ----------
address actual = getDelegatedAddress(wallet);
if (actual == address(0)) {
emit WalletNotDelegated(i, wallet);
continue;
}
if (actual != expected) {
emit DelegationMismatch(i, wallet, expected, actual);
continue;
}
// ---------- 4. Send the call data to the wallet ----------
// Forward all pending value on the first attempted call only.
uint256 valueToSend = pendingValue;
(bool success, bytes memory result) = wallet.call{value: valueToSend}(
_data[i]
);
if (!success) {
emit CallFailed(i, wallet, result);
continue;
}
pendingValue = 0;
emit CallSucceeded(i, wallet, result);
}
// ---------- 5. Return any value that was never delivered ----------
_refund(pendingValue);
}
function _refund(uint256 _amount) private {
if (_amount == 0) return;
(bool ok, ) = msg.sender.call{value: _amount}("");
if (!ok) emit RefundFailed(msg.sender, _amount);
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.