Skip to content

Commit

Permalink
Enhancements in src resulting from Iaroslav's re-audit
Browse files Browse the repository at this point in the history
  • Loading branch information
IaroslavMazur committed Jun 14, 2023
1 parent 5997ac0 commit 6ae1ca6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/SablierV2LockupDynamic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ contract SablierV2LockupDynamic is
}

/// @dev See the documentation for the user-facing functions that call this internal function.
function _withdrawableAmountOf(uint256 streamId) internal view override returns (uint128 withdrawableAmount) {
function withdrawableAmountOf(uint256 streamId) public view override(ISablierV2Lockup, SablierV2Lockup) notNull(streamId) returns (uint128 withdrawableAmount) {
withdrawableAmount = _streamedAmountOf(streamId) - _streams[streamId].amounts.withdrawn;
}

Expand Down Expand Up @@ -654,7 +654,7 @@ contract SablierV2LockupDynamic is
/// @dev See the documentation for the user-facing functions that call this internal function.
function _withdraw(uint256 streamId, address to, uint128 amount) internal override {
// Checks: the withdraw amount is not greater than the withdrawable amount.
uint128 withdrawableAmount = _withdrawableAmountOf(streamId);
uint128 withdrawableAmount = withdrawableAmountOf(streamId);
if (amount > withdrawableAmount) {
revert Errors.SablierV2Lockup_Overdraw(streamId, amount, withdrawableAmount);
}
Expand Down
4 changes: 2 additions & 2 deletions src/SablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ contract SablierV2LockupLinear is
}

/// @dev See the documentation for the user-facing functions that call this internal function.
function _withdrawableAmountOf(uint256 streamId) internal view override returns (uint128 withdrawableAmount) {
function withdrawableAmountOf(uint256 streamId) public view override(ISablierV2Lockup, SablierV2Lockup) notNull(streamId) returns (uint128 withdrawableAmount) {
withdrawableAmount = _streamedAmountOf(streamId) - _streams[streamId].amounts.withdrawn;
}

Expand Down Expand Up @@ -556,7 +556,7 @@ contract SablierV2LockupLinear is
/// @dev See the documentation for the user-facing functions that call this internal function.
function _withdraw(uint256 streamId, address to, uint128 amount) internal override {
// Checks: the withdraw amount is not greater than the withdrawable amount.
uint128 withdrawableAmount = _withdrawableAmountOf(streamId);
uint128 withdrawableAmount = withdrawableAmountOf(streamId);
if (amount > withdrawableAmount) {
revert Errors.SablierV2Lockup_Overdraw(streamId, amount, withdrawableAmount);
}
Expand Down
18 changes: 3 additions & 15 deletions src/abstracts/SablierV2Lockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,6 @@ abstract contract SablierV2Lockup is
/// @inheritdoc ISablierV2Lockup
function wasCanceled(uint256 streamId) public view virtual override returns (bool result);

/// @inheritdoc ISablierV2Lockup
function withdrawableAmountOf(uint256 streamId)
external
view
override
notNull(streamId)
returns (uint128 withdrawableAmount)
{
withdrawableAmount = _withdrawableAmountOf(streamId);
}

/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -217,9 +206,11 @@ abstract contract SablierV2Lockup is
_withdraw(streamId, to, amount);
}

function withdrawableAmountOf(uint256 streamId) public virtual view returns (uint128 withdrawableAmount);

/// @inheritdoc ISablierV2Lockup
function withdrawMax(uint256 streamId, address to) external override {
withdraw(streamId, to, _withdrawableAmountOf(streamId));
withdraw(streamId, to, withdrawableAmountOf(streamId));
}

/// @inheritdoc ISablierV2Lockup
Expand Down Expand Up @@ -272,9 +263,6 @@ abstract contract SablierV2Lockup is
/// @dev Retrieves the stream's status without performing a null check.
function _statusOf(uint256 streamId) internal view virtual returns (Lockup.Status status);

/// @dev See the documentation for the user-facing functions that call this internal function.
function _withdrawableAmountOf(uint256 streamId) internal view virtual returns (uint128 withdrawableAmount);

/*//////////////////////////////////////////////////////////////////////////
INTERNAL NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
Expand Down
1 change: 0 additions & 1 deletion test/utils/Fuzzers.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;

import { Math } from "@openzeppelin/contracts/utils/math/Math.sol";
import { PRBMathCastingUint128 as CastingUint128 } from "@prb/math/casting/Uint128.sol";
import { UD60x18, ud, uUNIT } from "@prb/math/UD60x18.sol";

Expand Down

0 comments on commit 6ae1ca6

Please sign in to comment.