-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can mine for a determinstic address for the proxy shim in a script, a…
…nd have a test that shows we can determinstically deploy proxy to that address with that salt and deployer account
- Loading branch information
Showing
5 changed files
with
91 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import "forge-std/Script.sol"; | ||
import "forge-std/console2.sol"; | ||
|
||
import {ZoraDeployerBase} from "./ZoraDeployerBase.sol"; | ||
import {Zora1155Factory} from "../src/proxies/Zora1155Factory.sol"; | ||
import {ProxyShim} from "../src/utils/ProxyShim.sol"; | ||
import {LibString} from "solady/utils/LibString.sol"; | ||
|
||
contract GetDeterminsticParam is ZoraDeployerBase { | ||
// copied from: https://github.com/karmacoma-eth/foundry-playground/blob/main/script/MineSaltScript.sol#L17C1-L36C9 | ||
function mineSalt(address deployer, bytes32 initCodeHash, string memory startsWith) public returns (string memory saltStr, address expectedAddress) { | ||
string[] memory args = new string[](8); | ||
args[0] = "cast"; | ||
args[1] = "create2"; | ||
args[2] = "--starts-with"; | ||
args[3] = startsWith; | ||
args[4] = "--deployer"; | ||
args[5] = LibString.toHexString(deployer); | ||
args[6] = "--init-code-hash"; | ||
args[7] = LibString.toHexStringNoPrefix(uint256(initCodeHash), 32); | ||
string memory result = string(vm.ffi(args)); | ||
|
||
uint256 addressIndex = LibString.indexOf(result, "Address: "); | ||
string memory addressStr = LibString.slice(result, addressIndex + 9, addressIndex + 9 + 42); | ||
expectedAddress = vm.parseAddress(addressStr); | ||
|
||
uint256 saltIndex = LibString.indexOf(result, "Salt: "); | ||
saltStr = LibString.slice(result, saltIndex + 6, bytes(result).length); | ||
} | ||
|
||
function run() public { | ||
address deployerAddress = makeAddr("determinsticDeployer"); | ||
|
||
console2.log(deployerAddress); | ||
|
||
address factoryShimAddress = address(new ProxyShim(deployerAddress)); | ||
console2.log(factoryShimAddress); | ||
|
||
bytes memory initCode = abi.encodePacked(type(Zora1155Factory).creationCode, abi.encode(factoryShimAddress, "")); | ||
|
||
bytes32 creationCodeHash = keccak256(initCode); | ||
|
||
console.log("init code hash: ", LibString.toHexStringNoPrefix(uint256(creationCodeHash), 32)); | ||
|
||
console2.log("mining for salt"); | ||
|
||
(string memory saltString, address expectedAddress) = mineSalt(deployerAddress, creationCodeHash, "0x7777777"); | ||
|
||
console.log("salt: ", saltString); | ||
console.log("expected address: ", expectedAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.17; | ||
|
||
import "forge-std/Test.sol"; | ||
import {Zora1155Factory} from "../../src/proxies/Zora1155Factory.sol"; | ||
import {ProxyShim} from "../../src/utils/ProxyShim.sol"; | ||
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol"; | ||
|
||
contract ZoraCreator1155FactoryTest is Test { | ||
function test_proxyCanByDeployedAtDesiredAddress() external { | ||
// the values in this test can be determined by running the script GetDeterminsticParam.s.sol, | ||
// then using the output of that to pipe into cast create2 to get a determinstic address that matches | ||
// 0x7777777 | ||
|
||
address deployerAddress = makeAddr("determinsticDeployer"); | ||
|
||
address factoryShimAddress = address(new ProxyShim(deployerAddress)); | ||
|
||
assertEq(factoryShimAddress, 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f, "factory shim"); | ||
|
||
bytes32 salt = bytes32(uint256(58621195373076836725248570099637242069749185457981134621891359830769662503721)); | ||
|
||
vm.startPrank(deployerAddress); | ||
address factoryProxyAddress = address(new Zora1155Factory{salt: salt}(factoryShimAddress, "")); | ||
|
||
assertEq(factoryProxyAddress, 0x7777777CC7d51bDfa57B1afC08Cea482AFfb40cf, "factory proxy address"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters