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 19 commits
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"
}
190 changes: 190 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,190 @@
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.

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

<CH.Section>
<CH.Code style={{ boxShadow: 'none' }}>
```bash pnpm
pnpm add @safe-global/protocol-kit
```

```bash npm
npm install @safe-global/protocol-kit
```

```bash yarn
yarn add @safe-global/protocol-kit
```
</CH.Code>
</CH.Section>

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

## Steps

<Steps>

### Imports

Import the `Safe` class from the Protocol Kit and chain configuration from `Viem`.

{/* <!-- 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

You need a signer to instantiate the Protocol Kit. This example uses a private key to obtain a signer, but other [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible signers are also supported. For detailed information about signers and providers, please refer to the [Protocol Kit reference](../../reference/safe.mdx#initialization).

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

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

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

### Define the Safe Configuration

Define the configuration for your Safe. This example includes the `owners`, `threshold`, `deploymentType`, `saltNonce`, and the `safeVersion`. You can read more about these properties in the [Protocol Kit reference](../../reference/safe.mdx#initialization).

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

```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 Protocol Kit for Sepolia and Chiado chain

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 predicted address across chains.

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

```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 Chiado chain using the same `predictedSafe` configuration to ensure the Safe address matches the one deployed on Sepolia.

{/* <!-- 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())
```

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

</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.
160 changes: 160 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,160 @@
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.

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

<CH.Section>
<CH.Code style={{ boxShadow: 'none' }}>
```bash pnpm
pnpm add @safe-global/protocol-kit
```

```bash npm
npm install @safe-global/protocol-kit
```

```bash yarn
yarn add @safe-global/protocol-kit
```
</CH.Code>
</CH.Section>

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

## Steps

<Steps>

### Imports

Import the `Safe` class from the Protocol Kit.

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

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

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

### Create a signer

You need a signer to instantiate the Protocol Kit. This example uses a private key to obtain a signer, but other [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible signers are also supported. For detailed information about signers and providers, please refer to the [Protocol Kit reference](../../reference/safe.mdx#initialization).

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

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

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

### Initialize the Protocol Kit

Initialize the Protocol Kit with the `provider`, `signer`, and the `predictedSafe` configuration. The `predictedSafe` property is used to define the desired configuration of the Safe account. You can read more about the avalable options in the [Protocol Kit reference](../../reference/safe.mdx#initialization).

Check failure on line 68 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 'avalable'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'avalable'?", "location": {"path": "pages/sdk/protocol-kit/guides/safe-deployment/deploy-safe.mdx", "range": {"start": {"line": 68, "column": 223}}}, "severity": "ERROR"}

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

```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 by using the `getAddress` method in the Protocol Kit.

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

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

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

### Create the deployment transaction

In this step we are going to create the transaction to deploy a new Safe account.

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

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

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

### Execute the deployment transaction

Once we create the deployment transaction object, we can execute it using the signer you specified earlier or your preferred external Ethereum client.

{/* <!-- 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 })
```

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

### Reconnect the Protocol Kit to the newly deployed Safe

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

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

```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())
```

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

</Steps>


## Recap and further reading

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