Skip to content

Commit

Permalink
Make leverage strategy view methods public
Browse files Browse the repository at this point in the history
  • Loading branch information
tsudmi committed Nov 28, 2024
1 parent e4d32a0 commit f3ff6fe
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 210 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
566045
566111
Original file line number Diff line number Diff line change
@@ -1 +1 @@
551330
551396
Original file line number Diff line number Diff line change
@@ -1 +1 @@
509091
509144
Original file line number Diff line number Diff line change
@@ -1 +1 @@
777310
778147
Original file line number Diff line number Diff line change
@@ -1 +1 @@
904108
904945
Original file line number Diff line number Diff line change
@@ -1 +1 @@
229074
229118
Original file line number Diff line number Diff line change
@@ -1 +1 @@
275190
275237
Original file line number Diff line number Diff line change
@@ -1 +1 @@
248522
248569
Original file line number Diff line number Diff line change
@@ -1 +1 @@
370257
370279
Original file line number Diff line number Diff line change
@@ -1 +1 @@
611636
611702
Original file line number Diff line number Diff line change
@@ -1 +1 @@
499998
500051
Original file line number Diff line number Diff line change
@@ -1 +1 @@
649991
650027
Original file line number Diff line number Diff line change
@@ -1 +1 @@
55699
55721
10 changes: 5 additions & 5 deletions script/DeployStakeHelpers.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ contract DeployStakeHelpers is Script {
struct ConfigParams {
address keeper;
address osTokenConfigV1;
address osTokenConfigV2;
address osTokenController;
address osTokenConfig;
address osTokenVaultController;
}

function _readEnvVariables() internal view returns (ConfigParams memory params) {
params.keeper = vm.envAddress('KEEPER');
params.osTokenConfigV1 = vm.envAddress('OS_TOKEN_CONFIG_V1');
params.osTokenConfigV2 = vm.envAddress('OS_TOKEN_CONFIG_V2');
params.osTokenController = vm.envAddress('OS_TOKEN_CONTROLLER');
params.osTokenConfig = vm.envAddress('OS_TOKEN_CONFIG');
params.osTokenVaultController = vm.envAddress('OS_TOKEN_VAULT_CONTROLLER');
}

function run() external {
Expand All @@ -31,7 +31,7 @@ contract DeployStakeHelpers is Script {

// Deploy StakeHelpers.
StakeHelpers stakeHelpers =
new StakeHelpers(params.keeper, params.osTokenConfigV1, params.osTokenConfigV2, params.osTokenController);
new StakeHelpers(params.keeper, params.osTokenConfigV1, params.osTokenConfig, params.osTokenVaultController);
console.log('StakeHelpers deployed at: ', address(stakeHelpers));

vm.stopBroadcast();
Expand Down
6 changes: 5 additions & 1 deletion src/MerkleDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ contract MerkleDistributor is Ownable2Step, EIP712, IMerkleDistributor {
rewardsRoot = newRewardsRoot;
// cannot overflow on human timescales
lastUpdateTimestamp = uint64(block.timestamp);
nonce += 1;

unchecked {
// cannot realistically overflow
nonce += 1;
}

// emit event
emit RewardsRootUpdated(msg.sender, newRewardsRoot, newRewardsIpfsHash);
Expand Down
13 changes: 0 additions & 13 deletions src/StakeHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.26;

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {Math} from '@openzeppelin/contracts/utils/math/Math.sol';
import {IOsTokenConfig as IOsTokenConfigV2} from '@stakewise-core/interfaces/IOsTokenConfig.sol';
import {IOsTokenVaultController} from '@stakewise-core/interfaces/IOsTokenVaultController.sol';
Expand Down Expand Up @@ -145,12 +144,6 @@ contract StakeHelpers is Multicall {
if (stakeAssets < outputData.receivedAssets) {
outputData.receivedAssets = stakeAssets;
}
stakeAssets -= outputData.receivedAssets;

// if less than 1% of stake assets left, add them to received assets
if (Math.mulDiv(outputData.receivedAssets, 0.01 ether, 1 ether) >= stakeAssets) {
outputData.receivedAssets += stakeAssets;
}
outputData.exitQueueShares =
Math.min(stakeShares, IVaultState(inputData.vault).convertToShares(outputData.receivedAssets));
}
Expand Down Expand Up @@ -192,12 +185,6 @@ contract StakeHelpers is Multicall {
if (stakeAssets < receivedAssets) {
receivedAssets = stakeAssets;
}
stakeAssets -= receivedAssets;

// if less than 1% of stake assets left, add them to received assets
if (Math.mulDiv(receivedAssets, 0.01 ether, 1 ether) >= stakeAssets) {
receivedAssets += stakeAssets;
}
receivedAssets += _osTokenController.convertToAssets(balanceOsTokenShares);
}

Expand Down
13 changes: 6 additions & 7 deletions src/leverage/AaveLeverageStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
pragma solidity ^0.8.26;

import {Math} from '@openzeppelin/contracts/utils/math/Math.sol';
import {SafeCast} from '@openzeppelin/contracts/utils/math/SafeCast.sol';
import {IPool} from '@aave-core/interfaces/IPool.sol';
import {IScaledBalanceToken} from '@aave-core/interfaces/IScaledBalanceToken.sol';
import {WadRayMath} from '@aave-core/protocol/libraries/math/WadRayMath.sol';
import {IStrategyProxy} from '../interfaces/IStrategyProxy.sol';
import {LeverageStrategy} from './LeverageStrategy.sol';
import {LeverageStrategy, ILeverageStrategy} from './LeverageStrategy.sol';

/**
* @title AaveLeverageStrategy
Expand Down Expand Up @@ -68,8 +67,8 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
_aaveVarDebtAssetToken = IScaledBalanceToken(aaveVarDebtAssetToken);
}

/// @inheritdoc LeverageStrategy
function _getBorrowLtv() internal view override returns (uint256) {
/// @inheritdoc ILeverageStrategy
function getBorrowLtv() public view override returns (uint256) {
// convert to 1e18 precision
uint256 aaveLtv = uint256(_aavePool.getEModeCategoryCollateralConfig(_emodeCategory).ltv) * 1e14;

Expand All @@ -82,10 +81,10 @@ abstract contract AaveLeverageStrategy is LeverageStrategy {
return Math.min(aaveLtv, abi.decode(maxBorrowLtvPercentConfig, (uint256)));
}

/// @inheritdoc LeverageStrategy
function _getBorrowState(
/// @inheritdoc ILeverageStrategy
function getBorrowState(
address proxy
) internal view override returns (uint256 borrowedAssets, uint256 suppliedOsTokenShares) {
) public view override returns (uint256 borrowedAssets, uint256 suppliedOsTokenShares) {
suppliedOsTokenShares = _aaveOsToken.scaledBalanceOf(proxy);
if (suppliedOsTokenShares != 0) {
uint256 normalizedIncome = _aavePool.getReserveNormalizedIncome(address(_osToken));
Expand Down
Loading

0 comments on commit f3ff6fe

Please sign in to comment.