Skip to content

Commit

Permalink
docs: Make minor changes to NatSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
mgnfy-view committed Apr 3, 2024
1 parent c3f6828 commit 0378f06
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 50 deletions.
6 changes: 2 additions & 4 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@

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.
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 and earn a fees of 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 burning these LP tokens, which allows them to withdraw their liquidity 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).
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's address (which is `IThunderSwapReceiver` interface compliant). 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). With flash swaps, contracts can also activate hooks before and after a swap to fine tune their swapping strategy.


### Built With
Expand Down Expand Up @@ -149,8 +149,6 @@ Distributed under the MIT License. See `LICENSE.txt` for more information.

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)


<!-- ACKNOWLEDGMENTS -->
<!-- ## Acknowledgments
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IThunderSwapHooks
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/ThunderSwapReceiver/interfaces/IThunderSwapHooks.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/ThunderSwapReceiver/interfaces/IThunderSwapHooks.sol)


## Functions
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# IThunderSwapReceiver
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/ThunderSwapReceiver/interfaces/IThunderSwapReceiver.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/ThunderSwapReceiver/interfaces/IThunderSwapReceiver.sol)

**Inherits:**
[IThunderSwapHooks](/src/ThunderSwapReceiver/interfaces/IThunderSwapHooks.sol/interface.IThunderSwapHooks.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
# LiquidityProviderToken
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/core/LiquidityProviderToken.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/core/LiquidityProviderToken.sol)

**Inherits:**
ERC20, Ownable

**Author:**
mgnfy-view

This is the ERC20 token that each `ThunderSwaPool` uses to keep track of the liquidity
supplied by LPs


## Functions
### constructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ThunderSwapPool
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/core/ThunderSwapPool.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/core/ThunderSwapPool.sol)

**Inherits:**
[IThunderSwapPool](/src/core/interfaces/IThunderSwapPool.sol/interface.IThunderSwapPool.md), ReentrancyGuard
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ThunderSwapPoolFactory
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/core/ThunderSwapPoolFactory.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/core/ThunderSwapPoolFactory.sol)

