@@ -38,7 +38,7 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
38
38
* @dev The vesting locks, mapped by account addresses.
39
39
* There is no guarantee that the locks are ordered by release date time.
40
40
*/
41
- mapping (address => Lock[]) public locks ;
41
+ mapping (address => Lock[]) private _locks ;
42
42
43
43
constructor (IERC20 _token ) ISecurity () {
44
44
DPS = _token;
@@ -67,13 +67,47 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
67
67
require (amount < available (from, block .timestamp ), "LockingSecurity: transfer amount exceeds available tokens " );
68
68
}
69
69
70
+ /**
71
+ * @notice Allow the owner to upgrade the bridge.
72
+ * @param newBridge New address of the bridge.
73
+ */
74
+ function upgradeBridge (address newBridge ) external onlyRole (DEFAULT_ADMIN_ROLE) {
75
+ bridge = newBridge;
76
+ }
77
+
78
+ /**
79
+ * @notice Returns the list of an investors locked funds.
80
+ * @dev Works as a getter.
81
+ * @param investor Address of the investor.
82
+ */
83
+ function locks (address investor ) public view returns (Lock[] memory ) {
84
+ return _locks[investor];
85
+ }
86
+
70
87
/**
71
88
* @notice Get the vesting schedule of an account.
72
89
* @dev There is date or amount sorting guarantee.
73
90
* @param account The address to check
74
91
*/
75
- function schedule (address account ) external view returns (Lock[] memory ) {
76
- return locks[account];
92
+ function schedule (address account , uint256 currentDate ) public view returns (Lock[] memory ) {
93
+ Lock[] memory _accountLocks = locks (account);
94
+ Lock[] memory _tmpLocks = new Lock [](_accountLocks.length );
95
+ uint256 found = 0 ;
96
+
97
+ for (uint256 i = 0 ; i < _accountLocks.length ; i++ ) {
98
+ if (_accountLocks[i].release < currentDate) continue ;
99
+
100
+ _tmpLocks[found] = _accountLocks[i];
101
+ found++ ;
102
+ }
103
+
104
+ Lock[] memory _activeLocks = new Lock [](found);
105
+
106
+ for (uint256 j = 0 ; j < found; j++ ) {
107
+ _activeLocks[j] = _tmpLocks[j];
108
+ }
109
+
110
+ return _activeLocks;
77
111
}
78
112
79
113
/**
@@ -83,12 +117,13 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
83
117
* @param currentDate The date reference to use.
84
118
*/
85
119
function locked (address account , uint256 currentDate ) public view returns (uint256 ) {
120
+ Lock[] memory _activeLocks = schedule (account, currentDate);
86
121
uint256 sum = 0 ;
87
122
88
- for (uint256 i = 0 ; i < locks[account] .length ; i++ ) {
89
- if (locks[account] [i].release < currentDate) continue ;
123
+ for (uint256 i = 0 ; i < _activeLocks .length ; i++ ) {
124
+ if (_activeLocks [i].release < currentDate) continue ;
90
125
91
- sum += locks[account] [i].value;
126
+ sum += _activeLocks [i].value;
92
127
}
93
128
94
129
return sum;
@@ -107,20 +142,25 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
107
142
}
108
143
109
144
/**
110
- * @notice Allow the owner to upgrade the bridge.
111
- * @param newBridge New address of the bridge.
145
+ * @notice Lock DPS to an investor.
146
+ * @param investor Address of the investor.
147
+ * @param details The amount to lock and the release date in epoch.
112
148
*/
113
- function upgradeBridge (address newBridge ) external onlyRole (DEFAULT_ADMIN_ROLE) {
114
- bridge = newBridge ;
149
+ function lock (address investor , Lock memory details ) public onlyRole (DEFAULT_ADMIN_ROLE) {
150
+ _locks[investor]. push (details) ;
115
151
}
116
152
117
153
/**
118
- * @notice Lock DPS to an investor .
119
- * @param investor Address of the investor .
120
- * @param details The amount to lock and the release date in epoch .
154
+ * @notice Batch lock DPS to investors .
155
+ * @param investors Address of the investors .
156
+ * @param details The lock details .
121
157
*/
122
- function lock (address investor , Lock memory details ) external onlyRole (DEFAULT_ADMIN_ROLE) {
123
- locks[investor].push (details);
158
+ function lockBatch (address [] memory investors , Lock[] memory details ) external onlyRole (DEFAULT_ADMIN_ROLE) {
159
+ require (investors.length == details.length , "LockingSecurity: lock batch size mismatch " );
160
+
161
+ for (uint256 i = 0 ; i < investors.length ; i++ ) {
162
+ lock (investors[i], details[i]);
163
+ }
124
164
}
125
165
126
166
/**
@@ -129,17 +169,21 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
129
169
* @param investor Address of the investor.
130
170
* @param details The amount to lock and the release date in epoch.
131
171
*/
132
- function vest (address investor , Lock memory details ) external onlyRole (DEFAULT_ADMIN_ROLE) {
133
- locks [investor].push (details);
172
+ function vest (address investor , Lock memory details ) public onlyRole (DEFAULT_ADMIN_ROLE) {
173
+ _locks [investor].push (details);
134
174
DPS.transferFrom (msg .sender , investor, details.value);
135
175
}
136
176
137
177
/**
138
- * @notice Returns the list of an investors locked funds .
139
- * @dev Works as a getter .
140
- * @param investor Address of the investor .
178
+ * @notice Batch lock DPS to investors.
179
+ * @param investors Address of the investors .
180
+ * @param details The lock details .
141
181
*/
142
- function getLocks (address investor ) public view returns (Lock[] memory ){
143
- return locks[investor];
182
+ function vestBatch (address [] memory investors , Lock[] memory details ) external onlyRole (DEFAULT_ADMIN_ROLE) {
183
+ require (investors.length == details.length , "LockingSecurity: vest batch size mismatch " );
184
+
185
+ for (uint256 i = 0 ; i < investors.length ; i++ ) {
186
+ vest (investors[i], details[i]);
187
+ }
144
188
}
145
189
}
0 commit comments