Skip to content
Verified contractExact

recoverooor

Address0x01e051e2f6af54ef9c599961ccf4b58e86f4e66e
Balance

0 ETH

 

Transactions

1

 

Compiler

vyper 0.4.2

 

Same code

42 more contracts

 

Details

Compiler
vyper 0.4.2+commit.c216787f
Language
vyper
License
Not stated
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
24,346,759
Creation transaction
0x55e9cf14fb…10a29bc175

recoverooor.vy

# pragma version ~=0.4.2
# pragma nonreentrancy off
"""
@title Multi-Token Recovery Contract
@custom:contract-name recoverooor
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions support (batch) recovery of both native assets
        and tokens across any standard (e.g., ERC-20, ERC-721, ERC-1155).
        When using EIP-7702 (https://eips.ethereum.org/EIPS/eip-7702),
        you can delegate to this contract and safely invoke and broadcast
        the appropriate recovery function from a trusted `OWNER` account.
        For batch recovery of native assets alongside multiple token transfers
        in a single transaction, use the `recover_multicall` function.
@custom:security This contract is untested and has not undergone a security audit.
                 Use with caution!
"""


# @dev We import the `IERC20`, `IERC721`, and `IERC1155` interfaces to
# enable easy recovery of these token types when EIP-7702 delegation is
# used.
from ethereum.ercs import IERC20
from ethereum.ercs import IERC721
from snekmate.tokens.interfaces import IERC1155


# @dev We import the `multicall` module.
# @notice Please note that the `multicall` module is stateless and therefore
# does not require the `initializes` keyword for initialisation.
from snekmate.utils import multicall


# @dev Stores the upper bound for batch calls.
_BATCH_SIZE: constant(uint8) = 128


# @dev Sets the trusted `OWNER` account.
# @notice We use an `immutable` variable instead of storage, since writes to storage
# in the constructor do not persist when using this contract as an implementation.
OWNER: public(immutable(address))


@deploy
def __init__(owner_: address):
    """
    @dev Transfers the ownership of the contract to a
         (trusted) account `owner_`.
    @param owner_ The 20-byte address of the owner.
    """
    OWNER = owner_


@external
def recover_eth():
    """
    @dev Transfers the full ether balance to a (trusted)
         account `OWNER`.
    """
    self._check_owner()
    # We force the full ether balance into the `OWNER` address.
    # For the `selfdestruct` behaviour, see: https://eips.ethereum.org/EIPS/eip-6780.
    selfdestruct(OWNER)


@external
def recover_erc20(tokens: DynArray[IERC20, _BATCH_SIZE]):
    """
    @dev Transfers the full ERC-20 balances of the specified
         contract addresses to a (trusted) account `OWNER`.
    @param tokens The 20-byte array of ERC-20 token contract
           addresses that are being transferred.
    """
    self._check_owner()
    for token: IERC20 in tokens:
        assert extcall token.transfer(
            OWNER, staticcall token.balanceOf(self), default_return_value=True
        ), "recoverooor: erc-20 transfer operation did not succeed"


@external
def recover_erc721(
    tokens: DynArray[IERC721, _BATCH_SIZE], token_ids: DynArray[DynArray[uint256, _BATCH_SIZE], _BATCH_SIZE]
):
    """
    @dev Transfers all ERC-721 `token_ids` of the specified
         contract addresses to a (trusted) account `OWNER`.
    @param tokens The 20-byte array of ERC-721 token contract
           addresses that are being transferred. Note that the
           length must match the 32-byte `token_ids` array.
    @param token_ids The 32-byte array of ERC-721 `token_ids`
           for each ERC-721 contract that are being transferred.
           Note that the length must match the 20-byte `tokens`
           array.
    """
    self._check_owner()
    assert len(tokens) == len(token_ids), "recoverooor: `tokens` and `token_ids` length mismatch"
    idx: uint256 = empty(uint256)
    for token: IERC721 in tokens:
        ids: DynArray[uint256, _BATCH_SIZE] = token_ids[idx]
        for id: uint256 in ids:
            extcall token.transferFrom(self, OWNER, id)
        idx = unsafe_add(idx, 1)


