Address Contract Verified
Address
0x282b3c1fF58B3b4587A22f761Bb1B8D2994FEB01
Balance
0 ETH
Nonce
1
Code Size
8827 bytes
Creator
0xAB44AE5F...57C7 at tx 0xdcfe4c87...f06ddb
Indexed Transactions
0
Contract Bytecode
8827 bytes
0x608060405234801561001057600080fd5b50600436106101005760003560e01c8063819d4cc611610097578063a694fc3a11610066578063a694fc3a1461024f578063b88a802f1461026b578063c601f35214610275578063f2fde38b146102a557610100565b8063819d4cc6146101ef5780638456cb591461020b5780638980f11f146102155780638da5cb5b1461023157610100565b80635c975abb116100d35780635c975abb1461018d5780635d3eea91146101ab578063616351b1146101c7578063715018a6146101e557610100565b80631126ce9a14610105578063150b7a02146101235780631caaa487146101535780633f4ba83a14610183575b600080fd5b61010d6102c1565b60405161011a9190611558565b60405180910390f35b61013d60048036038101906101389190611757565b6102cb565b60405161014a9190611815565b60405180910390f35b61016d60048036038101906101689190611830565b6102df565b60405161017a919061186c565b60405180910390f35b61018b610312565b005b610195610324565b6040516101a291906118a2565b60405180910390f35b6101c560048036038101906101c09190611830565b61033b565b005b6101cf6105ae565b6040516101dc919061197b565b60405180910390f35b6101ed610606565b005b6102096004803603810190610204919061199d565b61061a565b005b6102136106ce565b005b61022f600480360381019061022a919061199d565b6106e0565b005b6102396107a4565b604051610246919061186c565b60405180910390f35b61026960048036038101906102649190611830565b6107cd565b005b610273610a9e565b005b61028f600480360381019061028a91906119dd565b610d4e565b60405161029c9190611aef565b60405180910390f35b6102bf60048036038101906102ba91906119dd565b610e27565b005b65010d7adb7d2f81565b600063150b7a0260e01b9050949350505050565b60056020528060005260406000206000915054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b61031a610eaa565b610322610f28565b565b6000600260009054906101000a900460ff16905090565b610343610f8b565b6000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002090503373ffffffffffffffffffffffffffffffffffffffff166005600084815260200190815260200160002060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610427576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161041e90611b94565b60405180910390fd5b61043033610fda565b8160020160008282546104439190611be3565b9250508190555042816004018190555060006005600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508060030160008154809291906104bb90611c17565b91905055506104cd8282600001611061565b6104d8826004611061565b600260019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3033856040518463ffffffff1660e01b815260040161053793929190611c40565b600060405180830381600087803b15801561055157600080fd5b505af1158015610565573d6000803e3d6000fd5b505050507f0f5bb82176feb1b5e747e28471aa92156a04d9f3ab9f45f28e2d704232b93f75338360405161059a929190611c77565b60405180910390a1506105ab61107e565b50565b606060048054806020026020016040519081016040528092919081815260200182805480156105fc57602002820191906000526020600020905b8154815260200190600101908083116105e8575b5050505050905090565b61060e610eaa565b6106186000611087565b565b610622610eaa565b8173ffffffffffffffffffffffffffffffffffffffff166342842e0e3033846040518463ffffffff1660e01b815260040161065f93929190611c40565b600060405180830381600087803b15801561067957600080fd5b505af115801561068d573d6000803e3d6000fd5b505050507f57519b6a0997d7d44511836bcee0a36871aa79d445816f6c464abb0cd9d3f3e882826040516106c2929190611c77565b60405180910390a15050565b6106d6610eaa565b6106de61114b565b565b6106e8610eaa565b8173ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b8152600401610723929190611c77565b6020604051808303816000875af1158015610742573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107669190611ccc565b507f55350610fe57096d8c0ffa30beede987326bccfcb0b4415804164d0dd50ce8b18282604051610798929190611c77565b60405180910390a15050565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6107d5610f8b565b6107dd6111ae565b3373ffffffffffffffffffffffffffffffffffffffff16600260019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16636352211e836040518263ffffffff1660e01b815260040161084f9190611558565b602060405180830381865afa15801561086c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108909190611d0e565b73ffffffffffffffffffffffffffffffffffffffff16146108e6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108dd90611b94565b60405180910390fd5b65010d7adb7d2f6301e133806108fc9190611d3b565b65010d7adb7d2f6004805490506109139190611d3b565b6301e133806109229190611d3b565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b815260040161097d919061186c565b602060405180830381865afa15801561099a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109be9190611d92565b6109c89190611dbf565b11610a08576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109ff90611e65565b60405180910390fd5b6000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002090506000816003015403610a6557610a60826111f8565b610a92565b610a6e33610fda565b816002016000828254610a819190611be3565b92505081905550610a91826111f8565b5b50610a9b61107e565b50565b610aa6610f8b565b6000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020905060008160020154610af933610fda565b610b039190611be3565b905060008111610b48576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610b3f90611ed1565b60405180910390fd5b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231306040518263ffffffff1660e01b8152600401610ba3919061186c565b602060405180830381865afa158015610bc0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610be49190611d92565b8110610c25576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610c1c90611f3d565b60405180910390fd5b80826001016000828254610c399190611be3565b9250508190555042826004018190555060008260020181905550600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1663a9059cbb33836040518363ffffffff1660e01b8152600401610cb0929190611c77565b6020604051808303816000875af1158015610ccf573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cf39190611ccc565b503373ffffffffffffffffffffffffffffffffffffffff167fe2403640ba68fed3a2f88b7557551d1993f84b99bb10ff833f0cf8db0c5e048682604051610d3a9190611558565b60405180910390a25050610d4c61107e565b565b610d56611510565b600660008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206040518060a001604052908160008201805480602002602001604051908101604052809291908181526020018280548015610def57602002820191906000526020600020905b815481526020019060010190808311610ddb575b505050505081526020016001820154815260200160028201548152602001600382015481526020016004820154815250509050919050565b610e2f610eaa565b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1603610e9e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e9590611fcf565b60405180910390fd5b610ea781611087565b50565b610eb26113d4565b73ffffffffffffffffffffffffffffffffffffffff16610ed06107a4565b73ffffffffffffffffffffffffffffffffffffffff1614610f26576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f1d9061203b565b60405180910390fd5b565b610f306113dc565b6000600260006101000a81548160ff0219169083151502179055507f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa610f746113d4565b604051610f81919061186c565b60405180910390a1565b600260015403610fd0576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610fc7906120a7565b60405180910390fd5b6002600181905550565b600080600660008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002090506000808260040154426110319190611dbf565b905065010d7adb7d2f83600301546110499190611d3b565b816110549190611d3b565b9150819350505050919050565b600061106d8383611425565b9050611079818361146e565b505050565b60018081905550565b60008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055508173ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35050565b6111536111ae565b6001600260006101000a81548160ff0219169083151502179055507f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586111976113d4565b6040516111a4919061186c565b60405180910390a1565b6111b6610324565b156111f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016111ed90612113565b60405180910390fd5b565b6000600660003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000209050428160040181905550336005600084815260200190815260200160002060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060018160030160008282546112ab9190611be3565b92505081905550600482908060018154018082558091505060019003906000526020600020016000909190919091505580600001829080600181540180825580915050600190039060005260206000200160009091909190915055600260019054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166342842e0e3330856040518463ffffffff1660e01b815260040161136593929190611c40565b600060405180830381600087803b15801561137f57600080fd5b505af1158015611393573d6000803e3d6000fd5b505050507f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d33836040516113c8929190611c77565b60405180910390a15050565b600033905090565b6113e4610324565b611423576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161141a9061217f565b60405180910390fd5b565b600080600090505b838382815481106114415761144061219f565b5b90600052602060002001541461146457808061145c906121ce565b91505061142d565b8091505092915050565b5b600181805490506114809190611dbf565b8210156114e557806001836114959190611be3565b815481106114a6576114a561219f565b5b90600052602060002001548183815481106114c4576114c361219f565b5b906000526020600020018190555081806114dd906121ce565b92505061146f565b808054806114f6576114f5612216565b5b600190038181906000526020600020016000905590555050565b6040518060a0016040528060608152602001600081526020016000815260200160008152602001600081525090565b6000819050919050565b6115528161153f565b82525050565b600060208201905061156d6000830184611549565b92915050565b6000604051905090565b600080fd5b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b60006115b282611587565b9050919050565b6115c2816115a7565b81146115cd57600080fd5b50565b6000813590506115df816115b9565b92915050565b6115ee8161153f565b81146115f957600080fd5b50565b60008135905061160b816115e5565b92915050565b600080fd5b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b6116648261161b565b810181811067ffffffffffffffff821117156116835761168261162c565b5b80604052505050565b6000611696611573565b90506116a2828261165b565b919050565b600067ffffffffffffffff8211156116c2576116c161162c565b5b6116cb8261161b565b9050602081019050919050565b82818337600083830152505050565b60006116fa6116f5846116a7565b61168c565b90508281526020810184848401111561171657611715611616565b5b6117218482856116d8565b509392505050565b600082601f83011261173e5761173d611611565b5b813561174e8482602086016116e7565b91505092915050565b600080600080608085870312156117715761177061157d565b5b600061177f878288016115d0565b9450506020611790878288016115d0565b93505060406117a1878288016115fc565b925050606085013567ffffffffffffffff8111156117c2576117c1611582565b5b6117ce87828801611729565b91505092959194509250565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b61180f816117da565b82525050565b600060208201905061182a6000830184611806565b92915050565b6000602082840312156118465761184561157d565b5b6000611854848285016115fc565b91505092915050565b611866816115a7565b82525050565b6000602082019050611881600083018461185d565b92915050565b60008115159050919050565b61189c81611887565b82525050565b60006020820190506118b76000830184611893565b92915050565b600081519050919050565b600082825260208201905092915050565b6000819050602082019050919050565b6118f28161153f565b82525050565b600061190483836118e9565b60208301905092915050565b6000602082019050919050565b6000611928826118bd565b61193281856118c8565b935061193d836118d9565b8060005b8381101561196e57815161195588826118f8565b975061196083611910565b925050600181019050611941565b5085935050505092915050565b60006020820190508181036000830152611995818461191d565b905092915050565b600080604083850312156119b4576119b361157d565b5b60006119c2858286016115d0565b92505060206119d3858286016115fc565b9150509250929050565b6000602082840312156119f3576119f261157d565b5b6000611a01848285016115d0565b91505092915050565b600082825260208201905092915050565b6000611a26826118bd565b611a308185611a0a565b9350611a3b836118d9565b8060005b83811015611a6c578151611a5388826118f8565b9750611a5e83611910565b925050600181019050611a3f565b5085935050505092915050565b600060a0830160008301518482036000860152611a968282611a1b565b9150506020830151611aab60208601826118e9565b506040830151611abe60408601826118e9565b506060830151611ad160608601826118e9565b506080830151611ae460808601826118e9565b508091505092915050565b60006020820190508181036000830152611b098184611a79565b905092915050565b600082825260208201905092915050565b7f75736572206d75737420626520746865206f776e6572206f662074686520746f60008201527f6b656e0000000000000000000000000000000000000000000000000000000000602082015250565b6000611b7e602383611b11565b9150611b8982611b22565b604082019050919050565b60006020820190508181036000830152611bad81611b71565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611bee8261153f565b9150611bf98361153f565b9250828201905080821115611c1157611c10611bb4565b5b92915050565b6000611c228261153f565b915060008203611c3557611c34611bb4565b5b600182039050919050565b6000606082019050611c55600083018661185d565b611c62602083018561185d565b611c6f6040830184611549565b949350505050565b6000604082019050611c8c600083018561185d565b611c996020830184611549565b9392505050565b611ca981611887565b8114611cb457600080fd5b50565b600081519050611cc681611ca0565b92915050565b600060208284031215611ce257611ce161157d565b5b6000611cf084828501611cb7565b91505092915050565b600081519050611d08816115b9565b92915050565b600060208284031215611d2457611d2361157d565b5b6000611d3284828501611cf9565b91505092915050565b6000611d468261153f565b9150611d518361153f565b9250828202611d5f8161153f565b91508282048414831517611d7657611d75611bb4565b5b5092915050565b600081519050611d8c816115e5565b92915050565b600060208284031215611da857611da761157d565b5b6000611db684828501611d7d565b91505092915050565b6000611dca8261153f565b9150611dd58361153f565b9250828203905081811115611ded57611dec611bb4565b5b92915050565b7f546f74616c20616d6f756e74206f66207265776172647320697320746f6f206860008201527f6967680000000000000000000000000000000000000000000000000000000000602082015250565b6000611e4f602383611b11565b9150611e5a82611df3565b604082019050919050565b60006020820190508181036000830152611e7e81611e42565b9050919050565b7f596f752068617665206e6f207265776172647320746f20636c61696d00000000600082015250565b6000611ebb601c83611b11565b9150611ec682611e85565b602082019050919050565b60006020820190508181036000830152611eea81611eae565b9050919050565b7f4e6f7420656e6f75676820746f6b656e73000000000000000000000000000000600082015250565b6000611f27601183611b11565b9150611f3282611ef1565b602082019050919050565b60006020820190508181036000830152611f5681611f1a565b9050919050565b7f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b6000611fb9602683611b11565b9150611fc482611f5d565b604082019050919050565b60006020820190508181036000830152611fe881611fac565b9050919050565b7f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572600082015250565b6000612025602083611b11565b915061203082611fef565b602082019050919050565b6000602082019050818103600083015261205481612018565b9050919050565b7f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00600082015250565b6000612091601f83611b11565b915061209c8261205b565b602082019050919050565b600060208201905081810360008301526120c081612084565b9050919050565b7f5061757361626c653a2070617573656400000000000000000000000000000000600082015250565b60006120fd601083611b11565b9150612108826120c7565b602082019050919050565b6000602082019050818103600083015261212c816120f0565b9050919050565b7f5061757361626c653a206e6f7420706175736564000000000000000000000000600082015250565b6000612169601483611b11565b915061217482612133565b602082019050919050565b600060208201905081810360008301526121988161215c565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60006121d98261153f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff820361220b5761220a611bb4565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fdfea2646970667358221220357b0fa8c0ccfa949e702f344c04cc83fd5d89349ca03d2242a2dfe26b49deb564736f6c63430008120033
Verified Source Code Full Match
Compiler: v0.8.18+commit.87f61d96
EVM: paris
Optimization: No
StakingSPRV2.sol 158 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
contract StakingSPRV2 is Ownable, ERC721Holder, ReentrancyGuard, Pausable {
IERC721 private stakingToken; // Sheepoori NFT
IERC20 private rewardToken; // HANePlatform token
constructor(address _stakingToken, address _rewardToken) onlyOwner {
stakingToken = IERC721(_stakingToken);
rewardToken = IERC20(_rewardToken);
}
struct Staker {
uint256[] tokenIds; // Stacked NFT tokenID
uint256 totalReward; // The total amount of HAN Token received as reward
uint256 unclaimedRewards; // The accumulated amount of HAN token before "CLAIM"
uint256 countStaked; // The amount of NFT tokenID staked
uint256 timeOfLastUpdate; // Last updated time by NFT tokenID
}
uint256 public constant rewardTokenPerStakingToken = 1157407407407; // Quantity of HAN tokens rewarded per NFT tokenID
uint256[] private totalTokenIds;
mapping(uint256 => address) public tokenOwner; // Return owner address when NFT tokenID is entered
mapping(address => Staker) private stakers;
// ------------------ View Functions ------------------ //
function getStakerData(address _user) public view returns (Staker memory) {
return stakers[_user];
}
function getTotalTokenIds() public view returns (uint256[] memory) {
return totalTokenIds;
}
// ------------------ Transaction Functions ------------------ //
// "STAKE" function
function stake(uint256 _tokenId) public nonReentrant whenNotPaused {
require(stakingToken.ownerOf(_tokenId) == msg.sender, "user must be the owner of the token");
require(rewardToken.balanceOf(address(this)) - 365 days * (totalTokenIds.length * rewardTokenPerStakingToken) > 365 days * rewardTokenPerStakingToken, "Total amount of rewards is too high");
Staker storage staker = stakers[msg.sender];
if (staker.countStaked == 0) {
_stake(_tokenId);
} else {
staker.unclaimedRewards += calculateRewards(msg.sender);
_stake(_tokenId);
}
}
function _stake(uint256 _tokenId) internal {
Staker storage staker = stakers[msg.sender];
staker.timeOfLastUpdate = block.timestamp;
tokenOwner[_tokenId] = msg.sender;
staker.countStaked += 1;
totalTokenIds.push(_tokenId);
staker.tokenIds.push(_tokenId);
stakingToken.safeTransferFrom(msg.sender, address(this), _tokenId);
emit Staked(msg.sender, _tokenId);
}
// "UNSTAKE" function
function unStake(uint256 _tokenId) public nonReentrant {
Staker storage staker = stakers[msg.sender];
require(tokenOwner[_tokenId] == msg.sender, "user must be the owner of the token");
staker.unclaimedRewards += calculateRewards(msg.sender);
staker.timeOfLastUpdate = block.timestamp;
tokenOwner[_tokenId] = address(0);
staker.countStaked--;
removeByValue(_tokenId, staker.tokenIds);
removeByValue(_tokenId, totalTokenIds);
stakingToken.safeTransferFrom(address(this), msg.sender, _tokenId);
emit Unstaked(msg.sender, _tokenId);
}
// "CLAIM" function
function claimReward() public nonReentrant {
Staker storage staker = stakers[msg.sender];
uint256 rewards = calculateRewards(msg.sender) + staker.unclaimedRewards;
require(rewards > 0, "You have no rewards to claim");
require(rewards < rewardToken.balanceOf(address(this)), "Not enough tokens");
staker.totalReward += rewards;
staker.timeOfLastUpdate = block.timestamp;
staker.unclaimedRewards = 0;
rewardToken.transfer(msg.sender, rewards);
emit RewardPaid(msg.sender, rewards);
}
// ------------------ Admin ------------------ //
// Pause Staking
function pause() public onlyOwner {
_pause();
}
function unpause() public onlyOwner {
_unpause();
}
function recoverERC20(address _tokenAddress, uint256 _tokenAmount) external onlyOwner {
IERC20(_tokenAddress).transfer(msg.sender, _tokenAmount);
emit RecoveredERC20(_tokenAddress, _tokenAmount);
}
function recoverERC721(address _tokenAddress, uint256 _tokenId) external onlyOwner {
IERC721(_tokenAddress).safeTransferFrom(address(this), msg.sender, _tokenId);
emit RecoveredERC721(_tokenAddress, _tokenId);
}
// ------------------ Private Functions ------------------ //
// Reward amount check function
function calculateRewards(address _user) private view returns (uint256) {
Staker storage staker = stakers[_user];
uint256 reward;
uint256 stakedTime = block.timestamp - staker.timeOfLastUpdate;
reward = stakedTime * (staker.countStaked * rewardTokenPerStakingToken);
return reward;
}
function find(uint256 value, uint256[] storage tokenIds) private view returns (uint256) {
uint256 i = 0;
while (tokenIds[i] != value) {
i++;
}
return i;
}
function removeByValue(uint256 value, uint256[] storage tokenIds) private {
uint256 i = find(value, tokenIds);
removeByIndex(i, tokenIds);
}
function removeByIndex(uint256 i, uint256[] storage tokenIds) private {
while (i < tokenIds.length - 1) {
tokenIds[i] = tokenIds[i + 1];
i++;
}
tokenIds.pop();
}
// ------------------ Event ------------------ //
event Unstaked(address owner, uint256 tokenId);
event Staked(address owner, uint256 tokenId);
event RewardPaid(address indexed user, uint256 reward);
event RecoveredERC20(address token, uint256 amount);
event RecoveredERC721(address token, uint256 tokenId);
}
Context.sol 24 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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;
}
}
Ownable.sol 83 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../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.
*
* By default, the owner account will be the one that deploys the contract. 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;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @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 {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
}
Pausable.sol 105 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
IERC20.sol 78 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 amount) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
IERC721.sol 132 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../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 caller.
*
* 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);
}
ReentrancyGuard.sol 77 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @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 27 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @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 23 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/utils/ERC721Holder.sol)
pragma solidity ^0.8.0;
import "../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}.
*/
contract ERC721Holder is IERC721Receiver {
/**
* @dev See {IERC721Receiver-onERC721Received}.
*
* Always returns `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}
}
Read Contract
getStakerData 0xc601f352 → tuple
getTotalTokenIds 0x616351b1 → uint256[]
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
rewardTokenPerStakingToken 0x1126ce9a → uint256
tokenOwner 0x1caaa487 → address
Write Contract 10 functions
These functions modify contract state and require a wallet transaction to execute.
claimReward 0xb88a802f
No parameters
onERC721Received 0x150b7a02
address
address
uint256
bytes
returns: bytes4
pause 0x8456cb59
No parameters
recoverERC20 0x8980f11f
address _tokenAddress
uint256 _tokenAmount
recoverERC721 0x819d4cc6
address _tokenAddress
uint256 _tokenId
renounceOwnership 0x715018a6
No parameters
stake 0xa694fc3a
uint256 _tokenId
transferOwnership 0xf2fde38b
address newOwner
unStake 0x5d3eea91
uint256 _tokenId
unpause 0x3f4ba83a
No parameters
Recent Transactions
No transactions found for this address