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 all 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
2 changes: 1 addition & 1 deletion .github/styles/config/vocabularies/default/accept.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
[Mm]ainnet
[Mm]iddleware
[Mm]onerium
[Mm]ultichain
[Mm]ultisig
[Mm]ultisend
[Nn]extra
Expand Down Expand Up @@ -263,7 +264,6 @@ maxWidth
mempool
messageHash
monorepo
multichain
npm
onboarding
onchain
Expand Down
2 changes: 2 additions & 0 deletions pages/sdk/protocol-kit.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ The Protocol Kit enables developers to interact with [Safe Smart Accounts](https
</Grid>

The following guides show how to use the Protocol Kit and integrate it into your project:
- [Safe deployment](./protocol-kit/guides/safe-deployment.mdx)
- [Multichain Safe deployment](./protocol-kit/guides/multichain-safe-deployment.mdx)
- [Execute transactions](./protocol-kit/guides/execute-transactions.mdx)
- [Transactions signatures](./protocol-kit/guides/signatures/transactions.mdx)
- [Message signatures](./protocol-kit/guides/signatures/messages.mdx)
Expand Down
2 changes: 2 additions & 0 deletions pages/sdk/protocol-kit/guides/_meta.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"safe-deployment": "Safe deployment",
"multichain-safe-deployment": "Multichain Safe deployment",
"execute-transactions": "Execute transactions",
"signatures": "Signatures",
"migrate-to-v1": "Migrate to v1",
Expand Down
209 changes: 209 additions & 0 deletions pages/sdk/protocol-kit/guides/multichain-safe-deployment.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
import { Steps } from 'nextra/components'

# Multichain Safe Deployment

This guide will teach you how to replicate a Safe address across different chains using the Protocol Kit. This process includes initializing the Protocol Kit, configuring the Safes to deploy, predicting its address on different chains, and executing the deployment transactions.

## 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 --> */}

```bash
pnpm add @safe-global/protocol-kit viem
```

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

## Steps

<Steps>

### Imports

Here are all the necessary imports for this guide.

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

```typescript
import Safe, {
PredictedSafeProps,
SafeAccountConfig,
SafeDeploymentConfig
} from '@safe-global/protocol-kit'
import { waitForTransactionReceipt } from 'viem/actions'
import { gnosisChiado, sepolia } 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, please refer to the [Protocol Kit reference](../../../reference-sdk-protocol-kit/overview.md).

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

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

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

### Configure the Safe deployment

Define the [`predictedSafe`](../../../reference-sdk-protocol-kit/initialization/init.mdx#predictedsafe-optional) object with the configuration for all the Safe accounts you will deploy. Check the reference to learn about all the different configuration options.

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

```typescript
const safeAccountConfig: SafeAccountConfig = {
owners: ['0x...', '0x...', '0x...'],
threshold: 2
// More optional properties
}

const predictedSafe: PredictedSafeProps = {
safeAccountConfig
// More optional properties
}
```

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

### Initialize the Protocol Kit

Initialize an instance of the Protocol Kit for each network where you want to deploy a new Safe smart account by calling the [`init`](../../../reference-sdk-protocol-kit/initialization/init.mdx) method. Pass the `provider` with its corresponding value depending on the network, the `signer` executing the deployment, and the [`predictedSafe`](../../../reference-sdk-protocol-kit/initialization/init.mdx#predictedsafe-optional) with the Safe account configuration.

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

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

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

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

### Predict the Safe addresses

You can predict the Safe addresses by calling the [`getAddress`](../../../reference-sdk-protocol-kit/safe-info/getaddress.mdx) method from each Protocol Kit instance and ensure that the result addresses are the same.

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

```typescript
const sepoliaPredictedSafeAddress = await protocolKitSepolia.getAddress()
const chiadoPredictedSafeAddress = await protocolKitChiado.getAddress()
```

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

### Deployment on Sepolia

Create the deployment transaction to deploy a new Safe account in Sepolia by calling the [`createSafeDeploymentTransaction`](../../../reference-sdk-protocol-kit/deployment/createsafedeploymenttransaction.mdx) method.

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

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

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

Call the `sendTransaction` method from your Sepolia client instance and wait for the transaction to be executed.

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

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

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

await waitForTransactionReceipt(
sepoliaClient!,
{ hash: transactionHashSepolia }
)
```

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

Once the deployment transaction is executed, connect the new Safe address to the Protocol Kit instance by calling the [`connect`](../../../reference-sdk-protocol-kit/initialization/connect.mdx) method.

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

```typescript
const newProtocolKitSepolia = await protocolKitSepolia.connect({
safeAddress: sepoliaPredictedSafeAddress
})

const isSepoliaSafeDeployed = await newProtocolKitSepolia.isSafeDeployed() // True
const sepoliaDeployedSafeAddress = await newProtocolKitSepolia.getAddress()
```

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

If everything went well, `isSepoliaSafeDeployed` should be `true`, and the `sepoliaDeployedSafeAddress` should equal the `sepoliaPredictedSafeAddress`.

### Deployment on Chiado

Repeat the same steps to deploy a Safe with the same configuration on Chiado testnet.

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

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

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

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

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

const newProtocolKitChiado = await protocolKitChiado.connect({
safeAddress: chiadoPredictedSafeAddress
})

const isChiadoSafeDeployed = await newProtocolKitChiado.isSafeDeployed() // True
const chiadoDeployedSafeAddress = await newProtocolKitChiado.getAddress()
```

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

If everything went well, `isChiadoSafeDeployed` should be `true`, and the `chiadoDeployedSafeAddress` should equal the `chiadoPredictedSafeAddress`.

In addition, `chiadoDeployedSafeAddress` and `sepoliaDeployedSafeAddress` should have the same value.

</Steps>

## Recap and further reading

After following this guide, you are able to deploy multiple Safe accounts with the same address on different chains using the Protocol Kit.
155 changes: 155 additions & 0 deletions pages/sdk/protocol-kit/guides/safe-deployment.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
import { Steps } from 'nextra/components'

# Safe Deployment

This guide will teach you 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](../../../reference-sdk-protocol-kit/overview.mdx).

## Prerequisites

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

## Install dependencies

First, you need to install some dependencies.

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

```bash
pnpm add @safe-global/protocol-kit viem
```

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

## Steps

<Steps>

### Imports

Here are all the necessary imports for this guide.

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

```typescript
import Safe, {
PredictedSafeProps,
SafeAccountConfig,
SafeDeploymentConfig
} from '@safe-global/protocol-kit'
import { sepolia } 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 [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) compatible signers are also supported. For detailed information about signers, please refer to the [Protocol Kit reference](../../../reference-sdk-protocol-kit/overview.md).

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

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

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

### Initialize the Protocol Kit

Initialize an instance of the Protocol Kit for each network where you want to deploy a new Safe smart account by calling the [`init`](../../../reference-sdk-protocol-kit/initialization/init.mdx) method. Pass the `provider` with its corresponding value depending on the network, the `signer` executing the deployment, and the [`predictedSafe`](../../../reference-sdk-protocol-kit/initialization/init.mdx#predictedsafe-optional) with the Safe account configuration.

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

```typescript
const safeAccountConfig: SafeAccountConfig = {
owners: ['0x...', '0x...', '0x...'],
threshold: 2
// More optional properties
}

const predictedSafe: PredictedSafeProps = {
safeAccountConfig
// More optional properties
}

const protocolKit = await Safe.init({
provider: sepolia.rpcUrls.default.http[0],
signer: SIGNER_PRIVATE_KEY,
predictedSafe
})
```

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

### Predict the Safe address

You can predict the Safe address using the [`getAddress`](../../../reference-sdk-protocol-kit/safe-info/getaddress.mdx) method in the Protocol Kit.

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

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

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

### Create the deployment transaction

Create the deployment transaction to deploy a new Safe smart account by calling the [`createSafeDeploymentTransaction`](../../../reference-sdk-protocol-kit/deployment/createsafedeploymenttransaction.mdx) method.

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

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

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

### Execute the deployment transaction

Once the deployment transaction object is ready, execute it using the provided signer or your preferred external Ethereum client.

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

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

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

const transactionReceipt = await client.waitForTransactionReceipt({
hash: transactionHash
})
```

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

### Reinitialize the Protocol Kit

Once the deployment transaction is executed, connect the new Safe address to the Protocol Kit instance by calling the [`connect`](../../../reference-sdk-protocol-kit/initialization/connect.mdx) method.

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

```typescript
const newProtocolKit = await protocolKit.connect({
safeAddress
})

const isSafeDeployed = await newProtocolKit.isSafeDeployed() // True
const safeAddress = await newProtocolKit.getAddress()
const safeOwners = await newProtocolKit.getOwners()
const safeThreshold = await newProtocolKit.getThreshold()
```

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

</Steps>

## Recap and further reading

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