From c345e527366f11e48cb597ae24a44a8a54b3becf Mon Sep 17 00:00:00 2001 From: Sahil-Gujrati Date: Sat, 23 Mar 2024 13:16:01 +0530 Subject: [PATCH] docs: Update docs --- docs/src/README.md | 177 +++++++++++++++++- .../contract.LiquidityProviderToken.md | 2 +- .../contract.ThunderSwapPool.md | 2 +- .../contract.ThunderSwapPoolFactory.md | 67 ++++++- .../interface.IThunderSwapPool.md | 2 +- .../interface.IThunderSwapReceiver.md | 13 +- 6 files changed, 256 insertions(+), 7 deletions(-) diff --git a/docs/src/README.md b/docs/src/README.md index ba9b86c..804f4a3 100644 --- a/docs/src/README.md +++ b/docs/src/README.md @@ -1,3 +1,176 @@ -# Start of an amazing new project! + -I'll be updating the README soon! \ No newline at end of file + + + +[![Contributors][contributors-shield]][contributors-url] +[![Forks][forks-shield]][forks-url] +[![Stargazers][stars-shield]][stars-url] +[![Issues][issues-shield]][issues-url] +[![MIT License][license-shield]][license-url] +[![LinkedIn][linkedin-shield]][linkedin-url] + + + +
+
+

Thunder Swap

+ +

+ A decentralized exchange and flash swapping protocol +
+ Explore the docs » +
+ Report Bug + · + Request Feature +

+
+ + + +
+ Table of Contents +
    +
  1. + About The Project + +
  2. +
  3. + Getting Started + +
  4. +
  5. Roadmap
  6. +
  7. Contributing
  8. +
  9. License
  10. +
  11. Contact
  12. +
