Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move staking to metis #127

Merged
merged 6 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 4 additions & 20 deletions contracts/core/StakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -374,35 +374,19 @@ contract StakingPool is StakingRewardsPool {
}

/**
* @notice Returns the amount of rewards earned since the last call to updateStrategyRewards and the
* amount of fees that will be paid on the rewards
* @param _strategyIdxs indexes of strategies to sum rewards/fees for
* @notice Returns the amount of rewards earned since the last call to updateStrategyRewards
* @param _strategyIdxs indexes of strategies to sum rewards for
* @return total rewards
* @return total fees
**/
function getStrategyRewards(
uint256[] calldata _strategyIdxs
) external view returns (int256, uint256) {
function getStrategyRewards(uint256[] calldata _strategyIdxs) external view returns (int256) {
int256 totalRewards;
uint256 totalFees;

for (uint256 i = 0; i < _strategyIdxs.length; i++) {
IStrategy strategy = IStrategy(strategies[_strategyIdxs[i]]);
totalRewards += strategy.getDepositChange();
totalFees += strategy.getPendingFees();
}

if (totalRewards > 0) {
for (uint256 i = 0; i < fees.length; i++) {
totalFees += (uint256(totalRewards) * fees[i].basisPoints) / 10000;
}
}

if (totalFees >= totalStaked) {
totalFees = 0;
}

return (totalRewards, totalFees);
return totalRewards;
}

/**
Expand Down
8 changes: 0 additions & 8 deletions contracts/core/base/Strategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ abstract contract Strategy is IStrategy, Initializable, UUPSUpgradeable, Ownable
}
}

/**
* @notice returns the total amount of fees that will be paid on the next update
* @return total fees
*/
function getPendingFees() external view virtual returns (uint256) {
return 0;
}

/**
* @notice returns the total amount of deposits in this strategy
* @return total deposits
Expand Down
86 changes: 86 additions & 0 deletions contracts/core/ccip/base/CCIPReceiverUpgradeable.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

import {IAny2EVMMessageReceiver} from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IAny2EVMMessageReceiver.sol";
import {Client} from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/// @title CCIPReceiver - Base contract for CCIP applications that can receive messages.
/// @dev copied from https://github.com/smartcontractkit and modified to be upgradeable and make i_router settable
abstract contract CCIPReceiverUpgradeable is
IAny2EVMMessageReceiver,
IERC165,
Initializable,
UUPSUpgradeable,
OwnableUpgradeable
{
address internal i_router;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function __CCIPReceiverUpgradeable_init(address _router) public onlyInitializing {
__UUPSUpgradeable_init();
__Ownable_init();

if (_router == address(0)) revert InvalidRouter(address(0));
i_router = _router;
}

/// @notice IERC165 supports an interfaceId
/// @param _interfaceId The interfaceId to check
/// @return true if the interfaceId is supported
/// @dev Should indicate whether the contract implements IAny2EVMMessageReceiver
/// e.g. return interfaceId == type(IAny2EVMMessageReceiver).interfaceId || interfaceId == type(IERC165).interfaceId
/// This allows CCIP to check if ccipReceive is available before calling it.
/// If this returns false or reverts, only tokens are transferred to the receiver.
/// If this returns true, tokens are transferred and ccipReceive is called atomically.
/// Additionally, if the receiver address does not have code associated with
/// it at the time of execution (EXTCODESIZE returns 0), only tokens will be transferred.
function supportsInterface(bytes4 _interfaceId) public pure virtual override returns (bool) {
return
_interfaceId == type(IAny2EVMMessageReceiver).interfaceId ||
_interfaceId == type(IERC165).interfaceId;
}

/// @inheritdoc IAny2EVMMessageReceiver
function ccipReceive(
Client.Any2EVMMessage calldata _message
) external virtual override onlyRouter {
_ccipReceive(_message);
}

/// @notice Override this function in your implementation.
/// @param _message Any2EVMMessage
function _ccipReceive(Client.Any2EVMMessage memory _message) internal virtual;

/////////////////////////////////////////////////////////////////////
// Plumbing
/////////////////////////////////////////////////////////////////////

/// @notice Return the current router
/// @return i_router address
function getRouter() public view returns (address) {
return address(i_router);
}

/// @notice Sets the router
/// @param _router router address
function setRouter(address _router) external virtual onlyOwner {
if (_router == address(0)) revert InvalidRouter(address(0));
i_router = _router;
}

error InvalidRouter(address router);

/// @dev only calls from the set router are accepted.
modifier onlyRouter() {
if (msg.sender != address(i_router)) revert InvalidRouter(msg.sender);
_;
}
}
2 changes: 0 additions & 2 deletions contracts/core/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ interface IStrategy {
function canWithdraw() external view returns (uint256);

function getDepositChange() external view returns (int256);

function getPendingFees() external view returns (uint256);
}
21 changes: 0 additions & 21 deletions contracts/linkStaking/OperatorVCS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,6 @@ contract OperatorVCS is VaultControllerStrategy {
return amountToWithdraw;
}

/**
* @notice Returns the total amount of fees that will be paid on the next call to updateDeposits()
* @return total fees
*/
function getPendingFees() external view override returns (uint256) {
uint256 totalFees;

uint256 vaultCount = vaults.length;
for (uint256 i = 0; i < vaultCount; ++i) {
totalFees += IOperatorVault(address(vaults[i])).getPendingRewards();
}

int256 depositChange = getDepositChange();
if (depositChange > 0) {
for (uint256 i = 0; i < fees.length; ++i) {
totalFees += (uint256(depositChange) * fees[i].basisPoints) / 10000;
}
}
return totalFees;
}

/**
* @notice Updates deposit accounting and calculates fees on newly earned rewards
* @param _data encoded minRewards (uint256) - min amount of rewards required to claim (set 0 to skip reward claiming)
Expand Down
17 changes: 0 additions & 17 deletions contracts/linkStaking/base/VaultControllerStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -499,23 +499,6 @@ abstract contract VaultControllerStrategy is Strategy {
return int(totalBalance) - int(totalDeposits);
}

/**
* @notice Returns the total amount of fees that will be paid on the next call to updateDeposits()
* @dev fees are only paid when the depositChange since the last update is positive
* @return total fees
*/
function getPendingFees() external view virtual override returns (uint256) {
int256 depositChange = getDepositChange();
uint256 totalFees;

if (depositChange > 0) {
for (uint256 i = 0; i < fees.length; ++i) {
totalFees += (uint256(depositChange) * fees[i].basisPoints) / 10000;
}
}
return totalFees;
}

/**
* @notice Updates deposit accounting and calculates fees on newly earned rewards
* @return depositChange change in deposits since last update
Expand Down
Loading
Loading