Address Contract Verified
Address
0x287AD4A6BFe8f7f762A57Ed87749f6dda44C6975
Balance
0 ETH
Nonce
1
Code Size
5739 bytes
Creator
0x73395DD2...ae81 at tx 0xf8b6288f...a017a0
Indexed Transactions
0
Contract Bytecode
5739 bytes
0x608060405234801561005d5760405162461bcd60e51b815260206004820152602260248201527f45746865722073656e7420746f206e6f6e2d70617961626c652066756e637469604482019081526137b760f11b6064830152608482fd5b50600436106101015760003560e01c80638da5cb5b116100be5780638da5cb5b14610220578063a7310b5814610231578063ca628c78146102a7578063d96a094a146102af578063f2fde38b146102c2578063fc0c546a146102d557610101565b806310f57981146101665780632f48ab7d1461018f578063370158ea146101ba5780634e71d92d146102065780636865b8e714610210578063715018a614610218575b60405162461bcd60e51b815260206004820152603560248201527f436f6e747261637420646f6573206e6f7420686176652066616c6c6261636b2060448201908152746e6f7220726563656976652066756e6374696f6e7360581b6064830152608482fd5b60035461017a90600160a01b900460ff1681565b60405190151581526020015b60405180910390f35b6003546101a2906001600160a01b031681565b6040516001600160a01b039091168152602001610186565b6101c26102e8565b60408051998a5260208a0198909852968801959095526060870193909352608086019190915260a085015260c084015260e083015261010082015261012001610186565b61020e6103c9565b005b61020e6105a3565b61020e610740565b6000546001600160a01b03166101a2565b61024461023f3660046114a9565b610752565b6040516101869190600061010082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e0830151151560e083015292915050565b61020e61083f565b61020e6102bd3660046114d5565b6109b2565b61020e6102d03660046114a9565b610cfb565b6002546101a2906001600160a01b031681565b60008060008060008060008060007f00000000000000000000000000000000000000000000000000000000671a44d07f0000000000000000000000000000000000000000000000000000000067237f507f000000000000000000000000000000000000000000000000000000006724d0d07f0000000000000000000000000000000000000000000000000000000000ed4e007f0000000000000000000000000000000000000000000000000000000000278d006006546007546004546103ac610d36565b985098509850985098509850985098509850909192939495969798565b6103d1610d60565b7f000000000000000000000000000000000000000000000000000000006724d0d04210156104525760405162461bcd60e51b815260206004820152602360248201527f446973747269627574696f6e732068617665206e6f742073746172746564207960448201526265742160e81b60648201526084015b60405180910390fd5b33600090815260086020526040902080546104be5760405162461bcd60e51b815260206004820152602660248201527f596f752068617665206e6f7420706172746963697061746564205075626c69636044820152652053616c652160d01b6064820152608401610449565b60006104d282600101548360020154610d8a565b90506000811180156104eb575081600201548260010154115b61052a5760405162461bcd60e51b815260206004820152601060248201526f416c726561647920436c61696d65642160801b6044820152606401610449565b8082600201600082825461053e9190611507565b9091555050426003830155610561335b6002546001600160a01b03169083610e81565b60405181815233907f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d49060200160405180910390a250506105a160018055565b565b6105ab610ee5565b6105b3610d60565b7f0000000000000000000000000000000000000000000000000000000067237f5042116105f25760405162461bcd60e51b81526004016104499061151a565b6003546040516370a0823160e01b81523060048201526000916001600160a01b0316906370a082319060240160206040518083038186803b1580156106865760405162461bcd60e51b815260206004820152602560248201527f54617267657420636f6e747261637420646f6573206e6f7420636f6e7461696e604482019081526420636f646560d81b6064830152608482fd5b505afa15801561069a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106be9190611560565b90506106e86106d56000546001600160a01b031690565b6003546001600160a01b03169083610e81565b6000546001600160a01b03166001600160a01b03167f8cc3ca7b2b53047202b1d8aedcf4c411f8a59e8211f43555a19a2a486af1bb2e8260405161072e91815260200190565b60405180910390a2506105a160018055565b610748610ee5565b6105a16000610f12565b61075a611412565b6001600160a01b03821660009081526008602090815260409182902082516080810184528154815260018201549281019290925260028101549282019290925260039091015460608201526107ad611412565b815181526020808301805191830191909152604080840180519184019190915260608085015190840152905190516107e59190610d8a565b6080820152602082015160009081906107fd90610f62565b60a0850182905260c08501819052855191935091501580159061082857508360200151846040015110155b1561083557600160e08401525b5090949350505050565b610847610ee5565b61084f610d60565b7f0000000000000000000000000000000000000000000000000000000067237f50421161088e5760405162461bcd60e51b81526004016104499061151a565b600354600160a01b900460ff16156108e85760405162461bcd60e51b815260206004820152601a60248201527f596f7520686176652077697468647261776e20616c72656164790000000000006044820152606401610449565b60006005546004546108fa919061157c565b90506000811161093e5760405162461bcd60e51b815260206004820152600f60248201526e105b1b081d1bdad95b9cc81cdbdb19608a1b6044820152606401610449565b61095361054e6000546001600160a01b031690565b6003805460ff60a01b1916600160a01b1790556109786000546001600160a01b031690565b6001600160a01b03167f992ee874049a42cae0757a765cd7f641b6028cc35c3478bde8330bf417c3a7a98260405161072e91815260200190565b6109ba610d60565b7f00000000000000000000000000000000000000000000000000000000671a44d0421015610a2a5760405162461bcd60e51b815260206004820152601a60248201527f5075626c69632053616c65206973206e6f7420737461727465640000000000006044820152606401610449565b7f0000000000000000000000000000000000000000000000000000000067237f50421115610a925760405162461bcd60e51b8152602060048201526015602482015274141d589b1a58c814d85b194818dbdb5c1b195d1959605a1b6044820152606401610449565b336000908152600860205260409020610aaf620f4240603261158f565b82101580610abd5750805415155b610b1c5760405162461bcd60e51b815260206004820152602a60248201527f50757263686173696e6720616d6f756e74206d757374206265206d696e696d7560448201526936901a98102aa9a22a1760b11b6064820152608401610449565b610b2b620f42406103e861158f565b8154610b38908490611507565b1115610b9b5760405162461bcd60e51b815260206004820152602c60248201527f50757263686173696e6720616d6f756e74206d757374206265206d6178696d7560448201526b369018981818102aa9a22a1760a11b6064820152608401610449565b6000610ba6836110b1565b905060045481600554610bb99190611507565b1115610c1b5760405162461bcd60e51b815260206004820152602b60248201527f44656d616e64656420616d6f756e742073686f756c64206e6f7420657863656560448201526a642074686520706f6f6c2160a81b6064820152608401610449565b610c33336003546001600160a01b03169030866110d2565b8154600003610c525760068054906000610c4c836115a6565b91905055505b82826000016000828254610c669190611507565b9250508190555080826001016000828254610c819190611507565b925050819055508060056000828254610c9a9190611507565b925050819055508260076000828254610cb39190611507565b909155505060405183815233907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a25050610cf860018055565b50565b610d03610ee5565b6001600160a01b038116610d2d57604051631e4fbdf760e01b815260006004820152602401610449565b610cf881610f12565b60006103e8670de0b6b3a7640000600754610d51919061158f565b610d5b91906115bf565b905090565b600260015403610d8357604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b600042817f000000000000000000000000000000000000000000000000000000006724d0d08210610dd9576064610dc2600a8761158f565b610dcc91906115bf565b610dd69082611507565b90505b6000610de3611111565b9050808310610e605760007f0000000000000000000000000000000000000000000000000000000000278d00610e19838661157c565b610e2391906115bf565b610e2e906001611507565b9050806064610e3e60058a61158f565b610e4891906115bf565b610e52919061158f565b610e5c9084611507565b9250505b84610e6b838861115d565b610e75919061157c565b93505050505b92915050565b6040516001600160a01b03838116602483015260448201839052610ee091859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611175565b505050565b6000546001600160a01b031633146105a15760405163118cdaa760e01b8152336004820152602401610449565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60008082600003610f7857506000928392509050565b427f000000000000000000000000000000000000000000000000000000006724d0d0811015610fe2576064610fae600a8661158f565b610fb891906115bf565b947f000000000000000000000000000000000000000000000000000000006724d0d0945092505050565b6000610fec611111565b90507f000000000000000000000000000000000000000000000000000000006724d0d0821015801561101d57508082105b15611026578092505b80821015801561103c57506110396111d8565b82105b15611081577f0000000000000000000000000000000000000000000000000000000000278d0061106a61126c565b611074919061158f565b61107e9082611507565b92505b6110896111d8565b8210156110aa57606461109d60058761158f565b6110a791906115bf565b93505b5050915091565b60006103e86110c8670de0b6b3a76400008461158f565b610e7b91906115bf565b6040516001600160a01b03848116602483015283811660448301526064820183905261110b9186918216906323b872dd90608401610eae565b50505050565b6000610d5b7f0000000000000000000000000000000000000000000000000000000000ed4e007f000000000000000000000000000000000000000000000000000000006724d0d0611507565b600081831061116c578161116e565b825b9392505050565b600061118a6001600160a01b038416836112d2565b905080516000141580156111af5750808060200190518101906111ad91906115e1565b155b15610ee057604051635274afe760e01b81526001600160a01b0384166004820152602401610449565b600060016111e46112e0565b6111ee919061157c565b611218907f0000000000000000000000000000000000000000000000000000000000278d0061158f565b6112627f0000000000000000000000000000000000000000000000000000000000ed4e007f000000000000000000000000000000000000000000000000000000006724d0d0611507565b610d5b9190611507565b60004281611278611111565b9050808211156112c9577f0000000000000000000000000000000000000000000000000000000000278d006112ad828461157c565b6112b791906115bf565b6112c2906001611507565b9250505090565b60009250505090565b606061116e838360006112f0565b60006005610d51600a606461157c565b6060814710156113155760405163cd78605960e01b8152306004820152602401610449565b600080856001600160a01b031684866040516113319190611606565b60006040518083038185875af1925050503d806000811461136e576040519150601f19603f3d011682016040523d82523d6000602084013e611373565b606091505b509150915061138386838361138d565b9695505050505050565b6060826113a25761139d826113e9565b61116e565b81511580156113b957506001600160a01b0384163b155b156113e257604051639996b31560e01b81526001600160a01b0385166004820152602401610449565b508061116e565b8051156113f95780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b604051806101000160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581525090565b60405162461bcd60e51b815260206004820152602260248201527f414249206465636f64696e673a207475706c65206461746120746f6f2073686f6044820152611c9d60f21b6064820152608481fd5b6000602082840312156114be576114be611459565b81356001600160a01b038116811461116e57600080fd5b6000602082840312156114ea576114ea611459565b5035919050565b634e487b7160e01b600052601160045260246000fd5b80820180821115610e7b57610e7b6114f1565b60208082526026908201527f5075626c69632073616c652070726f63657373206973207374696c6c20636f6e6040820152653a34b73ab29760d11b606082015260800190565b60006020828403121561157557611575611459565b5051919050565b81810381811115610e7b57610e7b6114f1565b8082028115828204841417610e7b57610e7b6114f1565b6000600182016115b8576115b86114f1565b5060010190565b6000826115dc57634e487b7160e01b600052601260045260246000fd5b500490565b6000602082840312156115f6576115f6611459565b8151801515811461116e57600080fd5b6000825160005b81811015611627576020818601810151858301520161160d565b50600092019182525091905056fea26469706673582212203f20a866cedde7b2874543abfcd4b117268ff1b11be673ecb7a8b8543caf6bd264736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
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);
}
}
IERC20Permit.sol 90 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
IERC20.sol 79 lines
// SPDX-License-Identifier: MIT
// 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);
}
SafeERC20.sol 118 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 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 {
using Address for address;
/**
* @dev An operation with an ERC20 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.
*/
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.
*/
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.
*/
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 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).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}
Address.sol 159 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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 AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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
* {FailedInnerCall} 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 AddressInsufficientBalance(address(this));
}
(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 {FailedInnerCall}) 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 {FailedInnerCall} 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 {FailedInnerCall}.
*/
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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
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;
}
}
Math.sol 415 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}
ReentrancyGuard.sol 84 lines
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.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 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;
}
}
PublicSale.sol 410 lines
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/math/Math.sol";
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
/**
* @title Public Sale Phase for VSTR
* @dev A contract for managing a public token sale with vesting.
*/
contract PublicSale is Ownable, ReentrancyGuard {
event Deposit(address indexed account, uint256 amount);
event Claim(address indexed account, uint256 amount);
event WithdrawUsdt(address indexed owner, uint256 usdt);
event WithdrawToken(address indexed owner, uint256 token);
using SafeERC20 for IERC20;
using Math for uint256;
IERC20 public token;
IERC20 public usdt;
/// @notice isWithdrawToken Withdrawal status of unsold VSTR Tokens by Owner.
bool public isWithdrawToken;
uint256 internal _pool;
uint256 internal _totalSale;
uint256 internal _totalParticipants;
uint256 internal _totalInvestment;
// Constants
uint256 internal constant TOKEN_DECIMALS = 1e18;
uint256 internal constant USDT_DECIMALS = 1e6;
uint256 internal constant MIN_PURCHASE = 50 * USDT_DECIMALS; // 50.00 USDT
uint256 internal constant MAX_PURCHASE = 1_000 * USDT_DECIMALS; // 1,000.00 USDT
uint256 internal constant TOKEN_PRICE = 1000; // 0.001 USDT
uint256 internal constant TGE_RELEASE_PERCENTAGE = 10;
uint256 internal constant MONTHLY_RELEASE_PERCENTAGE = 5;
// Vesting variables
uint256 internal immutable START_TIME;
uint256 internal immutable END_TIME;
uint256 internal immutable START_VESTING_TIME;
uint256 internal immutable CLIFF_TIME;
uint256 internal immutable UNLOCK_PERIODS;
/// @title Account Information Data
/// @notice This structure contains a user's purchase information.
/// @dev A full description of the fields is provided below.
struct AccountData {
/// @notice The amount of USDT deposited by the user (6 decimals)
uint256 deposit;
/// @notice Total amount of VSTR purchased
uint256 totalAmount;
/// @notice Total amount of VSTR claimed
uint256 totalClaim;
/// @notice Last claim time (timestamp)
uint256 lastClaimTime;
}
/// @title The struct of Account Information
/// @notice This structure contains a user's vesting information.
/// @dev A full description of the fields is provided below.
struct AccountInfo {
/// @notice The amount of USDT deposited by the user (6 decimals)
uint256 deposit;
/// @notice Total amount of VSTR purchased
uint256 totalAmount;
/// @notice Total amount of VSTR claimed
uint256 totalClaim;
/// @notice Last claim time (timestamp)
uint256 lastClaimTime;
/// @notice Claimable VSTR amount
uint256 unlockedAmount;
/// @notice Sonraki claim miktarı
uint256 nextUnlockAmount;
/// @notice Next claimable time
uint256 nextUnlockTime;
/// @notice Have all entitlements been received?
bool isCompleted;
}
mapping(address => AccountData) internal _accounts;
/**
* @dev Constructor to initialize the public contract.
* @param initialOwner The initial owner of the contract.
* @param usdtAddress The address of the USDT token contract.
* @param tokenAddress The address of the token contract.
* @param pool The amount of VSTR to sale.
* @param startTime The start time of the public sale.
* @param endTime The end time of the public sale.
* @param startVestingTime The start time of vesting.
* @param cliffTime The cliff period after the first unlock.
* @param unlockPeriods The duration of each vesting period.
*/
constructor(
address initialOwner,
address usdtAddress,
address tokenAddress,
uint256 pool,
uint256 startTime,
uint256 endTime,
uint256 startVestingTime,
uint256 cliffTime,
uint256 unlockPeriods
) Ownable(initialOwner) {
require(
initialOwner != address(0),
"Owner's address cannot be zero"
);
require(usdtAddress != address(0), "USDT address cannot be zero");
require(
tokenAddress != address(0),
"Token address cannot be zero"
);
uint64 currentTime = uint64(block.timestamp);
require(
startTime > currentTime,
"Starting Public Sale Time must be in the future"
);
require(
endTime > startTime,
"End time must be after the starting Public sale time."
);
require(
startVestingTime > endTime,
"Start Vesting Time must be after the end time."
);
token = IERC20(tokenAddress);
usdt = IERC20(usdtAddress);
_pool = pool;
START_TIME = startTime; // start public sale
END_TIME = endTime; // end public sale
CLIFF_TIME = cliffTime;
UNLOCK_PERIODS = unlockPeriods;
START_VESTING_TIME = startVestingTime;
}
/**
* @notice Allows users to deposit USDT and participate in the public sale.
* @param usdtAmount The amount of USDT to deposit.
*/
function buy(uint256 usdtAmount) external nonReentrant {
require(
block.timestamp >= START_TIME,
"Public Sale is not started"
);
require(block.timestamp <= END_TIME, "Public Sale completed");
AccountData storage user = _accounts[_msgSender()];
require(
usdtAmount >= MIN_PURCHASE || user.deposit > 0,
"Purchasing amount must be minimum 50 USDT."
);
require(
(user.deposit + usdtAmount) <= MAX_PURCHASE,
"Purchasing amount must be maximum 1000 USDT."
);
uint256 buyTokenAmount = _calculate(usdtAmount);
require(_totalSale + buyTokenAmount <= _pool, "Demanded amount should not exceed the pool!");
usdt.safeTransferFrom(_msgSender(), address(this), usdtAmount);
if (user.deposit == 0) {
_totalParticipants++;
}
user.deposit += usdtAmount;
user.totalAmount += buyTokenAmount;
_totalSale += buyTokenAmount;
_totalInvestment += usdtAmount;
emit Deposit(_msgSender(), usdtAmount);
}
/**
* @notice Allows users to claim their vested tokens.
*/
function claim() external nonReentrant {
require(
block.timestamp >= START_VESTING_TIME,
"Distributions have not started yet!"
);
AccountData storage user = _accounts[_msgSender()];
require(user.deposit > 0, "You have not participated Public Sale!");
uint256 amount = _calculateUnlockAmount(user.totalAmount, user.totalClaim);
require(amount > 0 && user.totalAmount > user.totalClaim, "Already Claimed!");
user.totalClaim += amount;
user.lastClaimTime = block.timestamp;
token.safeTransfer(_msgSender(), amount);
emit Claim(_msgSender(), amount);
}
/**
* @notice Retrieves information about the specified account.
* @param account The address of the account.
*/
function accountInfo(address account) external view returns(AccountInfo memory){
AccountData memory user = _accounts[account];
AccountInfo memory i;
i.deposit = user.deposit;
i.totalAmount = user.totalAmount;
i.totalClaim = user.totalClaim;
i.lastClaimTime = user.lastClaimTime;
i.unlockedAmount = _calculateUnlockAmount(user.totalAmount, user.totalClaim);
(uint256 amount, uint256 time) = _nextUnlock(user.totalAmount);
i.nextUnlockAmount = amount;
i.nextUnlockTime = time;
if(user.deposit > 0 && user.totalClaim >= user.totalAmount){
i.isCompleted = true;
}
return i;
}
/**
*
* @return startSaleTime The start time of the public sale.
* @return endSaleTime The end time of the public sale.
* @return startVestingTime The start time of vesting.
* @return cliffTime The waiting time after the first unlock.
* @return periodsTime The duration of each vesting period.
* @return totalParticipants The total number of participants.
* @return totalInvestment The total investment (in USDT)
* @return pool The total supply for public sale.
* @return saleAmount Sold VSTR Amount.
*/
function info() public view
returns (
uint256 startSaleTime,
uint256 endSaleTime,
uint256 startVestingTime,
uint256 cliffTime,
uint256 periodsTime,
uint256 totalParticipants,
uint256 totalInvestment,
uint256 pool,
uint256 saleAmount
)
{
return (
START_TIME,
END_TIME,
START_VESTING_TIME,
CLIFF_TIME,
UNLOCK_PERIODS,
_totalParticipants,
_totalInvestment,
_pool,
_saleAmount()
);
}
function _saleAmount() internal view returns(uint256){
return (_totalInvestment * TOKEN_DECIMALS) / TOKEN_PRICE;
}
function _calculate(uint256 amount) internal pure returns(uint256){
return (amount * TOKEN_DECIMALS) / TOKEN_PRICE;
}
function _nextUnlock(uint256 totalAmount) internal view returns(uint256 amount, uint256 time){
if (totalAmount == 0) {
return (0, 0);
}
uint256 currentTime = block.timestamp;
if(currentTime < START_VESTING_TIME){
amount = totalAmount * TGE_RELEASE_PERCENTAGE / 100;
time = START_VESTING_TIME;
return (amount, time);
}
uint256 startPeriod = _startPeriodTime();
if (currentTime >= START_VESTING_TIME && currentTime < startPeriod) {
time = startPeriod;
}
if (currentTime >= startPeriod && currentTime < _endVestingTime()) {
time = startPeriod + (_currentPeriod() * UNLOCK_PERIODS);
}
if(currentTime < _endVestingTime()){
amount = totalAmount * MONTHLY_RELEASE_PERCENTAGE / 100;
}
}
/**
* @dev Returns the end vesting time.
* @return uint256 The end vesting time.
*/
function _endVestingTime() internal view returns (uint256) {
return
START_VESTING_TIME +
CLIFF_TIME +
(UNLOCK_PERIODS * (_totalPeriods() - 1));
}
/**
* @dev Returns the total number of periods.
* @return uint256 The total number of periods.
*/
function _totalPeriods() internal pure returns (uint256) {
return ((100 - TGE_RELEASE_PERCENTAGE) / MONTHLY_RELEASE_PERCENTAGE);
}
function _calculateUnlockAmount(uint256 totalAmount, uint256 totalClaim) internal view returns(uint256){
uint256 currentTime = block.timestamp;
uint256 unlockAmount;
// Calculate TGE
if (currentTime >= START_VESTING_TIME) {
unlockAmount += (totalAmount * TGE_RELEASE_PERCENTAGE) / 100;
}
// Calculate periods
uint256 startPeriod = _startPeriodTime();
if (currentTime >= startPeriod){
uint256 periods = ((currentTime - startPeriod) / UNLOCK_PERIODS) + 1;
unlockAmount += ((totalAmount * MONTHLY_RELEASE_PERCENTAGE) / 100) * periods;
}
return _min(unlockAmount, totalAmount) - totalClaim;
}
/**
* @dev Returns the smallest of two numbers.
*/
function _min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function _startPeriodTime() internal view returns(uint256){
return START_VESTING_TIME + CLIFF_TIME;
}
function _currentPeriod() internal view returns(uint256){
uint256 currentTime = block.timestamp;
uint256 startMaturity = _startPeriodTime();
if (currentTime > startMaturity) {
return ((currentTime - startMaturity) / UNLOCK_PERIODS) + 1;
}
return 0;
}
/**
* @notice Withdraw USDT and left tokens from poolsize. only by Owner
*/
function withdrawUsdt() external onlyOwner nonReentrant {
require(
block.timestamp > END_TIME,
"Public sale process is still continue."
);
uint256 balance = usdt.balanceOf(address(this));
usdt.safeTransfer(owner(), balance);
emit WithdrawUsdt(owner(), balance);
}
/**
* @notice Withdraw Token only by Owner
*/
function withdrawToken() external onlyOwner nonReentrant {
require(
block.timestamp > END_TIME,
"Public sale process is still continue."
);
require(!isWithdrawToken, "You have withdrawn already");
uint256 amount = _pool - _totalSale;
require(amount > 0, "All tokens sold");
// Token transfer process
token.safeTransfer(owner(), amount);
isWithdrawToken = true;
emit WithdrawToken(owner(), amount);
}
}
Read Contract
accountInfo 0xa7310b58 → tuple
info 0x370158ea → uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256
isWithdrawToken 0x10f57981 → bool
owner 0x8da5cb5b → address
token 0xfc0c546a → address
usdt 0x2f48ab7d → address
Write Contract 6 functions
These functions modify contract state and require a wallet transaction to execute.
buy 0xd96a094a
uint256 usdtAmount
claim 0x4e71d92d
No parameters
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
withdrawToken 0xca628c78
No parameters
withdrawUsdt 0x6865b8e7
No parameters
Recent Transactions
No transactions found for this address