**Inherits:**
Ownable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
# IThunderSwapPool
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/65d96eb516be89fd9526025068582cb68137dd6f/src/core/interfaces/IThunderSwapPool.sol)
[Git Source](https://github.com/Sahil-Gujrati/thunder-swap/blob/c3f6828c24263ecffb75bfebcd4e5ebc1eba6dc4/src/core/interfaces/IThunderSwapPool.sol)


## Functions
### addLiquidity

Allows users to become liquidity providers by supplying the protocol with liquidity

*Pool token 2 to supply is calculated based on pool token 1 amount. However, at inception
the first LP can decide on the ratio of his/her deposit*


```solidity
function addLiquidity(
uint256 _poolToken1Amount,
uint256 _poolToken2Amount,
uint256 _maximumPoolToken2ToDeposit,
uint256 _minimumLPTokensToMint,
uint256 _minimumLiquidityProviderTokensToMint,
uint256 _deadline
)
external;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`_poolToken1Amount`|`uint256`|The amount of pool token 1 to add as liquidity|
|`_poolToken2Amount`|`uint256`|The amount of pool token 2 to add as liquidity|
|`_maximumPoolToken2ToDeposit`|`uint256`|(slippage protection) The maximum amount of pool token 2 to deposit based on pool token 1 amount|
|`_minimumLiquidityProviderTokensToMint`|`uint256`|(slippage protection) The minimum share of the pool the liquidity provider is expecting to own|
|`_deadline`|`uint256`|Deadline before which the liquidity should be added|


### withdrawLiquidity

Allows liquidity providers to exit the protocol by withdrawing their deposited liquidity


```solidity
function withdrawLiquidity(
Expand All @@ -29,9 +46,20 @@ function withdrawLiquidity(
)
external;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`_liquidityProviderTokensToBurn`|`uint256`|The amount of LP tokens the LP wants to burn to claim his/her liquidity|
|`_minimumPoolToken1ToWithdraw`|`uint256`|(slippage protection) The minimum pool token 1 amount the LP is expecting to withdraw|
|`_minimumPoolToken2ToWithdraw`|`uint256`|(slippage protection) The minimum pool token 2 amount the LP is expecting to withdraw|
|`_deadline`|`uint256`|Deadline before which the liquidity should be withdrawn|


### flashSwapExactInput

Flash swaps exact amount of input token for output token


```solidity
function flashSwapExactInput(
Expand All @@ -46,9 +74,24 @@ function flashSwapExactInput(
)
external;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`_inputToken`|`IERC20`|The input token (supported by the pool)|
|`_inputAmount`|`uint256`|The amount of input token to send|
|`_minimumOutputTokenToReceive`|`uint256`|(slippage protection) The minimum amount of output token to receive|
|`_receiver`|`address`|Receiver of the output token amount (contract, or a wallet)|
|`_callContract`|`bool`|If true, call the `onThunderSwapReceived()` function on the receiver contract|
|`_callBeforeHook`|`bool`|if true, calls the `beforeThunderSwapReceived` hook on the receiver contract|
|`_callAfterHook`|`bool`|if true, calls the `afterThunderSwapReceived` hook on the receiver contract|
|`_deadline`|`uint256`|Deadline before which the flash swap should occur|


### flashSwapExactOutput

Flash swaps a certain amount of input token for an exact amount of output token


```solidity
function flashSwapExactOutput(
Expand All @@ -63,4 +106,17 @@ function flashSwapExactOutput(
)
external;
```
**Parameters**

|Name|Type|Description|
|----|----|-----------|
|`_outputToken`|`IERC20`|The output token (supported by the pool)|
|`_outputAmount`|`uint256`|The amount of output token to receive|
|`_maximumInputTokensToSend`|`uint256`|(slippage protection) The maximum amount of input token to send|
|`_receiver`|`address`|Receiver of the output token amount (contract, or a wallet)|
|`_callContract`|`bool`|If true, call the `onThunderSwapReceived()` function on the receiver contract|
|`_callBeforeHook`|`bool`|if true, calls the `beforeThunderSwapReceived` hook on the receiver contract|
|`_callAfterHook`|`bool`|if true, calls the `afterThunderSwapReceived` hook on the receiver contract|
|`_deadline`|`uint256`|Deadline before which the flash swap should occur|


6 changes: 6 additions & 0 deletions src/core/LiquidityProviderToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ pragma solidity 0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";

/**
* @title The token to keep track of the shares of the pool held by LPs
* @author mgnfy-view
* @notice This is the ERC20 token that each `ThunderSwaPool` uses to keep track of the liquidity
* supplied by LPs
*/
contract LiquidityProviderToken is ERC20, Ownable {
constructor(
string memory _name,
Expand Down
42 changes: 4 additions & 38 deletions src/core/ThunderSwapPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,7 @@ contract ThunderSwapPool is IThunderSwapPool, ReentrancyGuard {
}

/**
* @notice Allows users to become liquidity providers by supplying the protocol with liquidity
* @dev Pool token 2 to supply is calculated based on pool token 1 amount. However, at inception
* the first LP can decide on the ratio of his/her deposit
* @param _poolToken1Amount The amount of pool token 1 to add as liquidity
* @param _poolToken2Amount The amount of pool token 2 to add as liquidity
* @param _maximumPoolToken2ToDeposit (slippage protection) The maximum amount of pool token 2 to deposit
* based on pool token 1 amount
* @param _minimumLiquidityProviderTokensToMint (slippage protection) The minimum share of the pool the
* liquidity provider is expecting to own
* @param _deadline Deadline before which the liquidity should be added
* @inheritdoc IThunderSwapPool
*/
function addLiquidity(
uint256 _poolToken1Amount,
Expand Down Expand Up @@ -148,14 +139,7 @@ contract ThunderSwapPool is IThunderSwapPool, ReentrancyGuard {
}

/**
* @notice Allows liquidity providers to exit the protocol by withdrawing their deposited liquidity
* @param _liquidityProviderTokensToBurn The amount of LP tokens the LP wants to burn to claim
* his/her liquidity
* @param _minimumPoolToken1ToWithdraw (slippage protection) The minimum pool token 1 amount the LP
* is expecting to withdraw
* @param _minimumPoolToken2ToWithdraw (slippage protection) The minimum pool token 2 amount the LP
* is expecting to withdraw
* @param _deadline Deadline before which the liquidity should be withdrawn
* @inheritdoc IThunderSwapPool
*/
function withdrawLiquidity(
uint256 _liquidityProviderTokensToBurn,
Expand Down Expand Up @@ -202,16 +186,7 @@ contract ThunderSwapPool is IThunderSwapPool, ReentrancyGuard {
}

/**
* @notice Flash swaps exact amount of input token for output token
* @param _inputToken The input token (supported by the pool)
* @param _inputAmount The amount of input token to send
* @param _minimumOutputTokenToReceive (slippage protection) The minimum amount of output token
* to receive
* @param _receiver Receiver of the output token amount (contract, or a wallet)
* @param _callContract If true, call the `onThunderSwapReceived()` function on the receiver contract
* @param _callBeforeHook if true, calls the `beforeThunderSwapReceived` hook on the receiver contract
* @param _callAfterHook if true, calls the `afterThunderSwapReceived` hook on the receiver contract
* @param _deadline Deadline before which the flash swap should occur
* @inheritdoc IThunderSwapPool
*/
function flashSwapExactInput(
IERC20 _inputToken,
Expand Down Expand Up @@ -255,16 +230,7 @@ contract ThunderSwapPool is IThunderSwapPool, ReentrancyGuard {
}

/**
* @notice Flash swaps a certain amount of input token for an exact amount of output token
* @param _outputToken The output token (supported by the pool)
* @param _outputAmount The amount of output token to receive
* @param _maximumInputTokensToSend (slippage protection) The maximum amount of input token
* to send
* @param _receiver Receiver of the output token amount (contract, or a wallet)
* @param _callContract If true, call the `onThunderSwapReceived()` function on the receiver contract
* @param _callBeforeHook if true, calls the `beforeThunderSwapReceived` hook on the receiver contract
* @param _callAfterHook if true, calls the `afterThunderSwapReceived` hook on the receiver contract
* @param _deadline Deadline before which the flash swap should occur
* @inheritdoc IThunderSwapPool
*/
function flashSwapExactOutput(
IERC20 _outputToken,
Expand Down
48 changes: 47 additions & 1 deletion src/core/interfaces/IThunderSwapPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,37 @@ pragma solidity 0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IThunderSwapPool {
/**
* @notice Allows users to become liquidity providers by supplying the protocol with liquidity
* @dev Pool token 2 to supply is calculated based on pool token 1 amount. However, at inception
* the first LP can decide on the ratio of his/her deposit
* @param _poolToken1Amount The amount of pool token 1 to add as liquidity
* @param _poolToken2Amount The amount of pool token 2 to add as liquidity
* @param _maximumPoolToken2ToDeposit (slippage protection) The maximum amount of pool token 2 to deposit
* based on pool token 1 amount
* @param _minimumLiquidityProviderTokensToMint (slippage protection) The minimum share of the pool the
* liquidity provider is expecting to own
* @param _deadline Deadline before which the liquidity should be added
*/
function addLiquidity(
uint256 _poolToken1Amount,
uint256 _poolToken2Amount,
uint256 _maximumPoolToken2ToDeposit,
uint256 _minimumLPTokensToMint,
uint256 _minimumLiquidityProviderTokensToMint,
uint256 _deadline
)
external;

/**
* @notice Allows liquidity providers to exit the protocol by withdrawing their deposited liquidity
* @param _liquidityProviderTokensToBurn The amount of LP tokens the LP wants to burn to claim
* his/her liquidity
* @param _minimumPoolToken1ToWithdraw (slippage protection) The minimum pool token 1 amount the LP
* is expecting to withdraw
* @param _minimumPoolToken2ToWithdraw (slippage protection) The minimum pool token 2 amount the LP
* is expecting to withdraw
* @param _deadline Deadline before which the liquidity should be withdrawn
*/
function withdrawLiquidity(
uint256 _liquidityProviderTokensToBurn,
uint256 _minimumPoolToken1ToWithdraw,
Expand All @@ -21,6 +43,18 @@ interface IThunderSwapPool {
)
external;

/**
* @notice Flash swaps exact amount of input token for output token
* @param _inputToken The input token (supported by the pool)
* @param _inputAmount The amount of input token to send
* @param _minimumOutputTokenToReceive (slippage protection) The minimum amount of output token
* to receive
* @param _receiver Receiver of the output token amount (contract, or a wallet)
* @param _callContract If true, call the `onThunderSwapReceived()` function on the receiver contract
* @param _callBeforeHook if true, calls the `beforeThunderSwapReceived` hook on the receiver contract
* @param _callAfterHook if true, calls the `afterThunderSwapReceived` hook on the receiver contract
* @param _deadline Deadline before which the flash swap should occur
*/
function flashSwapExactInput(
IERC20 _inputToken,
uint256 _inputAmount,
Expand All @@ -33,6 +67,18 @@ interface IThunderSwapPool {
)
external;

/**
* @notice Flash swaps a certain amount of input token for an exact amount of output token
* @param _outputToken The output token (supported by the pool)
* @param _outputAmount The amount of output token to receive
* @param _maximumInputTokensToSend (slippage protection) The maximum amount of input token
* to send
* @param _receiver Receiver of the output token amount (contract, or a wallet)
* @param _callContract If true, call the `onThunderSwapReceived()` function on the receiver contract
* @param _callBeforeHook if true, calls the `beforeThunderSwapReceived` hook on the receiver contract
* @param _callAfterHook if true, calls the `afterThunderSwapReceived` hook on the receiver contract
* @param _deadline Deadline before which the flash swap should occur
*/
function flashSwapExactOutput(
IERC20 _outputToken,
uint256 _outputAmount,
Expand Down

0 comments on commit 0378f06

Please sign in to comment.