Skip to content

Commit 5865116

Browse files
author
Mathieu Bour
committed
feat(vesting): add fork script and finish vesting
1 parent 0ccdde7 commit 5865116

32 files changed

+760
-1016
lines changed

contracts/LockingSecurity.sol

+66-22
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
3838
* @dev The vesting locks, mapped by account addresses.
3939
* There is no guarantee that the locks are ordered by release date time.
4040
*/
41-
mapping(address => Lock[]) public locks;
41+
mapping(address => Lock[]) private _locks;
4242

4343
constructor(IERC20 _token) ISecurity() {
4444
DPS = _token;
@@ -67,13 +67,47 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
6767
require(amount < available(from, block.timestamp), "LockingSecurity: transfer amount exceeds available tokens");
6868
}
6969

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+
7087
/**
7188
* @notice Get the vesting schedule of an account.
7289
* @dev There is date or amount sorting guarantee.
7390
* @param account The address to check
7491
*/
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;
77111
}
78112

79113
/**
@@ -83,12 +117,13 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
83117
* @param currentDate The date reference to use.
84118
*/
85119
function locked(address account, uint256 currentDate) public view returns (uint256) {
120+
Lock[] memory _activeLocks = schedule(account, currentDate);
86121
uint256 sum = 0;
87122

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;
90125

91-
sum += locks[account][i].value;
126+
sum += _activeLocks[i].value;
92127
}
93128

94129
return sum;
@@ -107,20 +142,25 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
107142
}
108143

109144
/**
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.
112148
*/
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);
115151
}
116152

117153
/**
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.
121157
*/
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+
}
124164
}
125165

126166
/**
@@ -129,17 +169,21 @@ contract LockingSecurity is ISecurity, AccessControl, Ownable {
129169
* @param investor Address of the investor.
130170
* @param details The amount to lock and the release date in epoch.
131171
*/
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);
134174
DPS.transferFrom(msg.sender, investor, details.value);
135175
}
136176

137177
/**
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.
141181
*/
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+
}
144188
}
145189
}

0 commit comments

Comments
 (0)