Skip to content

Commit

Permalink
Merge pull request #17 from soramitsu/feature/erc721lockupstakingpool
Browse files Browse the repository at this point in the history
[Feature] Init ERC721 pools
  • Loading branch information
SergeyPoslavskiy authored May 14, 2024
2 parents 8c631f6 + 0f489a1 commit 3057de7
Show file tree
Hide file tree
Showing 27 changed files with 1,967 additions and 1,431 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/codespell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Codespell checkup

on:
push:
branches: [ develop ]
pull_request:
branches: [ master, develop ]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Run CodeSpell
uses: codespell-project/[email protected]
with:
check_filenames: true
skip: package-lock.json,*.pdf
8 changes: 7 additions & 1 deletion .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read
security-events: write
steps:
- name: Checkout repository
Expand All @@ -25,4 +26,9 @@ jobs:
fail-on: high
sarif: results.sarif
slither-config: slither.config.json
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/
slither-args: --checklist --markdown-root ${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.slither.outputs.sarif }}
6 changes: 4 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set .env
run: cp .env.example .env

Expand All @@ -24,4 +24,6 @@ jobs:
with:
node-version: ${{ matrix.node-version }}
- run: npm ci
- run: npm run test
- run: npm run test
- name: Markdown report
run: cat "./test/gasReport.md" > $GITHUB_STEP_SUMMARY
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules
/cache
/artifacts
/ignition/deployments
/test/gasReport.md

