Skip to content
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] Init ERC721 pool #17

Merged
merged 14 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}
2 changes: 1 addition & 1 deletion .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 Down
109 changes: 109 additions & 0 deletions contracts/interfaces/IERC721/IERC721BasePool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// 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 IERC721BasePool {
/**
* 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();

/**
* @notice Error emitted when attempting to unstake more tokens than the user has staked.
*/
error NotEnoughTokens();

/**
* @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 while pool is not active.
*/
error PoolNotActive();
/**
* @notice Error emitted when attempting an operation while pool is not active.
*/
error NotAdmin();

// **Events**

/**
* @notice Event emitted when tokens are staked into the pool.
* @param user The address of the user who staked the tokens.
* @param tokenIds The IDs of the staked tokens.
*/
event Stake(address indexed user, uint256[] indexed tokenIds);

/**
* @notice Event emitted when tokens are unstaked from the pool.
* @param user The address of the user who unstaked the tokens.
* @param tokenIds The IDs of the unstaked tokens.
*/
event Unstake(address indexed user, uint256[] indexed tokenIds);

/**
* @notice Event emitted when a user claims their rewards.
* @param user The address of the user who claimed the rewards.
* @param pending The amount of rewards claimed.
*/
event Claim(address indexed user, uint256 pending);

/**
* @notice Event emitted when the pool parameters are updated
* @param totalStaked Total number of tokens staked in the pool.
* @param accumulatedRewardTokenPerShare Accumulated reward tokens per staked share.
* @param lastBlockNumber Block number where the update happened.
*/
event UpdatePool(
uint256 indexed totalStaked,
uint256 indexed accumulatedRewardTokenPerShare,
uint256 lastBlockNumber
);

// **External Functions**

/**
* @notice Allows users to stake ERC721 tokens into the pool.
* @param _tokenIds An array of token IDs to be staked.
*/
function stake(uint256[] calldata _tokenIds) external;

/**
* @notice Allows users to unstake their ERC721 tokens from the pool.
* @param _tokenIds An array of token IDs to be unstaked.
*/
function unstake(uint256[] calldata _tokenIds) external;

/**
* @notice Allows users to claim their pending rewards.
*/
function claim() external;
}
67 changes: 67 additions & 0 deletions contracts/interfaces/IERC721/IERC721LockUpPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// 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";
import {IERC721BasePool} from "./IERC721BasePool.sol";

interface IERC721LockUpPool is IERC721BasePool{

/**
* @notice Storage for a user's staking information
* @dev amount Number of tokens staked by the user.
* @dev claimed The amount of rewards already claimed by the user
* @dev rewardDebt Used to calculate rewards efficiently
* @dev pending The amount of rewards pending for the user
*/
struct UserInfo {
uint256 amount;
uint256 claimed;
uint256 rewardDebt;
uint256 pending;
}

/**
* @notice Defines the pool state and config parameters
* @dev stakeToken The address of the ERC721 staking token
* @dev rewardToken The address of the ERC20 reward token
* @dev startTime The start time of the pool
* @dev endTime The end time of the pool
* @dev unstakeLockupTime The lockup period (in seconds) after unstaking
* @dev claimLockupTime The lockup period (in seconds) before claiming rewards
* @dev rewardTokenPerSecond The reward distribution rate per second
* @dev totalStaked: Total tokens staked
* @dev totalClaimed: Total rewards claimed
* @dev lastUpdateTimestamp: The timestamp of the last update
* @dev accRewardPerShare: Accumulated rewards per staked token
* @dev isActive: Flag indicating active/inactive pool
* @dev adminWallet: Address of the pool admin
* @dev userInfo: Mapping for user staking data
* @dev stakedTokens: Mapping tokenIds to owner addresses
*/
struct LockupPool {
IERC721 stakeToken;
IERC20 rewardToken;
uint256 startTime;
uint256 endTime;
uint256 rewardTokenPerSecond;
uint256 totalStaked;
uint256 totalClaimed;
uint256 lastUpdateTimestamp;
uint256 accRewardPerShare;
uint256 unstakeLockupTime; // Lockup period for unstaking
uint256 claimLockupTime; // Lockup period for claiming rewards
mapping(uint256 => address) stakedTokens;
}

/**
* ERROR MESSAGES
*/
/// @dev Error to indicate that tokens are still in lockup and cannot be accessed
/// @param currentTime The current timestamp
/// @param unlockTime The timestamp when the tokens will be unlocked
error TokensInLockup(uint256 currentTime, uint256 unlockTime);

/// @dev Error to indicate an invalid lockup time for unstaking or claiming rewards
error InvalidLockupTime();
}
Loading
Loading