Skip to content

Commit

Permalink
feat: swap vests assets and check no outgoing strategy assets
Browse files Browse the repository at this point in the history
  • Loading branch information
0xtekgrinder committed Jul 17, 2024
1 parent 6f63f55 commit 16bf664
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions contracts/BaseStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -525,23 +525,24 @@ abstract contract BaseStrategy is ERC4626, AccessControl {
* @custom:requires KEEPER_ROLE
*/
function swap(address[] calldata tokens, bytes[] calldata callDatas) public onlyRole(KEEPER_ROLE) {
address localAsset = asset();
address localStrategyAsset = STRATEGY_ASSET;
uint256 assetBalance = IERC20(localAsset).balanceOf(address(this));
uint256 strategyAssetBalance = IERC20(localStrategyAsset).balanceOf(address(this));
address _asset = asset();
address _strategyAsset = STRATEGY_ASSET;

uint256 assetBalance = IERC20(_asset).balanceOf(address(this));
uint256 strategyAssetBalance = IERC20(_strategyAsset).balanceOf(address(this));

_swap(tokens, callDatas);

uint256 newStrategyAssetBalance = IERC20(localStrategyAsset).balanceOf(address(this));
uint256 newAssetBalance = IERC20(_asset).balanceOf(address(this));

if (
IERC20(localAsset).balanceOf(address(this)) < assetBalance || newStrategyAssetBalance < strategyAssetBalance
) {
_handleUserGain(newAssetBalance);
_afterDeposit(newAssetBalance);

uint256 newStrategyAssetBalance = IERC20(_strategyAsset).balanceOf(address(this));

if (newStrategyAssetBalance < strategyAssetBalance) {
revert OutgoingAssets();
}

_handleUserGain(newStrategyAssetBalance);
_afterDeposit(newStrategyAssetBalance);
}

/**
Expand Down

0 comments on commit 16bf664

Please sign in to comment.