Skip to content

Commit

Permalink
test: create test
Browse files Browse the repository at this point in the history
  • Loading branch information
dristpunk committed Dec 19, 2023
1 parent 1db3386 commit 0777562
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 309 deletions.
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ src = 'solidity/interfaces/'
runs = 1000

[rpc_endpoints]
mainnet = "${MAINNET_RPC}"
mainnet = "${MAINNET_RPC}"
goerli = "${GOERLI_RPC}"
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"package.json": "sort-package-json"
},
"dependencies": {
"@sablier/v2-core": "^1.1.1",
"isolmate": "github:defi-wonderland/isolmate#59e1804"
},
"devDependencies": {
Expand Down
3 changes: 3 additions & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ds-test/=node_modules/ds-test/src
forge-std/=node_modules/forge-std/src
isolmate/=node_modules/isolmate/src
@sablier/v2-core/=node_modules/@sablier/v2-core
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts
@prb/math/=node_modules/@prb/math

contracts/=solidity/contracts
interfaces/=solidity/interfaces
Expand Down
59 changes: 0 additions & 59 deletions solidity/contracts/Greeter.sol

This file was deleted.

75 changes: 0 additions & 75 deletions solidity/interfaces/IGreeter.sol

This file was deleted.

30 changes: 0 additions & 30 deletions solidity/scripts/Deploy.sol

This file was deleted.

16 changes: 0 additions & 16 deletions solidity/test/integration/Greeter.t.sol

This file was deleted.

24 changes: 0 additions & 24 deletions solidity/test/integration/IntegrationBase.sol

This file was deleted.

99 changes: 99 additions & 0 deletions solidity/test/integration/LockupDynamicStreamCreator.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.19;

import {ISablierV2LockupDynamic} from '@sablier/v2-core/src/interfaces/ISablierV2LockupDynamic.sol';
import {Broker, LockupDynamic} from '@sablier/v2-core/src/types/DataTypes.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {ud2x18} from '@prb/math/src/UD2x18.sol';
import {ud60x18} from '@prb/math/src/UD60x18.sol';
import {Test} from 'forge-std/Test.sol';
import {console} from 'forge-std/Console.sol';

/// @notice Example of how to create a Lockup Dynamic stream.
/// @dev This code is referenced in the docs: https://docs.sablier.com/contracts/v2/guides/create-stream/lockup-dynamic
contract LockupDynamicStreamCreatorTest is Test {

Check warning on line 14 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

The order of data in contract LockupDynamicStreamCreatorTest should be: Constants, Immutable variables, State Variables
address internal _owner = makeAddr('owner');

address constant SABLIER_DYNAMIC_MAINNET = 0x39EFdC3dbB57B2388CcC4bb40aC4CB1226Bc9E44;

Check warning on line 17 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

Check warning on line 17 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

'SABLIER_DYNAMIC_MAINNET' should start with _
address constant NEXT_MAINNET = 0xFE67A4450907459c3e1FFf623aA927dD4e28c67a;

Check warning on line 18 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

Check warning on line 18 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

'NEXT_MAINNET' should start with _

address constant SABLIER_DYNAMIC_GOERLI = 0x4BE70EDe968e9dBA12DB42b9869Bec66bEDC17d7;

Check warning on line 20 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

Check warning on line 20 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

'SABLIER_DYNAMIC_GOERLI' should start with _
address constant NEXT_GOERLI = 0x7ea6eA49B0b0Ae9c5db7907d139D9Cd3439862a1;

Check warning on line 21 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

Check warning on line 21 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

'NEXT_GOERLI' should start with _

uint256 constant TOTAL_AMOUNT = 24_960_000 ether;

Check warning on line 23 in solidity/test/integration/LockupDynamicStreamCreator.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Explicitly mark visibility of state

ISablierV2LockupDynamic internal lockupDynamic;

function setUp() public {
// mint some NEXT tokens
vm.createSelectFork(vm.rpcUrl('mainnet'), 18_820_753);
deal(NEXT_MAINNET, _owner, TOTAL_AMOUNT);
vm.prank(_owner);
IERC20(NEXT_MAINNET).approve(address(this), TOTAL_AMOUNT);

lockupDynamic = ISablierV2LockupDynamic(SABLIER_DYNAMIC_MAINNET);
}

function test_Creation() external {
uint256 streamId = createLockupDynamicStream(1_920_000, 5_917_440, 17_122_560);
console.log('streamId: %s', streamId);
}

function createLockupDynamicStream(
uint256 amount0,
uint256 amount1,
uint256 amount2
) public returns (uint256 streamId) {
// Sum the segment amounts
uint256 totalAmount = amount0 + amount1 + amount2;

// Transfer the provided amount of DAI tokens to this contract
IERC20(NEXT_MAINNET).transferFrom(_owner, address(this), totalAmount);

// Approve the Sablier contract to spend DAI
IERC20(NEXT_MAINNET).approve(address(lockupDynamic), totalAmount);

console.log('HERE');

// Declare the params struct
LockupDynamic.CreateWithMilestones memory params;

// Declare the function parameters
params.sender = _owner; // The sender will be able to cancel the stream
params.recipient = address(0xcafe); // The recipient of the streamed assets
params.totalAmount = uint128(totalAmount); // Total amount is the amount inclusive of all fees
params.asset = IERC20(NEXT_MAINNET); // The streaming asset
params.cancelable = true; // Whether the stream will be cancelable or not
params.startTime = uint40(block.timestamp);
params.broker = Broker(address(0), ud60x18(0)); // Optional parameter left undefined

// Declare some dummy segments
params.segments = new LockupDynamic.Segment[](3);
params.segments[0] = LockupDynamic.Segment({
amount: uint128(amount0),
exponent: ud2x18(0), // unlock at milestone
milestone: uint40(block.timestamp + 365 days) // 12 months
});
params.segments[1] = (
LockupDynamic.Segment({
amount: uint128(amount1),
exponent: ud2x18(1e18), // linear unlock
milestone: uint40(block.timestamp + 365 days + 90 days) // ~15 months
})
);
params.segments[2] = (
LockupDynamic.Segment({
amount: uint128(amount2),
exponent: ud2x18(1e18), // linear unlock
milestone: uint40(block.timestamp + (365 days * 4)) // 48 months
})
);

console.log('HERE');

// Create the LockupDynamic stream
streamId = lockupDynamic.createWithMilestones(params);

console.log('HERE');
}
}
Loading

0 comments on commit 0777562

Please sign in to comment.