@external
def recover_erc1155(
    tokens: DynArray[IERC1155, _BATCH_SIZE],
    ids: DynArray[DynArray[uint256, _BATCH_SIZE], _BATCH_SIZE],
    amounts: DynArray[DynArray[uint256, _BATCH_SIZE], _BATCH_SIZE],
):
    """
    @dev Transfers all `amounts` for the token type `ids` of the
         specified ERC-1155 contract addresses `tokens` to a (trusted)
         account `OWNER`.
    @param tokens The 20-byte array of ERC-1155 token contract
           addresses that are being transferred. Note that the
           length must match the 32-byte `ids` and `amounts` arrays.
    @param ids The 32-byte array of token identifiers. Note that the
           length must match the 20-byte `tokens` arrays. Furthermore,
           note that for each array entry the order and length must
           match the 32-byte `amounts` array.
    @param amounts The 32-byte array of token amounts that are
           being transferred. Note that the length must match the
           20-byte `tokens` arrays. Furthermore, note that for each
           array entry the order and length must match the 32-byte
           `ids` array.
    """
    self._check_owner()
    assert len(tokens) == len(ids), "recoverooor: `tokens` and `ids` length mismatch"
    assert len(tokens) == len(amounts), "recoverooor: `tokens` and `amounts` length mismatch"
    idx: uint256 = empty(uint256)
    for token: IERC1155 in tokens:
        assert len(ids[idx]) == len(amounts[idx]), "recoverooor: `ids` and `amounts` length mismatch"
        extcall token.safeBatchTransferFrom(self, OWNER, ids[idx], amounts[idx], b"")
        idx = unsafe_add(idx, 1)


@external
@payable
def recover_multicall(
    data: DynArray[multicall.BatchValue, multicall._DYNARRAY_BOUND]
) -> DynArray[multicall.Result, multicall._DYNARRAY_BOUND]:
    """
    @dev Aggregates function calls with a `msg.value`, ensuring
         that each function returns successfully if required. Since
         this function uses `CALL`, the `msg.sender` will be the
         `recoverooor` contract itself.
    @notice This function is fully customisable and does not enforce
            any transfers to a (trusted) `OWNER` account, although this
            is still the recommended approach.
    @param data The array of `BatchValue` structs.
    @return DynArray The array of `Result` structs.
    """
    self._check_owner()
    return multicall._multicall_value(data)


@internal
def _check_owner():
    """
    @dev Throws if the sender is not the owner.
    """
    assert msg.sender == OWNER, "recoverooor: caller is not the owner"

venv/Lib/site-packages/snekmate/tokens/interfaces/IERC1155.vyi

# pragma version ~=0.4.2
"""
@title EIP-1155 Interface Definition
@custom:contract-name IERC1155
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice The required interface definition of an ERC-1155
        compliant smart contract as defined in:
        https://eips.ethereum.org/EIPS/eip-1155. Note that
        smart contracts implementing the ERC-1155 standard
        must implement all of the functions in the ERC-1155
        interface. For more details, please refer to:
        https://eips.ethereum.org/EIPS/eip-1155#specification.

        Note that Vyper interfaces that implement functions
        with return values that require an upper bound (e.g.
        `Bytes`, `DynArray`, or `String`), the upper bound
        defined in the interface represents the lower bound
        of the implementation:
        https://github.com/vyperlang/vyper/pull/3205.

        On how to use interfaces in Vyper, please visit:
        https://vyper.readthedocs.io/en/latest/interfaces.html#interfaces.
"""


# @dev We import and implement the `IERC165` interface,
# which is a built-in interface of the Vyper compiler.
from ethereum.ercs import IERC165
implements: IERC165


# @dev Emitted when `_value` tokens of token type
# `_id` are transferred from `_from` to `_to` by
# `_operator`.
event TransferSingle:
    _operator: indexed(address)
    _from: indexed(address)
    _to: indexed(address)
    _id: uint256
    _value: uint256


# @dev Equivalent to multiple `TransferSingle` events,
# where `_operator`, `_from`, and `_to` are the same
# for all transfers.
event TransferBatch:
    _operator: indexed(address)
    _from: indexed(address)
    _to: indexed(address)
    _ids: DynArray[uint256, 128]
    _values: DynArray[uint256, 128]


