Skip to content

Commit

Permalink
update with new deterministic configs
Browse files Browse the repository at this point in the history
  • Loading branch information
iainnash committed Sep 28, 2023
1 parent 818ffa5 commit c2ada90
Show file tree
Hide file tree
Showing 15 changed files with 368 additions and 149 deletions.
10 changes: 10 additions & 0 deletions deterministicConfig/factoryProxy/params.json

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions deterministicConfig/premintExecutorProxy/params.json

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions deterministicConfig/upgradeGate/params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"creationCode": "0x6080806040523461001657610948908161001c8239f35b600080fdfe6080604081815260048036101561001557600080fd5b600092833560e01c90816321f74347146107b95750806323452b9c14610753578063395db2cd146106d15780634dc5b7c71461068357806375d0c0dc1461062157806379ba5097146105cc5780638da5cb5b146105a457806392b60a4c1461042e578063c4d66de8146102d6578063e30c3978146102ad578063e8a3d48514610211578063ed0c7091146101ac578063f0fad9911461011c5763f2fde38b146100bd57600080fd5b34610118576020366003190112610118576100d6610805565b916001600160a01b038084161561010a5784541633036100fd57836100fa846108a9565b80f35b5163d238ed5960e01b8152fd5b5051631627621f60e11b8152fd5b8280fd5b5034610118578160031936011261011857610135610805565b9161013e610820565b845490936001600160a01b039390918416330361019e57508216918285526035602052818520931692838552602052832060ff1981541690557f0ebd98f6f75e38ba2f0751378f5c86205cafca83e206cb62795f45fcea7283338380a380f35b825163d238ed5960e01b8152fd5b50346101185782600319360112610118578254916001600160a01b039182841691338390036100fd57505083906000805160206108f38339815191528280a36001600160a01b03199182168355600154908116610207578280f35b1660015538808280f35b509190346102a957816003193601126102a957805191606083019083821067ffffffffffffffff831117610296575061029293508152602f82527f68747470733a2f2f6769746875622e636f6d2f6f75727a6f72612f7a6f72612d60208301526e313135352d636f6e7472616374732f60881b818301525191829182610836565b0390f35b634e487b7160e01b815260418552602490fd5b5080fd5b5050346102a957816003193601126102a95760015490516001600160a01b039091168152602090f35b5034610118576020366003190112610118576102f0610805565b6034549060ff8260081c16159182801590610422575b8061040a575b6103fa5760ff198116600117603455826103e8575b506001600160a01b03169283156103d9576034549260ff8460081c16156103cc575084546001600160a01b031916841785555192846000805160206108f38339815191528180a37f0c52cc367a132cac0ea9f3a1e1f75873b17977858812b85c89a9654486e444388480a1610394578280f35b61ff001916603455600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249890602090a138808280f35b90516296bfb160e81b8152fd5b51631627621f60e11b81529050fd5b61ffff19166101011760345538610321565b8451633d5c224160e11b81528490fd5b50303b15158061030c5750600160ff8216141561030c565b5060ff81161515610306565b503461011857816003193601126101185780359067ffffffffffffffff8083116105a057366023840112156105a057828201359281841161058d578360051b93855192601f19603f8701168401908482109082111761057a57865282526020936024858401918301019136831161057657602401905b828210610553575050506104b6610820565b855490946001600160a01b039390918416330361054557509293821692855b82518110156105415780846104ec6001938661087f565b51168852603587528288208689528752828820805460ff1916831790558585610515838761087f565b51167fab6a7dc54721d6a1a284ca865830f8981d6f12fbddb3618d1774b71c003680598a80a3016104d5565b8680f35b905163d238ed5960e01b8152fd5b81356001600160a01b03811681036105725781529085019085016104a4565b8880fd5b8780fd5b634e487b7160e01b885260418552602488fd5b634e487b7160e01b865260418352602486fd5b8480fd5b5050346102a957816003193601126102a957905490516001600160a01b039091168152602090f35b50346101185782600319360112610118576001546001600160a01b0392908316330361061457505033908254166000805160206108f38339815191528380a36100fa336108a9565b5163065cd53160e01b8152fd5b509190346102a957816003193601126102a9578051918183019083821067ffffffffffffffff83111761029657506102929350815260168252755a4f524120313135352055706772616465204761746560501b60208301525191829182610836565b5050346102a957806003193601126102a95760ff816020936106a3610805565b6106ab610820565b6001600160a01b0391821683526035875283832091168252855220549151911615158152f35b509034610118576020366003190112610118576001600160a01b0391826106f6610805565b1692831561074457845416918233036100fd575050600180546001600160a01b031916831790557f4f2638f5949b9614ef8d5e268cb51348ad7f434a34812bf64b6e95014fbd357e8380a380f35b509051631627621f60e11b8152fd5b50903461011857826003193601126101185782546001600160a01b039290831691338390036100fd575050600154918216907f682679deecef4dcd49674845cc1e3a075fea9073680aa445a8207d5a4bdea3da8480a36001600160a01b03191660015580f35b8490843461011857806003193601126101185760ff906020936107da610805565b6107e2610820565b6001600160a01b0391821683526035875283832091168252855220541615158152f35b600435906001600160a01b038216820361081b57565b600080fd5b602435906001600160a01b038216820361081b57565b6020808252825181830181905290939260005b82811061086b57505060409293506000838284010152601f8019910116010190565b818101860151848201604001528501610849565b80518210156108935760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b6000549060018060a01b03809116808284166000805160206108f3833981519152600080a36001600160a01b0319928316176000556001549081166108ec575050565b1660015556fe8292fce18fa69edf4db7b94ea2e58241df0ae57f97e0a6c9b29067028bf92d76a26469706673582212203688178943b2026721abcfbfcebbb085e4ba140c746a309cdb1069b7b4ee6d7264736f6c63430008110033",
"deployerAddress": "0x9444390c01Dd5b7249E53FAc31290F7dFF53450D",
"proxyDeployerAddress": "0x13c30fcbF4c50b7036881FC67Dd2E4c0068DA566",
"salt": "0x9444390c01dd5b7249e53fac31290f7dff53450d00000000000000000000000a",
"upgradeGateAddress": "0xCE3aDea9fdb1C1ABe71eaDd4Dd0d07C211d5A642"
}
45 changes: 43 additions & 2 deletions package/deployment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import { Address, LocalAccount } from "viem";
import { Address, LocalAccount, Hex } from "viem";

