Skip to content

Commit f812f86

Browse files
8sunyuan0xClandestine
authored andcommitted
feat: refactor to free all opsets on allo/deallo (#680)
* feat: operator commission bips (#627) * feat: operator commission bips configured with a delay * build: bindings * fix: interfaces and comments * fix: storage gap and comments * chore: tests cleanup * build: bindings * chore: `forge fmt src/contracts` * feat: `operatorCommissionUpdates` length getter * fix: remove unused imports * fix: optimizations * chore: uncheckeds and remove dup view * build: bindings * chore: format --------- Co-authored-by: clandestine.eth <[email protected]> * feat: refactor to free all opsets on allo/deallo * refactor: pendingFreeMagnitude and index pointers * chore: nits * chore: reorder storage * feat: numToComplete and rebase cleanup --------- Co-authored-by: clandestine.eth <[email protected]>
1 parent bd7fc4d commit f812f86

File tree

10 files changed

+292
-237
lines changed

10 files changed

+292
-237
lines changed

pkg/bindings/AVSDirectory/binding.go

Lines changed: 75 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/AVSDirectoryStorage/binding.go

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/IAVSDirectory/binding.go

Lines changed: 43 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/bindings/RewardsCoordinator/binding.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/contracts/core/AVSDirectory.sol

Lines changed: 108 additions & 71 deletions
Large diffs are not rendered by default.

src/contracts/core/AVSDirectoryStorage.sol

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,23 @@ abstract contract AVSDirectoryStorage is IAVSDirectory {
6060
/// Note that totalMagnitude is monotonically decreasing and only gets updated upon slashing
6161
mapping(address => mapping(IStrategy => Checkpoints.History)) internal _totalMagnitudeUpdate;
6262

63+
/// @notice Mapping: operator => strategy => avs => operatorSetId => checkpointed magnitude
64+
mapping(address => mapping(IStrategy => mapping(address => mapping(uint32 => Checkpoints.History)))) internal
65+
_magnitudeUpdate;
66+
6367
/// @notice Mapping: operator => strategy => free available magnitude that can be allocated to operatorSets
6468
/// Decrements whenever allocations take place and increments when deallocations are completed
6569
mapping(address => mapping(IStrategy => uint64)) public freeMagnitude;
6670

67-
/// @notice Mapping: operator => strategy => avs => operatorSetId => checkpointed magnitude
68-
mapping(address => mapping(IStrategy => mapping(address => mapping(uint32 => Checkpoints.History))))
69-
internal _magnitudeUpdate;
71+
/// @notice Mapping: operator => strategy => PendingFreeMagnitude[] to keep track of pending free magnitude from deallocations
72+
mapping(address => mapping(IStrategy => PendingFreeMagnitude[])) internal _pendingFreeMagnitude;
7073

71-
/// @notice Mapping: operator => strategy => avs => operatorSetId => queuedDeallocations
72-
mapping(address => mapping(IStrategy => mapping(address => mapping(uint32 => QueuedDeallocation[])))) internal
73-
_queuedDeallocations;
74+
/// @notice Mapping: operator => strategy => index pointing to next pendingFreeMagnitude to complete and add to freeMagnitude
75+
mapping(address => mapping(IStrategy => uint256)) internal _nextPendingFreeMagnitudeIndex;
7476

75-
/// @notice Mapping: operator => strategy => avs => operatorSetId => index pointing to next queuedDeallocation to complete
76-
mapping(address => mapping(IStrategy => mapping(address => mapping(uint32 => uint256)))) internal
77-
_nextDeallocationIndex;
77+
/// @notice Mapping: operator => strategy => avs => operatorSetId => list of queuedDeallocation indices
78+
mapping(address => mapping(IStrategy => mapping(address => mapping(uint32 => uint256[])))) internal
79+
_queuedDeallocationIndices;
7880

7981
/// @notice Mapping: operatorSet => List of operators that are registered to the operatorSet
8082
/// @dev Each key is formatted as such: bytes32(abi.encodePacked(avs, uint96(operatorSetId)))

src/contracts/core/RewardsCoordinatorStorage.sol

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ abstract contract RewardsCoordinatorStorage is IRewardsCoordinator {
9999

100100
/// @notice Mapping: address => bool to check if the address is permissioned to call createRewardsForAllSubmission
101101
mapping(address => bool) public isRewardsForAllSubmitter;
102-
/// @notice Mapping: operator => avs => operatorSetId => OperatorCommissionUpdate history
103-
mapping(address => mapping(address => mapping(uint32 => mapping(RewardType => OperatorCommissionUpdate[])))) public
104-
operatorCommissionUpdates;
105102

106103
/// @notice Mapping: avs => rewardsSubmissionHash => bool to check if operatorSet rewards submission hash has been submitted
107104
mapping(address => mapping(bytes32 => bool)) isOperatorSetRewardsSubmissionHash;

src/contracts/interfaces/IAVSDirectory.sol

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ interface IAVSDirectory is ISignatureUtils {
4646
}
4747

4848
/**
49-
* @notice struct used for queued deallocations. Stored in (operator, strategy, operatorSet) mapping
49+
* @notice struct used for pending free magnitude. Stored in (operator, strategy, operatorSet) mapping
5050
* to be used in completeDeallocations.
5151
* @param magnitudeDiff the amount of magnitude to deallocate
5252
* @param completableTimestamp the timestamp at which the deallocation can be completed, 21 days from when queued
5353
*/
54-
struct QueuedDeallocation {
54+
struct PendingFreeMagnitude {
5555
uint64 magnitudeDiff;
5656
uint32 completableTimestamp;
5757
}
@@ -225,27 +225,26 @@ interface IAVSDirectory is ISignatureUtils {
225225
* @param deallocations array of magnitude adjustments for multiple strategies and corresponding operator sets
226226
* @param operatorSignature signature of the operator if msg.sender is not the operator
227227
*/
228-
function queueDeallocate(
228+
function deallocate(
229229
address operator,
230230
MagnitudeAdjustment[] calldata deallocations,
231231
SignatureWithSaltAndExpiry calldata operatorSignature
232232
) external;
233233

234234
/**
235-
* @notice Complete queued deallocations of slashable stake for an operator, permissionlessly called by anyone
236-
* Increments the free magnitude of the operator by the sum of all deallocation amounts for each strategy.
237-
* If the operator was slashed, this will be a smaller amount than during queuing.
235+
* @notice For all pending deallocations that have become completable, their pending free magnitude can be
236+
* added back to the free magnitude of the (operator, strategy) amount. This function takes a list of strategies
237+
* and adds all completable deallocations for each strategy, updating the freeMagnitudes of the operator
238238
*
239239
* @param operator address to complete deallocations for
240240
* @param strategies a list of strategies to complete deallocations for
241-
* @param operatorSets a 2d list of operator sets to complete deallocations for, one list for each strategy
242241
*
243242
* @dev can be called permissionlessly by anyone
244243
*/
245-
function completeDeallocations(
244+
function updateFreeMagnitude(
246245
address operator,
247246
IStrategy[] calldata strategies,
248-
OperatorSet[][] calldata operatorSets
247+
uint8[] calldata numToComplete
249248
) external;
250249

251250
/**

src/contracts/interfaces/IRewardsCoordinator.sol

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,6 @@ interface IRewardsCoordinator {
8282
* using `OPERATOR_SET_GENESIS_REWARDS_TIMESTAMP` instead of `GENESIS_REWARDS_TIMESTAMP` and
8383
* `OPERATOR_SET_MAX_RETROACTIVE_LENGTH` instead of `MAX_RETROACTIVE_LENGTH`
8484
*/
85-
86-
struct OperatorSetRewardsSubmission {
87-
RewardType rewardType;
88-
uint32 operatorSetId;
89-
StrategyAndMultiplier[] strategiesAndMultipliers;
90-
IERC20 token;
91-
uint256 amount;
92-
uint32 startTimestamp;
93-
uint32 duration;
94-
}
95-
9685
struct OperatorSetRewardsSubmission {
9786
RewardType rewardType;
9887
uint32 operatorSetId;

src/test/mocks/AVSDirectoryMock.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ contract AVSDirectoryMock is IAVSDirectory, Test {
4242
SignatureWithSaltAndExpiry calldata operatorSignature
4343
) external {}
4444

45-
function queueDeallocate(
45+
function deallocate(
4646
address operator,
4747
MagnitudeAdjustment[] calldata deallocations,
4848
SignatureWithSaltAndExpiry calldata operatorSignature
4949
) external {}
5050

51-
function completeDeallocations(
51+
function updateFreeMagnitude(
5252
address operator,
5353
IStrategy[] calldata strategies,
54-
OperatorSet[][] calldata operatorSets
54+
uint8[] calldata freeMagnitudes
5555
) external {}
5656

5757
function slashOperator(

0 commit comments

Comments
 (0)