This repository has been archived by the owner on Jan 31, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSablierV2ProxyPlugin.sol
101 lines (84 loc) · 5.95 KB
/
SablierV2ProxyPlugin.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
101
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.19;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IPRBProxy } from "@prb/proxy/interfaces/IPRBProxy.sol";
import { IPRBProxyPlugin } from "@prb/proxy/interfaces/IPRBProxyPlugin.sol";
import { ISablierV2Lockup } from "@sablier/v2-core/interfaces/ISablierV2Lockup.sol";
import { ISablierV2LockupSender } from "@sablier/v2-core/interfaces/hooks/ISablierV2LockupSender.sol";
import { OnlyDelegateCall } from "./abstracts/OnlyDelegateCall.sol";
import { ISablierV2Archive } from "./interfaces/ISablierV2Archive.sol";
import { ISablierV2ProxyPlugin } from "./interfaces/ISablierV2ProxyPlugin.sol";
import { Errors } from "./libraries/Errors.sol";
/*
███████╗ █████╗ ██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗██████╗
██╔════╝██╔══██╗██╔══██╗██║ ██║██╔════╝██╔══██╗ ██║ ██║╚════██╗
███████╗███████║██████╔╝██║ ██║█████╗ ██████╔╝ ██║ ██║ █████╔╝
╚════██║██╔══██║██╔══██╗██║ ██║██╔══╝ ██╔══██╗ ╚██╗ ██╔╝██╔═══╝
███████║██║ ██║██████╔╝███████╗██║███████╗██║ ██║ ╚████╔╝ ███████╗
╚══════╝╚═╝ ╚═╝╚═════╝ ╚══════╝╚═╝╚══════╝╚═╝ ╚═╝ ╚═══╝ ╚══════╝
██████╗ ██████╗ ██████╗ ██╗ ██╗██╗ ██╗ ██████╗ ██╗ ██╗ ██╗ ██████╗ ██╗███╗ ██╗
██╔══██╗██╔══██╗██╔═══██╗╚██╗██╔╝╚██╗ ██╔╝ ██╔══██╗██║ ██║ ██║██╔════╝ ██║████╗ ██║
██████╔╝██████╔╝██║ ██║ ╚███╔╝ ╚████╔╝ ██████╔╝██║ ██║ ██║██║ ███╗██║██╔██╗ ██║
██╔═══╝ ██╔══██╗██║ ██║ ██╔██╗ ╚██╔╝ ██╔═══╝ ██║ ██║ ██║██║ ██║██║██║╚██╗██║
██║ ██║ ██║╚██████╔╝██╔╝ ██╗ ██║ ██║ ███████╗╚██████╔╝╚██████╔╝██║██║ ╚████║
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═════╝ ╚═╝╚═╝ ╚═══╝
*/
/// @title SablierV2ProxyPlugin
/// @notice See the documentation in {ISablierV2ProxyPlugin}.
contract SablierV2ProxyPlugin is
OnlyDelegateCall, // 0 inherited components
ISablierV2ProxyPlugin // 2 inherited components
{
using SafeERC20 for IERC20;
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc ISablierV2ProxyPlugin
ISablierV2Archive public immutable override archive;
/*//////////////////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////////////////*/
constructor(ISablierV2Archive archive_) {
archive = archive_;
}
/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc IPRBProxyPlugin
function getMethods() external pure returns (bytes4[] memory methods) {
methods = new bytes4[](1);
methods[0] = this.onStreamCanceled.selector;
}
/*//////////////////////////////////////////////////////////////////////////
NON-CONSTANT FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/// @inheritdoc ISablierV2LockupSender
/// @notice Forwards the refunded assets to the proxy owner when the recipient cancel a stream whose sender is the
/// proxy contract.
/// @dev Requirements:
/// - Must be delegate called.
/// - The caller must be an address listed in the archive.
function onStreamCanceled(
uint256 streamId,
address, /* recipient */
uint128 senderAmount,
uint128 /* recipientAmount */
)
external
onlyDelegateCall
{
// Checks: the caller is an address listed in the archive.
if (!archive.isListed(msg.sender)) {
revert Errors.SablierV2ProxyPlugin_UnknownCaller(msg.sender);
}
// This invariant should always hold but it's better to be safe than sorry.
ISablierV2Lockup lockup = ISablierV2Lockup(msg.sender);
address streamSender = lockup.getSender(streamId);
assert(streamSender == address(this));
// Effects: forward the refunded assets to the proxy owner.
IERC20 asset = lockup.getAsset(streamId);
address owner = IPRBProxy(address(this)).owner();
asset.safeTransfer({ to: owner, value: senderAmount });
}
}