Verified contractExactGPL-3.0
RebaseController
Address0x1711e93eec78ba83d38c26f0ff284eb478bdbec4
- Balance
0 ETH
- Transactions
234
- Compiler
solc 0.8.15
- Same code
Only this contract
Details
- Compiler
- solc 0.8.15+commit.e14f2714
- Language
- solidity
- Optimization
- Yes, 115 runs
- License
- GPL-3.0
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 21,789,082
- Creation transaction
- 0x949b5dade6…2de37277bc
10 files
- contracts/core/RebaseController.solmain6.06 KB
- @openzeppelin/contracts/access/Ownable.sol2.62 KB
- @openzeppelin/contracts/token/ERC20/IERC20.sol2.74 KB
- @openzeppelin/contracts/utils/Context.sol962 B
- contracts/core/interfaces/IERC677.sol294 B
- contracts/core/interfaces/IPriorityPool.sol1.83 KB
- contracts/core/interfaces/ISecurityPool.sol229 B
- contracts/core/interfaces/IStakingPool.sol1.47 KB
- contracts/core/interfaces/IStakingRewardsPool.sol1.08 KB
- contracts/core/interfaces/IStrategy.sol767 B
contracts/core/RebaseController.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
import "@openzeppelin/contracts/access/Ownable.sol";
import "./interfaces/IStakingPool.sol";
import "./interfaces/IPriorityPool.sol";
import "./interfaces/IStrategy.sol";
import "./interfaces/ISecurityPool.sol";
/**
* @title Rebase Controller
* @notice Updates strategy rewards in the Staking Pool and and performs emergency pausing/reopening of the pool
*/
contract RebaseController is Ownable {
// address of staking pool
IStakingPool public stakingPool;
// address of priority pool
IPriorityPool public priorityPool;
// address of security pool
ISecurityPool public securityPool;
// address authorized to pause pool in case of emergency
address public emergencyPauser;
// address authorized to update rewards
address public rewardsUpdater;
error PoolClosed();
error PoolOpen();
error SenderNotAuthorized();
error NoLossDetected();
/**
* @notice Initializes contract
* @param _stakingPool address of staking pool
* @param _priorityPool address of priority pool
* @param _securityPool address of security pool
* @param _emergencyPauser address authorized to pause pool in case of emergency
* @param _rewardsUpdater address authorized to update rewards
*/
constructor(
address _stakingPool,
address _priorityPool,
address _securityPool,
address _emergencyPauser,
address _rewardsUpdater
) {
stakingPool = IStakingPool(_stakingPool);
priorityPool = IPriorityPool(_priorityPool);
securityPool = ISecurityPool(_securityPool);
emergencyPauser = _emergencyPauser;
rewardsUpdater = _rewardsUpdater;
}
/**
* @notice Reverts if sender is not emergency pauser
*/
modifier onlyEmergencyPauser() {
if (msg.sender != emergencyPauser) revert SenderNotAuthorized();
_;
}
/**
* @notice Reverts if sender is not rewards updater
*/
modifier onlyRewardsUpdater() {
if (msg.sender != rewardsUpdater) revert SenderNotAuthorized();
_;
}
/**
* @notice Updates strategy rewards in the staking pool
* @param _data encoded data to pass to strategies
**/
function updateRewards(bytes calldata _data) external onlyRewardsUpdater {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.CLOSED) revert PoolClosed();
_updateRewards(_data);
}
/**
* @notice Returns whether a loss has been detected in a strategy
* @return upkeepNeeded whether or not loss has been detected
* @return performData abi encoded index of strategy with a loss
**/
function checkUpkeep(bytes calldata) external view returns (bool, bytes memory) {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.CLOSED) return (false, "");
address[] memory strategies = stakingPool.getStrategies();
for (uint256 i = 0; i < strategies.length; ++i) {
int256 depositChange = IStrategy(strategies[i]).getDepositChange();
if (depositChange < 0) {
return (true, abi.encode(i));
}
}
return (false, "");
}
/**
* @notice Pauses the priority pool if a loss has been detected
* @param _performData abi encoded index of strategy with a loss
*/
function performUpkeep(bytes calldata _performData) external {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.CLOSED) revert PoolClosed();
uint256 strategyIdxWithLoss = abi.decode(_performData, (uint256));
address[] memory strategies = stakingPool.getStrategies();
if (IStrategy(strategies[strategyIdxWithLoss]).getDepositChange() >= 0)
revert NoLossDetected();
priorityPool.setPoolStatus(IPriorityPool.PoolStatus.CLOSED);
if (address(securityPool) != address(0)) securityPool.initiateClaim();
}
/**
* @notice Pauses the priority pool in the case of an emergency
*/
function pausePool() external onlyEmergencyPauser {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.CLOSED) revert PoolClosed();
priorityPool.setPoolStatus(IPriorityPool.PoolStatus.CLOSED);
if (address(securityPool) != address(0)) securityPool.initiateClaim();
}
/**
* @notice Reopens the priority pool and security pool after they were paused as a result
* of a loss and updates strategy rewards in the staking pool
* @param _data encoded data to pass to strategies
*/
function reopenPool(bytes calldata _data) external onlyOwner {
if (priorityPool.poolStatus() == IPriorityPool.PoolStatus.OPEN) revert PoolOpen();
priorityPool.setPoolStatus(IPriorityPool.PoolStatus.OPEN);
if (address(securityPool) != address(0) && securityPool.claimInProgress()) {
securityPool.resolveClaim();
}
_updateRewards(_data);
}
/**
* @notice Sets the address authorized to pause the pool in the case of emergency
* @param _emergencyPauser address of emergency pauser
*/
function setEmergencyPauser(address _emergencyPauser) external onlyOwner {
emergencyPauser = _emergencyPauser;
}
/**
* @notice Sets the address authorized to update rewards
* @param _rewardsUpdater address of rewards updater
*/
function setRewardsUpdater(address _rewardsUpdater) external onlyOwner {
rewardsUpdater = _rewardsUpdater;
}
/**
* @notice Updates strategy rewards in the staking pool
* @param _data encoded data to pass to strategies
**/
function _updateRewards(bytes memory _data) private {
address[] memory strategies = stakingPool.getStrategies();
uint256[] memory strategyIdxs = new uint256[](strategies.length);
for (uint256 i = 0; i < strategies.length; ++i) {
strategyIdxs[i] = i;
}
stakingPool.updateStrategyRewards(strategyIdxs, _data);
}
}
@openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
contracts/core/interfaces/IERC677.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IERC677 is IERC20 {
function transferAndCall(
address _to,
uint256 _value,
bytes calldata _data
) external returns (bool success);
}
contracts/core/interfaces/IPriorityPool.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
interface IPriorityPool {
enum PoolStatus {
OPEN,
DRAINING,
CLOSED
}
function paused() external view returns (bool);
function depositsSinceLastUpdate() external view returns (uint256);
function poolStatus() external view returns (PoolStatus);
function ipfsHash() external view returns (bytes32);
function canWithdraw(
address _account,
uint256 _distributionAmount
) external view returns (uint256);
function getQueuedTokens(
address _account,
uint256 _distributionAmount
) external view returns (uint256);
function getLSDTokens(
address _account,
uint256 _distributionShareAmount
) external view returns (uint256);
function deposit(uint256 _amount, bool _shouldQueue, bytes[] calldata _data) external;
function withdraw(
uint256 _amountToWithdraw,
uint256 _amount,
uint256 _sharesAmount,
bytes32[] calldata _merkleProof,
bool _shouldUnqueue,
bool _shouldQueueWithdrawal,
bytes[] calldata _data
) external;
function claimLSDTokens(
uint256 _amount,
uint256 _sharesAmount,
bytes32[] calldata _merkleProof
) external;
function pauseForUpdate() external;
function setPoolStatus(PoolStatus _status) external;
function updateDistribution(
bytes32 _merkleRoot,
bytes32 _ipfsHash,
uint256 _amountDistributed,
uint256 _sharesAmountDistributed
) external;
function executeQueuedWithdrawals(uint256 _amount, bytes[] calldata _data) external;
function checkUpkeep(bytes calldata) external view returns (bool, bytes memory);
function performUpkeep(bytes calldata _performData) external;
}
contracts/core/interfaces/ISecurityPool.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
interface ISecurityPool {
function claimInProgress() external view returns (bool);
function initiateClaim() external;
function resolveClaim() external;
}
contracts/core/interfaces/IStakingPool.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
import "./IStakingRewardsPool.sol";
interface IStakingPool is IStakingRewardsPool {
function deposit(address _account, uint256 _amount, bytes[] calldata _data) external;
function withdraw(
address _account,
address _receiver,
uint256 _amount,
bytes[] calldata _data
) external;
function strategyDeposit(uint256 _index, uint256 _amount, bytes calldata _data) external;
function strategyWithdraw(uint256 _index, uint256 _amount, bytes calldata _data) external;
function updateStrategyRewards(uint256[] memory _strategyIdxs, bytes memory _data) external;
function getMaxDeposits() external view returns (uint256);
function addStrategy(address _strategy) external;
function removeStrategy(uint256 _index) external;
function reorderStrategies(uint256[] calldata _newOrder) external;
function getStrategies() external view returns (address[] memory);
function setPoolIndex(uint16 _poolIndex) external;
function canDeposit() external view returns (uint256);
function token() external view returns (address);
function poolIndex() external view returns (uint16);
function canWithdraw() external view returns (uint256);
function getStrategyDepositRoom() external view returns (uint256);
function getUnusedDeposits() external view returns (uint256);
function burn(uint256 _amount) external;
}
contracts/core/interfaces/IStakingRewardsPool.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
import "./IERC677.sol";
interface IStakingRewardsPool is IERC677 {
/**
* @notice returns an account's share balance
* @param _account account to return balance for
* @return account's share balance
**/
function sharesOf(address _account) external view returns (uint256);
/**
* @notice returns the amount of shares that corresponds to a staked amount
* @param _amount staked amount
* @return amount of shares
**/
function getSharesByStake(uint256 _amount) external view returns (uint256);
/**
* @notice returns the amount of stake that corresponds to an amount of shares
* @param _amount shares amount
* @return amount of stake
**/
function getStakeByShares(uint256 _amount) external view returns (uint256);
function totalShares() external view returns (uint256);
function totalSupply() external view returns (uint256);
function transferShares(address _recipient, uint256 _sharesAmount) external returns (bool);
}
contracts/core/interfaces/IStrategy.sol
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.15;
interface IStrategy {
function deposit(uint256 _amount, bytes calldata _data) external;
function withdraw(uint256 _amount, bytes calldata _data) external;
function updateDeposits(
bytes calldata _data
) external returns (int256 depositChange, address[] memory receivers, uint256[] memory amounts);
function getTotalDeposits() external view returns (uint256);
function getMaxDeposits() external view returns (uint256);
function getMinDeposits() external view returns (uint256);
function canDeposit() external view returns (uint256);
function canWithdraw() external view returns (uint256);
function getDepositChange() external view returns (int256);
}
Compiler settingsShow
{
"libraries": {},
"optimizer": {
"runs": 115,
"enabled": true
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.