Skip to content

Commit

Permalink
split DeployToken to DeployToken and Approve
Browse files Browse the repository at this point in the history
  • Loading branch information
ujnss committed Sep 29, 2024
1 parent 7b98a7d commit ee3f346
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 31 deletions.
29 changes: 26 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,9 @@ HOOK=0xd9Dd1FEaF845Dd036245A504317cCccE7Bc18f49
Add/replace the above address in `.env`.


### Testing

### Before Testing

- Test Initialize
- Initialize Pool

```sh
source .env
Expand All @@ -97,6 +96,30 @@ This command only needs to be executed once.

<br/>

- Transfer Token (Optional)

Request some tokens from the Token owner. (If necessary)

```sh
source .env
export RECEIVER=<the receiver address>
# export RECEIVER=0x...
forge script script/Transfer.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
```

<br/>

- Token Approve

Before swap testing, need approve first.

```sh
source .env
forge script script/Approve.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
```

### Testing

- Test AddLiquidity

```sh
Expand Down
63 changes: 63 additions & 0 deletions script/Approve.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol";
import {Currency} from "pancake-v4-core/src/types/Currency.sol";
import {SortTokens} from "pancake-v4-core/test/helpers/SortTokens.sol";
import {CLPositionManager} from "pancake-v4-periphery/src/pool-cl/CLPositionManager.sol";
import {ICLPositionManager} from "pancake-v4-periphery/src/pool-cl/interfaces/ICLPositionManager.sol";
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {UniversalRouter} from "pancake-v4-universal-router/src/UniversalRouter.sol";

import {console} from "forge-std/console.sol";
import "forge-std/Script.sol";

contract DeployTokenScript is Script {

function run() public {
console.log("msg.sender %s", msg.sender);
console.log("script %s", address(this));

uint256 privateKey = vm.envUint("PRIVATE_KEY");
address signerAddr = vm.addr(privateKey);
console.log("SIGNER=%s", signerAddr);

vm.startBroadcast(privateKey);

_deploy();

vm.stopBroadcast();
}

// prettier-ignore
function _deploy() internal {
address _token0 = vm.envAddress("TOKEN0");
console.log("_token0=%s", _token0);
address _token1 = vm.envAddress("TOKEN1");
console.log("_token1=%s", _token1);
address _positionManager = vm.envAddress("CL_POSITION_MANAGER");
console.log("_positionManager=%s", _positionManager);
address _universalRouter = vm.envAddress("UNIVERSAL_ROUTER");
console.log("_universalRouter=%s", _universalRouter);
CLPositionManager positionManager = CLPositionManager(_positionManager);
UniversalRouter universalRouter = UniversalRouter(payable(_universalRouter));
IAllowanceTransfer permit2 = positionManager.permit2();

MockERC20 token0 = MockERC20(_token0);
MockERC20 token1 = MockERC20(_token1);

// approve permit2 contract to transfer our funds
token0.approve(address(permit2), type(uint256).max);
token1.approve(address(permit2), type(uint256).max);

permit2.approve(address(token0), address(positionManager), type(uint160).max, type(uint48).max);
permit2.approve(address(token1), address(positionManager), type(uint160).max, type(uint48).max);

permit2.approve(address(token0), address(universalRouter), type(uint160).max, type(uint48).max);
permit2.approve(address(token1), address(universalRouter), type(uint160).max, type(uint48).max);
}
}
/*
source .env
forge script script/Approve.s.sol --rpc-url $RPC_URL --private-key $PRIVATE_KEY --broadcast
*/
29 changes: 1 addition & 28 deletions script/DeployToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,11 @@ pragma solidity ^0.8.24;
import {MockERC20} from "solmate/src/test/utils/mocks/MockERC20.sol";
import {Currency} from "pancake-v4-core/src/types/Currency.sol";
import {SortTokens} from "pancake-v4-core/test/helpers/SortTokens.sol";
import {PoolKey} from "pancake-v4-core/src/types/PoolKey.sol";
import {CLPositionManager} from "pancake-v4-periphery/src/pool-cl/CLPositionManager.sol";
import {ICLPositionManager} from "pancake-v4-periphery/src/pool-cl/interfaces/ICLPositionManager.sol";
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {UniversalRouter} from "pancake-v4-universal-router/src/UniversalRouter.sol";
import {PoolIdLibrary} from "pancake-v4-core/src/types/PoolId.sol";

import {console} from "forge-std/console.sol";
import "forge-std/Script.sol";

contract DeployTokenScript is Script {
// using Planner for Plan;
using PoolIdLibrary for PoolKey;

function run() public {
console.log("msg.sender %s", msg.sender);
console.log("script %s", address(this));
Expand All @@ -35,29 +26,11 @@ contract DeployTokenScript is Script {

// prettier-ignore
function _deploy() internal {
address _positionManager = vm.envAddress("CL_POSITION_MANAGER");
// console.log("_positionManager=%s", _positionManager);
address _universalRouter = vm.envAddress("UNIVERSAL_ROUTER");
// console.log("_universalRouter=%s", _universalRouter);
CLPositionManager positionManager = CLPositionManager(_positionManager);
UniversalRouter universalRouter = UniversalRouter(payable(_universalRouter));
IAllowanceTransfer permit2 = positionManager.permit2();

MockERC20 token0 = new MockERC20("token0", "T0", 18);
MockERC20 token1 = new MockERC20("token1", "T1", 18);
token0.mint(msg.sender, 10000000000 ether);
token1.mint(msg.sender, 10000000000 ether);

// approve permit2 contract to transfer our funds
token0.approve(address(permit2), type(uint256).max);
token1.approve(address(permit2), type(uint256).max);

permit2.approve(address(token0), address(positionManager), type(uint160).max, type(uint48).max);
permit2.approve(address(token1), address(positionManager), type(uint160).max, type(uint48).max);

permit2.approve(address(token0), address(universalRouter), type(uint160).max, type(uint48).max);
permit2.approve(address(token1), address(universalRouter), type(uint160).max, type(uint48).max);


(Currency currency0, Currency currency1)= SortTokens.sort(token0, token1);
console.log("TOKEN0=%s", Currency.unwrap(currency0));
console.log("TOKEN1=%s", Currency.unwrap(currency1));
Expand Down

0 comments on commit ee3f346

Please sign in to comment.