# @dev Emitted when `_owner` grants or revokes permission
# to `_operator` to transfer their tokens, according to
# `_approved`.
event ApprovalForAll:
    _owner: indexed(address)
    _operator: indexed(address)
    _approved: bool


# @dev Emitted when the Uniform Resource Identifier (URI)
# for token type `_id` changes to `_value`, if it is a
# non-programmatic URI. Note that if an `URI` event was
# emitted for `_id`, the EIP-1155 standard guarantees that
# `_value` will equal the value returned by {IERC1155MetadataURI-uri}.
event URI:
    _value: String[512]
    _id: indexed(uint256)


@external
@view
def supportsInterface(interfaceId: bytes4) -> bool:
    """
    @dev Returns `True` if this contract implements the
         interface defined by `interfaceId`.
    @notice For more details on how these identifiers are
            created, please refer to:
            https://eips.ethereum.org/EIPS/eip-165.
    @param interfaceId The 4-byte interface identifier.
    @return bool The verification whether the contract
            implements the interface or not.
    """
    ...


@external
def safeTransferFrom(_from: address, _to: address, _id: uint256, _value: uint256, _data: Bytes[1_024]):
    """
    @dev Transfers `_value` tokens of token type `_id` from
         `_from` to `_to`.
    @notice Note that `_to` cannot be the zero address. Also,
            if the caller is not `_from`, it must have been
            approved to spend `_from`'s tokens via `setApprovalForAll`.
            Furthermore, `_from` must have a balance of tokens
            of type `_id` of at least `_value`. Eventually, if
            `_to` refers to a smart contract, it must implement
            {IERC1155Receiver-onERC1155Received} and return the
            acceptance magic value.

            WARNING: This function can potentially allow a reentrancy
            attack when transferring tokens to an untrusted contract,
            when invoking {IERC1155Receiver-onERC1155Received} on the
            receiver. Ensure to follow the checks-effects-interactions
            (CEI) pattern and consider employing reentrancy guards when
            interacting with untrusted contracts.
    @param _from The 20-byte address which previously
           owned the token.
    @param _to The 20-byte receiver address.
    @param _id The 32-byte identifier of the token.
    @param _value The 32-byte token amount that is
           being transferred.
    @param _data The maximum 1,024-byte additional data
           with no specified format.
    """
    ...


@external
def safeBatchTransferFrom(
    _from: address, _to: address, _ids: DynArray[uint256, 128], _values: DynArray[uint256, 128], _data: Bytes[1_024]
):
    """
    @dev Batched version of `safeTransferFrom`.
    @notice Note that `_ids` and `_values` must have the
            same length. Also, if `_to` refers to a smart
            contract, it must implement {IERC1155Receiver-onERC1155BatchReceived}
            and return the acceptance magic value.

            WARNING: This function can potentially allow a reentrancy
            attack when transferring tokens to an untrusted contract,
            when invoking {IERC1155Receiver-onERC1155BatchReceived} on
            the receiver. Ensure to follow the checks-effects-interactions
            (CEI) pattern and consider employing reentrancy guards when
            interacting with untrusted contracts.
    @param _from The 20-byte address which previously
           owned the token.
    @param _to The 20-byte receiver address.
    @param _ids The 32-byte array of token identifiers. Note
           that the order and length must match the 32-byte
           `_values` array.
    @param _values The 32-byte array of token amounts that are being
           transferred. Note that the order and length must match
           the 32-byte `_ids` array.
    @param _data The maximum 1,024-byte additional data
           with no specified format.
    """
    ...


@external
@view
def balanceOf(_owner: address, _id: uint256) -> uint256:
    """
    @dev Returns the amount of tokens of token type
         `_id` owned by `_owner`.
    @param _owner The 20-byte owner address.
    @param _id The 32-byte identifier of the token.
    @return uint256 The 32-byte token amount owned
            by `_owner`.
    """
    ...


@external
@view
def balanceOfBatch(_owners: DynArray[address, 128], _ids: DynArray[uint256, 128]) -> DynArray[uint256, 128]:
    """
    @dev Batched version of `balanceOf`.
    @notice Note that `_owners` and `_ids` must have the
            same length.
    @param _owners The 20-byte array of owner addresses.
    @param _ids The 32-byte array of token identifiers.
    @return DynArray The 32-byte array of token amounts
            owned by `_owners`.
    """
    ...


