|
| 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