-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeployAutoWrapperAndInitPool.s.sol
More file actions
97 lines (87 loc) · 4.54 KB
/
Copy pathDeployAutoWrapperAndInitPool.s.sol
File metadata and controls
97 lines (87 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import "forge-std/Script.sol";
import {Hooks} from "@uniswap/v4-core/src/libraries/Hooks.sol";
import {IHooks} from "@uniswap/v4-core/src/interfaces/IHooks.sol";
import {IPoolManager} from "@uniswap/v4-core/src/interfaces/IPoolManager.sol";
import {INetwork} from "./INetwork.sol";
import {V4Router} from "@uniswap/v4-periphery/src/V4Router.sol";
import {NetworkSelector} from "./NetworkSelector.sol";
import {ERC4626} from "@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {AutoWrapper} from "../../src/AutoWrapper.sol";
import {PoolKey} from "@uniswap/v4-core/src/types/PoolKey.sol";
import {Currency} from "@uniswap/v4-core/src/types/Currency.sol";
import {HookMiner} from "../../test/utils/HookMiner.sol";
import {Constants} from "@uniswap/v4-core/test/utils/Constants.sol";
contract DeployAutoWrapperAndInitPool is Script {
INetwork private _env;
address private _hookAddress;
V4Router private _swapRouter;
int24 private _tickSpacing;
function _init() internal {
bool networkExists = vm.envExists("NETWORK");
bool hookAddressExists = vm.envExists("HOOK_ADDRESS");
bool swapRouterExists = vm.envExists("SWAP_ROUTER_ADDRESS");
require(
networkExists && hookAddressExists && swapRouterExists,
"All environment variables must be set if any are specified"
);
string memory _network = vm.envString("NETWORK");
_env = new NetworkSelector().select(_network);
_hookAddress = vm.envAddress("HOOK_ADDRESS");
_swapRouter = V4Router(vm.envAddress("SWAP_ROUTER_ADDRESS"));
}
function run() public {
_init();
INetwork.Config memory config = _env.config();
INetwork.TokenConfig memory tokenConfig = _env.tokenConfig();
IPoolManager manager = config.poolManager;
IERC20 wUSDL = IERC20(Currency.unwrap(tokenConfig.wUSDL));
IERC20 USDC = IERC20(Currency.unwrap(tokenConfig.USDC));
IERC20 USDL = IERC20(Currency.unwrap(tokenConfig.USDL));
IHooks hook = IHooks(_hookAddress);
_tickSpacing = 60;
PoolKey memory predicatePoolKey = PoolKey(tokenConfig.wUSDL, tokenConfig.USDC, 0, _tickSpacing, hook);
// initialize the auto wrapper
uint160 autoWrapperFlags = uint160(
Hooks.BEFORE_INITIALIZE_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG | Hooks.BEFORE_SWAP_FLAG
| Hooks.BEFORE_SWAP_RETURNS_DELTA_FLAG | Hooks.AFTER_SWAP_FLAG
);
bytes memory autoWrapperConstructorArgs =
abi.encode(manager, ERC4626(address(wUSDL)), USDC, predicatePoolKey, _swapRouter, msg.sender);
(address autoWrapperAddress, bytes32 autoWrapperSalt) = HookMiner.find(
config.create2Deployer, autoWrapperFlags, type(AutoWrapper).creationCode, autoWrapperConstructorArgs
);
vm.startBroadcast();
AutoWrapper autoWrapper = new AutoWrapper{salt: autoWrapperSalt}(
manager, ERC4626(address(wUSDL)), Currency.wrap(address(USDC)), predicatePoolKey, _swapRouter, msg.sender
);
require(address(autoWrapper) == autoWrapperAddress, "Hook deployment failed");
console.log("Deployed AutoWrapper at address: ", address(autoWrapper));
// initialize the ghost pool
PoolKey memory ghostPoolKey;
ghostPoolKey =
PoolKey(Currency.wrap(address(USDC)), Currency.wrap(address(USDL)), 0, _tickSpacing, IHooks(autoWrapper));
console.log(
"Deploying ghost pool with token0: %s and token1: %s",
Currency.unwrap(ghostPoolKey.currency0),
Currency.unwrap(ghostPoolKey.currency1)
);
uint160 ghostPoolStartingPrice = 79_228_162_514_264_337_593_543_950_336_000_000;
manager.initialize(ghostPoolKey, ghostPoolStartingPrice);
// move 2e18 USDL to the auto wrapper
USDL.transfer(address(autoWrapper), 2e18);
// set approvals
_setApprovals(wUSDL, USDC, USDL, autoWrapper);
vm.stopBroadcast();
}
function _setApprovals(IERC20 wUSDL, IERC20 USDC, IERC20 USDL, AutoWrapper autoWrapper) internal {
// Approve autoWrapper to spend USDL from msg.sender
USDL.approve(address(autoWrapper), type(uint256).max);
// Approve autoWrapper to spend USDC from msg.sender
USDC.approve(address(autoWrapper), type(uint256).max);
// Approve autoWrapper to spend wUSDL from msg.sender
wUSDL.approve(address(autoWrapper), type(uint256).max);
}
}