Skip to content
Verified contractPartial

ETFUSDCAndCompound

Address0x17c714bfb6c65bb88a223d4bf9e52ad4df862f2f
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.4.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.4.26+commit.4563c3fc
Language
solidity
Optimization
No
EVM version
byzantium
License
Not stated
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
9,830,684
Creation transaction
0xdd15eef821…edf32cfae3

ETFUSDCAndCompound.sol

pragma solidity ^0.4.24;
import "./BasicTokenMintable.sol";
import "./SafeMath.sol";
import "./SimpleOracleAccruedRatioUSDC.sol";
import "./CTokenInterface.sol";

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

contract ETFUSDCAndCompound is BasicTokenMintable{
    using SafeMath for uint256;

    uint256 public baseRatio = 1000000;
    string public constant symbol = "STUSDC";
    uint8 public decimals = 6;

    // USDC token contract
    ERC20 public StableToken;
    SimpleOracleAccruedRatioUSDC public oracle;
    // Defi contract
    CERC20 public cToken;

    // Roles
    address public bincentiveHot; // i.e., Platform Owner
    address public bincentiveCold;
    address[] public investors; // implicitly first investor is the lead investor
    address public trader;

    struct WithdrawRequest {
        address investor;
        uint256 tokenAmount;
    }
    uint256 public numRequestedWithdraw;
    uint256 public numProcessedWithdrawRequest;
    mapping(uint256 => WithdrawRequest) public withdrawRequest;
    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
    // 4: running
    // 5: stoppped
    // 6: closed
    uint256 public fundStatus;

    // Money
    uint256 public currentInvestedAmount;
    uint256 public totalMintedTokenAmount;

    // Fund Parameters
    uint256 public investPaymentDueTime;
    uint256 public percentageOffchainFund;

    // Events
    event Deposit(address indexed investor, uint256 investAmount, uint256 mintedAmount);
    event StartFund(uint256 num_investors, uint256 totalInvestedAmount, uint256 totalMintedTokenAmount);
    event Withdraw(address indexed investor, uint256 tokenAmount, uint256 USDCAmount);
    event MidwayQuit(address indexed investor, uint256 tokenAmount, uint256 USDCAmount);
    event ReturnAUM(uint256 StableTokenAmount);
    event DistributeAUM(address indexed to, uint256 tokenAmount, uint256 StableTokenAmount);
    // Defi Events
    event MintcUSDC(uint USDCAmount);
    event RedeemcUSDC(uint RedeemcUSDCAmount);

    // 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 afterStartedBeforeClosed() {
        require((fundStatus >= 3) && (fundStatus < 6));
        _;
    }

    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(balances[msg.sender] > 0);
        _;
    }

    // Getter Functions
    function getBalanceValue(address investor) public view returns(uint256) {
        uint256 accruedRatioUSDC = oracle.query();
        return balances[investor].mul(accruedRatioUSDC).div(baseRatio);
    }

    // Defi Functions
    function querycUSDCAmount() internal returns(uint256) {
        return cToken.balanceOf(address(this));
    }

    function querycExgRate() internal returns(uint256) {
        return cToken.exchangeRateCurrent();
    }

    function mintcUSDC(uint USDCAmount) public isBincentive {

        StableToken.approve(address(cToken), USDCAmount); // approve the transfer
        assert(cToken.mint(USDCAmount) == 0);

        emit MintcUSDC(USDCAmount);
    }

    function redeemcUSDC(uint RedeemcUSDCAmount) public isBincentive {

        require(cToken.redeem(RedeemcUSDCAmount) == 0, "something went wrong");

        emit RedeemcUSDC(RedeemcUSDCAmount);
    }


    // Investor Deposit
    function deposit(address investor, uint256 depositUSDCAmount) initialized public {
        require(now < investPaymentDueTime);
        require((investor != bincentiveHot) && (investor != bincentiveCold));

        // Transfer Stable Token to this contract
        // If deposit from bincentive, transferFrom `bincentiveCold`
        // Else transferFrom msg.sender
        if((msg.sender == bincentiveHot) || (msg.sender == bincentiveCold)) {
            require(StableToken.transferFrom(bincentiveCold, address(this), depositUSDCAmount));
        }
        else{
            require(StableToken.transferFrom(msg.sender, address(this), depositUSDCAmount));
        }

        if(balances[investor] == 0) {
            investors.push(investor);
        }
        currentInvestedAmount = currentInvestedAmount.add(depositUSDCAmount);

        // Query Oracle for current BTC / Stable Token pair
        uint256 accruedRatioUSDC = oracle.query();
        // Mint and distribute tokens to investors
        uint256 mintedTokenAmount;
        mintedTokenAmount = depositUSDCAmount.mul(baseRatio).div(accruedRatioUSDC);
        mint(investor, mintedTokenAmount);
        totalMintedTokenAmount = totalMintedTokenAmount.add(mintedTokenAmount);

        emit Deposit(investor, depositUSDCAmount, mintedTokenAmount);
    }

    // Start Investing
    function start() initialized isBincentive public {
        // Send 50% USDC offline
        uint256 amountSentOffline = currentInvestedAmount.mul(percentageOffchainFund).div(100);
        require(StableToken.transfer(trader, amountSentOffline));

        // Start the contract
        fundStatus = 4;
        emit StartFund(investors.length, currentInvestedAmount, totalMintedTokenAmount);
    }

    // Investor request to withdraw
    function requestWithdraw(uint256 tokenAmount) afterStartedBeforeStopped isInvestor public {
        require(tokenAmount > 0);
        require(balances[msg.sender] >= tokenAmount);

        balances[msg.sender] = balances[msg.sender].sub(tokenAmount);
        withdrawRequest[numRequestedWithdraw] = WithdrawRequest(
            msg.sender,
            tokenAmount
        );
        numRequestedWithdraw = numRequestedWithdraw.add(1);
    }

    function processWithdraw() afterStartedBeforeClosed isBincentive public {
        if(numRequestedWithdraw == numProcessedWithdrawRequest) return;
        // Query Oracle for current BTC / Stable Token pair
        uint256 accruedRatioUSDC = oracle.query();
        address investor;
        uint256 investor_amount;
        uint256 amountUSDCForInvestor;
        for(uint i = numProcessedWithdrawRequest; i < numRequestedWithdraw; i++) {
            investor = withdrawRequest[i].investor;
            investor_amount = withdrawRequest[i].tokenAmount;
            delete withdrawRequest[i];
            amountUSDCForInvestor = investor_amount.mul(accruedRatioUSDC).div(baseRatio);
            require(StableToken.transfer(investor, amountUSDCForInvestor));
            totalMintedTokenAmount = totalMintedTokenAmount.sub(investor_amount);
            numProcessedWithdrawRequest = numProcessedWithdrawRequest.add(1);
            emit Withdraw(investor, investor_amount, amountUSDCForInvestor);
        }

        // Close the contract if every investor has withdrawn
        if(totalMintedTokenAmount == 0) {
            fundStatus = 6;
        }
    }

    // Return AUM
    function returnAUM(uint256 stableTokenAmount) running isBincentiveCold public {
        // Option 1: contract transfer AUM directly from trader
        require(StableToken.transferFrom(trader, address(this), stableTokenAmount));
        // Option 2: trader transfer AUM to bincentiveCold and the contract transfer AUM from bincentiveCold
        // require(StableToken.transferFrom(bincentiveCold, address(this), stableTokenAmount));

        emit ReturnAUM(stableTokenAmount);

        fundStatus = 5;
    }

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

        // Query Oracle for current BTC / Stable Token pair
        uint256 accruedRatioUSDC = oracle.query();

        uint256 stableTokenDistributeAmount;
        address investor;
        uint256 investor_amount;
        // Distribute Stable Token to investors
        for(uint i = numAUMDistributedInvestors; i < (numAUMDistributedInvestors.add(numInvestorsToDistribute)); i++) {
            investor = investors[i];
            investor_amount = balances[investor];
            if(investor_amount == 0) continue;
            balances[investor] = 0;
            emit Transfer(investor, address(0), investor_amount);

            stableTokenDistributeAmount = investor_amount.mul(accruedRatioUSDC).div(baseRatio);
            require(StableToken.transfer(investor, stableTokenDistributeAmount));

            emit DistributeAUM(investor, investor_amount, stableTokenDistributeAmount);
        }

        numAUMDistributedInvestors = numAUMDistributedInvestors.add(numInvestorsToDistribute);
        // If all investors have received AUM, then close the fund.
        if(numAUMDistributedInvestors >= investors.length) {
            currentInvestedAmount = 0;
            fundStatus = 6;
        }
    }

    function claimWronglyTransferredFund() closedOrAborted isBincentive public {
        // withdraw leftover funds from Defi
        uint256 totalcUSDCAmount;
        totalcUSDCAmount = querycUSDCAmount();
        redeemcUSDC(totalcUSDCAmount);

        uint256 leftOverAmount = StableToken.balanceOf(address(this));
        if(leftOverAmount > 0) {
            require(StableToken.transfer(bincentiveCold, leftOverAmount));
        }
    }


    // Constructor
    constructor(
        address _oracle,
        address _StableToken,
        address _cToken,
        address _bincentiveHot,
        address _bincentiveCold,
        address _trader,
        uint256 _investPaymentPeriod,
        uint256 _percentageOffchainFund) public {

        oracle = SimpleOracleAccruedRatioUSDC(_oracle);
        bincentiveHot = _bincentiveHot;
        bincentiveCold = _bincentiveCold;
        StableToken = ERC20(_StableToken);
        cToken = CERC20(_cToken);

        trader = _trader;

        // Set parameters
        investPaymentDueTime = now.add(_investPaymentPeriod);
        percentageOffchainFund = _percentageOffchainFund;

        // Initialized the contract
        fundStatus = 1;
    }
}

