Skip to content

Commit

Permalink
Merge pull request #5 from simplemachine92/rev
Browse files Browse the repository at this point in the history
tests: correctly assert if stream has been cancelled
  • Loading branch information
simplemachine92 authored Aug 24, 2023
2 parents e1cd68b + 1fd4c26 commit 76723c9
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
29 changes: 24 additions & 5 deletions src/JBSips.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {IERC20} from 'lib/v2-periphery/lib/v2-core/src/types/Tokens.sol';

import {IPRBProxy} from '@sablier/v2-periphery/src/types/Proxy.sol';

import {Batch} from '@sablier/v2-periphery/src/types/DataTypes.sol';

/**
* @custom:benediction DEVS BENEDICAT ET PROTEGAT CONTRACTVS MEAM
*
Expand All @@ -45,10 +47,6 @@ contract JBSips is JBSablier, JBOperatable, IJBSplitAllocator {
error JuiceSips_Unauthorized();
error JuiceSips_MaximumSlippage();

//*********************************************************************//
// ----------------------------- events ----------------------------- //
//*********************************************************************//

//*********************************************************************//
// --------------------- public stored properties -------------------- //
//*********************************************************************//
Expand Down Expand Up @@ -128,7 +126,7 @@ contract JBSips is JBSablier, JBOperatable, IJBSplitAllocator {
}

//*********************************************************************//
// ----------------------- admin functions --------------------------- //
// ---------------------- stream management -------------------------- //
//*********************************************************************//

/// @notice Deploys PRBProxy and plugin via JBSablier
Expand Down Expand Up @@ -163,6 +161,27 @@ contract JBSips is JBSablier, JBOperatable, IJBSplitAllocator {
super._deployStreams(_streams, _cycle.number);
}

function batchCancelStreams(
Batch.CancelMultiple[] calldata _batch,
IERC20[] calldata _assets
)
external
requirePermission(controller.projects().ownerOf(projectId), projectId, JBOperations.SET_SPLITS)
{
bytes memory data = abi.encodeCall(
proxyTarget.batchCancelMultiple,
(_batch, _assets)
);

proxy.execute(address(proxyTarget), data);
}

//*********************************************************************//
// ----------------------- admin functions --------------------------- //
//*********************************************************************//



/// @notice Withdraws ETH..
function withdrawETH()
external
Expand Down
6 changes: 6 additions & 0 deletions src/abstract/JBSablier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ abstract contract JBSablier is ERC165, ERC1271, IUniswapV3SwapCallback {
mapping(uint256 cycleNumber => mapping(address user => uint256[] streamIds))
public streamsByCycleAndAddress;

mapping(uint256 streamId => bool isLinear) public isStreamLinear;

uint256 public immutable projectId;
IJBDirectory public directory;
IJBController3_1 public controller;
Expand Down Expand Up @@ -233,6 +235,7 @@ abstract contract JBSablier is ERC165, ERC1271, IUniswapV3SwapCallback {
address user = _data.linWithDur[i].recipient;
uint256 id = streamIds[i];
streamsByCycleAndAddress[_cycleNumber][user].push(id);
isStreamLinear[id] = true;
emit StreamForUser(user, id);
}
}
Expand All @@ -250,6 +253,7 @@ abstract contract JBSablier is ERC165, ERC1271, IUniswapV3SwapCallback {
address user = _data.linWithRange[i].recipient;
uint256 id = streamIds[i];
streamsByCycleAndAddress[_cycleNumber][user].push(id);
isStreamLinear[id] = true;
emit StreamForUser(user, id);
}
}
Expand All @@ -267,6 +271,7 @@ abstract contract JBSablier is ERC165, ERC1271, IUniswapV3SwapCallback {
address user = _data.dynWithDelta[i].recipient;
uint256 id = streamIds[i];
streamsByCycleAndAddress[_cycleNumber][user].push(id);
isStreamLinear[id] = false;
emit StreamForUser(user, id);
}
}
Expand All @@ -284,6 +289,7 @@ abstract contract JBSablier is ERC165, ERC1271, IUniswapV3SwapCallback {
address user = _data.dynWithMiles[i].recipient;
uint256 id = streamIds[i];
streamsByCycleAndAddress[_cycleNumber][user].push(id);
isStreamLinear[id] = false;
emit StreamForUser(user, id);
}
}
Expand Down
45 changes: 40 additions & 5 deletions test/Sips_Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {ISablierV2ProxyPlugin} from '@sablier/v2-periphery/src/interfaces/ISabli
import {ISablierV2ProxyTarget} from '@sablier/v2-periphery/src/interfaces/ISablierV2ProxyTarget.sol';
import {LockupLinear, LockupDynamic} from '@sablier/v2-periphery/src/types/DataTypes.sol';
import {Batch, Broker} from '@sablier/v2-periphery/src/types/DataTypes.sol';
import { ISablierV2Lockup } from "@sablier/v2-core/src/interfaces/ISablierV2Lockup.sol";
import {ud2x18, ud60x18} from '@sablier/v2-core/src/types/Math.sol';

