Skip to content

Commit

Permalink
[Update] Added erc20penaltyfee and erc721nolockup scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyPoslavskiy committed Jun 24, 2024
1 parent 9c283a6 commit 65aa9ed
Show file tree
Hide file tree
Showing 11 changed files with 529 additions and 15 deletions.
11 changes: 11 additions & 0 deletions contracts/factories/ERC20PenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
)
);
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);
// Transfer reward tokens from the owner to the contract
// slither-disable-next-line arbitrary-send-erc20
IERC20(req.data.rewardToken).safeTransferFrom(
msg.sender,
newPoolAddress,
rewardAmount
);
emit StakingPoolDeployed(newPoolAddress, id);
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/factories/ERC721PenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
/// @title ERC721PenaltyFeeStakingFactory
/// @notice A smart contract for deploying ERC721 staking pools with penalty fees.
/// @author Ayooluwa Akindeko, Soramitsu team
contract ERC20PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
contract ERC721PenaltyFeeStakingFactory is Ownable, IPenaltyFeeFactory {
using SafeERC20 for IERC20;

address[] public stakingPools;
Expand Down
19 changes: 12 additions & 7 deletions contracts/mocks/ERC20MockToken.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
pragma solidity 0.8.25;

import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ERC20MockToken is ERC20 {

contract ERC20MockToken is ERC20, Ownable {
uint8 private immutable _decimals;
constructor(string memory name, string memory symbol, uint8 decimals_) ERC20(name, symbol) {

constructor(
string memory name,
string memory symbol,
uint8 decimals_
) ERC20(name, symbol) Ownable(msg.sender) {
_decimals = decimals_;
}

function mint(address account, uint256 amount) external {
function mint(address account, uint256 amount) external onlyOwner {
_mint(account, amount);
}

function burn(address account, uint256 amount) external {
function burn(address account, uint256 amount) external onlyOwner {
_burn(account, amount);
}

function decimals() public view override returns (uint8) {
return _decimals;
}
}
}
19 changes: 19 additions & 0 deletions contracts/mocks/ERC721MockToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract ERC721MockToken is ERC721, Ownable {
uint256 private _nextTokenId;

constructor(
string memory name,
string memory symbol
) ERC721(name, symbol) Ownable(msg.sender) {}

function safeMint(address to) public onlyOwner {
uint256 tokenId = _nextTokenId++;
_safeMint(to, tokenId);
}
}
2 changes: 1 addition & 1 deletion contracts/pools/ERC20/ERC20LockUpStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ contract ERC20LockUpPool is
// Ensure the start time is in the future
if (poolStartTime < block.timestamp) revert InvalidStartTime();
// Ensure the staking period is valid
if (poolStartTime > poolEndTime) revert InvalidStakingPeriod();
if (poolStartTime >= poolEndTime) revert InvalidStakingPeriod();
// Ensure the LockUp periods are valid
if (unstakeLockUp > poolEndTime || claimLockUp > poolEndTime)
revert InvalidLockUpTime();
Expand Down
4 changes: 2 additions & 2 deletions contracts/pools/ERC20/ERC20PenaltyFeePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ contract ERC20PenaltyFeePool is
// Ensure the start time is in the future
if (poolStartTime < block.timestamp) revert InvalidStartTime();
// Ensure the staking period is valid
if (poolStartTime > poolEndTime) revert InvalidStakingPeriod();
if (poolEndTime - poolStartTime > penaltyPeriod)
if (poolStartTime >= poolEndTime) revert InvalidStakingPeriod();
if (poolStartTime + penaltyPeriod > poolEndTime)
revert InvalidPenaltyPeriod();
if (rewardTokenPerSecond == 0) revert InvalidRewardRate();
pool.stakeToken = stakeToken;
Expand Down
17 changes: 14 additions & 3 deletions contracts/pools/ERC721/ERC721LockUpStakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IPoolERC721} from "../../interfaces/IPools/IERC721Pool.sol";
import {IPoolErrors} from "../../interfaces/IPools/IPoolErrors.sol";
import {ILockUpPoolStorage} from "../../interfaces/IPools/ILockUpPool.sol";

contract ERC721LockUpPool is
ReentrancyGuard,
Ownable,
IERC721Receiver,
IPoolERC721,
ILockUpPoolStorage,
IPoolErrors
Expand All @@ -37,14 +39,14 @@ contract ERC721LockUpPool is
constructor(
address stakeToken,
address rewardToken,
uint256 rewardTokenPerSecond,
uint256 poolStartTime,
uint256 poolEndTime,
uint256 unstakeLockUpTime,
uint256 claimLockUpTime
uint256 claimLockUpTime,
uint256 rewardTokenPerSecond
) Ownable(msg.sender) {
// Ensure the staking period is valid
if (poolStartTime > poolEndTime) revert InvalidStakingPeriod();
if (poolStartTime >= poolEndTime) revert InvalidStakingPeriod();
// Ensure the start time is in the future
if (poolStartTime < block.timestamp) revert InvalidStartTime();
// Ensure the LockUp periods are valid
Expand All @@ -61,6 +63,15 @@ contract ERC721LockUpPool is
pool.lastUpdateTimestamp = pool.startTime;
}

function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}

/**
* @dev See {IERC721BasePool-stake}.
*/
Expand Down
13 changes: 12 additions & 1 deletion contracts/pools/ERC721/ERC721PenaltyFeePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
import {IPoolERC721} from "../../interfaces/IPools/IERC721Pool.sol";
import {IPoolErrors} from "../../interfaces/IPools/IPoolErrors.sol";
import {IPenaltyFeePoolStorage} from "../../interfaces/IPools/IPenaltyFeePool.sol";

contract ERC721PenaltyFeepPool is
ReentrancyGuard,
Ownable,
IERC721Receiver,
IPoolERC721,
IPenaltyFeePoolStorage,
IPoolErrors
Expand Down Expand Up @@ -55,7 +57,7 @@ contract ERC721PenaltyFeepPool is
// Ensure the start time is in the future
if (poolStartTime < block.timestamp) revert InvalidStartTime();
// Ensure the LockUp periods are valid
if (poolEndTime - poolStartTime > penaltyPeriod)
if (poolStartTime + penaltyPeriod > poolEndTime)
revert InvalidPenaltyPeriod();

pool.stakeToken = stakeToken;
Expand All @@ -68,6 +70,15 @@ contract ERC721PenaltyFeepPool is
pool.adminWallet = adminAddress;
}

function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}

/**
* @dev See {IERC721BasePool-stake}.
*/
Expand Down
File renamed without changes.
Loading

0 comments on commit 65aa9ed

Please sign in to comment.