# TypeChain files
/typechain
Expand Down
16 changes: 8 additions & 8 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 {ERC20LockUpStakingPool} from "../pools/ERC20LockUpStakingPool.sol";
import {ERC20LockupPool} from "../pools/ERC20LockUpStakingPool.sol";
import {IERC20LockUpFactory} from "../interfaces/IERC20Factories/IERC20LockUpFactory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -26,10 +26,10 @@ contract ERC20LockUpStakingFactory is Ownable, IERC20LockUpFactory {
function deploy(uint256 id) public returns (address newPoolAddress) {
if (requests.length < id) revert InvalidId();
Request memory req = requests[id];
if (req.requestStatus != Status.APROVED) revert InvalidRequestStatus();
if (req.requestStatus != Status.APPROVED) revert InvalidRequestStatus();
if (msg.sender != req.deployer) revert InvalidCaller();
newPoolAddress = address(
new ERC20LockUpStakingPool{
new ERC20LockupPool{
salt: keccak256(
abi.encode(
req.data.stakeToken,
Expand All @@ -42,19 +42,19 @@ contract ERC20LockUpStakingFactory is Ownable, IERC20LockUpFactory {
}(
req.data.stakeToken,
req.data.rewardToken,
req.data.rewardPerSecond,
req.data.poolStartTime,
req.data.poolEndTime,
req.data.unstakeLockupTime,
req.data.claimLockupTime
req.data.claimLockupTime,
req.data.rewardPerSecond
)
);
stakingPools.push(newPoolAddress);
requests[id].requestStatus = Status.DEPLOYED;
poolById[id] = newPoolAddress;
uint256 rewardAmount = (req.data.poolEndTime - req.data.poolStartTime) *
req.data.rewardPerSecond;
ERC20LockUpStakingPool(newPoolAddress).transferOwnership(msg.sender);
ERC20LockupPool(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(
Expand Down Expand Up @@ -88,7 +88,7 @@ contract ERC20LockUpStakingFactory is Ownable, IERC20LockUpFactory {
if (requests.length < id) revert InvalidId();
Request storage req = requests[id];
if (req.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.requestStatus = Status.APROVED;
req.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.requestStatus);
}

Expand All @@ -106,7 +106,7 @@ contract ERC20LockUpStakingFactory is Ownable, IERC20LockUpFactory {
if (msg.sender != req.deployer) revert InvalidCaller();
if (
req.requestStatus != Status.CREATED &&
req.requestStatus != Status.APROVED
req.requestStatus != Status.APPROVED
) revert InvalidRequestStatus();
req.requestStatus = Status.CANCELED;
emit RequestStatusChanged(id, req.requestStatus);
Expand Down
12 changes: 6 additions & 6 deletions contracts/factories/ERC20NoLockUpFactory.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 {ERC20NoLockUpStakingPool} from "../pools/ERC20NoLockUpStakingPool.sol";
import {ERC20NoLockUpPool} from "../pools/ERC20NoLockUpStakingPool.sol";
import {IERC20NoLockupFactory} from "../interfaces/IERC20Factories/IERC20NoLockupFactory.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
Expand All @@ -26,10 +26,10 @@ contract ERC20NoLockUpStakingFactory is Ownable, IERC20NoLockupFactory {
function deploy(uint256 id) public returns (address newPoolAddress) {
if (requests.length < id) revert InvalidId();
Request memory req = requests[id];
if (req.requestStatus != Status.APROVED) revert InvalidRequestStatus();
if (req.requestStatus != Status.APPROVED) revert InvalidRequestStatus();
if (msg.sender != req.deployer) revert InvalidCaller();
newPoolAddress = address(
new ERC20NoLockUpStakingPool{
new ERC20NoLockUpPool{
salt: keccak256(
abi.encode(
req.data.stakeToken,
Expand All @@ -52,7 +52,7 @@ contract ERC20NoLockUpStakingFactory is Ownable, IERC20NoLockupFactory {
poolById[id] = newPoolAddress;
uint256 rewardAmount = (req.data.poolEndTime - req.data.poolStartTime) *
req.data.rewardPerSecond;
ERC20NoLockUpStakingPool(newPoolAddress).transferOwnership(msg.sender);
ERC20NoLockUpPool(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(
Expand Down Expand Up @@ -86,7 +86,7 @@ contract ERC20NoLockUpStakingFactory is Ownable, IERC20NoLockupFactory {
if (requests.length < id) revert InvalidId();
Request storage req = requests[id];
if (req.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.requestStatus = Status.APROVED;
req.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.requestStatus);
}

Expand All @@ -104,7 +104,7 @@ contract ERC20NoLockUpStakingFactory is Ownable, IERC20NoLockupFactory {
if (msg.sender != req.deployer) revert InvalidCaller();
if (
req.requestStatus != Status.CREATED ||
req.requestStatus != Status.APROVED
req.requestStatus != Status.APPROVED
) revert InvalidRequestStatus();
req.requestStatus = Status.CANCELED;
emit RequestStatusChanged(id, req.requestStatus);
Expand Down
6 changes: 3 additions & 3 deletions contracts/factories/ERC20PenaltyFeeFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IERC20PenaltyFeeFactory {
function deploy(uint256 id) public returns (address newPoolAddress) {
if (requests.length < id) revert InvalidId();
Request memory req = requests[id];
if (req.requestStatus != Status.APROVED) revert InvalidRequestStatus();
if (req.requestStatus != Status.APPROVED) revert InvalidRequestStatus();
if (msg.sender != req.deployer) revert InvalidCaller();
newPoolAddress = address(
new ERC20PenaltyFeePool{
Expand Down Expand Up @@ -77,7 +77,7 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IERC20PenaltyFeeFactory {
if (requests.length < id) revert InvalidId();
Request storage req = requests[id];
if (req.requestStatus != Status.CREATED) revert InvalidRequestStatus();
req.requestStatus = Status.APROVED;
req.requestStatus = Status.APPROVED;
emit RequestStatusChanged(id, req.requestStatus);
}

Expand All @@ -95,7 +95,7 @@ contract ERC20PenaltyFeeStakingFactory is Ownable, IERC20PenaltyFeeFactory {
if (msg.sender != req.deployer) revert InvalidCaller();
if (
req.requestStatus != Status.CREATED ||
req.requestStatus != Status.APROVED
req.requestStatus != Status.APPROVED
) revert InvalidRequestStatus();
req.requestStatus = Status.CANCELED;
emit RequestStatusChanged(id, req.requestStatus);
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC20Factories/IERC20BaseFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ interface IERC20BaseFactory {
UNKNOWN,
CREATED,
DENIED,
APROVED,
APPROVED,
DEPLOYED,
CANCELED
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ interface IERC20LockUpFactory is IERC20BaseFactory {
struct DeploymentData {
address stakeToken;
address rewardToken;
uint256 rewardPerSecond;
uint256 poolStartTime;
uint256 poolEndTime;
uint256 unstakeLockupTime; // Lockup period for unstaking
uint256 claimLockupTime; // Lockup period for claiming rewards
uint256 rewardPerSecond;
}

struct Request {
Expand Down
11 changes: 7 additions & 4 deletions contracts/interfaces/IERC20Pools/IERC20BasePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,40 @@ interface IBasePoolERC20 {
/// @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
*/

/**
* @notice Event to notify when a user stakes tokens
* @dev Emmited in 'stake' function
* @dev Emitted in 'stake' function
* @param user The address of the user who stakes tokens
* @param amount The amount of tokens staked
*/
event Stake(address indexed user, uint256 amount);

/**
* @notice Event to notify when a user unstakes tokens
* @dev Emmited in 'unstake' function
* @dev Emitted in 'unstake' function
* @param user The address of the user who unstakes tokens
* @param amount The amount of tokens unstaked
*/
event Unstake(address indexed user, uint256 amount);

/**
* @notice Event to notify when a user claims rewards
* @dev Emmited in 'claim' function
* @dev Emitted in 'claim' function
* @param user The address of the user who claims rewards
* @param amount The amount of rewards claimed
*/
event Claim(address indexed user, uint256 amount);

/**
* @notice Event to notify when the staking pool is updated
* @dev Emmited in '_updatePool' function
* @dev Emitted in '_updatePool' function
* @param totalStaked The total amount of tokens staked in the pool
* @param accumulatedRewardTokenPerShare The accumulated rewards per share
* @param lastBlockTimestamp The timestamp of the last block with any user operation
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC20Pools/IERC20LockUpPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface IERC20LockupPool is IBasePoolERC20 {
uint256 rewardTokenPerSecond; // Rate of rewards per second
uint256 totalStaked; // Total amount of tokens staked
uint256 totalClaimed; // Total amount of claimed rewards
uint256 lastRewardTimestamp; // Timestamp of the last reward update
uint256 lastUpdateTimestamp; // Timestamp of the last reward update
uint256 accRewardPerShare; // Accumulated rewards per share
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC20Pools/IERC20NoLockupPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface IERC20NoLockupPool is IBasePoolERC20 {
uint256 rewardTokenPerSecond; // Rate of rewards per second
uint256 totalStaked; // Total amount of tokens staked
uint256 totalClaimed; // Total amount of claimed rewards
uint256 lastRewardTimestamp; // Timestamp of the last reward update
uint256 lastUpdateTimestamp; // Timestamp of the last reward update
uint256 accRewardPerShare; // Accumulated rewards per share
}
}
4 changes: 2 additions & 2 deletions contracts/interfaces/IERC20Pools/IERC20PenaltyPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface IERC20PenaltyPool is IBasePoolERC20 {
uint256 totalStaked; // Total amount of tokens staked
uint256 totalClaimed; // Total amount of claimed rewards
uint256 totalPenalties;
uint256 lastRewardTimestamp; // Timestamp of the last reward update
uint256 lastUpdateTimestamp; // Timestamp of the last reward update
uint256 accRewardPerShare; // Accumulated rewards per share
address adminWallet; // Address of the admin
}
Expand Down Expand Up @@ -45,7 +45,7 @@ interface IERC20PenaltyPool is IBasePoolERC20 {

/**
* @notice Event to notify when an admin claims accumulated fees
* @dev Emmited in 'claim' function
* @dev Emitted in 'claim' function
* @param amount The amount of fees claimed
*/
event FeeClaim(uint256 amount);
Expand Down
Loading

0 comments on commit 3057de7

Please sign in to comment.