Address Contract Verified
Address
0x7215A085ADe5a74D34d0bd8fFD2571aECBAa83eB
Balance
0 ETH
Nonce
1
Code Size
8791 bytes
Creator
0x73395DD2...ae81 at tx 0x76a1dd76...3f1f22
Indexed Transactions
0
Contract Bytecode
8791 bytes
0x608060405234801561005d5760405162461bcd60e51b815260206004820152602260248201527f45746865722073656e7420746f206e6f6e2d70617961626c652066756e637469604482019081526137b760f11b6064830152608482fd5b506004361061016e5760003560e01c80638a38bcbc116100fa578063d96a094a116100be578063d96a094a146103ae578063ea130b9c146103c1578063f2fde38b146103d8578063f340fa01146103eb578063fc0c546a146104145761016e565b80638a38bcbc1461034f5780638da5cb5b14610362578063a7310b5814610373578063ca628c7814610393578063d3635a021461039b5761016e565b806347ccca021161014157806347ccca02146103115780634e71d92d146103245780636c7e8cf71461032c578063715018a61461033f5780637a2f38dc146103475761016e565b80630f026cf7146101d357806310f57981146101e85780632f48ab7d1461020a578063370158ea14610235575b60405162461bcd60e51b815260206004820152603560248201527f436f6e747261637420646f6573206e6f7420686176652066616c6c6261636b2060448201908152746e6f7220726563656976652066756e6374696f6e7360581b6064830152608482fd5b6101e66101e1366004611e7b565b610427565b005b6006546101f59060ff1681565b60405190151581526020015b60405180910390f35b60035461021d906001600160a01b031681565b6040516001600160a01b039091168152602001610201565b600754600854604080517f0000000000000000000000000000000000000000000000000000000066ba075081527f0000000000000000000000000000000000000000000000000000000066c7365060208201527f000000000000000000000000000000000000000000000000000000006724d0d0918101919091527f000000000000000000000000000000000000000000000000000000000076a70060608201527f0000000000000000000000000000000000000000000000000000000000278d00608082015260a081019290925260c082015260e001610201565b60045461021d906001600160a01b031681565b6101e6610511565b6101f561033a366004611fe5565b61075e565b6101e661086d565b6101e661087f565b6101e661035d366004611fe5565b61099a565b6000546001600160a01b031661021d565b610386610381366004611fe5565b6109ff565b6040516102019190612003565b6101e6610baa565b6101e66103a9366004612095565b610e23565b6101e66103bc366004612095565b611015565b6103ca60055481565b604051908152602001610201565b6101e66103e6366004611fe5565b611340565b6103ca6103f9366004611fe5565b6001600160a01b03166000908152600c602052604090205490565b60025461021d906001600160a01b031681565b61042f61137b565b60005b815181101561050d576001600b6000848481518110610453576104536120b1565b60200260200101516001600160a01b03166001600160a01b0316815260200190815260200160002060006101000a81548160ff0219169083151502179055507fa54714518c5d275fdcd3d2a461e4858e4e8cb04fb93cd0bca9d6d34115f264408282815181106104c5576104c56120b1565b602002602001015160016040516104f39291906001600160a01b039290921682521515602082015260400190565b60405180910390a180610505816120dd565b915050610432565b5050565b61051a3361075e565b61053f5760405162461bcd60e51b8152600401610536906120f6565b60405180910390fd5b6105476113a8565b427f000000000000000000000000000000000000000000000000000000006724d0d08110156105c95760405162461bcd60e51b815260206004820152602860248201527f5053414c453a446973747269627574696f6e732068617665206e6f74207374616044820152671c9d1959081e595d60c21b6064820152608401610536565b336000818152600d60205260409020805415806105ea575060018101548154115b6106415760405162461bcd60e51b815260206004820152602260248201527f5053414c453a416c6c20746f6b656e732068617665206265656e20636c61696d604482015261195960f21b6064820152608401610536565b805460000361065357610653826113d2565b60008061066e83600001548460030154856002015488611529565b91509150600082116106ce5760405162461bcd60e51b815260206004820152602360248201527f5053414c453a4e6f20746f6b656e7320617661696c61626c6520666f7220636c60448201526261696d60e81b6064820152608401610536565b818360010160008282546106e2919061213c565b90915550506002808401829055600384018690555461070b906001600160a01b031685846115b7565b836001600160a01b03167f47cee97cb7acd717b3c0aa1435d004cd5b3c8c57d70dbceb4e4458bbd60e39d48360405161074691815260200190565b60405180910390a2505050505061075c60018055565b565b6001600160a01b0381166000908152600b602052604081205460ff1661086457600480546040516370a0823160e01b81526001600160a01b0385811693820193909352600092909116906370a082319060240160206040518083038186803b1580156108195760405162461bcd60e51b815260206004820152602560248201527f54617267657420636f6e747261637420646f6573206e6f7420636f6e7461696e604482019081526420636f646560d81b6064830152608482fd5b505afa15801561082d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610851919061214f565b1161085d576000610867565b6001610867565b60015b92915050565b61087561137b565b61075c600061161b565b6108883361075e565b6108a45760405162461bcd60e51b8152600401610536906120f6565b6108ac6113a8565b7f0000000000000000000000000000000000000000000000000000000066c7365042116109255760405162461bcd60e51b815260206004820152602160248201527f5053414c453a526566756e642074696d65206973206e6f7420737461727465646044820152601760f91b6064820152608401610536565b336000908152600d602052604090206004015460ff16156109885760405162461bcd60e51b815260206004820152601a60248201527f5053414c453a526566756e64207061696420616c72656164792e0000000000006044820152606401610536565b610991336113d2565b61075c60018055565b6109a261137b565b6001600160a01b0381166000818152600b60209081526040808320805460ff191690558051938452908301919091527fa54714518c5d275fdcd3d2a461e4858e4e8cb04fb93cd0bca9d6d34115f26440910160405180910390a150565b610a07611d40565b6001600160a01b0382166000908152600d6020908152604091829020825160a081018452815481526001820154928101929092526002810154928201929092526003820154606082015260049091015460ff1615156080820152610a69611d40565b6001600160a01b0384166000908152600c6020526040812054835190919015610a9457508251610aaf565b6000610a9f8361166b565b9050610aab83826116f6565b9150505b600080610ac6838760600151886040015142611529565b8587529092509050610ada6101f485612181565b610aec90670de0b6b3a76400006121a3565b602086015260408501839052610b018461166b565b6060860152602086018051608087015260a086018390525160408601518391610b29916121ba565b610b3391906121ba565b60c08601526040850151610b4690611722565b60e086015283610b57576000610b60565b610b60816117a3565b61010086015260608601516101208601526040850151602087015110610b87576001610b8a565b60005b151561014086015250505060809092015115156101608201529392505050565b610bb261137b565b610bba6113a8565b7f0000000000000000000000000000000000000000000000000000000066c736504211610c4f5760405162461bcd60e51b815260206004820152603b60248201527f5053414c453a7769746864726177546f6b656e3a507269766174652073616c6560448201527f2070726f63657373206973207374696c6c20636f6e74696e75652e00000000006064820152608401610536565b60065460ff1615610ca25760405162461bcd60e51b815260206004820181905260248201527f5053414c453a596f7520686176652077697468647261776e20616c72656164796044820152606401610536565b6000610cb1620f4240806121a3565b60085410610d4b5760075460095414610d215760405162461bcd60e51b815260206004820152602c60248201527f5053414c453a5468657265206973207374696c6c20757365722074686174206960448201526b39903737ba1031b630b4b69760a11b6064820152608401610536565b600a54610d3a670de0b6b3a764000063773594006121a3565b610d4491906121ba565b9050610d90565b6101f4600854610d5b9190612181565b610d6d90670de0b6b3a76400006121a3565b610d83670de0b6b3a764000063773594006121a3565b610d8d91906121ba565b90505b610db8610da56000546001600160a01b031690565b6002546001600160a01b031690836115b7565b6006805460ff19166001179055610dd76000546001600160a01b031690565b6001600160a01b03167f992ee874049a42cae0757a765cd7f641b6028cc35c3478bde8330bf417c3a7a982604051610e1191815260200190565b60405180910390a25061075c60018055565b610e2b61137b565b610e336113a8565b7f0000000000000000000000000000000000000000000000000000000066c736504211610ec85760405162461bcd60e51b815260206004820152603a60248201527f5053414c453a7769746864726177557364743a507269766174652073616c652060448201527f70726f63657373206973207374696c6c20636f6e74696e75652e0000000000006064820152608401610536565b600754610ed7906101f46121a3565b610ee4620f4240806121a3565b610eee91906121ba565b81600554610efc919061213c565b1115610f7c5760405162461bcd60e51b815260206004820152604360248201527f5053414c453a7769746864726177557364743a576974686472617720616d6f7560448201527f6e742063616e6e6f742065786365656420746f74616c2065787065637461746960648201526237b71760e91b608482015260a401610536565b610fa4610f916000546001600160a01b031690565b6003546001600160a01b031690836115b7565b8060056000828254610fb6919061213c565b90915550506000546001600160a01b03166001600160a01b03167f8cc3ca7b2b53047202b1d8aedcf4c411f8a59e8211f43555a19a2a486af1bb2e8260405161100191815260200190565b60405180910390a261101260018055565b50565b61101e3361075e565b61103a5760405162461bcd60e51b8152600401610536906120f6565b6110426113a8565b7f0000000000000000000000000000000000000000000000000000000066ba07504210156110bc5760405162461bcd60e51b815260206004820152602160248201527f5053414c453a507269766174652053616c65206973206e6f74207374617274656044820152601960fa1b6064820152608401610536565b7f0000000000000000000000000000000000000000000000000000000066c7365042111561112c5760405162461bcd60e51b815260206004820152601c60248201527f5053414c453a507269766174652053616c6520636f6d706c65746564000000006044820152606401610536565b3361113c620f42406101f46121a3565b8210158061116157506001600160a01b0381166000908152600c602052604090205415155b6111c75760405162461bcd60e51b815260206004820152603160248201527f5053414c453a50757263686173696e6720616d6f756e74206d7573742062652060448201527036b4b734b6bab6901a9818102aa9a22a1760791b6064820152608401610536565b6111d7620f4240620186a06121a3565b6001600160a01b0382166000908152600c60205260409020546111fb90849061213c565b11156112655760405162461bcd60e51b815260206004820152603360248201527f5053414c453a596f75206861766520657863656564656420746865206d6178696044820152721b5d5b481c1d5c98da185cd948185b5bdd5b9d606a1b6064820152608401610536565b60035461127d906001600160a01b0316823085611896565b6001600160a01b0381166000908152600c602052604081205490036112b257600780549060006112ac836120dd565b91905055505b6001600160a01b0381166000908152600c6020526040812080548492906112da90849061213c565b9250508190555081600860008282546112f3919061213c565b90915550506040518281526001600160a01b038216907fe1fffcc4923d04b559f4d29a8bfc6cda04eb5b0d3c460751c2402c5c5cc9109c9060200160405180910390a25061101260018055565b61134861137b565b6001600160a01b03811661137257604051631e4fbdf760e01b815260006004820152602401610536565b6110128161161b565b6000546001600160a01b0316331461075c5760405163118cdaa760e01b8152336004820152602401610536565b6002600154036113cb57604051633ee5aeb560e01b815260040160405180910390fd5b6002600155565b6001600160a01b0381166000908152600c6020526040902054806114525760405162461bcd60e51b815260206004820152603160248201527f5053414c453a596f7520646964206e6f7420706172746963697061746520696e6044820152702074686520707269766174652073616c6560781b6064820152608401610536565b600061145d8261166b565b905080156114bd5760035461147c906001600160a01b031684836115b7565b60405181815230906001600160a01b038516907ff40cc8c1a1d17359049ba500cfc894596a692cffc9d03943cd92ec2e159cf6ae9060200160405180910390a35b60006114c983836116f6565b6001600160a01b0385166000908152600d60205260408120828155600401805460ff19166001179055600a8054929350839290919061150990849061213c565b90915550506009805490600061151e836120dd565b919050555050505050565b600080600080611538856118d5565b90508615801561156857507f000000000000000000000000000000000000000000000000000000006724d0d08510155b156115835761157688611956565b611580908361213c565b91505b61158c88611965565b61159687836121ba565b6115a091906121a3565b6115aa908361213c565b9890975095505050505050565b6040516001600160a01b0383811660248301526044820183905261161691859182169063a9059cbb906064015b604051602081830303815290604052915060e01b6020820180516001600160e01b038381831617835250505050611974565b505050565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600061167a620f4240806121a3565b60085411156116db576008546000906116986402540be400856121a3565b6116a29190612181565b6116af620f4240806121a3565b6116b991906121a3565b90506116ca6402540be40082612181565b6116d490846121ba565b9392505050565b60006116e9836101f46119d7565b949350505050565b919050565b60006101f4670de0b6b3a764000061170e84866121ba565b61171891906121a3565b6116d49190612181565b6000427f000000000000000000000000000000000000000000000000000000006724d0d0811015611756576116d483611956565b7f000000000000000000000000000000000000000000000000000000006724d0d0811015801561178c5750611789611a0b565b81105b1561179a576116d483611965565b50600092915050565b600042816117af611aa4565b90507f000000000000000000000000000000000000000000000000000000006724d0d082101561180257507f000000000000000000000000000000000000000000000000000000006724d0d09392505050565b7f000000000000000000000000000000000000000000000000000000006724d0d0821015801561183157508082105b1561183d579392505050565b8082101580156118535750611850611a0b565b82105b1561188c576118827f0000000000000000000000000000000000000000000000000000000000278d00856121a3565b6116e9908261213c565b5060009392505050565b6040516001600160a01b0384811660248301528381166044830152606482018390526118cf9186918216906323b872dd906084016115e4565b50505050565b6000806118e0611aa4565b9050808310156118f35750600092915050565b60006118ff8483611af0565b915050600061192e827f0000000000000000000000000000000000000000000000000000000000278d00611b12565b915061194d905061194082600161213c565b611948611b45565b611b5f565b95945050505050565b600061086782600a6064611b75565b60006108678260056064611b75565b60006119896001600160a01b03841683611c39565b905080516000141580156119ae5750808060200190518101906119ac91906121cd565b155b1561161657604051635274afe760e01b81526001600160a01b0384166004820152602401610536565b600080826000036119ed57506000905080611a04565b60018385816119fe576119fe61216b565b06915091505b9250929050565b60006001611a17611b45565b611a2191906121ba565b611a4b907f0000000000000000000000000000000000000000000000000000000000278d006121a3565b611a957f000000000000000000000000000000000000000000000000000000000076a7007f000000000000000000000000000000000000000000000000000000006724d0d061213c565b611a9f919061213c565b905090565b6000611a9f7f000000000000000000000000000000000000000000000000000000000076a7007f000000000000000000000000000000000000000000000000000000006724d0d061213c565b60008083831115611b0657506000905080611a04565b50600193919092039150565b60008082600003611b2857506000905080611a04565b6001838581611b3957611b3961216b565b04915091509250929050565b60006005611b55600a60646121ba565b611a9f9190612181565b6000818310611b6e57816116d4565b5090919050565b6000838302816000198587098281108382030391505080600003611bac57838281611ba257611ba261216b565b04925050506116d4565b808411611bcc5760405163227bc15360e01b815260040160405180910390fd5b6000848688096000868103871696879004966002600389028118808a02820302808a02820302808a02820302808a02820302808a02820302808a02909103029181900381900460010186841190950394909402919094039290920491909117919091029150509392505050565b60606116d48383600084600080856001600160a01b03168486604051611c5f91906121f2565b60006040518083038185875af1925050503d8060008114611c9c576040519150601f19603f3d011682016040523d82523d6000602084013e611ca1565b606091505b5091509150611cb1868383611cbb565b9695505050505050565b606082611cd057611ccb82611d17565b6116d4565b8151158015611ce757506001600160a01b0384163b155b15611d1057604051639996b31560e01b81526001600160a01b0385166004820152602401610536565b50806116d4565b805115611d275780518082602001fd5b604051630a12f52160e11b815260040160405180910390fd5b604051806101800160405280600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000815260200160008152602001600081526020016000151581526020016000151581525090565b60405162461bcd60e51b815260206004820152602260248201527f414249206465636f64696e673a207475706c65206461746120746f6f2073686f6044820152611c9d60f21b6064820152608481fd5b634e487b7160e01b600052604160045260246000fd5b60405162461bcd60e51b815260206004820152602b60248201527f414249206465636f64696e673a20696e76616c69642063616c6c64617461206160448201526a727261792073747269646560a81b6064820152608481fd5b80356001600160a01b03811681146116f157600080fd5b60006020808385031215611e9157611e91611da5565b823567ffffffffffffffff80821115611ef45760405162461bcd60e51b815260048101849052602260248201527f414249206465636f64696e673a20696e76616c6964207475706c65206f666673604482015261195d60f21b6064820152608481fd5b818501915085601f830112611f5c5760405162461bcd60e51b815260048101849052602b60248201527f414249206465636f64696e673a20696e76616c69642063616c6c64617461206160448201526a1c9c985e481bd9999cd95d60aa1b6064820152608481fd5b813581811115611f6e57611f6e611df5565b8060051b604051601f19603f83011681018181108582111715611f9357611f93611df5565b604052918252848201925083810185019188831115611fb457611fb4611e0b565b938501935b82851015611fd957611fca85611e64565b84529385019392850192611fb9565b98975050505050505050565b600060208284031215611ffa57611ffa611da5565b6116d482611e64565b600061018082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015260c083015160c083015260e083015160e0830152610100808401518184015250610120808401518184015250610140808401516120828285018215159052565b5050610160928301511515919092015290565b6000602082840312156120aa576120aa611da5565b5035919050565b634e487b7160e01b600052603260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b6000600182016120ef576120ef6120c7565b5060010190565b60208082526026908201527f57484954454c4953543a596f7520617265206e6f7420696e20746865205768696040820152651d195b1a5cdd60d21b606082015260800190565b80820180821115610867576108676120c7565b60006020828403121561216457612164611da5565b5051919050565b634e487b7160e01b600052601260045260246000fd5b60008261219e57634e487b7160e01b600052601260045260246000fd5b500490565b8082028115828204841417610867576108676120c7565b81810381811115610867576108676120c7565b6000602082840312156121e2576121e2611da5565b815180151581146116d457600080fd5b6000825160005b8181101561221357602081860181015185830152016121f9565b50600092019182525091905056fea26469706673582212203bc5186cd7a097d170d0dae4124b5acc704303de755fde57f717bcb0cf68503064736f6c63430008140033
Verified Source Code Full Match
Compiler: v0.8.20+commit.a1b79de6
EVM: paris
Optimization: Yes (200 runs)
PrivateSale.sol 577 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";
interface ICMLE {
function balanceOf(address _address) external view returns (uint256);
}
/**
* @title PrivateSale Phase for VSTR
* @dev A contract for managing a private token sale with vesting.
*/
contract PrivateSale is Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
using Math for uint256;
event Deposit(address indexed account, uint256 amount);
event Claim(address indexed account, uint256 amount);
event Refund(
address indexed account,
address indexed sender,
uint256 amount
);
event WithdrawUsdt(address indexed owner, uint256 usdt);
event WithdrawToken(address indexed owner, uint256 token);
event Whitelisted(address account, bool status);
// Modifiers
modifier onlyWhiteList() {
require(
whiteListStatus(_msgSender()),
"WHITELIST:You are not in the Whitelist"
);
_;
}
// Constants
uint256 internal constant RATE = 1e10;
uint256 internal constant TOKEN_DECIMALS = 1e18;
uint256 internal constant USDT_DECIMALS = 1e6;
uint256 internal constant MIN_PURCHASE = 500 * USDT_DECIMALS;
uint256 internal constant MAX_PURCHASE = 100_000 * USDT_DECIMALS;
uint256 internal constant TOKEN_PRICE = 500; // 0.0005 USDT
uint256 internal constant TOTAL_ALLOCATION = 2_000_000_000 * TOKEN_DECIMALS;
uint256 internal constant TOTAL_EXPECTATION = 1_000_000 * USDT_DECIMALS;
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 WAITING_TIME;
uint256 internal immutable UNLOCK_PERIODS;
// State variables
IERC20 public token;
IERC20 public usdt;
ICMLE public nft;
uint256 public withdrawUsdtAmount;
bool public isWithdrawToken;
uint256 internal _totalParticipants;
uint256 internal _totalInvestment;
uint256 internal _refundedUserCount;
uint256 internal _totalDistribution;
struct AccountInfo{
uint256 deposit;
uint256 amountRequested;
uint256 amountReceivedPool;
uint256 refund;
uint256 totalClaim;
uint256 unlockedAmount;
uint256 restAmount;
uint256 nextUnlockAmount;
uint256 nextUnlockTime;
uint256 lastClaimTime;
bool isCompleted;
bool isRefunded;
}
struct VestingData {
uint256 totalAmount;
uint256 totalClaim;
uint256 maturityReceived;
uint256 lastClaimedTime;
bool isRefunded;
}
mapping(address => bool) internal _whitelist;
mapping(address => uint256) internal _deposits;
mapping(address => VestingData) internal _vestings;
/**
* @dev Constructor to initialize the PrivateSale 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 nftAddress The address of the NFT contract.
* @param startTime The start time of the private sale.
* @param endTime The end time of the private sale.
* @param startVestingTime The start time of vesting.
* @param waitingTime The waiting period after the first unlock.
* @param unlockPeriods The duration of each vesting period.
*/
constructor(
address initialOwner,
address usdtAddress,
address tokenAddress,
address nftAddress,
uint256 startTime,
uint256 endTime,
uint256 startVestingTime,
uint256 waitingTime,
uint256 unlockPeriods
) Ownable(initialOwner) {
require(
initialOwner != address(0),
"PSALE:Owner's address cannot be zero"
);
require(usdtAddress != address(0), "PSALE:USDT address cannot be zero");
require(
tokenAddress != address(0),
"PSALE:Token address cannot be zero"
);
require(nftAddress != address(0), "PSALE:NFT address cannot be zero");
uint64 currentTime = uint64(block.timestamp);
require(
startTime > currentTime,
"PSALE:Starting Private Sale Time must be in the future"
);
require(
endTime > startTime,
"PSALE:End time must be after the starting private sale time."
);
require(
startVestingTime > endTime,
"PSALE:Start Vesting Time must be after the end time."
);
token = IERC20(tokenAddress);
usdt = IERC20(usdtAddress);
nft = ICMLE(nftAddress);
START_TIME = startTime; // start private sale
END_TIME = endTime; // end private sale
WAITING_TIME = waitingTime;
UNLOCK_PERIODS = unlockPeriods;
START_VESTING_TIME = startVestingTime;
}
/**
* @notice Allows whitelisted users to deposit USDT and participate in the private sale.
* @param usdtAmount The amount of USDT to deposit.
*/
function buy(uint256 usdtAmount) external onlyWhiteList nonReentrant {
require(
block.timestamp >= START_TIME,
"PSALE:Private Sale is not started"
);
require(block.timestamp <= END_TIME, "PSALE:Private Sale completed");
address account = _msgSender();
require(
usdtAmount >= MIN_PURCHASE || _deposits[account] > 0,
"PSALE:Purchasing amount must be minimum 500 USDT."
);
require(
(_deposits[account] + usdtAmount) <= MAX_PURCHASE,
"PSALE:You have exceeded the maximum purchase amount"
);
usdt.safeTransferFrom(account, address(this), usdtAmount);
if (_deposits[account] == 0) {
_totalParticipants++;
}
_deposits[account] += usdtAmount;
_totalInvestment += usdtAmount;
emit Deposit(account, usdtAmount);
}
/**
* @notice Allows whitelisted users to deposit USDT and participate in the private sale.
* @param account The address of USDT to deposit.
*/
function deposit(address account) public view returns (uint256) {
return _deposits[account];
}
/**
* @notice Allows whitelisted users to claim their vested tokens.
*/
function claim() external onlyWhiteList nonReentrant {
uint256 currentTime = block.timestamp;
require(
currentTime >= START_VESTING_TIME,
"PSALE:Distributions have not started yet"
);
address account = _msgSender();
VestingData storage user = _vestings[account];
require(
user.totalAmount == 0 || user.totalAmount > user.totalClaim,
"PSALE:All tokens have been claimed"
);
if (user.totalAmount == 0) {
_sendRefund(account);
}
(uint256 amount, uint256 maturity) = _calculateClaim(
user.totalAmount,
user.lastClaimedTime,
user.maturityReceived,
currentTime
);
require(amount > 0, "PSALE:No tokens available for claim");
user.totalClaim += amount;
user.maturityReceived = maturity;
user.lastClaimedTime = currentTime;
token.safeTransfer(account, amount);
emit Claim(account, amount);
}
function refundClaim() external onlyWhiteList nonReentrant {
require(block.timestamp > END_TIME, "PSALE:Refund time is not started.");
require(!_vestings[_msgSender()].isRefunded, "PSALE:Refund paid already.");
_sendRefund(_msgSender());
}
function _sendRefund(address account) private {
uint256 userDeposit = _deposits[account];
require(
userDeposit > 0,
"PSALE:You did not participate in the private sale"
);
uint256 refundAmount = _refundedUsdt(userDeposit);
if (refundAmount > 0) {
usdt.safeTransfer(account, refundAmount);
emit Refund(account, address(this), refundAmount);
}
uint256 calcTotalAmount = _poolAllocation(userDeposit, refundAmount);
_vestings[account].totalAmount = calcTotalAmount;
_vestings[account].isRefunded = true;
_totalDistribution += calcTotalAmount;
_refundedUserCount ++;
}
function _poolAllocation(uint256 userDeposit, uint256 refundAmount) internal pure returns(uint256){
return ((userDeposit - refundAmount) * TOKEN_DECIMALS) / TOKEN_PRICE;
}
/**
* @notice Retrieves information about the specified account.
* @param account The address of the account.
*/
function accountInfo(address account) public view returns(
AccountInfo memory
){
VestingData memory user = _vestings[account];
AccountInfo memory i;
uint256 userDeposit = deposit(account);
uint256 totalAmount;
if(user.totalAmount > 0){
totalAmount = user.totalAmount;
}else{
uint256 refundAmount = _refundedUsdt(userDeposit);
totalAmount = _poolAllocation(userDeposit, refundAmount);
}
(uint256 amount, uint256 maturity) = _calculateClaim(totalAmount, user.lastClaimedTime, user.maturityReceived, block.timestamp);
i.deposit = userDeposit; // The deposited amount of USDT.
i.amountRequested = TOKEN_DECIMALS * (userDeposit / TOKEN_PRICE); // The total amount of tokens requested by the account.
i.amountReceivedPool = totalAmount;// The total amount of tokens received from the pool.
i.refund = _refundedUsdt(userDeposit); // The amount of USDT to be refunded.
i.totalClaim = user.totalClaim;// The total amount of tokens claimed by the account.
i.unlockedAmount = amount; // The amount of tokens ready to be claimed.
i.restAmount = (i.amountReceivedPool - user.totalClaim - amount); //The remaining amount of tokens to be unlocked.
i.nextUnlockAmount = _nextUnlockAmount(i.amountReceivedPool); // The amount of tokens to be unlocked next.
i.nextUnlockTime = userDeposit > 0 ? _nextUnlockTime(maturity) : 0; // The time of the next token unlock.
i.lastClaimTime = user.lastClaimedTime; // The time of the last token claim.
i.isCompleted = user.totalClaim < i.amountReceivedPool ? false : true; // A boolean indicating whether all tokens have been claimed.
i.isRefunded = user.isRefunded;
return i;
}
/**
* @notice Retrieves information about the PrivateSale contract.
* @return startSaleTime The start time of the private sale.
* @return endSaleTime The end time of the private sale.
* @return startVestingTime The start time of vesting.
* @return waitingTime 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).
*/
function info() public view returns(
uint256 startSaleTime,
uint256 endSaleTime,
uint256 startVestingTime,
uint256 waitingTime,
uint256 periodsTime,
uint256 totalParticipants,
uint256 totalInvestment
){
return (
START_TIME,
END_TIME,
START_VESTING_TIME,
WAITING_TIME,
UNLOCK_PERIODS,
_totalParticipants,
_totalInvestment
);
}
/**
* @notice Withdraw USDT and left tokens from poolsize. only by Owner
* @param usdtAmount The amount of USDT to withdraw.
*/
function withdrawUsdt(uint256 usdtAmount) external onlyOwner nonReentrant {
require(
block.timestamp > END_TIME,
"PSALE:withdrawUsdt:Private sale process is still continue."
);
require(
withdrawUsdtAmount + usdtAmount <= TOTAL_EXPECTATION - (TOKEN_PRICE * _totalParticipants),
"PSALE:withdrawUsdt:Withdraw amount cannot exceed total expectation."
);
usdt.safeTransfer(owner(), usdtAmount);
withdrawUsdtAmount += usdtAmount;
emit WithdrawUsdt(owner(), usdtAmount);
}
/**
* @notice Withdraw Token only by Owner
*/
function withdrawToken() external onlyOwner nonReentrant {
require(
block.timestamp > END_TIME,
"PSALE:withdrawToken:Private sale process is still continue."
);
require(!isWithdrawToken, "PSALE:You have withdrawn already");
uint256 rmPoolToken;
if(_totalInvestment >= TOTAL_EXPECTATION){
require (_refundedUserCount == _totalParticipants, "PSALE:There is still user that is not claim.");
rmPoolToken = TOTAL_ALLOCATION - _totalDistribution;
}else{
rmPoolToken = TOTAL_ALLOCATION - (TOKEN_DECIMALS * (_totalInvestment / TOKEN_PRICE));
}
// Token transfer process
token.safeTransfer(owner(), rmPoolToken);
isWithdrawToken = true;
emit WithdrawToken(owner(), rmPoolToken);
}
/**
* @notice Adds multiple addresses to the whitelist.
* @param accounts The addresses to add to the whitelist.
*/
function whiteListAdd(address[] memory accounts) external onlyOwner {
for (uint256 i = 0; i < accounts.length; i++) {
_whitelist[accounts[i]] = true;
emit Whitelisted(accounts[i], true);
}
}
/**
* @notice Removes an address from the whitelist.
* @param account The address to remove from the whitelist.
*/
function whiteListRemove(address account) external onlyOwner {
_whitelist[account] = false;
emit Whitelisted(account, false);
}
/**
* @notice Checks the whitelist status of an account.
* @param account The address of the account.
* @return status The whitelist status.
*/
function whiteListStatus(address account) public view returns (bool) {
return
_whitelist[account]
? true
: nft.balanceOf(account) > 0
? true
: false;
}
/**
* @dev Returns the next unlock amount based on the total amount and current time.
* @param totalAmount Total amount to unlock.
* @return uint256 The next unlock amount.
*/
function _nextUnlockAmount(
uint256 totalAmount
) internal view returns (uint256) {
uint256 currentTime = block.timestamp;
if (currentTime < START_VESTING_TIME) {
// Return the amount to be claimed first
return _tgeUnlockAmount(totalAmount);
} else if (
currentTime >= START_VESTING_TIME && currentTime < _endVestingTime()
) {
// If the current time is after vesting start and before the end of TGE waiting period, return the next unlock amount.
return _monthlyUnlockAmount(totalAmount);
} else {
return 0;
}
}
/**
* @dev Returns the next unlock time based on the maturity.
* @param maturity The maturity period.
* @return uint256 The next unlock time.
*/
function _nextUnlockTime(uint256 maturity) internal view returns (uint256) {
uint256 currentTime = block.timestamp;
uint256 firstMaturity = _firstPeriodTime(); // First installment time
if (currentTime < START_VESTING_TIME) {
// If the current time is before vesting start, return the vesting date
return START_VESTING_TIME;
} else if (
currentTime >= START_VESTING_TIME && currentTime < firstMaturity
) {
// If the current time is after vesting start and before the first installment time, return the first maturity
return firstMaturity;
} else if (
currentTime >= firstMaturity && currentTime < _endVestingTime()
) {
// If the current time is after the first maturity and before the end of vesting, calculate the next unlock time
return firstMaturity + (maturity * UNLOCK_PERIODS);
} else {
return 0;
}
}
/**
* @dev Calculates the claimable amount and maturity based on the total amount, last claimed time, maturity received, and current time.
* @param totalAmount Total amount to calculate claim from.
* @param lastClaimedTime Last time claimed.
* @param maturityReceived Maturity already received.
* @param currentTime Current time.
* @return uint256 The claimable amount.
* @return uint256 The maturity.
*/
function _calculateClaim(
uint256 totalAmount,
uint256 lastClaimedTime,
uint256 maturityReceived,
uint256 currentTime
) internal view returns (uint256, uint256) {
uint256 amount;
uint256 maturity = _currentMaturity(currentTime);
if (lastClaimedTime == 0 && currentTime >= START_VESTING_TIME) {
amount += _tgeUnlockAmount(totalAmount);
}
amount +=
(maturity - maturityReceived) *
_monthlyUnlockAmount(totalAmount);
return (amount, maturity);
}
/**
* @dev Returns the current maturity based on the current time.
* @param currentTime Current time.
* @return uint256 The current maturity.
*/
function _currentMaturity(
uint256 currentTime
) internal view returns (uint256) {
uint256 firstPeriodTime = _firstPeriodTime();
if (currentTime < firstPeriodTime) {
return 0;
}
(, uint256 _gapTime) = Math.trySub(currentTime, firstPeriodTime);
(, uint256 _maturity) = Math.tryDiv(_gapTime, UNLOCK_PERIODS);
return Math.min(_maturity + 1, _totalPeriods());
}
/**
* @dev Calculates the refunded USDT amount based on the deposit and the amount.
* @param _deposit The deposit amount.
*/
function _refundedUsdt(
uint256 _deposit
) internal view returns (uint256) {
if (_totalInvestment > TOTAL_EXPECTATION) {
uint256 poolRate = TOTAL_EXPECTATION * ((_deposit * RATE) / _totalInvestment);
return (_deposit - (poolRate / RATE));
}else{
(, uint256 _refund) = Math.tryMod(_deposit, TOKEN_PRICE);
return _refund;
}
}
/**
* @dev Returns the TGE unlock amount.
* @param amount The total amount.
* @return uint256 The TGE unlock amount.
*/
function _tgeUnlockAmount(uint256 amount) internal pure returns (uint256) {
return Math.mulDiv(amount, TGE_RELEASE_PERCENTAGE, 100);
}
/**
* @dev Returns the monthly unlock amount.
* @param amount The total amount.
* @return uint256 The monthly unlock amount.
*/
function _monthlyUnlockAmount(
uint256 amount
) internal pure returns (uint256) {
return Math.mulDiv(amount, MONTHLY_RELEASE_PERCENTAGE, 100);
}
/**
* @dev Returns the first period time.
* @return uint256 The first period time.
*/
function _firstPeriodTime() internal view returns (uint256) {
return START_VESTING_TIME + WAITING_TIME;
}
/**
* @dev Returns the end vesting time.
* @return uint256 The end vesting time.
*/
function _endVestingTime() internal view returns (uint256) {
return
START_VESTING_TIME +
WAITING_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);
}
}
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;
}
}
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);
}
}
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;
}
}
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);
}
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;
}
}
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;
}
}
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);
}
Read Contract
accountInfo 0xa7310b58 → tuple
deposit 0xf340fa01 → uint256
info 0x370158ea → uint256, uint256, uint256, uint256, uint256, uint256, uint256
isWithdrawToken 0x10f57981 → bool
nft 0x47ccca02 → address
owner 0x8da5cb5b → address
token 0xfc0c546a → address
usdt 0x2f48ab7d → address
whiteListStatus 0x6c7e8cf7 → bool
withdrawUsdtAmount 0xea130b9c → uint256
Write Contract 9 functions
These functions modify contract state and require a wallet transaction to execute.
buy 0xd96a094a
uint256 usdtAmount
claim 0x4e71d92d
No parameters
refundClaim 0x7a2f38dc
No parameters
renounceOwnership 0x715018a6
No parameters
transferOwnership 0xf2fde38b
address newOwner
whiteListAdd 0x0f026cf7
address[] accounts
whiteListRemove 0x8a38bcbc
address account
withdrawToken 0xca628c78
No parameters
withdrawUsdt 0xd3635a02
uint256 usdtAmount
Token Balances (1)
View Transfers →Recent Transactions
No transactions found for this address