|
{
|
|
"language": "Solidity",
|
|
"settings": {
|
|
"evmVersion": "london",
|
|
"libraries": {},
|
|
"metadata": {
|
|
"bytecodeHash": "ipfs",
|
|
"useLiteralContent": true
|
|
},
|
|
"optimizer": {
|
|
"enabled": true,
|
|
"runs": 2000
|
|
},
|
|
"remappings": [],
|
|
"outputSelection": {
|
|
"*": {
|
|
"*": [
|
|
"evm.bytecode",
|
|
"evm.deployedBytecode",
|
|
"devdoc",
|
|
"userdoc",
|
|
"metadata",
|
|
"abi"
|
|
]
|
|
}
|
|
}
|
|
},
|
|
"sources": {
|
|
"@adrastia-oracle/adrastia-core/contracts/accumulators/AbstractAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin-v4/contracts/utils/introspection/IERC165.sol\";\nimport \"@openzeppelin-v4/contracts/utils/math/SafeCast.sol\";\n\nimport \"../interfaces/IAccumulator.sol\";\n\nabstract contract AbstractAccumulator is IERC165, IAccumulator {\n uint256 public immutable override changePrecision = 10**8;\n\n uint256 public immutable override updateThreshold;\n\n constructor(uint256 updateThreshold_) {\n updateThreshold = updateThreshold_;\n }\n\n /// @inheritdoc IAccumulator\n function updateThresholdSurpassed(address token) public view virtual override returns (bool) {\n return changeThresholdSurpassed(token, updateThreshold);\n }\n\n /// @inheritdoc IERC165\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccumulator).interfaceId;\n }\n\n function calculateChange(uint256 a, uint256 b) internal view virtual returns (uint256 change, bool isInfinite) {\n // Ensure a is never smaller than b\n if (a < b) {\n uint256 temp = a;\n a = b;\n b = temp;\n }\n\n // a >= b\n\n if (a == 0) {\n // a == b == 0 (since a >= b), therefore no change\n return (0, false);\n } else if (b == 0) {\n // (a > 0 && b == 0) => change threshold passed\n // Zero to non-zero always returns true\n return (0, true);\n }\n\n unchecked {\n uint256 delta = a - b; // a >= b, therefore no underflow\n uint256 preciseDelta = delta * changePrecision;\n\n // If the delta is so large that multiplying by CHANGE_PRECISION overflows, we assume that\n // the change threshold has been surpassed.\n // If our assumption is incorrect, the accumulator will be extra-up-to-date, which won't\n // really break anything, but will cost more gas in keeping this accumulator updated.\n if (preciseDelta < delta) return (0, true);\n\n change = preciseDelta / b;\n isInfinite = false;\n }\n }\n\n function changeThresholdSurpassed(\n uint256 a,\n uint256 b,\n uint256 changeThreshold\n ) internal view virtual returns (bool) {\n (uint256 change, bool isInfinite) = calculateChange(a, b);\n\n return isInfinite || change >= changeThreshold;\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/accumulators/PriceAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\npragma experimental ABIEncoderV2;\n\nimport \"@openzeppelin-v4/contracts/utils/introspection/IERC165.sol\";\nimport \"@openzeppelin-v4/contracts/utils/math/SafeCast.sol\";\n\nimport \"./AbstractAccumulator.sol\";\nimport \"../interfaces/IPriceAccumulator.sol\";\nimport \"../interfaces/IPriceOracle.sol\";\nimport \"../libraries/ObservationLibrary.sol\";\nimport \"../libraries/AddressLibrary.sol\";\nimport \"../utils/SimpleQuotationMetadata.sol\";\n\nabstract contract PriceAccumulator is\n IERC165,\n IPriceAccumulator,\n IPriceOracle,\n AbstractAccumulator,\n SimpleQuotationMetadata\n{\n using AddressLibrary for address;\n using SafeCast for uint256;\n\n uint256 public immutable minUpdateDelay;\n uint256 public immutable maxUpdateDelay;\n\n mapping(address => AccumulationLibrary.PriceAccumulator) public accumulations;\n mapping(address => ObservationLibrary.PriceObservation) public observations;\n\n /**\n * @notice Emitted when the observed price is validated against a user (updater) provided price.\n * @param token The token that the price validation is for.\n * @param observedPrice The observed price from the on-chain data source.\n * @param providedPrice The price provided externally by the user (updater).\n * @param timestamp The timestamp of the block that the validation was performed in.\n * @param succeeded True if the observed price closely matches the provided price; false otherwise.\n */\n event ValidationPerformed(\n address indexed token,\n uint256 observedPrice,\n uint256 providedPrice,\n uint256 timestamp,\n bool succeeded\n );\n\n constructor(\n address quoteToken_,\n uint256 updateThreshold_,\n uint256 minUpdateDelay_,\n uint256 maxUpdateDelay_\n ) AbstractAccumulator(updateThreshold_) SimpleQuotationMetadata(quoteToken_) {\n require(maxUpdateDelay_ >= minUpdateDelay_, \"PriceAccumulator: INVALID_UPDATE_DELAYS\");\n\n minUpdateDelay = minUpdateDelay_;\n maxUpdateDelay = maxUpdateDelay_;\n }\n\n /// @inheritdoc IPriceAccumulator\n function calculatePrice(\n AccumulationLibrary.PriceAccumulator calldata firstAccumulation,\n AccumulationLibrary.PriceAccumulator calldata secondAccumulation\n ) external pure virtual override returns (uint112 price) {\n require(firstAccumulation.timestamp != 0, \"PriceAccumulator: TIMESTAMP_CANNOT_BE_ZERO\");\n\n uint32 deltaTime = secondAccumulation.timestamp - firstAccumulation.timestamp;\n require(deltaTime != 0, \"PriceAccumulator: DELTA_TIME_CANNOT_BE_ZERO\");\n\n unchecked {\n // Underflow is desired and results in correct functionality\n price = (secondAccumulation.cumulativePrice - firstAccumulation.cumulativePrice) / deltaTime;\n }\n }\n\n /// @notice Determines whether the specified change threshold has been surpassed for the specified token.\n /// @dev Calculates the change from the stored observation to the current observation.\n /// @param token The token to check.\n /// @param changeThreshold The change threshold as a percentage multiplied by the change precision\n /// (`changePrecision`). Ex: a 1% change is respresented as 0.01 * `changePrecision`.\n /// @return surpassed True if the update threshold has been surpassed; false otherwise.\n function changeThresholdSurpassed(address token, uint256 changeThreshold)\n public\n view\n virtual\n override\n returns (bool)\n {\n uint256 price = fetchPrice(token);\n\n ObservationLibrary.PriceObservation storage lastObservation = observations[token];\n\n return changeThresholdSurpassed(price, lastObservation.price, changeThreshold);\n }\n\n /// @notice Checks if this accumulator needs an update by checking the time since the last update and the change in\n /// liquidities.\n /// @param data The encoded address of the token for which to perform the update.\n /// @inheritdoc IUpdateable\n function needsUpdate(bytes memory data) public view virtual override returns (bool) {\n uint256 deltaTime = timeSinceLastUpdate(data);\n if (deltaTime < minUpdateDelay) {\n // Ensures updates occur at most once every minUpdateDelay (seconds)\n return false;\n } else if (deltaTime >= maxUpdateDelay) {\n // Ensures updates occur (optimistically) at least once every maxUpdateDelay (seconds)\n return true;\n }\n\n /*\n * maxUpdateDelay > deltaTime >= minUpdateDelay\n *\n * Check if the % change in price warrants an update (saves gas vs. always updating on change)\n */\n address token = abi.decode(data, (address));\n\n return updateThresholdSurpassed(token);\n }\n\n /// @param data The encoded address of the token for which to perform the update.\n /// @inheritdoc IUpdateable\n function canUpdate(bytes memory data) public view virtual override returns (bool) {\n return needsUpdate(data);\n }\n\n /// @notice Updates the accumulator for a specific token.\n /// @dev Must be called by an EOA to limit the attack vector, unless it's the first observation for a token.\n /// @param data Encoding of the token address followed by the expected price.\n /// @return updated True if anything was updated; false otherwise.\n function update(bytes memory data) public virtual override returns (bool) {\n if (needsUpdate(data)) return performUpdate(data);\n\n return false;\n }\n\n /// @param data The encoded address of the token for which the update relates to.\n /// @inheritdoc IUpdateable\n function lastUpdateTime(bytes memory data) public view virtual override returns (uint256) {\n address token = abi.decode(data, (address));\n\n return observations[token].timestamp;\n }\n\n /// @param data The encoded address of the token for which the update relates to.\n /// @inheritdoc IUpdateable\n function timeSinceLastUpdate(bytes memory data) public view virtual override returns (uint256) {\n return block.timestamp - lastUpdateTime(data);\n }\n\n /// @inheritdoc IPriceAccumulator\n function getLastAccumulation(address token)\n public\n view\n virtual\n override\n returns (AccumulationLibrary.PriceAccumulator memory)\n {\n return accumulations[token];\n }\n\n /// @inheritdoc IPriceAccumulator\n function getCurrentAccumulation(address token)\n public\n view\n virtual\n override\n returns (AccumulationLibrary.PriceAccumulator memory accumulation)\n {\n ObservationLibrary.PriceObservation storage lastObservation = observations[token];\n require(lastObservation.timestamp != 0, \"PriceAccumulator: UNINITIALIZED\");\n\n accumulation = accumulations[token]; // Load last accumulation\n\n uint32 deltaTime = (block.timestamp - lastObservation.timestamp).toUint32();\n\n if (deltaTime != 0) {\n // The last observation price has existed for some time, so we add that\n unchecked {\n // Overflow is desired and results in correct functionality\n // We add the last price multiplied by the time that price was active\n accumulation.cumulativePrice += lastObservation.price * deltaTime;\n\n accumulation.timestamp = block.timestamp.toUint32();\n }\n }\n }\n\n /// @inheritdoc IERC165\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(IERC165, SimpleQuotationMetadata, AbstractAccumulator)\n returns (bool)\n {\n return\n interfaceId == type(IPriceAccumulator).interfaceId ||\n interfaceId == type(IPriceOracle).interfaceId ||\n interfaceId == type(IUpdateable).interfaceId ||\n SimpleQuotationMetadata.supportsInterface(interfaceId) ||\n AbstractAccumulator.supportsInterface(interfaceId);\n }\n\n /// @inheritdoc IPriceOracle\n function consultPrice(address token) public view virtual override returns (uint112 price) {\n if (token == quoteTokenAddress()) return uint112(10**quoteTokenDecimals());\n\n ObservationLibrary.PriceObservation storage observation = observations[token];\n\n require(observation.timestamp != 0, \"PriceAccumulator: MISSING_OBSERVATION\");\n\n return observation.price;\n }\n\n /// @param maxAge The maximum age of the quotation, in seconds. If 0, fetches the real-time price.\n /// @inheritdoc IPriceOracle\n function consultPrice(address token, uint256 maxAge) public view virtual override returns (uint112 price) {\n if (token == quoteTokenAddress()) return uint112(10**quoteTokenDecimals());\n\n if (maxAge == 0) return fetchPrice(token);\n\n ObservationLibrary.PriceObservation storage observation = observations[token];\n\n require(observation.timestamp != 0, \"PriceAccumulator: MISSING_OBSERVATION\");\n require(block.timestamp <= observation.timestamp + maxAge, \"PriceAccumulator: RATE_TOO_OLD\");\n\n return observation.price;\n }\n\n function performUpdate(bytes memory data) internal virtual returns (bool) {\n address token = abi.decode(data, (address));\n\n uint112 price = fetchPrice(token);\n\n // If the observation fails validation, do not update anything\n if (!validateObservation(data, price)) return false;\n\n ObservationLibrary.PriceObservation storage observation = observations[token];\n AccumulationLibrary.PriceAccumulator storage accumulation = accumulations[token];\n\n if (observation.timestamp == 0) {\n /*\n * Initialize\n */\n observation.price = accumulation.cumulativePrice = price;\n observation.timestamp = accumulation.timestamp = block.timestamp.toUint32();\n\n emit Updated(token, price, block.timestamp);\n\n return true;\n }\n\n /*\n * Update\n */\n\n uint32 deltaTime = (block.timestamp - observation.timestamp).toUint32();\n\n if (deltaTime != 0) {\n unchecked {\n // Overflow is desired and results in correct functionality\n // We add the last price multiplied by the time that price was active\n accumulation.cumulativePrice += observation.price * deltaTime;\n\n observation.price = price;\n\n observation.timestamp = accumulation.timestamp = block.timestamp.toUint32();\n }\n\n emit Updated(token, price, block.timestamp);\n\n return true;\n }\n\n return false;\n }\n\n /// @notice Requires the message sender of an update to not be a smart contract.\n /// @dev Can be overridden to disable this requirement.\n function validateObservationRequireEoa() internal virtual {\n // Message sender should never be a smart contract. Smart contracts can use flash attacks to manipulate data.\n require(msg.sender == tx.origin, \"PriceAccumulator: MUST_BE_EOA\");\n }\n\n function validateObservationAllowedChange(address) internal virtual returns (uint256) {\n // Allow the price to change by half of the update threshold\n return updateThreshold / 2;\n }\n\n function validateObservation(bytes memory updateData, uint112 price) internal virtual returns (bool) {\n validateObservationRequireEoa();\n\n // Extract provided price\n // The message sender should call consultPrice immediately before calling the update function, passing\n // the returned value into the update data.\n // We could also use this to anchor the price to an off-chain price\n (address token, uint112 pPrice) = abi.decode(updateData, (address, uint112));\n\n uint256 allowedChangeThreshold = validateObservationAllowedChange(token);\n\n // We require the price to not change by more than the threshold above\n // This check limits the ability of MEV and flashbots from manipulating data\n bool validated = !changeThresholdSurpassed(price, pPrice, allowedChangeThreshold);\n\n emit ValidationPerformed(token, price, pPrice, block.timestamp, validated);\n\n return validated;\n }\n\n function fetchPrice(address token) internal view virtual returns (uint112 price);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/accumulators/proto/uniswap/UniswapV3PriceAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\npragma experimental ABIEncoderV2;\n\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol\";\nimport \"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol\";\n\nimport \"@openzeppelin-v4/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\nimport \"../../PriceAccumulator.sol\";\nimport \"../../../libraries/SafeCastExt.sol\";\nimport \"../../../libraries/uniswap-lib/FullMath.sol\";\n\ncontract UniswapV3PriceAccumulator is PriceAccumulator {\n using AddressLibrary for address;\n using SafeCastExt for uint256;\n\n /// @notice The identifying key of the pool\n struct PoolKey {\n address token0;\n address token1;\n uint24 fee;\n }\n\n address public immutable uniswapFactory;\n\n bytes32 public immutable initCodeHash;\n\n uint24[] public poolFees;\n\n constructor(\n address uniswapFactory_,\n bytes32 initCodeHash_,\n uint24[] memory poolFees_,\n address quoteToken_,\n uint256 updateTheshold_,\n uint256 minUpdateDelay_,\n uint256 maxUpdateDelay_\n ) PriceAccumulator(quoteToken_, updateTheshold_, minUpdateDelay_, maxUpdateDelay_) {\n uniswapFactory = uniswapFactory_;\n initCodeHash = initCodeHash_;\n poolFees = poolFees_;\n }\n\n /// @inheritdoc PriceAccumulator\n function canUpdate(bytes memory data) public view virtual override returns (bool) {\n address token = abi.decode(data, (address));\n\n if (token == address(0) || token == quoteToken) {\n // Invalid token\n return false;\n }\n\n (bool hasLiquidity, ) = calculateWeightedPrice(token);\n if (!hasLiquidity) {\n // Can't update if there's no liquidity (reverts)\n return false;\n }\n\n return super.canUpdate(data);\n }\n\n function calculatePriceFromSqrtPrice(\n address token,\n address quoteToken_,\n uint160 sqrtPriceX96,\n uint128 tokenAmount\n ) internal pure returns (uint256 price) {\n // Calculate quoteAmount with better precision if it doesn't overflow when multiplied by itself\n if (sqrtPriceX96 <= type(uint128).max) {\n uint256 ratioX192 = uint256(sqrtPriceX96) * sqrtPriceX96;\n price = token < quoteToken_\n ? FullMath.mulDiv(ratioX192, tokenAmount, 1 << 192)\n : FullMath.mulDiv(1 << 192, tokenAmount, ratioX192);\n } else {\n uint256 ratioX128 = FullMath.mulDiv(sqrtPriceX96, sqrtPriceX96, 1 << 64);\n price = token < quoteToken_\n ? FullMath.mulDiv(ratioX128, tokenAmount, 1 << 128)\n : FullMath.mulDiv(1 << 128, tokenAmount, ratioX128);\n }\n }\n\n /**\n * @notice Calculates the price of a token across all chosen pools.\n * @dev Uses harmonic mean, weighted by in-range liquidity.\n * @dev When the price equals 0, a price of 1 is actually returned.\n * @param token The token to get the price for.\n * @return hasLiquidity True if at least one of the chosen pools has [enough] in-range liquidity.\n * @return price The price of the specified token in terms of the quote token, scaled by the quote token decimal\n * places. If hasLiquidity equals false, the returned price will always equal 0.\n */\n function calculateWeightedPrice(address token) internal view returns (bool hasLiquidity, uint256 price) {\n uint24[] memory _poolFees = poolFees;\n\n uint128 wholeTokenAmount = computeWholeUnitAmount(token);\n\n uint256 numerator;\n uint256 denominator;\n\n for (uint256 i = 0; i < _poolFees.length; ++i) {\n address pool = computeAddress(uniswapFactory, initCodeHash, getPoolKey(token, quoteToken, _poolFees[i]));\n\n if (pool.isContract()) {\n uint256 liquidity = IUniswapV3Pool(pool).liquidity(); // Note: returns uint128\n if (liquidity == 0) {\n // No in-range liquidity, so ignore\n continue;\n }\n\n // Shift liquidity for more precise calculations as we divide this by the pool price\n // This is safe as liquidity < 2^128\n liquidity = liquidity << 120;\n\n (uint160 sqrtPriceX96, , , , , , ) = IUniswapV3Pool(pool).slot0();\n\n // Add 1 to all prices to prevent divide by 0\n // This should realistically never overflow\n uint256 poolPrice = calculatePriceFromSqrtPrice(token, quoteToken, sqrtPriceX96, wholeTokenAmount) + 1;\n\n // Supports up to 256 pools with max liquidity (2^128) before overflowing (with liquidity << 120)\n numerator += liquidity;\n\n // Note: (liquidity / poolPrice) will equal 0 if liquidity < poolPrice, but\n // for this to happen, price would have to be insanely high\n // (over 18 figures left of the decimal w/ 18 decimal places)\n denominator += liquidity / poolPrice;\n }\n }\n\n if (denominator == 0) {\n // No in-range liquidity (or very little) in all of the pools\n return (false, 0);\n }\n\n return (true, numerator / denominator);\n }\n\n function fetchPrice(address token) internal view virtual override returns (uint112) {\n require(token != quoteToken, \"UniswapV3PriceAccumulator: IDENTICAL_ADDRESSES\");\n require(token != address(0), \"UniswapV3PriceAccumulator: ZERO_ADDRESS\");\n\n (bool hasLiquidity, uint256 _price) = calculateWeightedPrice(token);\n\n // Note: Will cause prices calculated from accumulations to be fixed to the last price\n require(hasLiquidity, \"UniswapV3PriceAccumulator: NO_LIQUIDITY\");\n\n return _price.toUint112();\n }\n\n /// @notice Returns PoolKey: the ordered tokens with the matched fee levels\n /// @param tokenA The first token of a pool, unsorted\n /// @param tokenB The second token of a pool, unsorted\n /// @param fee The fee level of the pool\n /// @return Poolkey The pool details with ordered token0 and token1 assignments\n function getPoolKey(\n address tokenA,\n address tokenB,\n uint24 fee\n ) internal pure returns (PoolKey memory) {\n if (tokenA > tokenB) (tokenA, tokenB) = (tokenB, tokenA);\n return PoolKey({token0: tokenA, token1: tokenB, fee: fee});\n }\n\n /// @notice Deterministically computes the pool address given the factory and PoolKey\n /// @param factory The Uniswap V3 factory contract address\n /// @param key The PoolKey\n /// @return pool The contract address of the V3 pool\n function computeAddress(\n address factory,\n bytes32 _initCodeHash,\n PoolKey memory key\n ) internal pure returns (address pool) {\n require(key.token0 < key.token1);\n pool = address(\n uint160(\n uint256(\n keccak256(\n abi.encodePacked(\n hex\"ff\",\n factory,\n keccak256(abi.encode(key.token0, key.token1, key.fee)),\n _initCodeHash\n )\n )\n )\n )\n );\n }\n\n function computeWholeUnitAmount(address token) internal view returns (uint128 amount) {\n amount = uint128(10)**IERC20Metadata(token).decimals();\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/interfaces/IAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\n/**\n * @title IAccumulator\n * @notice An interface that defines an accumulator - that is, a contract that updates cumulative value(s) when the\n * underlying value(s) change by more than the update threshold.\n */\nabstract contract IAccumulator {\n /// @notice Gets the scalar (as a power of 10) to be used for calculating changes in value.\n /// @return The scalar to be used for calculating changes in value.\n function changePrecision() external view virtual returns (uint256);\n\n /// @notice Gets the threshold at which an update to the cumulative value(s) should be performed.\n /// @return A percentage scaled by the change precision.\n function updateThreshold() external view virtual returns (uint256);\n\n /// @notice Determines whether the specified change threshold has been surpassed for the specified token.\n /// @dev Calculates the change from the stored observation to the current observation.\n /// @param token The token to check.\n /// @param changeThreshold The change threshold as a percentage multiplied by the change precision\n /// (`changePrecision`). Ex: a 1% change is respresented as 0.01 * `changePrecision`.\n /// @return surpassed True if the update threshold has been surpassed; false otherwise.\n function changeThresholdSurpassed(address token, uint256 changeThreshold) public view virtual returns (bool);\n\n /// @notice Determines whether the update threshold has been surpassed for the specified token.\n /// @dev Calculates the change from the stored observation to the current observation.\n /// @param token The token to check.\n /// @return surpassed True if the update threshold has been surpassed; false otherwise.\n function updateThresholdSurpassed(address token) public view virtual returns (bool);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/interfaces/IPriceAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\npragma experimental ABIEncoderV2;\n\nimport \"./IAccumulator.sol\";\n\nimport \"../libraries/AccumulationLibrary.sol\";\nimport \"../libraries/ObservationLibrary.sol\";\n\n/**\n * @title IPriceAccumulator\n * @notice An interface that defines a \"price accumulator\" - that is, a cumulative price - with a single quote token\n * and many exchange tokens.\n * @dev Price accumulators are used to calculate time-weighted average prices.\n */\nabstract contract IPriceAccumulator is IAccumulator {\n /// @notice Emitted when the accumulator is updated.\n /// @dev The accumulator's observation and cumulative values are updated when this is emitted.\n /// @param token The address of the token that the update is for.\n /// @param price The quote token denominated price for a whole token.\n /// @param timestamp The epoch timestamp of the update (in seconds).\n event Updated(address indexed token, uint256 price, uint256 timestamp);\n\n /**\n * @notice Calculates a price from two different cumulative prices.\n * @param firstAccumulation The first cumulative price.\n * @param secondAccumulation The last cumulative price.\n * @dev Reverts if the timestamp of the first accumulation is 0, or if it's not strictly less than the timestamp of\n * the second.\n * @return price A time-weighted average price derived from two cumulative prices.\n */\n function calculatePrice(\n AccumulationLibrary.PriceAccumulator calldata firstAccumulation,\n AccumulationLibrary.PriceAccumulator calldata secondAccumulation\n ) external pure virtual returns (uint112 price);\n\n /// @notice Gets the last cumulative price that was stored.\n /// @param token The address of the token to get the cumulative price for.\n /// @return The last cumulative price along with the timestamp of that price.\n function getLastAccumulation(address token)\n public\n view\n virtual\n returns (AccumulationLibrary.PriceAccumulator memory);\n\n /// @notice Gets the current cumulative price.\n /// @param token The address of the token to get the cumulative price for.\n /// @return The current cumulative price along with the timestamp of that price.\n function getCurrentAccumulation(address token)\n public\n view\n virtual\n returns (AccumulationLibrary.PriceAccumulator memory);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/interfaces/IPriceOracle.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\nimport \"./IUpdateable.sol\";\nimport \"./IQuoteToken.sol\";\n\n/// @title IPriceOracle\n/// @notice An interface that defines a price oracle with a single quote token (or currency) and many exchange tokens.\nabstract contract IPriceOracle is IUpdateable, IQuoteToken {\n /**\n * @notice Gets the price of a token in terms of the quote token.\n * @param token The token to get the price of.\n * @return price The quote token denominated price for a whole token.\n */\n function consultPrice(address token) public view virtual returns (uint112 price);\n\n /**\n * @notice Gets the price of a token in terms of the quote token, reverting if the quotation is older than the\n * maximum allowable age.\n * @dev Using maxAge of 0 can be gas costly and the returned data is easier to manipulate.\n * @param token The token to get the price of.\n * @param maxAge The maximum age of the quotation, in seconds. If 0, the function gets the instant rates as of the\n * latest block, straight from the source.\n * @return price The quote token denominated price for a whole token.\n */\n function consultPrice(address token, uint256 maxAge) public view virtual returns (uint112 price);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/interfaces/IQuoteToken.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\n/**\n * @title IQuoteToken\n * @notice An interface that defines a contract containing a quote token (or currency), providing the associated\n * metadata.\n */\nabstract contract IQuoteToken {\n /// @notice Gets the quote token (or currency) name.\n /// @return The name of the quote token (or currency).\n function quoteTokenName() public view virtual returns (string memory);\n\n /// @notice Gets the quote token address (if any).\n /// @dev This may return address(0) if no specific quote token is used (such as an aggregate of quote tokens).\n /// @return The address of the quote token, or address(0) if no specific quote token is used.\n function quoteTokenAddress() public view virtual returns (address);\n\n /// @notice Gets the quote token (or currency) symbol.\n /// @return The symbol of the quote token (or currency).\n function quoteTokenSymbol() public view virtual returns (string memory);\n\n /// @notice Gets the number of decimal places that quote prices have.\n /// @return The number of decimals of the quote token (or currency) that quote prices have.\n function quoteTokenDecimals() public view virtual returns (uint8);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/interfaces/IUpdateable.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\n/// @title IUpdateByToken\n/// @notice An interface that defines a contract that is updateable as per the input data.\nabstract contract IUpdateable {\n /// @notice Performs an update as per the input data.\n /// @param data Any data needed for the update.\n /// @return b True if anything was updated; false otherwise.\n function update(bytes memory data) public virtual returns (bool b);\n\n /// @notice Checks if an update needs to be performed.\n /// @param data Any data relating to the update.\n /// @return b True if an update needs to be performed; false otherwise.\n function needsUpdate(bytes memory data) public view virtual returns (bool b);\n\n /// @notice Check if an update can be performed by the caller (if needed).\n /// @dev Tries to determine if the caller can call update with a valid observation being stored.\n /// @dev This is not meant to be called by state-modifying functions.\n /// @param data Any data relating to the update.\n /// @return b True if an update can be performed by the caller; false otherwise.\n function canUpdate(bytes memory data) public view virtual returns (bool b);\n\n /// @notice Gets the timestamp of the last update.\n /// @param data Any data relating to the update.\n /// @return A unix timestamp.\n function lastUpdateTime(bytes memory data) public view virtual returns (uint256);\n\n /// @notice Gets the amount of time (in seconds) since the last update.\n /// @param data Any data relating to the update.\n /// @return Time in seconds.\n function timeSinceLastUpdate(bytes memory data) public view virtual returns (uint256);\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/libraries/AccumulationLibrary.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\npragma experimental ABIEncoderV2;\n\n/**\n * @notice A library for calculating and storing accumulations of time-weighted average values in the form of sumations\n * of (value * time).\n */\nlibrary AccumulationLibrary {\n /**\n * @notice A struct for storing a snapshot of liquidity accumulations.\n * @dev The difference of a newer snapshot against an older snapshot can be used to derive time-weighted average\n * liquidities by dividing the difference in value by the difference in time.\n */\n struct LiquidityAccumulator {\n /*\n * @notice Accumulates time-weighted average liquidity of the token in the form of a sumation of (price * time),\n * with time measured in seconds.\n * @dev Overflow is desired and results in correct behavior as long as the difference between two snapshots\n * is less than or equal to 2^112.\n */\n uint112 cumulativeTokenLiquidity;\n /*\n * @notice Accumulates time-weighted average liquidity of the quote token in the form of a sumation of\n * (price * time), with time measured in seconds..\n * @dev Overflow is desired and results in correct behavior as long as the difference between two snapshots\n * is less than or equal to 2^112.\n */\n uint112 cumulativeQuoteTokenLiquidity;\n /*\n * @notice The unix timestamp (in seconds) of the last update of (addition to) the cumulative price.\n */\n uint32 timestamp;\n }\n\n /**\n * @notice A struct for storing a snapshot of price accumulations.\n * @dev The difference of a newer snapshot against an older snapshot can be used to derive a time-weighted average\n * price by dividing the difference in value by the difference in time.\n */\n struct PriceAccumulator {\n /*\n * @notice Accumulates time-weighted average prices in the form of a sumation of (price * time), with time\n * measured in seconds.\n * @dev Overflow is desired and results in correct behavior as long as the difference between two snapshots\n * is less than or equal to 2^112.\n */\n uint112 cumulativePrice;\n /*\n * @notice The unix timestamp (in seconds) of the last update of (addition to) the cumulative price.\n */\n uint32 timestamp;\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/libraries/AddressLibrary.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\npragma experimental ABIEncoderV2;\n\nlibrary AddressLibrary {\n /**\n * @notice Determines whether an address contains code (i.e. is a smart contract).\n * @dev Use with caution: if called within a constructor, will return false.\n * @param self The address to check.\n * @return b True if the address contains code, false otherwise.\n */\n function isContract(address self) internal view returns (bool) {\n uint256 size;\n assembly {\n size := extcodesize(self)\n }\n return size > 0;\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/libraries/ObservationLibrary.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\npragma experimental ABIEncoderV2;\n\nlibrary ObservationLibrary {\n struct Observation {\n uint112 price;\n uint112 tokenLiquidity;\n uint112 quoteTokenLiquidity;\n uint32 timestamp;\n }\n\n struct LiquidityObservation {\n uint112 tokenLiquidity;\n uint112 quoteTokenLiquidity;\n uint32 timestamp;\n }\n\n struct PriceObservation {\n uint112 price;\n uint32 timestamp;\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/libraries/SafeCastExt.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.0 (utils/math/SafeCast.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCastExt {\n /**\n * @dev Returns the downcasted uint112 from uint256, reverting on\n * overflow (when the input is greater than largest uint112).\n *\n * Counterpart to Solidity's `uint112` operator.\n *\n * Requirements:\n *\n * - input must fit into 112 bits\n */\n function toUint112(uint256 value) internal pure returns (uint112) {\n require(value <= type(uint112).max, \"SafeCast: value doesn't fit in 112 bits\");\n return uint112(value);\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/libraries/uniswap-lib/FullMath.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\n/**\n * @title Contains 512-bit math\n * @author Uniswap Labs (https://github.com/Uniswap/v3-core/blob/main/contracts/libraries/FullMath.sol)\n * @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of\n * precision\n * @dev Handles \"phantom overflow\" i.e., allows multiplication and division where an intermediate value overflows 256\n * bits\n */\nlibrary FullMath {\n /**\n * @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0\n * @param a The multiplicand\n * @param b The multiplier\n * @param denominator The divisor\n * @return result The 256-bit result\n * @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv\n */\n function mulDiv(\n uint256 a,\n uint256 b,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n // 512-bit multiply [prod1 prod0] = a * b\n // Compute the product mod 2**256 and mod 2**256 - 1\n // then use the Chinese Remainder Theorem to reconstruct\n // the 512 bit result. The result is stored in two 256\n // variables such that product = prod1 * 2**256 + prod0\n uint256 prod0; // Least significant 256 bits of the product\n uint256 prod1; // Most significant 256 bits of the product\n assembly {\n let mm := mulmod(a, b, not(0))\n prod0 := mul(a, b)\n prod1 := sub(sub(mm, prod0), lt(mm, prod0))\n }\n\n // Handle non-overflow cases, 256 by 256 division\n if (prod1 == 0) {\n require(denominator > 0);\n assembly {\n result := div(prod0, denominator)\n }\n return result;\n }\n\n // Make sure the result is less than 2**256.\n // Also prevents denominator == 0\n require(denominator > prod1);\n\n ///////////////////////////////////////////////\n // 512 by 256 division.\n ///////////////////////////////////////////////\n\n // Make division exact by subtracting the remainder from [prod1 prod0]\n // Compute remainder using mulmod\n uint256 remainder;\n assembly {\n remainder := mulmod(a, b, denominator)\n }\n // Subtract 256 bit number from 512 bit number\n assembly {\n prod1 := sub(prod1, gt(remainder, prod0))\n prod0 := sub(prod0, remainder)\n }\n\n // Factor powers of two out of denominator\n // Compute largest power of two divisor of denominator.\n // Always >= 1.\n uint256 twos = denominator & (~denominator + 1);\n // Divide denominator by power of two\n assembly {\n denominator := div(denominator, twos)\n }\n\n // Divide [prod1 prod0] by the factors of two\n assembly {\n prod0 := div(prod0, twos)\n }\n // Shift in bits from prod1 into prod0. For this we need\n // to flip `twos` such that it is 2**256 / twos.\n // If twos is zero, then it becomes one\n assembly {\n twos := add(div(sub(0, twos), twos), 1)\n }\n prod0 |= prod1 * twos;\n\n // Invert denominator mod 2**256\n // Now that denominator is an odd number, it has an inverse\n // modulo 2**256 such that denominator * inv = 1 mod 2**256.\n // Compute the inverse by starting with a seed that is correct\n // correct for four bits. That is, denominator * inv = 1 mod 2**4\n uint256 inv = (3 * denominator) ^ 2;\n // Now use Newton-Raphson iteration to improve the precision.\n // Thanks to Hensel's lifting lemma, this also works in modular\n // arithmetic, doubling the correct bits in each step.\n inv *= 2 - denominator * inv; // inverse mod 2**8\n inv *= 2 - denominator * inv; // inverse mod 2**16\n inv *= 2 - denominator * inv; // inverse mod 2**32\n inv *= 2 - denominator * inv; // inverse mod 2**64\n inv *= 2 - denominator * inv; // inverse mod 2**128\n inv *= 2 - denominator * inv; // inverse mod 2**256\n\n // Because the division is now exact we can divide by multiplying\n // with the modular inverse of denominator. This will give us the\n // correct result modulo 2**256. Since the precoditions guarantee\n // that the outcome is less than 2**256, this is the final result.\n // We don't need to compute the high bits of the result and prod1\n // is no longer required.\n result = prod0 * inv;\n return result;\n }\n }\n\n /**\n * @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or\n * denominator == 0\n * @param a The multiplicand\n * @param b The multiplier\n * @param denominator The divisor\n * @return result The 256-bit result\n */\n function mulDivRoundingUp(\n uint256 a,\n uint256 b,\n uint256 denominator\n ) internal pure returns (uint256 result) {\n unchecked {\n result = mulDiv(a, b, denominator);\n if (mulmod(a, b, denominator) > 0) {\n require(result < type(uint256).max);\n result++;\n }\n }\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-core/contracts/utils/SimpleQuotationMetadata.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\nimport \"@openzeppelin-v4/contracts/utils/introspection/IERC165.sol\";\nimport \"@openzeppelin-v4/contracts/token/ERC20/extensions/IERC20Metadata.sol\";\n\nimport \"../interfaces/IQuoteToken.sol\";\n\ncontract SimpleQuotationMetadata is IQuoteToken, IERC165 {\n address public immutable quoteToken;\n\n constructor(address quoteToken_) {\n quoteToken = quoteToken_;\n }\n\n /// @inheritdoc IQuoteToken\n function quoteTokenName() public view virtual override returns (string memory) {\n return getStringOrBytes32(quoteToken, IERC20Metadata.name.selector);\n }\n\n /// @inheritdoc IQuoteToken\n function quoteTokenAddress() public view virtual override returns (address) {\n return quoteToken;\n }\n\n /// @inheritdoc IQuoteToken\n function quoteTokenSymbol() public view virtual override returns (string memory) {\n return getStringOrBytes32(quoteToken, IERC20Metadata.symbol.selector);\n }\n\n /// @inheritdoc IQuoteToken\n function quoteTokenDecimals() public view virtual override returns (uint8) {\n (bool success, bytes memory result) = quoteToken.staticcall(\n abi.encodeWithSelector(IERC20Metadata.decimals.selector)\n );\n if (!success) return 18; // Return 18 by default\n\n return abi.decode(result, (uint8));\n }\n\n /// @inheritdoc IERC165\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IQuoteToken).interfaceId;\n }\n\n function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {\n // Calculate string length\n uint256 i = 0;\n while (i < 32 && _bytes32[i] != 0) ++i;\n\n bytes memory bytesArray = new bytes(i);\n\n // Extract characters\n for (i = 0; i < 32 && _bytes32[i] != 0; ++i) bytesArray[i] = _bytes32[i];\n\n return string(bytesArray);\n }\n\n function getStringOrBytes32(address contractAddress, bytes4 selector) internal view returns (string memory) {\n (bool success, bytes memory result) = contractAddress.staticcall(abi.encodeWithSelector(selector));\n if (!success) return \"\";\n\n return result.length == 32 ? bytes32ToString(bytes32(result)) : abi.decode(result, (string));\n }\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-periphery/contracts/access/Roles.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\npragma solidity >=0.5.0 <0.9.0;\n\nlibrary Roles {\n bytes32 public constant ADMIN = keccak256(\"ADMIN_ROLE\");\n\n bytes32 public constant ORACLE_UPDATER = keccak256(\"ORACLE_UPDATER_ROLE\");\n}\n"
|
|
},
|
|
"@adrastia-oracle/adrastia-periphery/contracts/accumulators/proto/uniswap/ManagedUniswapV3PriceAccumulator.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\nimport \"@adrastia-oracle/adrastia-core/contracts/accumulators/proto/uniswap/UniswapV3PriceAccumulator.sol\";\n\nimport \"@openzeppelin-v4/contracts/access/AccessControlEnumerable.sol\";\n\nimport \"../../../access/Roles.sol\";\n\ncontract ManagedUniswapV3PriceAccumulator is AccessControlEnumerable, UniswapV3PriceAccumulator {\n constructor(\n address uniswapFactory_,\n bytes32 initCodeHash_,\n uint24[] memory poolFees_,\n address quoteToken_,\n uint256 updateTheshold_,\n uint256 minUpdateDelay_,\n uint256 maxUpdateDelay_\n )\n UniswapV3PriceAccumulator(\n uniswapFactory_,\n initCodeHash_,\n poolFees_,\n quoteToken_,\n updateTheshold_,\n minUpdateDelay_,\n maxUpdateDelay_\n )\n {\n initializeRoles();\n }\n\n /**\n * @notice Modifier to make a function callable only by a certain role. In\n * addition to checking the sender's role, `address(0)` 's role is also\n * considered. Granting a role to `address(0)` is equivalent to enabling\n * this role for everyone.\n */\n modifier onlyRoleOrOpenRole(bytes32 role) {\n if (!hasRole(role, address(0))) {\n require(hasRole(role, msg.sender), \"ManagedUniswapV3PriceAccumulator: MISSING_ROLE\");\n }\n _;\n }\n\n function canUpdate(bytes memory data) public view virtual override returns (bool) {\n // Return false if the message sender is missing the required role\n if (!hasRole(Roles.ORACLE_UPDATER, address(0)) && !hasRole(Roles.ORACLE_UPDATER, msg.sender)) return false;\n\n return super.canUpdate(data);\n }\n\n function update(bytes memory data) public virtual override onlyRoleOrOpenRole(Roles.ORACLE_UPDATER) returns (bool) {\n return super.update(data);\n }\n\n function supportsInterface(bytes4 interfaceId)\n public\n view\n virtual\n override(AccessControlEnumerable, PriceAccumulator)\n returns (bool)\n {\n return\n AccessControlEnumerable.supportsInterface(interfaceId) || PriceAccumulator.supportsInterface(interfaceId);\n }\n\n function initializeRoles() internal virtual {\n // Setup admin role, setting msg.sender as admin\n _setupRole(Roles.ADMIN, msg.sender);\n _setRoleAdmin(Roles.ADMIN, Roles.ADMIN);\n\n // Set admin of ORACLE_UPDATER as ADMIN\n _setRoleAdmin(Roles.ORACLE_UPDATER, Roles.ADMIN);\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/access/AccessControl.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (access/AccessControl.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\nimport \"../utils/Context.sol\";\nimport \"../utils/Strings.sol\";\nimport \"../utils/introspection/ERC165.sol\";\n\n/**\n * @dev Contract module that allows children to implement role-based access\n * control mechanisms. This is a lightweight version that doesn't allow enumerating role\n * members except through off-chain means by accessing the contract event logs. Some\n * applications may benefit from on-chain enumerability, for those cases see\n * {AccessControlEnumerable}.\n *\n * Roles are referred to by their `bytes32` identifier. These should be exposed\n * in the external API and be unique. The best way to achieve this is by\n * using `public constant` hash digests:\n *\n * ```\n * bytes32 public constant MY_ROLE = keccak256(\"MY_ROLE\");\n * ```\n *\n * Roles can be used to represent a set of permissions. To restrict access to a\n * function call, use {hasRole}:\n *\n * ```\n * function foo() public {\n * require(hasRole(MY_ROLE, msg.sender));\n * ...\n * }\n * ```\n *\n * Roles can be granted and revoked dynamically via the {grantRole} and\n * {revokeRole} functions. Each role has an associated admin role, and only\n * accounts that have a role's admin role can call {grantRole} and {revokeRole}.\n *\n * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means\n * that only accounts with this role will be able to grant or revoke other\n * roles. More complex role relationships can be created by using\n * {_setRoleAdmin}.\n *\n * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to\n * grant and revoke this role. Extra precautions should be taken to secure\n * accounts that have been granted it.\n */\nabstract contract AccessControl is Context, IAccessControl, ERC165 {\n struct RoleData {\n mapping(address => bool) members;\n bytes32 adminRole;\n }\n\n mapping(bytes32 => RoleData) private _roles;\n\n bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;\n\n /**\n * @dev Modifier that checks that an account has a specific role. Reverts\n * with a standardized message including the required role.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n *\n * _Available since v4.1._\n */\n modifier onlyRole(bytes32 role) {\n _checkRole(role);\n _;\n }\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) public view virtual override returns (bool) {\n return _roles[role].members[account];\n }\n\n /**\n * @dev Revert with a standard message if `_msgSender()` is missing `role`.\n * Overriding this function changes the behavior of the {onlyRole} modifier.\n *\n * Format of the revert message is described in {_checkRole}.\n *\n * _Available since v4.6._\n */\n function _checkRole(bytes32 role) internal view virtual {\n _checkRole(role, _msgSender());\n }\n\n /**\n * @dev Revert with a standard message if `account` is missing `role`.\n *\n * The format of the revert reason is given by the following regular expression:\n *\n * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/\n */\n function _checkRole(bytes32 role, address account) internal view virtual {\n if (!hasRole(role, account)) {\n revert(\n string(\n abi.encodePacked(\n \"AccessControl: account \",\n Strings.toHexString(uint160(account), 20),\n \" is missing role \",\n Strings.toHexString(uint256(role), 32)\n )\n )\n );\n }\n }\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {\n return _roles[role].adminRole;\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _grantRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {\n _revokeRole(role, account);\n }\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been revoked `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) public virtual override {\n require(account == _msgSender(), \"AccessControl: can only renounce roles for self\");\n\n _revokeRole(role, account);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event. Note that unlike {grantRole}, this function doesn't perform any\n * checks on the calling account.\n *\n * [WARNING]\n * ====\n * This function should only be called from the constructor when setting\n * up the initial roles for the system.\n *\n * Using this function in any other way is effectively circumventing the admin\n * system imposed by {AccessControl}.\n * ====\n *\n * NOTE: This function is deprecated in favor of {_grantRole}.\n */\n function _setupRole(bytes32 role, address account) internal virtual {\n _grantRole(role, account);\n }\n\n /**\n * @dev Sets `adminRole` as ``role``'s admin role.\n *\n * Emits a {RoleAdminChanged} event.\n */\n function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {\n bytes32 previousAdminRole = getRoleAdmin(role);\n _roles[role].adminRole = adminRole;\n emit RoleAdminChanged(role, previousAdminRole, adminRole);\n }\n\n /**\n * @dev Grants `role` to `account`.\n *\n * Internal function without access restriction.\n */\n function _grantRole(bytes32 role, address account) internal virtual {\n if (!hasRole(role, account)) {\n _roles[role].members[account] = true;\n emit RoleGranted(role, account, _msgSender());\n }\n }\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * Internal function without access restriction.\n */\n function _revokeRole(bytes32 role, address account) internal virtual {\n if (hasRole(role, account)) {\n _roles[role].members[account] = false;\n emit RoleRevoked(role, account, _msgSender());\n }\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/access/AccessControlEnumerable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControlEnumerable.sol\";\nimport \"./AccessControl.sol\";\nimport \"../utils/structs/EnumerableSet.sol\";\n\n/**\n * @dev Extension of {AccessControl} that allows enumerating the members of each role.\n */\nabstract contract AccessControlEnumerable is IAccessControlEnumerable, AccessControl {\n using EnumerableSet for EnumerableSet.AddressSet;\n\n mapping(bytes32 => EnumerableSet.AddressSet) private _roleMembers;\n\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IAccessControlEnumerable).interfaceId || super.supportsInterface(interfaceId);\n }\n\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) {\n return _roleMembers[role].at(index);\n }\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) {\n return _roleMembers[role].length();\n }\n\n /**\n * @dev Overload {_grantRole} to track enumerable memberships\n */\n function _grantRole(bytes32 role, address account) internal virtual override {\n super._grantRole(role, account);\n _roleMembers[role].add(account);\n }\n\n /**\n * @dev Overload {_revokeRole} to track enumerable memberships\n */\n function _revokeRole(bytes32 role, address account) internal virtual override {\n super._revokeRole(role, account);\n _roleMembers[role].remove(account);\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/access/IAccessControl.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev External interface of AccessControl declared to support ERC165 detection.\n */\ninterface IAccessControl {\n /**\n * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`\n *\n * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite\n * {RoleAdminChanged} not being emitted signaling this.\n *\n * _Available since v3.1._\n */\n event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);\n\n /**\n * @dev Emitted when `account` is granted `role`.\n *\n * `sender` is the account that originated the contract call, an admin role\n * bearer except when using {AccessControl-_setupRole}.\n */\n event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Emitted when `account` is revoked `role`.\n *\n * `sender` is the account that originated the contract call:\n * - if using `revokeRole`, it is the admin role bearer\n * - if using `renounceRole`, it is the role bearer (i.e. `account`)\n */\n event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);\n\n /**\n * @dev Returns `true` if `account` has been granted `role`.\n */\n function hasRole(bytes32 role, address account) external view returns (bool);\n\n /**\n * @dev Returns the admin role that controls `role`. See {grantRole} and\n * {revokeRole}.\n *\n * To change a role's admin, use {AccessControl-_setRoleAdmin}.\n */\n function getRoleAdmin(bytes32 role) external view returns (bytes32);\n\n /**\n * @dev Grants `role` to `account`.\n *\n * If `account` had not been already granted `role`, emits a {RoleGranted}\n * event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function grantRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from `account`.\n *\n * If `account` had been granted `role`, emits a {RoleRevoked} event.\n *\n * Requirements:\n *\n * - the caller must have ``role``'s admin role.\n */\n function revokeRole(bytes32 role, address account) external;\n\n /**\n * @dev Revokes `role` from the calling account.\n *\n * Roles are often managed via {grantRole} and {revokeRole}: this function's\n * purpose is to provide a mechanism for accounts to lose their privileges\n * if they are compromised (such as when a trusted device is misplaced).\n *\n * If the calling account had been granted `role`, emits a {RoleRevoked}\n * event.\n *\n * Requirements:\n *\n * - the caller must be `account`.\n */\n function renounceRole(bytes32 role, address account) external;\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/access/IAccessControlEnumerable.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IAccessControl.sol\";\n\n/**\n * @dev External interface of AccessControlEnumerable declared to support ERC165 detection.\n */\ninterface IAccessControlEnumerable is IAccessControl {\n /**\n * @dev Returns one of the accounts that have `role`. `index` must be a\n * value between 0 and {getRoleMemberCount}, non-inclusive.\n *\n * Role bearers are not sorted in any particular way, and their ordering may\n * change at any point.\n *\n * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure\n * you perform all queries on the same block. See the following\n * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post]\n * for more information.\n */\n function getRoleMember(bytes32 role, uint256 index) external view returns (address);\n\n /**\n * @dev Returns the number of accounts that have `role`. Can be used\n * together with {getRoleMember} to enumerate all bearers of a role.\n */\n function getRoleMemberCount(bytes32 role) external view returns (uint256);\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/token/ERC20/IERC20.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC20 standard as defined in the EIP.\n */\ninterface IERC20 {\n /**\n * @dev Emitted when `value` tokens are moved from one account (`from`) to\n * another (`to`).\n *\n * Note that `value` may be zero.\n */\n event Transfer(address indexed from, address indexed to, uint256 value);\n\n /**\n * @dev Emitted when the allowance of a `spender` for an `owner` is set by\n * a call to {approve}. `value` is the new allowance.\n */\n event Approval(address indexed owner, address indexed spender, uint256 value);\n\n /**\n * @dev Returns the amount of tokens in existence.\n */\n function totalSupply() external view returns (uint256);\n\n /**\n * @dev Returns the amount of tokens owned by `account`.\n */\n function balanceOf(address account) external view returns (uint256);\n\n /**\n * @dev Moves `amount` tokens from the caller's account to `to`.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transfer(address to, uint256 amount) external returns (bool);\n\n /**\n * @dev Returns the remaining number of tokens that `spender` will be\n * allowed to spend on behalf of `owner` through {transferFrom}. This is\n * zero by default.\n *\n * This value changes when {approve} or {transferFrom} are called.\n */\n function allowance(address owner, address spender) external view returns (uint256);\n\n /**\n * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * IMPORTANT: Beware that changing an allowance with this method brings the risk\n * that someone may use both the old and the new allowance by unfortunate\n * transaction ordering. One possible solution to mitigate this race\n * condition is to first reduce the spender's allowance to 0 and set the\n * desired value afterwards:\n * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729\n *\n * Emits an {Approval} event.\n */\n function approve(address spender, uint256 amount) external returns (bool);\n\n /**\n * @dev Moves `amount` tokens from `from` to `to` using the\n * allowance mechanism. `amount` is then deducted from the caller's\n * allowance.\n *\n * Returns a boolean value indicating whether the operation succeeded.\n *\n * Emits a {Transfer} event.\n */\n function transferFrom(\n address from,\n address to,\n uint256 amount\n ) external returns (bool);\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)\n\npragma solidity ^0.8.0;\n\nimport \"../IERC20.sol\";\n\n/**\n * @dev Interface for the optional metadata functions from the ERC20 standard.\n *\n * _Available since v4.1._\n */\ninterface IERC20Metadata is IERC20 {\n /**\n * @dev Returns the name of the token.\n */\n function name() external view returns (string memory);\n\n /**\n * @dev Returns the symbol of the token.\n */\n function symbol() external view returns (string memory);\n\n /**\n * @dev Returns the decimals places of the token.\n */\n function decimals() external view returns (uint8);\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/Context.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Provides information about the current execution context, including the\n * sender of the transaction and its data. While these are generally available\n * via msg.sender and msg.data, they should not be accessed in such a direct\n * manner, since when dealing with meta-transactions the account sending and\n * paying for execution may not be the actual sender (as far as an application\n * is concerned).\n *\n * This contract is only required for intermediate, library-like contracts.\n */\nabstract contract Context {\n function _msgSender() internal view virtual returns (address) {\n return msg.sender;\n }\n\n function _msgData() internal view virtual returns (bytes calldata) {\n return msg.data;\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/Strings.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev String operations.\n */\nlibrary Strings {\n bytes16 private constant _HEX_SYMBOLS = \"0123456789abcdef\";\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` decimal representation.\n */\n function toString(uint256 value) internal pure returns (string memory) {\n // Inspired by OraclizeAPI's implementation - MIT licence\n // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol\n\n if (value == 0) {\n return \"0\";\n }\n uint256 temp = value;\n uint256 digits;\n while (temp != 0) {\n digits++;\n temp /= 10;\n }\n bytes memory buffer = new bytes(digits);\n while (value != 0) {\n digits -= 1;\n buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));\n value /= 10;\n }\n return string(buffer);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.\n */\n function toHexString(uint256 value) internal pure returns (string memory) {\n if (value == 0) {\n return \"0x00\";\n }\n uint256 temp = value;\n uint256 length = 0;\n while (temp != 0) {\n length++;\n temp >>= 8;\n }\n return toHexString(value, length);\n }\n\n /**\n * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.\n */\n function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {\n bytes memory buffer = new bytes(2 * length + 2);\n buffer[0] = \"0\";\n buffer[1] = \"x\";\n for (uint256 i = 2 * length + 1; i > 1; --i) {\n buffer[i] = _HEX_SYMBOLS[value & 0xf];\n value >>= 4;\n }\n require(value == 0, \"Strings: hex length insufficient\");\n return string(buffer);\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/introspection/ERC165.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)\n\npragma solidity ^0.8.0;\n\nimport \"./IERC165.sol\";\n\n/**\n * @dev Implementation of the {IERC165} interface.\n *\n * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check\n * for the additional interface id that will be supported. For example:\n *\n * ```solidity\n * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);\n * }\n * ```\n *\n * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.\n */\nabstract contract ERC165 is IERC165 {\n /**\n * @dev See {IERC165-supportsInterface}.\n */\n function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {\n return interfaceId == type(IERC165).interfaceId;\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/introspection/IERC165.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Interface of the ERC165 standard, as defined in the\n * https://eips.ethereum.org/EIPS/eip-165[EIP].\n *\n * Implementers can declare support of contract interfaces, which can then be\n * queried by others ({ERC165Checker}).\n *\n * For an implementation, see {ERC165}.\n */\ninterface IERC165 {\n /**\n * @dev Returns true if this contract implements the interface defined by\n * `interfaceId`. See the corresponding\n * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]\n * to learn more about how these ids are created.\n *\n * This function call must use less than 30 000 gas.\n */\n function supportsInterface(bytes4 interfaceId) external view returns (bool);\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/math/SafeCast.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow\n * checks.\n *\n * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can\n * easily result in undesired exploitation or bugs, since developers usually\n * assume that overflows raise errors. `SafeCast` restores this intuition by\n * reverting the transaction when such an operation overflows.\n *\n * Using this library instead of the unchecked operations eliminates an entire\n * class of bugs, so it's recommended to use it always.\n *\n * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing\n * all math on `uint256` and `int256` and then downcasting.\n */\nlibrary SafeCast {\n /**\n * @dev Returns the downcasted uint224 from uint256, reverting on\n * overflow (when the input is greater than largest uint224).\n *\n * Counterpart to Solidity's `uint224` operator.\n *\n * Requirements:\n *\n * - input must fit into 224 bits\n */\n function toUint224(uint256 value) internal pure returns (uint224) {\n require(value <= type(uint224).max, \"SafeCast: value doesn't fit in 224 bits\");\n return uint224(value);\n }\n\n /**\n * @dev Returns the downcasted uint128 from uint256, reverting on\n * overflow (when the input is greater than largest uint128).\n *\n * Counterpart to Solidity's `uint128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n */\n function toUint128(uint256 value) internal pure returns (uint128) {\n require(value <= type(uint128).max, \"SafeCast: value doesn't fit in 128 bits\");\n return uint128(value);\n }\n\n /**\n * @dev Returns the downcasted uint96 from uint256, reverting on\n * overflow (when the input is greater than largest uint96).\n *\n * Counterpart to Solidity's `uint96` operator.\n *\n * Requirements:\n *\n * - input must fit into 96 bits\n */\n function toUint96(uint256 value) internal pure returns (uint96) {\n require(value <= type(uint96).max, \"SafeCast: value doesn't fit in 96 bits\");\n return uint96(value);\n }\n\n /**\n * @dev Returns the downcasted uint64 from uint256, reverting on\n * overflow (when the input is greater than largest uint64).\n *\n * Counterpart to Solidity's `uint64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n */\n function toUint64(uint256 value) internal pure returns (uint64) {\n require(value <= type(uint64).max, \"SafeCast: value doesn't fit in 64 bits\");\n return uint64(value);\n }\n\n /**\n * @dev Returns the downcasted uint32 from uint256, reverting on\n * overflow (when the input is greater than largest uint32).\n *\n * Counterpart to Solidity's `uint32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n */\n function toUint32(uint256 value) internal pure returns (uint32) {\n require(value <= type(uint32).max, \"SafeCast: value doesn't fit in 32 bits\");\n return uint32(value);\n }\n\n /**\n * @dev Returns the downcasted uint16 from uint256, reverting on\n * overflow (when the input is greater than largest uint16).\n *\n * Counterpart to Solidity's `uint16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n */\n function toUint16(uint256 value) internal pure returns (uint16) {\n require(value <= type(uint16).max, \"SafeCast: value doesn't fit in 16 bits\");\n return uint16(value);\n }\n\n /**\n * @dev Returns the downcasted uint8 from uint256, reverting on\n * overflow (when the input is greater than largest uint8).\n *\n * Counterpart to Solidity's `uint8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits.\n */\n function toUint8(uint256 value) internal pure returns (uint8) {\n require(value <= type(uint8).max, \"SafeCast: value doesn't fit in 8 bits\");\n return uint8(value);\n }\n\n /**\n * @dev Converts a signed int256 into an unsigned uint256.\n *\n * Requirements:\n *\n * - input must be greater than or equal to 0.\n */\n function toUint256(int256 value) internal pure returns (uint256) {\n require(value >= 0, \"SafeCast: value must be positive\");\n return uint256(value);\n }\n\n /**\n * @dev Returns the downcasted int128 from int256, reverting on\n * overflow (when the input is less than smallest int128 or\n * greater than largest int128).\n *\n * Counterpart to Solidity's `int128` operator.\n *\n * Requirements:\n *\n * - input must fit into 128 bits\n *\n * _Available since v3.1._\n */\n function toInt128(int256 value) internal pure returns (int128) {\n require(value >= type(int128).min && value <= type(int128).max, \"SafeCast: value doesn't fit in 128 bits\");\n return int128(value);\n }\n\n /**\n * @dev Returns the downcasted int64 from int256, reverting on\n * overflow (when the input is less than smallest int64 or\n * greater than largest int64).\n *\n * Counterpart to Solidity's `int64` operator.\n *\n * Requirements:\n *\n * - input must fit into 64 bits\n *\n * _Available since v3.1._\n */\n function toInt64(int256 value) internal pure returns (int64) {\n require(value >= type(int64).min && value <= type(int64).max, \"SafeCast: value doesn't fit in 64 bits\");\n return int64(value);\n }\n\n /**\n * @dev Returns the downcasted int32 from int256, reverting on\n * overflow (when the input is less than smallest int32 or\n * greater than largest int32).\n *\n * Counterpart to Solidity's `int32` operator.\n *\n * Requirements:\n *\n * - input must fit into 32 bits\n *\n * _Available since v3.1._\n */\n function toInt32(int256 value) internal pure returns (int32) {\n require(value >= type(int32).min && value <= type(int32).max, \"SafeCast: value doesn't fit in 32 bits\");\n return int32(value);\n }\n\n /**\n * @dev Returns the downcasted int16 from int256, reverting on\n * overflow (when the input is less than smallest int16 or\n * greater than largest int16).\n *\n * Counterpart to Solidity's `int16` operator.\n *\n * Requirements:\n *\n * - input must fit into 16 bits\n *\n * _Available since v3.1._\n */\n function toInt16(int256 value) internal pure returns (int16) {\n require(value >= type(int16).min && value <= type(int16).max, \"SafeCast: value doesn't fit in 16 bits\");\n return int16(value);\n }\n\n /**\n * @dev Returns the downcasted int8 from int256, reverting on\n * overflow (when the input is less than smallest int8 or\n * greater than largest int8).\n *\n * Counterpart to Solidity's `int8` operator.\n *\n * Requirements:\n *\n * - input must fit into 8 bits.\n *\n * _Available since v3.1._\n */\n function toInt8(int256 value) internal pure returns (int8) {\n require(value >= type(int8).min && value <= type(int8).max, \"SafeCast: value doesn't fit in 8 bits\");\n return int8(value);\n }\n\n /**\n * @dev Converts an unsigned uint256 into a signed int256.\n *\n * Requirements:\n *\n * - input must be less than or equal to maxInt256.\n */\n function toInt256(uint256 value) internal pure returns (int256) {\n // Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive\n require(value <= uint256(type(int256).max), \"SafeCast: value doesn't fit in an int256\");\n return int256(value);\n }\n}\n"
|
|
},
|
|
"@openzeppelin-v4/contracts/utils/structs/EnumerableSet.sol": {
|
|
"content": "// SPDX-License-Identifier: MIT\n// OpenZeppelin Contracts (last updated v4.6.0) (utils/structs/EnumerableSet.sol)\n\npragma solidity ^0.8.0;\n\n/**\n * @dev Library for managing\n * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive\n * types.\n *\n * Sets have the following properties:\n *\n * - Elements are added, removed, and checked for existence in constant time\n * (O(1)).\n * - Elements are enumerated in O(n). No guarantees are made on the ordering.\n *\n * ```\n * contract Example {\n * // Add the library methods\n * using EnumerableSet for EnumerableSet.AddressSet;\n *\n * // Declare a set state variable\n * EnumerableSet.AddressSet private mySet;\n * }\n * ```\n *\n * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)\n * and `uint256` (`UintSet`) are supported.\n */\nlibrary EnumerableSet {\n // To implement this library for multiple types with as little code\n // repetition as possible, we write it in terms of a generic Set type with\n // bytes32 values.\n // The Set implementation uses private functions, and user-facing\n // implementations (such as AddressSet) are just wrappers around the\n // underlying Set.\n // This means that we can only create new EnumerableSets for types that fit\n // in bytes32.\n\n struct Set {\n // Storage of set values\n bytes32[] _values;\n // Position of the value in the `values` array, plus 1 because index 0\n // means a value is not in the set.\n mapping(bytes32 => uint256) _indexes;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function _add(Set storage set, bytes32 value) private returns (bool) {\n if (!_contains(set, value)) {\n set._values.push(value);\n // The value is stored at length-1, but we add 1 to all indexes\n // and use 0 as a sentinel value\n set._indexes[value] = set._values.length;\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function _remove(Set storage set, bytes32 value) private returns (bool) {\n // We read and store the value's index to prevent multiple reads from the same storage slot\n uint256 valueIndex = set._indexes[value];\n\n if (valueIndex != 0) {\n // Equivalent to contains(set, value)\n // To delete an element from the _values array in O(1), we swap the element to delete with the last one in\n // the array, and then remove the last element (sometimes called as 'swap and pop').\n // This modifies the order of the array, as noted in {at}.\n\n uint256 toDeleteIndex = valueIndex - 1;\n uint256 lastIndex = set._values.length - 1;\n\n if (lastIndex != toDeleteIndex) {\n bytes32 lastValue = set._values[lastIndex];\n\n // Move the last value to the index where the value to delete is\n set._values[toDeleteIndex] = lastValue;\n // Update the index for the moved value\n set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex\n }\n\n // Delete the slot where the moved value was stored\n set._values.pop();\n\n // Delete the index for the deleted slot\n delete set._indexes[value];\n\n return true;\n } else {\n return false;\n }\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function _contains(Set storage set, bytes32 value) private view returns (bool) {\n return set._indexes[value] != 0;\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function _length(Set storage set) private view returns (uint256) {\n return set._values.length;\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function _at(Set storage set, uint256 index) private view returns (bytes32) {\n return set._values[index];\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function _values(Set storage set) private view returns (bytes32[] memory) {\n return set._values;\n }\n\n // Bytes32Set\n\n struct Bytes32Set {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _add(set._inner, value);\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {\n return _remove(set._inner, value);\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {\n return _contains(set._inner, value);\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(Bytes32Set storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {\n return _at(set._inner, index);\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {\n return _values(set._inner);\n }\n\n // AddressSet\n\n struct AddressSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(AddressSet storage set, address value) internal returns (bool) {\n return _add(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(AddressSet storage set, address value) internal returns (bool) {\n return _remove(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(AddressSet storage set, address value) internal view returns (bool) {\n return _contains(set._inner, bytes32(uint256(uint160(value))));\n }\n\n /**\n * @dev Returns the number of values in the set. O(1).\n */\n function length(AddressSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(AddressSet storage set, uint256 index) internal view returns (address) {\n return address(uint160(uint256(_at(set._inner, index))));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(AddressSet storage set) internal view returns (address[] memory) {\n bytes32[] memory store = _values(set._inner);\n address[] memory result;\n\n assembly {\n result := store\n }\n\n return result;\n }\n\n // UintSet\n\n struct UintSet {\n Set _inner;\n }\n\n /**\n * @dev Add a value to a set. O(1).\n *\n * Returns true if the value was added to the set, that is if it was not\n * already present.\n */\n function add(UintSet storage set, uint256 value) internal returns (bool) {\n return _add(set._inner, bytes32(value));\n }\n\n /**\n * @dev Removes a value from a set. O(1).\n *\n * Returns true if the value was removed from the set, that is if it was\n * present.\n */\n function remove(UintSet storage set, uint256 value) internal returns (bool) {\n return _remove(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns true if the value is in the set. O(1).\n */\n function contains(UintSet storage set, uint256 value) internal view returns (bool) {\n return _contains(set._inner, bytes32(value));\n }\n\n /**\n * @dev Returns the number of values on the set. O(1).\n */\n function length(UintSet storage set) internal view returns (uint256) {\n return _length(set._inner);\n }\n\n /**\n * @dev Returns the value stored at position `index` in the set. O(1).\n *\n * Note that there are no guarantees on the ordering of values inside the\n * array, and it may change when more values are added or removed.\n *\n * Requirements:\n *\n * - `index` must be strictly less than {length}.\n */\n function at(UintSet storage set, uint256 index) internal view returns (uint256) {\n return uint256(_at(set._inner, index));\n }\n\n /**\n * @dev Return the entire set in an array\n *\n * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed\n * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that\n * this function has an unbounded cost, and using it as part of a state-changing function may render the function\n * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.\n */\n function values(UintSet storage set) internal view returns (uint256[] memory) {\n bytes32[] memory store = _values(set._inner);\n uint256[] memory result;\n\n assembly {\n result := store\n }\n\n return result;\n }\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title The interface for the Uniswap V3 Factory\n/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees\ninterface IUniswapV3Factory {\n /// @notice Emitted when the owner of the factory is changed\n /// @param oldOwner The owner before the owner was changed\n /// @param newOwner The owner after the owner was changed\n event OwnerChanged(address indexed oldOwner, address indexed newOwner);\n\n /// @notice Emitted when a pool is created\n /// @param token0 The first token of the pool by address sort order\n /// @param token1 The second token of the pool by address sort order\n /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n /// @param tickSpacing The minimum number of ticks between initialized ticks\n /// @param pool The address of the created pool\n event PoolCreated(\n address indexed token0,\n address indexed token1,\n uint24 indexed fee,\n int24 tickSpacing,\n address pool\n );\n\n /// @notice Emitted when a new fee amount is enabled for pool creation via the factory\n /// @param fee The enabled fee, denominated in hundredths of a bip\n /// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee\n event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);\n\n /// @notice Returns the current owner of the factory\n /// @dev Can be changed by the current owner via setOwner\n /// @return The address of the factory owner\n function owner() external view returns (address);\n\n /// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled\n /// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context\n /// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee\n /// @return The tick spacing\n function feeAmountTickSpacing(uint24 fee) external view returns (int24);\n\n /// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist\n /// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order\n /// @param tokenA The contract address of either token0 or token1\n /// @param tokenB The contract address of the other token\n /// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip\n /// @return pool The pool address\n function getPool(\n address tokenA,\n address tokenB,\n uint24 fee\n ) external view returns (address pool);\n\n /// @notice Creates a pool for the given two tokens and fee\n /// @param tokenA One of the two tokens in the desired pool\n /// @param tokenB The other of the two tokens in the desired pool\n /// @param fee The desired fee for the pool\n /// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved\n /// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments\n /// are invalid.\n /// @return pool The address of the newly created pool\n function createPool(\n address tokenA,\n address tokenB,\n uint24 fee\n ) external returns (address pool);\n\n /// @notice Updates the owner of the factory\n /// @dev Must be called by the current owner\n /// @param _owner The new owner of the factory\n function setOwner(address _owner) external;\n\n /// @notice Enables a fee amount with the given tickSpacing\n /// @dev Fee amounts may never be removed once enabled\n /// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)\n /// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount\n function enableFeeAmount(uint24 fee, int24 tickSpacing) external;\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\nimport './pool/IUniswapV3PoolImmutables.sol';\nimport './pool/IUniswapV3PoolState.sol';\nimport './pool/IUniswapV3PoolDerivedState.sol';\nimport './pool/IUniswapV3PoolActions.sol';\nimport './pool/IUniswapV3PoolOwnerActions.sol';\nimport './pool/IUniswapV3PoolEvents.sol';\n\n/// @title The interface for a Uniswap V3 Pool\n/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform\n/// to the ERC20 specification\n/// @dev The pool interface is broken up into many smaller pieces\ninterface IUniswapV3Pool is\n IUniswapV3PoolImmutables,\n IUniswapV3PoolState,\n IUniswapV3PoolDerivedState,\n IUniswapV3PoolActions,\n IUniswapV3PoolOwnerActions,\n IUniswapV3PoolEvents\n{\n\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissionless pool actions\n/// @notice Contains pool methods that can be called by anyone\ninterface IUniswapV3PoolActions {\n /// @notice Sets the initial price for the pool\n /// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value\n /// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96\n function initialize(uint160 sqrtPriceX96) external;\n\n /// @notice Adds liquidity for the given recipient/tickLower/tickUpper position\n /// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback\n /// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends\n /// on tickLower, tickUpper, the amount of liquidity, and the current price.\n /// @param recipient The address for which the liquidity will be created\n /// @param tickLower The lower tick of the position in which to add liquidity\n /// @param tickUpper The upper tick of the position in which to add liquidity\n /// @param amount The amount of liquidity to mint\n /// @param data Any data that should be passed through to the callback\n /// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback\n /// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback\n function mint(\n address recipient,\n int24 tickLower,\n int24 tickUpper,\n uint128 amount,\n bytes calldata data\n ) external returns (uint256 amount0, uint256 amount1);\n\n /// @notice Collects tokens owed to a position\n /// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.\n /// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or\n /// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the\n /// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.\n /// @param recipient The address which should receive the fees collected\n /// @param tickLower The lower tick of the position for which to collect fees\n /// @param tickUpper The upper tick of the position for which to collect fees\n /// @param amount0Requested How much token0 should be withdrawn from the fees owed\n /// @param amount1Requested How much token1 should be withdrawn from the fees owed\n /// @return amount0 The amount of fees collected in token0\n /// @return amount1 The amount of fees collected in token1\n function collect(\n address recipient,\n int24 tickLower,\n int24 tickUpper,\n uint128 amount0Requested,\n uint128 amount1Requested\n ) external returns (uint128 amount0, uint128 amount1);\n\n /// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position\n /// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0\n /// @dev Fees must be collected separately via a call to #collect\n /// @param tickLower The lower tick of the position for which to burn liquidity\n /// @param tickUpper The upper tick of the position for which to burn liquidity\n /// @param amount How much liquidity to burn\n /// @return amount0 The amount of token0 sent to the recipient\n /// @return amount1 The amount of token1 sent to the recipient\n function burn(\n int24 tickLower,\n int24 tickUpper,\n uint128 amount\n ) external returns (uint256 amount0, uint256 amount1);\n\n /// @notice Swap token0 for token1, or token1 for token0\n /// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback\n /// @param recipient The address to receive the output of the swap\n /// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0\n /// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)\n /// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this\n /// value after the swap. If one for zero, the price cannot be greater than this value after the swap\n /// @param data Any data to be passed through to the callback\n /// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive\n /// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive\n function swap(\n address recipient,\n bool zeroForOne,\n int256 amountSpecified,\n uint160 sqrtPriceLimitX96,\n bytes calldata data\n ) external returns (int256 amount0, int256 amount1);\n\n /// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback\n /// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback\n /// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling\n /// with 0 amount{0,1} and sending the donation amount(s) from the callback\n /// @param recipient The address which will receive the token0 and token1 amounts\n /// @param amount0 The amount of token0 to send\n /// @param amount1 The amount of token1 to send\n /// @param data Any data to be passed through to the callback\n function flash(\n address recipient,\n uint256 amount0,\n uint256 amount1,\n bytes calldata data\n ) external;\n\n /// @notice Increase the maximum number of price and liquidity observations that this pool will store\n /// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to\n /// the input observationCardinalityNext.\n /// @param observationCardinalityNext The desired minimum number of observations for the pool to store\n function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that is not stored\n/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the\n/// blockchain. The functions here may have variable gas costs.\ninterface IUniswapV3PoolDerivedState {\n /// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp\n /// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing\n /// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,\n /// you must call it with secondsAgos = [3600, 0].\n /// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in\n /// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.\n /// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned\n /// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp\n /// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block\n /// timestamp\n function observe(uint32[] calldata secondsAgos)\n external\n view\n returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);\n\n /// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range\n /// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.\n /// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first\n /// snapshot is taken and the second snapshot is taken.\n /// @param tickLower The lower tick of the range\n /// @param tickUpper The upper tick of the range\n /// @return tickCumulativeInside The snapshot of the tick accumulator for the range\n /// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range\n /// @return secondsInside The snapshot of seconds per liquidity for the range\n function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)\n external\n view\n returns (\n int56 tickCumulativeInside,\n uint160 secondsPerLiquidityInsideX128,\n uint32 secondsInside\n );\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Events emitted by a pool\n/// @notice Contains all events emitted by the pool\ninterface IUniswapV3PoolEvents {\n /// @notice Emitted exactly once by a pool when #initialize is first called on the pool\n /// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize\n /// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96\n /// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool\n event Initialize(uint160 sqrtPriceX96, int24 tick);\n\n /// @notice Emitted when liquidity is minted for a given position\n /// @param sender The address that minted the liquidity\n /// @param owner The owner of the position and recipient of any minted liquidity\n /// @param tickLower The lower tick of the position\n /// @param tickUpper The upper tick of the position\n /// @param amount The amount of liquidity minted to the position range\n /// @param amount0 How much token0 was required for the minted liquidity\n /// @param amount1 How much token1 was required for the minted liquidity\n event Mint(\n address sender,\n address indexed owner,\n int24 indexed tickLower,\n int24 indexed tickUpper,\n uint128 amount,\n uint256 amount0,\n uint256 amount1\n );\n\n /// @notice Emitted when fees are collected by the owner of a position\n /// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees\n /// @param owner The owner of the position for which fees are collected\n /// @param tickLower The lower tick of the position\n /// @param tickUpper The upper tick of the position\n /// @param amount0 The amount of token0 fees collected\n /// @param amount1 The amount of token1 fees collected\n event Collect(\n address indexed owner,\n address recipient,\n int24 indexed tickLower,\n int24 indexed tickUpper,\n uint128 amount0,\n uint128 amount1\n );\n\n /// @notice Emitted when a position's liquidity is removed\n /// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect\n /// @param owner The owner of the position for which liquidity is removed\n /// @param tickLower The lower tick of the position\n /// @param tickUpper The upper tick of the position\n /// @param amount The amount of liquidity to remove\n /// @param amount0 The amount of token0 withdrawn\n /// @param amount1 The amount of token1 withdrawn\n event Burn(\n address indexed owner,\n int24 indexed tickLower,\n int24 indexed tickUpper,\n uint128 amount,\n uint256 amount0,\n uint256 amount1\n );\n\n /// @notice Emitted by the pool for any swaps between token0 and token1\n /// @param sender The address that initiated the swap call, and that received the callback\n /// @param recipient The address that received the output of the swap\n /// @param amount0 The delta of the token0 balance of the pool\n /// @param amount1 The delta of the token1 balance of the pool\n /// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96\n /// @param liquidity The liquidity of the pool after the swap\n /// @param tick The log base 1.0001 of price of the pool after the swap\n event Swap(\n address indexed sender,\n address indexed recipient,\n int256 amount0,\n int256 amount1,\n uint160 sqrtPriceX96,\n uint128 liquidity,\n int24 tick\n );\n\n /// @notice Emitted by the pool for any flashes of token0/token1\n /// @param sender The address that initiated the swap call, and that received the callback\n /// @param recipient The address that received the tokens from flash\n /// @param amount0 The amount of token0 that was flashed\n /// @param amount1 The amount of token1 that was flashed\n /// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee\n /// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee\n event Flash(\n address indexed sender,\n address indexed recipient,\n uint256 amount0,\n uint256 amount1,\n uint256 paid0,\n uint256 paid1\n );\n\n /// @notice Emitted by the pool for increases to the number of observations that can be stored\n /// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index\n /// just before a mint/swap/burn.\n /// @param observationCardinalityNextOld The previous value of the next observation cardinality\n /// @param observationCardinalityNextNew The updated value of the next observation cardinality\n event IncreaseObservationCardinalityNext(\n uint16 observationCardinalityNextOld,\n uint16 observationCardinalityNextNew\n );\n\n /// @notice Emitted when the protocol fee is changed by the pool\n /// @param feeProtocol0Old The previous value of the token0 protocol fee\n /// @param feeProtocol1Old The previous value of the token1 protocol fee\n /// @param feeProtocol0New The updated value of the token0 protocol fee\n /// @param feeProtocol1New The updated value of the token1 protocol fee\n event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);\n\n /// @notice Emitted when the collected protocol fees are withdrawn by the factory owner\n /// @param sender The address that collects the protocol fees\n /// @param recipient The address that receives the collected protocol fees\n /// @param amount0 The amount of token0 protocol fees that is withdrawn\n /// @param amount0 The amount of token1 protocol fees that is withdrawn\n event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that never changes\n/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values\ninterface IUniswapV3PoolImmutables {\n /// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface\n /// @return The contract address\n function factory() external view returns (address);\n\n /// @notice The first of the two tokens of the pool, sorted by address\n /// @return The token contract address\n function token0() external view returns (address);\n\n /// @notice The second of the two tokens of the pool, sorted by address\n /// @return The token contract address\n function token1() external view returns (address);\n\n /// @notice The pool's fee in hundredths of a bip, i.e. 1e-6\n /// @return The fee\n function fee() external view returns (uint24);\n\n /// @notice The pool tick spacing\n /// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive\n /// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...\n /// This value is an int24 to avoid casting even though it is always positive.\n /// @return The tick spacing\n function tickSpacing() external view returns (int24);\n\n /// @notice The maximum amount of position liquidity that can use any tick in the range\n /// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and\n /// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool\n /// @return The max amount of liquidity per tick\n function maxLiquidityPerTick() external view returns (uint128);\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Permissioned pool actions\n/// @notice Contains pool methods that may only be called by the factory owner\ninterface IUniswapV3PoolOwnerActions {\n /// @notice Set the denominator of the protocol's % share of the fees\n /// @param feeProtocol0 new protocol fee for token0 of the pool\n /// @param feeProtocol1 new protocol fee for token1 of the pool\n function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;\n\n /// @notice Collect the protocol fee accrued to the pool\n /// @param recipient The address to which collected protocol fees should be sent\n /// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1\n /// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0\n /// @return amount0 The protocol fee collected in token0\n /// @return amount1 The protocol fee collected in token1\n function collectProtocol(\n address recipient,\n uint128 amount0Requested,\n uint128 amount1Requested\n ) external returns (uint128 amount0, uint128 amount1);\n}\n"
|
|
},
|
|
"@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol": {
|
|
"content": "// SPDX-License-Identifier: GPL-2.0-or-later\npragma solidity >=0.5.0;\n\n/// @title Pool state that can change\n/// @notice These methods compose the pool's state, and can change with any frequency including multiple times\n/// per transaction\ninterface IUniswapV3PoolState {\n /// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas\n /// when accessed externally.\n /// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value\n /// tick The current tick of the pool, i.e. according to the last tick transition that was run.\n /// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick\n /// boundary.\n /// observationIndex The index of the last oracle observation that was written,\n /// observationCardinality The current maximum number of observations stored in the pool,\n /// observationCardinalityNext The next maximum number of observations, to be updated when the observation.\n /// feeProtocol The protocol fee for both tokens of the pool.\n /// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0\n /// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.\n /// unlocked Whether the pool is currently locked to reentrancy\n function slot0()\n external\n view\n returns (\n uint160 sqrtPriceX96,\n int24 tick,\n uint16 observationIndex,\n uint16 observationCardinality,\n uint16 observationCardinalityNext,\n uint8 feeProtocol,\n bool unlocked\n );\n\n /// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool\n /// @dev This value can overflow the uint256\n function feeGrowthGlobal0X128() external view returns (uint256);\n\n /// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool\n /// @dev This value can overflow the uint256\n function feeGrowthGlobal1X128() external view returns (uint256);\n\n /// @notice The amounts of token0 and token1 that are owed to the protocol\n /// @dev Protocol fees will never exceed uint128 max in either token\n function protocolFees() external view returns (uint128 token0, uint128 token1);\n\n /// @notice The currently in range liquidity available to the pool\n /// @dev This value has no relationship to the total liquidity across all ticks\n function liquidity() external view returns (uint128);\n\n /// @notice Look up information about a specific tick in the pool\n /// @param tick The tick to look up\n /// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or\n /// tick upper,\n /// liquidityNet how much liquidity changes when the pool price crosses the tick,\n /// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,\n /// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,\n /// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick\n /// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,\n /// secondsOutside the seconds spent on the other side of the tick from the current tick,\n /// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.\n /// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.\n /// In addition, these values are only relative and must be used only in comparison to previous snapshots for\n /// a specific position.\n function ticks(int24 tick)\n external\n view\n returns (\n uint128 liquidityGross,\n int128 liquidityNet,\n uint256 feeGrowthOutside0X128,\n uint256 feeGrowthOutside1X128,\n int56 tickCumulativeOutside,\n uint160 secondsPerLiquidityOutsideX128,\n uint32 secondsOutside,\n bool initialized\n );\n\n /// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information\n function tickBitmap(int16 wordPosition) external view returns (uint256);\n\n /// @notice Returns the information about a position by the position's key\n /// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper\n /// @return _liquidity The amount of liquidity in the position,\n /// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,\n /// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,\n /// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,\n /// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke\n function positions(bytes32 key)\n external\n view\n returns (\n uint128 _liquidity,\n uint256 feeGrowthInside0LastX128,\n uint256 feeGrowthInside1LastX128,\n uint128 tokensOwed0,\n uint128 tokensOwed1\n );\n\n /// @notice Returns data about a specific observation index\n /// @param index The element of the observations array to fetch\n /// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time\n /// ago, rather than at a specific index in the array.\n /// @return blockTimestamp The timestamp of the observation,\n /// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,\n /// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,\n /// Returns initialized whether the observation has been initialized and the values are safe to use\n function observations(uint256 index)\n external\n view\n returns (\n uint32 blockTimestamp,\n int56 tickCumulative,\n uint160 secondsPerLiquidityCumulativeX128,\n bool initialized\n );\n}\n"
|
|
},
|
|
"contracts/AdrastiaVersioning.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\ncontract AdrastiaVersioning {\n string public constant ADRASTIA_CORE_VERSION = \"v1.0.0\";\n string public constant ADRASTIA_PERIPHERY_VERSION = \"v1.0.0\";\n string public constant ADRASTIA_PROTOCOL_VERSION = \"v0.0.8\";\n}\n"
|
|
},
|
|
"contracts/accumulators/UniswapV3PA.sol": {
|
|
"content": "//SPDX-License-Identifier: MIT\npragma solidity =0.8.13;\n\nimport \"@adrastia-oracle/adrastia-periphery/contracts/accumulators/proto/uniswap/ManagedUniswapV3PriceAccumulator.sol\";\n\nimport \"../AdrastiaVersioning.sol\";\n\ncontract AdrastiaUniswapV3PA is AdrastiaVersioning, ManagedUniswapV3PriceAccumulator {\n string public name;\n\n constructor(\n string memory name_,\n address uniswapFactory_,\n bytes32 initCodeHash_,\n uint24[] memory poolFees_,\n address quoteToken_,\n uint256 updateTheshold_,\n uint256 minUpdateDelay_,\n uint256 maxUpdateDelay_\n )\n ManagedUniswapV3PriceAccumulator(\n uniswapFactory_,\n initCodeHash_,\n poolFees_,\n quoteToken_,\n updateTheshold_,\n minUpdateDelay_,\n maxUpdateDelay_\n )\n {\n name = name_;\n }\n}\n"
|
|
}
|
|
}
|
|
} |