Skip to content

Commit

Permalink
feat: remove _all functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Van0k committed Nov 1, 2023
1 parent cf1f17f commit f4e4cef
Show file tree
Hide file tree
Showing 55 changed files with 197 additions and 1,583 deletions.
29 changes: 2 additions & 27 deletions contracts/adapters/aave/AaveV2_LendingPoolAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,7 @@ contract AaveV2_LendingPoolAdapter is AbstractAdapter, IAaveV2_LendingPoolAdapte
(tokensToEnable, tokensToDisable) = _depositDiffInternal(creditAccount, asset, leftoverAmount);
}

/// @notice Deposit all underlying tokens into Aave in exchange for aTokens, disables underlying
/// @param asset Address of underlying token to deposit
function depositAll(address asset)
external
override
creditFacadeOnly // U:[AAVE2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
address creditAccount = _creditAccount(); // U:[AAVE2-4]

(tokensToEnable, tokensToDisable) = _depositDiffInternal(creditAccount, asset, 1); // U:[AAVE2-4]
}

/// @dev Internal implementation of `depositDiff` and `depositAll`.
/// @dev Internal implementation of `depositDiff`
/// - Computes the amount to swap and passes to `_deposit`.
/// - If the leftover amount is 1 or less, disables the underlying token.
function _depositDiffInternal(address creditAccount, address asset, uint256 leftoverAmount)
Expand Down Expand Up @@ -144,18 +131,6 @@ contract AaveV2_LendingPoolAdapter is AbstractAdapter, IAaveV2_LendingPoolAdapte
(tokensToEnable, tokensToDisable) = _withdrawDiffInternal(creditAccount, asset, leftoverAmount);
}

/// @notice Withdraw all underlying tokens from Aave and burn aTokens, disables aToken
/// @param asset Address of underlying token to withdraw
function withdrawAll(address asset)
external
override
creditFacadeOnly // U:[AAVE2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
address creditAccount = _creditAccount();
(tokensToEnable, tokensToDisable) = _withdrawDiffInternal(creditAccount, asset, 1); // U:[AAVE2-6]
}

/// @dev Internal implementation of `withdraw` functionality
/// - using `_executeSwap` because need to check if tokens are recognized by the system
/// - aToken is not approved before the call because lending pool doesn't need permission to burn it
Expand All @@ -169,7 +144,7 @@ contract AaveV2_LendingPoolAdapter is AbstractAdapter, IAaveV2_LendingPoolAdapte
_executeSwapNoApprove(_aToken(asset), asset, _encodeWithdraw(creditAccount, asset, amount), false); // U:[AAVE2-5A]
}

/// @dev Internal implementation of `withdrawDiff` and `withdrawAll` functionality
/// @dev Internal implementation of `withdrawDiff`
/// - using `_executeSwap` because need to check if tokens are recognized by the system
/// - aToken is not approved before the call because lending pool doesn't need permission to burn it
/// - underlying is enabled after the call
Expand Down
44 changes: 2 additions & 42 deletions contracts/adapters/aave/AaveV2_WrappedATokenAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,6 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = _depositDiff(false, leftoverAssets);
}

/// @notice Deposit all balance of aTokens, disables aToken
function depositAll()
external
override
creditFacadeOnly // U:[AAVE2W-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _depositDiff(false, 1); // U:[AAVE2W-4]
}

/// @notice Deposit given amount underlying tokens
/// @param assets Amount of underlying tokens to deposit in exchange for waTokens
function depositUnderlying(uint256 assets)
Expand All @@ -105,16 +95,6 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = _depositDiff(true, leftoverAssets);
}

/// @notice Deposit all balance of underlying tokens, disables underlying
function depositAllUnderlying()
external
override
creditFacadeOnly // U:[AAVE2W-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _depositDiff(true, 1); // U:[AAVE2W-6]
}

/// @dev Internal implementation of `deposit` and `depositUnderlying`
/// - underlying / aAoken is approved because waToken contract needs permission to transfer it
/// - waToken is enabled after the call
Expand All @@ -131,7 +111,7 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = (waTokenMask, 0); // U:[AAVE2W-3,5]
}

/// @dev Internal implementation of `depositAll`, `depositDiff`, `depositAllUnderlying` and `depositDiffUnderlying`
/// @dev Internal implementation of `depositDiff` and `depositDiffUnderlying`
/// - underlying / aAoken is approved because wrapped aToken contract needs permission to transfer it
/// - waToken is enabled after the call
/// - underlying / aToken is disabled after the call if the leftover amount is 0 or 1
Expand Down Expand Up @@ -187,16 +167,6 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = _withdrawDiff(false, leftoverShares);
}

