@bananapus/core-v6 0.0.84 → 0.0.85
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/JBERC20.sol +32 -2
package/package.json
CHANGED
package/src/JBERC20.sol
CHANGED
|
@@ -237,28 +237,53 @@ contract JBERC20 is ERC20Votes, ERC20Permit, JBPermissioned, IERC1271, IJBActive
|
|
|
237
237
|
// ---------------------- internal transactions ---------------------- //
|
|
238
238
|
//*********************************************************************//
|
|
239
239
|
|
|
240
|
-
/// @notice Track active-
|
|
240
|
+
/// @notice Track active-vote-total changes when an account changes its delegate.
|
|
241
|
+
/// @dev Delegating to a nonzero address makes all of `account`'s voting units active. Clearing delegation removes
|
|
242
|
+
/// all of `account`'s voting units from the active total. Redelegating between two nonzero delegates only moves
|
|
243
|
+
/// votes inside OZ `Votes`, so the active total does not change.
|
|
244
|
+
/// @param account The account whose delegation is changing.
|
|
245
|
+
/// @param delegatee The new delegate. Use `address(0)` to clear delegation.
|
|
241
246
|
function _delegate(address account, address delegatee) internal virtual override {
|
|
247
|
+
// Read the current delegate before OZ mutates the delegate mapping.
|
|
242
248
|
address oldDelegate = delegates(account);
|
|
249
|
+
|
|
250
|
+
// Read the account's current voting units so any active-total delta matches the units OZ moves.
|
|
243
251
|
uint256 votingUnits = _getVotingUnits(account);
|
|
244
252
|
|
|
253
|
+
// Let OZ update the delegate mapping and the per-delegate vote checkpoints.
|
|
245
254
|
super._delegate({account: account, delegatee: delegatee});
|
|
246
255
|
|
|
256
|
+
// If the account had no delegate and now has one, its voting units just became active.
|
|
247
257
|
if (oldDelegate == address(0) && delegatee != address(0)) {
|
|
258
|
+
// Add the account's voting units to the checkpointed active total.
|
|
248
259
|
_updateActiveVotes({amount: votingUnits, increase: true});
|
|
249
260
|
} else if (oldDelegate != address(0) && delegatee == address(0)) {
|
|
261
|
+
// If the account had a delegate and now has none, its voting units just became inactive.
|
|
250
262
|
_updateActiveVotes({amount: votingUnits, increase: false});
|
|
251
263
|
}
|
|
252
264
|
}
|
|
253
265
|
|
|
254
|
-
/// @notice Track active-
|
|
266
|
+
/// @notice Track active-vote-total changes when voting units move between accounts.
|
|
267
|
+
/// @dev Moving voting units between two accounts with the same delegation status does not change the active total.
|
|
268
|
+
/// Moving voting units out of a delegated account and into an undelegated account decreases the active total, while
|
|
269
|
+
/// moving voting units out of an undelegated account and into a delegated account increases it.
|
|
270
|
+
/// @param from The account whose voting units are leaving. `address(0)` means the units are being minted.
|
|
271
|
+
/// @param to The account whose voting units are arriving. `address(0)` means the units are being burned.
|
|
272
|
+
/// @param amount The voting units moving between `from` and `to`.
|
|
255
273
|
function _transferVotingUnits(address from, address to, uint256 amount) internal virtual override {
|
|
274
|
+
// The active total decreases if units leave an account that already has a nonzero delegate.
|
|
256
275
|
bool decreaseActiveVotes = from != address(0) && delegates(from) != address(0);
|
|
276
|
+
|
|
277
|
+
// The active total increases if units arrive at an account that already has a nonzero delegate.
|
|
257
278
|
bool increaseActiveVotes = to != address(0) && delegates(to) != address(0);
|
|
258
279
|
|
|
280
|
+
// Let OZ update total voting-unit supply and per-delegate checkpoints first.
|
|
259
281
|
super._transferVotingUnits({from: from, to: to, amount: amount});
|
|
260
282
|
|
|
283
|
+
// If both sides are delegated or both sides are undelegated, the active total is unchanged.
|
|
261
284
|
if (decreaseActiveVotes == increaseActiveVotes) return;
|
|
285
|
+
|
|
286
|
+
// Otherwise apply the one-sided active-total delta implied by the receiver's delegated status.
|
|
262
287
|
_updateActiveVotes({amount: amount, increase: increaseActiveVotes});
|
|
263
288
|
}
|
|
264
289
|
|
|
@@ -268,14 +293,19 @@ contract JBERC20 is ERC20Votes, ERC20Permit, JBPermissioned, IERC1271, IJBActive
|
|
|
268
293
|
}
|
|
269
294
|
|
|
270
295
|
/// @notice Update the checkpointed total of delegated voting units.
|
|
296
|
+
/// @dev Writes at most one active-total checkpoint at the current OZ clock. A zero amount is ignored so zero-value
|
|
297
|
+
/// delegation or transfer hooks do not create empty checkpoints.
|
|
271
298
|
/// @param amount The amount of voting units to add or remove.
|
|
272
299
|
/// @param increase Whether to add `amount`; if false, `amount` is removed.
|
|
273
300
|
function _updateActiveVotes(uint256 amount, bool increase) internal {
|
|
301
|
+
// Ignore zero-unit updates because they do not change the active total.
|
|
274
302
|
if (amount == 0) return;
|
|
275
303
|
|
|
304
|
+
// Calculate the next active total by adding or subtracting from the latest checkpointed value.
|
|
276
305
|
uint256 updated =
|
|
277
306
|
increase ? _activeSupplyCheckpoints.latest() + amount : _activeSupplyCheckpoints.latest() - amount;
|
|
278
307
|
|
|
308
|
+
// Write the new active total at the current ERC-6372 clock using the same uint208 width as OZ `Votes`.
|
|
279
309
|
_activeSupplyCheckpoints.push({key: clock(), value: SafeCast.toUint208(updated)});
|
|
280
310
|
}
|
|
281
311
|
}
|