-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from symbioticfi/adapt-core
Add new hooks
- Loading branch information
Showing
35 changed files
with
2,443 additions
and
601 deletions.
There are no files selected for viewing
Submodule core
updated
56 files
Submodule openzeppelin-contracts
updated
469 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Hooks | ||
|
||
### FullRestakeDecreaseHook | ||
|
||
FullRestakeDecreaseHook supports `onSlash()` calls only from `FullRestakeDelegator`. | ||
|
||
This hook decreases the network's limit by the slashed amount and decreases the operator's limit also by the slashed amount. It doesn't change stake amounts for other operators. | ||
|
||
### FullRestakeResetHook | ||
|
||
FullRestakeResetHook supports `onSlash()` calls only from `FullRestakeDelegator`. | ||
|
||
This hook resets the slashed operator's limit to zero in case it was slashed a configured number of times during a configured period of time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Hooks | ||
|
||
### NetworkRestakeDecreaseHook | ||
|
||
NetworkRestakeDecreaseHook supports `onSlash()` calls only from `NetworkRestakeDelegator`. | ||
|
||
This hook decreases the network's limit by the slashed amount and decreases the slashed operator's shares in such a way as to decrease his stake (which depends on the network's limit) by the slashed amount. It doesn't change stake amounts for other operators. | ||
|
||
### NetworkRestakeRedistributeHook | ||
|
||
NetworkRestakeRedistributeHook supports `onSlash()` calls only from `NetworkRestakeDelegator`. | ||
|
||
This hook decreases the slashed operator's shares by slashed percent from the given stake, redistributing the decreased stake to other operators. | ||
|
||
### NetworkRestakeResetHook | ||
|
||
NetworkRestakeResetHook supports `onSlash()` calls only from `NetworkRestakeDelegator`. | ||
|
||
This hook resets the slashed operator's shares to zero in case it was slashed a configured number of times during a configured period of time. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
## Hooks | ||
|
||
### OperatorSpecificDecreaseHook | ||
|
||
OperatorSpecificDecreaseHook supports `onSlash()` calls only from `OperatorSpecificDelegator`. | ||
|
||
This hook decreases the network's limit by the slashed amount. | ||
|
||
### OperatorSpecificResetHook | ||
|
||
OperatorSpecificResetHook supports `onSlash()` calls only from `OperatorSpecificDelegator`. | ||
|
||
This hook resets the slashing network's limit to zero in case it was slashed a configured number of times during a configured period of time. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
src/contracts/fullRestakeDelegator/FullRestakeDecreaseHook.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IFullRestakeDecreaseHook} from "../../interfaces/fullRestakeDelegator/IFullRestakeDecreaseHook.sol"; | ||
|
||
import {IDelegatorHook} from "@symbioticfi/core/src/interfaces/delegator/IDelegatorHook.sol"; | ||
import {IEntity} from "@symbioticfi/core/src/interfaces/common/IEntity.sol"; | ||
import {IFullRestakeDelegator} from "@symbioticfi/core/src/interfaces/delegator/IFullRestakeDelegator.sol"; | ||
|
||
import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; | ||
|
||
contract FullRestakeDecreaseHook is IFullRestakeDecreaseHook { | ||
using Math for uint256; | ||
|
||
/** | ||
* @inheritdoc IDelegatorHook | ||
*/ | ||
function onSlash( | ||
bytes32 subnetwork, | ||
address operator, | ||
uint256 slashedAmount, | ||
uint48, /* captureTimestamp */ | ||
bytes calldata /* data */ | ||
) external { | ||
if (IEntity(msg.sender).TYPE() != 1) { | ||
revert NotFullRestakeDelegator(); | ||
} | ||
|
||
if (slashedAmount == 0) { | ||
return; | ||
} | ||
|
||
uint256 networkLimit = IFullRestakeDelegator(msg.sender).networkLimit(subnetwork); | ||
if (networkLimit != 0) { | ||
IFullRestakeDelegator(msg.sender).setNetworkLimit( | ||
subnetwork, networkLimit - Math.min(slashedAmount, networkLimit) | ||
); | ||
} | ||
|
||
uint256 operatorNetworkLimit = IFullRestakeDelegator(msg.sender).operatorNetworkLimit(subnetwork, operator); | ||
if (operatorNetworkLimit != 0) { | ||
IFullRestakeDelegator(msg.sender).setOperatorNetworkLimit( | ||
subnetwork, operator, operatorNetworkLimit - Math.min(slashedAmount, operatorNetworkLimit) | ||
); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/contracts/fullRestakeDelegator/FullRestakeResetHook.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IFullRestakeResetHook} from "../../interfaces/fullRestakeDelegator/IFullRestakeResetHook.sol"; | ||
|
||
import {IDelegatorHook} from "@symbioticfi/core/src/interfaces/delegator/IDelegatorHook.sol"; | ||
import {IEntity} from "@symbioticfi/core/src/interfaces/common/IEntity.sol"; | ||
import {IFullRestakeDelegator} from "@symbioticfi/core/src/interfaces/delegator/IFullRestakeDelegator.sol"; | ||
import {IVault} from "@symbioticfi/core/src/interfaces/vault/IVault.sol"; | ||
|
||
import {CircularBuffer} from "@openzeppelin/contracts/utils/structs/CircularBuffer.sol"; | ||
import {Time} from "@openzeppelin/contracts/utils/types/Time.sol"; | ||
|
||
contract FullRestakeResetHook is IFullRestakeResetHook { | ||
using CircularBuffer for CircularBuffer.Bytes32CircularBuffer; | ||
|
||
/** | ||
* @inheritdoc IFullRestakeResetHook | ||
*/ | ||
uint48 public immutable PERIOD; | ||
|
||
/** | ||
* @inheritdoc IFullRestakeResetHook | ||
*/ | ||
uint256 public immutable SLASH_COUNT; | ||
|
||
mapping(address vault => mapping(address operator => CircularBuffer.Bytes32CircularBuffer buffer)) private | ||
_slashings; | ||
|
||
constructor(uint48 period_, uint256 slashCount_) { | ||
if (slashCount_ == 0) { | ||
revert InvalidSlashCount(); | ||
} | ||
|
||
PERIOD = period_; | ||
SLASH_COUNT = slashCount_; | ||
} | ||
|
||
/** | ||
* @inheritdoc IDelegatorHook | ||
*/ | ||
function onSlash( | ||
bytes32 subnetwork, | ||
address operator, | ||
uint256, /* slashedAmount */ | ||
uint48, /* captureTimestamp */ | ||
bytes calldata /* data */ | ||
) external { | ||
if (IEntity(msg.sender).TYPE() != 1) { | ||
revert NotFullRestakeDelegator(); | ||
} | ||
|
||
address vault = IFullRestakeDelegator(msg.sender).vault(); | ||
|
||
if (IVault(vault).delegator() != msg.sender) { | ||
revert NotVaultDelegator(); | ||
} | ||
|
||
uint256 slashCount_ = SLASH_COUNT; | ||
if (_slashings[vault][operator].count() == 0) { | ||
_slashings[vault][operator].setup(slashCount_); | ||
} | ||
|
||
if (IFullRestakeDelegator(msg.sender).operatorNetworkLimit(subnetwork, operator) == 0) { | ||
return; | ||
} | ||
|
||
_slashings[vault][operator].push(bytes32(uint256(Time.timestamp()))); | ||
|
||
if ( | ||
_slashings[vault][operator].count() == slashCount_ | ||
&& Time.timestamp() - uint256(_slashings[vault][operator].last(slashCount_ - 1)) <= PERIOD | ||
) { | ||
IFullRestakeDelegator(msg.sender).setOperatorNetworkLimit(subnetwork, operator, 0); | ||
} | ||
} | ||
} |
Oops, something went wrong.