Skip to content

Commit

Permalink
fix: deploy script
Browse files Browse the repository at this point in the history
  • Loading branch information
guzus committed Nov 16, 2024
1 parent b7408c3 commit e84ab21
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions packages/foundry/script/00_Counter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,29 @@ contract EtfHookScript is Script, Constants {
// hook contracts must have specific flags encoded in the address
uint160 flags = uint160(
Hooks.BEFORE_SWAP_FLAG | Hooks.BEFORE_ADD_LIQUIDITY_FLAG
| Hooks.BEFORE_REMOVE_LIQUIDITY_FLAG
| Hooks.AFTER_REMOVE_LIQUIDITY_FLAG
);

// Mine a salt that will produce a hook address with the correct flags
bytes memory constructorArgs = abi.encode(POOLMANAGER);
(address hookAddress, bytes32 salt) =
HookMiner.find(CREATE2_DEPLOYER, flags, type(ETFHook).creationCode, constructorArgs);

// Deploy the hook using CREATE2
vm.broadcast();

token0 = new MockERC20("Token0", "T0", 18);
token1 = new MockERC20("Token1", "T1", 18);
token0.mint(msg.sender, 1_000_000);
token1.mint(msg.sender, 1_000_000);
address[2] memory TOKENS = [address(token0), address(token1)];
uint256[2] memory WEIGHTS = [uint256(1), uint256(1)];
uint256 REBALANCE_THRESHOLD = 5;

// Mine a salt that will produce a hook address with the correct flags
bytes memory constructorArgs = abi.encode(
POOLMANAGER, TOKENS, WEIGHTS, REBALANCE_THRESHOLD, address(0)
);
(address hookAddress, bytes32 salt) =
HookMiner.find(CREATE2_DEPLOYER, flags, type(ETFHook).creationCode, constructorArgs);

// Deploy the hook using CREATE2
vm.broadcast();

ETFHook etfHook = new ETFHook{salt: salt}(
IPoolManager(POOLMANAGER), TOKENS, WEIGHTS, REBALANCE_THRESHOLD, address(0), address(0), address(0), address(0)
IPoolManager(POOLMANAGER), TOKENS, WEIGHTS, REBALANCE_THRESHOLD, address(0)
);
require(address(etfHook) == hookAddress, "EtfHookScript: hook address mismatch");
}
Expand Down
4 changes: 2 additions & 2 deletions packages/foundry/script/base/Constants.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ contract Constants {
address constant CREATE2_DEPLOYER = address(0x4e59b44847b379578588920cA78FbF26c0B4956C);

/// @dev populated with default anvil addresses
IPoolManager constant POOLMANAGER = IPoolManager(address(0x5FbDB2315678afecb367f032d93F642f64180aa3));
PositionManager constant posm = PositionManager(payable(address(0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0)));
IPoolManager constant POOLMANAGER = IPoolManager(address(0x008c4bcbe6b9ef47855f97e675296fa3f6fafa5f1a));
PositionManager constant posm = PositionManager(payable(address(0x001b1c77b606d13b09c84d1c7394b96b147bc03147)));
IAllowanceTransfer constant PERMIT2 = IAllowanceTransfer(address(0x000000000022D473030F116dDEE9F6B43aC78BA3));
}

0 comments on commit e84ab21

Please sign in to comment.