Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings #34

Merged
merged 4 commits into from Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions contracts/compound/WidoCollateralSwap_Aave.sol
Expand Up @@ -13,6 +13,10 @@ import {LibCollateralSwap} from "./libraries/LibCollateralSwap.sol";
import {IWidoCollateralSwap} from "./interfaces/IWidoCollateralSwap.sol";
import {WidoRouter} from "../core/WidoRouter.sol";

/// @title WidoCollateralSwap_Aave
/// @notice Contract allows swapping Compound collateral from one token (TokenA) to the other (TokenB) without
/// closing the borrowing position. The contract makes use of flash loans to first supply TokenB,
/// then withdraws TokenA and swaps it for TokenB and closes the flash loan.
contract WidoCollateralSwap_Aave is IFlashLoanSimpleReceiver, IWidoCollateralSwap, ReentrancyGuard {
using SafeMath for uint256;

Expand Down Expand Up @@ -42,7 +46,7 @@ contract WidoCollateralSwap_Aave is IFlashLoanSimpleReceiver, IWidoCollateralSwa
WIDO_TOKEN_MANAGER = address(WidoRouter(_widoRouter).widoTokenManager());
}

/// @notice Performs a collateral swap with Aave
/// @notice Performs a Compound collateral swap using flash loan from Aave.
/// @param existingCollateral The collateral currently locked in the Comet contract
/// @param finalCollateral The final collateral desired collateral
/// @param sigs The required signatures to allow and revoke permission to this contract
Expand Down Expand Up @@ -70,13 +74,13 @@ contract WidoCollateralSwap_Aave is IFlashLoanSimpleReceiver, IWidoCollateralSwa
);
}

/// @notice Executes an operation after receiving the flash-borrowed asset
/// @notice Executes the collateral swap after receiving the flash-borrowed asset
/// @dev Ensure that the contract can return the debt + premium, e.g., has
/// enough funds to repay and has approved the Pool to pull the total amount
/// @param asset The address of the flash-borrowed asset
/// @param amount The amount of the flash-borrowed asset
/// @param premium The fee of the flash-borrowed asset
/// @param params The byte-encoded params passed when initiating the flashloan
/// @param params The byte-encoded params for the collateral swap passed when initiating the flashloan
/// @return True if the execution of the operation succeeds, false otherwise
function executeOperation(
address asset,
Expand Down
16 changes: 13 additions & 3 deletions contracts/compound/WidoCollateralSwap_ERC3156.sol
Expand Up @@ -11,6 +11,10 @@ import {LibCollateralSwap} from "./libraries/LibCollateralSwap.sol";
import {IWidoCollateralSwap} from "./interfaces/IWidoCollateralSwap.sol";
import {WidoRouter} from "../core/WidoRouter.sol";

/// @title WidoCollateralSwap_ERC3156
/// @notice Contract allows swapping Compound collateral from one token (TokenA) to the other (TokenB) without
/// closing the borrowing position. The contract makes use of flash loans to first supply TokenB,
/// then withdraws TokenA and swaps it for TokenB and closes the flash loan.
contract WidoCollateralSwap_ERC3156 is IERC3156FlashBorrower, IWidoCollateralSwap, ReentrancyGuard {
using SafeMath for uint256;

Expand Down Expand Up @@ -39,7 +43,7 @@ contract WidoCollateralSwap_ERC3156 is IERC3156FlashBorrower, IWidoCollateralSwa
WIDO_TOKEN_MANAGER = address(WidoRouter(_widoRouter).widoTokenManager());
}

/// @notice Performs a collateral swap
/// @notice Performs a Compound collateral swap using an ERC3156 compliant flash loan provider.
/// @param existingCollateral The collateral currently locked in the Comet contract
/// @param finalCollateral The final collateral desired collateral
/// @param sigs The required signatures to allow and revoke permission to this contract
Expand All @@ -66,8 +70,14 @@ contract WidoCollateralSwap_ERC3156 is IERC3156FlashBorrower, IWidoCollateralSwa
);
}

/// @notice Callback to be executed by the flash loan provider
/// @dev Only allow-listed providers should have access
/// @notice Executes the collateral swap after receiving the flash-borrowed asset
/// @dev This function is the callback executed by the flash loan provider after loan disbursement.
/// Only allowed providers can initiate the callback.
/// @param borrowedAsset The address of the asset that has been borrowed.
/// @param borrowedAmount The amount of the asset that has been borrowed.
/// @param fee The fee associated with the borrowed asset.
/// @param params The byte-encoded params for the collateral swap passed when initiating the flashloan
/// @return Returns the standard flash loan response of the callback function.
function onFlashLoan(
address initiator,
address borrowedAsset,
Expand Down
12 changes: 9 additions & 3 deletions contracts/compound/libraries/LibCollateralSwap.sol
Expand Up @@ -6,6 +6,8 @@ import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol";
import {SafeMath} from "@openzeppelin/contracts/utils/math/SafeMath.sol";
import {IComet} from "../interfaces/IComet.sol";

/// @title LibCollateralSwap Library
/// @notice Helper functions to swap collateral assets on Compound V3.
library LibCollateralSwap {
using SafeMath for uint256;

Expand Down Expand Up @@ -34,7 +36,11 @@ library LibCollateralSwap {
bytes callData;
}

/// @dev Performs all the steps to swap collaterals on the Comet contract
/// @dev Performs supply, withdraw and swap steps to swap collaterals on the Comet contract
/// @param borrowedAsset The address of the asset that has been borrowed.
/// @param borrowedAmount The amount of the asset that has been borrowed.
/// @param fee The fee associated with the borrowed asset.
/// @param data The encoded payload containing details required for the swap.
function performCollateralSwap(
address borrowedAsset,
uint256 borrowedAmount,
Expand Down Expand Up @@ -113,8 +119,8 @@ library LibCollateralSwap {
}

/// @dev This function withdraws the collateral from the user.
/// It requires two consecutive EIP712 signatures to allow and revoke
/// permissions to and from this contract.
/// It requires two consecutive EIP712 signatures to allow and revoke
/// permissions to and from this contract.
function _withdrawFrom(
IComet comet,
address user,
Expand Down