Contract 0x6Ccf2A03890867bf12E6b73d2942D7e9985D5CC9

 
 
Txn Hash Method
Block
From
To
Value [Txn Fee]
0x8f9f5767feb4462449f26c466f3783ae329795471e26e7f12801fee49ca4c8d60x60806040214439222021-11-16 16:24:2268 days 5 hrs ago0xb0dd96118594903bacb2746eb228550c10b2b1da IN  Create: Investments0 MATIC0.034538350
[ Download CSV Export 
Parent Txn Hash Block From To Value
Loading

Contract Source Code Verified (Exact Match)

Contract Name:
Investments

Compiler Version
v0.8.4+commit.c7e474f2

Optimization Enabled:
Yes with 200 runs

Other Settings:
default evmVersion, MIT license

Contract Source Code (Solidity Standard Json-Input format)

File 1 of 6 : Ownable.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import "../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.
 *
 * By default, the owner account will be the one that deploys the contract. 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;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    constructor() {
        _setOwner(_msgSender());
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _setOwner(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 {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _setOwner(newOwner);
    }

    function _setOwner(address newOwner) private {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}

File 2 of 6 : Context.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

/**
 * @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;
    }
}

File 3 of 6 : SafeMath.sol
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.

/**
 * @dev Wrappers over Solidity's arithmetic operations.
 *
 * NOTE: `SafeMath` is no longer needed starting with Solidity 0.8. The compiler
 * now has built in overflow checking.
 */
library SafeMath {
    /**
     * @dev Returns the addition of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    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 substraction of two unsigned integers, with an overflow flag.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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.
     *
     * _Available since v3.4._
     */
    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 addition of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `+` operator.
     *
     * Requirements:
     *
     * - Addition cannot overflow.
     */
    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        return a + b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting on
     * overflow (when the result is negative).
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return a - b;
    }

    /**
     * @dev Returns the multiplication of two unsigned integers, reverting on
     * overflow.
     *
     * Counterpart to Solidity's `*` operator.
     *
     * Requirements:
     *
     * - Multiplication cannot overflow.
     */
    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        return a * b;
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator.
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting when dividing by zero.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(uint256 a, uint256 b) internal pure returns (uint256) {
        return a % b;
    }

    /**
     * @dev Returns the subtraction of two unsigned integers, reverting with custom message on
     * overflow (when the result is negative).
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {trySub}.
     *
     * Counterpart to Solidity's `-` operator.
     *
     * Requirements:
     *
     * - Subtraction cannot overflow.
     */
    function sub(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b <= a, errorMessage);
            return a - b;
        }
    }

    /**
     * @dev Returns the integer division of two unsigned integers, reverting with custom message on
     * division by zero. The result is rounded towards zero.
     *
     * Counterpart to Solidity's `/` operator. Note: this function uses a
     * `revert` opcode (which leaves remaining gas untouched) while Solidity
     * uses an invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function div(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a / b;
        }
    }

    /**
     * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
     * reverting with custom message when dividing by zero.
     *
     * CAUTION: This function is deprecated because it requires allocating memory for the error
     * message unnecessarily. For custom revert reasons use {tryMod}.
     *
     * Counterpart to Solidity's `%` operator. This function uses a `revert`
     * opcode (which leaves remaining gas untouched) while Solidity uses an
     * invalid opcode to revert (consuming all remaining gas).
     *
     * Requirements:
     *
     * - The divisor cannot be zero.
     */
    function mod(
        uint256 a,
        uint256 b,
        string memory errorMessage
    ) internal pure returns (uint256) {
        unchecked {
            require(b > 0, errorMessage);
            return a % b;
        }
    }
}

File 4 of 6 : Investments.sol
//SPDX-License-Identifier: MIT
pragma solidity 0.8.4;

import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "../interfaces/IMemory.sol";
import "../interfaces/ICToken.sol";

interface IProtocolDataProvider {
	function getUserReserveData(address reserve, address user)
		external
		view
		returns (uint256 currentATokenBalance);

	function getReserveConfigurationData(address asset)
		external
		view
		returns (
			uint256 decimals,
			uint256 ltv,
			uint256 liquidationThreshold,
			uint256 liquidationBonus,
			uint256 reserveFactor,
			bool usageAsCollateralEnabled,
			bool borrowingEnabled,
			bool stableBorrowRateEnabled,
			bool isActive,
			bool isFrozen
		);
}

