Address Contract Verified
Address
0xc47987F0b717Ba3B274b571df8a66d21419bFC51
Balance
0 ETH
Nonce
1
Code Size
9688 bytes
Creator
0x0caCAA7A...adBF at tx 0xabdb8f66...8d3f00
Indexed Transactions
0
Contract Bytecode
9688 bytes
0x608060405234801561001057600080fd5b50600436106101a95760003560e01c80638da5cb5b116100f9578063bd30558e11610097578063df61775911610071578063df617759146104a1578063e8fa2182146104ab578063f2fde38b146104c9578063fd5e6dd1146104e5576101a9565b8063bd30558e1461045b578063be44547f14610479578063d06fcba814610483576101a9565b8063a694fc3a116100d3578063a694fc3a146103d3578063adee8ff2146103ef578063b390bd911461040d578063bbc4986d1461043d576101a9565b80638da5cb5b146103785780638f78e6a114610396578063a32bf597146103b2576101a9565b80634f90ff9c116101665780636f1e8533116101405780636f1e8533146102dc578063715018a61461030c5780637b831c30146103165780638c65c81f14610346576101a9565b80634f90ff9c146102825780636641ea08146102a05780636896ef4b146102be576101a9565b8063078b0fb7146101ae578063150b7a02146101de5780631959a0021461020e5780632e17de781461023e5780634195f53c1461025a5780634828478914610264575b600080fd5b6101c860048036038101906101c391906119e5565b610515565b6040516101d59190611a2b565b60405180910390f35b6101f860048036038101906101f39190611bb8565b610561565b6040516102059190611c76565b60405180910390f35b610228600480360381019061022391906119e5565b610575565b6040516102359190611a2b565b60405180910390f35b61025860048036038101906102539190611c91565b610593565b005b6102626108a3565b005b61026c61091b565b6040516102799190611a2b565b60405180910390f35b61028a610928565b6040516102979190611a2b565b60405180910390f35b6102a861092f565b6040516102b59190611a2b565b60405180910390f35b6102c6610936565b6040516102d39190611a2b565b60405180910390f35b6102f660048036038101906102f191906119e5565b61093c565b6040516103039190611cd9565b60405180910390f35b61031461095c565b005b610330600480360381019061032b9190611c91565b610970565b60405161033d9190611cd9565b60405180910390f35b610360600480360381019061035b9190611c91565b6109e2565b60405161036f93929190611cf4565b60405180910390f35b610380610a19565b60405161038d9190611d3a565b60405180910390f35b6103b060048036038101906103ab9190611c91565b610a42565b005b6103ba610ade565b6040516103ca9493929190611d55565b60405180910390f35b6103ed60048036038101906103e89190611c91565b610b58565b005b6103f7611085565b6040516104049190611a2b565b60405180910390f35b610427600480360381019061042291906119e5565b61108b565b6040516104349190611a2b565b60405180910390f35b610445611143565b6040516104529190611a2b565b60405180910390f35b610463611148565b6040516104709190611a2b565b60405180910390f35b61048161114d565b005b61048b61131d565b6040516104989190611df9565b60405180910390f35b6104a9611343565b005b6104b3611492565b6040516104c09190611cd9565b60405180910390f35b6104e360048036038101906104de91906119e5565b6114a5565b005b6104ff60048036038101906104fa9190611c91565b61152b565b60405161050c9190611d3a565b60405180910390f35b6000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020600101549050919050565b600063150b7a0260e01b9050949350505050565b60026020528060005260406000206000915090508060010154905081565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020905060005b816000018054905081101561086457828260000182815481106105ff576105fe611e14565b5b906000526020600020906005020160000154036108575781600001818154811061062c5761062b611e14565b5b906000526020600020906005020160030160009054906101000a900460ff1661068a576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161068190611ea0565b60405180910390fd5b6106ba8260000182815481106106a3576106a2611e14565b5b906000526020600020906005020160040154610970565b6106f9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106f090611f32565b60405180910390fd5b610703338261156a565b4282600001828154811061071a57610719611e14565b5b906000526020600020906005020160020181905550600082600001828154811061074757610746611e14565b5b906000526020600020906005020160030160006101000a81548160ff021916908315150217905550600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3033866040518463ffffffff1660e01b81526004016107ce93929190611f52565b600060405180830381600087803b1580156107e857600080fd5b505af11580156107fc573d6000803e3d6000fd5b505050503373ffffffffffffffffffffffffffffffffffffffff167f7fc4727e062e336010f2c282598ef5f14facb3de68cf8195c2f23e1454b2b74e8442604051610848929190611f89565b60405180910390a250506108a0565b80806001019150506105d9565b506040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161089790611ffe565b60405180910390fd5b50565b6108ab6116be565b60036000600454815260200190815260200160002060020160009054906101000a900460ff1615610911576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109089061206a565b60405180910390fd5b610919611745565b565b6000600680549050905090565b6206978081565b623b538081565b60045481565b60076020528060005260406000206000915054906101000a900460ff1681565b6109646116be565b61096e60006118a7565b565b6000808211801561098357506004548211155b6109c2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109b9906120d6565b60405180910390fd5b600360008381526020019081526020016000206001015442119050919050565b60036020528060005260406000206000915090508060000154908060010154908060020160009054906101000a900460ff16905083565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b610a4a6116be565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3033846040518463ffffffff1660e01b8152600401610aa993929190611f52565b600060405180830381600087803b158015610ac357600080fd5b505af1158015610ad7573d6000803e3d6000fd5b5050505050565b600080600080600060036000600454815260200190815260200160002060405180606001604052908160008201548152602001600182015481526020016002820160009054906101000a900460ff161515151581525050905060045481600001518260200151836040015194509450945094505090919293565b600560009054906101000a900460ff1615610ba8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b9f90612142565b60405180910390fd5b60036000600454815260200190815260200160002060020160009054906101000a900460ff16610c0d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c04906121ae565b60405180910390fd5b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002090506000805b8260000180549050811015610de35783836000018281548110610c7a57610c79611e14565b5b90600052602060002090600502016000015403610dd657826000018181548110610ca757610ca6611e14565b5b906000526020600020906005020160030160009054906101000a900460ff1615610d06576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610cfd9061221a565b60405180910390fd5b42836000018281548110610d1d57610d1c611e14565b5b9060005260206000209060050201600101819055506000836000018281548110610d4a57610d49611e14565b5b9060005260206000209060050201600201819055506001836000018281548110610d7757610d76611e14565b5b906000526020600020906005020160030160006101000a81548160ff021916908315150217905550600454836000018281548110610db857610db7611e14565b5b90600052602060002090600502016004018190555060019150610de3565b8080600101915050610c54565b5080610f1f57600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3330866040518463ffffffff1660e01b8152600401610e4893929190611f52565b600060405180830381600087803b158015610e6257600080fd5b505af1158015610e76573d6000803e3d6000fd5b50505050816000016040518060a0016040528085815260200142815260200160008152602001600115158152602001600454815250908060018154018082558091505060019003906000526020600020906005020160009091909190915060008201518160000155602082015181600101556040820151816002015560608201518160030160006101000a81548160ff0219169083151502179055506080820151816004015550505b600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661102c576006339080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001600760003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055505b3373ffffffffffffffffffffffffffffffffffffffff167fb4caaf29adda3eefee3ad552a8e85058589bf834c7466cae4ee58787f70589ed84426004546040516110789392919061223a565b60405180910390a2505050565b6103e881565b600080600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002090506000805b8260000180549050811015611138578260000181815481106110f8576110f7611e14565b5b906000526020600020906005020160030160009054906101000a900460ff161561112b578180611127906122a0565b9250505b80806001019150506110d3565b508092505050919050565b600381565b60c881565b6111556116be565b600560009054906101000a900460ff166111a4576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161119b90612334565b60405180910390fd5b60005b60068054905081101561131a576000600682815481106111ca576111c9611e14565b5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1690506000600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020905060005b816000018054905081101561130a5781600001818154811061126257611261611e14565b5b906000526020600020906005020160030160009054906101000a900460ff16156112fd57611290838261156a565b60008260000182815481106112a8576112a7611e14565b5b906000526020600020906005020160030160006101000a81548160ff021916908315150217905550428260000182815481106112e7576112e6611e14565b5b9060005260206000209060050201600201819055505b808060010191505061123d565b50505080806001019150506111a7565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61134b6116be565b600060045411611390576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611387906123a0565b60405180910390fd5b600060036000600454815260200190815260200160002090508060020160009054906101000a900460ff166113fa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016113f19061240c565b60405180910390fd5b42816001018190555060008160020160006101000a81548160ff0219169083151502179055507f8868888cc18628a149bc88cc32a91976ab30e2cd9aececb0cfe184a73fe551f960045442604051611453929190611f89565b60405180910390a1600360045410156114735761146e611745565b61148f565b6001600560006101000a81548160ff0219169083151502179055505b50565b600560009054906101000a900460ff1681565b6114ad6116be565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff160361151f5760006040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081526004016115169190611d3a565b60405180910390fd5b611528816118a7565b50565b6006818154811061153b57600080fd5b906000526020600020016000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020905060008160000183815481106115c5576115c4611e14565b5b9060005260206000209060050201905060008160030160009054906101000a900460ff166115f75781600201546115f9565b425b9050600082600101548261160d919061242c565b9050600060646301e1338060c8846103e86116289190612460565b6116329190612460565b61163c91906124d1565b61164691906124d1565b90508085600101600082825461165c9190612502565b925050819055508673ffffffffffffffffffffffffffffffffffffffff167fdf74e5e265dc029c80959a693f860cacd5d1fd1f0587e0838eae9c27ef8837e186600101546040516116ad9190611a2b565b60405180910390a250505050505050565b6116c661196b565b73ffffffffffffffffffffffffffffffffffffffff166116e4610a19565b73ffffffffffffffffffffffffffffffffffffffff16146117435761170761196b565b6040517f118cdaa700000000000000000000000000000000000000000000000000000000815260040161173a9190611d3a565b60405180910390fd5b565b60046000815480929190611758906122a0565b9190505550600360045411156117a3576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161179a90612582565b60405180910390fd5b6000429050600160045411156117e957620697806003600060016004546117ca919061242c565b8152602001908152602001600020600101546117e69190612502565b90505b6000623b5380826117fa9190612502565b9050604051806060016040528083815260200182815260200160011515815250600360006004548152602001908152602001600020600082015181600001556020820151816001015560408201518160020160006101000a81548160ff0219169083151502179055509050507fa359b664a68acd8839e42112eb50eff3408165e15074fde89ddb58a0db2e691d600454838360405161189b9392919061223a565b60405180910390a15050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b600033905090565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006119b282611987565b9050919050565b6119c2816119a7565b81146119cd57600080fd5b50565b6000813590506119df816119b9565b92915050565b6000602082840312156119fb576119fa61197d565b5b6000611a09848285016119d0565b91505092915050565b6000819050919050565b611a2581611a12565b82525050565b6000602082019050611a406000830184611a1c565b92915050565b611a4f81611a12565b8114611a5a57600080fd5b50565b600081359050611a6c81611a46565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611ac582611a7c565b810181811067ffffffffffffffff82111715611ae457611ae3611a8d565b5b80604052505050565b6000611af7611973565b9050611b038282611abc565b919050565b600067ffffffffffffffff821115611b2357611b22611a8d565b5b611b2c82611a7c565b9050602081019050919050565b82818337600083830152505050565b6000611b5b611b5684611b08565b611aed565b905082815260208101848484011115611b7757611b76611a77565b5b611b82848285611b39565b509392505050565b600082601f830112611b9f57611b9e611a72565b5b8135611baf848260208601611b48565b91505092915050565b60008060008060808587031215611bd257611bd161197d565b5b6000611be0878288016119d0565b9450506020611bf1878288016119d0565b9350506040611c0287828801611a5d565b925050606085013567ffffffffffffffff811115611c2357611c22611982565b5b611c2f87828801611b8a565b91505092959194509250565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b611c7081611c3b565b82525050565b6000602082019050611c8b6000830184611c67565b92915050565b600060208284031215611ca757611ca661197d565b5b6000611cb584828501611a5d565b91505092915050565b60008115159050919050565b611cd381611cbe565b82525050565b6000602082019050611cee6000830184611cca565b92915050565b6000606082019050611d096000830186611a1c565b611d166020830185611a1c565b611d236040830184611cca565b949350505050565b611d34816119a7565b82525050565b6000602082019050611d4f6000830184611d2b565b92915050565b6000608082019050611d6a6000830187611a1c565b611d776020830186611a1c565b611d846040830185611a1c565b611d916060830184611cca565b95945050505050565b6000819050919050565b6000611dbf611dba611db584611987565b611d9a565b611987565b9050919050565b6000611dd182611da4565b9050919050565b6000611de382611dc6565b9050919050565b611df381611dd8565b82525050565b6000602082019050611e0e6000830184611dea565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082825260208201905092915050565b7f4e4654206973206e6f742063757272656e746c79207374616b65640000000000600082015250565b6000611e8a601b83611e43565b9150611e9582611e54565b602082019050919050565b60006020820190508181036000830152611eb981611e7d565b9050919050565b7f43616e6e6f7420756e7374616b65206265666f726520746865207374616b656460008201527f20726f756e6420656e6473000000000000000000000000000000000000000000602082015250565b6000611f1c602b83611e43565b9150611f2782611ec0565b604082019050919050565b60006020820190508181036000830152611f4b81611f0f565b9050919050565b6000606082019050611f676000830186611d2b565b611f746020830185611d2b565b611f816040830184611a1c565b949350505050565b6000604082019050611f9e6000830185611a1c565b611fab6020830184611a1c565b9392505050565b7f5374616b65206e6f7420666f756e640000000000000000000000000000000000600082015250565b6000611fe8600f83611e43565b9150611ff382611fb2565b602082019050919050565b6000602082019050818103600083015261201781611fdb565b9050919050565b7f50726576696f757320726f756e64206973207374696c6c206163746976650000600082015250565b6000612054601e83611e43565b915061205f8261201e565b602082019050919050565b6000602082019050818103600083015261208381612047565b9050919050565b7f496e76616c696420726f756e6420696e64657800000000000000000000000000600082015250565b60006120c0601383611e43565b91506120cb8261208a565b602082019050919050565b600060208201905081810360008301526120ef816120b3565b9050919050565b7f5374616b696e672068617320656e646564000000000000000000000000000000600082015250565b600061212c601183611e43565b9150612137826120f6565b602082019050919050565b6000602082019050818103600083015261215b8161211f565b9050919050565b7f43757272656e7420726f756e64206973206e6f74206163746976650000000000600082015250565b6000612198601b83611e43565b91506121a382612162565b602082019050919050565b600060208201905081810360008301526121c78161218b565b9050919050565b7f4e465420697320616c7265616479207374616b65640000000000000000000000600082015250565b6000612204601583611e43565b915061220f826121ce565b602082019050919050565b60006020820190508181036000830152612233816121f7565b9050919050565b600060608201905061224f6000830186611a1c565b61225c6020830185611a1c565b6122696040830184611a1c565b949350505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b60006122ab82611a12565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036122dd576122dc612271565b5b600182019050919050565b7f416c6c20726f756e64732068617665206e6f7420656e64656420796574000000600082015250565b600061231e601d83611e43565b9150612329826122e8565b602082019050919050565b6000602082019050818103600083015261234d81612311565b9050919050565b7f4e6f2061637469766520726f756e640000000000000000000000000000000000600082015250565b600061238a600f83611e43565b915061239582612354565b602082019050919050565b600060208201905081810360008301526123b98161237d565b9050919050565b7f526f756e64206973206e6f742061637469766500000000000000000000000000600082015250565b60006123f6601383611e43565b9150612401826123c0565b602082019050919050565b60006020820190508181036000830152612425816123e9565b9050919050565b600061243782611a12565b915061244283611a12565b925082820390508181111561245a57612459612271565b5b92915050565b600061246b82611a12565b915061247683611a12565b925082820261248481611a12565b9150828204841483151761249b5761249a612271565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006124dc82611a12565b91506124e783611a12565b9250826124f7576124f66124a2565b5b828204905092915050565b600061250d82611a12565b915061251883611a12565b92508282019050808211156125305761252f612271565b5b92915050565b7f416c6c20726f756e647320636f6d706c65746564000000000000000000000000600082015250565b600061256c601483611e43565b915061257782612536565b602082019050919050565b6000602082019050818103600083015261259b8161255f565b905091905056fea26469706673582212205e07f0c0fe80ed2be0a87c8c7ab2f2add0cbd7d90bb00b3a2a428ebf31aedc9c64736f6c63430008180033
Verified Source Code Full Match
Compiler: v0.8.24+commit.e11b9ed9
EVM: paris
Optimization: No
Lock.sol 237 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
contract NFTStaking is ERC721Holder, Ownable {
IERC721 public nftToken;
uint256 public constant TOKENS_PER_NFT = 1000;
uint256 public constant APR = 200; // 6.9% APR
uint256 public constant ROUND_DURATION = 45 days;
uint256 public constant ROUND_COOLDOWN = 5 days;
uint256 public constant ROUNDS_COUNT = 3;
struct Stake {
uint256 tokenId;
uint256 startTime;
uint256 endTime;
bool isActive;
uint256 stakedRound;
}
struct Round {
uint256 startTime;
uint256 endTime;
bool isActive;
}
struct UserInfo {
Stake[] stakes;
uint256 totalRewards;
}
mapping(address => UserInfo) public userInfo;
mapping(uint256 => Round) public rounds;
uint256 public currentRoundIndex;
bool public allRoundsEnded;
address[] public stakers;
mapping(address => bool) public isStaker;
event Staked(
address indexed user,
uint256 tokenId,
uint256 timestamp,
uint256 roundIndex
);
event Unstaked(address indexed user, uint256 tokenId, uint256 timestamp);
event RoundStarted(uint256 roundIndex, uint256 startTime, uint256 endTime);
event RoundEnded(uint256 roundIndex, uint256 endTime);
event RewardsCalculated(address indexed user, uint256 rewards);
constructor(address _nftToken) Ownable(msg.sender) {
nftToken = IERC721(_nftToken);
}
function stake(uint256 tokenId) external {
require(!allRoundsEnded, "Staking has ended");
require(
rounds[currentRoundIndex].isActive,
"Current round is not active"
);
UserInfo storage user = userInfo[msg.sender];
bool found = false;
for (uint256 i = 0; i < user.stakes.length; i++) {
if (user.stakes[i].tokenId == tokenId) {
require(!user.stakes[i].isActive, "NFT is already staked");
user.stakes[i].startTime = block.timestamp;
user.stakes[i].endTime = 0;
user.stakes[i].isActive = true;
user.stakes[i].stakedRound = currentRoundIndex;
found = true;
break;
}
}
if (!found) {
nftToken.safeTransferFrom(msg.sender, address(this), tokenId);
user.stakes.push(
Stake(tokenId, block.timestamp, 0, true, currentRoundIndex)
);
}
if (!isStaker[msg.sender]) {
stakers.push(msg.sender);
isStaker[msg.sender] = true;
}
emit Staked(msg.sender, tokenId, block.timestamp, currentRoundIndex);
}
function unstake(uint256 tokenId) external {
UserInfo storage user = userInfo[msg.sender];
for (uint256 i = 0; i < user.stakes.length; i++) {
if (user.stakes[i].tokenId == tokenId) {
require(user.stakes[i].isActive, "NFT is not currently staked");
require(
isRoundEnded(user.stakes[i].stakedRound),
"Cannot unstake before the staked round ends"
);
_calculateAndUpdateRewards(msg.sender, i);
user.stakes[i].endTime = block.timestamp;
user.stakes[i].isActive = false;
nftToken.safeTransferFrom(address(this), msg.sender, tokenId);
emit Unstaked(msg.sender, tokenId, block.timestamp);
return;
}
}
revert("Stake not found");
}
function _calculateAndUpdateRewards(
address user,
uint256 stakeIndex
) internal {
UserInfo storage userInfo = userInfo[user];
Stake storage stake = userInfo.stakes[stakeIndex];
uint256 endTime = stake.isActive ? block.timestamp : stake.endTime;
uint256 stakeDuration = endTime - stake.startTime;
uint256 reward = (TOKENS_PER_NFT * stakeDuration * APR) /
(365 days) /
100;
userInfo.totalRewards += reward;
emit RewardsCalculated(user, userInfo.totalRewards);
}
function getUserRewards(address user) public view returns (uint256) {
return userInfo[user].totalRewards;
}
function rescueNFT(uint256 nftId) external onlyOwner {
nftToken.safeTransferFrom(address(this), msg.sender, nftId);
}
function _startNewRound() internal {
currentRoundIndex++;
require(currentRoundIndex <= ROUNDS_COUNT, "All rounds completed");
uint256 startTime = block.timestamp;
if (currentRoundIndex > 1) {
startTime = rounds[currentRoundIndex - 1].endTime + ROUND_COOLDOWN;
}
uint256 endTime = startTime + ROUND_DURATION;
rounds[currentRoundIndex] = Round(startTime, endTime, true);
emit RoundStarted(currentRoundIndex, startTime, endTime);
}
function startRoundEarly() external onlyOwner {
require(
!rounds[currentRoundIndex].isActive,
"Previous round is still active"
);
_startNewRound();
}
function endRoundEarly() external onlyOwner {
require(currentRoundIndex > 0, "No active round");
Round storage currentRound = rounds[currentRoundIndex];
require(currentRound.isActive, "Round is not active");
currentRound.endTime = block.timestamp;
currentRound.isActive = false;
emit RoundEnded(currentRoundIndex, block.timestamp);
if (currentRoundIndex < ROUNDS_COUNT) {
_startNewRound();
} else {
allRoundsEnded = true;
}
}
function getCurrentRound()
external
view
returns (uint256, uint256, uint256, bool)
{
Round memory currentRound = rounds[currentRoundIndex];
return (
currentRoundIndex,
currentRound.startTime,
currentRound.endTime,
currentRound.isActive
);
}
function calculateAllRewards() external onlyOwner {
require(allRoundsEnded, "All rounds have not ended yet");
for (uint256 i = 0; i < stakers.length; i++) {
address user = stakers[i];
UserInfo storage userInfo = userInfo[user];
for (uint256 j = 0; j < userInfo.stakes.length; j++) {
if (userInfo.stakes[j].isActive) {
_calculateAndUpdateRewards(user, j);
userInfo.stakes[j].isActive = false;
userInfo.stakes[j].endTime = block.timestamp;
}
}
}
}
function getStakersCount() external view returns (uint256) {
return stakers.length;
}
function isRoundEnded(uint256 roundIndex) public view returns (bool) {
require(
roundIndex > 0 && roundIndex <= currentRoundIndex,
"Invalid round index"
);
return block.timestamp > rounds[roundIndex].endTime;
}
// New function to get the number of staked NFTs for a given user
function getStakedNFTCount(address user) external view returns (uint256) {
UserInfo storage userInfo = userInfo[user];
uint256 count = 0;
for (uint256 i = 0; i < userInfo.stakes.length; i++) {
if (userInfo.stakes[i].isActive) {
count++;
}
}
return count;
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC721.sol 135 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or
* {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon
* a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the address zero.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
IERC721Receiver.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.20;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be
* reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
ERC721Holder.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.20;
import {IERC721Receiver} from "../IERC721Receiver.sol";
/**
* @dev Implementation of the {IERC721Receiver} interface.
*
* Accepts all token transfers.
* Make sure the contract is able to use its token with {IERC721-safeTransferFrom}, {IERC721-approve} or
* {IERC721-setApprovalForAll}.
*/
abstract contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual returns (bytes4) {
return this.onERC721Received.selector;
}
}
Read Contract
APR 0xbd30558e → uint256
ROUNDS_COUNT 0xbbc4986d → uint256
ROUND_COOLDOWN 0x4f90ff9c → uint256
ROUND_DURATION 0x6641ea08 → uint256
TOKENS_PER_NFT 0xadee8ff2 → uint256
allRoundsEnded 0xe8fa2182 → bool
currentRoundIndex 0x6896ef4b → uint256
getCurrentRound 0xa32bf597 → uint256, uint256, uint256, bool
getStakedNFTCount 0xb390bd91 → uint256
getStakersCount 0x48284789 → uint256
getUserRewards 0x078b0fb7 → uint256
isRoundEnded 0x7b831c30 → bool
isStaker 0x6f1e8533 → bool
nftToken 0xd06fcba8 → address
owner 0x8da5cb5b → address
rounds 0x8c65c81f → uint256, uint256, bool
stakers 0xfd5e6dd1 → address
userInfo 0x1959a002 → uint256
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
calculateAllRewards 0xbe44547f
No parameters
endRoundEarly 0xdf617759
No parameters
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
renounceOwnership 0x715018a6
No parameters
rescueNFT 0x8f78e6a1
uint256 nftId
stake 0xa694fc3a
uint256 tokenId
startRoundEarly 0x4195f53c
No parameters
transferOwnership 0xf2fde38b
address newOwner
unstake 0x2e17de78
uint256 tokenId
Recent Transactions
No transactions found for this address