Skip to content

Commit

Permalink
Restrict payable functions set for admin functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Aug 22, 2023
1 parent 73be288 commit e56cbf8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
18 changes: 15 additions & 3 deletions contracts/ethereum/src/v1/CasimirManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@ contract CasimirManager is ICasimirManager, Ownable, ReentrancyGuard {
}

/**
* @notice Deposit a given amount of rewards
* @notice Deposit a given amount of rewards from a pool
* @param poolId The pool ID
*/
function depositRewards() external payable {
function depositRewards(uint32 poolId) external payable {
require(msg.value > 0, "No rewards to deposit");
address poolAddress = poolAddresses[poolId];
require(msg.sender == poolAddress, "Not pool");

uint256 rewardsAfterFees = subtractFees(msg.value);
reservedFeeBalance += msg.value - rewardsAfterFees;
distributeStake(rewardsAfterFees);
Expand Down Expand Up @@ -766,8 +771,15 @@ contract CasimirManager is ICasimirManager, Ownable, ReentrancyGuard {

while (count > 0) {
count--;

uint32 poolId = pendingPoolIds[0];
ICasimirPool pool = ICasimirPool(poolAddresses[poolId]);
ICasimirPool.PoolDetails memory poolDetails = pool.getDetails();
require(
poolDetails.status == ICasimirPool.PoolStatus.PENDING,
"Pool not pending"
);

pool.setStatus(ICasimirPool.PoolStatus.ACTIVE);
pendingPoolIds.remove(0);
stakedPoolIds.push(poolId);

Expand Down
6 changes: 4 additions & 2 deletions contracts/ethereum/src/v1/CasimirPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ contract CasimirPool is ICasimirPool, Ownable, ReentrancyGuard {
* @notice Deposit rewards from a pool to the manager
*/
function depositRewards() external onlyOwner {
require(status == PoolStatus.ACTIVE, "Pool must be active");

uint256 balance = address(this).balance;
manager.depositRewards{value: balance}();
manager.depositRewards{value: balance}(id);
}

/**
Expand All @@ -83,7 +85,7 @@ contract CasimirPool is ICasimirPool, Ownable, ReentrancyGuard {
uint256 balance = address(this).balance;
int256 rewards = int256(balance) - int256(POOL_CAPACITY);
if (rewards > 0) {
manager.depositRewards{value: uint256(rewards)}();
manager.depositRewards{value: uint256(rewards)}(id);
}
for (uint256 i = 0; i < blamePercents.length; i++) {
uint256 blameAmount;
Expand Down
2 changes: 1 addition & 1 deletion contracts/ethereum/src/v1/interfaces/ICasimirManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ interface ICasimirManager {
/*************/

function depositStake() external payable;
function depositRewards() external payable;
function depositRewards(uint32 poolId) external payable;
function depositExitedBalance(uint32 poolId) external payable;
function depositRecoveredBalance(uint32 poolId) external payable;
function depositReservedFees() external payable;
Expand Down

0 comments on commit e56cbf8

Please sign in to comment.