Skip to content

Commit 5a7d7ab

Browse files
committed
Fixed Scripts
-Fixed Run Functions in Sctips -Updated README.md
1 parent e7e76cb commit 5a7d7ab

4 files changed

Lines changed: 68 additions & 11 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ It is a smart contract project written in [Solidity](https://docs.soliditylang.o
4040
SEPOLIA_RPC_URL=<YOUR SEPOLIA RPC URL>
4141
ETHERSCAN_API_KEY=<YOUR ETHERSCAN API KEY>
4242
SEPOLIA_PRIVATE_KEY=<YOUR PRIVATE KEY>
43+
44+
# Arguments for Pool Deployment
45+
TOKEN_A=<ADDRESS OF TOKEN A>
46+
TOKEN_B=<ADDRESS OF TOKEN B>
47+
FEE=<FEES IN BASIS POINTS(either 500, 3000 or 10000)>
48+
INITIAL_SQRT_PRICE_X96=<INTIAL SQUARE ROOT PRICE X96>
49+
50+
# Arguments for Position Management
51+
LOWER_TICK=-<LOWER TICK>
52+
UPPER_TICK=<UPPER TICK>
53+
AMOUNT_TO_ADD=<AMOUNT OF LIQUIDITY TO ADD>
54+
AMOUNT_TO_REMOVE=<AMOUNT OF LIQUIDITY TO REMOVE>
55+
56+
# Arguments for Collection of Fees or Removed/Burned Liquidity
57+
AMOUNT0_TO_COLLECT=<AMOUNT OF TOKEN A TO COLLECT>
58+
AMOUNT1_TO_COLLECT=<AMOUNT OF TOKEN B TO COLLECT>
59+
60+
# Arguments for Swap Management
61+
SWAP_AMOUNT=<AMOUNT OF TOKENS TO SWAP>
62+
SQRT_PRICE_LIMIT_X96=<SQRT PRICE LIMIT X96 WHILE SWAPPING>
4363
```
4464
- Remove pre installed cache, unecessary or partially cloned modules modules etc.
4565
```bash

script/CLAMMPoolDeployer.s.sol

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,25 @@ contract CLAMMPoolDeployer is Script {
1717
mapping(address => mapping(address => mapping(uint24 => address))) public poolForPair;
1818

1919
constructor() {
20-
owner = msg.sender;
20+
// vm.startBroadcast();
21+
// // Set the owner to the address that deploys the contract
22+
// owner = msg.sender;
23+
// vm.stopBroadcast();
24+
25+
console.log("owner in contructor", owner);
2126

2227
// Initialize the feeToTickSpacing mapping with values
2328
feeToTickSpacing[500] = 10;
2429
feeToTickSpacing[3000] = 60;
2530
feeToTickSpacing[10000] = 200;
2631
}
2732

28-
function run(address tokenA, address tokenB, uint24 fee, uint160 initialSqrtPriceX96) public returns (CLAMMPool) {
33+
function run() public returns (CLAMMPool) {
34+
address tokenA = vm.envAddress("TOKEN_A");
35+
address tokenB = vm.envAddress("TOKEN_B");
36+
uint24 fee = uint24(vm.envUint("FEE"));
37+
uint160 initialSqrtPriceX96 = uint160(vm.envUint("INITIAL_SQRT_PRICE_X96"));
38+
2939
if (tokenA == address(0) || tokenB == address(0)) {
3040
revert CLAMMPoolDeployer__InvalidTokenAddressEntered();
3141
}
@@ -35,7 +45,9 @@ contract CLAMMPoolDeployer is Script {
3545
if (feeToTickSpacing[fee] == 0) {
3646
revert CLAMMPoolDeployer__InvalidFeeEntered();
3747
}
38-
if (msg.sender != owner) {
48+
if (owner != address(0) && msg.sender != owner) {
49+
console.log("msg.sender", msg.sender);
50+
console.log("owner", owner);
3951
revert CLAMMPoolDeployer__NotOwner();
4052
}
4153
return deployCLAMMPoolContract(tokenA, tokenB, fee, initialSqrtPriceX96);
@@ -57,6 +69,7 @@ contract CLAMMPoolDeployer is Script {
5769
// Deploy the CLAMMPool contract
5870
CLAMMPool clammPool = new CLAMMPool(_tokenA, _tokenB, fee, feeToTickSpacing[fee]);
5971
clammPool.initialize(initialSqrtPriceX96);
72+
if (owner == address(0)) owner = msg.sender;
6073

6174
vm.stopBroadcast();
6275

script/Interactions.s.sol

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {DevOpsTools} from "../lib/foundry-devops/src/DevOpsTools.sol";
1111
* Position Management
1212
*/
1313
contract AddLiquidity is Script {
14-
function run(int24 tickLower, int24 tickUpper, uint128 amount) public {
14+
function run() public {
15+
int24 tickLower = int24(uint24(vm.envUint("LOWER_TICK")));
16+
int24 tickUpper = int24(uint24(vm.envUint("UPPER_TICK")));
17+
uint128 amount = uint128(vm.envUint("AMOUNT_TO_ADD"));
18+
1519
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
1620
CLAMMPool clammPool = CLAMMPool(recentDeployment);
1721

@@ -23,7 +27,11 @@ contract AddLiquidity is Script {
2327
}
2428

2529
contract RemoveLiquidity is Script {
26-
function run(int24 tickLower, int24 tickUpper, uint128 amount) public {
30+
function run() public {
31+
int24 tickLower = int24(uint24(vm.envUint("LOWER_TICK")));
32+
int24 tickUpper = int24(uint24(vm.envUint("UPPER_TICK")));
33+
uint128 amount = uint128(vm.envUint("AMOUNT_TO_REMOVE"));
34+
2735
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
2836
CLAMMPool clammPool = CLAMMPool(recentDeployment);
2937

@@ -38,7 +46,12 @@ contract RemoveLiquidity is Script {
3846
* Collect Fees or Removed/Burned Liquidity
3947
*/
4048
contract CollectFeesAndRemovedLiquidity is Script {
41-
function run(int24 tickLower, int24 tickUpper, uint128 amount0Requested, uint128 amount1Requested) public {
49+
function run() public {
50+
int24 tickLower = int24(uint24(vm.envUint("LOWER_TICK")));
51+
int24 tickUpper = int24(uint24(vm.envUint("UPPER_TICK")));
52+
uint128 amount0Requested = uint128(vm.envUint("AMOUNT0_TO_COLLECT"));
53+
uint128 amount1Requested = uint128(vm.envUint("AMOUNT1_TO_COLLECT"));
54+
4255
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
4356
CLAMMPool clammPool = CLAMMPool(recentDeployment);
4457

@@ -53,7 +66,10 @@ contract CollectFeesAndRemovedLiquidity is Script {
5366
* Swap Management
5467
*/
5568
contract SwapTokensZeroForOneExactInput is Script {
56-
function run(uint256 amount, uint160 sqrtPriceLimitX96) public {
69+
function run() public {
70+
uint256 amount = uint256(vm.envUint("SWAP_AMOUNT"));
71+
uint160 sqrtPriceLimitX96 = uint160(vm.envUint("SQRT_PRICE_LIMIT_X96"));
72+
5773
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
5874
CLAMMPool clammPool = CLAMMPool(recentDeployment);
5975

@@ -65,7 +81,10 @@ contract SwapTokensZeroForOneExactInput is Script {
6581
}
6682

6783
contract SwapTokensOneForZeroExactInput is Script {
68-
function run(uint256 amount, uint160 sqrtPriceLimitX96) public {
84+
function run() public {
85+
uint256 amount = uint256(vm.envUint("SWAP_AMOUNT"));
86+
uint160 sqrtPriceLimitX96 = uint160(vm.envUint("SQRT_PRICE_LIMIT_X96"));
87+
6988
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
7089
CLAMMPool clammPool = CLAMMPool(recentDeployment);
7190

@@ -77,7 +96,10 @@ contract SwapTokensOneForZeroExactInput is Script {
7796
}
7897

7998
contract SwapTokensZeroForOneExactOutput is Script {
80-
function run(uint256 amount, uint160 sqrtPriceLimitX96) public {
99+
function run() public {
100+
uint256 amount = uint256(vm.envUint("SWAP_AMOUNT"));
101+
uint160 sqrtPriceLimitX96 = uint160(vm.envUint("SQRT_PRICE_LIMIT_X96"));
102+
81103
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
82104
CLAMMPool clammPool = CLAMMPool(recentDeployment);
83105

@@ -89,7 +111,10 @@ contract SwapTokensZeroForOneExactOutput is Script {
89111
}
90112

91113
contract SwapTokensOneForZeroExactOutput is Script {
92-
function run(uint256 amount, uint160 sqrtPriceLimitX96) public {
114+
function run() public {
115+
uint256 amount = uint256(vm.envUint("SWAP_AMOUNT"));
116+
uint160 sqrtPriceLimitX96 = uint160(vm.envUint("SQRT_PRICE_LIMIT_X96"));
117+
93118
address recentDeployment = DevOpsTools.get_most_recent_deployment("CLAMMPool", block.chainid);
94119
CLAMMPool clammPool = CLAMMPool(recentDeployment);
95120

src/CLAMMPool.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ contract CLAMMPool {
173173
lock
174174
returns (uint256 amount0, uint256 amount1)
175175
{
176-
// mint logic
177176
if (amount <= 0) revert CLAMMPool__AmountInvalid();
178177
(, int256 amount0Int, int256 amount1Int) = _modifyPosition(
179178
ModifyPositionParams({

0 commit comments

Comments
 (0)