Skip to content

Commit d0e7dfe

Browse files
author
DESKTOP-D0CTM2M\hp
committed
Initial commit for new feature
0 parents  commit d0e7dfe

39 files changed

+21450
-0
lines changed

.github/workflows/test.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
FOUNDRY_PROFILE: ci
10+
11+
jobs:
12+
check:
13+
strategy:
14+
fail-fast: true
15+
16+
name: Foundry project
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: recursive
22+
23+
- name: Install Foundry
24+
uses: foundry-rs/foundry-toolchain@v1
25+
26+
- name: Show Forge version
27+
run: |
28+
forge --version
29+
30+
- name: Run Forge fmt
31+
run: |
32+
forge fmt --check
33+
id: fmt
34+
35+
- name: Run Forge build
36+
run: |
37+
forge build --sizes
38+
id: build
39+
40+
- name: Run Forge tests
41+
run: |
42+
forge test -vvv
43+
id: test

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
node_modules
2+
.env
3+
4+
# Hardhat files
5+
/cache
6+
/artifacts
7+
8+
# TypeChain files
9+
/typechain
10+
/typechain-types
11+
12+
# solidity-coverage files
13+
/coverage
14+
/coverage.json
15+
16+
# Hardhat Ignition default folder for deployments against a local node
17+
ignition/deployments/chain-31337
18+
.DS_Store
19+
20+
# Foundry files
21+
/out
22+
/cache_forge
23+
/broadcast
24+
/lib
25+
26+
# Editor files
27+
*.swp
28+
*.swo
29+
.vscode/
30+
31+
# Sensitive information
32+
*.private
33+
*private*.txt
34+
*secret*.txt
35+
*key*.txt
36+
*password*.txt
37+
38+
# Deployment artifacts
39+
cache/

.gitmodules

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[submodule "lib/forge-std"]
2+
path = lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/v4-core"]
5+
path = lib/v4-core
6+
url = https://github.com/uniswap/v4-core
7+
branch = main
8+
[submodule "lib/v4-periphery"]
9+
path = lib/v4-periphery
10+
url = https://github.com/uniswap/v4-periphery
11+
branch = main
12+
[submodule "lib/openzeppelin-contracts"]
13+
path = lib/openzeppelin-contracts
14+
url = https://github.com/OpenZeppelin/openzeppelin-contracts
15+
[submodule "lib/uniswap-hooks"]
16+
path = lib/uniswap-hooks
17+
url = https://github.com/uniswap/v4-periphery
18+
branch = main