/// @notice Withdraw all balance of waTokens for aTokens, disables waToken
function withdrawAll()
external
override
creditFacadeOnly // U:[AAVE2W-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _withdrawDiff(false, 1); // U:[AAVE2W-8]
}

/// @notice Withdraw given amount of waTokens for underlying tokens
/// @param shares Amount of waTokens to burn in exchange for underlying tokens
function withdrawUnderlying(uint256 shares)
Expand All @@ -218,16 +188,6 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = _withdrawDiff(true, leftoverShares);
}

/// @notice Withdraw all balance of waTokens for underlying tokens, disables waToken
function withdrawAllUnderlying()
external
override
creditFacadeOnly // U:[AAVE2W-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _withdrawDiff(true, 1); // U:[AAVE2W-10]
}

/// @dev Internal implementation of `withdraw` and `withdrawUnderlying`
/// - waToken is not approved because it doesn't need permission to burn share tokens
/// - underlying / aToken is enabled after the call
Expand All @@ -240,7 +200,7 @@ contract AaveV2_WrappedATokenAdapter is AbstractAdapter, IAaveV2_WrappedATokenAd
(tokensToEnable, tokensToDisable) = (toUnderlying ? tokenMask : aTokenMask, 0); // U:[AAVE2W-7,9]
}

/// @dev Internal implementation of `withdrawAll`, `withdrawAllUnderlying`, `withdrawDiff` and `withdrawDiffUnderlying`
/// @dev Internal implementation of `withdrawDiff` and `withdrawDiffUnderlying`
/// - waToken is not approved because it doesn't need permission to burn share tokens
/// - underlying / aToken is enabled after the call
/// - waToken is disabled after the call because operation spends the entire balance
Expand Down
72 changes: 5 additions & 67 deletions contracts/adapters/balancer/BalancerV2VaultAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import {
ExitPoolRequest
} from "../../integrations/balancer/IBalancerV2Vault.sol";
import {
IBalancerV2VaultAdapter,
SingleSwapAll,
SingleSwapDiff,
PoolStatus
IBalancerV2VaultAdapter, SingleSwapDiff, PoolStatus
} from "../../interfaces/balancer/IBalancerV2VaultAdapter.sol";

/// @title Balancer V2 Vault adapter
Expand Down Expand Up @@ -119,36 +116,7 @@ contract BalancerV2VaultAdapter is AbstractAdapter, IBalancerV2VaultAdapter {
);
}

/// @notice Swaps the entire balance of a token for another token within a single pool, disables input token
/// @param singleSwapAll Struct containing swap parameters
/// * `poolId` - ID of the pool to perform a swap in
/// * `assetIn` - asset to send
/// * `assetOut` - asset to receive
/// * `userData` - additional generic blob used to pass extra data
/// @param limitRateRAY The minimal resulting exchange rate of assetOut to assetIn, scaled by 1e27
/// @param deadline The latest timestamp at which the swap would be executed
/// @dev The function reverts if the poolId status is not ALLOWED or SWAP_ONLY
function swapAll(SingleSwapAll memory singleSwapAll, uint256 limitRateRAY, uint256 deadline)
external
override
creditFacadeOnly // U:[BAL2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
address creditAccount = _creditAccount(); // U:[BAL2-4]

(tokensToEnable, tokensToDisable) = _swapDiffInternal(
creditAccount,
singleSwapAll.poolId,
singleSwapAll.assetIn,
singleSwapAll.assetOut,
1,
singleSwapAll.userData,
limitRateRAY,
deadline
); // F: [ABV2-2]
}

/// @dev Implementation for `swapDiff` and `swapAll`.
/// @dev Implementation for `swapDiff`.
function _swapDiffInternal(
address creditAccount,
bytes32 poolId,
Expand Down Expand Up @@ -324,22 +292,6 @@ contract BalancerV2VaultAdapter is AbstractAdapter, IBalancerV2VaultAdapter {
); // U:[BAL2-7]
}

/// @notice Deposits the entire balance of given asset as liquidity into a Balancer pool, disables said asset
/// @param poolId ID of the pool to deposit into
/// @param assetIn Asset to deposit
/// @param minRateRAY The minimal exchange rate of assetIn to BPT, scaled by 1e27
/// @dev The function reverts if poolId status is not ALLOWED
function joinPoolSingleAssetAll(bytes32 poolId, IAsset assetIn, uint256 minRateRAY)
external
override
creditFacadeOnly // U:[BAL2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
address creditAccount = _creditAccount();
(tokensToEnable, tokensToDisable) =
_joinPoolSingleAssetDiffInternal(creditAccount, poolId, assetIn, 1, minRateRAY); // F: [ABV2-6]
}