BasicToken.sol

pragma solidity ^0.4.24;


import "./ERC20Basic.sol";
import "./SafeMath.sol";


/**
 * @title Basic token
 * @dev Basic version of StandardToken, with no allowances.
 */
contract BasicToken is ERC20Basic {
  using SafeMath for uint256;

  mapping(address => uint256) balances; // Storage slot 0

  uint256 totalSupply_; // Storage slot 1

  /**
  * @dev Total number of tokens in existence
  */
  function totalSupply() public view returns (uint256) {
    return totalSupply_;
  }

  /**
  * @dev Transfer token for a specified address
  * @param _to The address to transfer to.
  * @param _value The amount to be transferred.
  */
  function transfer(address _to, uint256 _value) public returns (bool) {
    require(_to != address(0));
    require(_value <= balances[msg.sender]);

    balances[msg.sender] = balances[msg.sender].sub(_value);
    balances[_to] = balances[_to].add(_value);
    emit Transfer(msg.sender, _to, _value);
    return true;
  }

  /**
  * @dev Gets the balance of the specified address.
  * @param _owner The address to query the the balance of.
  * @return An uint256 representing the amount owned by the passed address.
  */
  function balanceOf(address _owner) public view returns (uint256) {
    return balances[_owner];
  }

}

BasicTokenMintable.sol