README.md

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
# AutoGrowingLPToken
2+
3+
AutoGrowingLPToken is an ERC20 token built on Uniswap V4 that automatically grows in price based on purchase volume. It implements Uniswap V4 hooks to manage liquidity and fees.
4+
5+
## Features
6+
7+
- **Auto-Growing Price**: Each 1 ETH of purchase volume increases the token price by 0.1%
8+
- **Automatic Liquidity**: 50% of incoming ETH is automatically added to liquidity
9+
- **Fee Collection**: The contract collects trading fees and burns tokens to further increase value
10+
- **Owner Controls**: Owner can adjust fee parameters and distribution ratios
11+
12+
## Prerequisites
13+
14+
- [Foundry](https://book.getfoundry.sh/getting-started/installation)
15+
- [Node.js](https://nodejs.org/) (v16 or later)
16+
- [pnpm](https://pnpm.io/installation)
17+
18+
## Installation
19+
20+
1. Clone the repository:
21+
22+
```bash
23+
git clone https://github.com/yourusername/AutoGrowingLPToken.git
24+
cd AutoGrowingLPToken
25+
```
26+
27+
2. Install dependencies:
28+
29+
```bash
30+
pnpm install
31+
forge install
32+
```
33+
34+
## Project Structure
35+
36+
- `src/token.sol`: Main token contract implementing Uniswap V4 hooks
37+
- `script/DeployBaseTestnet.sol`: Deployment script for Base Sepolia testnet
38+
- `script/DeployTokenHook.s.sol`: Deployment script for local testing
39+
- `test/utils/HookMiner.sol`: Utility for mining hook addresses with specific flags
40+
41+
## Local Deployment
42+
43+
### 1. Start a Local Ethereum Node
44+
45+
Start Anvil (local Ethereum node):
46+
47+
```bash
48+
anvil
49+
```
50+
51+
This will start a local Ethereum node at `http://localhost:8545` with predefined accounts and private keys.
52+
53+
### 2. Deploy the Uniswap V4 PoolManager
54+
55+
Before deploying the token, you need to deploy the Uniswap V4 PoolManager contract:
56+
57+
```bash
58+
# Deploy the PoolManager contract
59+
forge script script/DeployPoolManager.s.sol:DeployPoolManager --rpc-url http://localhost:8545 --broadcast
60+
```
61+
62+
Note the address of the deployed PoolManager contract. You'll need to update the `POOL_MANAGER_ADDRESS` in the `DeployTokenHook.s.sol` script.
63+
64+
### 3. Update Deployment Configuration
65+
66+
Edit the `script/DeployTokenHook.s.sol` file to set your desired configuration:
67+
68+
```solidity
69+
// Configuration parameters
70+
string public constant TOKEN_NAME = "AutoGrowingLPToken";
71+
string public constant TOKEN_SYMBOL = "AGLP";
72+
address public constant DEV_WALLET = 0x70997970C51812dc3A010C7d01b50e0d17dc79C8; // Using the second anvil account
73+
uint160 public constant INITIAL_SQRT_PRICE = 79228162514264337593543950336; // 1:1 price
74+
75+
// PoolManager address (update this with your deployed PoolManager address)
76+
address public constant POOL_MANAGER_ADDRESS = 0x5FbDB2315678afecb367f032d93F642f64180aa3;
77+
```
78+
79+
### 4. Deploy the Token
80+
81+
Deploy the AutoGrowingLPToken contract:
82+
83+
```bash
84+
forge script script/DeployTokenHook.s.sol:DeployTokenHook --rpc-url http://localhost:8545 --broadcast -vvv
85+
```
86+
87+
This will:
88+
1. Mine a hook address with the correct flags
89+
2. Deploy the token contract to the mined address
90+
3. Initialize the pool with the specified price
91+
92+
## Base Sepolia Testnet Deployment
93+
94+
The project is already deployed on Base Sepolia testnet at address: `0x6121E72870F6a7a782Bd746A07245d90162c1440`
95+
96+
To deploy your own instance to Base Sepolia, follow these steps:
97+
98+
### 1. Update Deployment Configuration
99+
100+
Edit the `script/DeployBaseTestnet.sol` file to set your configuration:
101+
102+
```solidity
103+
// Configuration parameters
104+
string public constant TOKEN_NAME = "AutoGrowingLPToken";
105+
string public constant TOKEN_SYMBOL = "AGLP";
106+
address public constant DEV_WALLET = 0xYourDevWalletAddress; // Update with your wallet
107+
uint160 public constant INITIAL_SQRT_PRICE = 79228162514264337593543950336; // 1:1 price
108+
109+
// Base Sepolia PoolManager address (this is the correct address for Base Sepolia)
110+
address public constant POOL_MANAGER_ADDRESS = 0x05E73354cFDd6745C338b50BcFDfA3Aa6fA03408;
111+
112+
// Canonical CREATE2 factory address (same on all EVM chains including Base Sepolia)
113+
address public constant SINGLETON_FACTORY = 0xce0042B868300000d44A59004Da54A005ffdcf9f;
114+
115+
// Your private key - IMPORTANT: Handle this securely!
116+
uint256 constant PRIVATE_KEY = 0xYourPrivateKeyHere;
117+
```
118+
119+
### 2. Run the Deployment Script
120+
121+
We've created a convenient deployment script for Base Sepolia. Run it with:
122+
123+
```bash
124+
./deploy-base-sepolia.sh
125+
```
126+
127+
This script:
128+
1. Uses the canonical CREATE2 factory to deploy with deterministic addresses
129+
2. Finds a salt that produces a valid hook address with the correct flags
130+
3. Deploys the contract using the found salt
131+
4. Initializes the Uniswap V4 pool
132+
133+
### 3. Verify the Contract on Base Sepolia Explorer
134+
135+
After deployment, verify your contract with:
136+
137+
```bash
138+
./verify-contract.sh
139+
```
140+
141+
Make sure to update the script with:
142+
- Your contract address from the deployment
143+
- Your Base Sepolia API key
144+
- The correct constructor arguments
145+
146+
## How It Works: Base Sepolia Deployment
147+
148+
The deployment process for Base Sepolia uses a specific approach to ensure compatibility with Uniswap V4:
149+
150+
1. **Canonical CREATE2 Factory**: We use the EIP-2470 Singleton Factory at `0xce0042B868300000d44A59004Da54A005ffdcf9f` which exists at the same address on all EVM chains.
151+
152+
2. **Hook Address Mining**: Uniswap V4 requires hook addresses to have specific bits set in their address to indicate which hooks they implement. Our `HookMiner` utility finds a salt value that produces a valid hook address.
153+
154+
3. **Deployment**: The contract is deployed using the CREATE2 factory with the found salt, ensuring it has the correct address format.
155+
156+
4. **Pool Initialization**: After deployment, the script initializes the Uniswap V4 pool with the specified initial price.
157+
158+
## Interacting with the Token on Base Sepolia
159+
160+
After deployment, you can interact with the token using the following methods:
161+
162+
### Buying Tokens
163+
164+
Send ETH directly to the token contract to purchase tokens:
165+
166+
```bash
167+
cast send <TOKEN_ADDRESS> --value <ETH_AMOUNT_IN_WEI> --rpc-url https://sepolia.base.org --private-key <PRIVATE_KEY>
168+
```
169+
170+
### Checking Token Price
171+
172+
Get the current token price:
173+
174+
```bash
175+
cast call <TOKEN_ADDRESS> "getCurrentPrice()" --rpc-url https://sepolia.base.org
176+
```
177+
178+
### Collecting Fees
179+
180+
Trigger fee collection and token burning:
181+
182+
```bash
183+
cast send <TOKEN_ADDRESS> "collectFeesAndBurn()" --rpc-url https://sepolia.base.org --private-key <PRIVATE_KEY>
184+
```
185+
186+
## Requirements for Base Sepolia Deployment
187+
188+
1. **Base Sepolia Requirements**:
189+
- Private key with Base Sepolia ETH
190+
- Base Sepolia RPC URL (https://sepolia.base.org)
191+
- Base Sepolia API key for verification
192+
193+
2. **Security Considerations**:
194+
- Never commit your private key to Git
195+
- Consider using environment variables for sensitive information
196+
- Always verify your contract after deployment for transparency
197+
198+
## License
199+
200+
MIT

0 commit comments

Comments
 (0)