Skip to content

Commit

Permalink
create2 for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
snreynolds committed Dec 5, 2024
1 parent ef69e6d commit c6f69e3
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
62075
62063
2 changes: 1 addition & 1 deletion .forge-snapshots/PositionManager_permit_twice.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
44963
44975
2 changes: 1 addition & 1 deletion script/DeployPosm.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract DeployPosmTest is Script {
) public returns (IPositionDescriptor positionDescriptor, IPositionManager posm) {
vm.startBroadcast();

positionDescriptor = Deploy.positionDescriptor(poolManager, wrappedNative, nativeCurrencyLabel);
positionDescriptor = Deploy.positionDescriptor(poolManager, wrappedNative, nativeCurrencyLabel, hex"00");
console2.log("PositionDescriptor", address(positionDescriptor));

posm = Deploy.positionManager(
Expand Down
2 changes: 1 addition & 1 deletion script/DeployStateView.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployStateView is Script {
vm.startBroadcast();

// forge script --broadcast --sig 'run(address)' --rpc-url <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployStateView.s.sol:DeployStateView <POOL_MANAGER_ADDR>
state = Deploy.stateView(poolManager);
state = Deploy.stateView(poolManager, hex"00");
console2.log("StateView", address(state));
console2.log("PoolManager", address(state.poolManager()));

Expand Down
2 changes: 1 addition & 1 deletion script/DeployV4Quoter.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract DeployV4Quoter is Script {
vm.startBroadcast();

// forge script --broadcast --sig 'run(address)' --rpc-url <RPC_URL> --private-key <PRIV_KEY> --verify script/DeployV4Quoter.s.sol:DeployV4Quoter <POOL_MANAGER_ADDR>
state = Deploy.v4Quoter(poolManager);
state = Deploy.v4Quoter(poolManager, hex"00");
console2.log("V4Quoter", address(state));
console2.log("PoolManager", address(state.poolManager()));

Expand Down
2 changes: 1 addition & 1 deletion test/StateViewTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract StateViewTest is Test, Deployers, Fuzzers, GasSnapshot {
poolId = key.toId();
manager.initialize(key, SQRT_PRICE_1_1);

state = Deploy.stateView(address(manager));
state = Deploy.stateView(address(manager), hex"00");
}

function test_getSlot0() public {
Expand Down
2 changes: 1 addition & 1 deletion test/V4Quoter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract QuoterTest is Test, Deployers, GasSnapshot {

function setUp() public {
deployFreshManagerAndRouters();
quoter = Deploy.v4Quoter(address(manager));
quoter = Deploy.v4Quoter(address(manager), hex"00");
positionManager = new PoolModifyLiquidityTest(manager);

// salts are chosen so that address(token0) < address(token1) && address(token1) < address(token2)
Expand Down
20 changes: 11 additions & 9 deletions test/shared/Deploy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,32 @@ library Deploy {
}
}

function stateView(address poolManager) internal returns (IStateView stateView_) {
function stateView(address poolManager, bytes memory salt) internal returns (IStateView stateView_) {
bytes memory args = abi.encode(poolManager);
bytes memory initcode = abi.encodePacked(vm.getCode("StateView.sol:StateView"), args);
assembly {
stateView_ := create(0, add(initcode, 0x20), mload(initcode))
stateView_ := create2(0, add(initcode, 0x20), mload(initcode), salt)
}
}

function v4Quoter(address poolManager) internal returns (IV4Quoter quoter) {
function v4Quoter(address poolManager, bytes memory salt) internal returns (IV4Quoter quoter) {
bytes memory args = abi.encode(poolManager);
bytes memory initcode = abi.encodePacked(vm.getCode("V4Quoter.sol:V4Quoter"), args);
assembly {
quoter := create(0, add(initcode, 0x20), mload(initcode))
quoter := create2(0, add(initcode, 0x20), mload(initcode), salt)
}
}

function positionDescriptor(address poolManager, address wrappedNative, string memory nativeCurrencyLabel)
internal
returns (IPositionDescriptor descriptor)
{
function positionDescriptor(
address poolManager,
address wrappedNative,
string memory nativeCurrencyLabel,
bytes memory salt
) internal returns (IPositionDescriptor descriptor) {
bytes memory args = abi.encode(poolManager, wrappedNative, nativeCurrencyLabel);
bytes memory initcode = abi.encodePacked(vm.getCode("PositionDescriptor.sol:PositionDescriptor"), args);
assembly {
descriptor := create(0, add(initcode, 0x20), mload(initcode))
descriptor := create2(0, add(initcode, 0x20), mload(initcode), salt)
}
}
}
2 changes: 1 addition & 1 deletion test/shared/PosmTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract PosmTestSetup is Test, Deployers, DeployPermit2, LiquidityOperations {
// We use deployPermit2() to prevent having to use via-ir in this repository.
permit2 = IAllowanceTransfer(deployPermit2());
positionDescriptor =
Deploy.positionDescriptor(address(poolManager), 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, "ETH");
Deploy.positionDescriptor(address(poolManager), 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2, "ETH", hex"00");
lpm = Deploy.positionManager(
address(poolManager), address(permit2), 100_000, address(positionDescriptor), address(_WETH9), hex"03"
);
Expand Down

0 comments on commit c6f69e3

Please sign in to comment.