export type ConfiguredSalt = `0x${string}`;
// Load environment variables from `.env.local`
export type DeterministicDeploymentConfig = {
proxyDeployerAddress: Address;
proxyShimSalt: ConfiguredSalt;
proxySalt: ConfiguredSalt;
proxyCreationCode: `0x${string}`;
proxyCreationCode: Hex;
};

export type GenericDeploymentConfiguration = {
creationCode: Hex;
salt: Hex;
deployerAddress: Address;
upgradeGateAddress: Address;
proxyDeployerAddress: Address;
};

export type DeployedContracts = {
Expand Down Expand Up @@ -51,3 +59,36 @@ export const signDeployFactory = ({
verifyingContract: config.proxyDeployerAddress,
},
});

export const signGenericDeploy = ({
account,
config,
chainId,
initCall,
}: {
account: LocalAccount;
config: GenericDeploymentConfiguration;
initCall: Hex;
chainId: number;
}) =>
account.signTypedData({
types: {
createGenericContract: [
{ name: "salt", type: "bytes32" },
{ name: "creationCode", type: "bytes" },
{ name: "initCall", type: "bytes" },
],
},
message: {
salt: config.salt,
creationCode: config.creationCode,
initCall,
},
primaryType: "createGenericContract",
domain: {
chainId,
name: "DeterministicProxyDeployer",
version: "1",
verifyingContract: config.proxyDeployerAddress,
},
});
85 changes: 85 additions & 0 deletions script/CalculateDeterministicParams.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// 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 {UpgradeGate} from "../src/upgrades/UpgradeGate.sol";
import {LibString} from "solady/utils/LibString.sol";
import {Create2} from "@openzeppelin/contracts/utils/Create2.sol";
import {ZoraDeployerUtils} from "../src/deployment/ZoraDeployerUtils.sol";
import {Zora1155PremintExecutor} from "../src/proxies/Zora1155PremintExecutor.sol";
import {DeterministicDeployerScript, DeterministicParams} from "../src/deployment/DeterministicDeployerScript.sol";
import {DeterministicProxyDeployer} from "../src/deployment/DeterministicProxyDeployer.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";

