More Info
Private Name Tags
ContractCreator
Latest 25 from a total of 107 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Claim | 21247323 | 3 days ago | IN | 0 ETH | 0.00060356 | ||||
Unstake | 21217941 | 8 days ago | IN | 0 ETH | 0.00085201 | ||||
Unstake | 21180108 | 13 days ago | IN | 0 ETH | 0.00461358 | ||||
Unstake | 21172024 | 14 days ago | IN | 0 ETH | 0.00242677 | ||||
Unstake | 21171288 | 14 days ago | IN | 0 ETH | 0.0019657 | ||||
Unstake | 21168861 | 14 days ago | IN | 0 ETH | 0.00139397 | ||||
Claim | 21158174 | 16 days ago | IN | 0 ETH | 0.00173665 | ||||
Unstake | 21124767 | 21 days ago | IN | 0 ETH | 0.00029732 | ||||
Stake | 21109464 | 23 days ago | IN | 0 ETH | 0.00057866 | ||||
Unstake | 21106869 | 23 days ago | IN | 0 ETH | 0.00044481 | ||||
Stake | 21106294 | 23 days ago | IN | 0 ETH | 0.00041571 | ||||
Unstake | 21105895 | 23 days ago | IN | 0 ETH | 0.00007171 | ||||
Unstake | 21094452 | 25 days ago | IN | 0 ETH | 0.00081982 | ||||
Stake | 21094208 | 25 days ago | IN | 0 ETH | 0.00236338 | ||||
Stake | 21087729 | 26 days ago | IN | 0 ETH | 0.00131111 | ||||
Stake | 21083760 | 26 days ago | IN | 0 ETH | 0.00094822 | ||||
Unstake | 21082010 | 26 days ago | IN | 0 ETH | 0.00027075 | ||||
Claim | 21079637 | 27 days ago | IN | 0 ETH | 0.00151297 | ||||
Stake | 21079591 | 27 days ago | IN | 0 ETH | 0.00151657 | ||||
Unstake | 21079423 | 27 days ago | IN | 0 ETH | 0.00203812 | ||||
Unstake | 21079358 | 27 days ago | IN | 0 ETH | 0.00070207 | ||||
Claim | 21079346 | 27 days ago | IN | 0 ETH | 0.00115974 | ||||
Claim | 21079142 | 27 days ago | IN | 0 ETH | 0.00183581 | ||||
Claim | 21078301 | 27 days ago | IN | 0 ETH | 0.00059346 | ||||
Claim | 21071728 | 28 days ago | IN | 0 ETH | 0.0008128 |
Latest 25 internal transactions (View All)
Advanced mode:
Parent Transaction Hash | Block | From | To | |||
---|---|---|---|---|---|---|
21247323 | 3 days ago | 0.02423577 ETH | ||||
21232810 | 5 days ago | 0.00048576 ETH | ||||
21232810 | 5 days ago | 0.00072864 ETH | ||||
21221508 | 7 days ago | 0.00048086 ETH | ||||
21221508 | 7 days ago | 0.0007213 ETH | ||||
21221364 | 7 days ago | 0.00048105 ETH | ||||
21221364 | 7 days ago | 0.00072157 ETH | ||||
21221364 | 7 days ago | 0.00048105 ETH | ||||
21221364 | 7 days ago | 0.00072157 ETH | ||||
21221364 | 7 days ago | 0.00048105 ETH | ||||
21221364 | 7 days ago | 0.00072157 ETH | ||||
21221364 | 7 days ago | 0.00048105 ETH | ||||
21221364 | 7 days ago | 0.00072157 ETH | ||||
21221364 | 7 days ago | 0.00048105 ETH | ||||
21221364 | 7 days ago | 0.00072157 ETH | ||||
21221361 | 7 days ago | 0.00048105 ETH | ||||
21221361 | 7 days ago | 0.00072157 ETH | ||||
21221361 | 7 days ago | 0.00048105 ETH | ||||
21221361 | 7 days ago | 0.00072157 ETH | ||||
21221361 | 7 days ago | 0.00048105 ETH | ||||
21221361 | 7 days ago | 0.00072157 ETH | ||||
21221361 | 7 days ago | 0.00048105 ETH | ||||
21221361 | 7 days ago | 0.00072157 ETH | ||||
21221361 | 7 days ago | 0.00048105 ETH | ||||
21221361 | 7 days ago | 0.00072157 ETH |
Loading...
Loading
Contract Name:
TokenStaking
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 200 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED pragma solidity ^0.8.20; interface IERC20 { function totalSupply() external view returns (uint256); function balanceOf(address account) external view returns (uint256); function transfer(address recipient, uint256 amount) external returns (bool); function allowance(address owner, address spender) external view returns (uint256); function approve(address spender, uint256 amount) external returns (bool); function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); function burn(uint256 value) external; event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); } contract TokenStaking { IERC20 public taxFarmingToken; uint256 public totalStaked; // total token staked uint256 public totalRewards; // total rewards received by the contract uint256 private accumulatedRewardsPerToken = 1; // act as a price entry for new staker, the delta between this variable entry and exit is the effective rewards per token uint256 private constant DECIMALS = 1e12; // floor precision protection decimals struct Stake { uint256 tokensStaked; uint256 accumulatedRewardsPerToken; } mapping(address => Stake) public stakersInfos; mapping(address => uint256) public lastTx; // last tx block of stakers, used to avoid reentrancy and flashloans attacks uint256 private constant LOCK_PERIOD = 7 days; mapping(address => uint256) public lastClaimTime; event TokenStaked(address indexed user, uint256 amount, uint256 accumulatedRewardsPerToken); event TokenUnstaked(address indexed user, uint256 amount, uint256 accumulatedRewardsPerToken); constructor(address _taxFarmingToken) { taxFarmingToken = IERC20(_taxFarmingToken); } // prevent user to use any function again in this block modifier blockUser(address user) { require(lastTx[user] != block.number, "User blocked"); lastTx[user] = block.number; _; } function stake(uint256 amount) external blockUser(msg.sender) { if (amount == 0) return; address user = msg.sender; if (stakersInfos[user].tokensStaked == 0) { stakersInfos[user].accumulatedRewardsPerToken = accumulatedRewardsPerToken; } else { _claim(user); } taxFarmingToken.transferFrom(user, address(this), amount); totalStaked += amount; stakersInfos[user].tokensStaked += amount; emit TokenStaked(user, amount, accumulatedRewardsPerToken); } function unstake(uint256 amount) external blockUser(msg.sender) { address user = msg.sender; require(block.timestamp >= lastClaimTime[user] + LOCK_PERIOD, "Locked for 7 days after last claim"); if (amount == 0 || stakersInfos[user].tokensStaked == 0) return; require(stakersInfos[user].tokensStaked >= amount, "Not enough staked tokens"); stakersInfos[user].tokensStaked -= amount; totalStaked -= amount; taxFarmingToken.transfer(user, amount); emit TokenUnstaked(user, amount, accumulatedRewardsPerToken); } function claim() external blockUser(msg.sender) { _claim(msg.sender); } function _claim(address user) private { uint256 rewards = getUserRewards(user); stakersInfos[user].accumulatedRewardsPerToken = accumulatedRewardsPerToken; if (rewards == 0) return; (bool success,) = payable(user).call{value: rewards}(""); require(success, "Unable to claim rewards"); lastClaimTime[user] = block.timestamp; } function getUserRewards(address user) public view returns (uint256) { uint256 rewardsPerToken = accumulatedRewardsPerToken - stakersInfos[user].accumulatedRewardsPerToken; uint256 rewards = (rewardsPerToken * stakersInfos[user].tokensStaked) / DECIMALS; return rewards; } receive() external payable { require(totalStaked != 0, "No stakers"); uint256 rewardsPerToken = (msg.value * DECIMALS) / totalStaked; accumulatedRewardsPerToken += rewardsPerToken; totalRewards += msg.value; } }
{ "remappings": [ "forge-std/=lib/forge-std/src/", "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/", "ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/", "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "shanghai", "viaIR": false, "libraries": {} }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_taxFarmingToken","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accumulatedRewardsPerToken","type":"uint256"}],"name":"TokenStaked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"accumulatedRewardsPerToken","type":"uint256"}],"name":"TokenUnstaked","type":"event"},{"inputs":[],"name":"claim","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"}],"name":"getUserRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastClaimTime","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"lastTx","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"stake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"stakersInfos","outputs":[{"internalType":"uint256","name":"tokensStaked","type":"uint256"},{"internalType":"uint256","name":"accumulatedRewardsPerToken","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"taxFarmingToken","outputs":[{"internalType":"contract IERC20","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalRewards","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalStaked","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"unstake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60806040526001600355348015610014575f80fd5b50604051610a18380380610a1883398101604081905261003391610057565b5f80546001600160a01b0319166001600160a01b0392909216919091179055610084565b5f60208284031215610067575f80fd5b81516001600160a01b038116811461007d575f80fd5b9392505050565b610987806100915f395ff3fe608060405260043610610092575f3560e01c80637931cef5116100575780637931cef5146101e1578063817b1cd214610228578063a62b48ce1461023d578063a694fc3a14610268578063b77cf9c614610287575f80fd5b8063078b0fb71461012f5780630e15561a146101615780632e17de781461017657806342a9763f146101975780634e71d92d146101cd575f80fd5b3661012b576001545f036100da5760405162461bcd60e51b815260206004820152600a6024820152694e6f207374616b65727360b01b60448201526064015b60405180910390fd5b6001545f906100ee64e8d4a5100034610866565b6100f89190610883565b90508060035f82825461010b91906108a2565b925050819055503460025f82825461012391906108a2565b925050819055005b5f80fd5b34801561013a575f80fd5b5061014e6101493660046108b5565b6102b2565b6040519081526020015b60405180910390f35b34801561016c575f80fd5b5061014e60025481565b348015610181575f80fd5b506101956101903660046108e2565b61031a565b005b3480156101a2575f80fd5b505f546101b5906001600160a01b031681565b6040516001600160a01b039091168152602001610158565b3480156101d8575f80fd5b50610195610579565b3480156101ec575f80fd5b506102136101fb3660046108b5565b60046020525f90815260409020805460019091015482565b60408051928352602083019190915201610158565b348015610233575f80fd5b5061014e60015481565b348015610248575f80fd5b5061014e6102573660046108b5565b60056020525f908152604090205481565b348015610273575f80fd5b506101956102823660046108e2565b6105cd565b348015610292575f80fd5b5061014e6102a13660046108b5565b60066020525f908152604090205481565b6001600160a01b0381165f9081526004602052604081206001015460035482916102db916108f9565b6001600160a01b0384165f908152600460205260408120549192509064e8d4a51000906103089084610866565b6103129190610883565b949350505050565b335f818152600560205260409020544390036103485760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f908152600560209081526040808320439055338084526006909252909120546103809062093a80906108a2565b4210156103da5760405162461bcd60e51b815260206004820152602260248201527f4c6f636b656420666f7220372064617973206166746572206c61737420636c61604482015261696d60f01b60648201526084016100d1565b8215806103fc57506001600160a01b0381165f90815260046020526040902054155b1561040657505050565b6001600160a01b0381165f9081526004602052604090205483111561046d5760405162461bcd60e51b815260206004820152601860248201527f4e6f7420656e6f756768207374616b656420746f6b656e73000000000000000060448201526064016100d1565b6001600160a01b0381165f90815260046020526040812080548592906104949084906108f9565b925050819055508260015f8282546104ac91906108f9565b90915550505f5460405163a9059cbb60e01b81526001600160a01b038381166004830152602482018690529091169063a9059cbb906044016020604051808303815f875af1158015610500573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105249190610932565b50806001600160a01b03167f563fc70fca9d440d883299c76a721644d5aca7c45df98aeb5292c4cb823579bf8460035460405161056b929190918252602082015260400190565b60405180910390a2505b5050565b335f818152600560205260409020544390036105a75760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f9081526005602052604090204390556105ca3361075d565b50565b335f818152600560205260409020544390036105fb5760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f908152600560205260409020439055811561057557335f818152600460205260408120549003610653576003546001600160a01b0382165f9081526004602052604090206001015561065c565b61065c8161075d565b5f546040516323b872dd60e01b81526001600160a01b03838116600483015230602483015260448201869052909116906323b872dd906064016020604051808303815f875af11580156106b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106d59190610932565b508260015f8282546106e791906108a2565b90915550506001600160a01b0381165f90815260046020526040812080548592906107139084906108a2565b90915550506003546040516001600160a01b038316917f6173e4d2d9dd52aae0ed37afed3adcf924a490639b759ca93d32dc43366c17d29161056b91878252602082015260400190565b5f610767826102b2565b6003546001600160a01b0384165f90815260046020526040812060010191909155909150819003610796575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f81146107df576040519150601f19603f3d011682016040523d82523d5f602084013e6107e4565b606091505b50509050806108355760405162461bcd60e51b815260206004820152601760248201527f556e61626c6520746f20636c61696d207265776172647300000000000000000060448201526064016100d1565b50506001600160a01b03165f908152600660205260409020429055565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761087d5761087d610852565b92915050565b5f8261089d57634e487b7160e01b5f52601260045260245ffd5b500490565b8082018082111561087d5761087d610852565b5f602082840312156108c5575f80fd5b81356001600160a01b03811681146108db575f80fd5b9392505050565b5f602082840312156108f2575f80fd5b5035919050565b8181038181111561087d5761087d610852565b6020808252600c908201526b155cd95c88189b1bd8dad95960a21b604082015260600190565b5f60208284031215610942575f80fd5b815180151581146108db575f80fdfea2646970667358221220c1084375966d99077ed6fc405de6d80ca2c3c929474f7a47060f056997920a7f64736f6c63430008140033000000000000000000000000306a4b5b553c7d5cd4440e1cf4f897521c38cdaa
Deployed Bytecode
0x608060405260043610610092575f3560e01c80637931cef5116100575780637931cef5146101e1578063817b1cd214610228578063a62b48ce1461023d578063a694fc3a14610268578063b77cf9c614610287575f80fd5b8063078b0fb71461012f5780630e15561a146101615780632e17de781461017657806342a9763f146101975780634e71d92d146101cd575f80fd5b3661012b576001545f036100da5760405162461bcd60e51b815260206004820152600a6024820152694e6f207374616b65727360b01b60448201526064015b60405180910390fd5b6001545f906100ee64e8d4a5100034610866565b6100f89190610883565b90508060035f82825461010b91906108a2565b925050819055503460025f82825461012391906108a2565b925050819055005b5f80fd5b34801561013a575f80fd5b5061014e6101493660046108b5565b6102b2565b6040519081526020015b60405180910390f35b34801561016c575f80fd5b5061014e60025481565b348015610181575f80fd5b506101956101903660046108e2565b61031a565b005b3480156101a2575f80fd5b505f546101b5906001600160a01b031681565b6040516001600160a01b039091168152602001610158565b3480156101d8575f80fd5b50610195610579565b3480156101ec575f80fd5b506102136101fb3660046108b5565b60046020525f90815260409020805460019091015482565b60408051928352602083019190915201610158565b348015610233575f80fd5b5061014e60015481565b348015610248575f80fd5b5061014e6102573660046108b5565b60056020525f908152604090205481565b348015610273575f80fd5b506101956102823660046108e2565b6105cd565b348015610292575f80fd5b5061014e6102a13660046108b5565b60066020525f908152604090205481565b6001600160a01b0381165f9081526004602052604081206001015460035482916102db916108f9565b6001600160a01b0384165f908152600460205260408120549192509064e8d4a51000906103089084610866565b6103129190610883565b949350505050565b335f818152600560205260409020544390036103485760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f908152600560209081526040808320439055338084526006909252909120546103809062093a80906108a2565b4210156103da5760405162461bcd60e51b815260206004820152602260248201527f4c6f636b656420666f7220372064617973206166746572206c61737420636c61604482015261696d60f01b60648201526084016100d1565b8215806103fc57506001600160a01b0381165f90815260046020526040902054155b1561040657505050565b6001600160a01b0381165f9081526004602052604090205483111561046d5760405162461bcd60e51b815260206004820152601860248201527f4e6f7420656e6f756768207374616b656420746f6b656e73000000000000000060448201526064016100d1565b6001600160a01b0381165f90815260046020526040812080548592906104949084906108f9565b925050819055508260015f8282546104ac91906108f9565b90915550505f5460405163a9059cbb60e01b81526001600160a01b038381166004830152602482018690529091169063a9059cbb906044016020604051808303815f875af1158015610500573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105249190610932565b50806001600160a01b03167f563fc70fca9d440d883299c76a721644d5aca7c45df98aeb5292c4cb823579bf8460035460405161056b929190918252602082015260400190565b60405180910390a2505b5050565b335f818152600560205260409020544390036105a75760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f9081526005602052604090204390556105ca3361075d565b50565b335f818152600560205260409020544390036105fb5760405162461bcd60e51b81526004016100d19061090c565b6001600160a01b0381165f908152600560205260409020439055811561057557335f818152600460205260408120549003610653576003546001600160a01b0382165f9081526004602052604090206001015561065c565b61065c8161075d565b5f546040516323b872dd60e01b81526001600160a01b03838116600483015230602483015260448201869052909116906323b872dd906064016020604051808303815f875af11580156106b1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106d59190610932565b508260015f8282546106e791906108a2565b90915550506001600160a01b0381165f90815260046020526040812080548592906107139084906108a2565b90915550506003546040516001600160a01b038316917f6173e4d2d9dd52aae0ed37afed3adcf924a490639b759ca93d32dc43366c17d29161056b91878252602082015260400190565b5f610767826102b2565b6003546001600160a01b0384165f90815260046020526040812060010191909155909150819003610796575050565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f81146107df576040519150601f19603f3d011682016040523d82523d5f602084013e6107e4565b606091505b50509050806108355760405162461bcd60e51b815260206004820152601760248201527f556e61626c6520746f20636c61696d207265776172647300000000000000000060448201526064016100d1565b50506001600160a01b03165f908152600660205260409020429055565b634e487b7160e01b5f52601160045260245ffd5b808202811582820484141761087d5761087d610852565b92915050565b5f8261089d57634e487b7160e01b5f52601260045260245ffd5b500490565b8082018082111561087d5761087d610852565b5f602082840312156108c5575f80fd5b81356001600160a01b03811681146108db575f80fd5b9392505050565b5f602082840312156108f2575f80fd5b5035919050565b8181038181111561087d5761087d610852565b6020808252600c908201526b155cd95c88189b1bd8dad95960a21b604082015260600190565b5f60208284031215610942575f80fd5b815180151581146108db575f80fdfea2646970667358221220c1084375966d99077ed6fc405de6d80ca2c3c929474f7a47060f056997920a7f64736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000306a4b5b553c7d5cd4440e1cf4f897521c38cdaa
-----Decoded View---------------
Arg [0] : _taxFarmingToken (address): 0x306a4b5b553c7d5Cd4440e1cF4F897521c38cdaA
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000306a4b5b553c7d5cd4440e1cf4f897521c38cdaa
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|---|---|---|---|---|
ETH | Ether (ETH) | 100.00% | $3,322.56 | 4.6216 | $15,355.5 |
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.