S Price: $0.53928 (-4.54%)

Contract Diff Checker

Contract Name:
FAsale

Contract Source Code:

File 1 of 1 : FAsale

// File: @openzeppelin/contracts/security/ReentrancyGuard.sol


// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuard {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    constructor() {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }
}

// File: Token/FA Public Sales.sol


pragma solidity >= 0.8.19;


abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }
}


interface IERC20 {
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
    function decimals() external view returns (uint8);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

contract Ownable is Context {
    address private _owner;
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

    function owner() public view returns (address) {
        return _owner;
    }

    modifier onlyOwner() {
        require(_owner == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        emit OwnershipTransferred(_owner, newOwner);
        _owner = newOwner;
    }
}

//set WL start time
//set FCFS start time
//set pay token address
//set FA token address
//set WL addresses
//unpause
//transfer ownership

//setclaimable

contract FAsale is Ownable, ReentrancyGuard  {

    // Total USDC user can pay
    uint256 public SALE_CAP = 255000 * 10**6;
    // Total USDC user paid
    uint256 public TOTAL_PURCHASE = 0;

    mapping (address => bool) public whileLists_;
    address public payToken_;
    address public FAToken_;
    // FA Token price, need set before start claim
    uint256 public tokenPrice_ = 150000; //6 decimal

    // WL sale settings: min 50 payToken_, max 1000 payToken_
    uint256 public WL_MIN_INVEST = 50 * 10**6;
    uint256 public WL_MAX_INVEST = 1000 * 10**6;
    // use startWLPreSale() to start the WL sale.
    uint256 public WL_START_TIME = 999999999999999999999999;
    uint256 public WL_PERIOD = 2 days;
    
    // FCFS sale settings: min 50 payToken_, max 5000 payToken_
    uint256 public FCFS_MIN_INVEST = 50 * 10**6;
    uint256 public FCFS_MAX_INVEST = 5000 * 10**6;
    // use startFCFSPreSale() to start the FCFS sale.
    uint256 public FCFS_START_TIME = 999999999999999999999999;
    uint256 public FCFS_PERIOD = 7 days;

    mapping (address => uint256) public wlPurchaseAmount_;
    mapping (address => uint256) public fcfsPurchaseAmount_;

    // pause all
    bool public paused_ = true;
    bool public claimable_ = false;
    mapping (address => bool) public claimed_;

    // Total USDC user can pay
    function setSaleCap(uint256 saleCap) public onlyOwner {
        SALE_CAP = saleCap;
    }

    function setWLInvestLimit(uint256 minInvest, uint256 maxInvest) public onlyOwner {
        WL_MIN_INVEST = minInvest;
        WL_MAX_INVEST = maxInvest;
    }

    function setFCFSInvestLimit(uint256 minInvest, uint256 maxInvest) public onlyOwner {
        FCFS_MIN_INVEST = minInvest;
        FCFS_MAX_INVEST = maxInvest;
    }

    function setFAToken(address newToken) public onlyOwner {
        FAToken_ = newToken;
    }

    function setPayToken(address newToken) public onlyOwner {
        payToken_ = newToken;
    }

    // Token price for FA Token
    function setTokenPrice(uint256 tokenPrice) public onlyOwner {
        require(tokenPrice > 0, "Token price must be greater than 0");
        tokenPrice_ = tokenPrice;
    }

    function setWLPeriod(uint256 new_period) public onlyOwner {
        WL_PERIOD = new_period;
    }

    function setFCFSPeriod(uint256 new_period) public onlyOwner {
        FCFS_PERIOD = new_period;
    }

    function setWLPreSaleStartTime(uint256 startTime) public onlyOwner {
        WL_START_TIME = startTime;
    }

    function setFCFSPreSaleStartTime(uint256 startTime) public onlyOwner {
        require(startTime >= WL_START_TIME + WL_PERIOD, "FCFS can't start before WL sale.");
        FCFS_START_TIME = startTime;
    }

    function pause() public onlyOwner {
        paused_ = true;
    }

    function unpause() public onlyOwner {
        paused_ = false;
    }

    function finishSale() public onlyOwner {
        IERC20(payToken_).transfer(owner(), IERC20(payToken_).balanceOf(address(this)));
        pause();
    }

    function setClaimable(bool claimable) public onlyOwner {
        claimable_ = claimable;
    }

    function setWL(address[] calldata whileLists) public onlyOwner {
        uint256 length = whileLists.length;
        for (uint256 i=0; i<length; i++) {
            whileLists_[whileLists[i]] = true;
        }
    }

    function removeWL(address[] calldata whileLists) public onlyOwner {
        uint256 length = whileLists.length;
        for (uint256 i=0; i<length; i++) {
            whileLists_[whileLists[i]] = false;
        }
    }

    function wlPurchase(uint256 amount) public nonReentrant {
        require(TOTAL_PURCHASE + amount <= SALE_CAP, "Exceed the sale limit."); //in USDC 6 decimal 
        require(whileLists_[msg.sender], "Not in white lists.");
        require(block.timestamp >= WL_START_TIME && block.timestamp <= WL_START_TIME + WL_PERIOD, "Not in WL period.");
        require(!paused_, "Sale paused.");
        require(wlPurchaseAmount_[msg.sender] + amount <= WL_MAX_INVEST, "Exceed WL max.");
        require(wlPurchaseAmount_[msg.sender] + amount >= WL_MIN_INVEST, "Below WL min.");
        IERC20(payToken_).transferFrom(msg.sender, address(this), amount);
        wlPurchaseAmount_[msg.sender] += amount;
        TOTAL_PURCHASE += amount; //Amount in USDC 6 decimal
    }

    function fcfsPurchase(uint256 amount) public nonReentrant {
        require(TOTAL_PURCHASE + amount <= SALE_CAP, "Exceed the sale limit."); //in USDC 6 decimal 
        require(block.timestamp >= FCFS_START_TIME && block.timestamp <= FCFS_START_TIME + FCFS_PERIOD, "Not in FCFS period.");
        require(!paused_, "Sale paused.");
        require(fcfsPurchaseAmount_[msg.sender] + amount <= FCFS_MAX_INVEST, "Exceed FCFS max.");
        require(fcfsPurchaseAmount_[msg.sender] + amount >= FCFS_MIN_INVEST, "Below FCFS min.");
        IERC20(payToken_).transferFrom(msg.sender, address(this), amount);
        fcfsPurchaseAmount_[msg.sender] += amount;       
        TOTAL_PURCHASE += amount; //Amount in USDC 6 decimal
    }

    function claim() public nonReentrant {
        require(claimable_, "Claim not started yet.");
        require(!claimed_[msg.sender], "Already claimed token.");
        require(tokenPrice_ != 0, "Token Price Not set.");
        uint256 purchaseAmount = fcfsPurchaseAmount_[msg.sender] + wlPurchaseAmount_[msg.sender];
        uint256 claimableAmount = (((purchaseAmount*100) / tokenPrice_) * 10**IERC20(FAToken_).decimals())/100;//Amount in FA. keep 2 decimal place.
        claimed_[msg.sender] = true;
        IERC20(FAToken_).transfer(msg.sender, claimableAmount); 
    }

    // rescue token
    function rescueToken(address token) public onlyOwner {
        IERC20(token).transfer(msg.sender, IERC20(token).balanceOf(address(this)));
    }
    function rescueTokenCustom(address token, uint256 amount) public onlyOwner {
        IERC20(token).transfer(msg.sender, amount);
    }
}

Please enter a contract address above to load the contract details and source code.

Context size (optional):