This repository contains the ExampleNftPool
smart contract, a Solidity-based system for staking NFTs and earning token rewards. The contract supports NFTs with different rarities, each with specific reward multipliers, and is designed to operate on the Ethereum blockchain.
- NFT Staking and Unstaking: Users can stake and unstake their NFTs, classified by rarity levels (Common, Rare, Super Rare).
- Rewards Calculation: Tokens are distributed based on the rarity of staked NFTs, with configurable multipliers for each rarity level.
- Signature Verification: Uses signatures to validate rarity data with a trusted signer.
- Emergency Withdraw: Allows users to withdraw their NFTs without claiming rewards.
- Admin Controls: Adjust reward rates, max supply, and trusted signer address.
- Solidity >=0.8.0
- OpenZeppelin Contracts for Ownable, ReentrancyGuard, and cryptographic utilities.
- IERC721 Interface for interacting with NFTs.
- IVault Interface for token distribution.
- Clone this repository:
git clone https://github.com/parametprame/nft-staking-rewards-pool.git
- Install dependencies:
npm install
Deploy the contract with your chosen NFT and vault addresses, and specify a trusted signer.
Call stake
with token IDs, corresponding rarities, and signatures:
const tokenIds = [1, 2, 3];
const rarities = [0, 1, 2];
const signatures = [];
for (let i = 0; i < tokenIds.length; i++) {
const messageHash = ethers.keccak256(
ethers.concat([
ethers.zeroPadValue(ethers.toBeArray(tokenIds[i]), 32), // Pad _tokenId to 32 bytes
ethers.zeroPadValue(ethers.toBeArray(rarities[i]), 32), // Pad _rarity to 32 bytes
])
);
const signature = await trustedSigner.signMessage(ethers.getBytes(messageHash));
signatures.push(signature);
}
// Example staking call
await exampleNftPool.stake(tokenIds, rarities, signatures);
Call unstake
to retrieve staked NFTs:
await exampleNftPool.unstake([1, 2]);
Use claim
to claim accumulated rewards:
await exampleNftPool.claim();
The following is an example setup for testing the staking contract locally.
-
Setup: Deploy the contract on a local Ethereum environment like Hardhat or Ganache.
-
Generate Signatures: Use a trusted signer account to sign the rarity and token ID data. Each
stake
transaction requires valid signatures for token IDs and rarity values. -
Staking: Interact with the contract using the
stake
function and pass the required token IDs, rarities, and generated signatures. -
Claim Rewards: After a period, call
claim
to see rewards based on the staked NFTs' rarity. -
Unstaking: Call
unstake
to retrieve NFTs and optionally claim rewards.