-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/refactor #44
Feature/refactor #44
Changes from all commits
0d765be
0feb41c
1fd3ab2
6d94e11
ada8318
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
ERC20LockUpFactory | ||
SPDX-License-Identifier: MIT | ||
*/ | ||
|
||
pragma solidity 0.8.25; | ||
|
||
import {IRequestManager} from "./interfaces/IRequestManager.sol"; | ||
import {IBaseFactory} from "./interfaces/IFactories/IBaseFactory.sol"; | ||
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
/// @title RequestManager | ||
contract RequestManager is Ownable, IRequestManager { | ||
using SafeERC20 for IERC20; | ||
|
||
address[] public stakingPools; | ||
Request[] public requests; | ||
mapping(address factory => bool whitelisted) public whitelistFactory; | ||
mapping(uint256 id => address pool) public poolById; | ||
|
||
constructor() Ownable(msg.sender) {} | ||
|
||
function addFactory(address factory) onlyOwner external { | ||
if (factory == address(0)) revert InvalidAddress(); | ||
whitelistFactory[factory] = true; | ||
emit FactoryRegistered(factory); | ||
} | ||
|
||
function removeFactory(address factory) onlyOwner external { | ||
if (whitelistFactory[factory] != true) revert UnregisteredFactory(); | ||
whitelistFactory[factory] = false; | ||
emit FactoryUnregistered(factory); | ||
} | ||
|
||
/// @notice Function allows users to deploy the staking pool with specified parameters | ||
function deploy(uint256 id) external returns (address newPoolAddress) { | ||
if (requests.length <= id) revert InvalidId(); | ||
Request memory req = requests[id]; | ||
if (req.requestStatus != Status.APPROVED) revert InvalidRequestStatus(); | ||
if (msg.sender != req.data.deployer) revert InvalidCaller(); | ||
requests[id].requestStatus = Status.DEPLOYED; | ||
newPoolAddress = IBaseFactory(req.data.factory).deploy( | ||
req.data.deployer, | ||
req.data.stakingData | ||
); | ||
stakingPools.push(newPoolAddress); | ||
poolById[id] = newPoolAddress; | ||
emit RequestFullfilled(id, newPoolAddress); | ||
} | ||
|
||
function requestDeployment(RequestPayload calldata data) external { | ||
if (data.deployer == address(0) || data.factory == address(0)) | ||
revert InvalidAddress(); | ||
if (data.ipfsHash == bytes32(0)) revert InvalidIpfsHash(); | ||
if (data.stakingData.length == 0) revert InvalidPayload(); | ||
if (whitelistFactory[data.factory] != true) | ||
revert UnregisteredFactory(); | ||
requests.push(Request({requestStatus: Status.CREATED, data: data})); | ||
emit RequestSubmitted( | ||
requests.length - 1, | ||
data | ||
); | ||
} | ||
Comment on lines
+53
to
+65
Check warning Code scanning / Slither Boolean equality Warning
RequestManager.requestDeployment(IRequestManager.RequestPayload) compares to a boolean constant:
-whitelistFactory[data.factory] != true |
||
|
||
function approveRequest(uint256 id) external onlyOwner { | ||
if (requests.length <= id) revert InvalidId(); | ||
Request storage req = requests[id]; | ||
if (req.requestStatus != Status.CREATED) revert InvalidRequestStatus(); | ||
req.requestStatus = Status.APPROVED; | ||
emit RequestStatusChanged(id, req.requestStatus); | ||
} | ||
|
||
function denyRequest(uint256 id) external onlyOwner { | ||
if (requests.length <= id) revert InvalidId(); | ||
Request storage req = requests[id]; | ||
if (req.requestStatus != Status.CREATED) revert InvalidRequestStatus(); | ||
req.requestStatus = Status.DENIED; | ||
emit RequestStatusChanged(id, req.requestStatus); | ||
} | ||
|
||
function cancelRequest(uint256 id) external { | ||
if (requests.length <= id) revert InvalidId(); | ||
Request storage req = requests[id]; | ||
if (msg.sender != req.data.deployer) revert InvalidCaller(); | ||
if ( | ||
req.requestStatus != Status.CREATED && | ||
req.requestStatus != Status.APPROVED | ||
) revert InvalidRequestStatus(); | ||
req.requestStatus = Status.CANCELED; | ||
emit RequestStatusChanged(id, req.requestStatus); | ||
} | ||
|
||
function getRequests() external view returns (Request[] memory reqs) { | ||
reqs = requests; | ||
} | ||
|
||
function getPools() external view returns (address[] memory pools) { | ||
pools = stakingPools; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,114 +12,54 @@ | |
|
||
/// @title ERC20LockUpStakingFactory | ||
/// @notice A smart contract for deploying ERC20 LockUp staking pools. | ||
/// @author Ayooluwa Akindeko, Soramitsu team | ||
contract ERC20LockUpStakingFactory is Ownable, ILockUpFactory { | ||
using SafeERC20 for IERC20; | ||
|
||
address public requestManager; | ||
Check warning Code scanning / Slither State variables that could be declared immutable Warning
ERC20LockUpStakingFactory.requestManager should be immutable
|
||
address[] public stakingPools; | ||
LockUpRequest[] public requests; | ||
mapping(uint256 id => address pool) public poolById; | ||
|
||
constructor() Ownable(msg.sender) {} | ||
constructor(address managerContract) Ownable(msg.sender) { | ||
if (managerContract == address(0)) revert InvalidManagerAddress(); | ||
requestManager = managerContract; | ||
} | ||
|
||
/// @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(); | ||
LockUpRequest memory req = requests[id]; | ||
if (req.info.requestStatus != Status.APPROVED) | ||
revert InvalidRequestStatus(); | ||
if (msg.sender != req.info.deployer) revert InvalidCaller(); | ||
function deploy(address deployer, bytes calldata payload) external returns (address newPoolAddress) { | ||
if (payload.length != 224) revert InvalidPayloadLength(); | ||
if (msg.sender != requestManager) revert InvalidCaller(); | ||
DeploymentData memory data = abi.decode(payload, (DeploymentData)); | ||
newPoolAddress = address( | ||
new ERC20LockUpPool{ | ||
salt: keccak256( | ||
abi.encode( | ||
req.data.stakeToken, | ||
req.data.rewardToken, | ||
req.data.rewardPerSecond, | ||
req.data.poolStartTime, | ||
req.data.poolEndTime | ||
data.stakeToken, | ||
data.rewardToken, | ||
data.rewardPerSecond, | ||
data.poolStartTime, | ||
data.poolEndTime | ||
) | ||
) | ||
}( | ||
req.data.stakeToken, | ||
req.data.rewardToken, | ||
req.data.poolStartTime, | ||
req.data.poolEndTime, | ||
req.data.rewardPerSecond, | ||
req.data.unstakeLockUpTime, | ||
req.data.claimLockUpTime | ||
data.stakeToken, | ||
data.rewardToken, | ||
data.poolStartTime, | ||
data.poolEndTime, | ||
data.rewardPerSecond, | ||
data.unstakeLockUpTime, | ||
data.claimLockUpTime | ||
) | ||
); | ||
stakingPools.push(newPoolAddress); | ||
requests[id].info.requestStatus = Status.DEPLOYED; | ||
poolById[id] = newPoolAddress; | ||
uint256 rewardAmount = (req.data.poolEndTime - req.data.poolStartTime) * | ||
req.data.rewardPerSecond; | ||
ERC20LockUpPool(newPoolAddress).transferOwnership(msg.sender); | ||
uint256 rewardAmount = (data.poolEndTime - data.poolStartTime) * | ||
data.rewardPerSecond; | ||
ERC20LockUpPool(newPoolAddress).transferOwnership(deployer); | ||
// Transfer reward tokens from the owner to the contract | ||
// slither-disable-next-line arbitrary-send-erc20 | ||
IERC20(req.data.rewardToken).safeTransferFrom( | ||
msg.sender, | ||
IERC20(data.rewardToken).safeTransferFrom( | ||
deployer, | ||
newPoolAddress, | ||
rewardAmount | ||
); | ||
emit StakingPoolDeployed(newPoolAddress, id); | ||
} | ||
|
||
function requestDeployment( | ||
bytes32 ipfsHash, | ||
DeploymentData calldata data | ||
) external { | ||
if (data.stakeToken == address(0) || data.rewardToken == address(0)) | ||
revert InvalidTokenAddress(); | ||
requests.push( | ||
LockUpRequest({ | ||
info: RequestInfo({ | ||
ipfsHash: ipfsHash, | ||
deployer: msg.sender, | ||
requestStatus: Status.CREATED | ||
}), | ||
data: data | ||
}) | ||
); | ||
emit RequestSubmitted( | ||
requests.length - 1, | ||
msg.sender, | ||
Status.CREATED, | ||
data | ||
); | ||
} | ||
|
||
function approveRequest(uint256 id) external onlyOwner { | ||
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(); | ||
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(); | ||
LockUpRequest storage req = requests[id]; | ||
if (msg.sender != req.info.deployer) revert InvalidCaller(); | ||
if ( | ||
req.info.requestStatus != Status.CREATED && | ||
req.info.requestStatus != Status.APPROVED | ||
) revert InvalidRequestStatus(); | ||
req.info.requestStatus = Status.CANCELED; | ||
emit RequestStatusChanged(id, req.info.requestStatus); | ||
} | ||
|
||
function getRequests() external view returns (LockUpRequest[] memory reqs) { | ||
reqs = requests; | ||
emit StakingPoolDeployed(newPoolAddress); | ||
} | ||
|
||
function getPools() external view returns (address[] memory pools) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,107 +15,52 @@ | |
/// @author Ayooluwa Akindeko, Soramitsu team | ||
contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory { | ||
using SafeERC20 for IERC20; | ||
|
||
address public requestManager; | ||
Check warning Code scanning / Slither State variables that could be declared immutable Warning
ERC20PenaltyFeeStakingFactory.requestManager should be immutable
|
||
address[] public stakingPools; | ||
PenaltyFeeRequest[] public requests; | ||
mapping(uint256 id => address pool) public poolById; | ||
|
||
constructor() Ownable(msg.sender) {} | ||
constructor(address managerContract) Ownable(msg.sender) { | ||
if (managerContract == address(0)) revert InvalidManagerAddress(); | ||
requestManager = managerContract; | ||
} | ||
|
||
/// @notice Function allows users to deploy the penaltyFee staking pool with specified parameters | ||
function deploy(uint256 id) public returns (address newPoolAddress) { | ||
if (requests.length < id) revert InvalidId(); | ||
PenaltyFeeRequest memory req = requests[id]; | ||
if (req.info.requestStatus != Status.APPROVED) revert InvalidRequestStatus(); | ||
if (msg.sender != req.info.deployer) revert InvalidCaller(); | ||
function deploy(address deployer, bytes calldata payload) external returns (address newPoolAddress) { | ||
if (payload.length != 192) revert InvalidPayloadLength(); | ||
if (msg.sender != requestManager) revert InvalidCaller(); | ||
DeploymentData memory data = abi.decode(payload, (DeploymentData)); | ||
newPoolAddress = address( | ||
new ERC20PenaltyFeePool{ | ||
salt: keccak256( | ||
abi.encode( | ||
req.data.stakeToken, | ||
req.data.rewardToken, | ||
req.data.rewardPerSecond, | ||
req.data.poolStartTime, | ||
req.data.poolEndTime | ||
data.stakeToken, | ||
data.rewardToken, | ||
data.rewardPerSecond, | ||
data.poolStartTime, | ||
data.poolEndTime | ||
) | ||
) | ||
}( | ||
req.data.stakeToken, | ||
req.data.rewardToken, | ||
req.data.poolStartTime, | ||
req.data.poolEndTime, | ||
req.data.rewardPerSecond, | ||
req.data.penaltyPeriod, | ||
data.stakeToken, | ||
data.rewardToken, | ||
data.poolStartTime, | ||
data.poolEndTime, | ||
data.rewardPerSecond, | ||
data.penaltyPeriod, | ||
owner() | ||
) | ||
); | ||
stakingPools.push(newPoolAddress); | ||
requests[id].info.requestStatus = Status.DEPLOYED; | ||
poolById[id] = newPoolAddress; | ||
uint256 rewardAmount = (req.data.poolEndTime - req.data.poolStartTime) * | ||
req.data.rewardPerSecond; | ||
ERC20PenaltyFeePool(newPoolAddress).transferOwnership(msg.sender); | ||
uint256 rewardAmount = (data.poolEndTime - data.poolStartTime) * | ||
data.rewardPerSecond; | ||
ERC20PenaltyFeePool(newPoolAddress).transferOwnership(deployer); | ||
// Transfer reward tokens from the owner to the contract | ||
// slither-disable-next-line arbitrary-send-erc20 | ||
IERC20(req.data.rewardToken).safeTransferFrom( | ||
msg.sender, | ||
IERC20(data.rewardToken).safeTransferFrom( | ||
deployer, | ||
newPoolAddress, | ||
rewardAmount | ||
); | ||
emit StakingPoolDeployed(newPoolAddress, id); | ||
} | ||
|
||
function requestDeployment(bytes32 ipfsHash, DeploymentData calldata data) external { | ||
if (data.stakeToken == address(0) || data.rewardToken == address(0)) | ||
revert InvalidTokenAddress(); | ||
requests.push( | ||
PenaltyFeeRequest({ | ||
info: RequestInfo({ | ||
ipfsHash: ipfsHash, | ||
deployer: msg.sender, | ||
requestStatus: Status.CREATED | ||
}), | ||
data: data | ||
}) | ||
); | ||
emit RequestSubmitted( | ||
requests.length - 1, | ||
msg.sender, | ||
Status.CREATED, | ||
data | ||
); | ||
} | ||
|
||
function approveRequest(uint256 id) external onlyOwner { | ||
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(); | ||
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(); | ||
PenaltyFeeRequest storage req = requests[id]; | ||
if (msg.sender != req.info.deployer) revert InvalidCaller(); | ||
if ( | ||
req.info.requestStatus != Status.CREATED || | ||
req.info.requestStatus != Status.APPROVED | ||
) revert InvalidRequestStatus(); | ||
req.info.requestStatus = Status.CANCELED; | ||
emit RequestStatusChanged(id, req.info.requestStatus); | ||
} | ||
|
||
function getRequests() external view returns (PenaltyFeeRequest[] memory reqs) { | ||
reqs = requests; | ||
emit StakingPoolDeployed(newPoolAddress); | ||
} | ||
|
||
function getPools() external view returns (address[] memory pools) { | ||
|
Check warning
Code scanning / Slither
Boolean equality Warning