Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Add multichain Safe deployments guide #617

Merged
merged 27 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e1d7f5d
Add new safe-deployment guides
DaniSomoza Oct 15, 2024
3c92fec
Add installation snippet to align with our new documentation format
DaniSomoza Oct 25, 2024
a9495f9
fix comment in the import step
DaniSomoza Oct 25, 2024
638b413
update signer instantiation details
DaniSomoza Oct 25, 2024
29e97f2
update 'predictedSafe' property in Protocol Kit initialization
DaniSomoza Oct 25, 2024
753a8c4
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
6e02179
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
b92fc22
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
4be82a1
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
0b2dc93
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
0a8a7c8
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
bcbc179
Update pages/sdk/protocol-kit/guides/safe-deployment/address-replicat…
DaniSomoza Oct 25, 2024
7a0da37
Update pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
DaniSomoza Oct 25, 2024
f946aef
Update pages/sdk/protocol-kit/guides/safe-deployment/address-replicat…
DaniSomoza Oct 25, 2024
38b666a
updated Safe import section
DaniSomoza Oct 25, 2024
8242563
Update pages/sdk/protocol-kit/guides/safe-deployment/address-replicat…
DaniSomoza Oct 25, 2024
b66551c
fix: disable Vale in code snippets
dasanra Oct 25, 2024
a8be9b2
fix: move some Vale config entries to correct lines
dasanra Oct 25, 2024
5241929
chore: fix wording and style about initializaton
dasanra Oct 25, 2024
011b1d3
Merge branch 'main' into safe-deployment-guide-v2
germartinez Oct 31, 2024
5811e71
Fixes in Deploy Safe guide
germartinez Oct 31, 2024
680d3d3
Adjust multichain deployment guide
germartinez Oct 31, 2024
2a625ee
Adjustments in Safe deployment guide
germartinez Oct 31, 2024
d86d6fe
Rename guides
germartinez Oct 31, 2024
ca9366e
List deployment guides in the overview
germartinez Oct 31, 2024
daf0cb1
Fix vale
germartinez Oct 31, 2024
f6bff10
Update links
germartinez Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pages/sdk/protocol-kit/guides/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"safe-deployment": "Safe deployment",
"execute-transactions": "Execute transactions",
"signatures": "Signatures",
"migrate-to-v1": "Migrate to v1",
Expand Down
4 changes: 4 additions & 0 deletions pages/sdk/protocol-kit/guides/safe-deployment/_meta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"deploy-safe": "Deploy a Safe",
"address-replication": "Address replication"
}
173 changes: 173 additions & 0 deletions pages/sdk/protocol-kit/guides/safe-deployment/address-replication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
import { Steps } from "nextra/components";

# Safe Address Replication Across Chains

In this guide, you will learn how to replicate a Safe address across different chains using the Protocol Kit. This process includes initializing the Protocol Kit, configuring the Safe, predicting the Safe address on different chains, and executing the deployment.

We will demonstrate how to deploy a Safe account on both the Sepolia and Chiado chains with the same address using the Protocol Kit.

For more detailed information, see the [Protocol Kit Reference](../../../protocol-kit/reference/safe.mdx).

## Prerequisites

- [Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)

## Install dependencies

First, you need to install the Protocol Kit.

```bash
pnpm add @safe-global/protocol-kit
dasanra marked this conversation as resolved.
Show resolved Hide resolved
```

## Steps

<Steps>

### Imports

Begin by importing the `Safe` class from the Protocol Kit and chain configuration from viem.
dasanra marked this conversation as resolved.
Show resolved Hide resolved
dasanra marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
import Safe, { SafeDeploymentConfig, SafeAccountConfig } from '@safe-global/protocol-kit'
import { waitForTransactionReceipt } from 'viem/actions'
import { sepolia, gnosisChiado } from 'viem/chains'
```

{/* <!-- vale on --> */}

### Create a signer

Firstly, you need to get a signer to execute the deployment transaction in each chain. this example uses a private key, but any way to get an `EIP-1193` compatible signer can be used.
dasanra marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const SIGNER_PRIVATE_KEY = // ...
```

{/* <!-- vale on --> */}

### Define the Safe Configuration

{/* <!-- vale off --> */}

