From 46f1c9db796f60a795d24fb2fa92a8bc84fa4a40 Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Fri, 23 Jun 2023 09:50:55 +1000 Subject: [PATCH 1/3] removed unused StableMath from UniswapV3Strategy --- contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol | 2 -- 1 file changed, 2 deletions(-) diff --git a/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol b/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol index 070c277273..8a8ed55e2e 100644 --- a/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol +++ b/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol @@ -16,11 +16,9 @@ import { IUniswapV3Helper } from "../../interfaces/uniswap/v3/IUniswapV3Helper.s import { IUniswapV3Pool } from "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol"; import { IUniswapV3Strategy } from "../../interfaces/IUniswapV3Strategy.sol"; import { ISwapRouter } from "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol"; -import { StableMath } from "../../utils/StableMath.sol"; contract UniswapV3Strategy is UniswapV3StrategyStorage { using SafeERC20 for IERC20; - using StableMath for uint256; /** * @dev Initialize the contract From 59da960dbb65e84a27f00bf3c1aaa83b28811320 Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Fri, 23 Jun 2023 10:09:03 +1000 Subject: [PATCH 2/3] Updated Uniswap V3 Natspec --- .../strategies/uniswap/UniswapV3Strategy.sol | 8 +-- .../uniswap/UniswapV3StrategyStorage.sol | 55 +++++++++++-------- .../utils/InitializableAbstractStrategy.sol | 26 ++++----- 3 files changed, 49 insertions(+), 40 deletions(-) diff --git a/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol b/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol index 8a8ed55e2e..21f1230ef3 100644 --- a/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol +++ b/contracts/contracts/strategies/uniswap/UniswapV3Strategy.sol @@ -363,7 +363,7 @@ contract UniswapV3Strategy is UniswapV3StrategyStorage { } /** - * @dev Only checks the active LP position and undeployed/undeposited balance held by the contract. + * @notice Only checks the active LP position and undeployed/undeposited balance held by the contract. * Doesn't return the balance held in the reserve strategies. * @inheritdoc InitializableAbstractStrategy */ @@ -401,7 +401,7 @@ contract UniswapV3Strategy is UniswapV3StrategyStorage { ERC721 management ****************************************/ - /// Callback function for whenever a NFT is transferred to this contract + /// @notice Callback function for whenever a NFT is transferred to this contract // solhint-disable-next-line max-line-length /// Ref: https://docs.openzeppelin.com/contracts/3.x/api/token/erc721#IERC721Receiver-onERC721Received-address-address-uint256-bytes- function onERC721Received( @@ -433,7 +433,7 @@ contract UniswapV3Strategy is UniswapV3StrategyStorage { } /** - * Removes all allowance of both the tokens from NonfungiblePositionManager as + * @notice Removes all allowance of both the tokens from NonfungiblePositionManager as * well as from the Uniswap V3 Swap Router */ function resetAllowanceOfTokens() external onlyGovernor nonReentrant { @@ -484,7 +484,7 @@ contract UniswapV3Strategy is UniswapV3StrategyStorage { Proxy to liquidity management ****************************************/ /** - * @dev Sets the implementation for the liquidity manager + * @notice Sets the implementation for the liquidity manager * @param newImpl address of the implementation */ function setLiquidityManagerImpl(address newImpl) external onlyGovernor { diff --git a/contracts/contracts/strategies/uniswap/UniswapV3StrategyStorage.sol b/contracts/contracts/strategies/uniswap/UniswapV3StrategyStorage.sol index 2b9d41a021..aef4f194e7 100644 --- a/contracts/contracts/strategies/uniswap/UniswapV3StrategyStorage.sol +++ b/contracts/contracts/strategies/uniswap/UniswapV3StrategyStorage.sol @@ -91,24 +91,33 @@ abstract contract UniswapV3StrategyStorage is InitializableAbstractStrategy { uint256 netValue; // Last recorded net value of the position } - // Set to the proxy address when initialized + /// @notice The strategy's proxy contract address + /// @dev is set when initialized IUniswapV3Strategy public _self; - // The address that can manage the positions on Uniswap V3 + /// @notice The address that can manage the positions on Uniswap V3 address public operatorAddr; - address public token0; // Token0 of Uniswap V3 Pool - address public token1; // Token1 of Uniswap V3 Pool + /// @notice Token0 of Uniswap V3 Pool + address public token0; + /// @notice Token1 of Uniswap V3 Pool + address public token1; // When the funds are not deployed in Uniswap V3 Pool, they will // be deposited to these reserve strategies - IStrategy public reserveStrategy0; // Reserve strategy for token0 - IStrategy public reserveStrategy1; // Reserve strategy for token1 + /// @notice Reserve strategy for token0 + IStrategy public reserveStrategy0; + /// @notice Reserve strategy for token1 + IStrategy public reserveStrategy1; - uint24 public poolFee; // Uniswap V3 Pool Fee - bool public swapsPaused = false; // True if Swaps are paused - bool public rebalancePaused = false; // True if Swaps are paused + /// @notice Uniswap V3 Pool Fee + uint24 public poolFee; + /// @notice True if Swaps are paused + bool public swapsPaused = false; + /// @notice True if liquidity rebalances are paused + bool public rebalancePaused = false; - uint256 public maxTVL; // In USD, 18 decimals + /// @notice Maximum amount the strategy can have deployed in the Uniswap pool. In OTokens to 18 decimals + uint256 public maxTVL; // Deposits to reserve strategy when contract balance exceeds this amount uint256 public minDepositThreshold0; @@ -122,34 +131,34 @@ abstract contract UniswapV3StrategyStorage is InitializableAbstractStrategy { uint160 public minSwapPriceX96; uint160 public maxSwapPriceX96; - // Token ID of active Position on the pool. zero, if there are no active LP position + /// @notice Token ID of active Position on the pool. zero, if there are no active LP position uint256 public activeTokenId; - // Sum of loss in value of tokens deployed to the pool + /// @notice Sum of loss in value of tokens deployed to the pool uint256 public netLostValue; - // Max value loss threshold after which rebalances aren't allowed + /// @notice Max value loss threshold after which rebalances aren't allowed uint256 public maxPositionValueLostThreshold; - // Uniswap V3's Pool + /// @notice Uniswap V3's Pool IUniswapV3Pool public pool; - // Uniswap V3's PositionManager + /// @notice Uniswap V3's PositionManager INonfungiblePositionManager public positionManager; - // A deployed contract that's used to call methods of Uniswap V3's libraries despite version mismatch + /// @notice A deployed contract that's used to call methods of Uniswap V3's libraries despite version mismatch IUniswapV3Helper public helper; - // Uniswap Swap Router + /// @notice Uniswap Swap Router ISwapRouter public swapRouter; - // A lookup table to find token IDs of position using f(lowerTick, upperTick) + /// @notice A lookup table to find token IDs of position using f(lowerTick, upperTick) mapping(int48 => uint256) public ticksToTokenId; - // Maps tokenIDs to their Position object + /// @notice Maps tokenIDs to their Position object mapping(uint256 => Position) public tokenIdToPosition; - // keccak256("OUSD.UniswapV3Strategy.LiquidityManager.impl") + /// @notice keccak256("OUSD.UniswapV3Strategy.LiquidityManager.impl") bytes32 constant LIQUIDITY_MANAGER_IMPL_POSITION = 0xec676d52175f7cbb4e4ea392c6b70f8946575021aad20479602b98adc56ad62d; @@ -192,7 +201,7 @@ abstract contract UniswapV3StrategyStorage is InitializableAbstractStrategy { Shared functions ****************************************/ /** - * @notice Deposits token balances in the contract back to the reserve strategies + * @dev Deposits token balances in the contract back to the reserve strategies */ function _depositAll() internal { uint256 token0Bal = IERC20(token0).balanceOf(address(this)); @@ -209,7 +218,7 @@ abstract contract UniswapV3StrategyStorage is InitializableAbstractStrategy { } /** - * @notice Returns the balance of both tokens in a given position (including fees) + * @dev Returns the balance of both tokens in a given position (including fees) * @param tokenId tokenID of the Position NFT * @return amount0 Amount of token0 in position * @return amount1 Amount of token1 in position @@ -230,7 +239,7 @@ abstract contract UniswapV3StrategyStorage is InitializableAbstractStrategy { } /** - * @notice Returns the balance of both tokens in a given position (without fees) + * @dev Returns the balance of both tokens in a given position (without fees) * @param tokenId tokenID of the Position NFT * @return amount0 Amount of token0 in position * @return amount1 Amount of token1 in position diff --git a/contracts/contracts/utils/InitializableAbstractStrategy.sol b/contracts/contracts/utils/InitializableAbstractStrategy.sol index af07d57d9b..51e5d18a01 100644 --- a/contracts/contracts/utils/InitializableAbstractStrategy.sol +++ b/contracts/contracts/utils/InitializableAbstractStrategy.sol @@ -103,7 +103,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Collect accumulated reward token and send to Harvester. + * @notice Collect accumulated reward token and send to Harvester. */ function collectRewardTokens() external virtual onlyHarvester nonReentrant { _collectRewardTokens(); @@ -163,7 +163,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Set the reward token addresses. + * @notice Set the reward token addresses. * @param _rewardTokenAddresses Address array of the reward token */ function setRewardTokenAddresses(address[] calldata _rewardTokenAddresses) @@ -185,7 +185,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Get the reward token addresses. + * @notice Get the reward token addresses. * @return address[] the reward token addresses. */ function getRewardTokenAddresses() @@ -197,7 +197,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Provide support for asset by passing its pToken address. + * @notice Provide support for asset by passing its pToken address. * This method can only be called by the system Governor * @param _asset Address for the asset * @param _pToken Address for the corresponding platform token @@ -211,7 +211,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Remove a supported asset by passing its index. + * @notice Remove a supported asset by passing its index. * This method can only be called by the system Governor * @param _assetIndex Index of the asset to be removed */ @@ -252,7 +252,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Transfer token to governor. Intended for recovering tokens stuck in + * @notice Transfer token to governor. Intended for recovering tokens stuck in * strategy contracts, i.e. mistaken sends. * @param _asset Address for the asset * @param _amount Amount of the asset to transfer @@ -265,7 +265,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { } /** - * @dev Set the reward token addresses. + * @notice Set the reward token addresses. * @param _harvesterAddress Address of the harvester */ function setHarvesterAddress(address _harvesterAddress) @@ -291,25 +291,25 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { virtual; /** - * @dev Approve all the assets supported by the strategy + * @notice Approve all the assets supported by the strategy * to be moved around the platform. */ function safeApproveAllTokens() external virtual; /** - * @dev Deposit an amount of asset into the platform + * @notice Deposit an amount of asset into the platform * @param _asset Address for the asset * @param _amount Units of asset to deposit */ function deposit(address _asset, uint256 _amount) external virtual; /** - * @dev Deposit balance of all supported assets into the platform + * @notice Deposit balance of all supported assets into the platform */ function depositAll() external virtual; /** - * @dev Withdraw an amount of asset from the platform. + * @notice Withdraw an amount of asset from the platform. * @param _recipient Address to which the asset should be sent * @param _asset Address of the asset * @param _amount Units of asset to withdraw @@ -321,7 +321,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { ) external virtual; /** - * @dev Withdraw all assets from strategy sending assets to Vault. + * @notice Withdraw all assets from strategy sending assets to Vault. */ function withdrawAll() external virtual; @@ -338,7 +338,7 @@ abstract contract InitializableAbstractStrategy is Initializable, Governable { returns (uint256 balance); /** - * @dev Check if an asset is supported. + * @notice Check if an asset is supported. * @param _asset Address of the asset * @return bool Whether asset is supported */ From 5c7b675731fb376334fa982d5d42b737760b51a5 Mon Sep 17 00:00:00 2001 From: Nicholas Addison Date: Fri, 23 Jun 2023 14:30:57 +1000 Subject: [PATCH 3/3] Added Uniswap V3 strategy diagrams --- .../contracts/strategies/uniswap/README.md | 15 + contracts/docs/UniswapV3StrategyHierarchy.svg | 94 +++++ contracts/docs/UniswapV3StrategySquashed.svg | 162 ++++++++ contracts/docs/UniswapV3StrategyStorage.svg | 359 ++++++++++++++++++ contracts/docs/generate.sh | 5 + 5 files changed, 635 insertions(+) create mode 100644 contracts/contracts/strategies/uniswap/README.md create mode 100644 contracts/docs/UniswapV3StrategyHierarchy.svg create mode 100644 contracts/docs/UniswapV3StrategySquashed.svg create mode 100644 contracts/docs/UniswapV3StrategyStorage.svg diff --git a/contracts/contracts/strategies/uniswap/README.md b/contracts/contracts/strategies/uniswap/README.md new file mode 100644 index 0000000000..0ac339a4d8 --- /dev/null +++ b/contracts/contracts/strategies/uniswap/README.md @@ -0,0 +1,15 @@ +# Diagrams + +## Uniswap V3 Strategy + +### Hierarchy + +![Uniswap V3 Strategy Hierarchy](../../../docs/UniswapV3StrategyHierarchy.svg) + +### Squashed + +![Uniswap V3 Strategy Squashed](../../../docs/UniswapV3StrategySquashed.svg) + +### Storage + +![Uniswap V3 Strategy Storage](../../../docs/UniswapV3StrategyStorage.svg) diff --git a/contracts/docs/UniswapV3StrategyHierarchy.svg b/contracts/docs/UniswapV3StrategyHierarchy.svg new file mode 100644 index 0000000000..39db2d7dc4 --- /dev/null +++ b/contracts/docs/UniswapV3StrategyHierarchy.svg @@ -0,0 +1,94 @@ + + + + + + +UmlClassDiagram + + + +7 + +Governable +../contracts/governance/Governable.sol + + + +207 + +UniswapV3LiquidityManager +../contracts/strategies/uniswap/UniswapV3LiquidityManager.sol + + + +210 + +<<Abstract>> +UniswapV3StrategyStorage +../contracts/strategies/uniswap/UniswapV3StrategyStorage.sol + + + +207->210 + + + + + +209 + +UniswapV3Strategy +../contracts/strategies/uniswap/UniswapV3Strategy.sol + + + +209->210 + + + + + +156 + +<<Abstract>> +InitializableAbstractStrategy +../contracts/utils/InitializableAbstractStrategy.sol + + + +210->156 + + + + + +155 + +<<Abstract>> +Initializable +../contracts/utils/Initializable.sol + + + +156->7 + + + + + +156->155 + + + + + +156->156 + + + + + diff --git a/contracts/docs/UniswapV3StrategySquashed.svg b/contracts/docs/UniswapV3StrategySquashed.svg new file mode 100644 index 0000000000..a401150aed --- /dev/null +++ b/contracts/docs/UniswapV3StrategySquashed.svg @@ -0,0 +1,162 @@ + + + + + + +UmlClassDiagram + + + +209 + +UniswapV3Strategy +../contracts/strategies/uniswap/UniswapV3Strategy.sol + +Private: +   initialized: bool <<Initializable>> +   initializing: bool <<Initializable>> +   ______gap: uint256[50] <<Initializable>> +   governorPosition: bytes32 <<Governable>> +   pendingGovernorPosition: bytes32 <<Governable>> +   reentryStatusPosition: bytes32 <<Governable>> +   _reserved: int256[98] <<InitializableAbstractStrategy>> +Internal: +   assetsMapped: address[] <<InitializableAbstractStrategy>> +Public: +   _NOT_ENTERED: uint256 <<Governable>> +   _ENTERED: uint256 <<Governable>> +   platformAddress: address <<InitializableAbstractStrategy>> +   vaultAddress: address <<InitializableAbstractStrategy>> +   assetToPToken: mapping(address=>address) <<InitializableAbstractStrategy>> +   _deprecated_rewardTokenAddress: address <<InitializableAbstractStrategy>> +   _deprecated_rewardLiquidationThreshold: uint256 <<InitializableAbstractStrategy>> +   harvesterAddress: address <<InitializableAbstractStrategy>> +   rewardTokenAddresses: address[] <<InitializableAbstractStrategy>> +   _self: IUniswapV3Strategy <<UniswapV3StrategyStorage>> +   operatorAddr: address <<UniswapV3StrategyStorage>> +   token0: address <<UniswapV3StrategyStorage>> +   token1: address <<UniswapV3StrategyStorage>> +   reserveStrategy0: IStrategy <<UniswapV3StrategyStorage>> +   reserveStrategy1: IStrategy <<UniswapV3StrategyStorage>> +   poolFee: uint24 <<UniswapV3StrategyStorage>> +   swapsPaused: bool <<UniswapV3StrategyStorage>> +   rebalancePaused: bool <<UniswapV3StrategyStorage>> +   maxTVL: uint256 <<UniswapV3StrategyStorage>> +   minDepositThreshold0: uint256 <<UniswapV3StrategyStorage>> +   minDepositThreshold1: uint256 <<UniswapV3StrategyStorage>> +   minRebalanceTick: int24 <<UniswapV3StrategyStorage>> +   maxRebalanceTick: int24 <<UniswapV3StrategyStorage>> +   minSwapPriceX96: uint160 <<UniswapV3StrategyStorage>> +   maxSwapPriceX96: uint160 <<UniswapV3StrategyStorage>> +   activeTokenId: uint256 <<UniswapV3StrategyStorage>> +   netLostValue: uint256 <<UniswapV3StrategyStorage>> +   maxPositionValueLostThreshold: uint256 <<UniswapV3StrategyStorage>> +   pool: IUniswapV3Pool <<UniswapV3StrategyStorage>> +   positionManager: INonfungiblePositionManager <<UniswapV3StrategyStorage>> +   helper: IUniswapV3Helper <<UniswapV3StrategyStorage>> +   swapRouter: ISwapRouter <<UniswapV3StrategyStorage>> +   ticksToTokenId: mapping(int48=>uint256) <<UniswapV3StrategyStorage>> +   tokenIdToPosition: mapping(uint256=>Position) <<UniswapV3StrategyStorage>> +   LIQUIDITY_MANAGER_IMPL_POSITION: bytes32 <<UniswapV3StrategyStorage>> + +Internal: +    _governor(): (governorOut: address) <<Governable>> +    _pendingGovernor(): (pendingGovernor: address) <<Governable>> +    _setGovernor(newGovernor: address) <<Governable>> +    _setPendingGovernor(newGovernor: address) <<Governable>> +    _changeGovernor(_newGovernor: address) <<Governable>> +    _initialize(_platformAddress: address, _vaultAddress: address, _rewardTokenAddresses: address[], _assets: address[], _pTokens: address[]) <<InitializableAbstractStrategy>> +    _collectRewardTokens() <<InitializableAbstractStrategy>> +    _setPTokenAddress(_asset: address, _pToken: address) <<InitializableAbstractStrategy>> +    _abstractSetPToken(_asset: address, address) <<UniswapV3Strategy>> +    _depositAll() <<UniswapV3StrategyStorage>> +    getPositionBalance(tokenId: uint256): (amount0: uint256, amount1: uint256) <<UniswapV3StrategyStorage>> +    getPositionPrincipal(tokenId: uint256): (amount0: uint256, amount1: uint256) <<UniswapV3StrategyStorage>> +    _setOperator(_operator: address) <<UniswapV3Strategy>> +    _setMaxTVL(_maxTVL: uint256) <<UniswapV3Strategy>> +    _setMaxPositionValueLostThreshold(_maxValueLostThreshold: uint256) <<UniswapV3Strategy>> +    _onlyPoolTokens(addr: address) <<UniswapV3Strategy>> +External: +    transferGovernance(_newGovernor: address) <<onlyGovernor>> <<Governable>> +    claimGovernance() <<Governable>> +    initialize(_platformAddress: address, _vaultAddress: address, _rewardTokenAddresses: address[], _assets: address[], _pTokens: address[]) <<onlyGovernor, initializer>> <<InitializableAbstractStrategy>> +    collectRewardTokens() <<UniswapV3Strategy>> +    setRewardTokenAddresses(_rewardTokenAddresses: address[]) <<onlyGovernor>> <<InitializableAbstractStrategy>> +    getRewardTokenAddresses(): address[] <<InitializableAbstractStrategy>> +    setPTokenAddress(address, address) <<UniswapV3Strategy>> +    removePToken(uint256) <<UniswapV3Strategy>> +    setHarvesterAddress(_harvesterAddress: address) <<onlyGovernor>> <<InitializableAbstractStrategy>> +    safeApproveAllTokens() <<onlyGovernor, nonReentrant>> <<UniswapV3Strategy>> +    deposit(address, uint256) <<onlyVault, nonReentrant>> <<UniswapV3Strategy>> +    depositAll() <<onlyVault, nonReentrant>> <<UniswapV3Strategy>> +    withdraw(recipient: address, _asset: address, amount: uint256) <<onlyVault, nonReentrant>> <<UniswapV3Strategy>> +    withdrawAll() <<onlyVault, nonReentrant>> <<UniswapV3Strategy>> +    checkBalance(_asset: address): (balance: uint256) <<UniswapV3Strategy>> +    supportsAsset(_asset: address): bool <<UniswapV3Strategy>> +    initialize(_vaultAddress: address, _poolAddress: address, _nonfungiblePositionManager: address, _helper: address, _swapRouter: address, _operator: address, _maxTVL: uint256, _maxValueLostThreshold: uint256) <<onlyGovernor, initializer>> <<UniswapV3Strategy>> +    setOperator(_operator: address) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setReserveStrategy(_asset: address, _reserveStrategy: address) <<onlyGovernorOrStrategist, nonReentrant>> <<UniswapV3Strategy>> +    reserveStrategy(_asset: address): (reserveStrategyAddr: address) <<UniswapV3Strategy>> +    setMinDepositThreshold(_asset: address, _minThreshold: uint256) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setRebalancePaused(_paused: bool) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setSwapsPaused(_paused: bool) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setMaxTVL(_maxTVL: uint256) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setMaxPositionValueLostThreshold(_maxValueLostThreshold: uint256) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    resetLostValue() <<onlyGovernor>> <<UniswapV3Strategy>> +    setRebalancePriceThreshold(minTick: int24, maxTick: int24) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    setSwapPriceThreshold(minTick: int24, maxTick: int24) <<onlyGovernorOrStrategist>> <<UniswapV3Strategy>> +    getPendingFees(): (amount0: uint256, amount1: uint256) <<UniswapV3Strategy>> +    onERC721Received(address, address, uint256, bytes): bytes4 <<UniswapV3Strategy>> +    resetAllowanceOfTokens() <<onlyGovernor, nonReentrant>> <<UniswapV3Strategy>> +    setLiquidityManagerImpl(newImpl: address) <<onlyGovernor>> <<UniswapV3Strategy>> +    null() <<UniswapV3Strategy>> +Public: +    <<event>> PendingGovernorshipTransfer(previousGovernor: address, newGovernor: address) <<Governable>> +    <<event>> GovernorshipTransferred(previousGovernor: address, newGovernor: address) <<Governable>> +    <<event>> PTokenAdded(_asset: address, _pToken: address) <<InitializableAbstractStrategy>> +    <<event>> PTokenRemoved(_asset: address, _pToken: address) <<InitializableAbstractStrategy>> +    <<event>> Deposit(_asset: address, _pToken: address, _amount: uint256) <<InitializableAbstractStrategy>> +    <<event>> Withdrawal(_asset: address, _pToken: address, _amount: uint256) <<InitializableAbstractStrategy>> +    <<event>> RewardTokenCollected(recipient: address, rewardToken: address, amount: uint256) <<InitializableAbstractStrategy>> +    <<event>> RewardTokenAddressesUpdated(_oldAddresses: address[], _newAddresses: address[]) <<InitializableAbstractStrategy>> +    <<event>> HarvesterAddressesUpdated(_oldHarvesterAddress: address, _newHarvesterAddress: address) <<InitializableAbstractStrategy>> +    <<event>> OperatorChanged(_address: address) <<UniswapV3StrategyStorage>> +    <<event>> LiquidityManagerImplementationUpgraded(_newImpl: address) <<UniswapV3StrategyStorage>> +    <<event>> ReserveStrategyChanged(asset: address, reserveStrategy: address) <<UniswapV3StrategyStorage>> +    <<event>> MinDepositThresholdChanged(asset: address, minDepositThreshold: uint256) <<UniswapV3StrategyStorage>> +    <<event>> RebalancePauseStatusChanged(paused: bool) <<UniswapV3StrategyStorage>> +    <<event>> SwapsPauseStatusChanged(paused: bool) <<UniswapV3StrategyStorage>> +    <<event>> RebalancePriceThresholdChanged(minTick: int24, maxTick: int24) <<UniswapV3StrategyStorage>> +    <<event>> SwapPriceThresholdChanged(minTick: int24, minSwapPriceX96: uint160, maxTick: int24, maxSwapPriceX96: uint160) <<UniswapV3StrategyStorage>> +    <<event>> MaxTVLChanged(maxTVL: uint256) <<UniswapV3StrategyStorage>> +    <<event>> MaxValueLostThresholdChanged(amount: uint256) <<UniswapV3StrategyStorage>> +    <<event>> NetLostValueReset(_by: address) <<UniswapV3StrategyStorage>> +    <<event>> NetLostValueChanged(currentNetLostValue: uint256) <<UniswapV3StrategyStorage>> +    <<event>> PositionValueChanged(tokenId: uint256, initialValue: uint256, currentValue: uint256, delta: int256) <<UniswapV3StrategyStorage>> +    <<event>> AssetSwappedForRebalancing(tokenIn: address, tokenOut: address, amountIn: uint256, amountOut: uint256) <<UniswapV3StrategyStorage>> +    <<event>> UniswapV3LiquidityAdded(tokenId: uint256, amount0Sent: uint256, amount1Sent: uint256, liquidityMinted: uint128) <<UniswapV3StrategyStorage>> +    <<event>> UniswapV3LiquidityRemoved(tokenId: uint256, amount0Received: uint256, amount1Received: uint256, liquidityBurned: uint128) <<UniswapV3StrategyStorage>> +    <<event>> UniswapV3PositionMinted(tokenId: uint256, lowerTick: int24, upperTick: int24) <<UniswapV3StrategyStorage>> +    <<event>> UniswapV3PositionClosed(tokenId: uint256, amount0Received: uint256, amount1Received: uint256) <<UniswapV3StrategyStorage>> +    <<event>> UniswapV3FeeCollected(tokenId: uint256, amount0: uint256, amount1: uint256) <<UniswapV3StrategyStorage>> +    <<modifier>> initializer() <<Initializable>> +    <<modifier>> onlyGovernor() <<Governable>> +    <<modifier>> nonReentrant() <<Governable>> +    <<modifier>> nonReentrantView() <<Governable>> +    <<modifier>> onlyVault() <<InitializableAbstractStrategy>> +    <<modifier>> onlyHarvester() <<InitializableAbstractStrategy>> +    <<modifier>> onlyVaultOrGovernor() <<InitializableAbstractStrategy>> +    <<modifier>> onlyVaultOrGovernorOrStrategist() <<InitializableAbstractStrategy>> +    <<modifier>> onlyGovernorOrStrategist() <<UniswapV3StrategyStorage>> +    <<modifier>> onlyGovernorOrStrategistOrOperator() <<UniswapV3StrategyStorage>> +    constructor() <<UniswapV3StrategyStorage>> +    governor(): address <<Governable>> +    isGovernor(): bool <<Governable>> +    transferToken(_asset: address, _amount: uint256) <<onlyGovernor>> <<InitializableAbstractStrategy>> + + + diff --git a/contracts/docs/UniswapV3StrategyStorage.svg b/contracts/docs/UniswapV3StrategyStorage.svg new file mode 100644 index 0000000000..99c8364697 --- /dev/null +++ b/contracts/docs/UniswapV3StrategyStorage.svg @@ -0,0 +1,359 @@ + + + + + + +StorageDiagram + + + +6 + +UniswapV3Strategy <<Contract>> + +slot + +0 + +1-50 + +51 + +52 + +53 + +54 + +55 + +56 + +57 + +58 + +59-156 + +157 + +158 + +159 + +160 + +161 + +162 + +163 + +164 + +165 + +166 + +167 + +168 + +169 + +170 + +171 + +172 + +173 + +174 + +175 + +176 + +type: <inherited contract>.variable (bytes) + +unallocated (30) + +bool: Initializable.initializing (1) + +bool: Initializable.initialized (1) + +uint256[50]: Initializable.______gap (1600) + +unallocated (12) + +address: InitializableAbstractStrategy.platformAddress (20) + +unallocated (12) + +address: InitializableAbstractStrategy.vaultAddress (20) + +mapping(address=>address): InitializableAbstractStrategy.assetToPToken (32) + +address[]: InitializableAbstractStrategy.assetsMapped (32) + +unallocated (12) + +address: InitializableAbstractStrategy._deprecated_rewardTokenAddress (20) + +uint256: InitializableAbstractStrategy._deprecated_rewardLiquidationThreshold (32) + +unallocated (12) + +address: InitializableAbstractStrategy.harvesterAddress (20) + +address[]: InitializableAbstractStrategy.rewardTokenAddresses (32) + +int256[98]: InitializableAbstractStrategy._reserved (3136) + +unallocated (12) + +IUniswapV3Strategy: UniswapV3StrategyStorage._self (20) + +unallocated (12) + +address: UniswapV3StrategyStorage.operatorAddr (20) + +unallocated (12) + +address: UniswapV3StrategyStorage.token0 (20) + +unallocated (12) + +address: UniswapV3StrategyStorage.token1 (20) + +unallocated (12) + +IStrategy: UniswapV3StrategyStorage.reserveStrategy0 (20) + +unallocated (7) + +bool: UniswapV3StrategyStorage.rebalancePaused (1) + +bool: UniswapV3StrategyStorage.swapsPaused (1) + +uint24: UniswapV3StrategyStorage.poolFee (3) + +IStrategy: UniswapV3StrategyStorage.reserveStrategy1 (20) + +uint256: UniswapV3StrategyStorage.maxTVL (32) + +uint256: UniswapV3StrategyStorage.minDepositThreshold0 (32) + +uint256: UniswapV3StrategyStorage.minDepositThreshold1 (32) + +unallocated (6) + +uint160: UniswapV3StrategyStorage.minSwapPriceX96 (20) + +int24: UniswapV3StrategyStorage.maxRebalanceTick (3) + +int24: UniswapV3StrategyStorage.minRebalanceTick (3) + +unallocated (12) + +uint160: UniswapV3StrategyStorage.maxSwapPriceX96 (20) + +uint256: UniswapV3StrategyStorage.activeTokenId (32) + +uint256: UniswapV3StrategyStorage.netLostValue (32) + +uint256: UniswapV3StrategyStorage.maxPositionValueLostThreshold (32) + +unallocated (12) + +IUniswapV3Pool: UniswapV3StrategyStorage.pool (20) + +unallocated (12) + +INonfungiblePositionManager: UniswapV3StrategyStorage.positionManager (20) + +unallocated (12) + +IUniswapV3Helper: UniswapV3StrategyStorage.helper (20) + +unallocated (12) + +ISwapRouter: UniswapV3StrategyStorage.swapRouter (20) + +mapping(int48=>uint256): UniswapV3StrategyStorage.ticksToTokenId (32) + +mapping(uint256=>Position): UniswapV3StrategyStorage.tokenIdToPosition (32) + + + +1 + +uint256[50]: ______gap <<Array>> + +slot + +1 + +2 + +3-48 + +49 + +50 + +type: variable (bytes) + +uint256 (32) + +uint256 (32) + +---- (1472) + +uint256 (32) + +uint256 (32) + + + +6:8->1 + + + + + +2 + +address[]: assetsMapped <<Array>> +0x4a11f94e20a93c79f6ec743a1954ec4fc2c08429ae2122118bf234b2185c81b8 + +offset + +0 + +type: variable (bytes) + +unallocated (12) + +address (20) + + + +6:13->2 + + + + + +3 + +address[]: rewardTokenAddresses <<Array>> +0xa2999d817b6757290b50e8ecf3fa939673403dd35c97de392fdb343b4015ce9e + +offset + +0 + +type: variable (bytes) + +unallocated (12) + +address (20) + + + +6:18->3 + + + + + +4 + +int256[98]: _reserved <<Array>> + +slot + +59 + +60 + +61-154 + +155 + +156 + +type: variable (bytes) + +int256 (32) + +int256 (32) + +---- (3008) + +int256 (32) + +int256 (32) + + + +6:24->4 + + + + + +5 + +Position <<Struct>> + +offset + +0 + +1 + +2 + +3 + +4 + +type: variable (bytes) + +uint256: tokenId (32) + +unallocated (9) + +bool: exists (1) + +int24: upperTick (3) + +int24: lowerTick (3) + +uint128: liquidity (16) + +unallocated (12) + +uint160: sqrtRatioAX96 (20) + +unallocated (12) + +uint160: sqrtRatioBX96 (20) + +uint256: netValue (32) + + + +6:57->5 + + + + + diff --git a/contracts/docs/generate.sh b/contracts/docs/generate.sh index 5f5badbd24..601094d788 100644 --- a/contracts/docs/generate.sh +++ b/contracts/docs/generate.sh @@ -67,6 +67,11 @@ sol2uml .. -v -hv -hf -he -hs -hl -b MorphoCompoundStrategy -o MorphoCompStrateg sol2uml .. -s -d 0 -b MorphoCompoundStrategy -o MorphoCompStrategySquashed.svg sol2uml storage .. -c MorphoCompoundStrategy -o MorphoCompStrategyStorage.svg +# contracts/strategies/uniswap/v3 +sol2uml .. -v -hv -hf -he -hs -hl -hi -b UniswapV3Strategy,UniswapV3LiquidityManager -o UniswapV3StrategyHierarchy.svg +sol2uml .. -s -d 0 -b UniswapV3Strategy -o UniswapV3StrategySquashed.svg +sol2uml storage .. -c UniswapV3Strategy -o UniswapV3StrategyStorage.svg + # contracts/timelock sol2uml .. -v -hv -hf -he -hs -hl -b Timelock -o TimelockHierarchy.svg sol2uml .. -s -d 0 -b Timelock -o TimelockSquashed.svg