编译器
0.8.14+commit.80d49f37
文件 1 的 7:Context.sol
pragma solidity ^0.8.0;
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
文件 2 的 7:ERC721Holder.sol
pragma solidity ^0.8.0;
import "../IERC721Receiver.sol";
contract ERC721Holder is IERC721Receiver {
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
文件 3 的 7:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 4 的 7:IERC721.sol
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
interface IERC721 is IERC165 {
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
function balanceOf(address owner) external view returns (uint256 balance);
function ownerOf(uint256 tokenId) external view returns (address owner);
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
function approve(address to, uint256 tokenId) external;
function setApprovalForAll(address operator, bool _approved) external;
function getApproved(uint256 tokenId) external view returns (address operator);
function isApprovedForAll(address owner, address operator) external view returns (bool);
}
文件 5 的 7:IERC721Receiver.sol
pragma solidity ^0.8.0;
interface IERC721Receiver {
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}
文件 6 的 7:Ownable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor() {
_transferOwnership(_msgSender());
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 7 的 7:SenseiStaking.sol
pragma solidity ^0.8.13;
import "openzeppelin/contracts/token/ERC721/IERC721.sol";
import "openzeppelin/contracts/access/Ownable.sol";
import "openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
contract SenseiStaking is Ownable, ERC721Holder {
IERC721 public senseiNFT;
uint256 public stakedTotal;
struct StakedToken {
address owner;
uint256 lockDownExpiration;
}
constructor(IERC721 _senseiNFT) {
senseiNFT = _senseiNFT;
}
mapping(uint256 => StakedToken) internal stakedToken;
mapping(address => uint256[]) public staker;
bool enabled;
event BatchStaked(address owner, uint256[] tokenIds);
event BatchUnstaked(address owner, uint256[] tokenIds);
event LockDownExpirationChanged(
address user,
uint256 tokenId,
uint256 lockdownExpiration
);
function enableStaking() public onlyOwner {
require(!enabled, "Already initialised");
enabled = true;
}
function stopStaking() public onlyOwner {
require(enabled, "Already stopped");
enabled = false;
}
function stakedTokens(address _user)
public
view
returns (uint256[] memory tokenIds)
{
return staker[_user];
}
function tokenInfo(uint256 _tokenId)
public
view
returns (StakedToken memory info)
{
return stakedToken[_tokenId];
}
function stakingEnabled() public view returns (bool) {
return enabled;
}
function stakeBatch(uint256[] memory tokenIds, uint256 _lockdownExpiration)
public
{
require(tokenIds.length > 0, "You are trying to stake 0 tokens");
for (uint256 i = 0; i < tokenIds.length; i++) {
_stake(msg.sender, tokenIds[i], _lockdownExpiration);
}
emit BatchStaked(msg.sender, tokenIds);
}
function _stake(
address _user,
uint256 _tokenId,
uint256 _lockdownExpiration
) internal {
require(enabled, "Staking System: the staking has not started");
require(
_lockdownExpiration > block.timestamp,
"Expiration time is in the past must be in the future"
);
require(
senseiNFT.ownerOf(_tokenId) == _user,
"user must be the owner of the token"
);
require(
senseiNFT.isApprovedForAll(_user, address(this)),
"user needs to set approval first"
);
stakedToken[_tokenId].owner = _user;
stakedToken[_tokenId].lockDownExpiration = _lockdownExpiration;
staker[_user].push(_tokenId);
senseiNFT.safeTransferFrom(_user, address(this), _tokenId);
stakedTotal++;
}
function unstakeBatch(uint256[] memory tokenIds) public {
require(tokenIds.length > 0, "You are trying to unstake 0 tokens");
for (uint256 i = 0; i < tokenIds.length; i++) {
_unstake(msg.sender, tokenIds[i]);
}
emit BatchUnstaked(msg.sender, tokenIds);
}
function _unstake(address _user, uint256 _tokenId) internal {
require(
enabled,
"Staking System: the staking system is not enabled, cannot unstake tokens."
);
require(
block.timestamp >= stakedToken[_tokenId].lockDownExpiration,
"Your token is currently locked down"
);
require(
stakedToken[_tokenId].owner == _user,
"You are not the owner if this token or token is not staked"
);
delete stakedToken[_tokenId].owner;
delete stakedToken[_tokenId].lockDownExpiration;
senseiNFT.safeTransferFrom(address(this), _user, _tokenId);
for (uint256 i = 0; i < staker[_user].length; i++) {
if (staker[_user][i] == _tokenId) {
staker[_user][i] = staker[_user][staker[_user].length - 1];
staker[_user].pop();
}
}
stakedTotal--;
}
function updateLockDown(
uint256 lockdownExpiration,
uint256[] memory tokenIds
) public onlyOwner {
require(tokenIds.length > 0, "You are trying to modify 0 tokens");
for (uint256 i = 0; i < tokenIds.length; i++) {
_updateLockDown(lockdownExpiration, tokenIds[i]);
}
}
function _updateLockDown(uint256 _lockdownExpiration, uint256 _tokenId)
internal
{
require(
_lockdownExpiration > block.timestamp,
"You are trying to update in the past"
);
require(enabled, "Staking System: the staking has not started");
stakedToken[_tokenId].lockDownExpiration = _lockdownExpiration;
emit LockDownExpirationChanged(
stakedToken[_tokenId].owner,
_tokenId,
_lockdownExpiration
);
}
}
{
"compilationTarget": {
"src/SenseiStaking.sol": "SenseiStaking"
},
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [
":ds-test/=lib/forge-std/lib/ds-test/src/",
":forge-std/=lib/forge-std/src/",
":openzeppelin-contracts/=lib/openzeppelin-contracts/",
":openzeppelin/=lib/openzeppelin-contracts/"
]
}
[{"inputs":[{"internalType":"contract IERC721","name":"_senseiNFT","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"BatchStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"owner","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"BatchUnstaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"lockdownExpiration","type":"uint256"}],"name":"LockDownExpirationChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"enableStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"onERC721Received","outputs":[{"internalType":"bytes4","name":"","type":"bytes4"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"senseiNFT","outputs":[{"internalType":"contract IERC721","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"},{"internalType":"uint256","name":"_lockdownExpiration","type":"uint256"}],"name":"stakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"}],"name":"stakedTokens","outputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakedTotal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"staker","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stakingEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stopStaking","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"tokenInfo","outputs":[{"components":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"lockDownExpiration","type":"uint256"}],"internalType":"struct SenseiStaking.StakedToken","name":"info","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"unstakeBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"lockdownExpiration","type":"uint256"},{"internalType":"uint256[]","name":"tokenIds","type":"uint256[]"}],"name":"updateLockDown","outputs":[],"stateMutability":"nonpayable","type":"function"}]