Address Contract Verified
Address
0xfb1c814370E85b8097e8B4373d3397bf08388Dac
Balance
0 ETH
Nonce
1
Code Size
6853 bytes
Creator
0xCe8C74b6...6ee1 at tx 0x3062ce44...4de043
Indexed Transactions
0
Contract Bytecode
6853 bytes
0x608060405234801561001057600080fd5b50600436106101fb5760003560e01c806372f702f31161011a578063bcd11014116100ad578063e70b9e271161007c578063e70b9e27146104a5578063e74b981b146104d0578063e941fa78146104e3578063f1229777146104ec578063f2fde38b146104ff57600080fd5b8063bcd1101414610464578063c4ae316814610477578063c7b9d5301461047f578063d0ed26ae1461049257600080fd5b8063a694fc3a116100e9578063a694fc3a14610422578063b66503cf14610435578063b6ac642a14610448578063bc063e1a1461045b57600080fd5b806372f702f3146103d35780637bb7bed1146103e65780638980f11f146103f95780638da5cb5b1461040c57600080fd5b806348e5d9f81161019257806367a527931161016157806367a527931461036e5780637035ab981461037757806370a08231146103a2578063715018a6146103cb57600080fd5b806348e5d9f8146102ab578063490ae210146103325780635c975abb14610345578063638634ee1461035b57600080fd5b80632e1a7d4d116101ce5780632e1a7d4d1461026a5780633d18b9121461027d5780633f695b4514610285578063469048401461029857600080fd5b806318160ddd146102005780631fe4a68614610217578063211dc32d146102425780632378bea614610255575b600080fd5b6007545b6040519081526020015b60405180910390f35b60095461022a906001600160a01b031681565b6040516001600160a01b03909116815260200161020e565b61020461025036600461191e565b610512565b610268610263366004611951565b6105ac565b005b61026861027836600461197b565b610683565b6102686108b3565b61026861029336600461191e565b610aa4565b600a5461022a906001600160a01b031681565b6102fb6102b9366004611994565b60036020819052600091825260409091208054600182015460028301549383015460048401546005909401546001600160a01b03909316949193919290919086565b604080516001600160a01b0390971687526020870195909552938501929092526060840152608083015260a082015260c00161020e565b61026861034036600461197b565b610b4c565b60015460ff16604051901515815260200161020e565b610204610369366004611994565b610bd6565b610204600b5481565b61020461038536600461191e565b600560209081526000928352604080842090915290825290205481565b6102046103b0366004611994565b6001600160a01b031660009081526008602052604090205490565b610268610c20565b60025461022a906001600160a01b031681565b61022a6103f436600461197b565b610c32565b610268610407366004611951565b610c5c565b60015461010090046001600160a01b031661022a565b61026861043036600461197b565b610d27565b610268610443366004611951565b610f52565b61026861045636600461197b565b61121b565b6102046101f481565b610204610472366004611994565b6112a5565b6102686112d1565b61026861048d366004611994565b611366565b6102686104a03660046119af565b61141f565b6102046104b336600461191e565b600660209081526000928352604080842090915290825290205481565b6102686104de366004611994565b6114bb565b610204600c5481565b6102046104fa366004611994565b611576565b61026861050d366004611994565b611628565b6001600160a01b038083166000818152600660209081526040808320948616808452948252808320549383526005825280832094835293905291822054670de0b6b3a76400009061056285611576565b61056c9190611a01565b6001600160a01b03861660009081526008602052604090205461058f9190611a14565b6105999190611a2b565b6105a39190611a4d565b90505b92915050565b6001600160a01b038281166000908152600360205260409020541633146105d257600080fd5b600081116106275760405162461bcd60e51b815260206004820181905260248201527f526577617264206475726174696f6e206d757374206265206e6f6e2d7a65726f60448201526064015b60405180910390fd5b6001600160a01b038216600081815260036020908152604091829020600101849055815192835282018390527fad2f86b01ed93b4b3a150d448c61a4f5d8d38075d3c0c64cc0a26fd6e1f4954591015b60405180910390a15050565b61068b611663565b3360005b600454811015610784576000600482815481106106ae576106ae611a60565b6000918252602090912001546001600160a01b031690506106ce81611576565b6001600160a01b0382166000908152600360205260409020600501556106f381610bd6565b6001600160a01b03808316600090815260036020526040902060040191909155831615610771576107248382610512565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b508061077c81611a76565b91505061068f565b50600082116107c95760405162461bcd60e51b8152602060048201526011602482015270043616e6e6f74207769746864726177203607c1b604482015260640161061e565b816007546107d79190611a01565b600755336000908152600860205260409020546107f5908390611a01565b33600090815260086020526040902055600c5415610858576000612710600c54846108209190611a14565b61082a9190611a2b565b600a5460025491925061084a916001600160a01b0390811691168361168d565b6108548184611a01565b9250505b60025461086f906001600160a01b0316338461168d565b60405182815233907f7084f5476618d8e60b11ef0d7d3f06914655adb8793e28ff7f018d4c76d505d5906020015b60405180910390a2506108b06001600055565b50565b6108bb611663565b3360005b6004548110156109b4576000600482815481106108de576108de611a60565b6000918252602090912001546001600160a01b031690506108fe81611576565b6001600160a01b03821660009081526003602052604090206005015561092381610bd6565b6001600160a01b038083166000908152600360205260409020600401919091558316156109a1576109548382610512565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b50806109ac81611a76565b9150506108bf565b5060005b600454811015610a96576000600482815481106109d7576109d7611a60565b60009182526020808320909101543383526006825260408084206001600160a01b03909216808552919092529120549091508015610a81573360008181526006602090815260408083206001600160a01b0387168085529252822091909155610a40918361168d565b6040518181526001600160a01b0383169033907f540798df468d7b23d11f156fdb954cb19ad414d150722a7b6d55ba369dea792e9060200160405180910390a35b50508080610a8e90611a76565b9150506109b8565b5050610aa26001600055565b565b60015461010090046001600160a01b03166001600160a01b0316336001600160a01b03161480610ade57506009546001600160a01b031633145b610b1e5760405162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015260640161061e565b6001600160a01b03918216600090815260036020526040902080546001600160a01b03191691909216179055565b610b546116f1565b6101f4811115610b955760405162461bcd60e51b815260206004820152600c60248201526b0cccaca40e8dede40d0d2ced60a31b604482015260640161061e565b600b5460408051918252602082018390527f828cf983933545af35b9ba46eec951db1cb4c5433c3ec403aeced2963c264790910160405180910390a1600b55565b6001600160a01b0381166000908152600360205260408120600201544210610c19576001600160a01b0382166000908152600360205260409020600201546105a6565b4292915050565b610c286116f1565b610aa26000611724565b60048181548110610c4257600080fd5b6000918252602090912001546001600160a01b0316905081565b610c646116f1565b6002546001600160a01b0390811690831603610cc25760405162461bcd60e51b815260206004820152601d60248201527f43616e6e6f74207769746864726177207374616b696e6720746f6b656e000000604482015260640161061e565b600154610ce89061010090046001600160a01b03166001600160a01b038416908361168d565b604080516001600160a01b0384168152602081018390527f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa289101610677565b610d2f611663565b610d3761177e565b3360005b600454811015610e3057600060048281548110610d5a57610d5a611a60565b6000918252602090912001546001600160a01b03169050610d7a81611576565b6001600160a01b038216600090815260036020526040902060050155610d9f81610bd6565b6001600160a01b03808316600090815260036020526040902060040191909155831615610e1d57610dd08382610512565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b5080610e2881611a76565b915050610d3b565b5060008211610e725760405162461bcd60e51b815260206004820152600e60248201526d043616e6e6f74207374616b6520360941b604482015260640161061e565b600b5415610ec7576000612710600b5484610e8d9190611a14565b610e979190611a2b565b600a54600254919250610eb9916001600160a01b0390811691339116846117a2565b610ec38184611a01565b9250505b81600754610ed59190611a4d565b60075533600090815260086020526040902054610ef3908390611a4d565b33600081815260086020526040902091909155600254610f20916001600160a01b039091169030856117a2565b60405182815233907f9e71bc8eea02a63969f509818f2dafb9254532904319f9dbda79b67bd34a5f3d9060200161089d565b6000805b60045481101561104b57600060048281548110610f7557610f75611a60565b6000918252602090912001546001600160a01b03169050610f9581611576565b6001600160a01b038216600090815260036020526040902060050155610fba81610bd6565b6001600160a01b0380831660009081526003602052604090206004019190915583161561103857610feb8382610512565b6001600160a01b0380851660008181526006602090815260408083209487168084529482528083209590955560038152848220600590810154938352815284822093825292909252919020555b508061104381611a76565b915050610f56565b506001600160a01b0383811660009081526003602052604090205416331461107257600080fd5b6110876001600160a01b0384163330856117a2565b6001600160a01b03831660009081526003602052604090206002015442106110f1576001600160a01b0383166000908152600360205260409020600101546110cf9083611a2b565b6001600160a01b03841660009081526003602081905260409091200155611195565b6001600160a01b038316600090815260036020526040812060020154611118904290611a01565b6001600160a01b038516600090815260036020819052604082200154919250906111429083611a14565b6001600160a01b03861660009081526003602052604090206001015490915061116b8286611a4d565b6111759190611a2b565b6001600160a01b0386166000908152600360208190526040909120015550505b6001600160a01b038316600090815260036020526040902042600482018190556001909101546111c491611a4d565b6001600160a01b03841660009081526003602090815260409182902060020192909255518381527fde88a922e0d3b88b24e9623efeb464919c6bf9f66857a65e2bfcf2ce87a9433d910160405180910390a1505050565b6112236116f1565b6101f48111156112645760405162461bcd60e51b815260206004820152600c60248201526b0cccaca40e8dede40d0d2ced60a31b604482015260640161061e565b600c5460408051918252602082018390527f733071ab8253b372ed26a6d1b04aec71c4bfcd209c93397df32bb77478cdd2c8910160405180910390a1600c55565b6001600160a01b0381166000908152600360208190526040822060018101549101546105a69190611a14565b60015461010090046001600160a01b03166001600160a01b0316336001600160a01b0316148061130b57506009546001600160a01b031633145b61134b5760405162461bcd60e51b81526020600482015260116024820152701c195c9b5a5cdcda5bdb8819195b9a5959607a1b604482015260640161061e565b60015460ff161561135e57610aa26117e1565b610aa2611833565b61136e6116f1565b6001600160a01b0381166113b65760405162461bcd60e51b815260206004820152600f60248201526e073747261746567697374206973203608c1b604482015260640161061e565b600954604080516001600160a01b03928316815291831660208301527ff6a8d961ba4f41874e38ad8bed56ca4bcf2356a3dd5bfa626b8a73a0da9f5c69910160405180910390a1600980546001600160a01b0319166001600160a01b0392909216919091179055565b6114276116f1565b6001600160a01b0383166000908152600360205260409020600101541561144d57600080fd5b6004805460018181019092557f8a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19b0180546001600160a01b039586166001600160a01b031991821681179092556000918252600360205260409091208054949095169316929092178355910155565b6114c36116f1565b6001600160a01b03811661150d5760405162461bcd60e51b81526020600482015260116024820152700666565526563697069656e74206973203607c1b604482015260640161061e565b600a54604080516001600160a01b03928316815291831660208301527faaebcf1bfa00580e41d966056b48521fa9f202645c86d4ddf28113e617c1b1d3910160405180910390a1600a80546001600160a01b0319166001600160a01b0392909216919091179055565b60006007546000036115a157506001600160a01b031660009081526003602052604090206005015490565b6007546001600160a01b0383166000908152600360208190526040909120908101546004909101546115d285610bd6565b6115dc9190611a01565b6115e69190611a14565b6115f890670de0b6b3a7640000611a14565b6116029190611a2b565b6001600160a01b0383166000908152600360205260409020600501546105a69190611a4d565b6116306116f1565b6001600160a01b03811661165a57604051631e4fbdf760e01b81526000600482015260240161061e565b6108b081611724565b60026000540361168657604051633ee5aeb560e01b815260040160405180910390fd5b6002600055565b6040516001600160a01b038381166024830152604482018390526116ec91859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b03838183161783525050505061186e565b505050565b6001546001600160a01b03610100909104163314610aa25760405163118cdaa760e01b815233600482015260240161061e565b600180546001600160a01b03838116610100818102610100600160a81b031985161790945560405193909204169182907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60015460ff1615610aa25760405163d93c066560e01b815260040160405180910390fd5b6040516001600160a01b0384811660248301528381166044830152606482018390526117db9186918216906323b872dd906084016116ba565b50505050565b6117e96118df565b6001805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b61183b61177e565b6001805460ff1916811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25833611816565b600080602060008451602086016000885af180611891576040513d6000823e3d81fd5b50506000513d915081156118a95780600114156118b6565b6001600160a01b0384163b155b156117db57604051635274afe760e01b81526001600160a01b038516600482015260240161061e565b60015460ff16610aa257604051638dfc202b60e01b815260040160405180910390fd5b80356001600160a01b038116811461191957600080fd5b919050565b6000806040838503121561193157600080fd5b61193a83611902565b915061194860208401611902565b90509250929050565b6000806040838503121561196457600080fd5b61196d83611902565b946020939093013593505050565b60006020828403121561198d57600080fd5b5035919050565b6000602082840312156119a657600080fd5b6105a382611902565b6000806000606084860312156119c457600080fd5b6119cd84611902565b92506119db60208501611902565b9150604084013590509250925092565b634e487b7160e01b600052601160045260246000fd5b818103818111156105a6576105a66119eb565b80820281158282048414176105a6576105a66119eb565b600082611a4857634e487b7160e01b600052601260045260246000fd5b500490565b808201808211156105a6576105a66119eb565b634e487b7160e01b600052603260045260246000fd5b600060018201611a8857611a886119eb565b506001019056fea2646970667358221220967b92284f94eedb557789773c78b662fb98077e7b35f81b435fbfb51544989664736f6c63430008150033
Verified Source Code Full Match
Compiler: v0.8.21+commit.d9974bed
EVM: paris
Optimization: Yes (200 runs)
Ownable.sol 100 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
IERC1363.sol 86 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}
IERC165.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";
IERC20.sol 6 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";
IERC20Metadata.sol 26 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC-20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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);
}
SafeERC20.sol 199 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}
Address.sol 150 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}
Context.sol 28 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Errors.sol 34 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
IERC165.sol 25 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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);
}
Pausable.sol 119 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Pausable.sol)
pragma solidity ^0.8.20;
import {Context} from "../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 {
bool private _paused;
/**
* @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);
/**
* @dev The operation failed because the contract is paused.
*/
error EnforcedPause();
/**
* @dev The operation failed because the contract is not paused.
*/
error ExpectedPause();
/**
* @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 {
if (paused()) {
revert EnforcedPause();
}
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
if (!paused()) {
revert ExpectedPause();
}
}
/**
* @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());
}
}
ReentrancyGuard.sol 87 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @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 EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* 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;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
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
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// 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;
}
}
TBANKStaking.sol 313 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
/***
TTTTT BBBBB A N N K K
T B B A A NN N K K
T BBBBB A A N N N KK
T B B AAAAA N NN K K
T BBBBB A A N N K K
***/
import '@openzeppelin/contracts/utils/ReentrancyGuard.sol';
import '@openzeppelin/contracts/utils/Pausable.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol';
import '@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol';
contract TBANKStaking is ReentrancyGuard, Pausable, Ownable {
using SafeERC20 for IERC20;
/* ========== STATE VARIABLES ========== */
struct Reward {
address rewardsDistributor;
uint256 rewardsDuration;
uint256 periodFinish;
uint256 rewardRate;
uint256 lastUpdateTime;
uint256 rewardPerTokenStored;
}
IERC20 public stakingToken;
mapping(address => Reward) public rewardData;
address[] public rewardTokens;
// user -> reward token -> amount
mapping(address => mapping(address => uint256))
public userRewardPerTokenPaid;
mapping(address => mapping(address => uint256)) public rewards;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
address public strategist;
address public feeRecipient;
uint256 public constant MAX_FEE = 500; // 5%
uint256 public depositFee = 0; // 0%
uint256 public withdrawFee = 0; // 0%
/* ========== CONSTRUCTOR ========== */
modifier onlyOwnerOrStrategist() {
require(
msg.sender == owner() || msg.sender == strategist,
'permission denied'
);
_;
}
constructor(address _stakingToken) Ownable(msg.sender) {
stakingToken = IERC20(_stakingToken);
strategist = msg.sender;
feeRecipient = msg.sender;
}
function togglePause() external onlyOwnerOrStrategist {
if (paused()) _unpause();
else _pause();
}
function setStrategist(address _strategist) external onlyOwner {
require(_strategist != address(0), 'strategist is 0');
emit StrategistUpdated(strategist, _strategist);
strategist = _strategist;
}
function setFeeRecipient(address _feeRecipient) external onlyOwner {
require(_feeRecipient != address(0), 'feeRecipient is 0');
emit FeeRecipientUpdated(feeRecipient, _feeRecipient);
feeRecipient = _feeRecipient;
}
function setDepositFee(uint256 _depositFee) external onlyOwner {
require(_depositFee <= MAX_FEE, 'fee too high');
emit DepositFeeUpdated(depositFee, _depositFee);
depositFee = _depositFee;
}
function setWithdrawFee(uint256 _withdrawFee) external onlyOwner {
require(_withdrawFee <= MAX_FEE, 'fee too high');
emit WithdrawFeeUpdated(withdrawFee, _withdrawFee);
withdrawFee = _withdrawFee;
}
function addReward(
address _rewardsToken,
address _rewardsDistributor,
uint256 _rewardsDuration
) public onlyOwner {
require(rewardData[_rewardsToken].rewardsDuration == 0);
rewardTokens.push(_rewardsToken);
rewardData[_rewardsToken].rewardsDistributor = _rewardsDistributor;
rewardData[_rewardsToken].rewardsDuration = _rewardsDuration;
}
/* ========== VIEWS ========== */
function totalSupply() external view returns (uint256) {
return _totalSupply;
}
function balanceOf(address account) external view returns (uint256) {
return _balances[account];
}
function lastTimeRewardApplicable(
address _rewardsToken
) public view returns (uint256) {
return (
block.timestamp < rewardData[_rewardsToken].periodFinish
? block.timestamp
: rewardData[_rewardsToken].periodFinish
);
}
function rewardPerToken(
address _rewardsToken
) public view returns (uint256) {
if (_totalSupply == 0) {
return rewardData[_rewardsToken].rewardPerTokenStored;
}
return
rewardData[_rewardsToken].rewardPerTokenStored +
(((lastTimeRewardApplicable(_rewardsToken) -
rewardData[_rewardsToken].lastUpdateTime) *
rewardData[_rewardsToken].rewardRate) * 1e18) /
_totalSupply;
}
function earned(
address account,
address _rewardsToken
) public view returns (uint256) {
return
((_balances[account] *
(rewardPerToken(_rewardsToken) -
userRewardPerTokenPaid[account][_rewardsToken])) / 1e18) +
rewards[account][_rewardsToken];
}
function getRewardForDuration(
address _rewardsToken
) external view returns (uint256) {
return
rewardData[_rewardsToken].rewardRate *
rewardData[_rewardsToken].rewardsDuration;
}
/* ========== MUTATIVE FUNCTIONS ========== */
function setRewardsDistributor(
address _rewardsToken,
address _rewardsDistributor
) external onlyOwnerOrStrategist {
rewardData[_rewardsToken].rewardsDistributor = _rewardsDistributor;
}
function stake(
uint256 amount
) external nonReentrant whenNotPaused updateReward(msg.sender) {
require(amount > 0, 'Cannot stake 0');
if (depositFee > 0) {
uint256 _fee = (amount * depositFee) / 10000;
stakingToken.safeTransferFrom(msg.sender, feeRecipient, _fee);
amount = amount - _fee;
}
_totalSupply = _totalSupply + amount;
_balances[msg.sender] = _balances[msg.sender] + amount;
stakingToken.safeTransferFrom(msg.sender, address(this), amount);
emit Staked(msg.sender, amount);
}
function withdraw(
uint256 amount
) public nonReentrant updateReward(msg.sender) {
require(amount > 0, 'Cannot withdraw 0');
_totalSupply = _totalSupply - amount;
_balances[msg.sender] = _balances[msg.sender] - amount;
if (withdrawFee > 0) {
uint256 fee = (amount * withdrawFee) / 10000;
stakingToken.safeTransfer(feeRecipient, fee);
amount = amount - fee;
}
stakingToken.safeTransfer(msg.sender, amount);
emit Withdrawn(msg.sender, amount);
}
function getReward() public nonReentrant updateReward(msg.sender) {
for (uint i; i < rewardTokens.length; i++) {
address _rewardsToken = rewardTokens[i];
uint256 reward = rewards[msg.sender][_rewardsToken];
if (reward > 0) {
rewards[msg.sender][_rewardsToken] = 0;
IERC20(_rewardsToken).safeTransfer(msg.sender, reward);
emit RewardPaid(msg.sender, _rewardsToken, reward);
}
}
}
/* ========== RESTRICTED FUNCTIONS ========== */
function notifyRewardAmount(
address _rewardsToken,
uint256 reward
) external updateReward(address(0)) {
require(rewardData[_rewardsToken].rewardsDistributor == msg.sender);
// handle the transfer of reward tokens via `transferFrom` to reduce the number
// of transactions required and ensure correctness of the reward amount
IERC20(_rewardsToken).safeTransferFrom(
msg.sender,
address(this),
reward
);
if (block.timestamp >= rewardData[_rewardsToken].periodFinish) {
rewardData[_rewardsToken].rewardRate =
reward /
(rewardData[_rewardsToken].rewardsDuration);
} else {
uint256 remaining = rewardData[_rewardsToken].periodFinish -
(block.timestamp);
uint256 leftover = remaining *
(rewardData[_rewardsToken].rewardRate);
rewardData[_rewardsToken].rewardRate =
(reward + leftover) /
(rewardData[_rewardsToken].rewardsDuration);
}
rewardData[_rewardsToken].lastUpdateTime = block.timestamp;
rewardData[_rewardsToken].periodFinish =
block.timestamp +
(rewardData[_rewardsToken].rewardsDuration);
emit RewardAdded(reward);
}
// Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
function recoverERC20(
address tokenAddress,
uint256 tokenAmount
) external onlyOwner {
require(
tokenAddress != address(stakingToken),
'Cannot withdraw staking token'
);
IERC20(tokenAddress).safeTransfer(owner(), tokenAmount);
emit Recovered(tokenAddress, tokenAmount);
}
function setRewardsDuration(
address _rewardsToken,
uint256 _rewardsDuration
) external {
require(rewardData[_rewardsToken].rewardsDistributor == msg.sender);
require(_rewardsDuration > 0, 'Reward duration must be non-zero');
rewardData[_rewardsToken].rewardsDuration = _rewardsDuration;
emit RewardsDurationUpdated(
_rewardsToken,
rewardData[_rewardsToken].rewardsDuration
);
}
/* ========== MODIFIERS ========== */
modifier updateReward(address account) {
for (uint i; i < rewardTokens.length; i++) {
address token = rewardTokens[i];
rewardData[token].rewardPerTokenStored = rewardPerToken(token);
rewardData[token].lastUpdateTime = lastTimeRewardApplicable(token);
if (account != address(0)) {
rewards[account][token] = earned(account, token);
userRewardPerTokenPaid[account][token] = rewardData[token]
.rewardPerTokenStored;
}
}
_;
}
/* ========== EVENTS ========== */
event RewardAdded(uint256 reward);
event Staked(address indexed user, uint256 amount);
event Withdrawn(address indexed user, uint256 amount);
event RewardPaid(
address indexed user,
address indexed rewardsToken,
uint256 reward
);
event RewardsDurationUpdated(address token, uint256 newDuration);
event Recovered(address token, uint256 amount);
event Invested(address indexed strategist, uint256 amount);
event StrategistUpdated(address oldStrategist, address newStrategist);
event FeeRecipientUpdated(address oldFeeRecipient, address newFeeRecipient);
event DepositFeeUpdated(uint256 oldDepositFee, uint256 newDepositFee);
event WithdrawFeeUpdated(uint256 oldWithdrawFee, uint256 newWithdrawFee);
}
Read Contract
MAX_FEE 0xbc063e1a → uint256
balanceOf 0x70a08231 → uint256
depositFee 0x67a52793 → uint256
earned 0x211dc32d → uint256
feeRecipient 0x46904840 → address
getRewardForDuration 0xbcd11014 → uint256
lastTimeRewardApplicable 0x638634ee → uint256
owner 0x8da5cb5b → address
paused 0x5c975abb → bool
rewardData 0x48e5d9f8 → address, uint256, uint256, uint256, uint256, uint256
rewardPerToken 0xf1229777 → uint256
rewardTokens 0x7bb7bed1 → address
rewards 0xe70b9e27 → uint256
stakingToken 0x72f702f3 → address
strategist 0x1fe4a686 → address
totalSupply 0x18160ddd → uint256
userRewardPerTokenPaid 0x7035ab98 → uint256
withdrawFee 0xe941fa78 → uint256
Write Contract 15 functions
These functions modify contract state and require a wallet transaction to execute.
addReward 0xd0ed26ae
address _rewardsToken
address _rewardsDistributor
uint256 _rewardsDuration
getReward 0x3d18b912
No parameters
notifyRewardAmount 0xb66503cf
address _rewardsToken
uint256 reward
recoverERC20 0x8980f11f
address tokenAddress
uint256 tokenAmount
renounceOwnership 0x715018a6
No parameters
setDepositFee 0x490ae210
uint256 _depositFee
setFeeRecipient 0xe74b981b
address _feeRecipient
setRewardsDistributor 0x3f695b45
address _rewardsToken
address _rewardsDistributor
setRewardsDuration 0x2378bea6
address _rewardsToken
uint256 _rewardsDuration
setStrategist 0xc7b9d530
address _strategist
setWithdrawFee 0xb6ac642a
uint256 _withdrawFee
stake 0xa694fc3a
uint256 amount
togglePause 0xc4ae3168
No parameters
transferOwnership 0xf2fde38b
address newOwner
withdraw 0x2e1a7d4d
uint256 amount
Recent Transactions
No transactions found for this address