+
+ + + +## About The Project + +Thunder Swap is a decentralized exchange protocol that also supports flash swaps. A flash swap allows you to get a certain amount of a type of token within the pool as loan, and swap it for a certain amount of the other type of token in the pool, plus some minimal fee. + +A thunder swap pool factory is deployed on-chain, and users can interact with it to deploy thunder swap pools for supported tokens (set by the deployer). Liquidity providers can supply pools with liquidity (using the `ThunderSwapPool::addLiquidity()` function) and earn fees (0.3%) on each swap. Each liquidity provider is minted LP (Liquidity Provider) tokens representing the portion of the pool they own. At any time, liquidity providers can exit the protocol by withdrawing their liquidity (using the `ThunderSwapPool::withdrawLiquidity()` function, which burns LP tokens) along with any accrued fees. + +Both normal swaps and flash swaps take place using the `ThunderSwapPool::flashSwapExactInput()` and `ThunderSwapPool::flashSwapExactOutput()` functions. In a normal swap, the `receiver` address is the user's wallet address; however, in a flash swap, a user sets the `receiver` address as the contract address (which implements the `IThunderSwapReceiver` interface). The contract that receives the token loan has to ensure that enough tokens are approved to the `ThunderSwapPool` when the control returns to it and the loan is paid back (along with fees). + + +### Built With + +- ![Foundry](https://img.shields.io/badge/-FOUNDRY-%23323330.svg?style=for-the-badge) +- ![Solidity](https://img.shields.io/badge/Solidity-%23363636.svg?style=for-the-badge&logo=solidity&logoColor=white) +- ![NPM](https://img.shields.io/badge/NPM-%23CB3837.svg?style=for-the-badge&logo=npm&logoColor=white) + + + +## Getting Started + +To get a local copy up and running follow these simple steps. + +### Prerequisites + +Ensure that you have the Foundry framework installed on your system. You can get the installation instructions [here](https://book.getfoundry.sh/getting-started/installation). +Also, you'll need pnpm and make installed and configured on your system. + +### Installation + +Clone the repo + +```shell +git clone https://github.com/mgnfy-view/thunder-swap +``` + +cd into the repo, and install the necessary dependencies + +```shell +cd thunder-swap +make install +pnpm intall +``` + +That's it, you are good to go now! + + + +## Roadmap + +- [x] Smart contract development +- [ ] Testing + - [x] Unit testing + - [ ] Fuzz testing +- [ ] UI development + +See the [open issues](https://github.com/mgnfy-view/thunder-swap/issues) for a full list of proposed features (and known issues). + + + +## Contributing + +Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**. + +If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". +Don't forget to give the project a star! Thanks again! + +1. Fork the Project +2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`) +3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`) +4. Push to the Branch (`git push origin feature/AmazingFeature`) +5. Open a Pull Request + + + +## License + +Distributed under the MIT License. See `LICENSE.txt` for more information. + + + +## Contact + +Sahil Gujrati - [@https://twitter.com/mgnfy_view](https://twitter.com/https://twitter.com/mgnfy_view) - sahilgujrati12@gmail.com + +Project Link: [https://github.com/mgnfy-view/thunder-swap](https://github.com/mgnfy-view/thunder-swap) + + + + + + + + +[contributors-shield]: https://img.shields.io/github/contributors/mgnfy-view/thunder-swap.svg?style=for-the-badge +[contributors-url]: https://github.com/mgnfy-view/thunder-swap/graphs/contributors +[forks-shield]: https://img.shields.io/github/forks/mgnfy-view/thunder-swap.svg?style=for-the-badge +[forks-url]: https://github.com/mgnfy-view/thunder-swap/network/members +[stars-shield]: https://img.shields.io/github/stars/mgnfy-view/thunder-swap.svg?style=for-the-badge +[stars-url]: https://github.com/mgnfy-view/thunder-swap/stargazers +[issues-shield]: https://img.shields.io/github/issues/mgnfy-view/thunder-swap.svg?style=for-the-badge +[issues-url]: https://github.com/mgnfy-view/thunder-swap/issues +[license-shield]: https://img.shields.io/github/license/mgnfy-view/thunder-swap.svg?style=for-the-badge +[license-url]: https://github.com/mgnfy-view/thunder-swap/blob/main/LICENSE.txt +[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 +[linkedin-url]: https://linkedin.com/in/sahil-gujrati-125ab0284 \ No newline at end of file diff --git a/docs/src/src/LiquidityProviderToken.sol/contract.LiquidityProviderToken.md b/docs/src/src/LiquidityProviderToken.sol/contract.LiquidityProviderToken.md index a6348e8..88f0ab4 100644 --- a/docs/src/src/LiquidityProviderToken.sol/contract.LiquidityProviderToken.md +++ b/docs/src/src/LiquidityProviderToken.sol/contract.LiquidityProviderToken.md @@ -1,5 +1,5 @@ # LiquidityProviderToken -[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/997ceda25caa399aceddccd5cec1898cfe55e38c/src/LiquidityProviderToken.sol) +[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/3fd7cb494e239f3a5cfc07b6750a10fc84968ecc/src/LiquidityProviderToken.sol) **Inherits:** ERC20, Ownable diff --git a/docs/src/src/ThunderSwapPool.sol/contract.ThunderSwapPool.md b/docs/src/src/ThunderSwapPool.sol/contract.ThunderSwapPool.md index 6fb4456..863ff55 100644 --- a/docs/src/src/ThunderSwapPool.sol/contract.ThunderSwapPool.md +++ b/docs/src/src/ThunderSwapPool.sol/contract.ThunderSwapPool.md @@ -1,5 +1,5 @@ # ThunderSwapPool -[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/997ceda25caa399aceddccd5cec1898cfe55e38c/src/ThunderSwapPool.sol) +[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/3fd7cb494e239f3a5cfc07b6750a10fc84968ecc/src/ThunderSwapPool.sol) **Inherits:** [IThunderSwapPool](/src/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md) diff --git a/docs/src/src/ThunderSwapPoolFactory.sol/contract.ThunderSwapPoolFactory.md b/docs/src/src/ThunderSwapPoolFactory.sol/contract.ThunderSwapPoolFactory.md index 3874fe6..8733b7b 100644 --- a/docs/src/src/ThunderSwapPoolFactory.sol/contract.ThunderSwapPoolFactory.md +++ b/docs/src/src/ThunderSwapPoolFactory.sol/contract.ThunderSwapPoolFactory.md @@ -1,5 +1,5 @@ # ThunderSwapPoolFactory -[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/997ceda25caa399aceddccd5cec1898cfe55e38c/src/ThunderSwapPoolFactory.sol) +[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/3fd7cb494e239f3a5cfc07b6750a10fc84968ecc/src/ThunderSwapPoolFactory.sol) **Inherits:** Ownable @@ -37,13 +37,23 @@ constructor() Ownable(msg.sender); ### setSupportedToken +Adds tokens for which a thunder swap pool can be deployed + ```solidity function setSupportedToken(address _token) external onlyOwner; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_token`|`address`|The token to support| + ### deployThunderSwapPool +Deploys a thunder swap pool for the two specified supported tokens + ```solidity function deployThunderSwapPool( @@ -53,27 +63,82 @@ function deployThunderSwapPool( external returns (ThunderSwapPool); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_token1`|`address`|Pool token 1| +|`_token2`|`address`|Pool token 2| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`ThunderSwapPool`|The deployed thunder swap pool| + ### isTokenSupported +Checks if the token is supported + ```solidity function isTokenSupported(address _token) public view returns (bool); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_token`|`address`|The token to check| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`bool`|A bool indicating if the token is supported or not| + ### getPoolFromToken +Gets the thunder swap pool for the specified token + ```solidity function getPoolFromToken(address _token) external view returns (address); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_token`|`address`|The token to find a pool for| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address`|The thunder swap pool address for the given token| + ### getPoolTokens +Gets the pool tokens supported by a specified pool + ```solidity function getPoolTokens(address _pool) external view returns (address[] memory); ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_pool`|`address`|The thunder swap pool| + +**Returns** + +|Name|Type|Description| +|----|----|-----------| +|``|`address[]`|An array of the pool tokens supported by the thunder swap pool| + ## Events ### PoolCreated diff --git a/docs/src/src/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md b/docs/src/src/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md index bd51bee..7113729 100644 --- a/docs/src/src/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md +++ b/docs/src/src/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md @@ -1,5 +1,5 @@ # IThunderSwapPool -[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/997ceda25caa399aceddccd5cec1898cfe55e38c/src/interfaces/IThunderSwapPool.sol) +[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/3fd7cb494e239f3a5cfc07b6750a10fc84968ecc/src/interfaces/IThunderSwapPool.sol) ## Functions diff --git a/docs/src/src/interfaces/IThunderSwapReceiver.sol/interface.IThunderSwapReceiver.md b/docs/src/src/interfaces/IThunderSwapReceiver.sol/interface.IThunderSwapReceiver.md index 41d9292..f70d651 100644 --- a/docs/src/src/interfaces/IThunderSwapReceiver.sol/interface.IThunderSwapReceiver.md +++ b/docs/src/src/interfaces/IThunderSwapReceiver.sol/interface.IThunderSwapReceiver.md @@ -1,10 +1,12 @@ # IThunderSwapReceiver -[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/997ceda25caa399aceddccd5cec1898cfe55e38c/src/interfaces/IThunderSwapReceiver.sol) +[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/3fd7cb494e239f3a5cfc07b6750a10fc84968ecc/src/interfaces/IThunderSwapReceiver.sol) ## Functions ### onThunderSwapReceived +This function is invoked on each flash swap if `_callContract` was set to true + ```solidity function onThunderSwapReceived( @@ -15,4 +17,13 @@ function onThunderSwapReceived( ) external; ``` +**Parameters** + +|Name|Type|Description| +|----|----|-----------| +|`_inputToken`|`IERC20`|The input token| +|`_inputAmount`|`uint256`|The input token amount| +|`_outputToken`|`IERC20`|The output token| +|`_outputAmount`|`uint256`|The output token amount| +