import {IJBDelegatesRegistry} from '@jbx-protocol/juice-delegates-registry/src/interfaces/IJBDelegatesRegistry.sol';
Expand All @@ -32,12 +33,12 @@ import {TickMath} from '@uniswap/v3-core/contracts/libraries/TickMath.sol';

import {AddStreamsData} from '../src/structs/Streams.sol';
import {IPRBProxy, IPRBProxyRegistry} from '@sablier/v2-periphery/src/types/Proxy.sol';
import { Lockup } from 'lib/v2-periphery/lib/v2-core/src/types/DataTypes.sol';

import {Test, console2} from 'forge-std/Test.sol';

contract SipsTest is TestBaseWorkflowV3 {
contract SipsTest_Int is TestBaseWorkflowV3 {
using JBFundingCycleMetadataResolver for JBFundingCycle;
using stdStorage for StdStorage;

// Assigned when project is launched
uint256 _projectId;
Expand Down Expand Up @@ -313,12 +314,46 @@ contract SipsTest is TestBaseWorkflowV3 {
_sips.swapAndDeployStreams(3 ether, _sData);
}

function testWithdrawAllDust() public {
function test_WithdrawAllDust() public {
vm.prank(address(123));
_sips.withdrawAllTokenDust(USDC);
}

function testStreamWithdraw() public {
function test_BatchCancelStreams() public {
// Arrange our data for proxy call of batchCancelMultiple
uint256[] memory _ids = new uint256[](1);
uint256[] memory ids = _sips.getStreamsByCycleAndAddress(
1,
0x000000000000000000000000000000000000cafE
);
_ids[0] = ids[0];

Batch.CancelMultiple memory stream1;
Batch.CancelMultiple[] memory batch = new Batch.CancelMultiple[](1);

IERC20[] memory tokens = new IERC20[](1);

tokens[0] = USDC;

stream1.streamIds = _ids;
_sips.isStreamLinear(ids[0]) ? stream1.lockup = lockupLinear : stream1.lockup = lockupDynamic;

batch[0] = stream1;

vm.warp(block.timestamp + 1 weeks);

// Cancel the stream
vm.startPrank(address(123));
_sips.batchCancelStreams(batch, tokens);

Lockup.Status expectedStatus = Lockup.Status.CANCELED;
Lockup.Status actualLinearStatus = lockupLinear.statusOf(stream1.streamIds[0]);
if (expectedStatus != actualLinearStatus){
revert();
}
}

function test_StreamWithdraw() public {
// Since we've forked mainnet, we can't really expect specific values, but there should be 2 stream ids
uint256[] memory ids = _sips.getStreamsByCycleAndAddress(
1,
Expand Down Expand Up @@ -364,7 +399,7 @@ contract SipsTest is TestBaseWorkflowV3 {
_sips.deployProxy();
}

function testPoolValidity() public {
function test_PoolValidity() public {
emit log_address(address(_sips.POOL()));
}
}

0 comments on commit 76723c9

Please sign in to comment.