-
Notifications
You must be signed in to change notification settings - Fork 11
/
RwaInputConduit2.sol
138 lines (123 loc) · 4.36 KB
/
RwaInputConduit2.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright (C) 2020, 2021 Lev Livnev <lev@liv.nev.org.uk>
// Copyright (C) 2022 Dai Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.6.12;
import {DSTokenAbstract} from "dss-interfaces/dapp/DSTokenAbstract.sol";
/**
* @author Lev Livnev <lev@liv.nev.org.uk>
* @author Kaue Cano <kaue@clio.finance>
* @author Henrique Barcelos <henrique@clio.finance>
* @title An Input Conduit for real-world assets (RWA).
* @dev This contract differs from the original [RwaInputConduit](https://github.com/makerdao/MIP21-RWA-Example/blob/fce06885ff89d10bf630710d4f6089c5bba94b4d/src/RwaConduit.sol#L20-L39):
* - The caller of `push()` is not required to hold MakerDAO governance tokens.
* - The `push()` method is permissioned.
* - `push()` permissions are managed by `mate()`/`hate()` methods.
*/
contract RwaInputConduit2 {
/// @dev This is declared here so the storage layout lines up with RwaInputConduit.
DSTokenAbstract private __unused_gov;
/// @notice Dai token contract address
DSTokenAbstract public dai;
/// @notice RWA urn contract address
address public to;
/// @notice Addresses with admin access on this contract. `wards[usr]`
mapping(address => uint256) public wards;
/// @notice Addresses with push access on this contract. `may[usr]`
mapping(address => uint256) public may;
/**
* @notice `usr` was granted admin access.
* @param usr The user address.
*/
event Rely(address indexed usr);
/**
* @notice `usr` admin access was revoked.
* @param usr The user address.
*/
event Deny(address indexed usr);
/**
* @notice `usr` was granted push access.
* @param usr The user address.
*/
event Mate(address indexed usr);
/**
* @notice `usr` push access was revoked.
* @param usr The user address.
*/
event Hate(address indexed usr);
/**
* @notice `wad` amount of Dai was pushed to `to`
* @param to The RwaUrn address
* @param wad The amount of Dai
*/
event Push(address indexed to, uint256 wad);
/**
* @notice Define addresses and gives `msg.sender` admin access.
* @param _dai Dai token contract address.
* @param _to RwaUrn contract address.
*/
constructor(address _dai, address _to) public {
dai = DSTokenAbstract(_dai);
to = _to;
wards[msg.sender] = 1;
emit Rely(msg.sender);
}
modifier auth() {
require(wards[msg.sender] == 1, "RwaInputConduit2/not-authorized");
_;
}
/**
* @notice Grants `usr` admin access to this contract.
* @param usr The user address.
*/
function rely(address usr) external auth {
wards[usr] = 1;
emit Rely(usr);
}
/**
* @notice Revokes `usr` admin access from this contract.
* @param usr The user address.
*/
function deny(address usr) external auth {
wards[usr] = 0;
emit Deny(usr);
}
/**
* @notice Grants `usr` push access to this contract.
* @param usr The user address.
*/
function mate(address usr) external auth {
may[usr] = 1;
emit Mate(usr);
}
/**
* @notice Revokes `usr` push access from this contract.
* @param usr The user address.
*/
function hate(address usr) external auth {
may[usr] = 0;
emit Hate(usr);
}
/**
* @notice Pushes contract Dai balance into RwaUrn address.
* @dev `msg.sender` must first receive push acess through mate().
*/
function push() external {
require(may[msg.sender] == 1, "RwaInputConduit2/not-mate");
uint256 balance = dai.balanceOf(address(this));
dai.transfer(to, balance);
emit Push(to, balance);
}
}