Skip to content

Commit

Permalink
test: basic allocation tests (#824)
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatil12 authored Oct 15, 2024
1 parent d33b1ac commit 1ac0c6d
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 140 deletions.
9 changes: 5 additions & 4 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ contract AllocationManager is
PendingMagnitudeInfo memory info =
_getPendingMagnitudeInfo(params.operator, params.strategies[i], operatorSetKey);

// 1. Calculate slashing amount and update current/ encumbered magnitude
require(info.currentMagnitude > 0, OperatorNotAllocated());

// 1. Calculate slashing amount and update current/encumbered magnitude
uint64 slashedMagnitude = uint64(uint256(info.currentMagnitude).mulWad(params.wadToSlash));
info.currentMagnitude -= slashedMagnitude;
info.encumberedMagnitude -= slashedMagnitude;
Expand Down Expand Up @@ -108,7 +110,7 @@ contract AllocationManager is
key: uint32(block.timestamp),
value: maxMagnitudeAfterSlash
});
emit TotalMagnitudeUpdated(params.operator, params.strategies[i], maxMagnitudeAfterSlash);
emit MaxMagnitudeUpdated(params.operator, params.strategies[i], maxMagnitudeAfterSlash);

// 5. Decrease operators shares in the DelegationManager
delegation.decreaseOperatorShares({
Expand All @@ -119,8 +121,7 @@ contract AllocationManager is
});

// 6. Record the proportion of shares slashed
// TODO: use lib?
wadSlashed[i] = WAD * slashedMagnitude / maxMagnitudeBeforeSlash;
wadSlashed[i] = uint256(slashedMagnitude).divWad(maxMagnitudeBeforeSlash);
}

emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description);
Expand Down
4 changes: 3 additions & 1 deletion src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ interface IAllocationManagerErrors {
error InvalidTimestamp();
/// @dev Thrown when an invalid allocation delay is set
error InvalidAllocationDelay();
/// @dev Thrown when a slash is attempted on an operator who has not allocated to the strategy, operatorSet pair
error OperatorNotAllocated();
}

interface IAllocationManagerTypes {
Expand Down Expand Up @@ -125,7 +127,7 @@ interface IAllocationManagerEvents is IAllocationManagerTypes {
event EncumberedMagnitudeUpdated(address operator, IStrategy strategy, uint64 encumberedMagnitude);

/// @notice Emitted when an operator's total magnitude is updated for a given strategy
event TotalMagnitudeUpdated(address operator, IStrategy strategy, uint64 totalMagnitude);
event MaxMagnitudeUpdated(address operator, IStrategy strategy, uint64 totalMagnitude);

/// @notice Emitted when an operator is slashed by an operator set for a strategy
/// `wadSlashed` is the proportion of the operator's total delegated stake that was slashed
Expand Down
13 changes: 13 additions & 0 deletions src/test/mocks/AVSDirectoryMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ contract AVSDirectoryMock is Test {
_isOperatorSlashable[operator][bytes32(abi.encode(operatorSet))] = value;
}

function setIsOperatorSlashable(
address operator,
address avs,
uint32 operatorSetId,
bool value
) public virtual {
OperatorSet memory operatorSet = OperatorSet({
avs: avs,
operatorSetId: operatorSetId
});
setIsOperatorSlashable(operator, operatorSet, value);
}

function setIsOperatorSetBatch(OperatorSet[] memory operatorSets, bool value) public virtual {
_isOperatorSetBatch[keccak256(abi.encode(operatorSets))] = value;
}
Expand Down
Loading

0 comments on commit 1ac0c6d

Please sign in to comment.