contract Investments is Ownable {
	using SafeMath for uint256;

	IMemory public memoryContract;

	address internal constant MATIC =
		0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
	address internal constant WMATIC =
		0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270;

	IProtocolDataProvider aaveDataProviderV2 =
		IProtocolDataProvider(0x7551b5D2763519d4e37e8B81929D336De671d46d);

	struct Balance {
		uint256 aave;
		uint256 cream;
	}

	constructor(IMemory _memoryContract) {
		memoryContract = _memoryContract;
	}

	function setMemoryContract(IMemory _memory) external onlyOwner {
		memoryContract = _memory;
	}

	function getAaveBalanceV2(address token, address account)
		public
		view
		returns (uint256)
	{
		(, , , , , , , , bool isActive, ) = aaveDataProviderV2
			.getReserveConfigurationData(token);

		if (!isActive) return 0;

		return
			aaveDataProviderV2.getUserReserveData(
				token == MATIC ? WMATIC : token,
				account
			);
	}

	function getCreamBalance(address token, address user)
		public
		view
		returns (uint256)
	{
		address cToken = memoryContract.getCrToken(token);

		if (cToken == address(0)) return 0;

		(, uint256 balance, , uint256 rate) = ICToken(cToken)
			.getAccountSnapshot(user);

		return balance.mul(rate).div(1 ether);
	}

	function getBalances(address[] calldata tokens, address user)
		external
		view
		returns (Balance[] memory)
	{
		Balance[] memory balances = new Balance[](tokens.length);

		for (uint256 i = 0; i < tokens.length; i++) {
			balances[i].aave = getAaveBalanceV2(tokens[i], user);
			balances[i].cream = getCreamBalance(tokens[i], user);
		}

		return balances;
	}
}

File 5 of 6 : ICToken.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface ICToken {
	function redeem(uint256 redeemTokens) external returns (uint256);

	function redeemUnderlying(uint256 redeemAmount) external returns (uint256);

	function borrow(uint256 borrowAmount) external returns (uint256);

	function liquidateBorrow(
		address borrower,
		uint256 repayAmount,
		address cTokenCollateral
	) external returns (uint256);

	function liquidateBorrow(address borrower, address cTokenCollateral)
		external
		payable;

	function exchangeRateCurrent() external returns (uint256);

	function getCash() external view returns (uint256);

	function borrowRatePerBlock() external view returns (uint256);

	function supplyRatePerBlock() external view returns (uint256);

	function totalReserves() external view returns (uint256);

	function totalBorrows() external view returns (uint256);

	function reserveFactorMantissa() external view returns (uint256);

	function totalSupply() external view returns (uint256);

	function balanceOf(address owner) external view returns (uint256 balance);

	function borrowBalanceStored(address owner)
		external
		view
		returns (uint256 balance);

	function allowance(address, address) external view returns (uint256);

	function approve(address, uint256) external;

	function transfer(address, uint256) external returns (bool);

	function transferFrom(
		address,
		address,
		uint256
	) external returns (bool);

	function decimals() external view returns (uint8);

	function symbol() external view returns (string memory);

	function getAccountSnapshot(address)
		external
		view
		returns (
			uint256,
			uint256,
			uint256,
			uint256
		);
}

File 6 of 6 : IMemory.sol
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IMemory {
	function getUint(uint256) external view returns (uint256);

	function setUint(uint256 id, uint256 value) external;

	function getAToken(address asset) external view returns (address);

	function setAToken(address asset, address _aToken) external;

	function getCrToken(address asset) external view returns (address);

	function setCrToken(address asset, address _crToken) external;
}

Settings
{
  "evmVersion": "istanbul",
  "libraries": {},
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": true
  },
  "optimizer": {
    "enabled": true,
    "runs": 200
  },
  "remappings": [],
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  }
}

Contract Security Audit

Contract ABI

