Skip to content

Commit

Permalink
fix: move common function to base contract (#13)
Browse files Browse the repository at this point in the history
* fix: move common function to base contract

* fix: make allowance function internal

* remove redundant function
  • Loading branch information
parth-15 authored Mar 7, 2024
1 parent ac087c4 commit cb77b7f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 54 deletions.
13 changes: 13 additions & 0 deletions src/contracts/base/BaseParaSwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,17 @@ abstract contract BaseParaSwapAdapter is Ownable, IBaseParaSwapAdapter {
POOL.withdraw(reserve, aTokenBalanceDiff, address(this));
return aTokenBalanceDiff;
}

/**
* @dev Renews the asset allowance in case the current allowance is below a given threshold
* @param asset The address of the asset
* @param minAmount The minimum required allowance to the Aave Pool
*/
function _conditionalRenewAllowance(address asset, uint256 minAmount) internal {
uint256 allowance = IERC20(asset).allowance(address(this), address(POOL));
if (allowance < minAmount) {
IERC20(asset).safeApprove(address(POOL), 0);
IERC20(asset).safeApprove(address(POOL), type(uint256).max);
}
}
}
12 changes: 0 additions & 12 deletions src/contracts/base/ParaSwapDebtSwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ abstract contract ParaSwapDebtSwapAdapter is
}
}

function renewAllowance(address reserve) public {
IERC20WithPermit(reserve).safeApprove(address(POOL), 0);
IERC20WithPermit(reserve).safeApprove(address(POOL), type(uint256).max);
}

/**
* @dev Swaps one type of debt to another. Therefore this methods performs the following actions in order:
* 1. Delegate credit in new debt
Expand Down Expand Up @@ -235,11 +230,4 @@ abstract contract ParaSwapDebtSwapAdapter is
);
return amountSold;
}

function _conditionalRenewAllowance(address asset, uint256 minAmount) internal {
uint256 allowance = IERC20(asset).allowance(address(this), address(POOL));
if (allowance < minAmount) {
renewAllowance(asset);
}
}
}
21 changes: 0 additions & 21 deletions src/contracts/base/ParaSwapLiquiditySwapAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ abstract contract ParaSwapLiquiditySwapAdapter is
}
}

/**
* @notice Renews the asset allowance to the Aave Pool
* @param reserve The address of the asset
*/
function renewAllowance(address reserve) public {
IERC20(reserve).safeApprove(address(POOL), 0);
IERC20(reserve).safeApprove(address(POOL), type(uint256).max);
}

/// @inheritdoc IParaSwapLiquiditySwapAdapter
function swapLiquidity(
LiquiditySwapParams memory liquiditySwapParams,
Expand Down Expand Up @@ -191,18 +182,6 @@ abstract contract ParaSwapLiquiditySwapAdapter is
return amountReceived;
}

/**
* @dev Renews the asset allowance in case the current allowance is below a given threshold
* @param asset The address of the asset
* @param minAmount The minimum required allowance to the Aave Pool
*/
function _conditionalRenewAllowance(address asset, uint256 minAmount) internal {
uint256 allowance = IERC20(asset).allowance(address(this), address(POOL));
if (allowance < minAmount) {
renewAllowance(asset);
}
}

/**
* @dev Triggers the flashloan passing encoded params for the collateral swap
* @param liquiditySwapParams struct describing the liquidity swap
Expand Down
21 changes: 0 additions & 21 deletions src/contracts/base/ParaSwapRepayAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@ abstract contract ParaSwapRepayAdapter is
}
}

/**
* @notice Renews the asset allowance to the Aave Pool
* @param reserve The address of the asset
*/
function renewAllowance(address reserve) public {
IERC20(reserve).safeApprove(address(POOL), 0);
IERC20(reserve).safeApprove(address(POOL), type(uint256).max);
}

/// @inheritdoc IParaSwapRepayAdapter
function repayWithCollateral(
RepayParams memory repayParams,
Expand Down Expand Up @@ -240,18 +231,6 @@ abstract contract ParaSwapRepayAdapter is
);
}

/**
* @dev Renews the asset allowance in case the current allowance is below a given threshold
* @param asset The address of the asset
* @param minAmount The minimum required allowance to the Aave Pool
*/
function _conditionalRenewAllowance(address asset, uint256 minAmount) internal {
uint256 allowance = IERC20(asset).allowance(address(this), address(POOL));
if (allowance < minAmount) {
renewAllowance(asset);
}
}

/**
* @dev Returns the amount of debt to repay for the user
* @param debtAsset The address of the asset to repay the debt
Expand Down

0 comments on commit cb77b7f

Please sign in to comment.