/// @notice Deposits the entire balance of given asset, except a specified amount, as liquidity into a Balancer pool
/// @param poolId ID of the pool to deposit into
/// @param assetIn Asset to deposit
Expand All @@ -357,7 +309,7 @@ contract BalancerV2VaultAdapter is AbstractAdapter, IBalancerV2VaultAdapter {
_joinPoolSingleAssetDiffInternal(creditAccount, poolId, assetIn, leftoverAmount, minRateRAY);
}

/// @dev Implementation for `joinPoolSingleAssetDiff` and `joinPoolSingleAssetAll`.
/// @dev Implementation for `joinPoolSingleAssetDiff`.
function _joinPoolSingleAssetDiffInternal(
address creditAccount,
bytes32 poolId,
Expand Down Expand Up @@ -494,20 +446,6 @@ contract BalancerV2VaultAdapter is AbstractAdapter, IBalancerV2VaultAdapter {
); // U:[BAL2-10]
}

/// @notice Withdraws all liquidity from a Balancer pool, burning BPT and receiving a single asset, disables BPT
/// @param poolId ID of the pool to withdraw from
/// @param assetOut Asset to withdraw
/// @param minRateRAY Minimal exchange rate of BPT to assetOut, scaled by 1e27
function exitPoolSingleAssetAll(bytes32 poolId, IAsset assetOut, uint256 minRateRAY)
external
override
creditFacadeOnly // U:[BAL2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
address creditAccount = _creditAccount();
(tokensToEnable, tokensToDisable) = _exitPoolSingleAssetDiff(creditAccount, poolId, assetOut, 1, minRateRAY); // U:[BAL2-11]
}

/// @notice Withdraws all liquidity from a Balancer pool except the specified amount, burning BPT and receiving a single asset
/// @param poolId ID of the pool to withdraw from
/// @param assetOut Asset to withdraw
Expand All @@ -521,10 +459,10 @@ contract BalancerV2VaultAdapter is AbstractAdapter, IBalancerV2VaultAdapter {
{
address creditAccount = _creditAccount();
(tokensToEnable, tokensToDisable) =
_exitPoolSingleAssetDiff(creditAccount, poolId, assetOut, leftoverAmount, minRateRAY); // F: [ABV2-9]
_exitPoolSingleAssetDiff(creditAccount, poolId, assetOut, leftoverAmount, minRateRAY);
}

/// @dev Implementation for `exitPoolSingleAssetDiff` and `exitPoolSingleAssetAll`.
/// @dev Implementation for `exitPoolSingleAssetDiff`.
function _exitPoolSingleAssetDiff(
address creditAccount,
bytes32 poolId,
Expand Down
26 changes: 1 addition & 25 deletions contracts/adapters/compound/CompoundV2_CTokenAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,6 @@ abstract contract CompoundV2_CTokenAdapter is AbstractAdapter, ICompoundV2_CToke
_revertOnError(error);
}

/// @notice Deposit all underlying tokens into Compound in exchange for cTokens, disables underlying
function mintAll()
external
override
creditFacadeOnly // U:[COMP2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
uint256 error;
(tokensToEnable, tokensToDisable, error) = _mintDiff(1); // U:[COMP2-5]
_revertOnError(error);
}

/// @dev Internal implementation of `mint`
/// Since minting process might be different for CErc20 and CEther,
/// it's up to deriving adapters to implement this function
Expand Down Expand Up @@ -117,18 +105,6 @@ abstract contract CompoundV2_CTokenAdapter is AbstractAdapter, ICompoundV2_CToke
_revertOnError(error);
}

/// @notice Withdraw all underlying tokens from Compound and burn cTokens, disables cToken
function redeemAll()
external
override
creditFacadeOnly // U:[COMP2-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
uint256 error;
(tokensToEnable, tokensToDisable, error) = _redeemDiff(1); // // U:[COMP2-7]
_revertOnError(error);
}

/// @dev Internal implementation of `redeem`
/// Since redeeming process might be different for CErc20 and CEther,
/// it's up to deriving adapters to implement this function
Expand All @@ -137,7 +113,7 @@ abstract contract CompoundV2_CTokenAdapter is AbstractAdapter, ICompoundV2_CToke
virtual
returns (uint256 tokensToEnable, uint256 tokensToDisable, uint256 error);

