Skip to content

Commit e0e9a83

Browse files
authored
Merge pull request #22 from GenerationSoftware/main
pull in latest changes
2 parents e920407 + 49240b4 commit e0e9a83

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/TwabController.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ error PeriodLengthTooShort();
1818
/// @param periodOffset The period offset that was passed in
1919
error PeriodOffsetInFuture(uint48 periodOffset);
2020

21+
/// @notice Emitted when a user tries to mint or transfer to the zero address
22+
error TransferToZeroAddress();
23+
2124
// The minimum period length
2225
uint48 constant MINIMUM_PERIOD_LENGTH = 1 hours;
2326

27+
// Allows users to revoke their chances to win by delegating to the sponsorship address.
2428
address constant SPONSORSHIP_ADDRESS = address(1);
2529

2630
/**
@@ -37,8 +41,6 @@ address constant SPONSORSHIP_ADDRESS = address(1);
3741
*/
3842
contract TwabController {
3943
using SafeCast for uint256;
40-
41-
/// @notice Allows users to revoke their chances to win by delegating to the sponsorship address.
4244

4345
/// @notice Sets the minimum period length for Observations. When a period elapses, a new Observation is recorded, otherwise the most recent Observation is updated.
4446
uint48 public immutable PERIOD_LENGTH;
@@ -447,6 +449,9 @@ contract TwabController {
447449
* @param _amount The amount to mint
448450
*/
449451
function mint(address _to, uint112 _amount) external {
452+
if (_to == address(0)) {
453+
revert TransferToZeroAddress();
454+
}
450455
_transferBalance(msg.sender, address(0), _to, _amount);
451456
}
452457

@@ -471,6 +476,9 @@ contract TwabController {
471476
* @param _amount The amount to transfer
472477
*/
473478
function transfer(address _from, address _to, uint112 _amount) external {
479+
if (_to == address(0)) {
480+
revert TransferToZeroAddress();
481+
}
474482
_transferBalance(msg.sender, _from, _to, _amount);
475483
}
476484

test/TwabController.t.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
MINIMUM_PERIOD_LENGTH,
1212
PeriodLengthTooShort,
1313
SPONSORSHIP_ADDRESS,
14+
TransferToZeroAddress,
1415
PeriodOffsetInFuture
1516
} from "../src/TwabController.sol";
1617
import {
@@ -735,6 +736,23 @@ contract TwabControllerTest is BaseTest {
735736
assertEq(twabController.delegateOf(mockVault, alice), bob);
736737
}
737738

739+
function testMint_toZero() public {
740+
vm.startPrank(mockVault);
741+
742+
uint96 _amount = 1000e18;
743+
vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector));
744+
twabController.mint(address(0), _amount);
745+
}
746+
747+
function testTransfer_toZero() public {
748+
vm.startPrank(mockVault);
749+
750+
uint96 _amount = 1000e18;
751+
twabController.mint(alice, _amount);
752+
vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector));
753+
twabController.transfer(alice, address(0), _amount);
754+
}
755+
738756
function testDelegate_toSelf() public {
739757
vm.startPrank(mockVault);
740758

0 commit comments

Comments
 (0)