Define the configuration for your Safe. This includes the `owners`, `threshold`, deployment type, salt nonce for address predictability, and the version of the Safe.
dasanra marked this conversation as resolved.
Show resolved Hide resolved

```typescript
// Safe account config
const safeAccountConfig: SafeAccountConfig = {
owners: ['0xOwnerAddress'],
threshold: 1
}

// Safe deployment config
const safeDeploymentConfig: SafeDeploymentConfig = {
deploymentType: 'canonical',
saltNonce: '12345',
safeVersion: '1.3.0'
}
```

{/* <!-- vale on --> */}

### Initialize the `ProtocolKit` for Sepolia and Chiado chain
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}


Initialize the Protocol Kit for deploying on Sepolia and Chiado. Set up the provider and signer along with the predicted Safe configuration.

You can use the `getAddress` method to ensure that the Safe account has the same address across chains.
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

```typescript
let protocolKitSepolia = await Safe.init({
provider: sepolia.rpcUrls.default.http[0],
signer: SIGNER_PRIVATE_KEY,
predictedSafe: {
safeAccountConfig,
safeDeploymentConfig
}
})

let protocolKitChiado = await Safe.init({
provider: gnosisChiado.rpcUrls.default.http[0],
signer: PRIVATE_KEY,
predictedSafe: {
safeAccountConfig,
safeDeploymentConfig
}
})

const safeAddressInSepolia = await protocolKitSepolia.getAddress()
const safeAddressInChiado = await protocolKitChiado.getAddress()

console.log('safeAddressInSepolia: ', safeAddressInSepolia)
console.log('safeAddressInChiado: ', safeAddressInChiado)
```

{/* <!-- vale on --> */}

### Deploy the Safe on Sepolia

Create and send the deployment transaction on Sepolia.

{/* <!-- vale off --> */}

```typescript
const deploymentTransactionInSepolia = await protocolKitSepolia.createSafeDeploymentTransaction()

const sepoliaClient = await protocolKitSepolia.getSafeProvider().getExternalSigner()

const txHashSepolia = await sepoliaClient!.sendTransaction({
to: deploymentTransactionInSepolia.to,
value: BigInt(deploymentTransactionInSepolia.value),
data: deploymentTransactionInSepolia.data as `0x${string}`,
chain: sepolia
})

await waitForTransactionReceipt(sepoliaClient!, { hash: txHashSepolia })

protocolKitSepolia = await protocolKitSepolia.connect({ safeAddress: safeAddressInSepolia })

// Confirm the Safe is deployed in Sepolia and fetch Safe info
console.log('Is Safe deployed:', await protocolKitSepolia.isSafeDeployed())
console.log('Safe Address:', await protocolKitSepolia.getAddress())
```

{/* <!-- vale on --> */}

### Repeat Deployment for Chiado

Repeat the initialization and deployment for the Chiado chain using the same predictedSafe configuration to ensure the Safe address matches the one deployed on Sepolia.

Check failure on line 144 in pages/sdk/protocol-kit/guides/safe-deployment/address-replication.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'predictedSafe'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'predictedSafe'?", "location": {"path": "pages/sdk/protocol-kit/guides/safe-deployment/address-replication.mdx", "range": {"start": {"line": 144, "column": 78}}}, "severity": "ERROR"}
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const deploymentTransactionInChiado = await protocolKitChiado.createSafeDeploymentTransaction()

const chiadoClient = await protocolKitChiado.getSafeProvider().getExternalSigner()

const txHashChiado = await chiadoClient!.sendTransaction({
to: deploymentTransactionInChiado.to,
value: BigInt(deploymentTransactionInChiado.value),
data: deploymentTransactionInChiado.data as `0x${string}`,
chain: gnosisChiado
})

await waitForTransactionReceipt(chiadoClient!, { hash: txHashChiado })

protocolKitChiado = await protocolKitChiado.connect({ safeAddress: safeAddressInChiado })

