Skip to content

Commit b5a0233

Browse files
authored
Merge pull request #99 from NFTX-project/add-gen-readme-script
Add script to generate addresses table in README
2 parents c23e81a + 8e139b0 commit b5a0233

File tree

6 files changed

+318
-31
lines changed

6 files changed

+318
-31
lines changed

README.md

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,26 @@ The vTokens can then be used to earn yield by:<br>
1515

1616
<hr />
1717

18-
Core contracts:
19-
20-
1. `NFTXVaultUpgradeableV3`
21-
2. `NFTXVaultFactoryUpgradeableV3`
22-
3. `NFTXFeeDistributorV3`
23-
4. `NFTXInventoryStakingV3Upgradeable`
24-
5. `UniswapV3FactoryUpgradeable`
25-
6. `UniswapV3PoolUpgradeable`
26-
7. `NonfungiblePositionManager`
27-
8. `NFTXRouter`
28-
29-
Zaps:
30-
31-
1. `CreateVaultZap`
32-
2. `MarketplaceUniversalRouterZap`
33-
3. `MigratorZap`
18+
## Contracts
19+
20+
Contract | mainnet | sepolia | goerli
21+
--- | --- | --- | ---
22+
[CreateVaultZap](./src/zaps/CreateVaultZap.sol) | [0x56dab32697B4A313f353DA0CE42B5113eD8E6f74](https://etherscan.io/address/0x56dab32697B4A313f353DA0CE42B5113eD8E6f74#code) | [0xD80b916470F8e79FD8d09874cb159CbB8D13d8da](https://sepolia.etherscan.io/address/0xD80b916470F8e79FD8d09874cb159CbB8D13d8da#code) | [0xc6464CC63bC20b64e1633A0293C2C9b202F4f1b6](https://goerli.etherscan.io/address/0xc6464CC63bC20b64e1633A0293C2C9b202F4f1b6#code)
23+
[MarketplaceUniversalRouterZap](./src/zaps/MarketplaceUniversalRouterZap.sol) | [0x293A0c49c85F1D8851C665Ac3cE1f1DC2a79bE3d](https://etherscan.io/address/0x293A0c49c85F1D8851C665Ac3cE1f1DC2a79bE3d#code) | [0xd88a3B9D0Fb2d39ec8394CfFD983aFBB2D4a6410](https://sepolia.etherscan.io/address/0xd88a3B9D0Fb2d39ec8394CfFD983aFBB2D4a6410#code) | [0x0be2D766Eef4b6a72F1fAe2e49619F013d647B8A](https://goerli.etherscan.io/address/0x0be2D766Eef4b6a72F1fAe2e49619F013d647B8A#code)
24+
[MigratorZap](./src/zaps/MigratorZap.sol) | [0x089610Fb04c34C014B4B391f4eCEFAef94E98CEc](https://etherscan.io/address/0x089610Fb04c34C014B4B391f4eCEFAef94E98CEc#code) | [0x19762e505aF085284E287c8DAb931fb28545461f](https://sepolia.etherscan.io/address/0x19762e505aF085284E287c8DAb931fb28545461f#code) | [0xD4B67Fe6a1258fd5e1C4dF84f3De01F62e7ac127](https://goerli.etherscan.io/address/0xD4B67Fe6a1258fd5e1C4dF84f3De01F62e7ac127#code)
25+
[NFTXEligibilityManager](./src/v2/NFTXEligibilityManager.sol) | [0x4086e98Cce041d286112d021612fD894cFed94D5](https://etherscan.io/address/0x4086e98Cce041d286112d021612fD894cFed94D5#code) | [0xa1ad09f8Fd789E3A940Ba9Dc5aE4D17021eF290D](https://sepolia.etherscan.io/address/0xa1ad09f8Fd789E3A940Ba9Dc5aE4D17021eF290D#code) | [0xA4e9e286CE7A34d19f774c36844225468290C3A8](https://goerli.etherscan.io/address/0xA4e9e286CE7A34d19f774c36844225468290C3A8#code)
26+
[NFTXFeeDistributorV3](./src/NFTXFeeDistributorV3.sol) | [0xF4d96C5094FCD9eC24E612585e723b58F89e21fe](https://etherscan.io/address/0xF4d96C5094FCD9eC24E612585e723b58F89e21fe#code) | [0x66EF5B4b6ee05639194844CE4867515665F14fED](https://sepolia.etherscan.io/address/0x66EF5B4b6ee05639194844CE4867515665F14fED#code) | [0xA8076Ec5Dbb95165e14624Ff43dE2290e78A6905](https://goerli.etherscan.io/address/0xA8076Ec5Dbb95165e14624Ff43dE2290e78A6905#code)
27+
[NFTXInventoryStakingV3Upgradeable](./src/NFTXInventoryStakingV3Upgradeable.sol) | [0x889f313e2a3FDC1c9a45bC6020A8a18749CD6152](https://etherscan.io/address/0x889f313e2a3FDC1c9a45bC6020A8a18749CD6152#code) | [0xfBFf0635f7c5327FD138E1EBa72BD9877A6a7C1C](https://sepolia.etherscan.io/address/0xfBFf0635f7c5327FD138E1EBa72BD9877A6a7C1C#code) | [0xEf771a17e6970d8B4b208a76e94F175277554230](https://goerli.etherscan.io/address/0xEf771a17e6970d8B4b208a76e94F175277554230#code)
28+
[NFTXRouter](./src/NFTXRouter.sol) | [0x70A741A12262d4b5Ff45C0179c783a380EebE42a](https://etherscan.io/address/0x70A741A12262d4b5Ff45C0179c783a380EebE42a#code) | [0x441b7DE4340AAa5aA86dB4DA43d9Badf7B2DAA66](https://sepolia.etherscan.io/address/0x441b7DE4340AAa5aA86dB4DA43d9Badf7B2DAA66#code) | [0x8E16cdd0D9A15d2d0EFeA531660e8DbD0F6eE12D](https://goerli.etherscan.io/address/0x8E16cdd0D9A15d2d0EFeA531660e8DbD0F6eE12D#code)
29+
[nftxUniversalRouter](https://github.com/NFTX-project/nftx-universal-router/blob/nftx-universal-router/contracts/UniversalRouter.sol) | [0x250d62a67254A46c0De472d2c9215E1d890cC90f](https://etherscan.io/address/0x250d62a67254A46c0De472d2c9215E1d890cC90f#code) | [0x12156cCA1958B6591CC49EaE03a5553458a4b424](https://sepolia.etherscan.io/address/0x12156cCA1958B6591CC49EaE03a5553458a4b424#code) | [0xF7c4FC5C2e30258e1E4d1197fc63aeDE371508f3](https://goerli.etherscan.io/address/0xF7c4FC5C2e30258e1E4d1197fc63aeDE371508f3#code)
30+
[NFTXVaultFactoryUpgradeableV3](./src/NFTXVaultFactoryUpgradeableV3.sol) | [0xC255335bc5aBd6928063F5788a5E420554858f01](https://etherscan.io/address/0xC255335bc5aBd6928063F5788a5E420554858f01#code) | [0x31C56CaF49125043e80B4d3C7f8734f949d8178C](https://sepolia.etherscan.io/address/0x31C56CaF49125043e80B4d3C7f8734f949d8178C#code) | [0x1d552A0e6c2f680872C4a88b1e7def05F1858dF0](https://goerli.etherscan.io/address/0x1d552A0e6c2f680872C4a88b1e7def05F1858dF0#code)
31+
[NonfungiblePositionManager](./src/uniswap/v3-periphery/NonfungiblePositionManager.sol) | [0x26387fcA3692FCac1C1e8E4E2B22A6CF0d4b71bF](https://etherscan.io/address/0x26387fcA3692FCac1C1e8E4E2B22A6CF0d4b71bF#code) | [0xA9bCC1e29d3460177875f68fDCC0264D22c40BF0](https://sepolia.etherscan.io/address/0xA9bCC1e29d3460177875f68fDCC0264D22c40BF0#code) | [0xDa9411C5455a1bfDb527d0988c0A2764E2a104be](https://goerli.etherscan.io/address/0xDa9411C5455a1bfDb527d0988c0A2764E2a104be#code)
32+
[permit2](https://github.com/Uniswap/permit2/blob/main/src/Permit2.sol) | [0x000000000022d473030f116ddee9f6b43ac78ba3](https://etherscan.io/address/0x000000000022d473030f116ddee9f6b43ac78ba3#code) | [0x000000000022d473030f116ddee9f6b43ac78ba3](https://sepolia.etherscan.io/address/0x000000000022d473030f116ddee9f6b43ac78ba3#code) | [0x000000000022d473030f116ddee9f6b43ac78ba3](https://goerli.etherscan.io/address/0x000000000022d473030f116ddee9f6b43ac78ba3#code)
33+
[QuoterV2](./src/uniswap/v3-periphery/lens/QuoterV2.sol) | [0x5493dF723c17B6A768aA61F79405bA56ffC5294a](https://etherscan.io/address/0x5493dF723c17B6A768aA61F79405bA56ffC5294a#code) | [0xb8EB27ca4715f7A04228c6F83935379D1f5AbABd](https://sepolia.etherscan.io/address/0xb8EB27ca4715f7A04228c6F83935379D1f5AbABd#code) | [0xBb473dbEF3363b5d7CDD5f12429Fd1C5F0c10499](https://goerli.etherscan.io/address/0xBb473dbEF3363b5d7CDD5f12429Fd1C5F0c10499#code)
34+
[SwapRouter](./src/uniswap/v3-periphery/SwapRouter.sol) | [0x1703f8111B0E7A10e1d14f9073F53680d64277A3](https://etherscan.io/address/0x1703f8111B0E7A10e1d14f9073F53680d64277A3#code) | [0xa7069da6a7e600e0348620484fD2B1f24E075d5f](https://sepolia.etherscan.io/address/0xa7069da6a7e600e0348620484fD2B1f24E075d5f#code) | [0x2E77A788fc66c5312354aaE0df1dC1895ce556f8](https://goerli.etherscan.io/address/0x2E77A788fc66c5312354aaE0df1dC1895ce556f8#code)
35+
[TickLens](./src/uniswap/v3-periphery/lens/TickLens.sol) | [0x1650115DDD287bE6F4972180d290D0FF89a42c40](https://etherscan.io/address/0x1650115DDD287bE6F4972180d290D0FF89a42c40#code) | [0xA13E04fAEe08E784A44C27e9E77Ca7a02D45BFd7](https://sepolia.etherscan.io/address/0xA13E04fAEe08E784A44C27e9E77Ca7a02D45BFd7#code) | [0x32A7703773cBc265cf79D49340F656837169FEcD](https://goerli.etherscan.io/address/0x32A7703773cBc265cf79D49340F656837169FEcD#code)
36+
[UniswapV3FactoryUpgradeable](./src/uniswap/v3-core/UniswapV3FactoryUpgradeable.sol) | [0xa70e10beB02fF9a44007D9D3695d4b96003db101](https://etherscan.io/address/0xa70e10beB02fF9a44007D9D3695d4b96003db101#code) | [0xDD2dce9C403f93c10af1846543870D065419E70b](https://sepolia.etherscan.io/address/0xDD2dce9C403f93c10af1846543870D065419E70b#code) | [0xf25081B098c5929A26F562aa2502795fE89BC73f](https://goerli.etherscan.io/address/0xf25081B098c5929A26F562aa2502795fE89BC73f#code)
37+
[WETH](https://vscode.blockscan.com/ethereum/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2) | [0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2](https://etherscan.io/address/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2#code) | [0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14](https://sepolia.etherscan.io/address/0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14#code) | [0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6](https://goerli.etherscan.io/address/0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6#code)
3438

3539
## Core Contracts
3640

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"verify:sepolia": "hardhat --network sepolia etherscan-verify",
1515
"verify:mainnet": "hardhat --network mainnet etherscan-verify",
1616
"verify:arbitrum": "hardhat --network arbitrum etherscan-verify",
17-
"gen:addresses": "ts-node ./script/genAddressesJson.ts"
17+
"gen:addresses": "ts-node ./script/genAddressesJson.ts",
18+
"gen:readme": "ts-node ./script/genREADME.ts",
19+
"gen:addresses-and-readme": "yarn gen:addresses && yarn gen:readme"
1820
},
1921
"devDependencies": {
2022
"@ethersproject/units": "^5.7.0",
@@ -37,9 +39,9 @@
3739
"husky": "^8.0.3",
3840
"prettier": "^2.4.1",
3941
"prettier-plugin-solidity": "^1.0.0-beta.18",
40-
"ts-node": "^10.8.0",
42+
"ts-node": "^10.9.2",
4143
"typechain": "^5.1.1",
42-
"typescript": "^4.7.2"
44+
"typescript": "^5.3.3"
4345
},
4446
"dependencies": {
4547
"@nomicfoundation/hardhat-verify": "^1.1.1"

script/base-README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# NFTX Protocol V3
2+
3+
<img alt="NFTX Logo" src=".github/nftx-logo.jpg" />
4+
5+
## Overview
6+
7+
NFTX is a platform for creating liquid markets for illiquid Non-Fungible Tokens (NFTs).
8+
<br>
9+
Users deposit their NFT into an NFTX vault to fractionalize and mint a fungible ERC20 token (vToken). This vToken can be redeem back for any NFT from the vault, by paying a redeem fee in ETH.
10+
<br><br>
11+
The vTokens can then be used to earn yield by:<br>
12+
13+
1. Depositing into InventoryStaking to earn ETH (from vault fees) + vTokens (from early withdrawal fees)
14+
2. Pairing the vTokens with ETH and providing concentrated liquidity into the NFTX AMM to earn trading fees and additional ETH (from vault fees).
15+
16+
<hr />
17+
18+
## Contracts
19+
20+
[addresses-table]
21+
22+
## Core Contracts
23+
24+
### 1. NFTXVaultUpgradeableV3
25+
26+
Allows the following 3 main operations:<br />
27+
i. `mint`: Deposits NFTs and mints vault tokens in exchange.<br />
28+
ii. `redeem`: Burn vault tokens to redeem NFTs from the vault in exchange.<br />
29+
iii. `swap`: Swap an array of NFTs into a desired array of NFTs from the vault.
30+
31+
All of the above operations require the user to pay vault fees in ETH, calculated as a % of the ~20 min TWAP of the vToken from our AMM pool (with fee tier = `FeeDistributor.rewardFeeTier()`). If the pool doesn't exist yet, then no vault fees are deducted.<br /><br />
32+
The vault fees collected here are sent to the `NFTXFeeDistributorV3` in the same transaction to distribute to Inventory stakers and Liquidity Providers.<br />
33+
<br />
34+
In case of redeeming/swapping into a newly deposited NFT from a vault, an extra premium in ETH needs to be paid along with the vault fees. This premium is shared with the original depositor of the redeemed tokenId and the rest of the stakers. This premium amount goes down exponentially since being deposited into the vault and finally settling on 0.<br />
35+
<br />
36+
Additional features:
37+
38+
- Flash-minting without any added fees.
39+
- Using Eligibility modules to only allow certain tokenIds into the Vault.
40+
41+
### 2. NFTXVaultFactoryUpgradeableV3
42+
43+
Allows to deploy Beacon Proxies for the Vaults.
44+
45+
### 3. NFTXFeeDistributorV3
46+
47+
Allows to distribute WETH (vault fees) between multiple receivers including inventory stakers and NFTX AMM liquidity providers in the `rewardFeeTier` pool.
48+
49+
### 4. NFTXInventoryStakingV3Upgradeable
50+
51+
Allows users to stake vTokens and mint xNFT in exchange that earns WETH and vTokens as fees. The WETH vault fees are distributed equally among all the stakers.<br />
52+
53+
- NFTs can also be directly staked via Inventory, which internally mints vTokens but without deducting any vault fees. As users can use this to game and avoid the mint fees, so a redeem timelock is placed on the xNFT.
54+
- There is an option to early withdraw (while still in timelock) by paying a % of your vTokens as penalty, which gets distributed among rest of the stakers. This penalty goes down linearly overtime.
55+
- Users can collect and withdraw the WETH accumulated by their position
56+
- During withdrawal, users have the option to redeem NFTs from the vault with their underlying vToken balance. No vault fees is paid if initially the xNFT position was created by depositing NFTs.
57+
- Users can combine multiple xNFT positions into one, after each of their timelocks have run out.
58+
59+
### 5. UniswapV3FactoryUpgradeable
60+
61+
Forked from Uniswap, and converted into an upgradeable contract. Allows to deploy NFTX AMM pools as Create2 Beacon Proxies.
62+
63+
### 6. UniswapV3PoolUpgradeable
64+
65+
Forked from Uniswap. Added `distributeRewards` function, to be called by the FeeDistributor, which allows to distribute the WETH vault fees to the LPs in the current tick, proportional to their share of the liquidity. <br />
66+
If the pool is in `rewardFeeTier`, then cardinality is set during initialization of the pool so that it's able to provide TWAP for the vault fee calculations. The cost of initialization of the observations slots is forwarded & distributed to the first swappers.
67+
68+
### 7. NonfungiblePositionManager
69+
70+
Forked from Uniswap. Allows NFTX AMM positions to be represented as ERC721 NFTs. Allows the NFTXRouter to timelock positions from withdrawing liquidity, though more liquidity can still be added.
71+
72+
- Vault fees accumulated as WETH show up the same way as normal LP fees.
73+
74+
### 8. NFTXRouter
75+
76+
Router to facilitate vault tokens minting/burning + addition/removal of concentrated liquidity, all in one transaction. <br />
77+
78+
- NFTs can be directly deposited into the pool via NFTXRouter, which internally mints vTokens but without deducting any vault fees. As users can use this to game and avoid the mint fees, so a redeem timelock is placed on the LP NFT.
79+
- During withdrawal, users have the option to redeem NFTs from the vault with their underlying vToken balance. No vault fees is paid if initially the position was created by depositing NFTs.
80+
- NFTs can be directly sold and bought from the pool in exchange for ETH, via the AMM.
81+
82+
## Zaps
83+
84+
### 1. CreateVaultZap
85+
86+
An amalgomation of vault creation steps, merged and optimised in a single contract call. <br />
87+
Allows to create a new Vault, mint vTokens in exchange for NFTs, deploy new NFTX AMM pool, deposit the minted vTokens and the ETH sent into the AMM pool to mint liquidity position NFT, deposit the remaining vTokens into inventory staking to mint xNFT.
88+
89+
### 2. MarketplaceUniversalRouterZap
90+
91+
Marketplace Zap that utilizes Uniswap's Universal Router to facilitate tokens swaps via Sushiswap and NFTX AMM. Enables deducting creator royalties via ERC2981.<br />
92+
93+
- `sell721`/`sell1155`: sell NFT tokenIds to ETH.<br />
94+
`idsIn --{--mint-> [vault] -> vTokens --sell-> [UniversalRouter] --}-> ETH`
95+
- `swap721`/`swap1155`: Swap an array of NFTs into a desired array of NFTs from the vault, by paying ETH for vault fees.
96+
- `buyNFTsWithETH`: buy NFT tokenIds with ETH.<br />
97+
`ETH --{-sell-> [UniversalRouter] -> vTokens + ETH --redeem-> [vault] --}-> idsOut`
98+
- `buyNFTsWithERC20`: buy NFT tokenIds with ERC20.<br/>
99+
`ERC20 --{-sell-> [UniversalRouter] -> ETH -> [UniversalRouter] -> vTokens + ETH --redeem-> [vault] --}-> idsOut`
100+
101+
### 3. MigratorZap
102+
103+
Allows the users to migrate their NFTX v2 positions to v3:
104+
105+
- from v2 vTokens in sushiswap liquidity to v3 vTokens in NFTX AMM.
106+
- from v2 vTokens in v2 inventory staking to v3 vTokens in xNFT.
107+
- from v2 vTokens to v3 vTokens in xNFT.
108+
109+
<hr />
110+
111+
## Project Setup
112+
113+
We use [Foundry](https://book.getfoundry.sh/) for tests and [Hardhat](https://hardhat.org/docs) for contract deployments. Refer to installation instructions for foundry [here](https://github.com/foundry-rs/foundry#installation).
114+
115+
```sh
116+
git clone https://github.com/NFTX-project/nftx-protocol-v3.git
117+
cd nftx-protocol-v3
118+
forge install
119+
yarn install
120+
```
121+
122+
Copy `.env.sample` into `.env` and fill out the env variables.
123+
124+
### Tests
125+
126+
```sh
127+
forge test
128+
```
129+
130+
### Deployment
131+
132+
1. To deploy core V3 contracts (including Uniswap V3 Fork):
133+
134+
```sh
135+
yarn deploy:goerli --maxfee <inWei> --priorityfee <inWei> --tags NFTXV3
136+
```
137+
138+
2. Deploy new Universal Router (https://github.com/NFTX-project/nftx-universal-router) with updated address for UniswapV3 Factory address.
139+
3. Deploy all Zaps:
140+
141+
```sh
142+
yarn deploy:goerli --maxfee <inWei> --priorityfee <inWei> --tags Zaps
143+
```
144+
145+
4. Run the following to generate `./addresses.json` for the deployed contract addresses
146+
147+
```sh
148+
yarn gen:addresses
149+
```
150+
151+
Note: Tags are defined in the deploy script at the end like: `func.tags = ["<tag>"]`
152+
153+
### Verify Contracts
154+
155+
`yarn verify:goerli`
156+
157+
**Note:** For some UniswapV3 contracts there might be some error while verifying, so run this for those contracts:
158+
159+
`yarn verify:goerli --license "GPL-2.0" --force-license --solc-input`
160+
161+
How to verify the BeaconProxy (for Vaults):
162+
`source .env && forge verify-contract --chain-id 5 --num-of-optimizations 800 --watch --etherscan-api-key $ETHERSCAN_API_KEY --compiler-version v0.8.15+commit.e14f2714 0xffE5d77309efd6e9391Ac14D95f2035A1e138659 lib/openzeppelin-contracts/contracts/proxy/beacon/BeaconProxy.sol:BeaconProxy --constructor-args $(cast abi-encode "constructor(address,bytes)" 0x1d552A0e6c2f680872C4a88b1e7def05F1858dF0 "")`
163+
164+
where `0xffE5d77309efd6e9391Ac14D95f2035A1e138659` = vault (proxy) address\
165+
and `0x1d552A0e6c2f680872C4a88b1e7def05F1858dF0` = vault factory

0 commit comments

Comments
 (0)