From c77fac2d918c644421e91160eab825725d01d9d4 Mon Sep 17 00:00:00 2001 From: vgorkavenko Date: Tue, 5 Dec 2023 12:10:42 +0400 Subject: [PATCH] fix: review (part 1) --- src/CSAccounting.sol | 65 ++++++++----- src/CSBondLock.sol | 41 ++++---- test/CSBondLock.t.sol | 213 ++++++++++++++++++------------------------ 3 files changed, 153 insertions(+), 166 deletions(-) diff --git a/src/CSAccounting.sol b/src/CSAccounting.sol index d61a9568..cec775e4 100644 --- a/src/CSAccounting.sol +++ b/src/CSAccounting.sol @@ -56,6 +56,8 @@ contract CSAccountingBase { uint256 proposedBlockNumber, uint256 stolenAmount ); + event BondLockCompensated(uint256 indexed nodeOperatorId, uint256 amount); + event BondLockReleased(uint256 indexed nodeOperatorId, uint256 amount); error NotOwnerToClaim(address msgSender, address owner); error InvalidSender(); @@ -79,6 +81,8 @@ contract CSAccounting is keccak256("INSTANT_PENALIZE_BOND_ROLE"); // 0x9909cf24c2d3bafa8c229558d86a1b726ba57c3ef6350848dcf434a4181b56c7 bytes32 public constant EL_REWARDS_STEALING_PENALTY_INIT_ROLE = keccak256("EL_REWARDS_STEALING_PENALTY_INIT_ROLE"); // 0xcc2e7ce7be452f766dd24d55d87a3d42901c31ffa5b600cd1dff475abec91c1f + bytes32 public constant EL_REWARDS_STEALING_PENALTY_RELEASE_ROLE = + keccak256("EL_REWARDS_STEALING_PENALTY_RELEASE_ROLE"); // 0x8d78671045c549f09e0cf6e7e9856c36698f72f93962abf8e1955dc595a592ee bytes32 public constant EL_REWARDS_STEALING_PENALTY_SETTLE_ROLE = keccak256("EL_REWARDS_STEALING_PENALTY_SETTLE_ROLE"); // 0xdf6226649a1ca132f86d419e46892001284368a8f7445b5eb0d3fadf91329fe6 bytes32 public constant SET_BOND_CURVE_ROLE = @@ -100,8 +104,8 @@ contract CSAccounting is /// @param lidoLocator lido locator contract address /// @param wstETH wstETH contract address /// @param communityStakingModule community staking module contract address - /// @param bondLockRetentionPeriod retention period for blocked bond in seconds - /// @param bondLockManagementPeriod management period for blocked bond in seconds + /// @param bondLockRetentionPeriod retention period for locked bond in seconds + /// @param bondLockManagementPeriod management period for locked bond in seconds constructor( uint256[] memory bondCurve, address admin, @@ -135,7 +139,7 @@ contract CSAccounting is FEE_DISTRIBUTOR = fdAddress; } - function setBlockedBondPeriods( + function setLockedBondPeriods( uint256 retention, uint256 management ) external onlyRole(DEFAULT_ADMIN_ROLE) { @@ -275,13 +279,24 @@ contract CSAccounting is return WSTETH.getWstETHByStETH(getMissingBondStETH(nodeOperatorId)); } - /// @notice Returns the amount of ETH blocked by the given node operator. - function getBlockedBondETH( + /// @notice Returns information about the locked bond for the given node operator. + /// @param nodeOperatorId id of the node operator to get locked bond info for. + /// @return locked bond info. + function getLockedBondInfo( uint256 nodeOperatorId - ) public view returns (uint256) { + ) public view returns (CSBondLock.BondLock memory) { return CSBondLock._get(nodeOperatorId); } + /// @notice Returns the amount of locked bond in ETH by the given node operator. + /// @param nodeOperatorId id of the node operator to get locked bond amount. + /// @return amount of locked bond in ETH. + function getActualLockedBondETH( + uint256 nodeOperatorId + ) public view returns (uint256) { + return CSBondLock._getActualAmount(nodeOperatorId); + } + /// @notice Returns the required bond ETH (inc. missed and excess) for the given node operator to upload new keys. /// @param nodeOperatorId id of the node operator to get required bond for. /// @return required bond ETH. @@ -377,10 +392,10 @@ contract CSAccounting is ) public view returns (uint256) { uint256 activeKeys = _getNodeOperatorActiveKeys(nodeOperatorId); uint256 currentBond = _ethByShares(_bondShares[nodeOperatorId]); - uint256 blockedBond = getBlockedBondETH(nodeOperatorId); - if (currentBond > blockedBond) { + uint256 lockedBond = getActualLockedBondETH(nodeOperatorId); + if (currentBond > lockedBond) { uint256 multiplier = getBondMultiplier(nodeOperatorId); - currentBond -= blockedBond; + currentBond -= lockedBond; uint256 bondedKeys = _getKeysCountByBondAmount( currentBond, multiplier @@ -696,33 +711,35 @@ contract CSAccounting is CSBondLock._lock(nodeOperatorId, amount); } - /// @notice Releases blocked bond ETH for the given node operator. - /// @param nodeOperatorId id of the node operator to release blocked bond for. + /// @notice Releases locked bond ETH for the given node operator. + /// @param nodeOperatorId id of the node operator to release locked bond for. /// @param amount amount of ETH to release. - function releaseBlockedBondETH( + function releaseLockedBondETH( uint256 nodeOperatorId, uint256 amount ) external - onlyRole(EL_REWARDS_STEALING_PENALTY_INIT_ROLE) + onlyRole(EL_REWARDS_STEALING_PENALTY_RELEASE_ROLE) onlyExistingNodeOperator(nodeOperatorId) { - CSBondLock._release(nodeOperatorId, amount); + CSBondLock._reduceAmount(nodeOperatorId, amount); + emit BondLockReleased(nodeOperatorId, amount); } - /// @notice Compensates blocked bond ETH for the given node operator. - /// @param nodeOperatorId id of the node operator to compensate blocked bond for. - function compensateBlockedBondETH( + /// @notice Compensates locked bond ETH for the given node operator. + /// @param nodeOperatorId id of the node operator to compensate locked bond for. + function compensateLockedBondETH( uint256 nodeOperatorId ) external payable onlyExistingNodeOperator(nodeOperatorId) { - CSBondLock._compensate(nodeOperatorId, msg.value); payable(LIDO_LOCATOR.elRewardsVault()).transfer(msg.value); + CSBondLock._reduceAmount(nodeOperatorId, msg.value); + emit BondLockCompensated(nodeOperatorId, msg.value); } - /// @dev Should be called by the committee. Doesn't settle blocked bond if it is in the safe frame (1 day) - /// @notice Settles blocked bond for the given node operators. - /// @param nodeOperatorIds ids of the node operators to settle blocked bond for. - function settleBlockedBondETH( + /// @dev Should be called by the committee. Doesn't settle locked bond if it is in the safe frame (1 day) + /// @notice Settles locked bond for the given node operators. + /// @param nodeOperatorIds ids of the node operators to settle locked bond for. + function settleLockedBondETH( uint256[] memory nodeOperatorIds ) external onlyRole(EL_REWARDS_STEALING_PENALTY_SETTLE_ROLE) { CSBondLock._settle(nodeOperatorIds); @@ -828,7 +845,7 @@ contract CSAccounting is _getNodeOperatorActiveKeys(nodeOperatorId), getBondMultiplier(nodeOperatorId) ) + - getBlockedBondETH(nodeOperatorId); + getActualLockedBondETH(nodeOperatorId); } function _bondSharesSummary( @@ -842,7 +859,7 @@ contract CSAccounting is getBondMultiplier(nodeOperatorId) ) ) + - _sharesByEth(getBlockedBondETH(nodeOperatorId)); + _sharesByEth(getActualLockedBondETH(nodeOperatorId)); } function _sharesByEth(uint256 ethAmount) internal view returns (uint256) { diff --git a/src/CSBondLock.sol b/src/CSBondLock.sol index 038f59ea..14d5076a 100644 --- a/src/CSBondLock.sol +++ b/src/CSBondLock.sol @@ -9,10 +9,12 @@ abstract contract CSBondLockBase { uint256 newAmount, uint256 retentionUntil ); - event BondLockCompensated(uint256 indexed nodeOperatorId, uint256 amount); - event BondLockReleased(uint256 indexed nodeOperatorId, uint256 amount); + event BondLockPeriodsChanged( + uint256 retentionPeriod, + uint256 managementPeriod + ); - error InvalidBondLockRetentionPeriod(); + error InvalidBondLockPeriods(); error InvalidBondLockAmount(); } @@ -44,6 +46,7 @@ abstract contract CSBondLock is CSBondLockBase { _validateBondLockPeriods(retention, management); _bondLockRetentionPeriod = retention; _bondLockManagementPeriod = management; + emit BondLockPeriodsChanged(retention, management); } function getBondLockPeriods() @@ -64,12 +67,21 @@ abstract contract CSBondLock is CSBondLockBase { management < MIN_BOND_LOCK_MANAGEMENT_PERIOD || management > MAX_BOND_LOCK_MANAGEMENT_PERIOD ) { - revert InvalidBondLockRetentionPeriod(); + revert InvalidBondLockPeriods(); } } + /// @notice Returns the amount and retention time of locked bond by the given node operator. + function _get( + uint256 nodeOperatorId + ) internal view returns (BondLock memory) { + return _bondLock[nodeOperatorId]; + } + /// @notice Returns the amount of locked bond by the given node operator. - function _get(uint256 nodeOperatorId) internal view returns (uint256) { + function _getActualAmount( + uint256 nodeOperatorId + ) internal view returns (uint256) { if (_bondLock[nodeOperatorId].retentionUntil >= block.timestamp) { return _bondLock[nodeOperatorId].amount; } @@ -121,23 +133,8 @@ abstract contract CSBondLock is CSBondLockBase { } } - /// @notice Releases blocked bond ETH for the given node operator. - /// @param nodeOperatorId id of the node operator to release blocked bond for. - /// @param amount amount of ETH to release. - function _release(uint256 nodeOperatorId, uint256 amount) internal { - emit BondLockReleased(nodeOperatorId, amount); - _reduceAmount(nodeOperatorId, amount); - } - - /// @notice Compensates blocked bond ETH for the given node operator. - /// @param nodeOperatorId id of the node operator to compensate blocked bond for. - function _compensate(uint256 nodeOperatorId, uint256 amount) internal { - emit BondLockCompensated(nodeOperatorId, amount); - _reduceAmount(nodeOperatorId, amount); - } - - function _reduceAmount(uint256 nodeOperatorId, uint256 amount) private { - uint256 blocked = _get(nodeOperatorId); + function _reduceAmount(uint256 nodeOperatorId, uint256 amount) internal { + uint256 blocked = _getActualAmount(nodeOperatorId); if (amount == 0) { revert InvalidBondLockAmount(); } diff --git a/test/CSBondLock.t.sol b/test/CSBondLock.t.sol index 383dd60c..aa88f4f5 100644 --- a/test/CSBondLock.t.sol +++ b/test/CSBondLock.t.sol @@ -39,10 +39,16 @@ contract CSBondLockTestable is CSBondLockTestableBase, CSBondLock { _setBondLockPeriods(retention, management); } - function get(uint256 nodeOperatorId) external view returns (uint256) { + function get( + uint256 nodeOperatorId + ) external view returns (CSBondLock.BondLock memory) { return _get(nodeOperatorId); } + function getActualAmount(uint256 amount) external view returns (uint256) { + return _getActualAmount(amount); + } + function lock(uint256 nodeOperatorId, uint256 amount) external { _lock(nodeOperatorId, amount); } @@ -51,29 +57,26 @@ contract CSBondLockTestable is CSBondLockTestableBase, CSBondLock { _settle(nodeOperatorIds); } - function release(uint256 nodeOperatorId, uint256 amount) external { - _release(nodeOperatorId, amount); - } - - function compensate(uint256 nodeOperatorId, uint256 amount) external { - _compensate(nodeOperatorId, amount); + function reduceAmount(uint256 nodeOperatorId, uint256 amount) external { + _reduceAmount(nodeOperatorId, amount); } - uint256 internal _mockedBondAmountForPenalize; + uint256 internal _mockedUncoveredPenalty; function _penalize( uint256 nodeOperatorId, uint256 amount ) internal override returns (uint256) { - uint256 toPenalize = amount < _mockedBondAmountForPenalize - ? amount - : _mockedBondAmountForPenalize; - emit BondPenalized(nodeOperatorId, amount, toPenalize); - return amount - toPenalize; + emit BondPenalized( + nodeOperatorId, + amount, + amount - _mockedUncoveredPenalty + ); + return _mockedUncoveredPenalty; } - function mock_bondAmount(uint256 amount) external { - _mockedBondAmountForPenalize = amount; + function mock_uncoveredPenalty(uint256 amount) external { + _mockedUncoveredPenalty = amount; } } @@ -88,6 +91,9 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { uint256 retention = 4 weeks; uint256 management = 2 days; + vm.expectEmit(true, true, true, true, address(bondLock)); + emit BondLockPeriodsChanged(retention, management); + bondLock.setBondLockPeriods(retention, management); (uint256 _retention, uint256 _management) = bondLock @@ -97,60 +103,62 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { } function test_setBondLockPeriods_RevertWhen_RetentionLessThanMin() public { - vm.expectRevert(InvalidBondLockRetentionPeriod.selector); + vm.expectRevert(InvalidBondLockPeriods.selector); bondLock.setBondLockPeriods(3 weeks, 1 days); } function test_setBondLockPeriods_RevertWhen_RetentionGreaterThanMax() public { - vm.expectRevert(InvalidBondLockRetentionPeriod.selector); + vm.expectRevert(InvalidBondLockPeriods.selector); bondLock.setBondLockPeriods(366 days, 1 days); } function test_setBondLockPeriods_RevertWhen_ManagementLessThanMin() public { - vm.expectRevert(InvalidBondLockRetentionPeriod.selector); + vm.expectRevert(InvalidBondLockPeriods.selector); bondLock.setBondLockPeriods(8 weeks, 23 hours); } function test_setBondLockPeriods_RevertWhen_ManagementGreaterThanMax() public { - vm.expectRevert(InvalidBondLockRetentionPeriod.selector); + vm.expectRevert(InvalidBondLockPeriods.selector); bondLock.setBondLockPeriods(8 weeks, 8 days); } - function test_get() public { + function test_getActualAmount() public { uint256 noId = 0; uint256 amount = 1 ether; bondLock.lock(noId, amount); - uint256 value = bondLock.get(noId); + uint256 value = bondLock.getActualAmount(noId); assertEq(value, amount); } - function test_get_WhenRetentionPeriodIsPassed() public { + function test_getActualAmount_WhenRetentionPeriodIsPassed() public { uint256 noId = 0; uint256 amount = 1 ether; bondLock.lock(noId, amount); vm.warp(block.timestamp + 8 weeks + 1 seconds); - uint256 value = bondLock.get(noId); + uint256 value = bondLock.getActualAmount(noId); assertEq(value, 0); } function test_lock() public { uint256 noId = 0; uint256 amount = 1 ether; + uint256 retentionUntil = block.timestamp + 8 weeks; vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(noId, amount, block.timestamp + 8 weeks); + emit BondLockChanged(noId, amount, retentionUntil); bondLock.lock(noId, amount); - uint256 value = bondLock.get(noId); - assertEq(value, amount); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, amount); + assertEq(lock.retentionUntil, retentionUntil); } function test_lock_WhenSecondTime() public { @@ -169,8 +177,9 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { ); bondLock.lock(noId, 1.5 ether); - uint256 value = bondLock.get(noId); - assertEq(value, amount + 1.5 ether); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, amount + 1.5 ether); + assertEq(lock.retentionUntil, newBlockTimestamp + 8 weeks); } function test_lock_RevertWhen_ZeroAmount() public { @@ -179,73 +188,56 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { } function test_settle() public { + uint256 noId = 0; uint256[] memory idsToSettle = new uint256[](1); - idsToSettle[0] = 0; + idsToSettle[0] = noId; bondLock.lock(0, 1 ether); - bondLock.mock_bondAmount(1 ether); + bondLock.mock_uncoveredPenalty(0 ether); // more than 1 day (management period) after penalty init // eligible to settle vm.warp(block.timestamp + 1 days + 1 seconds); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondPenalized(0, 1 ether, 1 ether); + emit BondPenalized(noId, 1 ether, 1 ether); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(0, 0, 0); + emit BondLockChanged(noId, 0, 0); bondLock.settle(idsToSettle); - uint256 value = bondLock.get(0); - assertEq(value, 0 ether); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, 0 ether); + assertEq(lock.retentionUntil, 0); } - function test_settle_WhenLockIsLessThanBond() public { - uint256[] memory idsToSettle = new uint256[](1); - idsToSettle[0] = 0; - bondLock.lock(0, 0.7 ether); - bondLock.mock_bondAmount(1 ether); - - // more than 1 day (management period) after penalty init - // eligible to settle - vm.warp(block.timestamp + 1 days + 1 seconds); - - vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondPenalized(0, 0.7 ether, 0.7 ether); - - vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(0, 0, 0); - - bondLock.settle(idsToSettle); - - uint256 value = bondLock.get(0); - assertEq(value, 0); - } - - function test_settle_WhenLockIsGreaterThanBond() public { + function test_settle_WhenUncovered() public { + uint256 noId = 0; uint256[] memory idsToSettle = new uint256[](1); idsToSettle[0] = 0; bondLock.lock(0, 1 ether); uint256 retentionPeriodWhenLock = block.timestamp + 8 weeks; - bondLock.mock_bondAmount(0.7 ether); + bondLock.mock_uncoveredPenalty(0.3 ether); // more than 1 day (management period) after penalty init // eligible to settle vm.warp(block.timestamp + 1 days + 1 seconds); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondPenalized(0, 1 ether, 0.7 ether); + emit BondPenalized(noId, 1 ether, 0.7 ether); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(0, 0.3 ether, retentionPeriodWhenLock); + emit BondLockChanged(noId, 0.3 ether, retentionPeriodWhenLock); bondLock.settle(idsToSettle); - uint256 value = bondLock.get(0); - assertEq(value, 0.3 ether); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, 0.3 ether); + assertEq(lock.retentionUntil, retentionPeriodWhenLock); } function test_settle_WhenRetentionPeriodIsExpired() public { + uint256 noId = 0; uint256[] memory idsToSettle = new uint256[](1); idsToSettle[0] = 0; bondLock.lock(0, 1 ether); @@ -255,14 +247,15 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { vm.warp(block.timestamp + 8 weeks + 1 seconds); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(0, 0, 0); + emit BondLockChanged(noId, 0, 0); vm.recordLogs(); bondLock.settle(idsToSettle); - uint256 value = bondLock.get(0); - assertEq(value, 0 ether); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, 0 ether); + assertEq(lock.retentionUntil, 0); assertEq( vm.getRecordedLogs().length, @@ -272,9 +265,11 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { } function test_settle_WhenInManagementPeriod() public { + uint256 noId = 0; uint256[] memory idsToSettle = new uint256[](1); idsToSettle[0] = 0; bondLock.lock(0, 1 ether); + uint256 retentionPeriodWhenLock = block.timestamp + 8 weeks; // less than 1 day (management period) after penalty init // not eligible to settle yet @@ -284,8 +279,9 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { bondLock.settle(idsToSettle); - uint256 value = bondLock.get(0); - assertEq(value, 1 ether); + CSBondLock.BondLock memory lock = bondLock.get(noId); + assertEq(lock.amount, 1 ether); + assertEq(lock.retentionUntil, retentionPeriodWhenLock); assertEq(vm.getRecordedLogs().length, 0, "should not emit any events"); } @@ -305,12 +301,13 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { // more than 1 day (management period) after penalty init // eligible to settle bondLock.lock(1, 1 ether); - bondLock.mock_bondAmount(1 ether); + bondLock.mock_uncoveredPenalty(0 ether); vm.warp(block.timestamp + 1 days + 1 seconds); // less than 1 day (management period) after penalty init // not eligible to settle yet bondLock.lock(2, 1 ether); + uint256 retentionPeriodWhenLockTheLast = block.timestamp + 8 weeks; vm.expectEmit(true, true, true, true, address(bondLock)); emit BondLockChanged(0, 0, 0); @@ -325,93 +322,69 @@ contract CSBondLockTest is Test, CSBondLockBase, CSBondLockTestableBase { bondLock.settle(idsToSettle); - uint256 value = bondLock.get(0); - assertEq(value, 0 ether); + CSBondLock.BondLock memory lock = bondLock.get(0); + assertEq(lock.amount, 0 ether); + assertEq(lock.retentionUntil, 0); - value = bondLock.get(1); - assertEq(value, 0 ether); + lock = bondLock.get(1); + assertEq(lock.amount, 0 ether); + assertEq(lock.retentionUntil, 0); - value = bondLock.get(2); - assertEq(value, 1 ether); + lock = bondLock.get(2); + assertEq(lock.amount, 1 ether); + assertEq(lock.retentionUntil, retentionPeriodWhenLockTheLast); assertEq(vm.getRecordedLogs().length, 3, "should emit 3 events"); } - function test_release() public { + function test_reduceAmount_WhenFull() public { uint256 noId = 0; uint256 amount = 100 ether; bondLock.lock(noId, amount); - uint256 toRelease = 10 ether; - uint256 rest = amount - toRelease; - - vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockReleased(noId, toRelease); vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(noId, rest, block.timestamp + 8 weeks); + emit BondLockChanged(noId, 0, 0); - bondLock.release(noId, toRelease); + bondLock.reduceAmount(noId, amount); - uint256 value = bondLock.get(noId); - assertEq(value, rest); - - vm.warp(block.timestamp + 8 weeks + 1 seconds); - value = bondLock.get(noId); - assertEq(value, 0); + CSBondLock.BondLock memory lock = bondLock.get(0); + assertEq(lock.amount, 0); + assertEq(lock.retentionUntil, 0); } - function test_release_RevertWhen_ZeroAmount() public { - vm.expectRevert(InvalidBondLockAmount.selector); - bondLock.release(0, 0); - } - - function test_release_RevertWhen_GreaterThanLock() public { - uint256 noId = 0; - uint256 amount = 100 ether; - - bondLock.lock(noId, amount); - - vm.expectRevert(InvalidBondLockAmount.selector); - bondLock.release(noId, amount + 1 ether); - } - - function test_compensate() public { + function test_reduceAmount_WhenPartial() public { uint256 noId = 0; uint256 amount = 100 ether; bondLock.lock(noId, amount); + uint256 retentionPeriodWhenLock = block.timestamp + 8 weeks; - uint256 toCompensate = 10 ether; - uint256 rest = amount - toCompensate; + uint256 toRelease = 10 ether; + uint256 rest = amount - toRelease; vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockCompensated(noId, toCompensate); - vm.expectEmit(true, true, true, true, address(bondLock)); - emit BondLockChanged(noId, rest, block.timestamp + 8 weeks); + emit BondLockChanged(noId, rest, retentionPeriodWhenLock); - bondLock.compensate(noId, toCompensate); + bondLock.reduceAmount(noId, toRelease); - uint256 value = bondLock.get(noId); - assertEq(value, rest); - - vm.warp(block.timestamp + 8 weeks + 1 seconds); - value = bondLock.get(noId); - assertEq(value, 0); + CSBondLock.BondLock memory lock = bondLock.get(0); + assertEq(lock.amount, rest); + assertEq(lock.retentionUntil, retentionPeriodWhenLock); } - function test_compensate_RevertWhen_ZeroAmount() public { + function test_reduceAmount_RevertWhen_ZeroAmount() public { vm.expectRevert(InvalidBondLockAmount.selector); - bondLock.compensate(0, 0); + bondLock.reduceAmount(0, 0); } - function test_compensate_RevertWhen_GreaterThanLock() public { + function test_reduceAmount_RevertWhen_GreaterThanLock() public { uint256 noId = 0; uint256 amount = 100 ether; bondLock.lock(noId, amount); vm.expectRevert(InvalidBondLockAmount.selector); - bondLock.compensate(noId, amount + 1 ether); + bondLock.reduceAmount(noId, amount + 1 ether); } }