Skip to content

Commit

Permalink
chore: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Aug 11, 2022
1 parent 8fdf71d commit d131c0a
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 77 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
20 changes: 10 additions & 10 deletions src/SablierV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract contract SablierV2 is ISablierV2 {
revert SablierV2__StreamNonCancelable(streamId);
}

cancelInternal(streamId);
_cancel(streamId);
}

/// @inheritdoc ISablierV2
Expand All @@ -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.
Expand All @@ -106,7 +106,7 @@ abstract contract SablierV2 is ISablierV2 {
revert SablierV2__RenounceNonCancelableStream(streamId);
}

renounceInternal(streamId);
_renounce(streamId);
}

/// @inheritdoc ISablierV2
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand All @@ -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);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand Down
52 changes: 26 additions & 26 deletions src/SablierV2Linear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ contract SablierV2Linear is
//////////////////////////////////////////////////////////////////////////*/

/// @dev Sablier V2 linear streams mapped by unsigned integers.
mapping(uint256 => Stream) internal streams;
mapping(uint256 => Stream) internal _streams;

/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/

/// @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
Expand All @@ -48,72 +48,72 @@ 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;
}

// If the cliff time is greater than the block timestamp, return zero. Because the cliff time 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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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.
Expand Down
Loading

0 comments on commit d131c0a

Please sign in to comment.