diff --git a/README.md b/README.md index e988f58..6abd473 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Zap +# Zap Flashloan Utility [![Github Actions][gha-badge]][gha] [![Foundry][foundry-badge]][foundry] @@ -11,63 +11,55 @@ [license]: https://opensource.org/license/GPL-3.0/ [license-badge]: https://img.shields.io/badge/GitHub-GPL--3.0-informational -## Aave Flashloans +## Overview -Execution Flow -For developers, a helpful mental model to consider when developing your solution: -Your contract calls the Pool contract, requesting a Flash Loan of a certain amount(s) of reserve(s) using flashLoanSimple() or flashLoan(). -After some sanity checks, the Pool transfers the requested amounts of the reserves to your contract, then calls executeOperation() on receiver contract . -Your contract, now holding the flash loaned amount(s), executes any arbitrary operation in its code. -If you are performing a flashLoanSimple, then when your code has finished, you approve Pool for flash loaned amount + fee. -If you are performing flashLoan, then for all the reserves either depending on interestRateMode passed for the asset, either the Pool must be approved for flash loaned amount + fee or must or sufficient collateral or credit delegation should be available to open debt position. -If the amount owing is not available (due to a lack of balance or approval or insufficient collateral for debt), then the transaction is reverted. -All of the above happens in 1 transaction (hence in a single ethereum block). +Zap is a smart contract that facilitates stablecoin "zapping" and Synthetix native collateral unwinding by integrating flash loans from Aave and Uniswap v3 swaps. -The flash loan fee is initialized at deployment to 0.05% and can be updated via Governance Vote. Use FLASHLOAN_PREMIUM_TOTAL to get current value. -Flashloan fee can be shared by the LPs (liquidity providers) and the protocol treasury. The FLASHLOAN_PREMIUM_TOTAL represents the total fee paid by the borrowers of which: -Fee to LP: FLASHLOAN_PREMIUM_TOTAL - FLASHLOAN_PREMIUM_TO_PROTOCOL -Fee to Protocol: FLASHLOAN_PREMIUM_TO_PROTOCOL +### What is a **Zap**? +> ONLY USDC is supported -The pool.sol contract is the main user facing contract of the protocol. It exposes the liquidity management methods that can be invoked using either Solidity or Web3 libraries. +USDC <--(spot market)--> sUSDC <--(spot market)--> USDx -flashLoanSimple -function flashLoanSimple( address receiverAddress, address asset, uint256 amount, bytes calldata params, uint16 referralCode) -Allows users to access liquidity of one reserve or one transaction as long as the amount taken plus fee is returned. +### What is **Collateral Unwinding**? -## Tests +#### Flashloan Utility Flow -1. Follow the [Foundry guide to working on an existing project](https://book.getfoundry.sh/projects/working-on-an-existing-project.html) +1. **Request Flash Loans (Aave):** Borrow USDC to access liquidity without posting collateral. +2. **Zap into USDx (Synthetix Spot Market):** Use the borrowed funds to zap into USDx. +3. **Burn USDx & Repay Debt (Synthetix Core):** Repay Synthetix debt by burning USDx. +4. **Withdraw and Unwrap Collateral (Synthetix Spot Market):** Withdraw margin (e.g., sETH) and convert it back to underlying assets (e.g., WETH). +5. **Swap (Uniswap):** Exchange collateral assets (like WETH) for USDC to repay the flash loan. +6. **Flash Loan Repayment (Aave):** The USDC loan, including the premium, is repaid to Aave. +7. **Send Remaining Collateral (Synthetix):** Any surplus collateral is returned to the user. -2. Build project +## Key Features -``` -npm run compile -``` +- Zap via Synthetix +- Wrap & Unwrap Collateral via Synthetix +- Buy & Sell via Synthetix +- Unwind Collateral via Synthetix, Aave, and Uniswap +- Burn Debt via Synthetix +- Withdraw Perp Collateral via Synthetix +- Swap via Uniswap -3. Execute tests (requires rpc url(s) to be set in `.env`) +## Build and Test -``` -npm run test -``` +### Build and Run -4. Run specific test +1. **Build the project** + ```bash + forge build + ``` -``` -forge test --fork-url $(grep BASE_RPC_URL .env | cut -d '=' -f2) --match-test TEST_NAME -vvv -``` +2. **Run tests** + ```bash + forge test + ``` -## Deployment Addresses +## Deployment -> See `deployments/` folder - -1. Optimism deployments found in `deployments/Optimism.json` -2. Optimism Goerli deployments found in `deployments/OptimismGoerli.json` -3. Base deployments found in `deployments/Base.json` -4. Base Goerli deployments found in `deployments/BaseGoerli.json` +- See the `deployments/` folder for Arbitrum and Base deployments. ## Audits -> See `audits/` folder - -1. Internal audits found in `audits/internal/` -2. External audits found in `audits/external/` \ No newline at end of file +- See the `audits/` folder for Audit reports.