@external
def setApprovalForAll(_operator: address, _approved: bool):
    """
    @dev Grants or revokes permission to `_operator` to
         transfer the caller's tokens, according to `_approved`.
    @notice Note that `_operator` cannot be the caller.
    @param _operator The 20-byte operator address.
    @param _approved The Boolean variable that sets the
           approval status.
    """
    ...


@external
@view
def isApprovedForAll(_owner: address, _operator: address) -> bool:
    """
    @dev Returns `True` if `_operator` is approved to transfer
         `_owner`'s tokens.
    @notice Note that `_operator` cannot be the caller.
    @param _owner The 20-byte owner address.
    @param _operator The 20-byte operator address.
    @return bool The verification whether `_operator` is approved
            or not.
    """
    ...

venv/Lib/site-packages/snekmate/utils/multicall.vy

# pragma version ~=0.4.2
# pragma nonreentrancy off
"""
@title Multicall Functions
@custom:contract-name multicall
@license GNU Affero General Public License v3.0 only
@author pcaversaccio
@notice These functions can be used to batch together multiple `external`
        function calls into one single `external` function call. Please note
        that this contract is written in the most agnostic way possible and
        users should adjust statically allocatable memory to their specific
        needs before deploying it:
        https://github.com/pcaversaccio/snekmate/discussions/82.
        The implementation is inspired by Matt Solomon's implementation here:
        https://github.com/mds1/multicall/blob/main/src/Multicall3.sol.
@custom:security You must ensure that any contract that integrates the `CALL`-based
                 `multicall` and `multicall_value` functions never holds funds after
                 the end of a transaction. Otherwise, any ETH, tokens, or other funds
                 held by this contract can be stolen. Also, never approve a contract
                 that integrates the `CALL`-based functions `multicall` and `multicall_value`
                 to spend your tokens. If you do, anyone can steal your tokens! Eventually,
                 please make sure you understand how `msg.sender` works in `CALL` vs
                 `DELEGATECALL` to the multicall contract, as well as the risks of
                 using `msg.value` in a multicall. To learn more about the latter, see:
                 - https://github.com/runtimeverification/verified-smart-contracts/wiki/List-of-Security-Vulnerabilities#payable-multicall,
                 - https://samczsun.com/two-rights-might-make-a-wrong.
"""


# @dev Stores the 1-byte upper bound for the dynamic arrays.
_DYNARRAY_BOUND: constant(uint8) = max_value(uint8)


# @dev Batch struct for ordinary (i.e. `nonpayable`) function calls.
struct Batch:
    target: address
    allow_failure: bool
    calldata: Bytes[1_024]


# @dev Batch struct for `payable` function calls.
struct BatchValue:
    target: address
    allow_failure: bool
    value: uint256
    calldata: Bytes[1_024]


# @dev Batch struct for ordinary (i.e. `nonpayable`) function calls
# using this contract as destination address.
struct BatchSelf:
    allow_failure: bool
    calldata: Bytes[1_024]


# @dev Result struct for function call results.
struct Result:
    success: bool
    return_data: Bytes[max_value(uint8)]


@deploy
@payable
def __init__():
    """
    @dev To omit the opcodes for checking the `msg.value`
         in the creation-time EVM bytecode, the constructor
         is declared as `payable`.
    """
    pass


@internal
def _multicall(data: DynArray[Batch, _DYNARRAY_BOUND]) -> DynArray[Result, _DYNARRAY_BOUND]:
    """
    @dev Aggregates function calls, ensuring that each
         function returns successfully if required.
         Since this function uses `CALL`, the `msg.sender`
         will be the multicall contract itself.
    @notice It is important to note that an external call
            via `raw_call` does not perform an external code
            size check on the target address.
    @param data The array of `Batch` structs.
    @return DynArray The array of `Result` structs.
    """
    results: DynArray[Result, _DYNARRAY_BOUND] = []
    success: bool = empty(bool)
    return_data: Bytes[max_value(uint8)] = b""
    for batch: Batch in data:
        if batch.allow_failure:
            success, return_data = raw_call(batch.target, batch.calldata, max_outsize=255, revert_on_failure=False)
        else:
            success = True
            return_data = raw_call(batch.target, batch.calldata, max_outsize=255)
        results.append(Result(success=success, return_data=return_data))
    return results


