Transactions
Token Transfers
Tokens
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- RewardSystem
- Optimization enabled
- true
- Compiler version
- v0.8.20+commit.a1b79de6
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-05-03T22:42:31.477286Z
Constructor Arguments
0x000000000000000000000000c985a14a3b518924e69d926df80afddbcec42ee9
Arg [0] (address) : 0xc985a14a3b518924e69d926df80afddbcec42ee9
Contract source code
// SPDX-License-Identifier: MIT
// File: @openzeppelin/contracts/token/ERC20/IERC20.sol
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity 0.8.20;
/**
* @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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}
// File: @openzeppelin/contracts/security/ReentrancyGuard.sol
// 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;
}
}
/*
https://t.me/OAT_PL
//Experimental Proof of concept.
//Tokens can be locked in the RewardSystem Contract for Minted Rewards
//Nodes can potentially be used as a fill-in Oracle Price feed on Networks not supported by Large Oracle Projects
//Use at your own risk
*/
contract RewardSystem is ReentrancyGuard {
IERC20 public token;
mapping(address => uint256) public lockedBalances;
mapping(address => uint256) public lastLockedTime;
address[] public stakers;
uint256 public totalLocked;
address constant BURN_ADDRESS = 0x0000000000000000000000000000000000000369; // Burn address
uint256 public constant LOCK_PERIOD = 14 days; // 14-day lock period for unlocking tokens
event Locked(address indexed user, uint256 amount);
event Unlocked(address indexed user, uint256 amount);
event RewardDistributed(address indexed staker, uint256 reward);
event RewardsBurned(uint256 amount);
constructor(address _token) {
token = IERC20(_token);
}
function lockTokens(uint256 amount) external nonReentrant {
require(token.transferFrom(msg.sender, address(this), amount), "Transfer failed");
if (lockedBalances[msg.sender] == 0) {
stakers.push(msg.sender); // Add to stakers array if not already a staker
}
lockedBalances[msg.sender] += amount;
totalLocked += amount;
lastLockedTime[msg.sender] = block.timestamp; // Update the last locked time
emit Locked(msg.sender, amount);
}
function unlockTokens() external nonReentrant {
require(block.timestamp >= lastLockedTime[msg.sender] + LOCK_PERIOD, "Tokens are locked, cannot unlock yet");
uint256 balance = lockedBalances[msg.sender];
require(balance > 0, "No tokens locked");
require(token.transfer(msg.sender, balance), "Transfer failed");
totalLocked -= balance;
lockedBalances[msg.sender] = 0;
removeStaker(msg.sender); // Remove from stakers list
emit Unlocked(msg.sender, balance);
}
function distributeRewards(uint256 rewardAmount) external nonReentrant {
if (totalLocked == 0) {
token.transfer(BURN_ADDRESS, rewardAmount);
emit RewardsBurned(rewardAmount);
return;
}
for (uint i = 0; i < stakers.length; i++) {
address staker = stakers[i];
uint256 balance = lockedBalances[staker];
if (balance > 0) {
uint256 reward = (balance * rewardAmount) / totalLocked;
token.transfer(staker, reward);
emit RewardDistributed(staker, reward);
}
}
}
function removeStaker(address staker) private {
for (uint i = 0; i < stakers.length; i++) {
if (stakers[i] == staker) {
stakers[i] = stakers[stakers.length - 1];
stakers.pop();
break;
}
}
}
}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_token","internalType":"address"}]},{"type":"event","name":"Locked","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RewardDistributed","inputs":[{"type":"address","name":"staker","internalType":"address","indexed":true},{"type":"uint256","name":"reward","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"RewardsBurned","inputs":[{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Unlocked","inputs":[{"type":"address","name":"user","internalType":"address","indexed":true},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"LOCK_PERIOD","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"distributeRewards","inputs":[{"type":"uint256","name":"rewardAmount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lastLockedTime","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"lockTokens","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"lockedBalances","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"stakers","inputs":[{"type":"uint256","name":"","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20"}],"name":"token","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"totalLocked","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"unlockTokens","inputs":[]}]
Contract Creation Code
0x608060405234801561000f575f80fd5b50604051610a62380380610a6283398101604081905261002e91610057565b60015f81905580546001600160a01b0319166001600160a01b0392909216919091179055610084565b5f60208284031215610067575f80fd5b81516001600160a01b038116811461007d575f80fd5b9392505050565b6109d1806100915f395ff3fe608060405234801561000f575f80fd5b5060043610610090575f3560e01c80636e27d889116100635780636e27d889146100ee578063cf97502014610101578063f968f49314610120578063fc0c546a14610128578063fd5e6dd114610153575f80fd5b80630483a7f6146100945780631820cabb146100c657806356891412146100d057806359974e38146100d9575b5f80fd5b6100b36100a2366004610882565b60026020525f908152604090205481565b6040519081526020015b60405180910390f35b6100b36212750081565b6100b360055481565b6100ec6100e73660046108af565b610166565b005b6100ec6100fc3660046108af565b610369565b6100b361010f366004610882565b60036020525f908152604090205481565b6100ec610512565b60015461013b906001600160a01b031681565b6040516001600160a01b0390911681526020016100bd565b61013b6101613660046108af565b610700565b61016e610728565b6005545f036102245760015460405163a9059cbb60e01b81526103696004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303815f875af11580156101c7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101eb91906108c6565b506040518181527f44d5cd18c37b86a3423952287006d9550ab3cff404d6e899d5499d9ef87100b59060200160405180910390a161035d565b5f5b60045481101561035b575f60048281548110610244576102446108e5565b5f9182526020808320909101546001600160a01b031680835260029091526040909120549091508015610346576005545f90610280868461090d565b61028a919061092a565b60015460405163a9059cbb60e01b81526001600160a01b0386811660048301526024820184905292935091169063a9059cbb906044016020604051808303815f875af11580156102dc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030091906108c6565b50826001600160a01b03167fe34918ff1c7084970068b53fd71ad6d8b04e9f15d3886cbf006443e6cdc52ea68260405161033c91815260200190565b60405180910390a2505b5050808061035390610949565b915050610226565b505b61036660015f55565b50565b610371610728565b6001546040516323b872dd60e01b8152336004820152306024820152604481018390526001600160a01b03909116906323b872dd906064016020604051808303815f875af11580156103c5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103e991906108c6565b61042c5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064015b60405180910390fd5b335f90815260026020526040812054900361048357600480546001810182555f919091527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0180546001600160a01b031916331790555b335f90815260026020526040812080548392906104a1908490610961565b925050819055508060055f8282546104b99190610961565b9091555050335f8181526003602052604090819020429055517f9f1ec8c880f76798e7b793325d625e9b60e4082a553c98f42b6cda368dd60008906105019084815260200190565b60405180910390a261036660015f55565b61051a610728565b335f90815260036020526040902054610537906212750090610961565b4210156105925760405162461bcd60e51b8152602060048201526024808201527f546f6b656e7320617265206c6f636b65642c2063616e6e6f7420756e6c6f636b604482015263081e595d60e21b6064820152608401610423565b335f90815260026020526040902054806105e15760405162461bcd60e51b815260206004820152601060248201526f139bc81d1bdad95b9cc81b1bd8dad95960821b6044820152606401610423565b60015460405163a9059cbb60e01b8152336004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303815f875af115801561062f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061065391906108c6565b6106915760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610423565b8060055f8282546106a29190610974565b9091555050335f818152600260205260408120556106bf9061077f565b60405181815233907f0f0bc5b519ddefdd8e5f9e6423433aa2b869738de2ae34d58ebc796fc749fa0d9060200160405180910390a2506106fe60015f55565b565b6004818154811061070f575f80fd5b5f918252602090912001546001600160a01b0316905081565b60025f54036107795760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610423565b60025f55565b5f5b60045481101561087e57816001600160a01b0316600482815481106107a8576107a86108e5565b5f918252602090912001546001600160a01b03160361086c57600480546107d190600190610974565b815481106107e1576107e16108e5565b5f91825260209091200154600480546001600160a01b03909216918390811061080c5761080c6108e5565b905f5260205f20015f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550600480548061084857610848610987565b5f8281526020902081015f1990810180546001600160a01b03191690550190555050565b8061087681610949565b915050610781565b5050565b5f60208284031215610892575f80fd5b81356001600160a01b03811681146108a8575f80fd5b9392505050565b5f602082840312156108bf575f80fd5b5035919050565b5f602082840312156108d6575f80fd5b815180151581146108a8575f80fd5b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610924576109246108f9565b92915050565b5f8261094457634e487b7160e01b5f52601260045260245ffd5b500490565b5f6001820161095a5761095a6108f9565b5060010190565b80820180821115610924576109246108f9565b81810381811115610924576109246108f9565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220de120efa0bc7628e0624a70332d6df94a425b0086837d56a4099682bf9a37ba364736f6c63430008140033000000000000000000000000c985a14a3b518924e69d926df80afddbcec42ee9
Deployed ByteCode
0x608060405234801561000f575f80fd5b5060043610610090575f3560e01c80636e27d889116100635780636e27d889146100ee578063cf97502014610101578063f968f49314610120578063fc0c546a14610128578063fd5e6dd114610153575f80fd5b80630483a7f6146100945780631820cabb146100c657806356891412146100d057806359974e38146100d9575b5f80fd5b6100b36100a2366004610882565b60026020525f908152604090205481565b6040519081526020015b60405180910390f35b6100b36212750081565b6100b360055481565b6100ec6100e73660046108af565b610166565b005b6100ec6100fc3660046108af565b610369565b6100b361010f366004610882565b60036020525f908152604090205481565b6100ec610512565b60015461013b906001600160a01b031681565b6040516001600160a01b0390911681526020016100bd565b61013b6101613660046108af565b610700565b61016e610728565b6005545f036102245760015460405163a9059cbb60e01b81526103696004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303815f875af11580156101c7573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101eb91906108c6565b506040518181527f44d5cd18c37b86a3423952287006d9550ab3cff404d6e899d5499d9ef87100b59060200160405180910390a161035d565b5f5b60045481101561035b575f60048281548110610244576102446108e5565b5f9182526020808320909101546001600160a01b031680835260029091526040909120549091508015610346576005545f90610280868461090d565b61028a919061092a565b60015460405163a9059cbb60e01b81526001600160a01b0386811660048301526024820184905292935091169063a9059cbb906044016020604051808303815f875af11580156102dc573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030091906108c6565b50826001600160a01b03167fe34918ff1c7084970068b53fd71ad6d8b04e9f15d3886cbf006443e6cdc52ea68260405161033c91815260200190565b60405180910390a2505b5050808061035390610949565b915050610226565b505b61036660015f55565b50565b610371610728565b6001546040516323b872dd60e01b8152336004820152306024820152604481018390526001600160a01b03909116906323b872dd906064016020604051808303815f875af11580156103c5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103e991906108c6565b61042c5760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b60448201526064015b60405180910390fd5b335f90815260026020526040812054900361048357600480546001810182555f919091527f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0180546001600160a01b031916331790555b335f90815260026020526040812080548392906104a1908490610961565b925050819055508060055f8282546104b99190610961565b9091555050335f8181526003602052604090819020429055517f9f1ec8c880f76798e7b793325d625e9b60e4082a553c98f42b6cda368dd60008906105019084815260200190565b60405180910390a261036660015f55565b61051a610728565b335f90815260036020526040902054610537906212750090610961565b4210156105925760405162461bcd60e51b8152602060048201526024808201527f546f6b656e7320617265206c6f636b65642c2063616e6e6f7420756e6c6f636b604482015263081e595d60e21b6064820152608401610423565b335f90815260026020526040902054806105e15760405162461bcd60e51b815260206004820152601060248201526f139bc81d1bdad95b9cc81b1bd8dad95960821b6044820152606401610423565b60015460405163a9059cbb60e01b8152336004820152602481018390526001600160a01b039091169063a9059cbb906044016020604051808303815f875af115801561062f573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061065391906108c6565b6106915760405162461bcd60e51b815260206004820152600f60248201526e151c985b9cd9995c8819985a5b1959608a1b6044820152606401610423565b8060055f8282546106a29190610974565b9091555050335f818152600260205260408120556106bf9061077f565b60405181815233907f0f0bc5b519ddefdd8e5f9e6423433aa2b869738de2ae34d58ebc796fc749fa0d9060200160405180910390a2506106fe60015f55565b565b6004818154811061070f575f80fd5b5f918252602090912001546001600160a01b0316905081565b60025f54036107795760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c006044820152606401610423565b60025f55565b5f5b60045481101561087e57816001600160a01b0316600482815481106107a8576107a86108e5565b5f918252602090912001546001600160a01b03160361086c57600480546107d190600190610974565b815481106107e1576107e16108e5565b5f91825260209091200154600480546001600160a01b03909216918390811061080c5761080c6108e5565b905f5260205f20015f6101000a8154816001600160a01b0302191690836001600160a01b03160217905550600480548061084857610848610987565b5f8281526020902081015f1990810180546001600160a01b03191690550190555050565b8061087681610949565b915050610781565b5050565b5f60208284031215610892575f80fd5b81356001600160a01b03811681146108a8575f80fd5b9392505050565b5f602082840312156108bf575f80fd5b5035919050565b5f602082840312156108d6575f80fd5b815180151581146108a8575f80fd5b634e487b7160e01b5f52603260045260245ffd5b634e487b7160e01b5f52601160045260245ffd5b8082028115828204841417610924576109246108f9565b92915050565b5f8261094457634e487b7160e01b5f52601260045260245ffd5b500490565b5f6001820161095a5761095a6108f9565b5060010190565b80820180821115610924576109246108f9565b81810381811115610924576109246108f9565b634e487b7160e01b5f52603160045260245ffdfea2646970667358221220de120efa0bc7628e0624a70332d6df94a425b0086837d56a4099682bf9a37ba364736f6c63430008140033