[{"inputs":[{"internalType":"contract IMemory","name":"_memoryContract","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"account","type":"address"}],"name":"getAaveBalanceV2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"},{"internalType":"address","name":"user","type":"address"}],"name":"getBalances","outputs":[{"components":[{"internalType":"uint256","name":"aave","type":"uint256"},{"internalType":"uint256","name":"cream","type":"uint256"}],"internalType":"struct Investments.Balance[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"getCreamBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"memoryContract","outputs":[{"internalType":"contract IMemory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IMemory","name":"_memory","type":"address"}],"name":"setMemoryContract","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]

6080604052600280546001600160a01b031916737551b5d2763519d4e37e8b81929d336de671d46d17905534801561003657600080fd5b50604051610b4a380380610b4a833981016040819052610055916100d3565b61005e33610083565b600180546001600160a01b0319166001600160a01b0392909216919091179055610101565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6000602082840312156100e4578081fd5b81516001600160a01b03811681146100fa578182fd5b9392505050565b610a3a806101106000396000f3fe608060405234801561001057600080fd5b50600436106100885760003560e01c8063c7cb09b11161005b578063c7cb09b1146100f5578063d1c0702814610108578063d4c767c214610128578063f2fde38b1461013b57600080fd5b806320f0218a1461008d578063715018a6146100b35780638da5cb5b146100bd578063abbd23f3146100e2575b600080fd5b6100a061009b36600461075f565b61014e565b6040519081526020015b60405180910390f35b6100bb6102c0565b005b6000546001600160a01b03165b6040516001600160a01b0390911681526020016100aa565b6100bb6100f0366004610727565b6102ff565b6001546100ca906001600160a01b031681565b61011b610116366004610797565b61034b565b6040516100aa91906108fb565b6100a061013636600461075f565b6104ba565b6100bb610149366004610727565b610608565b600254604051633e15014160e01b81526001600160a01b0384811660048301526000928392911690633e150141906024016101406040518083038186803b15801561019857600080fd5b505afa1580156101ac573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d09190610865565b5098505050505050505050806101ea5760009150506102ba565b6002546001600160a01b03908116906328dd2d0190861673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee146102215785610237565b730d500b1d8e8ef31e21c99d1db9a6444d3adf12705b6040516001600160e01b031960e084901b1681526001600160a01b039182166004820152908616602482015260440160206040518083038186803b15801561027e57600080fd5b505afa158015610292573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102b69190610818565b9150505b92915050565b6000546001600160a01b031633146102f35760405162461bcd60e51b81526004016102ea9061094a565b60405180910390fd5b6102fd60006106a3565b565b6000546001600160a01b031633146103295760405162461bcd60e51b81526004016102ea9061094a565b600180546001600160a01b0319166001600160a01b0392909216919091179055565b606060008367ffffffffffffffff81111561037657634e487b7160e01b600052604160045260246000fd5b6040519080825280602002602001820160405280156103bb57816020015b60408051808201909152600080825260208201528152602001906001900390816103945790505b50905060005b848110156104b1576104078686838181106103ec57634e487b7160e01b600052603260045260246000fd5b90506020020160208101906104019190610727565b8561014e565b82828151811061042757634e487b7160e01b600052603260045260246000fd5b60209081029190910101515261047186868381811061045657634e487b7160e01b600052603260045260246000fd5b905060200201602081019061046b9190610727565b856104ba565b82828151811061049157634e487b7160e01b600052603260045260246000fd5b6020908102919091018101510152806104a9816109be565b9150506103c1565b50949350505050565b600154604051632c45227d60e21b81526001600160a01b038481166004830152600092839291169063b11489f49060240160206040518083038186803b15801561050357600080fd5b505afa158015610517573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061053b9190610743565b90506001600160a01b0381166105555760009150506102ba565b6040516361bfb47160e11b81526001600160a01b038481166004830152600091829184169063c37f68e29060240160806040518083038186803b15801561059b57600080fd5b505afa1580156105af573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105d39190610830565b9350509250506105fe670de0b6b3a76400006105f883856106f390919063ffffffff16565b90610706565b9695505050505050565b6000546001600160a01b031633146106325760405162461bcd60e51b81526004016102ea9061094a565b6001600160a01b0381166106975760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016102ea565b6106a0816106a3565b50565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60006106ff828461099f565b9392505050565b60006106ff828461097f565b8051801515811461072257600080fd5b919050565b600060208284031215610738578081fd5b81356106ff816109ef565b600060208284031215610754578081fd5b81516106ff816109ef565b60008060408385031215610771578081fd5b823561077c816109ef565b9150602083013561078c816109ef565b809150509250929050565b6000806000604084860312156107ab578081fd5b833567ffffffffffffffff808211156107c2578283fd5b818601915086601f8301126107d5578283fd5b8135818111156107e3578384fd5b8760208260051b85010111156107f7578384fd5b6020928301955093505084013561080d816109ef565b809150509250925092565b600060208284031215610829578081fd5b5051919050565b60008060008060808587031215610845578081fd5b505082516020840151604085015160609095015191969095509092509050565b6000806000806000806000806000806101408b8d031215610884578586fd5b8a51995060208b0151985060408b0151975060608b0151965060808b015195506108b060a08c01610712565b94506108be60c08c01610712565b93506108cc60e08c01610712565b92506108db6101008c01610712565b91506108ea6101208c01610712565b90509295989b9194979a5092959850565b602080825282518282018190526000919060409081850190868401855b8281101561093d57815180518552860151868501529284019290850190600101610918565b5091979650505050505050565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b60008261099a57634e487b7160e01b81526012600452602481fd5b500490565b60008160001904831182151516156109b9576109b96109d9565b500290565b60006000198214156109d2576109d26109d9565b5060010190565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811681146106a057600080fdfea2646970667358221220f751021748ec127e2cba881a477a36dba3411408ef272debc5cce3d74f438b9664736f6c634300080400330000000000000000000000007f3584b047e3c23fc7ff1fb2ac55130ac2162e20

Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)

0000000000000000000000007f3584b047e3c23fc7ff1fb2ac55130ac2162e20

-----Decoded View---------------
Arg [0] : _memoryContract (address): 0x7f3584b047e3c23fc7ff1fb2ac55130ac2162e20

-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000007f3584b047e3c23fc7ff1fb2ac55130ac2162e20


Block Transaction Gas Used Reward
Age Block Fee Address BC Fee Address Voting Power Jailed Incoming
Block Uncle Number Difficulty Gas Used Reward
Loading
Loading
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.