// Confirm the Safe is deployed in Chiado and fetch properties
console.log('Is Safe deployed:', await protocolKitChiado.isSafeDeployed())
console.log('Safe Address:', await protocolKitChiado.getAddress())
```

</Steps>

## Recap and further reading

By following this guide, you've learned how to deploy Safes with the same address on multiple chains using the Protocol Kit.
139 changes: 139 additions & 0 deletions pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import { Steps } from 'nextra/components'

# Deploy a Safe

In this guide, you will learn how to deploy a new Safe using the Protocol Kit. This process includes initializing the Protocol Kit, setting up your Safe configuration, and executing the deployment.

For more detailed information, see the [Protocol Kit Reference](../../../protocol-kit/reference/safe.mdx).

## Prerequisites

- [Node.js and npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm)

## Install dependencies

First, you need to install the Protocol Kit.

```bash
pnpm add @safe-global/protocol-kit
dasanra marked this conversation as resolved.
Show resolved Hide resolved
```

## Steps

<Steps>

### Imports

Begin by importing the `Safe` class from the Protocol Kit.
dasanra marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
import Safe from '@safe-global/protocol-kit'
```

{/* <!-- vale on --> */}

### Create a signer

Firstly, you need to get a signer, this example uses a private key, but any way to get an `EIP-1193` compatible signer can be used.
dasanra marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const SIGNER_PRIVATE_KEY = // ...
const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'
```

{/* <!-- vale on --> */}

### Initialize the `ProtocolKit`
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

Initialize the Protocol Kit with the `provider`, `signer`, and the `predictedSafe` configuration.
dasanra marked this conversation as resolved.
Show resolved Hide resolved

```typescript
// Define your Safe configuration
const predictedSafe = {
safeAccountConfig: {
owners: ['0xOwner1', '0xOwner2', '0xOwner3'], // In this example, 3 owners
threshold: 2 // Requires at least 2 signatures to approve a transaction
}
}

// Initialize the Protocol Kit with the predictedSafe
const protocolKit = await Safe.init({
provider: RPC_URL,
signer: SIGNER_PRIVATE_KEY,
predictedSafe
})
```

{/* <!-- vale on --> */}

### Predict your Safe address

you can predict your Safe address using the `getAddress` method in the Protocol Kit.
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const safeAddress = await protocolKit.getAddress()
```

{/* <!-- vale on --> */}

### Create the deployement transaction

Check failure on line 87 in pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'deployement'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'deployement'?", "location": {"path": "pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx", "range": {"start": {"line": 87, "column": 18}}}, "severity": "ERROR"}
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

Now, generate the transaction to deploy the Safe and execute it using the Protocol Kit.
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const deploymentTransaction = await protocolKit.createSafeDeploymentTransaction()
```

{/* <!-- vale on --> */}

### Execute the deployement transaction

Check failure on line 99 in pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'deployement'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'deployement'?", "location": {"path": "pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx", "range": {"start": {"line": 99, "column": 19}}}, "severity": "ERROR"}
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

You can execute the deployement transaction using the integrated signer or your preferred external Ethereum client.

Check failure on line 101 in pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'deployement'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'deployement'?", "location": {"path": "pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx", "range": {"start": {"line": 101, "column": 23}}}, "severity": "ERROR"}
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

{/* <!-- vale off --> */}

```typescript
const client = await protocolKit.getSafeProvider().getExternalSigner()

const txHash = await client.sendTransaction({
to: deploymentTransaction.to,
value: BigInt(deploymentTransaction.value),
data: deploymentTransaction.data as `0x${string}`,
chain: sepolia
})

const txReceipt = await client.waitForTransactionReceipt({ hash: txHash })
```

### Reconnect the `protocolKit` to the newly deployed Safe
DaniSomoza marked this conversation as resolved.
Show resolved Hide resolved

Once the deployment transaction has been successfully executed, it's necessary to reconnect your Protocol Kit instance to the address of the newly created Safe using the `connect` Method

```typescript
// Reconnect to the newly deployed Safe using the protocol-kit
protocolKit = await protocolKit.connect({ safeAddress })

// Confirm the Safe is deployed and fetch properties
console.log("Is Safe deployed:", await protocolKit.isSafeDeployed())
console.log("Safe Address:", await protocolKit.getAddress())
console.log("Safe Owners:", await protocolKit.getOwners())
console.log("Safe Threshold:", await protocolKit.getThreshold())
```


</Steps>


## Recap and further reading

After following this guide, you are able to deploy new Safe accounts with the Protocol Kit.
Loading