Skip to content
Verified contractPartial

RockFlameOffchainUSDT

Address0xbbb1bc511c535878957dd29256efe5530b41fad3
Balance

0 ETH

 

Transactions

5

 

Compiler

solc 0.4.26

 

Same code

6 more contracts

 

Details

Compiler
solc 0.4.26+commit.4563c3fc
Language
solidity
Optimization
Yes, 200 runs
EVM version
byzantium
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
9,952,662
Creation transaction
0x119a2106d2…507c9c9dd2
Main copy (most transactions)
0xb4674ec4…910c2adc

2 files

RockFlameOffchainUSDT.sol

pragma solidity ^0.4.24;
import "./SafeMath.sol";

interface ERC20 {
    function balanceOf(address who) external view returns (uint256);
    function transfer(address to, uint256 value) external returns (bool);
    function transferFrom(address from, address to, uint256 value) external returns (bool);
}

contract RockFlameOffchainUSDT {
    using SafeMath for uint256;

    // BCNT token contract
    ERC20 public BCNTToken;

    // Roles
    address public bincentiveHot; // i.e., Platform Owner
    address public bincentiveCold;
    address[] public rockInvestors;

    uint256 public numMidwayQuitInvestors;
    uint256 public numAUMDistributedInvestors; // i.e., number of investors that already received AUM

    // Contract(Fund) Status
    // 0: not initialized
    // 1: initialized
    // 2: not enough fund came in in time
    // 3: fundStarted(skipped)
    // 4: running
    // 5: stoppped
    // 6: closed
    uint256 public fundStatus;

    // Money
    uint256 public totalRockInvestedAmount;
    mapping(address => uint256) public rockInvestedAmount;

    uint256 public BCNTLockAmount;

    uint256 public returnedUSDTAmounts;

    // Events
    event Deposit(address indexed investor, uint256 amount);
    event StartFund(uint256 num_investors, uint256 totalInvestedAmount, uint256 BCNTLockAmount);
    event AbortFund(uint256 num_investors, uint256 totalInvestedAmount);
    event MidwayQuit(address indexed investor, uint256 investAmount, uint256 BCNTWithdrawAmount);
    event ReturnAUM(uint256 amountUSDT);
    event DistributeAUM(address indexed to, uint256 amountUSDT);


    // Modifiers
    modifier initialized() {
        require(fundStatus == 1);
        _;
    }

    // modifier fundStarted() {
    //     require(fundStatus == 3);
    //     _;
    // }

    modifier running() {
        require(fundStatus == 4);
        _;
    }

    modifier stopped() {
        require(fundStatus == 5);
        _;
    }

    // modifier afterStartedBeforeStopped() {
    //     require((fundStatus >= 3) && (fundStatus < 5));
    //     _;
    // }

    modifier closedOrAborted() {
        require((fundStatus == 6) || (fundStatus == 2));
        _;
    }

    modifier isBincentive() {
        require(
            (msg.sender == bincentiveHot) || (msg.sender == bincentiveCold)
        );
        _;
    }

    modifier isBincentiveCold() {
        require(msg.sender == bincentiveCold);
        _;
    }

    modifier isInvestor() {
        // bincentive is not investor
        require(msg.sender != bincentiveHot);
        require(msg.sender != bincentiveCold);
        require(rockInvestedAmount[msg.sender] > 0);
        _;
    }

    // Getter Functions


    // Investor Deposit
    function deposit(address[] investors, uint256[] depositUSDTAmounts) initialized isBincentive public {
        require(investors.length > 0, "Must has at least one investor");
        require(investors.length == depositUSDTAmounts.length, "Input not of the same length");

        address investor;
        uint256 depositUSDTAmount;
        for(uint i = 0; i < investors.length; i++) {
            investor = investors[i];
            depositUSDTAmount = depositUSDTAmounts[i];

            require((investor != bincentiveHot) && (investor != bincentiveCold));

            totalRockInvestedAmount = totalRockInvestedAmount.add(depositUSDTAmount);
            if(rockInvestedAmount[investor] == 0) {
                rockInvestors.push(investor);
            }
            rockInvestedAmount[investor] = rockInvestedAmount[investor].add(depositUSDTAmount);

            emit Deposit(investor, depositUSDTAmount);
        }
    }

    // Start Investing
    function start(uint256 _BCNTLockAmount) initialized isBincentive public {
        // Transfer and lock BCNT into the contract
        require(BCNTToken.transferFrom(bincentiveCold, address(this), _BCNTLockAmount));
        BCNTLockAmount = _BCNTLockAmount;

        // Run it
        fundStatus = 4;
        emit StartFund(rockInvestors.length, totalRockInvestedAmount, BCNTLockAmount);
    }

    // NOTE: might consider changing to withdrawal pattern
    // Not Enough Fund
    function notEnoughFund() initialized isBincentive public {
        fundStatus = 2;
        emit AbortFund(rockInvestors.length, totalRockInvestedAmount);
    }

    // Investor quit and withdraw
    function midwayQuitByAdmin(address _investor) running isBincentive public {
        require(_investor != bincentiveHot && _investor != bincentiveCold);
        uint256 investor_amount = rockInvestedAmount[_investor];
        rockInvestedAmount[_investor] = 0;

        // Subtract total invest amount and transfer investor's share to `bincentiveCold`
        uint256 totalAmount = totalRockInvestedAmount;
        totalRockInvestedAmount = totalRockInvestedAmount.sub(investor_amount);
        rockInvestedAmount[bincentiveCold] = rockInvestedAmount[bincentiveCold].add(investor_amount);

        uint256 BCNTWithdrawAmount = BCNTLockAmount.mul(investor_amount).div(totalAmount);
        BCNTLockAmount = BCNTLockAmount.sub(BCNTWithdrawAmount);
        require(BCNTToken.transfer(_investor, BCNTWithdrawAmount));

        numMidwayQuitInvestors = numMidwayQuitInvestors.add(1);
        // Close the contract if every investor has quit
        if(numMidwayQuitInvestors == rockInvestors.length) {
            fundStatus = 6;
        }

        emit MidwayQuit(_investor, investor_amount, BCNTWithdrawAmount);
    }


    // Investor quit and withdraw
    function midwayQuit() running isInvestor public {
        uint256 investor_amount = rockInvestedAmount[msg.sender];
        rockInvestedAmount[msg.sender] = 0;

        // Subtract total invest amount and transfer investor's share to `bincentiveCold`
        uint256 totalAmount = totalRockInvestedAmount;
        totalRockInvestedAmount = totalRockInvestedAmount.sub(investor_amount);
        rockInvestedAmount[bincentiveCold] = rockInvestedAmount[bincentiveCold].add(investor_amount);

        uint256 BCNTWithdrawAmount = BCNTLockAmount.mul(investor_amount).div(totalAmount);
        BCNTLockAmount = BCNTLockAmount.sub(BCNTWithdrawAmount);
        require(BCNTToken.transfer(msg.sender, BCNTWithdrawAmount));

        numMidwayQuitInvestors = numMidwayQuitInvestors.add(1);
        // Close the contract if every investor has quit
        if(numMidwayQuitInvestors == rockInvestors.length) {
            fundStatus = 6;
        }

        emit MidwayQuit(msg.sender, investor_amount, BCNTWithdrawAmount);
    }

    // Return AUM
    function returnAUM(uint256 USDTAmount) running isBincentiveCold public {

        returnedUSDTAmounts = USDTAmount;

        emit ReturnAUM(USDTAmount);

        fundStatus = 5;
    }

    // Distribute AUM
    function distributeAUM(uint256 numInvestorsToDistribute) stopped isBincentive public {
        require(numAUMDistributedInvestors.add(numInvestorsToDistribute) <= rockInvestors.length, "Distributing to more than total number of rockInvestors");

        uint256 totalUSDTReturned = returnedUSDTAmounts;
        // Count `bincentiveCold`'s share in total amount when distributing AUM
        uint256 totalAmount = totalRockInvestedAmount.add(rockInvestedAmount[bincentiveCold]);

        uint256 USDTDistributeAmount;
        address investor;
        uint256 investor_amount;
        // Distribute USDT to rockInvestors
        for(uint i = numAUMDistributedInvestors; i < (numAUMDistributedInvestors.add(numInvestorsToDistribute)); i++) {
            investor = rockInvestors[i];
            if(rockInvestedAmount[investor] == 0) continue;
            investor_amount = rockInvestedAmount[investor];
            rockInvestedAmount[investor] = 0;

            USDTDistributeAmount = totalUSDTReturned.mul(investor_amount).div(totalAmount);

            emit DistributeAUM(investor, USDTDistributeAmount);
        }

        numAUMDistributedInvestors = numAUMDistributedInvestors.add(numInvestorsToDistribute);
        // If all rockInvestors have received AUM,
        // distribute AUM and return BCNT stake to `bincentiveCold` then close the fund.
        if(numAUMDistributedInvestors >= rockInvestors.length) {
            returnedUSDTAmounts = 0;
            totalRockInvestedAmount = 0;
            // Distribute USDT and BCNT to `bincentiveCold`
            if(rockInvestedAmount[bincentiveCold] > 0) {
                investor_amount = rockInvestedAmount[bincentiveCold];
                rockInvestedAmount[bincentiveCold] = 0;

                USDTDistributeAmount = totalUSDTReturned.mul(investor_amount).div(totalAmount);

                emit DistributeAUM(bincentiveCold, USDTDistributeAmount);
            }

            // Transfer the BCNT stake left back to `bincentiveCold`
            uint256 _BCNTLockAmount = BCNTLockAmount;
            BCNTLockAmount = 0;
            require(BCNTToken.transfer(bincentiveCold, _BCNTLockAmount));

            fundStatus = 6;
        }
    }

    // Constructor
    constructor(
        address _BCNTToken,
        address _bincentiveHot,
        address _bincentiveCold) public {

        BCNTToken = ERC20(_BCNTToken);
        bincentiveHot = _bincentiveHot;
        bincentiveCold = _bincentiveCold;

        // Initialized the contract
        fundStatus = 1;
    }
}

SafeMath.sol

pragma solidity ^0.4.24;


/**
 * @title SafeMath
 * @dev Math operations with safety checks that throw on error
 */
library SafeMath {

  /**
  * @dev Multiplies two numbers, throws on overflow.
  */
  function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
    // Gas optimization: this is cheaper than asserting 'a' not being zero, but the
    // benefit is lost if 'b' is also tested.
    // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
    if (a == 0) {
      return 0;
    }

    c = a * b;
    assert(c / a == b);
    return c;
  }

  /**
  * @dev Integer division of two numbers, truncating the quotient.
  */
  function div(uint256 a, uint256 b) internal pure returns (uint256) {
    // assert(b > 0); // Solidity automatically throws when dividing by 0
    // uint256 c = a / b;
    // assert(a == b * c + a % b); // There is no case in which this doesn't hold
    return a / b;
  }

  /**
  * @dev Subtracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  */
  function sub(uint256 a, uint256 b) internal pure returns (uint256) {
    assert(b <= a);
    return a - b;
  }

  /**
  * @dev Adds two numbers, throws on overflow.
  */
  function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
    c = a + b;
    assert(c >= a);
    return c;
  }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "byzantium",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.