From adc14600c7263c62b7ec9da011a677b7271551a6 Mon Sep 17 00:00:00 2001 From: xBalbinus Date: Thu, 5 Sep 2024 07:41:00 -0700 Subject: [PATCH 1/4] deterministic proxy deployment docs: draft --- .gitbook.yaml | 1 + SUMMARY.md | 1 + .../advanced/deterministic-deployment.md | 141 ++++++++++++++++++ 3 files changed, 143 insertions(+) create mode 100644 smart-contracts/advanced/deterministic-deployment.md diff --git a/.gitbook.yaml b/.gitbook.yaml index 0734253be..3bcd94403 100644 --- a/.gitbook.yaml +++ b/.gitbook.yaml @@ -326,6 +326,7 @@ redirects: smart-contracts/advanced/wfil: smart-contracts/advanced/wrapped-fil.md smart-contracts/advanced/multicall: smart-contracts/advanced/multicall.md smart-contracts/advanced/multisig: smart-contracts/advanced/multisig.md + smart-contracts/advanced/deterministic-deployment: smart-contracts/advanced/deterministic-deployment.md smart-contracts/developing-contracts: smart-contracts/developing-contracts/best-practices.md smart-contracts/filecoin-evm-runtime/differences-with-ethereum: smart-contracts/fundamentals/README.md smart-contracts/filecoin-evm-runtime/filforwader: smart-contracts/filecoin-evm-runtime/filforwarder.md diff --git a/SUMMARY.md b/SUMMARY.md index 66b34b939..f36cabdb1 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -131,6 +131,7 @@ * [Oracles](smart-contracts/advanced/oracles.md) * [Multicall](smart-contracts/advanced/multicall.md) * [Multisig](smart-contracts/advanced/multisig.md) + * [Deterministic deployment](smart-contracts/advanced/deterministic-deployment.md) * [Cross-chain bridges](smart-contracts/advanced/cross-chain-bridges.md) * [Aggregated deal-making](smart-contracts/advanced/aggregated-deal-making.md) diff --git a/smart-contracts/advanced/deterministic-deployment.md b/smart-contracts/advanced/deterministic-deployment.md new file mode 100644 index 000000000..0d53a4acd --- /dev/null +++ b/smart-contracts/advanced/deterministic-deployment.md @@ -0,0 +1,141 @@ +## What is deterministic deployment? + +Deterministic deployment refers to the ability to deploy smart contracts to the same address across different blockchain networks. This consistency can be particularly useful when deploying the same contract on multiple chains to streamline interactions or ensure interoperability. There are two primary methods to achieve deterministic deployment: + +- Using a **factory contract that has been deployed keylessly** to deploy your contracts. + - The factory usually uses the `CREATE2` opcode to deploy your contracts, precomputing the deployment address and ensuring consistency across all chains. +- **Deploying your contracts keylessly** (without using any factory) onto all blockchains. + - You must keep the code and constructor arguments unchanged to get the same address. + +## Creating a deterministic deployment + +Contract address can be precomputed, before the contract is deployed, using a create opcode. This is one of the options for deterministic deployment. + +### **`CREATE`** + +If deploying from an externally-owned account (EOA), e.g. by calling `ethers.deployContract` from a hardhat script, the `CREATE` opcode will run in the EVM and contract addresses will be calculated using the: + +- Address of the EOA; +- Nonce of the EOA. + +If deploying using a `CREATE` factory contract, contract addresses are calculated using the: + +- Address of the factory contract (that calls `CREATE` opcode) itself; +- Nonce of the factory contract ([EIP-161](https://eips.ethereum.org/EIPS/eip-161) specifies that contract nonce starts at 1, not 0 like EOAs). + +### **`CREATE2`** + +The `CREATE2` opcode must be run from a deployed contract, so usually it's done from a `CREATE2` factory contract. Contract addresses are precomputed using the: + +- Address of the factory contract (that calls `CREATE2` opcode) itself; +- Bytecode of the contract; +- Salt (a chosen value). + +See the following code snippet for an example of how to call `CREATE2` from a factory contract: + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +... + +function deploy(bytes memory bytecode, uint256 _salt) public payable { + address addr; + + /* + NOTE: How to call create2 + + create2(v, p, n, s) + create new contract with code at memory p to p + n + and send v wei + and return the new address + where new address = first 20 bytes of keccak256(0xff + address(this) + s + keccak256(mem[p…(p+n))) + s = big-endian 256-bit value + */ + assembly { + addr := + create2( + callvalue(), // wei sent with current call + // Actual code starts after skipping the first 32 bytes + add(bytecode, 0x20), + mload(bytecode), // Load the size of code contained in the first 32 bytes + _salt // Salt from function arguments + ) + + if iszero(extcodesize(addr)) { revert(0, 0) } + } + + emit Deployed(addr, _salt); +} +``` + +### **`CREATE3`** + +With `CREATE2`, the contract bytecode affects the deployment address. So even blank spaces and comment text can affect the address. + +CREATE3 is similar to CREATE2 but without including the contract initCode on the address derivation formula. It can be used to generate deterministic contract addresses that aren’t tied to a specific contract code. + +CREATE3 is a way to use CREATE and CREATE2 in combination such that bytecode no longer affects the deployment address. — CREATE3 is more expensive than CREATE or CREATE2 (Fixed extra cost of ~55k gas). + +Check out a reference implementation [here](https://github.com/0xsequence/create3). + +### **Usage** + +Other people may have already deployed the factory contract onto some of your desired blockchains to the expected address (if they didn't change the deployment transaction data), in which case you won't need to deploy it on those blockchains - you can then just use those already-deployed factory contracts to deploy whatever other contracts you want to deploy. So first check the expected address on a blockchain explorer to see if a factory contract already exists there. + +If there isn't one yet then you'll need to deploy the factory contract via a **reusable signed raw deployment transaction**. The factory contract will then have the same address as on other blockchains (as long as the transaction bytecode stays the same). See the steps below to deploy the factory. + +1. **Prepare the deployment transaction:** + - Write the smart contract code for the factory contract. + - Compile the contract to get the bytecode. + - Create a deployment transaction with the bytecode. + +2. **Sign the deployment transaction:** + - Use a private key to sign the deployment transaction. + - Ensure the private key is securely stored and not exposed. + +3. **Broadcast the signed transaction:** + - Send the signed transaction to the desired blockchain network. + - Wait for the transaction to be mined and confirmed. + +4. **Verify the deployment:** + - Check the blockchain explorer to verify that the factory contract has been deployed to the expected address. + - Ensure the contract code matches the expected bytecode. + +By following these steps, you can deploy the factory contract to multiple blockchains, ensuring it has the same address on each one. This allows for consistent and deterministic deployment of other contracts using the factory contract. + +## **Popular Tools** + +1. [**Deterministic Deployment Proxy by Arachnid**](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master) + - Signing the Proxy deployment tx is hidden, only recover the public key from signed tx. + - Somehow, the signing key and address is associated with the deployment tx. So if we change anything related to that deployment tx, the signing key and address will be different → proxy address is different. +2. **Safe singleton Factory** + - Safe Multisig Wallet + - [Masa Finance](https://www.masa.ai/) + - Starlings lab forked and deployed it on many blockchains + - [align.network](http://align.network) - Long-term storage solution for Ethereum +3. [**pcaversaccio/createx**](https://createx.rocks/) + + They offer two options for deploying [`CreateX`](https://github.com/pcaversaccio/createx/blob/main/src/CreateX.sol) to your desired chain: + + 1. Deploy it yourself by using one of the pre-signed transactions. Details can be found in the subsequent paragraph. + 2. Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+). You can significantly reduce the time to deployment by sending funds to cover the deployment cost (a reliable amount with a small tip 😏 would be ~0.3 ETH) to the deployer account: `0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5`. + 3. See the [deployment result from Dune](https://dune.com/patronumlabs/createx) + +4. [**pcaversaccio/xdeployer**](https://github.com/pcaversaccio/xdeployer) - hardhat + hardhat **plugin** to deploy your smart contracts across multiple EVM chains with the same deterministic address. + `npx hardhat xdeploy` + + - It also deployed on Filecoin mainnet and testnet. + - contract creation transaction is the helper smart contract [`CreateX`](https://github.com/pcaversaccio/createx) with address `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed` + +5. OpenZepplin Defender + - [How to tutorial](https://blog.openzeppelin.com/evm-deterministic-deployments-made-easy-with-openzeppelin-defender) + +Some of the most popular projects are using their own proxy for deterministic deployment across multiple chains. For example, + +- Uniswap V2/V3 Factory Contracts +- Compound and Aave Proxy Contracts +- Synthetix Proxy and Synth Contracts +- ENS (Ethereum Name Service) Registrar Contracts +- Argent Wallet’s `Identity Proxy Factory` From 1f3fe8fc0271a01636a6f8cd6ba3bd842f08eb93 Mon Sep 17 00:00:00 2001 From: xBalbinus Date: Wed, 11 Sep 2024 09:43:52 -0700 Subject: [PATCH 2/4] fix: address all feedback on determ deploy --- .../advanced/deterministic-deployment.md | 123 +++++------------- 1 file changed, 34 insertions(+), 89 deletions(-) diff --git a/smart-contracts/advanced/deterministic-deployment.md b/smart-contracts/advanced/deterministic-deployment.md index 0d53a4acd..b61176b60 100644 --- a/smart-contracts/advanced/deterministic-deployment.md +++ b/smart-contracts/advanced/deterministic-deployment.md @@ -13,11 +13,6 @@ Contract address can be precomputed, before the contract is deployed, using a cr ### **`CREATE`** -If deploying from an externally-owned account (EOA), e.g. by calling `ethers.deployContract` from a hardhat script, the `CREATE` opcode will run in the EVM and contract addresses will be calculated using the: - -- Address of the EOA; -- Nonce of the EOA. - If deploying using a `CREATE` factory contract, contract addresses are calculated using the: - Address of the factory contract (that calls `CREATE` opcode) itself; @@ -25,63 +20,17 @@ If deploying using a `CREATE` factory contract, contract addresses are calculate ### **`CREATE2`** -The `CREATE2` opcode must be run from a deployed contract, so usually it's done from a `CREATE2` factory contract. Contract addresses are precomputed using the: +Similar to `CREATE`, `CREATE2` is used to deploy contracts to the same address across different blockchain networks in factory contract implementations. Contract addresses are precomputed using the: - Address of the factory contract (that calls `CREATE2` opcode) itself; - Bytecode of the contract; - Salt (a chosen value). -See the following code snippet for an example of how to call `CREATE2` from a factory contract: - -```solidity -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.0; - -... - -function deploy(bytes memory bytecode, uint256 _salt) public payable { - address addr; - - /* - NOTE: How to call create2 - - create2(v, p, n, s) - create new contract with code at memory p to p + n - and send v wei - and return the new address - where new address = first 20 bytes of keccak256(0xff + address(this) + s + keccak256(mem[p…(p+n))) - s = big-endian 256-bit value - */ - assembly { - addr := - create2( - callvalue(), // wei sent with current call - // Actual code starts after skipping the first 32 bytes - add(bytecode, 0x20), - mload(bytecode), // Load the size of code contained in the first 32 bytes - _salt // Salt from function arguments - ) - - if iszero(extcodesize(addr)) { revert(0, 0) } - } - - emit Deployed(addr, _salt); -} -``` +See this [code snippet](https://solidity-by-example.org/app/create2/) for an example of how to call `CREATE2` from a factory contract. -### **`CREATE3`** +## **Deploying a factory contract to Filecoin** -With `CREATE2`, the contract bytecode affects the deployment address. So even blank spaces and comment text can affect the address. - -CREATE3 is similar to CREATE2 but without including the contract initCode on the address derivation formula. It can be used to generate deterministic contract addresses that aren’t tied to a specific contract code. - -CREATE3 is a way to use CREATE and CREATE2 in combination such that bytecode no longer affects the deployment address. — CREATE3 is more expensive than CREATE or CREATE2 (Fixed extra cost of ~55k gas). - -Check out a reference implementation [here](https://github.com/0xsequence/create3). - -### **Usage** - -Other people may have already deployed the factory contract onto some of your desired blockchains to the expected address (if they didn't change the deployment transaction data), in which case you won't need to deploy it on those blockchains - you can then just use those already-deployed factory contracts to deploy whatever other contracts you want to deploy. So first check the expected address on a blockchain explorer to see if a factory contract already exists there. +Other people may have already deployed the factory contract onto Filecoin, in which case you won't need to redeploy it. You can just use the factory to deploy your contracts. So first check the expected address on a blockchain explorer to see if a factory contract already exists there. If there isn't one yet then you'll need to deploy the factory contract via a **reusable signed raw deployment transaction**. The factory contract will then have the same address as on other blockchains (as long as the transaction bytecode stays the same). See the steps below to deploy the factory. @@ -99,43 +48,39 @@ If there isn't one yet then you'll need to deploy the factory contract via a **r - Wait for the transaction to be mined and confirmed. 4. **Verify the deployment:** - - Check the blockchain explorer to verify that the factory contract has been deployed to the expected address. + - Check the [blockchain explorer](https://docs.filecoin.io/networks/mainnet/explorers) to verify that the factory contract has been deployed to the expected address. - Ensure the contract code matches the expected bytecode. By following these steps, you can deploy the factory contract to multiple blockchains, ensuring it has the same address on each one. This allows for consistent and deterministic deployment of other contracts using the factory contract. - -## **Popular Tools** - -1. [**Deterministic Deployment Proxy by Arachnid**](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master) - - Signing the Proxy deployment tx is hidden, only recover the public key from signed tx. - - Somehow, the signing key and address is associated with the deployment tx. So if we change anything related to that deployment tx, the signing key and address will be different → proxy address is different. -2. **Safe singleton Factory** +## **Using Popular Tools on Filecoin** + +### **1. Deterministic Deployment Proxy by Arachnid** +- **Address:** `0x4e59b44847b379578588920ca78fbf26c0b4956c` +- **How-to:** + - Signing the Proxy deployment transaction is hidden, only recover the public key from the signed transaction. + - The signing key and address are associated with the deployment transaction. If anything related to the deployment transaction changes, the signing key and address will be different, resulting in a different proxy address. + - [Repository Link](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master) + +### **2. Safe Singleton Factory** +- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7` +- **How-to:** - Safe Multisig Wallet + - Deployed by Masa Finance, Starlings lab, and align.network on many blockchains. - [Masa Finance](https://www.masa.ai/) - - Starlings lab forked and deployed it on many blockchains - - [align.network](http://align.network) - Long-term storage solution for Ethereum -3. [**pcaversaccio/createx**](https://createx.rocks/) - - They offer two options for deploying [`CreateX`](https://github.com/pcaversaccio/createx/blob/main/src/CreateX.sol) to your desired chain: - - 1. Deploy it yourself by using one of the pre-signed transactions. Details can be found in the subsequent paragraph. - 2. Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+). You can significantly reduce the time to deployment by sending funds to cover the deployment cost (a reliable amount with a small tip 😏 would be ~0.3 ETH) to the deployer account: `0xeD456e05CaAb11d66C4c797dD6c1D6f9A7F352b5`. - 3. See the [deployment result from Dune](https://dune.com/patronumlabs/createx) - -4. [**pcaversaccio/xdeployer**](https://github.com/pcaversaccio/xdeployer) - hardhat - hardhat **plugin** to deploy your smart contracts across multiple EVM chains with the same deterministic address. - `npx hardhat xdeploy` - - - It also deployed on Filecoin mainnet and testnet. - - contract creation transaction is the helper smart contract [`CreateX`](https://github.com/pcaversaccio/createx) with address `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed` - -5. OpenZepplin Defender + - [align.network](http://align.network) + +### **3. CreateX / xdeployer by pcaversaccio** +- **Address:** `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed` +- **How-to:** + - Deploy it yourself using one of the pre-signed transactions. Details can be found in the repository. + - xdeployer is a hardhat plugin that allows you to deploy your smart contracts across multiple EVM chains with the same deterministic address. + - It is deployed on Filecoin mainnet and testnet. + - Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+). + - [CreateX Repository](https://github.com/pcaversaccio/createx), [xdeployer Repository](https://github.com/pcaversaccio/xdeployer) + - [Deployment Result from Dune](https://dune.com/patronumlabs/createx) + +### **4. OpenZeppelin Defender** +- **Address:** N/A +- **How-to:** + - Follow the tutorial to use OpenZeppelin Defender for deterministic deployments. - [How to tutorial](https://blog.openzeppelin.com/evm-deterministic-deployments-made-easy-with-openzeppelin-defender) - -Some of the most popular projects are using their own proxy for deterministic deployment across multiple chains. For example, - -- Uniswap V2/V3 Factory Contracts -- Compound and Aave Proxy Contracts -- Synthetix Proxy and Synth Contracts -- ENS (Ethereum Name Service) Registrar Contracts -- Argent Wallet’s `Identity Proxy Factory` From 54ac19f1da7d5fe37bc598b514a6c2560464a7ca Mon Sep 17 00:00:00 2001 From: xBalbinus Date: Wed, 11 Sep 2024 09:45:59 -0700 Subject: [PATCH 3/4] fix: safe singleton factory link --- smart-contracts/advanced/deterministic-deployment.md | 1 + 1 file changed, 1 insertion(+) diff --git a/smart-contracts/advanced/deterministic-deployment.md b/smart-contracts/advanced/deterministic-deployment.md index b61176b60..42ad652d3 100644 --- a/smart-contracts/advanced/deterministic-deployment.md +++ b/smart-contracts/advanced/deterministic-deployment.md @@ -68,6 +68,7 @@ By following these steps, you can deploy the factory contract to multiple blockc - Deployed by Masa Finance, Starlings lab, and align.network on many blockchains. - [Masa Finance](https://www.masa.ai/) - [align.network](http://align.network) + - [Repository Link](https://github.com/safe-global/safe-singleton-factory) ### **3. CreateX / xdeployer by pcaversaccio** - **Address:** `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed` From 12a397839bd385d10a5e32d521757d6bc0ffa086 Mon Sep 17 00:00:00 2001 From: xBalbinus Date: Wed, 18 Sep 2024 17:57:56 +0800 Subject: [PATCH 4/4] fix: new format / content structure --- .../advanced/deterministic-deployment.md | 122 ++++++++++-------- 1 file changed, 66 insertions(+), 56 deletions(-) diff --git a/smart-contracts/advanced/deterministic-deployment.md b/smart-contracts/advanced/deterministic-deployment.md index 42ad652d3..7ba68b04f 100644 --- a/smart-contracts/advanced/deterministic-deployment.md +++ b/smart-contracts/advanced/deterministic-deployment.md @@ -2,85 +2,95 @@ Deterministic deployment refers to the ability to deploy smart contracts to the same address across different blockchain networks. This consistency can be particularly useful when deploying the same contract on multiple chains to streamline interactions or ensure interoperability. There are two primary methods to achieve deterministic deployment: -- Using a **factory contract that has been deployed keylessly** to deploy your contracts. +- **Building your own factory contract** to deploy your contracts deterministically. - The factory usually uses the `CREATE2` opcode to deploy your contracts, precomputing the deployment address and ensuring consistency across all chains. -- **Deploying your contracts keylessly** (without using any factory) onto all blockchains. - - You must keep the code and constructor arguments unchanged to get the same address. +- **Using supported pre-built tools** to deploy your contracts deterministically. -## Creating a deterministic deployment +## **Deploying a factory contract to Filecoin** -Contract address can be precomputed, before the contract is deployed, using a create opcode. This is one of the options for deterministic deployment. +Other people may have already deployed the factory contract onto Filecoin, in which case you won't need to redeploy it. You can just use the factory to deploy your contracts. So first check the expected address on a blockchain explorer to see if a factory contract already exists there. -### **`CREATE`** +If there isn't one yet then you'll need to deploy the factory contract. The factory contract will then have the same address as on other blockchains (as long as the transaction bytecode stays the same). -If deploying using a `CREATE` factory contract, contract addresses are calculated using the: +### Creating a deterministic deployment factory contract -- Address of the factory contract (that calls `CREATE` opcode) itself; -- Nonce of the factory contract ([EIP-161](https://eips.ethereum.org/EIPS/eip-161) specifies that contract nonce starts at 1, not 0 like EOAs). +Contract address get precomputed by the factory contract, before the contract is deployed, typically using the create2 opcode. -### **`CREATE2`** +#### **`CREATE2`** -Similar to `CREATE`, `CREATE2` is used to deploy contracts to the same address across different blockchain networks in factory contract implementations. Contract addresses are precomputed using the: +`CREATE2` is used to deploy contracts to the same address across different blockchain networks in factory contract implementations. Contract addresses are precomputed using the: - Address of the factory contract (that calls `CREATE2` opcode) itself; - Bytecode of the contract; - Salt (a chosen value). -See this [code snippet](https://solidity-by-example.org/app/create2/) for an example of how to call `CREATE2` from a factory contract. - -## **Deploying a factory contract to Filecoin** - -Other people may have already deployed the factory contract onto Filecoin, in which case you won't need to redeploy it. You can just use the factory to deploy your contracts. So first check the expected address on a blockchain explorer to see if a factory contract already exists there. - -If there isn't one yet then you'll need to deploy the factory contract via a **reusable signed raw deployment transaction**. The factory contract will then have the same address as on other blockchains (as long as the transaction bytecode stays the same). See the steps below to deploy the factory. +See this [code snippet](https://solidity-by-example.org/app/create2/) for an example of how to call `CREATE2` from a factory contract. Alternatively, you can base your own on [this popular proxy](https://github.com/Arachnid/deterministic-deployment-proxy). -1. **Prepare the deployment transaction:** - - Write the smart contract code for the factory contract. - - Compile the contract to get the bytecode. - - Create a deployment transaction with the bytecode. +## **Supported Tools on Filecoin** -2. **Sign the deployment transaction:** - - Use a private key to sign the deployment transaction. - - Ensure the private key is securely stored and not exposed. +There exists popular tools that have already deployed factory contracts on Filecoin. You can use these tools to deploy your contracts deterministically instead of writing your own factory contract. -3. **Broadcast the signed transaction:** - - Send the signed transaction to the desired blockchain network. - - Wait for the transaction to be mined and confirmed. +### **Safe Singleton Factory** +- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7` +- **How-to:** + - Import the Safe Singleton Factory information via. the [library](https://github.com/safe-global/safe-singleton-factory). + - Use the `getSingletonFactoryInfo` function in hardhat config to get the factory address, deployer address, and signed transaction. -4. **Verify the deployment:** - - Check the [blockchain explorer](https://docs.filecoin.io/networks/mainnet/explorers) to verify that the factory contract has been deployed to the expected address. - - Ensure the contract code matches the expected bytecode. +```ts +import { getSingletonFactoryInfo } from '@safe-global/safe-singleton-factory' -By following these steps, you can deploy the factory contract to multiple blockchains, ensuring it has the same address on each one. This allows for consistent and deterministic deployment of other contracts using the factory contract. -## **Using Popular Tools on Filecoin** +... -### **1. Deterministic Deployment Proxy by Arachnid** -- **Address:** `0x4e59b44847b379578588920ca78fbf26c0b4956c` -- **How-to:** - - Signing the Proxy deployment transaction is hidden, only recover the public key from the signed transaction. - - The signing key and address are associated with the deployment transaction. If anything related to the deployment transaction changes, the signing key and address will be different, resulting in a different proxy address. - - [Repository Link](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master) +function deterministicDeployment(network: string): DeterministicDeploymentInfo { + const info = getSingletonFactoryInfo(parseInt(network)) -### **2. Safe Singleton Factory** -- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7` -- **How-to:** - - Safe Multisig Wallet - - Deployed by Masa Finance, Starlings lab, and align.network on many blockchains. - - [Masa Finance](https://www.masa.ai/) - - [align.network](http://align.network) - - [Repository Link](https://github.com/safe-global/safe-singleton-factory) + ... + return { + factory: info.address, + deployer: info.signerAddress, + funding: String(gasLimit * gasPrice), + signedTx: info.transaction, + } +} +``` -### **3. CreateX / xdeployer by pcaversaccio** +### **CreateX / xdeployer by pcaversaccio** - **Address:** `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed` - **How-to:** - - Deploy it yourself using one of the pre-signed transactions. Details can be found in the repository. - - xdeployer is a hardhat plugin that allows you to deploy your smart contracts across multiple EVM chains with the same deterministic address. - - It is deployed on Filecoin mainnet and testnet. - - Request a deployment by opening an [issue](https://github.com/pcaversaccio/createx/issues/new?assignees=pcaversaccio&labels=new+deployment+%E2%9E%95&projects=&template=deployment_request.yml&title=%5BNew-Deployment-Request%5D%3A+). - - [CreateX Repository](https://github.com/pcaversaccio/createx), [xdeployer Repository](https://github.com/pcaversaccio/xdeployer) - - [Deployment Result from Dune](https://dune.com/patronumlabs/createx) - -### **4. OpenZeppelin Defender** + - CreateX is meant to be a wrapper around the create opcodes that you can integrate into your own factory contract. Details can be found in the [CreateX Repository](https://github.com/pcaversaccio/createx). + - [xdeployer](https://github.com/pcaversaccio/xdeployer) is a hardhat plugin that allows you to deploy your smart contracts across multiple EVM chains with the same deterministic address. You can import and configure in your hardhat configuration file like so: + +```ts +import "xdeployer"; + +const config: HardhatUserConfig = { + networks: { + mainnet: { ... } + }, + xdeploy: { + contract: "YOUR_CONTRACT_NAME_TO_BE_DEPLOYED", + constructorArgsPath: "PATH_TO_CONSTRUCTOR_ARGS", // optional; default value is `undefined` + salt: "YOUR_SALT_MESSAGE", + signer: "SIGNER_PRIVATE_KEY", + networks: ["LIST_OF_NETWORKS"], + rpcUrls: ["LIST_OF_RPCURLS"], + gasLimit: 1_500_000, // optional; default value is `1.5e6` + }, +}; +``` + +or in the case of solidity files: + +```solidity +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.23; + +import { CreateX } from "xdeployer/src/contracts/CreateX.sol"; + +contract Create2DeployerLocal is CreateX {} +``` + +### **OpenZeppelin Defender** - **Address:** N/A - **How-to:** - Follow the tutorial to use OpenZeppelin Defender for deterministic deployments.