-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add "withdrawMax" in "SablierV2"
docs: fix note about "to" address in NatSpec for "withdraw" docs: improve wording in NatSpec comments refactor: define "getWithdrawableAmount" in "SablierV2" test: rename "StreamEnded" branch to "CurrentTimeEqualToStopTme" test: rename "StreamOngoing" branch to "CurrentTimeLessThanStopTime" test: rename "withdrawableAmount" variable to "streamedAmount" test: test "withdrawMax" function
- Loading branch information
Showing
12 changed files
with
145 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/unit/sablier-v2/linear/withdraw-max/withdrawMax.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.13 <0.9.0; | ||
|
||
import { ISablierV2 } from "src/interfaces/ISablierV2.sol"; | ||
|
||
import { LinearTest } from "test/unit/sablier-v2/linear/LinearTest.t.sol"; | ||
import { WithdrawMax_Test } from "test/unit/sablier-v2/shared/withdraw-max/withdrawMax.t.sol"; | ||
|
||
contract WithdrawMax_LinearTest is LinearTest, WithdrawMax_Test { | ||
function setUp() public virtual override(LinearTest, WithdrawMax_Test) { | ||
WithdrawMax_Test.setUp(); | ||
sablierV2 = ISablierV2(linear); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.13 <0.9.0; | ||
|
||
import { ISablierV2 } from "src/interfaces/ISablierV2.sol"; | ||
|
||
import { ProTest } from "test/unit/sablier-v2/pro/ProTest.t.sol"; | ||
import { WithdrawMax_Test } from "test/unit/sablier-v2/shared/withdraw-max/withdrawMax.t.sol"; | ||
|
||
contract WithdrawMax_ProTest is ProTest, WithdrawMax_Test { | ||
function setUp() public virtual override(ProTest, WithdrawMax_Test) { | ||
WithdrawMax_Test.setUp(); | ||
sablierV2 = ISablierV2(pro); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
test/unit/sablier-v2/shared/withdraw-max/withdrawMax.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.13 <0.9.0; | ||
|
||
import { IERC20 } from "@prb/contracts/token/erc20/IERC20.sol"; | ||
|
||
import { Events } from "src/libraries/Events.sol"; | ||
|
||
import { SharedTest } from "../SharedTest.t.sol"; | ||
|
||
abstract contract WithdrawMax_Test is SharedTest { | ||
uint256 internal defaultStreamId; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
|
||
// Create the default stream. | ||
defaultStreamId = createDefaultStream(); | ||
|
||
// Make the recipient the caller in this test suite. | ||
changePrank(users.recipient); | ||
} | ||
|
||
/// @dev it should make the withdrawal and delete the stream. | ||
function test_WithdrawMax_CurrentTimeEqualToStopTime() external { | ||
// Warp to the end of the stream. | ||
vm.warp({ timestamp: DEFAULT_STOP_TIME }); | ||
|
||
// Make the withdrawal. | ||
sablierV2.withdrawMax({ streamId: defaultStreamId, to: users.recipient }); | ||
|
||
// Assert that the stream was deleted. | ||
assertDeleted(defaultStreamId); | ||
|
||
// Assert that the NFT was not burned. | ||
address actualNFTowner = sablierV2.ownerOf({ tokenId: defaultStreamId }); | ||
address expectedNFTOwner = users.recipient; | ||
assertEq(actualNFTowner, expectedNFTOwner); | ||
} | ||
|
||
modifier currentTimeLessThanStopTime() { | ||
_; | ||
} | ||
|
||
/// @dev it should make the max withdrawal, emit a Withdraw event, and update the withdrawn amount | ||
function testFuzz_WithdrawMax(uint256 timeWarp) external currentTimeLessThanStopTime { | ||
timeWarp = bound(timeWarp, DEFAULT_CLIFF_DURATION, DEFAULT_TOTAL_DURATION - 1); | ||
|
||
// Warp into the future. | ||
vm.warp({ timestamp: DEFAULT_START_TIME + timeWarp }); | ||
|
||
// Bound the withdraw amount. | ||
uint128 withdrawAmount = sablierV2.getWithdrawableAmount(defaultStreamId); | ||
|
||
// Expect the withdrawal to be made to the recipient. | ||
vm.expectCall(address(dai), abi.encodeCall(IERC20.transfer, (users.recipient, withdrawAmount))); | ||
|
||
// Expect an event to be emitted. | ||
vm.expectEmit({ checkTopic1: true, checkTopic2: true, checkTopic3: false, checkData: true }); | ||
emit Events.Withdraw({ streamId: defaultStreamId, to: users.recipient, amount: withdrawAmount }); | ||
|
||
// Make the withdrawal. | ||
sablierV2.withdrawMax(defaultStreamId, users.recipient); | ||
|
||
// Assert that the withdrawn amount was updated. | ||
uint128 actualWithdrawnAmount = sablierV2.getWithdrawnAmount(defaultStreamId); | ||
uint128 expectedWithdrawnAmount = withdrawAmount; | ||
assertEq(actualWithdrawnAmount, expectedWithdrawnAmount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
withdrawMax.t.sol | ||
├── when the current time is greater than or equal to the stop time | ||
│ └── it should make the max withdrawal and delete the stream | ||
└── when the current time is less than the stop time | ||
└── it should make the max withdrawal, emit a Withdraw event, and update the withdrawn amount |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters