Skip to content

Commit

Permalink
[Update] Minor refactoring, added test scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyPoslavskiy committed Jun 20, 2024
1 parent cbeae50 commit 6f57271
Show file tree
Hide file tree
Showing 18 changed files with 576 additions and 300 deletions.
11 changes: 5 additions & 6 deletions contracts/factories/ERC20LockUpFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT
*/

pragma solidity 0.8.25;
import {ERC20LockUpPool} from "../pools/ERC20LockUpStakingPool.sol";
import {ERC20LockUpPool} from "../pools/ERC20/ERC20LockUpStakingPool.sol";
import {ILockUpFactory} from "../interfaces/IFactories/ILockUpFactory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -24,7 +24,7 @@ contract ERC20LockUpStakingFactory is Ownable, ILockUpFactory {

/// @notice Function allows users to deploy the LockUp staking pool with specified parameters
function deploy(uint256 id) public returns (address newPoolAddress) {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest memory req = requests[id];
if (req.info.requestStatus != Status.APPROVED)
revert InvalidRequestStatus();
Expand Down Expand Up @@ -72,7 +72,6 @@ contract ERC20LockUpStakingFactory is Ownable, ILockUpFactory {
) external {
if (data.stakeToken == address(0) || data.rewardToken == address(0))
revert InvalidTokenAddress();
if (data.rewardPerSecond == 0) revert InvalidRewardRate();
requests.push(
LockUpRequest({
info: RequestInfo({
Expand All @@ -92,23 +91,23 @@ contract ERC20LockUpStakingFactory is Ownable, ILockUpFactory {
}

function approveRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function denyRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.DENIED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function cancelRequest(uint256 id) external {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (msg.sender != req.info.deployer) revert InvalidCaller();
if (
Expand Down
9 changes: 4 additions & 5 deletions contracts/factories/ERC20PenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT
*/

pragma solidity 0.8.25;
import {ERC20PenaltyFeePool} from "../pools/ERC20PenaltyFeePool.sol";
import {ERC20PenaltyFeePool} from "../pools/ERC20/ERC20PenaltyFeePool.sol";
import {IPenaltyFeeFactory} from "../interfaces/IFactories/IPenaltyFeeFactory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand Down Expand Up @@ -57,7 +57,6 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
function requestDeployment(bytes32 ipfsHash, DeploymentData calldata data) external {
if (data.stakeToken == address(0) || data.rewardToken == address(0))
revert InvalidTokenAddress();
if (data.rewardPerSecond == 0) revert InvalidRewardRate();
requests.push(
PenaltyFeeRequest({
info: RequestInfo({
Expand All @@ -77,23 +76,23 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
}

function approveRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function denyRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.DENIED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function cancelRequest(uint256 id) external {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (msg.sender != req.info.deployer) revert InvalidCaller();
if (
Expand Down
7 changes: 3 additions & 4 deletions contracts/factories/ERC721LockUpFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ contract ERC721LockUpStakingFactory is Ownable, ILockUpFactory {
) external {
if (data.stakeToken == address(0) || data.rewardToken == address(0))
revert InvalidTokenAddress();
if (data.rewardPerSecond == 0) revert InvalidRewardRate();
requests.push(
LockUpRequest({
info: RequestInfo({
Expand All @@ -92,23 +91,23 @@ contract ERC721LockUpStakingFactory is Ownable, ILockUpFactory {
}

function approveRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function denyRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.DENIED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function cancelRequest(uint256 id) external {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
LockUpRequest storage req = requests[id];
if (msg.sender != req.info.deployer) revert InvalidCaller();
if (
Expand Down
13 changes: 6 additions & 7 deletions contracts/factories/ERC721PenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SPDX-License-Identifier: MIT
*/

pragma solidity 0.8.25;
import {draftERC721PenaltyFeepPool} from "../pools/ERC721/ERC721PenaltyFeePool.sol";
import {ERC721PenaltyFeepPool} from "../pools/ERC721/ERC721PenaltyFeePool.sol";
import {IPenaltyFeeFactory} from "../interfaces/IFactories/IPenaltyFeeFactory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -29,7 +29,7 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
if (req.info.requestStatus != Status.APPROVED) revert InvalidRequestStatus();
if (msg.sender != req.info.deployer) revert InvalidCaller();
newPoolAddress = address(
new draftERC721PenaltyFeepPool{
new ERC721PenaltyFeepPool{
salt: keccak256(
abi.encode(
req.data.stakeToken,
Expand All @@ -50,14 +50,13 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
)
);
stakingPools.push(newPoolAddress);
draftERC721PenaltyFeepPool(newPoolAddress).transferOwnership(msg.sender);
ERC721PenaltyFeepPool(newPoolAddress).transferOwnership(msg.sender);
emit StakingPoolDeployed(newPoolAddress, id);
}

function requestDeployment(bytes32 ipfsHash, DeploymentData calldata data) external {
if (data.stakeToken == address(0) || data.rewardToken == address(0))
revert InvalidTokenAddress();
if (data.rewardPerSecond == 0) revert InvalidRewardRate();
requests.push(
PenaltyFeeRequest({
info: RequestInfo({
Expand All @@ -77,23 +76,23 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
}

function approveRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function denyRequest(uint256 id) external onlyOwner {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (req.info.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.info.requestStatus = Status.DENIED;
emit RequestStatusChanged(id, req.info.requestStatus);
}

function cancelRequest(uint256 id) external {
if (requests.length < id) revert InvalidId();
if (requests.length <= id) revert InvalidId();
PenaltyFeeRequest storage req = requests[id];
if (msg.sender != req.info.deployer) revert InvalidCaller();
if (
Expand Down
10 changes: 6 additions & 4 deletions contracts/interfaces/IFactories/IBaseFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ interface IBaseFactory {
error InvalidRequestStatus();
error InvalidCaller();
error InvalidTokenAddress();
error InvalidRewardRate();

event StakingPoolDeployed(address indexed stakingAddress, uint256 indexed id);

event StakingPoolDeployed(
address indexed stakingAddress,
uint256 indexed id
);
event RequestStatusChanged(uint256 indexed id, Status indexed status);
}
}
8 changes: 6 additions & 2 deletions contracts/interfaces/IFactories/ILockUpFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.25;
import {IBaseFactory} from "./IBaseFactory.sol";

interface ILockUpFactory is IBaseFactory {

struct DeploymentData {
address stakeToken;
address rewardToken;
Expand All @@ -19,5 +18,10 @@ interface ILockUpFactory is IBaseFactory {
DeploymentData data;
}

event RequestSubmitted(uint256 indexed id, address indexed deployer, Status indexed status, DeploymentData data);
event RequestSubmitted(
uint256 indexed id,
address indexed deployer,
Status indexed status,
DeploymentData data
);
}
10 changes: 7 additions & 3 deletions contracts/interfaces/IFactories/IPenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity 0.8.25;
import {IBaseFactory} from "./IBaseFactory.sol";

interface IPenaltyFeeFactory is IBaseFactory {

struct DeploymentData {
address stakeToken;
address rewardToken;
Expand All @@ -18,5 +17,10 @@ interface IPenaltyFeeFactory is IBaseFactory {
DeploymentData data;
}

event RequestSubmitted(uint256 indexed id, address indexed deployer, Status indexed status, DeploymentData data);
}
event RequestSubmitted(
uint256 indexed id,
address indexed deployer,
Status indexed status,
DeploymentData data
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,6 @@
pragma solidity 0.8.25;

interface IPoolERC20 {
/**
* ERROR MESSAGES
*/
/// @dev Error to indicate an invalid staking period
error InvalidStakingPeriod();

/// @dev Error to indicate an invalid start time for the staking pool
error InvalidStartTime();

/// @dev Error to indicate an invalid input amount for the staking and unstaking operations in the pool
error InvalidAmount();

/// @dev Error to indicate insufficient amount of tokens
/// @param reqAmount The amount of tokens that is required
/// @param currentAmount The current amount of tokens
error InsufficientAmount(uint256 reqAmount, uint256 currentAmount);

/// @dev Error to indicate that the user has no available rewards to claim
error NothingToClaim();

/// @dev Error to indicate that the staking pool has not started yet
error PoolNotStarted();

/// @dev Error to indicate that the staking pool has already ended
error PoolHasEnded();

/**
* EVENTS
*/
Expand Down Expand Up @@ -55,11 +29,7 @@ interface IPoolERC20 {
* @param amount The amount of rewards claimed
* @param penaltyAmount The amount deducted as penalty fee
*/
event Claim(
address indexed user,
uint256 amount,
uint256 penaltyAmount
);
event Claim(address indexed user, uint256 amount, uint256 penaltyAmount);

/**
* @notice Event to notify when the staking pool is updated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,56 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IPoolERC721 {
/**
* ERROR MESSAGES
*/

/**
* @dev Error to indicate an invalid staking period
*/
error InvalidStakingPeriod();

/**
* @dev Error to indicate an invalid start time for the staking pool
*/
error InvalidStartTime();

/**
* @notice Error emitted when attempting to stake zero tokens.
*/
error InvalidAmount();

/**
* @dev Error to indicate insufficient amount of tokens
* @param reqAmount The amount of tokens that is required
* @param currentAmount The current amount of tokens
*/
error InsufficientAmount(uint256 reqAmount, uint256 currentAmount);

/**
* @notice Error emitted when a user other than the owner of a token attempts to unstake it.
*/
error NotStaker();

/**
* @notice Error emitted when attempting to claim rewards but there are none available.
*/
error NothingToClaim();

/**
* @notice Error emitted when attempting an operation before the pool has started.
*/
error PoolNotStarted();

/**
* @notice Error emitted when attempting an operation after the pool has ended.
*/
error PoolHasEnded();

// **Events**
/**
* @notice Event emitted when tokens are staked into the pool.
Expand All @@ -72,11 +23,7 @@ interface IPoolERC721 {
* @param pending The amount of rewards claimed.
* @param penaltyAmount The amount deducted as penalty fee
*/
event Claim(
address indexed user,
uint256 pending,
uint256 penaltyAmount
);
event Claim(address indexed user, uint256 pending, uint256 penaltyAmount);

/**
* @notice Event emitted when the pool parameters are updated
Expand Down
Loading

0 comments on commit 6f57271

Please sign in to comment.