From d131c0a30c0785c0260b5cc2621b6e98efdd89c9 Mon Sep 17 00:00:00 2001 From: andreivladbrg Date: Thu, 11 Aug 2022 15:01:05 +0300 Subject: [PATCH] chore: resolve conflicts --- README.md | 2 +- package.json | 2 +- src/SablierV2.sol | 20 +++++------ src/SablierV2Linear.sol | 52 +++++++++++++-------------- src/SablierV2Pro.sol | 78 ++++++++++++++++++++--------------------- 5 files changed, 77 insertions(+), 77 deletions(-) diff --git a/README.md b/README.md index cc7f5a7a9..86f26d610 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ [license]: https://www.gnu.org/licenses/lgpl-3.0 [license-badge]: https://img.shields.io/badge/License-LGPL_v3-blue.svg -Core smart contracts of the Sablier V2 money streaming protocol. In-depth documentation is available at [docs.sablier.finance](https://docs.sablier.finance). +Core smart contracts of the Sablier V2 token streaming protocol. In-depth documentation is available at [docs.sablier.finance](https://docs.sablier.finance). ## Install diff --git a/package.json b/package.json index fe4b7347a..c2781ddf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sablier/v2-core", - "description": "Core smart contracts for the Sablier V2 money streaming protocol", + "description": "Core smart contracts for the Sablier V2 token streaming protocol", "version": "1.0.0", "author": { "name": "Sablier Labs Ltd.", diff --git a/src/SablierV2.sol b/src/SablierV2.sol index 2cb52d42b..1c15dabd9 100644 --- a/src/SablierV2.sol +++ b/src/SablierV2.sol @@ -71,7 +71,7 @@ abstract contract SablierV2 is ISablierV2 { revert SablierV2__StreamNonCancelable(streamId); } - cancelInternal(streamId); + _cancel(streamId); } /// @inheritdoc ISablierV2 @@ -84,7 +84,7 @@ abstract contract SablierV2 is ISablierV2 { // Cancel the stream only if the `streamId` points to a stream that exists and is cancelable. if (getSender(streamId) != address(0) && isCancelable(streamId)) { - cancelInternal(streamId); + _cancel(streamId); } // Increment the for loop iterator. @@ -106,7 +106,7 @@ abstract contract SablierV2 is ISablierV2 { revert SablierV2__RenounceNonCancelableStream(streamId); } - renounceInternal(streamId); + _renounce(streamId); } /// @inheritdoc ISablierV2 @@ -116,7 +116,7 @@ abstract contract SablierV2 is ISablierV2 { onlySenderOrAuthorized(streamId) { address to = getRecipient(streamId); - withdrawInternal(streamId, to, amount); + _withdraw(streamId, to, amount); } /// @inheritdoc ISablierV2 @@ -147,7 +147,7 @@ abstract contract SablierV2 is ISablierV2 { } // Effects and Interactions: withdraw from the stream. - withdrawInternal(streamId, recipient, amounts[i]); + _withdraw(streamId, recipient, amounts[i]); } // Increment the for loop iterator. @@ -188,7 +188,7 @@ abstract contract SablierV2 is ISablierV2 { } // Effects and Interactions: withdraw from the stream. - withdrawInternal(streamId, to, amounts[i]); + _withdraw(streamId, to, amounts[i]); } // Increment the for loop iterator. @@ -213,7 +213,7 @@ abstract contract SablierV2 is ISablierV2 { if (!isApprovedOrOwner(streamId)) { revert SablierV2__Unauthorized(streamId, msg.sender); } - withdrawInternal(streamId, to, amount); + _withdraw(streamId, to, amount); } /*////////////////////////////////////////////////////////////////////////// @@ -254,13 +254,13 @@ abstract contract SablierV2 is ISablierV2 { //////////////////////////////////////////////////////////////////////////*/ /// @dev See the documentation for the public functions that call this internal function. - function cancelInternal(uint256 streamId) internal virtual; + function _cancel(uint256 streamId) internal virtual; /// @dev See the documentation for the public functions that call this internal function. - function renounceInternal(uint256 streamId) internal virtual; + function _renounce(uint256 streamId) internal virtual; /// @dev See the documentation for the public functions that call this internal function. - function withdrawInternal( + function _withdraw( uint256 streamId, address to, uint256 amount diff --git a/src/SablierV2Linear.sol b/src/SablierV2Linear.sol index a25582309..c546f69a1 100644 --- a/src/SablierV2Linear.sol +++ b/src/SablierV2Linear.sol @@ -24,7 +24,7 @@ contract SablierV2Linear is //////////////////////////////////////////////////////////////////////////*/ /// @dev Sablier V2 linear streams mapped by unsigned integers. - mapping(uint256 => Stream) internal streams; + mapping(uint256 => Stream) internal _streams; /*////////////////////////////////////////////////////////////////////////// CONSTANT FUNCTIONS @@ -32,12 +32,12 @@ contract SablierV2Linear is /// @inheritdoc ISablierV2Linear function getCliffTime(uint256 streamId) external view override returns (uint256 cliffTime) { - cliffTime = streams[streamId].cliffTime; + cliffTime = _streams[streamId].cliffTime; } /// @inheritdoc ISablierV2 function getDepositAmount(uint256 streamId) external view override returns (uint256 depositAmount) { - depositAmount = streams[streamId].depositAmount; + depositAmount = _streams[streamId].depositAmount; } /// @inheritdoc ISablierV2 @@ -48,40 +48,40 @@ contract SablierV2Linear is /// @inheritdoc ISablierV2 function getReturnableAmount(uint256 streamId) external view returns (uint256 returnableAmount) { // If the stream does not exist, return zero. - if (streams[streamId].sender == address(0)) { + if (_streams[streamId].sender == address(0)) { return 0; } unchecked { uint256 withdrawableAmount = getWithdrawableAmount(streamId); - returnableAmount = streams[streamId].depositAmount - streams[streamId].withdrawnAmount - withdrawableAmount; + returnableAmount = _streams[streamId].depositAmount - _streams[streamId].withdrawnAmount - withdrawableAmount; } } /// @inheritdoc ISablierV2 function getSender(uint256 streamId) public view override(ISablierV2, SablierV2) returns (address sender) { - sender = streams[streamId].sender; + sender = _streams[streamId].sender; } /// @inheritdoc ISablierV2 function getStartTime(uint256 streamId) external view override returns (uint256 startTime) { - startTime = streams[streamId].startTime; + startTime = _streams[streamId].startTime; } /// @inheritdoc ISablierV2 function getStopTime(uint256 streamId) external view override returns (uint256 stopTime) { - stopTime = streams[streamId].stopTime; + stopTime = _streams[streamId].stopTime; } /// @inheritdoc ISablierV2Linear function getStream(uint256 streamId) external view override returns (Stream memory stream) { - stream = streams[streamId]; + stream = _streams[streamId]; } /// @inheritdoc ISablierV2 function getWithdrawableAmount(uint256 streamId) public view returns (uint256 withdrawableAmount) { // If the stream does not exist, return zero. - if (streams[streamId].sender == address(0)) { + if (_streams[streamId].sender == address(0)) { return 0; } @@ -89,31 +89,31 @@ contract SablierV2Linear is // always greater than the start time, this also checks whether the start time is greater than // the block timestamp. uint256 currentTime = block.timestamp; - if (streams[streamId].cliffTime > currentTime) { + if (_streams[streamId].cliffTime > currentTime) { return 0; } unchecked { // If the current time is greater than or equal to the stop time, return the deposit minus // the withdrawn amount. - if (currentTime >= streams[streamId].stopTime) { - return streams[streamId].depositAmount - streams[streamId].withdrawnAmount; + if (currentTime >= _streams[streamId].stopTime) { + return _streams[streamId].depositAmount - _streams[streamId].withdrawnAmount; } // In all other cases, calculate how much the recipient can withdraw. - UD60x18 elapsedTime = toUD60x18(currentTime - streams[streamId].startTime); - UD60x18 totalTime = toUD60x18(streams[streamId].stopTime - streams[streamId].startTime); + UD60x18 elapsedTime = toUD60x18(currentTime - _streams[streamId].startTime); + UD60x18 totalTime = toUD60x18(_streams[streamId].stopTime - _streams[streamId].startTime); UD60x18 quotient = elapsedTime.div(totalTime); - UD60x18 depositAmount = UD60x18.wrap(streams[streamId].depositAmount); + UD60x18 depositAmount = UD60x18.wrap(_streams[streamId].depositAmount); UD60x18 streamedAmount = quotient.mul(depositAmount); - UD60x18 withdrawnAmount = UD60x18.wrap(streams[streamId].withdrawnAmount); + UD60x18 withdrawnAmount = UD60x18.wrap(_streams[streamId].withdrawnAmount); withdrawableAmount = UD60x18.unwrap(streamedAmount.uncheckedSub(withdrawnAmount)); } } /// @inheritdoc ISablierV2 function getWithdrawnAmount(uint256 streamId) external view override returns (uint256 withdrawnAmount) { - withdrawnAmount = streams[streamId].withdrawnAmount; + withdrawnAmount = _streams[streamId].withdrawnAmount; } /// @inheritdoc ISablierV2 @@ -124,7 +124,7 @@ contract SablierV2Linear is /// @inheritdoc ISablierV2 function isCancelable(uint256 streamId) public view override(ISablierV2, SablierV2) returns (bool cancelable) { - cancelable = streams[streamId].cancelable; + cancelable = _streams[streamId].cancelable; } /// @inheritdoc ERC721 @@ -182,7 +182,7 @@ contract SablierV2Linear is /// @dev See the documentation for the public functions that call this internal function. function cancelInternal(uint256 streamId) internal override onlySenderOrAuthorized(streamId) { - Stream memory stream = streams[streamId]; + Stream memory stream = _streams[streamId]; // Calculate the withdraw and the return amounts. uint256 withdrawAmount = getWithdrawableAmount(streamId); @@ -194,7 +194,7 @@ contract SablierV2Linear is address recipient = getRecipient(streamId); // Effects: delete the stream from storage. - delete streams[streamId]; + delete _streams[streamId]; // Interactions: withdraw the tokens to the recipient, if any. if (withdrawAmount > 0) { @@ -236,7 +236,7 @@ contract SablierV2Linear is // Effects: create and store the stream. streamId = nextStreamId; - streams[streamId] = Stream({ + _streams[streamId] = Stream({ cancelable: cancelable, cliffTime: cliffTime, depositAmount: depositAmount, @@ -277,7 +277,7 @@ contract SablierV2Linear is /// @dev See the documentation for the public functions that call this internal function. function renounceInternal(uint256 streamId) internal override { // Effects: make the stream non-cancelable. - streams[streamId].cancelable = false; + _streams[streamId].cancelable = false; // Emit an event. emit Renounce(streamId); @@ -302,15 +302,15 @@ contract SablierV2Linear is // Effects: update the withdrawn amount. unchecked { - streams[streamId].withdrawnAmount += amount; + _streams[streamId].withdrawnAmount += amount; } // Load the stream in memory, we will need it below. - Stream memory stream = streams[streamId]; + Stream memory stream = _streams[streamId]; // Effects: if this stream is done, save gas by deleting it from storage. if (stream.depositAmount == stream.withdrawnAmount) { - delete streams[streamId]; + delete _streams[streamId]; } // Interactions: perform the ERC-20 transfer. diff --git a/src/SablierV2Pro.sol b/src/SablierV2Pro.sol index 8820911d4..98d9cbea6 100644 --- a/src/SablierV2Pro.sol +++ b/src/SablierV2Pro.sol @@ -34,7 +34,7 @@ contract SablierV2Pro is //////////////////////////////////////////////////////////////////////////*/ /// @dev Sablier V2 pro streams mapped by unsigned integers. - mapping(uint256 => Stream) internal streams; + mapping(uint256 => Stream) internal _streams; /*////////////////////////////////////////////////////////////////////////// CONSTRUCTOR @@ -50,7 +50,7 @@ contract SablierV2Pro is /// @inheritdoc ISablierV2 function getDepositAmount(uint256 streamId) external view override returns (uint256 depositAmount) { - depositAmount = streams[streamId].depositAmount; + depositAmount = _streams[streamId].depositAmount; } /// @inheritdoc ISablierV2 @@ -61,29 +61,29 @@ contract SablierV2Pro is /// @inheritdoc ISablierV2 function getReturnableAmount(uint256 streamId) external view returns (uint256 returnableAmount) { // If the stream does not exist, return zero. - if (streams[streamId].sender == address(0)) { + if (_streams[streamId].sender == address(0)) { return 0; } unchecked { uint256 withdrawableAmount = getWithdrawableAmount(streamId); - returnableAmount = streams[streamId].depositAmount - streams[streamId].withdrawnAmount - withdrawableAmount; + returnableAmount = _streams[streamId].depositAmount - _streams[streamId].withdrawnAmount - withdrawableAmount; } } /// @inheritdoc ISablierV2 function getSender(uint256 streamId) public view override(ISablierV2, SablierV2) returns (address sender) { - sender = streams[streamId].sender; + sender = _streams[streamId].sender; } /// @inheritdoc ISablierV2Pro function getSegmentAmounts(uint256 streamId) external view override returns (uint256[] memory segmentAmounts) { - segmentAmounts = streams[streamId].segmentAmounts; + segmentAmounts = _streams[streamId].segmentAmounts; } /// @inheritdoc ISablierV2Pro function getSegmentExponents(uint256 streamId) external view override returns (SD59x18[] memory segmentExponents) { - segmentExponents = streams[streamId].segmentExponents; + segmentExponents = _streams[streamId].segmentExponents; } /// @inheritdoc ISablierV2Pro @@ -93,42 +93,42 @@ contract SablierV2Pro is override returns (uint256[] memory segmentMilestones) { - segmentMilestones = streams[streamId].segmentMilestones; + segmentMilestones = _streams[streamId].segmentMilestones; } /// @inheritdoc ISablierV2 function getStartTime(uint256 streamId) external view override returns (uint256 startTime) { - startTime = streams[streamId].startTime; + startTime = _streams[streamId].startTime; } /// @inheritdoc ISablierV2 function getStopTime(uint256 streamId) external view override returns (uint256 stopTime) { - stopTime = streams[streamId].stopTime; + stopTime = _streams[streamId].stopTime; } /// @inheritdoc ISablierV2Pro function getStream(uint256 streamId) external view returns (Stream memory stream) { - return streams[streamId]; + return _streams[streamId]; } /// @inheritdoc ISablierV2 function getWithdrawableAmount(uint256 streamId) public view returns (uint256 withdrawableAmount) { // If the stream does not exist, return zero. - if (streams[streamId].sender == address(0)) { + if (_streams[streamId].sender == address(0)) { return 0; } // If the start time is greater than or equal to the block timestamp, return zero. uint256 currentTime = block.timestamp; - if (streams[streamId].startTime >= currentTime) { + if (_streams[streamId].startTime >= currentTime) { return 0; } unchecked { // If the current time is greater than or equal to the stop time, return the deposit minus // the withdrawn amount. - if (currentTime >= streams[streamId].stopTime) { - return streams[streamId].depositAmount - streams[streamId].withdrawnAmount; + if (currentTime >= _streams[streamId].stopTime) { + return _streams[streamId].depositAmount - _streams[streamId].withdrawnAmount; } // Define the common variables used in the calculations below. @@ -139,28 +139,28 @@ contract SablierV2Pro is uint256 previousSegmentAmounts; // If there's more than one segment, we have to iterate over all of them. - uint256 segmentCount = streams[streamId].segmentAmounts.length; + uint256 segmentCount = _streams[streamId].segmentAmounts.length; if (segmentCount > 1) { // Sum up the amounts found in all preceding segments. Set the sum to the negation of the first segment // amount such that we avoid adding an if statement in the while loop. - uint256 currentSegmentMilestone = streams[streamId].segmentMilestones[0]; + uint256 currentSegmentMilestone = _streams[streamId].segmentMilestones[0]; uint256 index = 1; while (currentSegmentMilestone < currentTime) { - previousSegmentAmounts += streams[streamId].segmentAmounts[index - 1]; - currentSegmentMilestone = streams[streamId].segmentMilestones[index]; + previousSegmentAmounts += _streams[streamId].segmentAmounts[index - 1]; + currentSegmentMilestone = _streams[streamId].segmentMilestones[index]; index += 1; } // After the loop exits, the current segment is found at index `index - 1`, while the previous segment // is found at `index - 2`. - currentSegmentAmount = SD59x18.wrap(int256(streams[streamId].segmentAmounts[index - 1])); - currentSegmentExponent = streams[streamId].segmentExponents[index - 1]; - currentSegmentMilestone = streams[streamId].segmentMilestones[index - 1]; + currentSegmentAmount = SD59x18.wrap(int256(_streams[streamId].segmentAmounts[index - 1])); + currentSegmentExponent = _streams[streamId].segmentExponents[index - 1]; + currentSegmentMilestone = _streams[streamId].segmentMilestones[index - 1]; // If the current segment is at an index that is >= 2, take the difference between the current segment // milestone and the previous segment milestone. if (index > 1) { - uint256 previousSegmentMilestone = streams[streamId].segmentMilestones[index - 2]; + uint256 previousSegmentMilestone = _streams[streamId].segmentMilestones[index - 2]; elapsedSegmentTime = toSD59x18(int256(currentTime - previousSegmentMilestone)); // Calculate the time between the current segment milestone and the previous segment milestone. @@ -169,16 +169,16 @@ contract SablierV2Pro is // If the current segment is at index 1, take the difference between the current segment milestone and // the start time of the stream. else { - elapsedSegmentTime = toSD59x18(int256(currentTime - streams[streamId].startTime)); - totalSegmentTime = toSD59x18(int256(currentSegmentMilestone - streams[streamId].startTime)); + elapsedSegmentTime = toSD59x18(int256(currentTime - _streams[streamId].startTime)); + totalSegmentTime = toSD59x18(int256(currentSegmentMilestone - _streams[streamId].startTime)); } } // Otherwise, if there's only one segment, we use the start time of the stream in the calculations. else { - currentSegmentAmount = SD59x18.wrap(int256(streams[streamId].segmentAmounts[0])); - currentSegmentExponent = streams[streamId].segmentExponents[0]; - elapsedSegmentTime = toSD59x18(int256(currentTime - streams[streamId].startTime)); - totalSegmentTime = toSD59x18(int256(streams[streamId].stopTime - streams[streamId].startTime)); + currentSegmentAmount = SD59x18.wrap(int256(_streams[streamId].segmentAmounts[0])); + currentSegmentExponent = _streams[streamId].segmentExponents[0]; + elapsedSegmentTime = toSD59x18(int256(currentTime - _streams[streamId].startTime)); + totalSegmentTime = toSD59x18(int256(_streams[streamId].stopTime - _streams[streamId].startTime)); } // Calculate the streamed amount. @@ -186,14 +186,14 @@ contract SablierV2Pro is SD59x18 multiplier = quotient.pow(currentSegmentExponent); SD59x18 proRataAmount = multiplier.mul(currentSegmentAmount); SD59x18 streamedAmount = SD59x18.wrap(int256(previousSegmentAmounts)).add(proRataAmount); - SD59x18 withdrawnAmount = SD59x18.wrap(int256(streams[streamId].withdrawnAmount)); + SD59x18 withdrawnAmount = SD59x18.wrap(int256(_streams[streamId].withdrawnAmount)); withdrawableAmount = uint256(SD59x18.unwrap(streamedAmount.uncheckedSub(withdrawnAmount))); } } /// @inheritdoc ISablierV2 function getWithdrawnAmount(uint256 streamId) external view override returns (uint256 withdrawnAmount) { - withdrawnAmount = streams[streamId].withdrawnAmount; + withdrawnAmount = _streams[streamId].withdrawnAmount; } /// @inheritdoc ISablierV2 @@ -204,7 +204,7 @@ contract SablierV2Pro is /// @inheritdoc ISablierV2 function isCancelable(uint256 streamId) public view override(ISablierV2, SablierV2) returns (bool cancelable) { - cancelable = streams[streamId].cancelable; + cancelable = _streams[streamId].cancelable; } /// @inheritdoc ERC721 @@ -389,7 +389,7 @@ contract SablierV2Pro is /// @dev See the documentation for the public functions that call this internal function. function cancelInternal(uint256 streamId) internal override onlySenderOrAuthorized(streamId) { - Stream memory stream = streams[streamId]; + Stream memory stream = _streams[streamId]; // Calculate the withdraw and the return amounts. uint256 withdrawAmount = getWithdrawableAmount(streamId); @@ -401,7 +401,7 @@ contract SablierV2Pro is address recipient = getRecipient(streamId); // Effects: delete the stream from storage. - delete streams[streamId]; + delete _streams[streamId]; // Interactions: withdraw the tokens to the recipient, if any. if (withdrawAmount > 0) { @@ -443,7 +443,7 @@ contract SablierV2Pro is // Effects: create and store the stream. streamId = nextStreamId; - streams[streamId] = Stream({ + _streams[streamId] = Stream({ cancelable: cancelable, depositAmount: depositAmount, segmentAmounts: segmentAmounts, @@ -487,7 +487,7 @@ contract SablierV2Pro is /// @dev See the documentation for the public functions that call this internal function. function renounceInternal(uint256 streamId) internal override { // Effects: make the stream non-cancelable. - streams[streamId].cancelable = false; + _streams[streamId].cancelable = false; // Emit an event. emit Renounce(streamId); @@ -512,15 +512,15 @@ contract SablierV2Pro is // Effects: update the withdrawn amount. unchecked { - streams[streamId].withdrawnAmount += amount; + _streams[streamId].withdrawnAmount += amount; } // Load the stream in memory, we will need it below. - Stream memory stream = streams[streamId]; + Stream memory stream = _streams[streamId]; // Effects: if this stream is done, save gas by deleting it from storage. if (stream.depositAmount == stream.withdrawnAmount) { - delete streams[streamId]; + delete _streams[streamId]; } // Interactions: perform the ERC-20 transfer.