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

feat: factory enhancements #59

Merged
merged 67 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
cdd4e40
feat: use beacon
0xSolDev Dec 9, 2024
881ea96
feat: added configs
0xSolDev Dec 10, 2024
014d415
feat: modify symbol
0xSolDev Dec 10, 2024
0c052c1
fix: added admin modified event
0xSolDev Dec 10, 2024
c2e61a8
feat: choose exchange rate provider
0xSolDev Dec 11, 2024
39d6dd3
feat: renamed lp token contracts
0xSolDev Dec 11, 2024
3de94d1
feat: auto percision
0xSolDev Dec 11, 2024
e0d94f7
feat: wip - tests
0xSolDev Dec 11, 2024
7f42b40
feat: check balance in test
0xSolDev Dec 12, 2024
99af94b
fix: fixed build
0xSolDev Dec 12, 2024
28ec9a5
fix: fixed factory size
0xSolDev Dec 12, 2024
93d0f27
feat: added deployment scripts
0xSolDev Dec 12, 2024
466f46e
chore: fixed lint
0xSolDev Dec 12, 2024
3650acb
fix: fixed build
0xSolDev Dec 12, 2024
ad8b003
feat: deployed to testnet
0xSolDev Dec 13, 2024
c31ef7b
feat: instructions to verify contract
0xSolDev Dec 13, 2024
16a059c
feat: added create pool script
0xSolDev Dec 13, 2024
358c676
fix: redeployed
0xSolDev Dec 13, 2024
9ef1bd9
fix: updated to v1.5 audited code
0xSolDev Dec 16, 2024
b7debda
fix: fixed compiler version
0xSolDev Dec 16, 2024
38f09c2
fix: fixed lint
0xSolDev Dec 16, 2024
a655f38
fix: removed lastRedeemOrMint
0xSolDev Dec 16, 2024
77caec2
fix: removed lastRedeemOrMint
0xSolDev Dec 16, 2024
68aef87
feat: added types for token A
0xSolDev Dec 17, 2024
3b31965
feat: added a unit test
0xSolDev Dec 17, 2024
dc5e9fa
feat: added test for exchange rate tokens
0xSolDev Dec 17, 2024
1b39a88
fix: fixed lint
0xSolDev Dec 17, 2024
5274a0e
feat: convert WLPToken to ERC4626 standard
0xSolDev Dec 18, 2024
777c498
feat: use uups upgrades
0xSolDev Dec 18, 2024
3e49ab3
fix: fixed lint
0xSolDev Dec 18, 2024
64a16b2
feat: updated governance model for factory
0xSolDev Dec 19, 2024
ee4c890
fix: fixed test
0xSolDev Dec 19, 2024
30ab88e
fix: fixed scripts
0xSolDev Dec 19, 2024
ea8bfe6
fix: remove timelock from factory
0xSolDev Dec 21, 2024
421add1
feat: renamed to self pegging asset
0xSolDev Dec 23, 2024
19e12d4
feat: use custom errors
0xSolDev Dec 24, 2024
d31c92f
fix: fixed admin privilages
0xSolDev Dec 24, 2024
fd0f54d
fix: merge conflict
0xSolDev Dec 24, 2024
5677293
fix: removed application contract
0xSolDev Dec 25, 2024
d8e4540
fix: merge conflict
0xSolDev Dec 25, 2024
d7da416
feat: added netspec
0xSolDev Dec 25, 2024
846fa0c
fix: added netspec
0xSolDev Dec 25, 2024
6d763d4
fix: refactored tests
0xSolDev Dec 25, 2024
b3e76a4
feat: upgraded oz
0xSolDev Dec 28, 2024
f30361a
feat: added tests
0xSolDev Dec 28, 2024
9f2a7be
feat: added tests
0xSolDev Dec 28, 2024
790ba15
feat: added tests
0xSolDev Dec 28, 2024
8b03f90
feat: added tests
0xSolDev Dec 28, 2024
acbf81b
feat: added tests
0xSolDev Dec 28, 2024
2e87c5e
feat: reverted tests
0xSolDev Dec 28, 2024
cfe6617
feat: added lp and wlp token tests
0xSolDev Dec 29, 2024
1a28658
feat: deployed on base sepolia
0xSolDev Dec 30, 2024
88d46b4
feat: created pool
0xSolDev Dec 30, 2024
dc3116d
fix: revert contract
0xSolDev Dec 30, 2024
78e79e0
fix: updated readme
0xSolDev Dec 30, 2024
323b737
fix: fixed lint
0xSolDev Dec 31, 2024
b376364
fix: fixed lint
0xSolDev Dec 31, 2024
b443603
Merge pull request #66 from nutsfinance/feat/demo-deployment
0xSolDev Dec 31, 2024
27790a9
Merge pull request #65 from nutsfinance/feat/tests
0xSolDev Dec 31, 2024
3b60b4a
Merge pull request #64 from nutsfinance/feat/coding-standard
0xSolDev Dec 31, 2024
993b4c7
Merge pull request #63 from nutsfinance/feat/timelock-integration
0xSolDev Dec 31, 2024
db8eaed
Merge pull request #62 from nutsfinance/feat/uups-upgradable
0xSolDev Dec 31, 2024
89e99ce
feat: overwrite preview and withdraw funcs
0xSolDev Dec 31, 2024
4ff4518
fix: remove duplicate override
0xSolDev Dec 31, 2024
c07f54e
fix: added mint function override
0xSolDev Dec 31, 2024
430f9d3
Merge pull request #61 from nutsfinance/feat/erc-4626
0xSolDev Dec 31, 2024
de3d17d
Merge pull request #60 from nutsfinance/feat/token-a-types
0xSolDev Dec 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
export API_KEY_ALCHEMY="YOUR_API_KEY_ALCHEMY"
export API_KEY_ARBISCAN="YOUR_API_KEY_ARBISCAN"
export API_KEY_BSCSCAN="YOUR_API_KEY_BSCSCAN"
export API_KEY_ETHERSCAN="YOUR_API_KEY_ETHERSCAN"
export API_KEY_GNOSISSCAN="YOUR_API_KEY_GNOSISSCAN"
export API_KEY_INFURA="YOUR_API_KEY_INFURA"
export API_KEY_OPTIMISTIC_ETHERSCAN="YOUR_API_KEY_OPTIMISTIC_ETHERSCAN"
export API_KEY_POLYGONSCAN="YOUR_API_KEY_POLYGONSCAN"
export API_KEY_SNOWTRACE="YOUR_API_KEY_SNOWTRACE"
export MNEMONIC="YOUR_MNEMONIC"
export FOUNDRY_PROFILE="default"
export TESTNET=true
export HEX_PRIV_KEY="HEX_PRIV_KEY"
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: "CI"

