Skip to content

Commit

Permalink
Merge pull request #22 from GenerationSoftware/main
Browse files Browse the repository at this point in the history
pull in latest changes
  • Loading branch information
trmid authored Aug 30, 2023
2 parents e920407 + 49240b4 commit e0e9a83
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/TwabController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ error PeriodLengthTooShort();
/// @param periodOffset The period offset that was passed in
error PeriodOffsetInFuture(uint48 periodOffset);

/// @notice Emitted when a user tries to mint or transfer to the zero address
error TransferToZeroAddress();

// The minimum period length
uint48 constant MINIMUM_PERIOD_LENGTH = 1 hours;

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

/**
Expand All @@ -37,8 +41,6 @@ address constant SPONSORSHIP_ADDRESS = address(1);
*/
contract TwabController {
using SafeCast for uint256;

/// @notice Allows users to revoke their chances to win by delegating to the sponsorship address.

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

Expand All @@ -471,6 +476,9 @@ contract TwabController {
* @param _amount The amount to transfer
*/
function transfer(address _from, address _to, uint112 _amount) external {
if (_to == address(0)) {
revert TransferToZeroAddress();
}
_transferBalance(msg.sender, _from, _to, _amount);
}

Expand Down
18 changes: 18 additions & 0 deletions test/TwabController.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
MINIMUM_PERIOD_LENGTH,
PeriodLengthTooShort,
SPONSORSHIP_ADDRESS,
TransferToZeroAddress,
PeriodOffsetInFuture
} from "../src/TwabController.sol";
import {
Expand Down Expand Up @@ -735,6 +736,23 @@ contract TwabControllerTest is BaseTest {
assertEq(twabController.delegateOf(mockVault, alice), bob);
}

function testMint_toZero() public {
vm.startPrank(mockVault);

uint96 _amount = 1000e18;
vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector));
twabController.mint(address(0), _amount);
}

function testTransfer_toZero() public {
vm.startPrank(mockVault);

uint96 _amount = 1000e18;
twabController.mint(alice, _amount);
vm.expectRevert(abi.encodeWithSelector(TransferToZeroAddress.selector));
twabController.transfer(alice, address(0), _amount);
}

function testDelegate_toSelf() public {
vm.startPrank(mockVault);

Expand Down

0 comments on commit e0e9a83

Please sign in to comment.