Skip to content

Commit

Permalink
Add natspecs for SelfdestructEthSender and mock
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Apr 4, 2024
1 parent fb8c3f2 commit 588be93
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
15 changes: 14 additions & 1 deletion contracts/mixins/SelfdestructEthSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

pragma solidity ^0.8.25;


/**
* @title SelfdestructEthSender
* @notice A one-time-use contract for cost-effective ETH transfers using the `selfdestruct` mechanism.
* @dev Upon construction, this contract verifies EVM compatibility with the Cancun upgrade, specifically
* testing for support of transient storage via `tload`. It is intended for single-use, allowing for ETH to
* be sent more cheaply by self-destructing and sending its balance to a designated address.
*/
abstract contract SelfdestructEthSender {
/**
* @dev Initializes the contract, verifying compatibility with the Cancun EVM upgrade through transient storage support check.
*/
constructor() {
// tload is done to verify that the EVM is cancun-compatible
// solhint-disable-next-line no-inline-assembly
Expand All @@ -12,6 +21,10 @@ abstract contract SelfdestructEthSender {
}
}

/**
* @notice Self-destruct contract, transferring the entire ETH balance of the contract to the specified address.
* @param receiver The recipient address of the contract's ETH balance.
*/
function stopAndTransferBalance(address payable receiver) external {
selfdestruct(receiver);
}
Expand Down
10 changes: 10 additions & 0 deletions contracts/mocks/SelfdestructEthSenderMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ pragma solidity ^0.8.25;

import "../mixins/SelfdestructEthSender.sol";

/**
* @title SelfdestructEthSenderMock
* @notice Mock contract extending SelfdestructEthSender for testing purposes, with added functionality to transfer ETH.
*/
contract SelfdestructEthSenderMock is SelfdestructEthSender {
/// @notice Indicates that an attempt to transfer ETH has failed.
error ETHTransferFailed();

/// @notice Allows the contract to receive ETH.
receive() external payable {}

/**
* @notice Transfers the contract's entire ETH balance to the specified address.
* @param receiver The address to which the contract's ETH balance will be transferred.
*/
function transferBalance(address payable receiver) external payable {
// solhint-disable-next-line avoid-low-level-calls
(bool success, ) = receiver.call{value: address(this).balance}("");
Expand Down

0 comments on commit 588be93

Please sign in to comment.