env:
API_KEY_ALCHEMY: ${{ secrets.API_KEY_ALCHEMY }}
FOUNDRY_PROFILE: "ci"

on:
Expand Down
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cache
coverage
node_modules
out
broadcast/**/dry-run/

# files
*.env
Expand All @@ -11,9 +12,4 @@ out
.pnp.*
lcov.info
package-lock.json
pnpm-lock.yaml

# broadcasts
!broadcast
broadcast/*
broadcast/*/31337/
pnpm-lock.yaml
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "solhint:recommended",
"rules": {
"code-complexity": ["error", 10],
"code-complexity": ["error", 12],
"compiler-version": ["error", ">=0.8.25"],
"func-name-mixedcase": "off",
"func-visibility": ["error", { "ignoreConstructors": true }],
Expand Down
158 changes: 66 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ applications.

The main contracts of Tapio V1.5 are the following:

**TapEth** : contract of rebase token tapETH
**LPToken** : contract of rebase token lpToken

**WtapETH**: contract of wrapped tapETH
**WlpToken**: contract of wrapped lpToken

**StableAsset**: contract of stableswap pool
**SelfPeggingAsset**: contract of stableswap pool

**StableAssetApplication**: user contract interface for different stableSwap pools
**SelfPeggingAssetApplication**: user contract interface for different stableSwap pools

# Smart Contracts OVERVIEW

The main contracts of Tapio V1.5 are the following:

**TapEth** : contract of rebase token tapETH
**LPToken** : contract of rebase token lpToken

**WtapETH**: contract of wrapped tapETH
**WlpToken**: contract of wrapped lpToken

**StableAsset**: contract of stableswap pool
**SelfPeggingAsset**: contract of stableswap pool

**StableAssetApplication**: user contract interface for different stableSwap pools
**SelfPeggingAssetApplication**: user contract interface for different stableSwap pools

## Contract TapETH
## Contract LPToken

The contract **TapETH** is upgradable and uses the interface IERC20.
The contract **LPToken** is upgradable and uses the interface IERC20.

### Write Methodes

Expand All @@ -49,99 +49,65 @@ The contract **TapETH** is upgradable and uses the interface IERC20.

- **transferShares(address \_recipient, uint256 \_sharesAmount)**

This function allows the caller to transfer `_sharesAmount` shares of tapETH from his address to `_recipient`.
This function allows the caller to transfer `_sharesAmount` shares of lpToken from his address to `_recipient`.

- **transferSharesFrom(address \_sender, address \_recipient, uint256 \_sharesAmount)**

This function allows the spender to transfer `_sharesAmount` shares of tapETH from to `_sender` to `_recipient`.
This function allows the spender to transfer `_sharesAmount` shares of lpToken from to `_sender` to `_recipient`.

- **mintShares(address \_account, uint256 \_tokenAmount)**

This function can be executed by a whitelisted stableSwap pool to mint `_tokenAmount` of tapETH for `_account`.
This function can be executed by a whitelisted stableSwap pool to mint `_tokenAmount` of lpToken for `_account`.

- **burnShares(uint256 \_tokenAmount)**

This function allows the caller to burn `_tokenAmount` of tapETH.
This function allows the caller to burn `_tokenAmount` of lpToken.

- **burnSharesFrom(address \_account, uint256 \_tokenAmount)**

This function allows the spender to burn `_tokenAmount` of tapETH from the addresss `_account`.
This function allows the spender to burn `_tokenAmount` of lpToken from the addresss `_account`.

### View Methodes

- **getTotalPooledEther()**
- **getTotalPeggedTokener()**

This function returns the total supply of tapETH (uint256).
This function returns the total supply of lpToken (uint256).

- **getTotalShares()**

This function returns the total shares of tapETH (uint256).
This function returns the total shares of lpToken (uint256).

- **getSharesByPooledEth(uint256_tapETHAmount)**
- **getSharesByPeggedToken(uint256_lpTokenAmount)**

This function returns the shares of tapETH (uint256) corresponding to `_tapETHAmount` of tapETH.
This function returns the shares of lpToken (uint256) corresponding to `_lpTokenAmount` of lpToken.

- **getPooledEthByShares(uint256 \_sharesAmount)**
- **getPeggedTokenByShares(uint256 \_sharesAmount)**

This function returns the amount of tapETH (uint256) corresponding to `sharesAmount' shares of tapETH.
This function returns the amount of lpToken (uint256) corresponding to `sharesAmount' shares of lpToken.

- **setTotalSupply(uint256 \_amount)**

This function can be only called by a whitelist stableSwap pool contract to increase the total supply of tapETH by
This function can be only called by a whitelist stableSwap pool contract to increase the total supply of lpToken by
`_amount`.

## Contract WTapETH
## Contract SelfPeggingAsset

The contract **WTapETH** is upgradable and inherits from the contract ERC20Permit.

### Write Methodes

- **wrap(uint256 \_tapETHAmount)**

This function allows the user to wrap `_ tapETHAmount` of tapETH that consisting in transferring `_tapETHAmount` of
tapETH to the smart contract WTapETH and minting the corresponding shares amount in wtapETH.

- **unwrap(uint256 \_wtapETHAmount)**

This function allows the user to unwrap `_wtapETHAmount` of wtapETH that consisting in burning `wtapETHAmount` of
wtapETH and sending from the smart contract WTapETH to the caller the corresponding amount of tapETH.

### View Methodes

- **getWtapETHByTapETH(uint256 \_tapETHAmount)**

This function returns the amount of wtapETH that corresponds to `_tapETHAmount` of tapETH.

- **getTapETHByWtapETH(uint256 \_wtapETHAmount)**

This function returns the amount of tapETH that corresponds to `_wtapETHAmount` of wtapETH.

- **tapETHPerToken()**

This function returns the amount of tapETH that corresponds to 1 wtapETH.

- **tokensPerTapETH()**

This function returns the amount of wtapETH that corresponds to 1 tapETH.

## Contract StableAsset

The contract **StableAsset** is upgradable and inherits from the contract ReentrancyGuard.
The contract **SelfPeggingAsset** is upgradable and inherits from the contract ReentrancyGuard.

### Write Methodes

- **mint(uint256[] calldata \_amounts, uint256 \_minMintAmount)**

This function allows the user to provide liquidity in the different tokens of the pool to mint at least `_wtapETHAmount`
of tapETH. The Logic of the function consists of :
This function allows the user to provide liquidity in the different tokens of the pool to mint at least
`_wlpTokenAmount` of lpToken. The Logic of the function consists of :

1. update token balances
2. calculate the new D value
3. calculate delta D = new D - old D
4. calculate mintAmount = delta D - feeAmount = delta D \* ( 1- mintFee)
5. revert if mintAmount < \_minMintAmount
6. mint mintAmount of tapETH for the caller
7. increase the total supply of tapETH by feeAmount
6. mint mintAmount of lpToken for the caller
7. increase the total supply of lpToken by feeAmount

- **swap(uint256 \_i, uint256 \_j, uint256 \_dx, uint256 \_minDy)**

Expand All @@ -154,11 +120,11 @@ The Logic of the function consists of:
4. calculate outputAmount = delta y - feeAmount = delta y \* ( 1- swapFee)
5. revert if outputAmount < \_minDy
6. send outputAmount of token index `j` to the caller
7. increase the total supply of tapETH by feeAmount
7. increase the total supply of lpToken by feeAmount

- **redeemProportion(uint256 \_amount, uint256[] calldata \_minRedeemAmounts)**

This function allows the user to redeem `_amount `of tapETH in order to receive at least `_minRedeemAmounts[i]` of each
This function allows the user to redeem `_amount `of lpToken in order to receive at least `_minRedeemAmounts[i]` of each
token index i. The Logic of the function consists of:

1. calculate redeemAmount = \_amount - feeAmount = amount \* ( 1 - redeemFee).
Expand All @@ -167,24 +133,24 @@ token index i. The Logic of the function consists of:
- revert if tokenAmount < minRedeemAmounts[i]
- send tokenAmount of token index i to the caller
3. update D = D - \_amount
4. burn \_amount of tapETH from the caller
5. increase the totalSupply of tapETH by feeAmount
4. burn \_amount of lpToken from the caller
5. increase the totalSupply of lpToken by feeAmount

- **redeemSingle(uint256 \_amount, uint256 \_i, uint256 \_minRedeemAmount)**

This function allows the user to redeem `_amount `of tapETH in order to receive at least `_minRedeemAmount` of token
This function allows the user to redeem `_amount `of lpToken in order to receive at least `_minRedeemAmount` of token
index i. The Logic of the function consists of:

1. calculate redeemAmount = \_amount - feeAmount = amount \* ( 1 - redeemFee).
2. calculate the new amount of token i (new y ) for D = D - redeemAmount
3. calculate delta y = new y - old y
4. revert if delta y < \_minRedeemAmount
5. send delta y of token index `i` to the caller
6. increase the total supply of tapETH by feeAmount
6. increase the total supply of lpToken by feeAmount

- **redeemMulti(uint256[] calldata \_amounts, uint256 \_maxRedeemAmount)**

This function allows the user to redeem at most `_maxRedeemAmount ` of tapETH to receive `_amouns[i] `of each token
This function allows the user to redeem at most `_maxRedeemAmount ` of lpToken to receive `_amouns[i] `of each token
index i. The Logic of the function consists of:

1. update balance of each token index `i ` .
Expand All @@ -193,7 +159,7 @@ index i. The Logic of the function consists of:
4. calculate redeemAmount = delta D + feeAmount = delta D \* ( 1 + redeemFee)
5. revert if redeemAmount > \_maxRedeemAmount
6. for each token index i, send \_amounts[i] to the caller
7. increase the total supply of tapETH by feeAmount
7. increase the total supply of lpToken by feeAmount

functions to be executed only by the governance:

Expand Down Expand Up @@ -242,7 +208,7 @@ This function returns the current value of A.

- **getMintAmount(uint256[] calldata \_amounts)**

This function returns (uint256 mintAmount, uint256 fee) where mintAmount is the amount of tapETH to mint for the user,
This function returns (uint256 mintAmount, uint256 fee) where mintAmount is the amount of lpToken to mint for the user,
and fee is the mint fee.

- **getSwapAmount(uint256 \_i, uint256 \_j, uint256 \_dx)**
Expand All @@ -262,37 +228,37 @@ user, and fee is the redeem fee.

- **getRedeemMultiAmount(uint256[] calldata \_amounts)**

This function returns (uint256 amount, uint256 fee) where amount is the amount of tapETH to redeem and fee is the redeem
fee.
This function returns (uint256 amount, uint256 fee) where amount is the amount of lpToken to redeem and fee is the
redeem fee.

## Contract StableAssetApplication
## Contract SelfPeggingAssetApplication

The contract **StableAssetApplication** is upgradable and inherits from the contract ReentrancyGuard.
The contract **SelfPeggingAssetApplication** is upgradable and inherits from the contract ReentrancyGuard.

### Write Methodes

- **mint(StableAsset \_pool, uint256[] calldata \_amounts, uint256 \_minMintAmount )**
- **mint(SelfPeggingAsset \_pool, uint256[] calldata \_amounts, uint256 \_minMintAmount )**

This function allows the user to provide liquidity in the different tokens of the pool `_pool` to mint at least
`_wtapETHAmount` of tapETH.
`_wlpTokenAmount` of lpToken.

- **swap(StableAsset \_pool, uint256 \_i, uint256 \_j, uint256 \_dx, uint256 \_minDy)**
- **swap(SelfPeggingAsset \_pool, uint256 \_i, uint256 \_j, uint256 \_dx, uint256 \_minDy)**

This function allows the user to swap `_dx ` amount of token index `i` to at least `_minDy` amount of token index `j`
using the pool `_pool`.

- **redeemProportion(StableAsset \_pool, uint256 \_amount, uint256[] calldata \_minRedeemAmounts)**
- **redeemProportion(SelfPeggingAsset \_pool, uint256 \_amount, uint256[] calldata \_minRedeemAmounts)**

This function allows the user to redeem `_amount `of tapETH from the pool `_pool` in order to receive at least
This function allows the user to redeem `_amount `of lpToken from the pool `_pool` in order to receive at least
`_minRedeemAmounts[i]` of each token index i .

- **redeemSingle(StableAsset \_pool, uint256 \_amount, uint256 \_i, uint256 \_minRedeemAmount)**
- **redeemSingle(SelfPeggingAsset \_pool, uint256 \_amount, uint256 \_i, uint256 \_minRedeemAmount)**

This function allows the user to redeem `_amount `of tapETH from the pool `_pool` in order to receive at least
This function allows the user to redeem `_amount `of lpToken from the pool `_pool` in order to receive at least
`_minRedeemAmount` of token index i.

- **swapCrossPool(StableAsset \_sourcePool, StableAsset \_destPool, address \_sourceToken, address \_destToken, uint256
\_amount, uint256 \_minSwapAmount)**
- **swapCrossPool(SelfPeggingAsset \_sourcePool, SelfPeggingAsset \_destPool, address \_sourceToken, address
\_destToken, uint256 \_amount, uint256 \_minSwapAmount)**

This function allows the user to swap `_amount ` amount of token `_sourceToken` from the pool `_sourcePool` to at least
`_minSwapAmount` amount of token `_destToken` from the pool `_destPool`.
Expand Down Expand Up @@ -333,19 +299,27 @@ Get a test coverage report:
$ forge coverage
```

### Deploy
### Deploy to Testnet

Deploy to Anvil:
Deploy to Base Testnet:

```sh
$ forge script script/Deploy.s.sol --broadcast --fork-url http://localhost:8545
$ forge script ./script/Testnet.s.sol -vvv --rpc-url basesepolia --broadcast
```

For this script to work, you need to have a `MNEMONIC` environment variable set to a valid
[BIP39 mnemonic](https://iancoleman.io/bip39/).
Before deploying make sure you configure the neccessary variables in `.env` file. To just test the scripts with just a
dry run remove the `--broadcast` flag.

### Verifying Contracts on Testnet Explorer

Here is an example on how to verify a contract on base sepolia:

```sh
$ forge verify-contract <contract-address> <contract-name> --watch --etherscan-api-key <basescan-api-key> --chain-id 84532 --constructor-args <encoded-constructor-args>
```

For instructions on how to deploy to a testnet or mainnet, check out the
[Solidity Scripting](https://book.getfoundry.sh/tutorials/solidity-scripting.html) tutorial.
You can find the contract name and constructor args in the broadcast directory. To encode the constructor args you can
use: https://abi.hashex.org/

### Format

Expand Down
Loading
Loading