Instead of requiring users to have assets readily available to repay their loans, flash loans enable them to temporarily borrow the needed funds, use those funds to repay their debt, and immediately reclaim their locked collateral. Once the collateral is received, it can be swapped or liquidated to cover the borrowed amount, ensuring the loan is repaid within the same transaction. This approach eliminates the need for users to preemptively sell assets or find external liquidity, making it a highly flexible and efficient way to manage debt positions.Documentation Index
Fetch the complete documentation index at: https://cowswap-mintlify-docs-quality-audit-1774257282.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
How to pay back a debt with collateral
This can be achieved using a buy order where:- The buy token is the flash loaned asset that needs to be repaid.
- The buy amount is the exact amount needed to repay the flash loan (it must be sufficient to complete the transaction; otherwise, the transaction will revert!).
- The sell token is the asset used as collateral.
- The sell amount is the full collateral amount.
Lender allows a third-party to initiate the transfer of collateral tokens
In this case, the user can sign a pre-hook that deploys a COWShed to repay the debt using flash-loaned tokens.COWShed is a user owned ERC-1967 proxy deployed at a deterministic address. This deterministic deployment allows users to set the proxy address as the receiver for cowswap orders with pre/post-hooks. The user signs a EIP-712 message for the pre/post-hooks which gets validated. Only user signed hooks are executed on the user’s proxy. This allows users to confidently perform permissioned actions in the hooks such as:
- transferring assets from the proxy to someone else.
- use the proxy to add collateral or repay debt on a maker CDP or an AAVE debt position, etc.
COWShed, the user can use the COWShed SDK.
The underlying user order is only used to repay the required flash loan. Since the repayment is handled via COWShed, the user can be either an EOA (Externally Owned Account) or a contract (e.g., a SAFE wallet).