zellic-audit
Initial commit
f998fcd
raw
history blame
15 kB
{
"language": "Solidity",
"settings": {
"evmVersion": "london",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": true,
"runs": 200
},
"remappings": [],
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
},
"sources": {
"@openzeppelin/contracts/utils/math/SafeMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol)\n\npragma solidity ^0.8.0;\n\n// CAUTION\n// This version of SafeMath should only be used with Solidity 0.8 or later,\n// because it relies on the compiler's built in overflow checks.\n\n/**\n * @dev Wrappers over Solidity's arithmetic operations.\n *\n * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler\n * now has built in overflow checking.\n */\nlibrary SafeMath {\n /**\n * @dev Returns the addition of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n uint256 c = a + b;\n if (c < a) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b > a) return (false, 0);\n return (true, a - b);\n }\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, with an overflow flag.\n *\n * _Available since v3.4._\n */\n function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) return (true, 0);\n uint256 c = a * b;\n if (c / a != b) return (false, 0);\n return (true, c);\n }\n }\n\n /**\n * @dev Returns the division of two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a / b);\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.\n *\n * _Available since v3.4._\n */\n function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {\n unchecked {\n if (b == 0) return (false, 0);\n return (true, a % b);\n }\n }\n\n /**\n * @dev Returns the addition of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `+` operator.\n *\n * Requirements:\n *\n * - Addition cannot overflow.\n */\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n return a + b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting on\n * overflow (when the result is negative).\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return a - b;\n }\n\n /**\n * @dev Returns the multiplication of two unsigned integers, reverting on\n * overflow.\n *\n * Counterpart to Solidity's `*` operator.\n *\n * Requirements:\n *\n * - Multiplication cannot overflow.\n */\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n return a * b;\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator.\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return a / b;\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting when dividing by zero.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return a % b;\n }\n\n /**\n * @dev Returns the subtraction of two unsigned integers, reverting with custom message on\n * overflow (when the result is negative).\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {trySub}.\n *\n * Counterpart to Solidity's `-` operator.\n *\n * Requirements:\n *\n * - Subtraction cannot overflow.\n */\n function sub(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b <= a, errorMessage);\n return a - b;\n }\n }\n\n /**\n * @dev Returns the integer division of two unsigned integers, reverting with custom message on\n * division by zero. The result is rounded towards zero.\n *\n * Counterpart to Solidity's `/` operator. Note: this function uses a\n * `revert` opcode (which leaves remaining gas untouched) while Solidity\n * uses an invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function div(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a / b;\n }\n }\n\n /**\n * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),\n * reverting with custom message when dividing by zero.\n *\n * CAUTION: This function is deprecated because it requires allocating memory for the error\n * message unnecessarily. For custom revert reasons use {tryMod}.\n *\n * Counterpart to Solidity's `%` operator. This function uses a `revert`\n * opcode (which leaves remaining gas untouched) while Solidity uses an\n * invalid opcode to revert (consuming all remaining gas).\n *\n * Requirements:\n *\n * - The divisor cannot be zero.\n */\n function mod(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n unchecked {\n require(b > 0, errorMessage);\n return a % b;\n }\n }\n}\n"
},
"contracts/neuron-option-strategy/libraries/ShareMath.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.9;\n\nimport { SafeMath } from \"@openzeppelin/contracts/utils/math/SafeMath.sol\";\nimport { Vault } from \"./Vault.sol\";\n\nlibrary ShareMath {\n using SafeMath for uint256;\n\n uint256 internal constant PLACEHOLDER_UINT = 1;\n\n function assetToShares(\n uint256 assetAmount,\n uint256 assetPerShare,\n uint256 decimals\n ) internal pure returns (uint256) {\n // If this throws, it means that vault's roundPricePerShare[currentRound] has not been set yet\n // which should never happen.\n // Has to be larger than 1 because `1` is used in `initRoundPricePerShares` to prevent cold writes.\n require(assetPerShare > PLACEHOLDER_UINT, \"Invalid assetPerShare\");\n\n return assetAmount.mul(10**decimals).div(assetPerShare);\n }\n\n function sharesToAsset(\n uint256 shares,\n uint256 assetPerShare,\n uint256 decimals\n ) internal pure returns (uint256) {\n // If this throws, it means that vault's roundPricePerShare[currentRound] has not been set yet\n // which should never happen.\n // Has to be larger than 1 because `1` is used in `initRoundPricePerShares` to prevent cold writes.\n require(assetPerShare > PLACEHOLDER_UINT, \"Invalid assetPerShare\");\n\n return shares.mul(assetPerShare).div(10**decimals);\n }\n\n /**\n * @notice Returns the shares unredeemed by the user given their DepositReceipt\n * @param depositReceipt is the user's deposit receipt\n * @param currentRound is the `round` stored on the vault\n * @param assetPerShare is the price in asset per share\n * @param decimals is the number of decimals the asset/shares use\n * @return unredeemedShares is the user's virtual balance of shares that are owed\n */\n function getSharesFromReceipt(\n Vault.DepositReceipt memory depositReceipt,\n uint256 currentRound,\n uint256 assetPerShare,\n uint256 decimals\n ) internal pure returns (uint256 unredeemedShares) {\n if (depositReceipt.round > 0 && depositReceipt.round < currentRound) {\n uint256 sharesFromRound = assetToShares(depositReceipt.amount, assetPerShare, decimals);\n\n return uint256(depositReceipt.unredeemedShares).add(sharesFromRound);\n }\n return depositReceipt.unredeemedShares;\n }\n\n function pricePerShare(\n uint256 totalSupply,\n uint256 totalBalance,\n uint256 pendingAmount,\n uint256 decimals\n ) internal pure returns (uint256) {\n uint256 singleShare = 10**decimals;\n return totalSupply > 0 ? singleShare.mul(totalBalance.sub(pendingAmount)).div(totalSupply) : singleShare;\n }\n\n /************************************************\n * HELPERS\n ***********************************************/\n\n function assertUint104(uint256 num) internal pure {\n require(num <= type(uint104).max, \"Overflow uint104\");\n }\n\n function assertUint128(uint256 num) internal pure {\n require(num <= type(uint128).max, \"Overflow uint128\");\n }\n}\n"
},
"contracts/neuron-option-strategy/libraries/Vault.sol": {
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity 0.8.9;\n\nlibrary Vault {\n /************************************************\n * IMMUTABLES & CONSTANTS\n ***********************************************/\n\n // Fees are 6-decimal places. For example: 20 * 10**6 = 20%\n uint256 internal constant FEE_MULTIPLIER = 10**6;\n\n // Premium discount has 1-decimal place. For example: 80 * 10**1 = 80%. Which represents a 20% discount.\n uint256 internal constant PREMIUM_DISCOUNT_MULTIPLIER = 10;\n\n struct CollateralVaultParams {\n // Option type the vault is selling\n bool isPut;\n // Token decimals for vault shares\n uint8 decimals;\n // Neuron pool address\n address collateralAsset;\n // Underlying asset of the options sold by vault\n address underlying;\n // Minimum supply of the vault shares issued, for ETH it's 10**10\n uint56 minimumSupply;\n // Vault cap\n uint104 cap;\n }\n\n struct CollateralUpdate {\n address[] newCollateralVaults;\n address[] newCollateralAssets;\n }\n\n struct VaultParams {\n // Option type the vault is selling\n bool isPut;\n // Asset used in Theta / Delta Vault\n address[] collateralAssets;\n // Underlying asset of the options sold by vault\n address underlying;\n // Addresses of collateral vaults for collateral assets\n address[] collateralVaults;\n }\n\n struct AuctionParams {\n // Auction duration\n uint256 auctionDuration;\n // Auction bid token address\n address auctionBiddingToken;\n }\n\n struct OptionState {\n // Option that the vault is shorting / longing in the next cycle\n address nextOption;\n // Option that the vault is currently shorting / longing\n address currentOption;\n // The timestamp when the `nextOption` can be used by the vault\n uint32 nextOptionReadyAt;\n }\n\n struct CollateralVaultState {\n // 32 byte slot 1\n // Current round number. `round` represents the number of `period`s elapsed.\n uint16 round;\n // Amount that is currently locked for selling options\n uint104 lockedAmount;\n // Amount that was locked for selling options in the previous round\n // used for calculating performance fee deduction\n uint104 lastLockedAmount;\n // 32 byte slot 2\n // Stores the total tally of how much of `asset` there is\n // to be used to mint nTHETA tokens\n uint128 totalPending;\n // Amount locked for scheduled withdrawals;\n uint128 queuedWithdrawShares;\n bool isDisabled;\n }\n\n struct VaultState {\n // 32 byte slot 1\n // Current round number. `round` represents the number of `period`s elapsed.\n uint16 round;\n // Amount that is currently locked for selling options\n uint104 lockedValue;\n // Amount that was locked for selling options in the previous round\n // used for calculating performance fee deduction\n uint104 lastLockedValue;\n }\n\n struct DepositReceipt {\n // Maximum of 65535 rounds. Assuming 1 round is 7 days, maximum is 1256 years.\n uint16 round;\n // Deposit amount, max 20,282,409,603,651 or 20 trillion ETH deposit\n uint104 amount;\n // Unredeemed shares balance\n uint128 unredeemedShares;\n }\n\n struct Withdrawal {\n // Maximum of 65535 rounds. Assuming 1 round is 7 days, maximum is 1256 years.\n uint16 round;\n // Number of shares withdrawn\n uint128 shares;\n }\n\n struct AuctionSellOrder {\n // Amount of `asset` token offered in auction\n uint96 sellAmount;\n // Amount of onToken requested in auction\n uint96 buyAmount;\n // User Id of delta vault in latest gnosis auction\n uint64 userId;\n }\n}\n"
}
}
}