From 8a686fa07c14bdd1cc46d3e67efffa3d5f555333 Mon Sep 17 00:00:00 2001 From: Schlag <89420541+Schlagonia@users.noreply.github.com> Date: Fri, 22 Mar 2024 14:36:41 -0600 Subject: [PATCH] fix: move up available withdraw limit (#28) * chore: remove old periphery * forge install: tokenized-strategy-periphery 3986b04bc9f49af8d2615e198a531b16c1e0ccf2 * fix: move up withdraw limit * fix: lint --- .gitmodules | 8 +-- lib/tokenized-strategy-periphery | 2 +- src/Strategy.sol | 97 +++++++++++++++++--------------- 3 files changed, 56 insertions(+), 51 deletions(-) diff --git a/.gitmodules b/.gitmodules index a5533c1d..cf82e815 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,10 +6,10 @@ path = lib/tokenized-strategy url = https://github.com/yearn/tokenized-strategy release = v3.0.2 -[submodule "lib/tokenized-strategy-periphery"] - path = lib/tokenized-strategy-periphery - url = https://github.com/yearn/tokenized-strategy-periphery - release = v3.0.2 [submodule "lib/openzeppelin-contracts"] path = lib/openzeppelin-contracts url = https://github.com/OpenZeppelin/openzeppelin-contracts +[submodule "lib/tokenized-strategy-periphery"] + path = lib/tokenized-strategy-periphery + url = https://github.com/yearn/tokenized-strategy-periphery + branch = master \ No newline at end of file diff --git a/lib/tokenized-strategy-periphery b/lib/tokenized-strategy-periphery index 62fff222..3986b04b 160000 --- a/lib/tokenized-strategy-periphery +++ b/lib/tokenized-strategy-periphery @@ -1 +1 @@ -Subproject commit 62fff222eac29f544ce8a1cd8ee2a4b478aaf628 +Subproject commit 3986b04bc9f49af8d2615e198a531b16c1e0ccf2 diff --git a/src/Strategy.sol b/src/Strategy.sol index 72499cd9..b97517cf 100644 --- a/src/Strategy.sol +++ b/src/Strategy.sol @@ -118,37 +118,37 @@ contract Strategy is BaseStrategy { //////////////////////////////////////////////////////////////*/ /** - * @dev Optional function for strategist to override that can - * be called in between reports. - * - * If '_tend' is used tendTrigger() will also need to be overridden. - * - * This call can only be called by a permissioned role so may be - * through protected relays. - * - * This can be used to harvest and compound rewards, deposit idle funds, - * perform needed position maintenance or anything else that doesn't need - * a full report for. + * @notice Gets the max amount of `asset` that can be withdrawn. + * @dev Defaults to an unlimited amount for any address. But can + * be overridden by strategists. * - * EX: A strategy that can not deposit funds without getting - * sandwiched can use the tend when a certain threshold - * of idle to totalAssets has been reached. + * This function will be called before any withdraw or redeem to enforce + * any limits desired by the strategist. This can be used for illiquid + * or sandwichable strategies. * - * This will have no effect on PPS of the strategy till report() is called. + * EX: + * return asset.balanceOf(yieldSource); * - * @param _totalIdle The current amount of idle funds that are available to deploy. + * This does not need to take into account the `_owner`'s share balance + * or conversion rates from shares to assets. * - function _tend(uint256 _totalIdle) internal override {} - */ + * @param . The address that is withdrawing from the strategy. + * @return . The available amount that can be withdrawn in terms of `asset` + */ + function availableWithdrawLimit( + address /*_owner*/ + ) public view override returns (uint256) { + // NOTE: Withdraw limitations such as liquidity constraints should be accounted for HERE + // rather than _freeFunds in order to not count them as losses on withdraws. - /** - * @dev Optional trigger to override if tend() will be used by the strategy. - * This must be implemented if the strategy hopes to invoke _tend(). - * - * @return . Should return true if tend() should be called by keeper or false if not. - * - function _tendTrigger() internal view override returns (bool) {} - */ + // TODO: If desired implement withdraw limit logic and any needed state variables. + + // EX: + // if(yieldSource.notShutdown()) { + // return asset.balanceOf(address(this)) + asset.balanceOf(yieldSource); + // } + return asset.balanceOf(address(this)); + } /** * @notice Gets the max amount of `asset` that an address can deposit. @@ -183,31 +183,36 @@ contract Strategy is BaseStrategy { */ /** - * @notice Gets the max amount of `asset` that can be withdrawn. - * @dev Defaults to an unlimited amount for any address. But can - * be overridden by strategists. + * @dev Optional function for strategist to override that can + * be called in between reports. * - * This function will be called before any withdraw or redeem to enforce - * any limits desired by the strategist. This can be used for illiquid - * or sandwichable strategies. + * If '_tend' is used tendTrigger() will also need to be overridden. * - * EX: - * return asset.balanceOf(address(this));; + * This call can only be called by a permissioned role so may be + * through protected relays. * - * This does not need to take into account the `_owner`'s share balance - * or conversion rates from shares to assets. + * This can be used to harvest and compound rewards, deposit idle funds, + * perform needed position maintenance or anything else that doesn't need + * a full report for. * - * @param . The address that is withdrawing from the strategy. - * @return . The available amount that can be withdrawn in terms of `asset` + * EX: A strategy that can not deposit funds without getting + * sandwiched can use the tend when a certain threshold + * of idle to totalAssets has been reached. * - function availableWithdrawLimit( - address _owner - ) public view override returns (uint256) { - TODO: If desired Implement withdraw limit logic and any needed state variables. - - EX: - return asset.balanceOf(address(this)); - } + * This will have no effect on PPS of the strategy till report() is called. + * + * @param _totalIdle The current amount of idle funds that are available to deploy. + * + function _tend(uint256 _totalIdle) internal override {} + */ + + /** + * @dev Optional trigger to override if tend() will be used by the strategy. + * This must be implemented if the strategy hopes to invoke _tend(). + * + * @return . Should return true if tend() should be called by keeper or false if not. + * + function _tendTrigger() internal view override returns (bool) {} */ /**