Skip to content

Commit

Permalink
IStrategy.isReadyForHardWork
Browse files Browse the repository at this point in the history
  • Loading branch information
a17 committed Mar 4, 2024
1 parent a423d80 commit 95a3ac3
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/interfaces/IStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ interface IStrategy is IERC165 {
/// @notice Is HardWork on vault deposits can be enabled
function isHardWorkOnDepositAllowed() external view returns (bool);

/// @notice Is HardWork can be executed
function isReadyForHardWork() external view returns (bool);

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* WRITE FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
5 changes: 5 additions & 0 deletions src/strategies/CompoundFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ contract CompoundFarmStrategy is FarmingStrategyBase {
return true;
}

/// @inheritdoc IStrategy
function isReadyForHardWork() external pure returns (bool isReady) {
isReady = true;
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* FARMING STRATEGY BASE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
6 changes: 6 additions & 0 deletions src/strategies/DefiEdgeQuickSwapMerklFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ contract DefiEdgeQuickSwapMerklFarmStrategy is LPStrategyBase, FarmingStrategyBa
/// @inheritdoc IStrategy
function isHardWorkOnDepositAllowed() external pure returns (bool allowed) {}

/// @inheritdoc IStrategy
function isReadyForHardWork() external view returns (bool) {
FarmingStrategyBaseStorage storage _$_ = _getFarmingStrategyBaseStorage();
return StrategyLib.assetsAreOnBalance(_$_._rewardAssets);
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRATEGY BASE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
6 changes: 6 additions & 0 deletions src/strategies/GammaQuickSwapMerklFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ contract GammaQuickSwapMerklFarmStrategy is LPStrategyBase, FarmingStrategyBase
/// @inheritdoc IStrategy
function isHardWorkOnDepositAllowed() external pure returns (bool allowed) {}

/// @inheritdoc IStrategy
function isReadyForHardWork() external view returns (bool) {
FarmingStrategyBaseStorage storage _$_ = _getFarmingStrategyBaseStorage();
return StrategyLib.assetsAreOnBalance(_$_._rewardAssets);
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRATEGY BASE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
6 changes: 6 additions & 0 deletions src/strategies/IchiQuickSwapMerklFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ contract IchiQuickSwapMerklFarmStrategy is LPStrategyBase, FarmingStrategyBase {
/// @inheritdoc IStrategy
function isHardWorkOnDepositAllowed() external pure returns (bool allowed) {}

/// @inheritdoc IStrategy
function isReadyForHardWork() external view returns (bool) {
FarmingStrategyBaseStorage storage _$_ = _getFarmingStrategyBaseStorage();
return StrategyLib.assetsAreOnBalance(_$_._rewardAssets);
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRATEGY BASE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
6 changes: 6 additions & 0 deletions src/strategies/IchiRetroMerklFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ contract IchiRetroMerklFarmStrategy is LPStrategyBase, FarmingStrategyBase {
/// @inheritdoc IStrategy
function isHardWorkOnDepositAllowed() external pure returns (bool allowed) {}

/// @inheritdoc IStrategy
function isReadyForHardWork() external view returns (bool) {
FarmingStrategyBaseStorage storage _$_ = _getFarmingStrategyBaseStorage();
return StrategyLib.assetsAreOnBalance(_$_._rewardAssets);
}

/// @dev this special method used to fix forge coverage issue
function t() external pure returns (bool) {
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/strategies/QuickswapV3StaticFarmStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ contract QuickSwapV3StaticFarmStrategy is LPStrategyBase, FarmingStrategyBase {
return false;

Check warning on line 220 in src/strategies/QuickswapV3StaticFarmStrategy.sol

View check run for this annotation

Codecov / codecov/patch

src/strategies/QuickswapV3StaticFarmStrategy.sol#L220

Added line #L220 was not covered by tests
}

/// @inheritdoc IStrategy
function isReadyForHardWork() external pure returns (bool isReady) {
isReady = true;
}

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* STRATEGY BASE */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Expand Down
10 changes: 10 additions & 0 deletions src/strategies/libs/StrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@ library StrategyLib {
}
}

function assetsAreOnBalance(address[] memory assets) external view returns (bool isReady) {
uint rwLen = assets.length;
for (uint i; i < rwLen; ++i) {
if (IERC20(assets[i]).balanceOf(address(this)) > 0) {
isReady = true;
break;
}
}
}

// function getFarmsForStrategyId(address platform, string memory _id) external view returns (IFactory.Farm[] memory farms) {
// uint total;
// IFactory.Farm[] memory allFarms = IFactory(IPlatform(platform).factory()).farms();
Expand Down
5 changes: 5 additions & 0 deletions src/test/MockStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ contract MockStrategy is LPStrategyBase {
return true;
}

/// @inheritdoc IStrategy
function isReadyForHardWork() external pure returns (bool isReady) {
isReady = true;

Check warning on line 60 in src/test/MockStrategy.sol

View check run for this annotation

Codecov / codecov/patch

src/test/MockStrategy.sol#L60

Added line #L60 was not covered by tests
}

function initVariants(address)
public
pure
Expand Down
1 change: 1 addition & 0 deletions test/base/UniversalTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ abstract contract UniversalTest is Test, ChainSetup, Utils {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* HARDWORK 0 */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
assertEq(strategy.isReadyForHardWork(), true);
vm.txGasPrice(15e10); // 150gwei
{
vars.apr = 0;
Expand Down

0 comments on commit 95a3ac3

Please sign in to comment.