|
13 | 13 | //
|
14 | 14 | // You should have received a copy of the GNU Affero General Public License
|
15 | 15 | // along with this program. If not, see <https://www.gnu.org/licenses/>.
|
| 16 | + |
16 | 17 | pragma solidity ^0.8.24;
|
17 | 18 |
|
18 | 19 | interface ERC20Like {
|
19 |
| - function balanceOf(address) external view returns (uint256); |
| 20 | + function balanceOf(address account) external view returns (uint256); |
20 | 21 | function approve(address usr, uint256 wad) external returns (bool);
|
21 | 22 | }
|
22 | 23 |
|
23 | 24 | interface DaiJoinLike {
|
24 | 25 | function dai() external view returns (address);
|
25 |
| - function join(address, uint256) external; |
| 26 | + function join(address usr, uint256 wad) external; |
26 | 27 | }
|
27 | 28 |
|
28 | 29 | interface UsdsJoinLike is DaiJoinLike {
|
29 | 30 | function usds() external view returns (address);
|
30 | 31 | }
|
31 | 32 |
|
| 33 | +/// @title DssBlow2 |
| 34 | +/// @notice This contract acts as a bridge to incorporate any available Dai or USDS |
| 35 | +/// balances into the protocol's Surplus Buffer by invoking the appropriate join adapters. |
| 36 | +/// @dev The contract automatically approves the maximum token amount for both join adapters during construction. |
32 | 37 | contract DssBlow2 {
|
| 38 | + /// @notice The address of the Vow contract that receives tokens. |
33 | 39 | address public immutable vow;
|
| 40 | + |
| 41 | + /// @notice The ERC20 token representing Dai. |
34 | 42 | ERC20Like public immutable dai;
|
| 43 | + |
| 44 | + /// @notice The ERC20 token representing USDS. |
35 | 45 | ERC20Like public immutable usds;
|
| 46 | + |
| 47 | + /// @notice The adapter for joining Dai into the protocol. |
36 | 48 | DaiJoinLike public immutable daiJoin;
|
| 49 | + |
| 50 | + /// @notice The adapter for joining USDS into the protocol. |
37 | 51 | UsdsJoinLike public immutable usdsJoin;
|
38 | 52 |
|
| 53 | + /// @notice Emitted when tokens are transferred into the protocol. |
| 54 | + /// @param token The address of the token (Dai or USDS) that was transferred. |
| 55 | + /// @param amount The amount of tokens that was transferred. |
39 | 56 | event Blow(address indexed token, uint256 amount);
|
40 | 57 |
|
| 58 | + /// @notice Initializes the DssBlow2 contract. |
| 59 | + /// @param daiJoin_ The address of the DaiJoin contract. |
| 60 | + /// @param usdsJoin_ The address of the UsdsJoin contract. |
| 61 | + /// @param vow_ The address of the Vow contract. |
41 | 62 | constructor(address daiJoin_, address usdsJoin_, address vow_) {
|
42 | 63 | daiJoin = DaiJoinLike(daiJoin_);
|
43 | 64 | dai = ERC20Like(daiJoin.dai());
|
44 | 65 | usdsJoin = UsdsJoinLike(usdsJoin_);
|
45 | 66 | usds = ERC20Like(usdsJoin.usds());
|
46 | 67 | vow = vow_;
|
| 68 | + |
| 69 | + // Approve the maximum uint256 amount for both join adapters. |
47 | 70 | dai.approve(daiJoin_, type(uint256).max);
|
48 | 71 | usds.approve(usdsJoin_, type(uint256).max);
|
49 | 72 | }
|
50 | 73 |
|
| 74 | + /// @notice Transfers any available Dai and USDS balances from this contract to the protocol's Surplus Buffer. |
| 75 | + /// @dev For each token, if the balance is greater than zero, the respective join adapter's join function is called. |
51 | 76 | function blow() public {
|
52 | 77 | uint256 daiBalance = dai.balanceOf(address(this));
|
53 | 78 | if (daiBalance > 0) {
|
54 | 79 | daiJoin.join(vow, daiBalance);
|
55 | 80 | emit Blow(address(dai), daiBalance);
|
56 | 81 | }
|
| 82 | + |
57 | 83 | uint256 usdsBalance = usds.balanceOf(address(this));
|
58 | 84 | if (usdsBalance > 0) {
|
59 | 85 | usdsJoin.join(vow, usdsBalance);
|
|
0 commit comments