@internal
@payable
def _multicall_value(data: DynArray[BatchValue, _DYNARRAY_BOUND]) -> DynArray[Result, _DYNARRAY_BOUND]:
    """
    @dev Aggregates function calls with a `msg.value`,
         ensuring that each function returns successfully
         if required. Since this function uses `CALL`,
         the `msg.sender` will be the multicall contract
         itself.
    @notice It is important to note that an external call
            via `raw_call` does not perform an external code
            size check on the target address.
    @param data The array of `BatchValue` structs.
    @return DynArray The array of `Result` structs.
    """
    value_accumulator: uint256 = empty(uint256)
    results: DynArray[Result, _DYNARRAY_BOUND] = []
    success: bool = empty(bool)
    return_data: Bytes[max_value(uint8)] = b""
    for batch: BatchValue in data:
        msg_value: uint256 = batch.value
        # WARNING: If you expect to hold any funds in a contract that integrates
        # this function, you must ensure that the next line uses checked arithmetic!
        # Please read the contract-level security notice carefully. For further
        # insights also, see the following X thread:
        # https://x.com/Guhu95/status/1736983530343981307.
        value_accumulator = unsafe_add(value_accumulator, msg_value)
        if batch.allow_failure:
            success, return_data = raw_call(
                batch.target, batch.calldata, max_outsize=255, value=msg_value, revert_on_failure=False
            )
        else:
            success = True
            return_data = raw_call(batch.target, batch.calldata, max_outsize=255, value=msg_value)
        results.append(Result(success=success, return_data=return_data))
    assert msg.value == value_accumulator, "multicall: value mismatch"
    return results


@internal
def _multicall_self(data: DynArray[BatchSelf, _DYNARRAY_BOUND]) -> DynArray[Result, _DYNARRAY_BOUND]:
    """
    @dev Aggregates function calls using `DELEGATECALL`,
         ensuring that each function returns successfully
         if required. Since this function uses `DELEGATECALL`,
         the `msg.sender` remains the same account that
         invoked the function `multicall_self` in the first place.
    @notice Developers can include this function in their own
            contract so that users can submit multiple function
            calls in one transaction. Since the `msg.sender` is
            preserved, it's equivalent to sending multiple transactions
            from an EOA (externally-owned account, i.e. non-contract account).

            Furthermore, it is important to note that an external
            call via `raw_call` does not perform an external code
            size check on the target address.
    @param data The array of `BatchSelf` structs.
    @return DynArray The array of `Result` structs.
    """
    results: DynArray[Result, _DYNARRAY_BOUND] = []
    success: bool = empty(bool)
    return_data: Bytes[max_value(uint8)] = b""
    for batch: BatchSelf in data:
        if batch.allow_failure:
            success, return_data = raw_call(
                self, batch.calldata, max_outsize=255, is_delegate_call=True, revert_on_failure=False
            )
        else:
            success = True
            return_data = raw_call(self, batch.calldata, max_outsize=255, is_delegate_call=True)
        results.append(Result(success=success, return_data=return_data))
    return results


@internal
@view
def _multistaticcall(data: DynArray[Batch, _DYNARRAY_BOUND]) -> DynArray[Result, _DYNARRAY_BOUND]:
    """
    @dev Aggregates static function calls, ensuring that each
         function returns successfully if required.
    @notice It is important to note that an external call
            via `raw_call` does not perform an external code
            size check on the target address.
    @param data The array of `Batch` structs.
    @return DynArray The array of `Result` structs.
    """
    results: DynArray[Result, _DYNARRAY_BOUND] = []
    success: bool = empty(bool)
    return_data: Bytes[max_value(uint8)] = b""
    for batch: Batch in data:
        if batch.allow_failure:
            success, return_data = raw_call(
                batch.target, batch.calldata, max_outsize=255, is_static_call=True, revert_on_failure=False
            )
        else:
            success = True
            return_data = raw_call(batch.target, batch.calldata, max_outsize=255, is_static_call=True)
        results.append(Result(success=success, return_data=return_data))
    return results
Compiler settingsShow
{
  "search_paths": [
    "venv/Lib/site-packages",
    "venv",
    "."
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.