Skip to content
Verified contractExactUNLICENSED

HoldefiRead

Address0xeaa9af1bf6e226e36bcc0702b4bbde89b78914ea
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.6.12

 

Same code

Only this contract

 

Details

Compiler
solc 0.6.12+commit.27d51765
Language
solidity
Optimization
Yes, 200 runs
EVM version
istanbul
License
UNLICENSED
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
12,587,856
Creation transaction
0x0c29fd887f…59a1ed95bc

HoldefiV1.1/HoldefiRead.sol

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.6.12;
pragma experimental ABIEncoderV2;

import "./IERC20.sol";

interface IHoldefi {

	struct Market {
		uint256 totalSupply;

		uint256 supplyIndex;
		uint256 supplyIndexUpdateTime;

		uint256 totalBorrow;

		uint256 borrowIndex;
		uint256 borrowIndexUpdateTime;

		uint256 promotionReserveScaled;
		uint256 promotionReserveLastUpdateTime;

		uint256 promotionDebtScaled;
		uint256 promotionDebtLastUpdateTime;
	}


	struct Collateral {
		uint256 totalCollateral;
		uint256 totalLiquidatedCollateral;
	}

	function marketAssets(address market) external view returns(Market memory);
	function collateralAssets(address collateral) external view returns(Collateral memory);

	function getAccountSupply(address account, address market)
		external
		view
		returns (uint256 balance, uint256 interest, uint256 currentSupplyIndex);

	function getAccountBorrow(address account, address market, address collateral)
		external
		view
		returns (uint256 balance, uint256 interest, uint256 currentBorrowIndex);

	function getAccountCollateral(address account, address collateral)
		external
		view
		returns (
			uint256 balance,
			uint256 timeSinceLastActivity,
			uint256 borrowPowerValue,
			uint256 totalBorrowValue,
			bool underCollateral
		);

	function getCurrentSupplyIndex (address market)
		external
		view
		returns (
			uint256 supplyIndex,
			uint256 supplyRate,
			uint256 currentTime
		);

	function getCurrentBorrowIndex (address market)
		external
		view
		returns (
			uint256 borrowIndex,
			uint256 borrowRate,
			uint256 currentTime
		);

	function marketDebt (address collateral, address market)
		external
		view
		returns(
			uint256 debt
		);

	function isPaused(string memory operation) external view returns (bool res);
}

interface IHoldefiSettings {

	struct MarketSettings {
		bool isExist;
		bool isActive;      

		uint256 borrowRate;
		uint256 borrowRateUpdateTime;

		uint256 suppliersShareRate;
		uint256 suppliersShareRateUpdateTime;

		uint256 promotionRate;
	}

	struct CollateralSettings {
		bool isExist;
		bool isActive;    

		uint256 valueToLoanRate; 
		uint256 VTLUpdateTime;

		uint256 penaltyRate;
		uint256 penaltyUpdateTime;

		uint256 bonusRate;
	}

	function marketAssets(address market) external view returns(MarketSettings memory);
	function collateralAssets(address collateral) external view returns(CollateralSettings memory);
}


interface IHoldefiPrices {
	function getPrice(address asset) external view returns (uint256 price, uint256 priceDecimals);
}