/// @title Gets parameters for determinstically deploying a new 1155 factory proxy at an address starting with 0x777777, regardless of the chain.
/// @dev Example usage: DEPLOYER=0xf69fEc6d858c77e969509843852178bd24CAd2B6 forge script script/GetDeterminsticParam.s.sol --rpc-url https://testnet.rpc.zora.energy --ffi
/// @author doved
/// @notice Ensure to set env variable for DEPLOYER
contract FactoryProxyDeterministicParams is ZoraDeployerBase, DeterministicDeployerScript {
address deployerAddress;
// Set in step 2
address proxyDeployerAddress;

function run() public {
vm.createSelectFork("zora_goerli", 1252119);

deployerAddress = vm.envAddress("TURNKEY_TARGET_ADDRESS");

calculateForFactoryProxy();
calculateForPremintExecutorProxy();

// Note: relies on proxyDeployerAddress
calculateUpgradeGateAddress();
}

function calculateForFactoryProxy() internal {
bytes memory proxyCreationCode = type(Zora1155Factory).creationCode;

DeterministicParams memory deterministicParams = getDeterministicDeploymentParams(deployerAddress, proxyCreationCode, 100);

proxyDeployerAddress = deterministicParams.proxyDeployerAddress;

mkdir("deterministicConfig/factoryProxy");
serializeAndSaveOutput(deterministicParams, "factoryProxy");
}

function calculateForPremintExecutorProxy() internal {
bytes memory proxyCreationCode = type(Zora1155PremintExecutor).creationCode;

DeterministicParams memory deterministicParams = getDeterministicDeploymentParams(deployerAddress, proxyCreationCode, 200);

mkdir("deterministicConfig/premintExecutorProxy");
serializeAndSaveOutput(deterministicParams, "premintExecutorProxy");
}

// @notice Since this doesn't
function calculateUpgradeGateAddress() internal {
bytes memory creationCodeUpgradeGate = type(UpgradeGate).creationCode;
bytes32 salt = saltWithAddressInFirst20Bytes(deployerAddress, 10);
address resultAddress = Create2.computeAddress(salt, keccak256(creationCodeUpgradeGate), proxyDeployerAddress);

vm.serializeAddress("UPGRADE_GATE_JSON", "deployerAddress", deployerAddress);
vm.serializeAddress("UPGRADE_GATE_JSON", "upgradeGateAddress", resultAddress);
vm.serializeAddress("UPGRADE_GATE_JSON", "proxyDeployerAddress", proxyDeployerAddress);
vm.serializeBytes32("UPGRADE_GATE_JSON", "salt", salt);
string memory output = vm.serializeBytes("UPGRADE_GATE_JSON", "creationCode", creationCodeUpgradeGate);

console2.log(output);

mkdir("deterministicConfig/upgradeGate");
vm.writeJson(output, paramsFilePath("upgradeGate"));
}

function mkdir(string memory path) internal {
string[] memory commands = new string[](3);
commands[0] = "mkdir";
commands[1] = "-p";
commands[2] = path;
vm.ffi(commands);
}
}
7 changes: 7 additions & 0 deletions script/DeployNewImplementation.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ contract DeployNewImplementations is ZoraDeployerBase {
console2.log("factoryOwner", chainConfig.factoryOwner);
console2.log("protocolRewards", chainConfig.protocolRewards);

deployment.upgradeGate = vm.parseJsonAddress(
vm.readFile("./deterministicDeployments/upgradeGate/params.json"),
".upgradeGateAddress"
);

console2.log("upgradeGateAddress", deployment.upgradeGate);

vm.startBroadcast();

(address factoryImplAddress, address contract1155ImplAddress) = ZoraDeployerUtils.deployNew1155AndFactoryImpl(
Expand Down
14 changes: 14 additions & 0 deletions script/DeployNewProxies.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ contract DeployNewProxies is ZoraDeployerBase, DeterministicDeployerScript {
// get signing instructions
vm.startBroadcast(deployerPrivateKey);

// Sanity check to make sure that the factory owner is a smart contract.
// This may catch cross-chain data copy mistakes where there is no safe at the desired admin address.
if (
address(chainConfig.factoryOwner).code.length == 0
) {
revert("FactoryOwner should be a contract. See DeployNewProxies:31.");
}

address factoryProxyAddress = deployDeterministicProxy({
proxyName: "factoryProxy",
implementation: deployment.factoryImpl,
Expand All @@ -39,10 +47,16 @@ contract DeployNewProxies is ZoraDeployerBase, DeterministicDeployerScript {
chain: chain
});

address upgradeGateAddress = deployUpgradeGate({
chain: chain,
upgradeGateOwner: chainConfig.factoryOwner
});

vm.stopBroadcast();

deployment.factoryProxy = factoryProxyAddress;
deployment.preminterProxy = preminterProxyAddress;
deployment.upgradeGate = upgradeGateAddress;

return getDeploymentJSON(deployment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {ZoraCreatorFixedPriceSaleStrategy} from "../src/minters/fixed-price/Zora
import {ZoraCreatorMerkleMinterStrategy} from "../src/minters/merkle/ZoraCreatorMerkleMinterStrategy.sol";
import {ZoraCreatorRedeemMinterFactory} from "../src/minters/redeem/ZoraCreatorRedeemMinterFactory.sol";

contract DeployScript is ZoraDeployerBase {
contract DeployerMintersScript is ZoraDeployerBase {
function run() public returns (string memory) {
Deployment memory deployment;
ChainConfig memory chainConfig = getChainConfig();
Expand Down
31 changes: 0 additions & 31 deletions script/FactoryProxyDeterministicParams.s.sol

This file was deleted.

31 changes: 0 additions & 31 deletions script/PremintProxyDeterminsticParams.sol

This file was deleted.

Loading

0 comments on commit c2ada90

Please sign in to comment.