Skip to content

Commit b8dc82a

Browse files
sohkaißingen
and
ßingen
authored
[Internal audit] Part 2 notes (aragon#63)
* Checkpointing: optimize some edge cases * Initial comments * Restore comments for _add192 function * Fix Checkpointing compilation errors * Rearrange some contract locations * Remove unused ScriptHelpers * Remove broken gas tests * Move TimeLockManager to test folder * Remove comment from Checkpointing * fixup! Remove broken gas tests * Remove Staking proxy * fixup! Move TimeLockManager to test folder * Staking: add more notes * Style changes to StakingFactory * Minor changes to IStakingLocking * Add tests to Checkpointing * Remove note from Checkpointing * Remove note from StandardTokenMock * Remove setLockManager * Rename stakingToken to token * Remove setLockManager from docs * Remove _toBytes4 function * Remove TimeLockManager * Merge require’s on receiveApproval * Prevent locking by user directly in Staking contract Locking has to be done always from/by LockManager. * Remove require from slashAndUnlock To save gas. Now this function can behave the same as slash if _unlockAmount is zero. * Clarify comment * Remove unused ECRProxy interface * Rename interfaces with prefix I * docs: Prevent locking by user directly in Staking contract * docs: Remove references to contract initialization * fixup! docs: Remove references to contract initialization * Add ERC900 optional methods * Index some IStakingLocking events * Inline Staking functions (transferAndUnstake and slashAndUnstake) * Rename IStakingLocking to ILockable * Add ERC223Recipient fallback * Update exported IStaking interface * Staking: polish interfaces * Add missing headers for IERC900 * Split optional History methods from IERC900 * Remove increase param from ILockable events * Revert "Add ERC223Recipient fallback" This reverts commit 0c1c768. * Re-add IApproveAndCallFallBack * Staking: dedupe _transferAndUnstake() * Staking: remove unused errors Co-authored-by: ßingen <[email protected]>
1 parent 96c4d64 commit b8dc82a

28 files changed

+331
-576
lines changed

docs/3-entry-points/README.md

+3-71
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ Funds flows with different origin and destiny:
2020
| Lock | Stake | slash |
2121
| Lock | Wallet | slashAndUnstake |
2222

23-
### initialize
24-
25-
This is used by the Staking Factory when creating a new proxy. See deployment section for more details.
23+
### constructor
2624

2725
- **Actor:** Deployer account
2826
- **Inputs:**
@@ -47,7 +45,6 @@ Stakes `_amount` tokens, transferring them from `msg.sender`
4745
- **_data:** Used in Staked event, to add signalling information in more complex staking applications
4846
- **Authentication:** Open
4947
- **Pre-flight checks:**
50-
- Checks that contract has been initialized
5148
- Checks that amount is not zero
5249
- **State transitions:**
5350
- Transfers tokens from sender to contract
@@ -65,7 +62,6 @@ Stakes `_amount` tokens, transferring them from `msg.sender`, and assigns them t
6562
- **_data:** Used in Staked event, to add signalling information in more complex staking applications
6663
- **Authentication:** Open
6764
- **Pre-flight checks:**
68-
- Checks that contract has been initialized
6965
- Checks that amount is not zero
7066
- **State transitions:**
7167
- Transfers tokens from sender to contract
@@ -83,7 +79,6 @@ Unstakes `_amount` tokens, returning them to the user
8379
- **_data:** Used in Unstaked event, to add signalling information in more complex staking applications
8480
- **Authentication:** Open
8581
- **Pre-flight checks:**
86-
- Checks that contract has been initialized
8782
- Checks that amount is not zero
8883
- **State transitions:**
8984
- Transfers tokens from contract to sender
@@ -99,8 +94,6 @@ Get the token used by the contract for staking and locking
9994
- **Outputs:**
10095
- Address of the staking token
10196
- **Authentication:** Open
102-
- **Pre-flight checks:**
103-
- Checks that contract has been initialized
10497

10598

10699
### supportsHistory
@@ -123,8 +116,6 @@ Get last time `_user` modified its staked balance
123116
- **Outputs:**
124117
- Last block number when account’s balance was modified
125118
- **Authentication:** Open
126-
- **Pre-flight checks:**
127-
- Checks that contract has been initialized
128119

129120

130121
### totalStakedForAt
@@ -138,8 +129,6 @@ Get the total amount of tokens staked by `_user` at block number `_blockNumber`
138129
- **Outputs:**
139130
- The amount of tokens staked by the account at the given block number
140131
- **Authentication:** Open
141-
- **Pre-flight checks:**
142-
- Checks that contract has been initialized
143132

144133

145134
### totalStakedAt
@@ -152,8 +141,6 @@ Get the total amount of tokens staked by all users at block number `_blockNumber
152141
- **Outputs:**
153142
- The amount of tokens staked at the given block number
154143
- **Authentication:** Open
155-
- **Pre-flight checks:**
156-
- Checks that contract has been initialized
157144

158145

159146
### totalStakedFor
@@ -166,8 +153,6 @@ Get the amount of tokens staked by `_user`
166153
- **Outputs:**
167154
- The amount of tokens staked by the given account
168155
- **Authentication:** Open
169-
- **Pre-flight checks:**
170-
- Checks that contract has been initialized
171156

172157
### totalStaked
173158

@@ -177,8 +162,6 @@ Get the total amount of tokens staked by all users
177162
- **Outputs:**
178163
- The total amount of tokens staked by all users
179164
- **Authentication:** Open
180-
- **Pre-flight checks:**
181-
- Checks that contract has been initialized
182165

183166

184167
## Locking interface
@@ -195,35 +178,10 @@ It creates a new lock, so the lock for this manager cannot exist before.
195178
- **_data:** Used in `NewLockManager` event and to parametrize logic for the lock to be enforced by the manager
196179
- **Authentication:** Open. Implicitly, sender must be staking owner.
197180
- **Pre-flight checks:**
198-
- Checks that contract has been initialized
199-
- Checks that allowance input is not zero
200-
- Checks that lock didn’t exist before
201-
- **State transitions:**
202-
- Sets allowance for the pair owner-manager to the given amount
203-
- Calls lock manager callback
204-
205-
### allowManagerAndLock
206-
207-
Lock `_amount` staked tokens and assign `_lockManager` as manager with `_allowance` allowed tokens and `_data` as data, so they can not be unstaked
208-
209-
- **Actor:** Staking user (owner)
210-
- **Inputs:**
211-
- **_amount:** The amount of tokens to be locked
212-
- **_lockManager:** The manager entity for this particular lock
213-
- **_allowance:** Amount of tokens that the manager can lock
214-
- **_data:** Used in `NewLockManager` event and to parametrize logic for the lock to be enforced by the manager
215-
- **Authentication:** Open. Implicitly, sender must be staking owner.
216-
- **Pre-flight checks:**
217-
- Checks that contract has been initialized
218181
- Checks that allowance input is not zero
219182
- Checks that lock didn’t exist before
220-
- Checks that amount input is not zero
221-
- Checks that user has enough unlocked tokens available
222-
- Checks that amount is not greater than allowance
223183
- **State transitions:**
224184
- Sets allowance for the pair owner-manager to the given amount
225-
- Sets the amount of tokens as locked by the manager
226-
- Increases the total amount of locked tokens balance for the user
227185
- Calls lock manager callback
228186

229187

@@ -237,7 +195,6 @@ Transfer `_amount` tokens to `_to`’s staked balance
237195
- **_amount:** Number of tokens to be transferred
238196
- **Authentication:** Open. Implicitly, sender must be staking owner.
239197
- **Pre-flight checks:**
240-
- Checks that contract has been initialized
241198
- Checks that amount input is not zero
242199
- Checks that user has enough unlocked tokens available
243200
- **State transitions:**
@@ -254,7 +211,6 @@ Transfer `_amount` tokens to `_to`’s external balance (i.e. unstaked)
254211
- **_amount:** Number of tokens to be transferred
255212
- **Authentication:** Open. Implicitly, sender must be staking owner.
256213
- **Pre-flight checks:**
257-
- Checks that contract has been initialized
258214
- Checks that amount input is not zero
259215
- Checks that user has enough unlocked tokens available
260216
- **State transitions:**
@@ -273,7 +229,6 @@ Transfer `_amount` tokens from `_from`'s lock by `msg.sender` to `_to`
273229
- **_amount:** Number of tokens to be transferred
274230
- **Authentication:** Open. Implicitly, sender must be lock manager.
275231
- **Pre-flight checks:**
276-
- Checks that contract has been initialized
277232
- Check that owner’s lock is enough
278233
- Checks that amount input is not zero
279234
- **State transitions:**
@@ -293,7 +248,6 @@ Transfer `_amount` tokens from `_from`'s lock by `msg.sender` to `_to`’s exter
293248
- **_amount:** Number of tokens to be transferred
294249
- **Authentication:** Open. Implicitly, sender must be lock manager
295250
- **Pre-flight checks:**
296-
- Checks that contract has been initialized
297251
- Check that owner’s lock is enough
298252
- Checks that amount input is not zero
299253
- **State transitions:**
@@ -315,7 +269,6 @@ Transfer `_transferAmount` tokens from `_from`'s lock by `msg.sender` to `_to`,
315269
- **_slashAmount:** Number of tokens to be transferred
316270
- **Authentication:** Open. Implicitly, sender must be lock manager
317271
- **Pre-flight checks:**
318-
- Checks that contract has been initialized
319272
- Check that owner’s lock is enough
320273
- Checks that unlock amount input is not zero
321274
- Checks that slash amount input is not zero
@@ -336,7 +289,6 @@ Increase allowance in `_allowance` tokens of lock manager `_lockManager` for use
336289
- **_allowance:** Amount of allowed tokens increase
337290
- **Authentication:** Open. Implicitly, sender must be staking owner.
338291
- **Pre-flight checks:**
339-
- Checks that contract has been initialized
340292
- Checks that lock exists (i.e., it has a previous allowance)
341293
- Checks that amount input is not zero
342294
- **State transitions:**
@@ -353,7 +305,6 @@ Decrease allowance in `_allowance` tokens of lock manager `_lockManager` for use
353305
- **_allowance:** Amount of allowed tokens decrease
354306
- **Authentication:** Only owner or lock manager
355307
- **Pre-flight checks:**
356-
- Checks that contract has been initialized
357308
- Checks that amount input is not zero
358309
- Checks that lock exists (i.e., it has a previous allowance)
359310
- Checks that final allowed amount is not less than currently locked tokens
@@ -364,16 +315,14 @@ Decrease allowance in `_allowance` tokens of lock manager `_lockManager` for use
364315

365316
### lock
366317

367-
Increase locked amount by `_amount` tokens for user `_user` by lock manager `_lockManager`
318+
Increase locked amount by `_amount` tokens for user `_user` by lock manager `msg.sender`
368319

369-
- **Actor:** Staking user (owner) or lock manager
320+
- **Actor:** Lock manager
370321
- **Inputs:**
371322
- **_user:** Owner of locked tokens
372-
- **_lockManager:** The manager entity for this particular lock
373323
- **_amount:** Amount of locked tokens increase
374324
- **Authentication:** Only owner or lock manager
375325
- **Pre-flight checks:**
376-
- Checks that contract has been initialized
377326
- Checks that amount input is not zero
378327
- Checks that user has enough unlocked tokens available
379328
- Checks that lock has enough allowance
@@ -392,7 +341,6 @@ Decrease locked amount by `_amount` tokens for user `_user` by lock manager `_lo
392341
- **_amount:** Amount of locked tokens decrease
393342
- **Authentication:** Only owner or lock manager
394343
- **Pre-flight checks:**
395-
- Checks that contract has been initialized
396344
- Checks that amount input is not zero
397345
- Checks that lock exists (i.e., it has a previous allowance)
398346
- Checks that user has enough unlocked tokens available
@@ -412,28 +360,12 @@ Unlock `_user`'s lock by `_lockManager` so locked tokens can be unstaked again
412360
- **_lockManager:** The manager entity for this particular lock
413361
- **Authentication:** Only owner or lock manager
414362
- **Pre-flight checks:**
415-
- Checks that contract has been initialized
416363
- Checks that lock exists (i.e., it has a previous allowance)
417364
- If sender is owner and there were locked tokens, checks that manager allows to unlock
418365
- **State transitions:**
419366
- Decreases owner’s total locked amount by currently locked tokens for this lock manager
420367
- Deletes lock for this pair of owner and lock manager
421368

422-
### setLockManager
423-
424-
Change the manager of `_user`'s lock from `msg.sender` to `_newLockManager`
425-
426-
- **Actor:** Lock manager
427-
- **Inputs:**
428-
- **_user:** Owner of lock
429-
- **_newLockManager:** New lock manager
430-
- **Authentication:** Open. Implicitly, sender must be lock manager
431-
- **Pre-flight checks:**
432-
- Checks that contract has been initialized
433-
- Checks that lock exists
434-
- **State transitions:**
435-
- Assigns lock to new manager
436-
437369
### getTotalLockedOf
438370

439371
Get total amount of locked tokens for `_user`

docs/5-external-interface/README.md

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# External interface
22

3-
### Initialize
3+
### Constructor
44

5-
- **Name:** initialize
5+
- **Name:** constructor
66
- **Inputs:**
77
- **_stakingToken:** ERC20 token to be used for staking
88

@@ -92,15 +92,6 @@
9292
- **_allowance:** Amount of tokens that the manager can lock
9393
- **_data:** Used in `NewLockManager` event and to parametrize logic for the lock to be enforced by the manager
9494

95-
### Allow new manager and lock
96-
97-
- **Name:** allowManagerAndLock
98-
- **Inputs:**
99-
- **_amount:** The amount of tokens to be locked
100-
- **_lockManager:** The manager entity for this particular lock
101-
- **_allowance:** Amount of tokens that the manager can lock
102-
- **_data:** Used in `NewLockManager` event and to parametrize logic for the lock to be enforced by the manager
103-
10495
### Transfer
10596

10697
- **Name:** transfer
@@ -160,7 +151,6 @@
160151
- **Name:** lock
161152
- **Inputs:**
162153
- **_user:** Owner of locked tokens
163-
- **_lockManager:** The manager entity for this particular lock
164154
- **_amount:** Amount of locked tokens increase
165155

166156
### Unlock
@@ -178,13 +168,6 @@
178168
- **_user:** Owner of locked tokens
179169
- **_lockManager:** The manager entity for this particular lock
180170

181-
### Set lock manager
182-
183-
- **Name:** setLockManager
184-
- **Inputs:**
185-
- **_user:** Owner of lock
186-
- **_newLockManager:** New lock manager
187-
188171
### Get total locked of
189172

190173
- **Name:** getTotalLockedOf

0 commit comments

Comments
 (0)