pragma solidity ^0.4.24;


import "./BasicToken.sol";
import "./SafeMath.sol";


/**
 * @title Basic token
 * @dev Basic version of StandardToken, with no allowances.
 */
contract BasicTokenMintable is BasicToken {
  using SafeMath for uint256;

  function mint(address account, uint256 amount) internal {
    require(account != address(0));
    totalSupply_ = totalSupply_.add(amount);
    balances[account] = balances[account].add(amount);
    emit Transfer(address(0), account, amount);
  }
}

CTokenInterface.sol

pragma solidity ^0.4.25;


interface CERC20 {
    function mint(uint mintAmount) returns (uint);
    function redeem(uint redeemTokens) returns (uint);
    function supplyRatePerBlock() returns (uint);
    function exchangeRateCurrent() returns (uint);
    function balanceOf(address _owner) public view returns (uint balance);
    function balanceOfUnderlying(address account) returns (uint);
}

interface CEther {
    function mint() payable;
    function redeem(uint redeemTokens) returns (uint);
    function supplyRatePerBlock() returns (uint);
    function balanceOf(address _owner) public view returns (uint balance);
    function balanceOfUnderlying(address account) returns (uint);
}

ERC20Basic.sol

pragma solidity ^0.4.24;


/**
 * @title ERC20Basic
 * @dev Simpler version of ERC20 interface
 * See https://github.com/ethereum/EIPs/issues/179
 */
contract ERC20Basic {
  function totalSupply() public view returns (uint256);
  function balanceOf(address who) public view returns (uint256);
  function transfer(address to, uint256 value) public returns (bool);
  event Transfer(address indexed from, address indexed to, uint256 value);
}

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;
  }
}

SimpleOracleAccruedRatioUSDC.sol

pragma solidity ^0.4.24;

contract SimpleOracleAccruedRatioUSDC {
    address public owner;
    uint256 public accruedRatioUSDC;

    // event QueryEvent(bytes32 id, string query);

    constructor(uint256 _accruedRatioUSDC) {
        owner = msg.sender;
        accruedRatioUSDC = _accruedRatioUSDC;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    function set(uint256 _accruedRatioUSDC) onlyOwner {
        accruedRatioUSDC = _accruedRatioUSDC;
    }

    function query() returns(uint256) {
        // QueryEvent(msg.sender, block.number);
        return accruedRatioUSDC;
    }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "byzantium",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.