-
Notifications
You must be signed in to change notification settings - Fork 7
/
SablierV2MerkleStreamerLL.sol
100 lines (84 loc) · 3.99 KB
/
SablierV2MerkleStreamerLL.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;
import { BitMaps } from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
import { Broker, LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
import { ud } from "@prb/math/src/UD60x18.sol";
import { SablierV2MerkleStreamer } from "./abstracts/SablierV2MerkleStreamer.sol";
import { ISablierV2MerkleStreamerLL } from "./interfaces/ISablierV2MerkleStreamerLL.sol";
import { MerkleStreamer } from "./types/DataTypes.sol";
/// @title SablierV2MerkleStreamerLL
/// @notice See the documentation in {ISablierV2MerkleStreamerLL}.
contract SablierV2MerkleStreamerLL is
ISablierV2MerkleStreamerLL, // 2 inherited components
SablierV2MerkleStreamer // 4 inherited components
{
using BitMaps for BitMaps.BitMap;
using SafeERC20 for IERC20;
/*//////////////////////////////////////////////////////////////////////////
USER-FACING CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc ISablierV2MerkleStreamerLL
ISablierV2LockupLinear public immutable override LOCKUP_LINEAR;
/*//////////////////////////////////////////////////////////////////////////
USER-FACING STORAGE
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc ISablierV2MerkleStreamerLL
LockupLinear.Durations public override streamDurations;
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
/// @dev Constructs the contract by initializing the immutable state variables, and max approving the Sablier
/// contract.
constructor(
MerkleStreamer.ConstructorParams memory params,
ISablierV2LockupLinear lockupLinear,
LockupLinear.Durations memory streamDurations_
)
SablierV2MerkleStreamer(params)
{
LOCKUP_LINEAR = lockupLinear;
streamDurations = streamDurations_;
// Max approve the Sablier contract to spend funds from the Merkle streamer.
ASSET.forceApprove(address(LOCKUP_LINEAR), type(uint256).max);
}
/*//////////////////////////////////////////////////////////////////////////
USER-FACING NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc ISablierV2MerkleStreamerLL
function claim(
uint256 index,
address recipient,
uint128 amount,
bytes32[] calldata merkleProof
)
external
override
returns (uint256 streamId)
{
// Generate the Merkle tree leaf by hashing the corresponding parameters. Hashing twice prevents second
// preimage attacks.
bytes32 leaf = keccak256(bytes.concat(keccak256(abi.encode(index, recipient, amount))));
// Checks: validate the function.
_checkClaim(index, leaf, merkleProof);
// Effects: mark the index as claimed.
_claimedBitMap.set(index);
// Interactions: create the stream via {SablierV2LockupLinear}.
streamId = LOCKUP_LINEAR.createWithDurations(
LockupLinear.CreateWithDurations({
sender: admin,
recipient: recipient,
totalAmount: amount,
asset: ASSET,
cancelable: CANCELABLE,
transferable: TRANSFERABLE,
durations: streamDurations,
broker: Broker({ account: address(0), fee: ud(0) })
})
);
// Log the claim.
emit Claim(index, recipient, amount, streamId);
}
}