Skip to content

Commit

Permalink
fix: check the start time in SablierV2LockupLinear._calculateStreamed…
Browse files Browse the repository at this point in the history
…Amount (#941)

test: test streamedAmountOf when cliff time is zero and the stream is
PENDING
test: correct tree branches in streamedAmountOf
  • Loading branch information
andreivladbrg committed Jul 3, 2024
1 parent 3836bf9 commit 63f7d97
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/SablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@ contract SablierV2LockupLinear is
/// - $d$ is the deposited amount.
/// - $c$ is the cliff amount.
function _calculateStreamedAmount(uint256 streamId) internal view override returns (uint128) {
// If the cliff time is in the future, return zero.
uint256 cliffTime = uint256(_cliffs[streamId]);
uint256 startTime = uint256(_streams[streamId].startTime);
uint256 blockTimestamp = block.timestamp;
if (cliffTime > blockTimestamp) {

// If the cliff time or the start time is in the future, return zero.
if (cliffTime > blockTimestamp || startTime > blockTimestamp) {
return 0;
}

Expand All @@ -204,7 +206,6 @@ contract SablierV2LockupLinear is
// because there is no mix of amounts with different decimals.
unchecked {
// Calculate how much time has passed since the stream started, and the stream's total duration.
uint256 startTime = uint256(_streams[streamId].startTime);
UD60x18 elapsedTime = ud(blockTimestamp - startTime);
UD60x18 totalDuration = ud(endTime - startTime);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22 <0.9.0;

import { LockupLinear } from "src/types/DataTypes.sol";

import { LockupLinear_Integration_Concrete_Test } from "../LockupLinear.t.sol";
import { StreamedAmountOf_Integration_Concrete_Test } from "../../lockup/streamed-amount-of/streamedAmountOf.t.sol";

Expand All @@ -17,7 +19,28 @@ contract StreamedAmountOf_LockupLinear_Integration_Concrete_Test is
StreamedAmountOf_Integration_Concrete_Test.setUp();
}

function test_StreamedAmountOf_CliffTimeInThePast()
modifier givenStatusPendind() {
_;
}

function test_StreamedAmountOf_CliffTimeZero()
external
givenNotNull
givenStreamHasNotBeenCanceled
givenStatusPendind
{
vm.warp({ newTimestamp: defaults.START_TIME() - 1 });

LockupLinear.Timestamps memory timestamps = defaults.lockupLinearTimestamps();
timestamps.cliff = 0;
uint256 streamId = createDefaultStreamWithTimestamps(timestamps);

uint128 actualStreamedAmount = lockupLinear.streamedAmountOf(streamId);
uint128 expectedStreamedAmount = 0;
assertEq(actualStreamedAmount, expectedStreamedAmount, "streamedAmount");
}

function test_StreamedAmountOf_CliffTimeInTheFuture()
external
view
givenNotNull
Expand All @@ -41,7 +64,7 @@ contract StreamedAmountOf_LockupLinear_Integration_Concrete_Test is
assertEq(actualStreamedAmount, expectedStreamedAmount, "streamedAmount");
}

function test_StreamedAmountOf_CliffTimeInTheFuture()
function test_StreamedAmountOf_CliffTimeInThePast()
external
givenNotNull
givenStreamHasNotBeenCanceled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
streamedAmountOf.t.sol
├── given the stream's status is "PENDING"
│ └── given the cliff time is zero
│ └── it should return zero
└── given the stream's status is "STREAMING"
├── given the cliff time is in the past
├── given the cliff time is in the future
│ └── it should return zero
├── given the cliff time is in the present
│ └── it should return the correct streamed amount
└── given the cliff time is in the future
└── given the cliff time is in the past
└── it should return the correct streamed amount

0 comments on commit 63f7d97

Please sign in to comment.