Skip to content

Commit 12a3978

Browse files
committed
fix: new format / content structure
1 parent 54ac19f commit 12a3978

File tree

1 file changed

+66
-56
lines changed

1 file changed

+66
-56
lines changed

smart-contracts/advanced/deterministic-deployment.md

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,85 +2,95 @@
22

33
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:
44

5-
- Using a **factory contract that has been deployed keylessly** to deploy your contracts.
5+
- **Building your own factory contract** to deploy your contracts deterministically.
66
- The factory usually uses the `CREATE2` opcode to deploy your contracts, precomputing the deployment address and ensuring consistency across all chains.
7-
- **Deploying your contracts keylessly** (without using any factory) onto all blockchains.
8-
- You must keep the code and constructor arguments unchanged to get the same address.
7+
- **Using supported pre-built tools** to deploy your contracts deterministically.
98

10-
## Creating a deterministic deployment
9+
## **Deploying a factory contract to Filecoin**
1110

12-
Contract address can be precomputed, before the contract is deployed, using a create opcode. This is one of the options for deterministic deployment.
11+
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.
1312

14-
### **`CREATE`**
13+
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).
1514

16-
If deploying using a `CREATE` factory contract, contract addresses are calculated using the:
15+
### Creating a deterministic deployment factory contract
1716

18-
- Address of the factory contract (that calls `CREATE` opcode) itself;
19-
- 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).
17+
Contract address get precomputed by the factory contract, before the contract is deployed, typically using the create2 opcode.
2018

21-
### **`CREATE2`**
19+
#### **`CREATE2`**
2220

23-
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:
21+
`CREATE2` is used to deploy contracts to the same address across different blockchain networks in factory contract implementations. Contract addresses are precomputed using the:
2422

2523
- Address of the factory contract (that calls `CREATE2` opcode) itself;
2624
- Bytecode of the contract;
2725
- Salt (a chosen value).
2826

29-
See this [code snippet](https://solidity-by-example.org/app/create2/) for an example of how to call `CREATE2` from a factory contract.
30-
31-
## **Deploying a factory contract to Filecoin**
32-
33-
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.
34-
35-
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.
27+
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).
3628

37-
1. **Prepare the deployment transaction:**
38-
- Write the smart contract code for the factory contract.
39-
- Compile the contract to get the bytecode.
40-
- Create a deployment transaction with the bytecode.
29+
## **Supported Tools on Filecoin**
4130

42-
2. **Sign the deployment transaction:**
43-
- Use a private key to sign the deployment transaction.
44-
- Ensure the private key is securely stored and not exposed.
31+
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.
4532

46-
3. **Broadcast the signed transaction:**
47-
- Send the signed transaction to the desired blockchain network.
48-
- Wait for the transaction to be mined and confirmed.
33+
### **Safe Singleton Factory**
34+
- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7`
35+
- **How-to:**
36+
- Import the Safe Singleton Factory information via. the [library](https://github.com/safe-global/safe-singleton-factory).
37+
- Use the `getSingletonFactoryInfo` function in hardhat config to get the factory address, deployer address, and signed transaction.
4938

50-
4. **Verify the deployment:**
51-
- Check the [blockchain explorer](https://docs.filecoin.io/networks/mainnet/explorers) to verify that the factory contract has been deployed to the expected address.
52-
- Ensure the contract code matches the expected bytecode.
39+
```ts
40+
import { getSingletonFactoryInfo } from '@safe-global/safe-singleton-factory'
5341

54-
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.
55-
## **Using Popular Tools on Filecoin**
42+
...
5643

57-
### **1. Deterministic Deployment Proxy by Arachnid**
58-
- **Address:** `0x4e59b44847b379578588920ca78fbf26c0b4956c`
59-
- **How-to:**
60-
- Signing the Proxy deployment transaction is hidden, only recover the public key from the signed transaction.
61-
- 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.
62-
- [Repository Link](https://github.com/Arachnid/deterministic-deployment-proxy/tree/master)
44+
function deterministicDeployment(network: string): DeterministicDeploymentInfo {
45+
const info = getSingletonFactoryInfo(parseInt(network))
6346

64-
### **2. Safe Singleton Factory**
65-
- **Address:** `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7`
66-
- **How-to:**
67-
- Safe Multisig Wallet
68-
- Deployed by Masa Finance, Starlings lab, and align.network on many blockchains.
69-
- [Masa Finance](https://www.masa.ai/)
70-
- [align.network](http://align.network)
71-
- [Repository Link](https://github.com/safe-global/safe-singleton-factory)
47+
...
48+
return {
49+
factory: info.address,
50+
deployer: info.signerAddress,
51+
funding: String(gasLimit * gasPrice),
52+
signedTx: info.transaction,
53+
}
54+
}
55+
```
7256

73-
### **3. CreateX / xdeployer by pcaversaccio**
57+
### **CreateX / xdeployer by pcaversaccio**
7458
- **Address:** `0xba5Ed099633D3B313e4D5F7bdc1305d3c28ba5Ed`
7559
- **How-to:**
76-
- Deploy it yourself using one of the pre-signed transactions. Details can be found in the repository.
77-
- xdeployer is a hardhat plugin that allows you to deploy your smart contracts across multiple EVM chains with the same deterministic address.
78-
- It is deployed on Filecoin mainnet and testnet.
79-
- 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+).
80-
- [CreateX Repository](https://github.com/pcaversaccio/createx), [xdeployer Repository](https://github.com/pcaversaccio/xdeployer)
81-
- [Deployment Result from Dune](https://dune.com/patronumlabs/createx)
82-
83-
### **4. OpenZeppelin Defender**
60+
- 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).
61+
- [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:
62+
63+
```ts
64+
import "xdeployer";
65+
66+
const config: HardhatUserConfig = {
67+
networks: {
68+
mainnet: { ... }
69+
},
70+
xdeploy: {
71+
contract: "YOUR_CONTRACT_NAME_TO_BE_DEPLOYED",
72+
constructorArgsPath: "PATH_TO_CONSTRUCTOR_ARGS", // optional; default value is `undefined`
73+
salt: "YOUR_SALT_MESSAGE",
74+
signer: "SIGNER_PRIVATE_KEY",
75+
networks: ["LIST_OF_NETWORKS"],
76+
rpcUrls: ["LIST_OF_RPCURLS"],
77+
gasLimit: 1_500_000, // optional; default value is `1.5e6`
78+
},
79+
};
80+
```
81+
82+
or in the case of solidity files:
83+
84+
```solidity
85+
// SPDX-License-Identifier: MIT
86+
pragma solidity ^0.8.23;
87+
88+
import { CreateX } from "xdeployer/src/contracts/CreateX.sol";
89+
90+
contract Create2DeployerLocal is CreateX {}
91+
```
92+
93+
### **OpenZeppelin Defender**
8494
- **Address:** N/A
8595
- **How-to:**
8696
- Follow the tutorial to use OpenZeppelin Defender for deterministic deployments.

0 commit comments

Comments
 (0)