|
1 | 1 | # GnoSwap Contracts |
2 | 2 |
|
3 | | -This repository contains smart contracts (realms) for GnoSwap. |
| 3 | +Smart contracts for GnoSwap AMM DEX on Gno.land. |
4 | 4 |
|
5 | | -## Index |
6 | | - |
7 | | -- [Setting Up and Testing GnoSwap Contracts](#setting-up-and-testing-gnoswap-contracts) |
8 | | - - [Prerequisites](#prerequisites) |
9 | | - - [Setting Up GnoSwap Contracts](#setting-up-gnoswap-contracts) |
10 | | - - [Running Tests](#running-tests) |
11 | | -- [Realms](#realms) |
12 | | - - [Core Realms Deployed on Testnet5](#core-realms-deployed-on-testnet5) |
13 | | - |
14 | | - |
15 | | -## Setting Up and Testing GnoSwap Contracts |
16 | | - |
17 | | -There are two ways to set up GnoSwap contracts: using the provided setup script or manually following the steps below. |
18 | | - |
19 | | -### Prerequisites |
| 5 | +## Prerequisites |
20 | 6 |
|
21 | 7 | - GNU Make 3.81 or higher |
22 | 8 | - Latest version of [gno.land](https://github.com/gnolang/gno) |
23 | 9 | - Python 3.12 or higher |
24 | 10 |
|
25 | | -### Using the Setup Script |
26 | | - |
27 | | -> Note: If you're using the script, you don't need to manually perform the steps listed in the next section. |
28 | | -
|
29 | | -For convenience, we provide a Python script that automates the setup process. This script can clone the repository, copy contracts, and move test files as needed. |
30 | | - |
31 | | -- To set up in your home directory without cloning the repository: |
| 11 | +## Setup |
32 | 12 |
|
33 | | - ```bash |
34 | | - python3 setup.py |
35 | | - ``` |
36 | | - |
37 | | -- To set up in a specific directory without cloning: |
38 | | - |
39 | | - ```bash |
40 | | - python3 setup.py -w /path/to/workdir |
41 | | - ``` |
42 | | - |
43 | | -- To clone the repository and set up in your home directory: |
| 13 | +```bash |
| 14 | +# Quick setup in home directory |
| 15 | +python3 setup.py |
44 | 16 |
|
45 | | - ```bash |
46 | | - python3 setup.py -c |
47 | | - ``` |
| 17 | +# Setup in custom directory |
| 18 | +python3 setup.py -w /path/to/workdir |
48 | 19 |
|
49 | | -- To clone the repository and set up in a specific directory: |
| 20 | +# Clone repository and setup |
| 21 | +python3 setup.py -c |
50 | 22 |
|
51 | | - ```bash |
52 | | - python3 setup.py -w /path/to/workdir -c |
53 | | - ``` |
| 23 | +# Clone to custom directory |
| 24 | +python3 setup.py -w /path/to/workdir -c |
| 25 | +``` |
54 | 26 |
|
55 | 27 | Options: |
56 | 28 |
|
57 | | -- `-w` or `--workdir`: Specify the working directory (default is your home directory) |
58 | | -- `-c` or `--clone`: Clone the gnoswap repository before setting up |
59 | | - |
60 | | -The script will perform all necessary steps to set up the GnoSwap contracts in the specified directory. |
61 | | - |
62 | | -<details> |
63 | | -<summary><h3>Setting Up GnoSwap Contracts Manually</h3></summary> |
64 | | - |
65 | | -> Important: This manual setup method is not recommended and should only be used as a last resort. If the setup script is not working properly, please create an issue in the repository. |
66 | | -
|
67 | | -This section guides you through the process of setting up GnoSwap contracts. The process involves three main steps: cloning the `gnoswap` repository, copying the contracts to the `gno` directory, and moving test cases to their respective directories. |
68 | | - |
69 | | -1. Clone the repository: |
70 | | - |
71 | | - ```bash |
72 | | - cd $WORKDIR |
73 | | - git clone https://github.com/gnoswap-labs/gnoswap.git |
74 | | - cd gnoswap |
75 | | - ``` |
76 | | - |
77 | | -2. Understand the directory structure pattern: |
78 | | - |
79 | | - ```tree |
80 | | - contract/ |
81 | | - ├── p/ # Packages directory |
82 | | - │ └── gnoswap/ |
83 | | - │ ├── gnsmath/ |
84 | | - │ └── ... |
85 | | - └── r/ # Realms directory |
86 | | - └── gnoswap/ |
87 | | - ├── common/ |
88 | | - ├── pool/ |
89 | | - └── ... |
90 | | - ``` |
91 | | - |
92 | | -3. Create the base directories: |
93 | | - |
94 | | - ```bash |
95 | | - # Create directories for packages and realms |
96 | | - mkdir -p $WORKDIR/gno/examples/gno.land/p/gnoswap |
97 | | - mkdir -p $WORKDIR/gno/examples/gno.land/r/gnoswap/v1 |
98 | | - ``` |
99 | | - |
100 | | -4. Copy files following these patterns: |
101 | | - |
102 | | - For packages: |
103 | | - |
104 | | - ```bash |
105 | | - # Pattern: |
106 | | - cp -R contract/p/gnoswap/<package_name> $WORKDIR/gno/examples/gno.land/p/gnoswap/ |
107 | | - |
108 | | - # Examples: |
109 | | - cp -R contract/p/gnoswap/consts $WORKDIR/gno/examples/gno.land/p/gnoswap/ |
110 | | - cp -R contract/p/gnoswap/gnsmath $WORKDIR/gno/examples/gno.land/p/gnoswap/ |
111 | | - ``` |
112 | | - |
113 | | - For realm modules: |
114 | | - |
115 | | - ```bash |
116 | | - # Pattern: |
117 | | - cp -R contract/r/gnoswap/<module_name> $WORKDIR/gno/examples/gno.land/r/gnoswap/v1/ |
| 29 | +- `-w` or `--workdir`: Specify working directory (default: home directory) |
| 30 | +- `-c` or `--clone`: Clone gnoswap repository before setup |
118 | 31 |
|
119 | | - # Examples: |
120 | | - cp -R contract/r/gnoswap/pool $WORKDIR/gno/examples/gno.land/r/gnoswap/v1/ |
121 | | - cp -R contract/r/gnoswap/router $WORKDIR/gno/examples/gno.land/r/gnoswap/v1/ |
122 | | - ``` |
| 32 | +If the setup script fails, you can manually copy contracts: |
123 | 33 |
|
124 | | - For test tokens: |
| 34 | +1. Clone repository: |
125 | 35 |
|
126 | | - ```bash |
127 | | - # Pattern: |
128 | | - cp -R contract/r/gnoswap/test_token/<token_name> $WORKDIR/gno/examples/gno.land/r/ |
129 | | - |
130 | | - # Example: |
131 | | - cp -R contract/r/gnoswap/test_token/usdc $WORKDIR/gno/examples/gno.land/r/ |
132 | | - ``` |
133 | | - |
134 | | -5. Verify the setup: |
135 | | - |
136 | | - ```bash |
137 | | - cd $WORKDIR/gno/examples |
138 | | - gno test -root-dir $WORKDIR/gno -v=false ./gno.land/r/gnoswap/v1/pool |
139 | | - ``` |
140 | | - |
141 | | -> Note: The setup maintains the original directory structure, including test files which are now part of their respective packages. |
142 | | -
|
143 | | -</details> |
144 | | - |
145 | | -### Directory Structure Overview |
146 | | - |
147 | | -Key directories and their purposes: |
148 | | - |
149 | | -- `p/gnoswap/`: Core packages including math utilities and constants |
150 | | -- `r/gnoswap/v1/`: Protocol realms (pool, router, position, etc.) |
151 | | -- `r/gnoswap/test_token/`: Test tokens for development |
152 | | - |
153 | | -Once you understand these patterns, you can copy any additional modules using the same structure. |
| 36 | +```bash |
| 37 | +git clone https://github.com/gnoswap-labs/gnoswap.git |
| 38 | +``` |
154 | 39 |
|
155 | | -### Running Tests |
| 40 | +2. Copy packages: |
156 | 41 |
|
157 | | -While it's possible to run tests in the cloned `gno` directory (where the above setup process was completed), it's recommended to run them in the `gnoswap` directory to avoid confusion due to the large number of changed files. |
| 42 | +```bash |
| 43 | +mkdir -p $WORKDIR/gno/examples/gno.land/p/gnoswap |
| 44 | +cp -R contract/p/gnoswap/* $WORKDIR/gno/examples/gno.land/p/gnoswap/ |
| 45 | +``` |
158 | 46 |
|
159 | | -First, navigate to the `gno/examples` directory: |
| 47 | +3. Copy realms: |
160 | 48 |
|
161 | 49 | ```bash |
162 | | -cd $WORKDIR/gno/examples |
| 50 | +mkdir -p $WORKDIR/gno/examples/gno.land/r/gnoswap/v1 |
| 51 | +cp -R contract/r/gnoswap/* $WORKDIR/gno/examples/gno.land/r/gnoswap/v1/ |
163 | 52 | ``` |
164 | 53 |
|
165 | | -Next, move to the Realm directory you want to test (such as `pool`, `staker`, etc.), then run the tests using the `gno test` command: |
| 54 | +4. Copy test tokens: |
166 | 55 |
|
167 | 56 | ```bash |
168 | | -gno test -root-dir $WORKDIR/gno -v=false ./gno.land/r/gnoswap/v1/pool |
| 57 | +cp -R contract/r/gnoswap/test_token/* $WORKDIR/gno/examples/gno.land/r/ |
169 | 58 | ``` |
170 | 59 |
|
171 | | -## Realms |
| 60 | +## Directory Structure |
172 | 61 |
|
173 | | -### Core Realms Deployed on Testnet5 |
174 | | - |
175 | | -- pool: [gno.land/r/gnoswap/v1/pool](https://gnoscan.io/realms/details?path=gno.land/r/gnoswap/v1/pool) |
176 | | -- position: [gno.land/r/gnoswap/v1/position](https://gnoscan.io/realms/details?path=gno.land/r/gnoswap/v1/position) |
177 | | -- router: [gno.land/r/gnoswap/v1/router](https://gnoscan.io/realms/details?path=gno.land/r/gnoswap/v1/router) |
178 | | -- staker: [gno.land/r/gnoswap/v1/staker](https://gnoscan.io/realms/details?path=gno.land/r/gnoswap/v1/staker) |
| 62 | +``` |
| 63 | +gnoswap/ |
| 64 | +├── contract/ # Smart contracts |
| 65 | +│ ├── p/ # Packages (libraries) |
| 66 | +│ │ └── gnoswap/ |
| 67 | +│ │ ├── gnsmath/ # AMM math utilities |
| 68 | +│ │ ├── int256/ # 256-bit signed integers |
| 69 | +│ │ ├── uint256/ # 256-bit unsigned integers |
| 70 | +│ │ ├── rbac/ # Role-based access control |
| 71 | +│ │ └── consts/ # Protocol constants |
| 72 | +│ │ |
| 73 | +│ └── r/ # Realms (contracts) |
| 74 | +│ └── gnoswap/ |
| 75 | +│ ├── v1/ # Protocol v1 contracts |
| 76 | +│ │ ├── pool/ # Concentrated liquidity pools |
| 77 | +│ │ ├── position/ # LP position NFTs |
| 78 | +│ │ ├── router/ # Swap routing |
| 79 | +│ │ ├── staker/ # Liquidity mining |
| 80 | +│ │ ├── gov/ # Governance |
| 81 | +│ │ ├── launchpad/ # Token distribution |
| 82 | +│ │ ├── protocol_fee/ # Fee management |
| 83 | +│ │ └── community_pool/ # Treasury |
| 84 | +│ │ |
| 85 | +│ ├── access/ # Access control |
| 86 | +│ ├── emission/ # GNS emission |
| 87 | +│ ├── gns/ # GNS token |
| 88 | +│ ├── halt/ # Emergency pause |
| 89 | +│ ├── rbac/ # RBAC realm |
| 90 | +│ ├── referral/ # Referral system |
| 91 | +│ └── test_token/ # Test tokens |
| 92 | +│ |
| 93 | +├── tests/ # Test suites |
| 94 | +│ ├── scenario/ # Scenario-based tests |
| 95 | +│ ├── integration/ # Integration tests |
| 96 | +│ └── deploy/ # Deployment scripts |
| 97 | +│ |
| 98 | +└── scripts/ # Utility scripts |
| 99 | +``` |
179 | 100 |
|
180 | | -## Development Environment Setup |
| 101 | +## Testing |
181 | 102 |
|
182 | | -### Using Docker (Recommended) |
| 103 | +### Run All Tests |
183 | 104 |
|
184 | | -1. Build the Docker image: |
185 | 105 | ```bash |
186 | | -make docker-build |
| 106 | +make test |
187 | 107 | ``` |
188 | 108 |
|
189 | | -2. Start the container: |
190 | | -```bash |
191 | | -make docker-up |
192 | | -``` |
| 109 | +### Run Specific Scenario Tests |
193 | 110 |
|
194 | | -3. Access the container shell: |
195 | 111 | ```bash |
196 | | -make docker-shell |
| 112 | +make test-folder FOLDER=tests/scenario/pool |
| 113 | +make test-folder FOLDER=tests/scenario/router |
197 | 114 | ``` |
198 | 115 |
|
199 | | -4. View logs: |
200 | | -```bash |
201 | | -make docker-logs |
202 | | -``` |
| 116 | +### Run Integration Tests |
203 | 117 |
|
204 | | -5. Stop the container: |
205 | 118 | ```bash |
206 | | -make docker-down |
| 119 | +cd $WORKDIR/gno/examples |
| 120 | +gno test -root-dir $WORKDIR/gno -v=false ./gno.land/r/gnoswap/v1/pool |
207 | 121 | ``` |
208 | 122 |
|
209 | | -### Manual Setup |
| 123 | +## Security |
210 | 124 |
|
211 | | -If you prefer to set up the environment manually: |
| 125 | +GnoSwap implements multiple layers of security across all contracts. For security concerns or vulnerability reports, see [SECURITY.md](SECURITY.md). |
212 | 126 |
|
213 | | -1. Install Python 3.11 or later |
214 | | -2. Install uv package manager: |
215 | | -```bash |
216 | | -pip install uv |
217 | | -``` |
| 127 | +## License |
218 | 128 |
|
219 | | -3. Create a virtual environment and install dependencies: |
220 | | -```bash |
221 | | -uv venv |
222 | | -source .venv/bin/activate # On Unix/macOS |
223 | | -# or |
224 | | -.venv\Scripts\activate # On Windows |
225 | | -uv pip install -r requirements.txt |
226 | | -``` |
| 129 | +Licensed under the GNU Affero General Public License v3.0. See [LICENSE](LICENSE) for details. |
| 130 | + |
| 131 | +## Contributing |
| 132 | + |
| 133 | +Contributions are welcome! Please follow existing patterns, include tests, and maintain documentation. |
0 commit comments