Skip to content

Commit

Permalink
Docs: Improve safe-singleton-factory docs (#266)
Browse files Browse the repository at this point in the history
* Improve safe-singleton-factory docs

* Improve safe-singleton-factory docs
  • Loading branch information
mmv08 authored Nov 13, 2023
1 parent 261ab53 commit 6b52fa2
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
12 changes: 12 additions & 0 deletions .github/release_new_npm_package_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: Biweekly release of the new npm package
assignees: "safe-global/safe-protocol"
---

It's time to release the new version to NPM. Before releasing, please:

1. Check if there are any breaking changes in the new version.
2. Check if there are any unreviewed PRs.
3. Create a pull request to bump the version in the `package.json` file.
4. Create a Github release with the new version.
5. Publish the new version to NPM.
37 changes: 37 additions & 0 deletions .github/workflows/create-release-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
on:
schedule:
# * is a special character in YAML so you have to quote this string
# There's no direct way to schedule the job run every 2 weeks, instead we schedule it on the 1st and 15th of every month. The trick is taken from https://stackoverflow.com/a/46233330/7820085
- cron: "30 1 1,15 * *"

name: Create an issue to release the NPM package
permissions:
contents: read
issues: write

jobs:
create_issue:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main

- name: Check if there's been any commits in the last two weeks
run: |
counter=$(git log --since='2 weeks ago' --pretty=oneline | wc -l)
if [ $counter -eq 0 ]; then
echo "No commits in the last two weeks, exiting"
exit 1
fi
echo "There are $counter commits in the last two weeks, continuing"
- name: Create an issue
uses: JasonEtco/create-an-issue@v2
if: success()
with:
filename: .github/release_new_npm_package_template.md
update_existing: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
47 changes: 32 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,68 @@
# Safe Singleton Factory

Singleton factory used by Safe related contracts based on https://github.com/Arachnid/deterministic-deployment-proxy
Singleton factory used by Safe-related contracts based on https://github.com/Arachnid/deterministic-deployment-proxy

The original library used a presigned transaction without a chain id to allow deployment on different chains. Some chains do not allow such transactions to be submitted (e.g. Celo and Avalanche) therefore this repository will provide the same factory that can be deployed via a presigned transaction that includes the chain id. The key that is used to sign is controlled by the Safe team.
The original library used a pre-signed transaction without a chain ID to allow deployment on different chains. Some chains do not allow such transactions to be submitted (e.g. Celo and Avalanche); therefore, this repository will provide the same factory that can be deployed via a pre-signed transaction that includes the chain ID. The key that is used to sign is controlled by the Safe team.

# User documentation

## Explanation (from Arachnid's repo)

This repository contains a simple contract that can deploy other contracts with a deterministic address on any chain using CREATE2. The CREATE2 call will deploy a contract (like CREATE opcode), but instead of the address being `keccak256(rlp([deployer_address, nonce]))` it instead uses the hash of the contract's bytecode and a salt. This means that a given deployer address will deploy the same code to the same address no matter when or where they issue the deployment. The deployer is deployed with a one-time-use account, so its address will always be the same no matter what chain the deployer is on. This means the only variables in determining your contract's address are its bytecode hash and the provided salt.

Between the use of CREATE2 opcode and the one-time-use account for the deployer, we can ensure that a given contract will exist at the exact same address on every chain, but without using the exact gas pricing or limits every time.

## Encoding the deployment transaction

The data should be the 32 byte 'salt' followed by the init code.

## How to get the singleton deployed to your network

As the singleton is deployed with an EIP155 transaction, we need to sign the deployment transaction for your network. But some prerequisites must be met before that, and the most important one is having funds on the deployer so we can deploy the contract.
As the singleton is deployed with an EIP155 transaction, we must sign the deployment transaction for your network. But some prerequisites must be met before that, and the most important one is having funds on the deployer so we can deploy the contract.

1. Make sure your network is on https://chainlist.org/ . We will not accept networks not present there.
2. Create an issue following the request for a new network template.
3. Once the issue is created, the issue will be automatically validated, and a bot will post a comment with the address of the deployer and the amount of funds needed to deploy the contract.
4. After you have sent the funds to the deployer, mark the checkbox on the issue, and the Safe team will sign the transaction and deploy the contract.

- Make sure your network is on https://chainlist.org/ . We will not accept networks not present there.
- Install dependencies running `yarn`.
- Estimate the contract deployment: `RPC='http://my-rpc-address' yarn estimate`.
- Send `requiredFunds` to the deployer address `0xE1CB04A0fA36DdD16a06ea828007E35e1a3cBC37`.
- Open a PR and we will deploy the singleton contract.
The Safe team will aim to respond to new network requests within two weeks.

## Expected Addresses

For all networks the same deployer key is used. The address for this key is `0xE1CB04A0fA36DdD16a06ea828007E35e1a3cBC37`.
For all networks, the same deployer key is used. The address for this key is `0xE1CB04A0fA36DdD16a06ea828007E35e1a3cBC37`.

This results in the address for the factory being `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7` for all bytecode-compatible EVM networks.

For zkSync-based networks, the same deployer is used, and the expected factory address is `0xaECDbB0a3B1C6D1Fe1755866e330D82eC81fD4FD`, and the factory is deployed using the `create2` method of the system deployer using the zero hash (`0x0000000000000000000000000000000000000000000000000000000000000000`).

This results in the address for the factory to be `0x914d7Fec6aaC8cd542e72Bca78B30650d45643d7` for all bytecode compatible EVM networks.
## NPM Package release cycle

For zkSync based networks the same deployer is used and expected factory address is `0xaECDbB0a3B1C6D1Fe1755866e330D82eC81fD4FD`.
The Safe team will aim to release a new version of the package every two weeks.

Note: For zkSync the factory is deployed using the `create2` method of the system deployer using the zero hash (`0x0000000000000000000000000000000000000000000000000000000000000000`).
Please note that the package is not required for the factory to work. The package is only a convenience for developers to use the factory.
Most libraries that support deterministic deployments accept the factory address as a parameter, so you can use the factory without the package.
For example, see the [documentation](https://github.com/wighawag/hardhat-deploy/blob/42964ca4f74a3f3c57cf694e9713b335f8ba7b2c/README.md#4-deterministicdeployment-ability-to-specify-a-deployment-factory) for the `deterministicDeployment` option in the `hardhat-deploy` plugin.

# Safe developers documentation

## Adding new networks

To generate the deployment data for a new network the following steps are necessary:
To generate the deployment data for a new network, the following steps are necessary:

- Set `RPC` in the `.env` file for the new network.
- Set `MNEMONIC` in the `.env` file.
- Estimate transaction params via `yarn estimate`
- Run `yarn compile <chain_id> [--gasPrice <overwrite_gas_price>] [--gasLimit <overwrite_gas_limit>]`

To do `estimate` and `compile` steps together:
To do the `estimate` and `compile` steps together:

- Run `yarn estimate-compile ["$RPC"]`

To submit a transaction after the deployment data is created:

- Run `yarn submit`

## For zkSync
## For zkSync-based networks

- Set `MNEMONIC` or `PK` in the `.env` file
- Run `yarn compile:zk`

0 comments on commit 6b52fa2

Please sign in to comment.