From b256fae61bc8e5cdc8b0a56d7f67f1b08bc86aca Mon Sep 17 00:00:00 2001 From: johnnyonline Date: Sat, 9 Mar 2024 22:25:57 +0200 Subject: [PATCH] feat: enable zero incentivesController and fix constructor assertions --- .../SiloStrategy.sol} | 17 +++++++++--- src/test/utils/Strategies.sol | 26 +++++++++++-------- 2 files changed, 28 insertions(+), 15 deletions(-) rename src/strategies/{crvUSD/SiloLlamaStrategy.sol => silo/SiloStrategy.sol} (94%) diff --git a/src/strategies/crvUSD/SiloLlamaStrategy.sol b/src/strategies/silo/SiloStrategy.sol similarity index 94% rename from src/strategies/crvUSD/SiloLlamaStrategy.sol rename to src/strategies/silo/SiloStrategy.sol index 360bca9..dd6ca72 100644 --- a/src/strategies/crvUSD/SiloLlamaStrategy.sol +++ b/src/strategies/silo/SiloStrategy.sol @@ -10,6 +10,7 @@ import {AuctionSwapper, Auction} from "@periphery/swappers/AuctionSwapper.sol"; import {IAaveIncentivesController} from "@silo/external/aave/interfaces/IAaveIncentivesController.sol"; import {ISilo} from "@silo/interfaces/ISilo.sol"; import {IShareToken} from "@silo/interfaces/IShareToken.sol"; +import {ISiloRepository} from "@silo/interfaces/ISiloRepository.sol"; import {EasyMathV2} from "@silo/lib/EasyMathV2.sol"; /** @@ -25,7 +26,7 @@ import {EasyMathV2} from "@silo/lib/EasyMathV2.sol"; // NOTE: To implement permissioned functions you can use the onlyManagement, onlyEmergencyAuthorized and onlyKeepers modifiers -contract SiloLlamaStrategy is AuctionSwapper, BaseStrategy { +contract SiloStrategy is AuctionSwapper, BaseStrategy { using SafeERC20 for ERC20; using EasyMathV2 for uint256; @@ -50,13 +51,21 @@ contract SiloLlamaStrategy is AuctionSwapper, BaseStrategy { */ IShareToken private immutable share; + /** + * @notice Used to initialize the strategy on deployment. + * @param _siloRepository The address of the SiloRepository. + * @param _incentivesController The address of the IncentivesController. If address(0), the strategy will not claim incentives. + * @param _siloAsset The address of the Silo asset. Used to retrieve the Silo address from the SiloRepository. + * @param _asset The address of the strategy asset. + */ constructor( - address _silo, + address _siloRepository, address _incentivesController, + address _siloAsset, address _asset, string memory _name ) BaseStrategy(_asset, _name) { - silo = ISilo(_silo); + silo = ISilo(ISiloRepository(_siloRepository).getSilo(_siloAsset)); share = silo.assetStorage(_asset).collateralToken; require(address(share) != address(0), "wrong silo"); @@ -72,7 +81,7 @@ contract SiloLlamaStrategy is AuctionSwapper, BaseStrategy { incentivesController = IAaveIncentivesController(_incentivesController); rewardToken = ERC20(_rewardToken); - ERC20(_asset).forceApprove(_silo, type(uint256).max); + ERC20(_asset).forceApprove(address(silo), type(uint256).max); } /*////////////////////////////////////////////////////////////// diff --git a/src/test/utils/Strategies.sol b/src/test/utils/Strategies.sol index 098e0d3..20c0949 100644 --- a/src/test/utils/Strategies.sol +++ b/src/test/utils/Strategies.sol @@ -3,31 +3,35 @@ pragma solidity 0.8.18; import {ISilo} from "@silo/interfaces/ISilo.sol"; -import {SiloLlamaStrategy} from "../../strategies/crvUSD/SiloLlamaStrategy.sol"; +import {SiloStrategy} from "../../strategies/silo/SiloStrategy.sol"; contract Strategies { - address private _crvUSDCRVSilo = 0x96eFdF95Cc47fe90e8f63D2f5Ef9FB8B180dAeB9; - address private _crvUSD = 0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E; + address private constant _crvUSDCRVSilo = 0x96eFdF95Cc47fe90e8f63D2f5Ef9FB8B180dAeB9; + address private constant _siloRepository = 0xBCd67f35c7A2F212db0AD7f68fC773b5aC15377c; + address private constant _crvUSD = 0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E; + address private constant _incentivesController = 0x361384A0d755f972E5Eea26e4F4efBAf976B6461; + address private constant _crv = 0xD533a949740bb3306d119CC777fa900bA034cd52; function _setUpStrategy() internal returns (address) { - return _setUpSiloLlamaStrategy(); + return _setUpSiloStrategy(); } function _earnInterest() internal { - _earnSiloLlamaInterest(); + _earnSiloInterest(); } - function _setUpSiloLlamaStrategy() private returns (address _strategy) { - _strategy = address(new SiloLlamaStrategy( - address(_crvUSDCRVSilo), // _silo - address(0x361384A0d755f972E5Eea26e4F4efBAf976B6461), // _incentivesController - _crvUSD, // _asset + function _setUpSiloStrategy() private returns (address _strategy) { + _strategy = address(new SiloStrategy( + _siloRepository, + _incentivesController, + _crv, + _crvUSD, "crvUSD/CRV SiloLlamaStrategy" )); } - function _earnSiloLlamaInterest() private { + function _earnSiloInterest() private { ISilo(_crvUSDCRVSilo).accrueInterest(_crvUSD); } } \ No newline at end of file