/// @dev Internal implementation of `redeemAll`
/// @dev Internal implementation of `redeemDeef`
/// Since redeeming process might be different for CErc20 and CEther,
/// it's up to deriving adapters to implement this function
function _redeemDiff(uint256 leftoverAmount)
Expand Down
34 changes: 3 additions & 31 deletions contracts/adapters/convex/ConvexV1_BaseRewardPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,7 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo
(tokensToEnable, tokensToDisable) = _stakeDiff(leftoverAmount);
}

/// @notice Stakes the entire balance of Convex LP token in the reward pool, disables LP token
function stakeAll() external override creditFacadeOnly returns (uint256 tokensToEnable, uint256 tokensToDisable) {
(tokensToEnable, tokensToDisable) = _stakeDiff(1);
}

/// @dev Internal implementation for `stakeDiff` and `stakeAll`.
/// @dev Internal implementation for `stakeDiff`.
function _stakeDiff(uint256 leftoverAmount) internal returns (uint256 tokensToEnable, uint256 tokensToDisable) {
address creditAccount = _creditAccount();

Expand Down Expand Up @@ -216,18 +211,7 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo
(tokensToEnable, tokensToDisable) = _withdrawDiff(leftoverAmount, claim);
}

/// @notice Withdraws the entire balance of Convex LP token from the reward pool, disables staked token
/// @param claim Whether to claim staking rewards
function withdrawAll(bool claim)
external
override
creditFacadeOnly // U:[CVX1R-3]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _withdrawDiff(1, claim);
}

/// @dev Internal implementation for `withdrawDiff` and `withdrawAll`.
/// @dev Internal implementation for `withdrawDiff`.
function _withdrawDiff(uint256 leftoverAmount, bool claim)
internal
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand Down Expand Up @@ -289,19 +273,7 @@ contract ConvexV1BaseRewardPoolAdapter is AbstractAdapter, IConvexV1BaseRewardPo
(tokensToEnable, tokensToDisable) = _withdrawDiffAndUnwrap(leftoverAmount, claim);
}

/// @notice Withdraws the entire balance of Convex LP token from the reward pool and unwraps it into Curve LP token,
/// disables staked token
/// @param claim Whether to claim staking rewards
function withdrawAllAndUnwrap(bool claim)
external
override
creditFacadeOnly // U:[CVX1R-3]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _withdrawDiffAndUnwrap(1, claim); // F: [ACVX1_P-9]
}

/// @dev Internal implementation for `withdrawDiffAndUnwrap` and `withdrawAllAndUnwrap`.
/// @dev Internal implementation for `withdrawDiffAndUnwrap`.
function _withdrawDiffAndUnwrap(uint256 leftoverAmount, bool claim)
internal
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand Down
27 changes: 2 additions & 25 deletions contracts/adapters/convex/ConvexV1_Booster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,7 @@ contract ConvexV1BoosterAdapter is AbstractAdapter, IConvexV1BoosterAdapter {
(tokensToEnable, tokensToDisable) = _depositDiff(leftoverAmount, _pid, _stake);
}

/// @notice Deposits the entire balance of Curve LP tokens into Booster, disables Curve LP token
/// @param _pid ID of the pool to deposit to
/// @param _stake Whether to stake Convex LP tokens in the rewards pool
function depositAll(uint256 _pid, bool _stake)
external
override
creditFacadeOnly // U:[CVX1B-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _depositDiff(1, _pid, _stake);
}

/// @dev Internal implementation for `depositAll` and `depositDiff`
/// @dev Internal implementation for `depositDiff`
function _depositDiff(uint256 leftoverAmount, uint256 _pid, bool _stake)
internal
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand Down Expand Up @@ -146,18 +134,7 @@ contract ConvexV1BoosterAdapter is AbstractAdapter, IConvexV1BoosterAdapter {
(tokensToEnable, tokensToDisable) = _withdrawDiff(leftoverAmount, _pid);
}

/// @notice Withdraws all Curve LP tokens from Booster, disables Convex LP token
/// @param _pid ID of the pool to withdraw from
function withdrawAll(uint256 _pid)
external
override
creditFacadeOnly // U:[CVX1B-2]
returns (uint256 tokensToEnable, uint256 tokensToDisable)
{
(tokensToEnable, tokensToDisable) = _withdrawDiff(1, _pid);
}

/// @dev Internal implementation for `withdrawAll` and `withdrawDiff`
/// @dev Internal implementation for `withdrawDiff`
function _withdrawDiff(uint256 leftoverAmount, uint256 _pid)
internal
returns (uint256 tokensToEnable, uint256 tokensToDisable)
Expand Down
Loading

0 comments on commit f4e4cef

Please sign in to comment.