Skip to content

Commit

Permalink
metis staking fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BkChoy committed Apr 12, 2024
1 parent 4a6789a commit 41238dc
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 103 deletions.
6 changes: 3 additions & 3 deletions contracts/core/StakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract StakingPool is StakingRewardsPool {
for (uint256 i = 0; i < _fees.length; i++) {
fees.push(_fees[i]);
}
require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
require(_totalFeesBasisPoints() <= 4000, "Total fees must be <= 40%");
}

modifier onlyPriorityPool() {
Expand Down Expand Up @@ -282,7 +282,7 @@ contract StakingPool is StakingRewardsPool {
**/
function addFee(address _receiver, uint256 _feeBasisPoints) external onlyOwner {
fees.push(Fee(_receiver, _feeBasisPoints));
require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
require(_totalFeesBasisPoints() <= 4000, "Total fees must be <= 40%");
}

/**
Expand All @@ -306,7 +306,7 @@ contract StakingPool is StakingRewardsPool {
fees[_index].basisPoints = _feeBasisPoints;
}

require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
require(_totalFeesBasisPoints() <= 4000, "Total fees must be <= 40%");
}

/**
Expand Down
16 changes: 16 additions & 0 deletions contracts/core/ccip/WrappedTokenBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,22 @@ contract WrappedTokenBridge is CCIPReceiver {
}
}

/**
* @notice Sets the CCIP router
* @param _router router address
**/
function setRouter(address _router) external override onlyOwner {
if (_router == address(0)) revert InvalidRouter(address(0));

address curRouter = getRouter();
linkToken.approve(curRouter, 0);
wrappedToken.approve(curRouter, 0);

linkToken.approve(_router, type(uint256).max);
wrappedToken.approve(_router, type(uint256).max);
i_router = _router;
}

/**
* @notice Wraps and transfers tokens to a destination chain
* @param _destinationChainSelector id of destination chain
Expand Down
2 changes: 1 addition & 1 deletion contracts/core/ccip/base/CCIPReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ abstract contract CCIPReceiver is IAny2EVMMessageReceiver, IERC165, Ownable {

/// @notice Sets the router
/// @param _router router address
function setRouter(address _router) external onlyOwner {
function setRouter(address _router) external virtual onlyOwner {
if (_router == address(0)) revert InvalidRouter(address(0));
i_router = _router;
}
Expand Down
16 changes: 16 additions & 0 deletions contracts/core/ccip/base/SDLPoolCCIPController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ abstract contract SDLPoolCCIPController is CCIPReceiver {
reSDLTokenBridge = _reSDLTokenBridge;
}

/**
* @notice Sets the CCIP router
* @param _router router address
**/
function setRouter(address _router) external override onlyOwner {
if (_router == address(0)) revert InvalidRouter(address(0));

address curRouter = getRouter();
linkToken.approve(curRouter, 0);
sdlToken.approve(curRouter, 0);

linkToken.approve(_router, type(uint256).max);
sdlToken.approve(_router, type(uint256).max);
i_router = _router;
}

/**
* @notice Verifies the sender of a CCIP message is whitelisted
* @param _message CCIP message
Expand Down
14 changes: 0 additions & 14 deletions contracts/linkStaking/OperatorVCS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,4 @@ contract OperatorVCS is VaultControllerStrategy {
function togglePreRelease() external onlyOwner {
preRelease = !preRelease;
}

/**
* @notice updates rewards for all strategies controlled by the staking pool
* @dev called before operatorRewardPercentage is changed to
* credit any past rewards at the old rate
*/
function _updateStrategyRewards() 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, "");
}
}
63 changes: 30 additions & 33 deletions contracts/linkStaking/base/VaultControllerStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ abstract contract VaultControllerStrategy is Strategy {

uint256[9] private __gap;

event UpgradedVaults(uint256 startIndex, uint256 numVaults, bytes data);
event UpgradedVaults(uint256[] vaults);
event SetMaxDepositSizeBP(uint256 maxDepositSizeBP);
event SetVaultImplementation(address vaultImplementation);

error FeesTooLarge();
error InvalidBasisPoints();

/**
Expand Down Expand Up @@ -71,7 +72,7 @@ abstract contract VaultControllerStrategy is Strategy {
for (uint256 i = 0; i < _fees.length; ++i) {
fees.push(_fees[i]);
}
require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
if (_totalFeesBasisPoints() > 3000) revert FeesTooLarge();

if (_maxDepositSizeBP > 10000) revert InvalidBasisPoints();
maxDepositSizeBP = _maxDepositSizeBP;
Expand Down Expand Up @@ -234,21 +235,19 @@ abstract contract VaultControllerStrategy is Strategy {
}

/**
* @notice upgrades vaults to a new implementation contract
* @dev reverts if sender is not owner
* @param _startIndex index of first vault to upgrade
* @param _numVaults number of vaults to upgrade starting at _startIndex
* @param _data optional encoded function call to be executed after upgrade
* @notice Upgrades vaults to a new implementation contract
* @param _vaults list of vault indexes to upgrade
* @param _data list of encoded function calls to be executed for each vault after upgrade
*/
function upgradeVaults(
uint256 _startIndex,
uint256 _numVaults,
bytes memory _data
) external onlyOwner {
for (uint256 i = _startIndex; i < _startIndex + _numVaults; ++i) {
_upgradeVault(i, _data);
function upgradeVaults(uint256[] calldata _vaults, bytes[] memory _data) external onlyOwner {
for (uint256 i = 0; i < _vaults.length; ++i) {
if (_data[i].length == 0) {
vaults[_vaults[i]].upgradeTo(vaultImplementation);
} else {
vaults[_vaults[i]].upgradeToAndCall(vaultImplementation, _data[i]);
}
}
emit UpgradedVaults(_startIndex, _numVaults, _data);
emit UpgradedVaults(_vaults);
}

/**
Expand All @@ -261,22 +260,21 @@ abstract contract VaultControllerStrategy is Strategy {

/**
* @notice adds a new fee
* @dev
* - reverts if sender is not owner
* - reverts if total fees exceed 50%
* @dev stakingPool.updateStrategyRewards is called to credit all past fees at
* the old rate before the percentage changes
* @param _receiver receiver of fee
* @param _feeBasisPoints fee in basis points
**/
function addFee(address _receiver, uint256 _feeBasisPoints) external onlyOwner {
_updateStrategyRewards();
fees.push(Fee(_receiver, _feeBasisPoints));
require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
if (_totalFeesBasisPoints() > 3000) revert FeesTooLarge();
}

/**
* @notice updates an existing fee
* @dev
* - reverts if sender is not owner
* - reverts if total fees exceed 50%
* @dev stakingPool.updateStrategyRewards is called to credit all past fees at
* the old rate before the percentage changes
* @param _index index of fee
* @param _receiver receiver of fee
* @param _feeBasisPoints fee in basis points
Expand All @@ -286,7 +284,7 @@ abstract contract VaultControllerStrategy is Strategy {
address _receiver,
uint256 _feeBasisPoints
) external onlyOwner {
require(_index < fees.length, "Fee does not exist");
_updateStrategyRewards();

if (_feeBasisPoints == 0) {
fees[_index] = fees[fees.length - 1];
Expand All @@ -296,7 +294,7 @@ abstract contract VaultControllerStrategy is Strategy {
fees[_index].basisPoints = _feeBasisPoints;
}

require(_totalFeesBasisPoints() <= 5000, "Total fees must be <= 50%");
if (_totalFeesBasisPoints() > 3000) revert FeesTooLarge();
}

/**
Expand Down Expand Up @@ -372,17 +370,16 @@ abstract contract VaultControllerStrategy is Strategy {
}

/**
* @notice upgrades a vault controlled by this strategy
* @param _vaultIdx index of vault to upgrade
* @param _data optional encoded function call to be executed after upgrade
* @notice Updates rewards for all strategies controlled by the staking pool
* @dev called before fees are changed to credit any past rewards at the old rate
*/
function _upgradeVault(uint256 _vaultIdx, bytes memory _data) internal {
IVault vault = vaults[_vaultIdx];
if (_data.length == 0) {
vault.upgradeTo(vaultImplementation);
} else {
vault.upgradeToAndCall(vaultImplementation, _data);
function _updateStrategyRewards() internal {
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, "");
}

/**
Expand Down
Loading

0 comments on commit 41238dc

Please sign in to comment.