contract HoldefiRead {

	address constant public ethAddress = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;

	string[8] private operationsList = [
		"supply",
		"withdrawSupply",
		"collateralize",
		"withdrawCollateral",
		"borrow",
		"repayBorrow",
		"liquidateBorrowerCollateral",
		"buyLiquidatedCollateral"
	];

	struct AccountMarketData {
		address market;
		uint256 balance;
		uint256 interest;
		uint256 index;
	}

	struct AccountCollateralData {
		address collateral;
		uint256 balance;
		uint256 timeSinceLastActivity;
		uint256 borrowPowerValue;
		uint256 totalBorrowValue;
		bool underCollateral;

		AccountMarketData[] userBorrows;
	}

	struct AccountAssetData {
		address asset;
		uint256 walletBalance;
		uint256 allowance;
		uint256 price;
		uint256 priceDecimals;
	}

	struct MarketData {
		address market;

		bool isExist;
		bool isActive;      

		uint256 borrowRate;
		uint256 supplyRate;

		uint256 suppliersShareRate;
		uint256 promotionRate;

		uint256 totalSupply;
		uint256 totalBorrow;

		uint256 supplyIndex;
		uint256 borrowIndex;

		uint256 price;
		uint256 priceDecimals;
	}

	struct CollateralData {
		address collateral;

		bool isExist;
		bool isActive;    

		uint256 valueToLoanRate; 
		uint256 penaltyRate;
		uint256 bonusRate;

		uint256 totalCollateral;
		uint256 totalLiquidatedCollateral;

		MarketDebtData[] marketDebt;

		uint256 price;
		uint256 priceDecimals;
	}

	struct OperationPauseStatus {
		string operation;
		bool pauseStatus;
	}

	struct MarketDebtData {
		address market;
		uint256 debt;
	}

	IHoldefi public holdefi;

	IHoldefiSettings public holdefiSettings;

	IHoldefiPrices public holdefiPrices;


	constructor(
		IHoldefi holdefiAddress,
		IHoldefiSettings holdefiSettingsAddress,
		IHoldefiPrices holdefiPricesAddress
	)
		public
	{
		holdefi = holdefiAddress;
		holdefiSettings = holdefiSettingsAddress;
		holdefiPrices = holdefiPricesAddress;
	}

	function getWalletBalance(address account, address asset) public view returns (uint256 res) {
		if (asset == ethAddress) {
			res = account.balance;
		}
		else {
			IERC20 token = IERC20(asset);
			res = token.balanceOf(account);
		}
	}

	function getWalletAllowance(address account, address asset) public view returns (uint256 res) {
		if (asset != ethAddress) {
			IERC20 token = IERC20(asset);
			res = token.allowance(account, address(holdefi));
		}
	}


	function getUserData(address userAddress, address[] memory marketList, address[] memory collateralList)
		public
		view
		returns(
			AccountMarketData[] memory userSupplies,
			AccountCollateralData[] memory userCollaterals,
			AccountAssetData[] memory userAssets
		)
	{
		userSupplies = new AccountMarketData[](marketList.length);
		userCollaterals = new AccountCollateralData[](collateralList.length);
		address[] memory assets = new address[](marketList.length + collateralList.length);

		bool isExist;
		uint256 index;
		uint256 i;
		uint256 j;
		for (i = 0 ; i < collateralList.length ; i++) {
			isExist = false;
			userCollaterals[i].collateral = collateralList[i];
			(
				userCollaterals[i].balance,
				userCollaterals[i].timeSinceLastActivity,
				userCollaterals[i].borrowPowerValue,
				userCollaterals[i].totalBorrowValue,
				userCollaterals[i].underCollateral
			) = holdefi.getAccountCollateral(userAddress, collateralList[i]);
			userCollaterals[i].userBorrows = new AccountMarketData[](marketList.length);
			for (j = 0 ; j < marketList.length ; j++) {
				if (i == 0) {
					userSupplies[j].market = marketList[j];
					(
						userSupplies[j].balance,
						userSupplies[j].interest,
						userSupplies[j].index
					) = holdefi.getAccountSupply(userAddress, marketList[j]);

					assets[j] = marketList[j];
					index = j + 1;
				}
				if (collateralList[i] == marketList[j]) {
					isExist = true;
				}

				userCollaterals[i].userBorrows[j].market = marketList[j];
				(
					userCollaterals[i].userBorrows[j].balance,
					userCollaterals[i].userBorrows[j].interest,
					userCollaterals[i].userBorrows[j].index
				) = holdefi.getAccountBorrow(userAddress, marketList[j], collateralList[i]);
				
			}

			if (!isExist) {
				assets[index] = collateralList[i];
				index = index + 1;
			}
		}

		userAssets = new AccountAssetData[](index);
		for (i = 0 ; i < index ; i++) {
			userAssets[i].asset = assets[i];
			(userAssets[i].price, userAssets[i].priceDecimals) = holdefiPrices.getPrice(assets[i]);
			userAssets[i].walletBalance = getWalletBalance(userAddress, assets[i]);
			userAssets[i].allowance = getWalletAllowance(userAddress, assets[i]);
		}
	}

	function getProtocolData(address[] memory marketList, address[] memory collateralList)
		public
		view
		returns(
			MarketData[] memory markets,
			CollateralData[] memory collaterals, 
			OperationPauseStatus[8] memory operations
		)
	{

		markets = new MarketData[](marketList.length);
		collaterals = new CollateralData[](collateralList.length);

		uint256 i;
		uint256 j;
		for (i = 0 ; i < marketList.length ; i++) {
			IHoldefi.Market memory holdefiMarket = holdefi.marketAssets(marketList[i]);

			markets[i].market = marketList[i];
			markets[i].totalSupply = holdefiMarket.totalSupply;
			markets[i].totalBorrow = holdefiMarket.totalBorrow;

			(
				markets[i].supplyIndex,
				markets[i].supplyRate,
			) = holdefi.getCurrentSupplyIndex(marketList[i]);


			(
				markets[i].borrowIndex,
				markets[i].borrowRate,
			) = holdefi.getCurrentBorrowIndex(marketList[i]);


			IHoldefiSettings.MarketSettings memory holdefiSettingsMarket = holdefiSettings.marketAssets(marketList[i]);
			markets[i].isExist = holdefiSettingsMarket.isExist;
			markets[i].isActive = holdefiSettingsMarket.isActive;
			markets[i].suppliersShareRate = holdefiSettingsMarket.suppliersShareRate;
			markets[i].promotionRate = holdefiSettingsMarket.promotionRate;

			(markets[i].price, markets[i].priceDecimals) = holdefiPrices.getPrice(marketList[i]);
		}

		for (i = 0 ; i < collateralList.length ; i++) {
			IHoldefi.Collateral memory holdefiCollateral = holdefi.collateralAssets(collateralList[i]);
			collaterals[i].collateral = collateralList[i];
			collaterals[i].totalCollateral = holdefiCollateral.totalCollateral;
			collaterals[i].totalLiquidatedCollateral = holdefiCollateral.totalLiquidatedCollateral;

			IHoldefiSettings.CollateralSettings memory holdefiSettingsCollateral = holdefiSettings.collateralAssets(collateralList[i]);
			collaterals[i].isExist = holdefiSettingsCollateral.isExist;
			collaterals[i].isActive = holdefiSettingsCollateral.isActive;
			collaterals[i].valueToLoanRate = holdefiSettingsCollateral.valueToLoanRate;
			collaterals[i].penaltyRate = holdefiSettingsCollateral.penaltyRate;
			collaterals[i].bonusRate = holdefiSettingsCollateral.bonusRate;

			(collaterals[i].price, collaterals[i].priceDecimals) = holdefiPrices.getPrice(collateralList[i]);

			collaterals[i].marketDebt = new MarketDebtData[](marketList.length);
			for (j = 0 ; j < marketList.length ; j++) {
				collaterals[i].marketDebt[j].market = marketList[j];
				collaterals[i].marketDebt[j].debt = holdefi.marketDebt(collateralList[i], marketList[j]);
			}
		}

		for (i = 0 ; i < operationsList.length ; i++) {
			operations[i].operation = operationsList[i];
			operations[i].pauseStatus = holdefi.isPaused(operationsList[i]);
		}
	}


	function getUserProtocolData(address userAddress, address[] memory marketList, address[] memory collateralList)
		public
		view
		returns(
			AccountMarketData[] memory userSupplies,
			AccountCollateralData[] memory userCollaterals,
			AccountAssetData[] memory userAssets,
			MarketData[] memory markets,
			CollateralData[] memory collaterals,
			OperationPauseStatus[8] memory operations
		)
	{
		(userSupplies, userCollaterals, userAssets) = getUserData(userAddress, marketList, collateralList);
		(markets, collaterals, operations) = getProtocolData(marketList, collateralList);
	}


	function getUserAssetsData(address userAddress, address[] memory marketList, address[] memory collateralList)
		public
		view
		returns(
			AccountAssetData[] memory userAssets
		)
	{
		address[] memory assets = new address[](marketList.length + collateralList.length);

		bool isExist;
		uint256 index;
		uint256 i;
		uint256 j;
		for (i = 0 ; i < collateralList.length ; i++) {
			isExist = false;
			for (j = 0 ; j < marketList.length ; j++) {
				if (i == 0) {
					assets[j] = marketList[j];
					index = j + 1;
				}

				if (collateralList[i] == marketList[j]) {
					isExist = true;
				}
			}

			if (!isExist) {
				assets[index] = collateralList[i];
				index = index + 1;
			}
		}

		userAssets = new AccountAssetData[](index);
		for (i = 0 ; i < index ; i++) {
			userAssets[i].asset = assets[i];
			(userAssets[i].price, userAssets[i].priceDecimals) = holdefiPrices.getPrice(assets[i]);
			userAssets[i].walletBalance = getWalletBalance(userAddress, assets[i]);
			userAssets[i].allowance = getWalletAllowance(userAddress, assets[i]);
		}
	}
}

HoldefiV1.1/IERC20.sol

// SPDX-License-Identifier: MIT

pragma solidity ^0.6.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `recipient`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `sender` to `recipient` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);

    /**
     * @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);
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "istanbul",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.