Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/safe-global/safe-docs into …
Browse files Browse the repository at this point in the history
…google-tag
  • Loading branch information
louis-md committed May 24, 2024
2 parents 1e518a4 + f5781a5 commit 9998bc9
Show file tree
Hide file tree
Showing 35 changed files with 731 additions and 551 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.5.4",
"version": "4.6.0",
"description": "Safe docs",
"scripts": {
"build": "next build",
Expand Down
7 changes: 0 additions & 7 deletions pages/advanced/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
"smart-account-supported-networks": "Supported Networks",
"smart-account-audits": "Audits",
"smart-account-bug-bounty": "Bug Bounty",
"-- Safe{Core} API Infrastructure": {
"type": "separator",
"title": "Safe{Core} API Infrastructure"
},
"api-overview": "Overview",
"api-safe-transaction-service": "Safe Transaction Service",
"api-new-networks": "Add New Networks",
"-- Safe CLI": {
"type": "separator",
"title": "Safe CLI"
Expand Down
11 changes: 9 additions & 2 deletions pages/core-api/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
"title": "← Go Home",
"href": "/"
},
"-- Safe Transaction Service API": {
"-- Safe{Core} Infrastructure": {
"type": "separator",
"title": "Safe Transaction Service API"
"title": "Safe{Core} Infrastructure"
},
"api-overview": "Overview",
"api-safe-transaction-service": "Running the Safe Transaction Service",
"api-support-new-chains": "Support New Chains",
"-- Safe Transaction Service": {
"type": "separator",
"title": "Safe Transaction Service"
},
"transaction-service-overview": "Overview",
"transaction-service-supported-networks": "Supported Networks",
Expand Down
28 changes: 17 additions & 11 deletions pages/advanced/api-overview.md → pages/core-api/api-overview.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
# Service architecture
# Safe{Core} Infrastructure

The Safe{Core} infrastructure consists of the following services:
The Safe{Core} Infrastructure consists of the following services:

* [Safe Transaction Service](https://github.com/safe-global/safe-transaction-service): Keeps track of transactions related to Safe contracts (Python).
* [Safe Events Service](https://github.com/safe-global/safe-events-service): Handles Safe indexing events from the Transaction Service and delivers them as HTTP webhooks (NodeJS).
## Safe Transaction Service

Safe{Wallet} uses these services to offer functionality to end customers via the web and mobile applications. The [Safe Client Gateway](https://github.com/safe-global/safe-client-gateway-nest) acts as a facade between the end customer and the Safe{Core} services and the [Safe Config Service](https://github.com/safe-global/safe-config-service) stores all supported networks and chain-specific variables.
The Safe Transaction Service tracks transactions related to Safe contracts using tracing on Mainnet, Sepolia, and Gnosis Chain. It uses event indexing for the other chains. For each [supported network](./transaction-service-supported-networks.md) there is one instance of the Transaction Service.

Safe's production setup consists of several instances of the Transaction Service orchestrated by the Config Service, which are later consumed by the Safe Client Gateway. The Events Service notifies the Safe Client Gateway when new events are indexed, helping to improve the user experience.
- Learn about the [tech stack and how to run the service](./api-safe-transaction-service.mdx).
- Learn about the [Safe Transaction Service API](./transaction-service-overview.mdx).
- Check the [API Reference](./transaction-service-reference.mdx).
- Check the [GitHub repository](https://github.com/safe-global/safe-transaction-service) (Python).

![Overview of the backend services and their components.](../../assets/diagram-services.png)
## Safe Events Service

## Safe Transaction Service
The Events Service handles Safe indexing events and delivers them as HTTP webhooks, connection to the events queue processed by the Transaction Service. The service's database stores the configuration of webhook destinations.

The Transaction Service uses tracing in Mainnet/Sepolia and Gnosis Chain and event indexing in other chains to keep track of transactions related to Safe contracts. One instance of the Transaction Service runs per supported network (Mainnet, Sepolia, Gnosis Chain, Polygon, etc.).
- Check the [GitHub repository](https://github.com/safe-global/safe-events-service) (NodeJS).

## Safe Events Service
## Architecture

Safe{Wallet} uses these services to offer functionality to end customers via the web and mobile applications. The [Safe Client Gateway](https://github.com/safe-global/safe-client-gateway-nest) acts as a facade between the end customer and the Safe{Core} services and the [Safe Config Service](https://github.com/safe-global/safe-config-service) stores all supported networks and chain-specific variables.

The Events Service connects to the events queue processed by the Transaction Service. It handles Safe indexing events and delivers them as HTTP webhooks. The service's database stores the configuration of webhook destinations.
Safe's production setup consists of several instances of the Transaction Service orchestrated by the Config Service, which are later consumed by the Safe Client Gateway. The Events Service notifies the Safe Client Gateway when new events are indexed, helping to improve the user experience.

![Overview of the backend services and their components.](../../assets/diagram-services.png)

## Integration Flow for Safe{Wallet} and Safe{Core}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Safe Transaction Service
# Running the Safe Transaction Service

The Safe Transaction Service tracks transactions sent via Safe contracts. It indexes these transactions using events (L2 chains) and tracing (L1 chains) mechanisms.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Steps } from 'nextra/components'

# Add New Networks
# Support New Chains

Safe's vision is to make every web3 account a smart account. Therefore, we prioritize teams and chains building with smart accounts, especially if they push account abstraction (for example, ERC-4337/EIP-1271 adoption) with Safe (learn more [here](https://docs.safe.global/home/4337-safe)).

Expand Down
24 changes: 5 additions & 19 deletions pages/core-api/transaction-service-guides/delegates.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
```typescript
import { ethers } from 'ethers'
import SafeApiKit, { AddSafeDelegateProps } from '@safe-global/api-kit'
import { EthersAdapter } from '@safe-global/protocol-kit'
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -65,22 +64,11 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the API Kit
const apiKit = new SafeApiKit({
chainId: 11155111n
})

const ownerAAddress = await ethAdapterOwnerA.getSignerAddress()

// Get the Safe delegates
const delegates = await apiKit.getSafeDelegates({
delegatorAddress: config.SAFE_ADDRESS
Expand Down Expand Up @@ -118,15 +106,13 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const provider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner B
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, provider)
const ownerAAddress = await ownerA.getAddress()

const ownerBAddress = await ethAdapterOwnerB.getSignerAddress()
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, provider)
const ownerBAddress = await ownerB.getAddress()

const delegateConfig: AddSafeDelegateProps = {
delegateAddress: ownerBAddress || '0x',
Expand Down
34 changes: 10 additions & 24 deletions pages/core-api/transaction-service-guides/messages.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```bash
yarn add ethers @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
yarn add @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -41,9 +41,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```typescript
import { ethers } from 'ethers'
import SafeApiKit, { AddMessageProps } from '@safe-global/api-kit'
import Safe, { EthersAdapter, hashSafeMessage } from '@safe-global/protocol-kit'
import Safe, { hashSafeMessage } from '@safe-global/protocol-kit'
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -67,18 +66,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the Protocol Kit with Owner A
const protocolKitOwnerA = await Safe.create({
ethAdapter: ethAdapterOwnerA,
const protocolKitOwnerA = await Safe.init({
provider: config.RPC_URL,
signer: config.OWNER_A_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -194,16 +185,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
// Instantiate an EthAdapter with Owner B
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})

// Initialize the Protocol Kit with Owner B
const protocolKitOwnerB = await Safe.create({
ethAdapter: ethAdapterOwnerB,
const protocolKitOwnerB = await Safe.init({
provider: config.RPC_URL,
signer: config.OWNER_B_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -243,7 +228,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
// Sign the message with Owner B
const signedMessageOwnerB = await protocolKitOwnerB.signMessage(safeServiceMessage)

const ownerBAddress = (await ethAdapterOwnerB.getSignerAddress()) || '0x'
// Get Owner B address
const ownerBAddress = '0x...'

// Send the message to the Transaction Service with the signature from Owner B
await apiKit.addMessageSignature(
Expand Down
35 changes: 9 additions & 26 deletions pages/core-api/transaction-service-guides/transactions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```bash
yarn add ethers @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
yarn add @safe-global/api-kit @safe-global/protocol-kit @safe-global/safe-core-sdk-types
```
</Tabs.Tab>
<Tabs.Tab>
Expand All @@ -41,9 +41,8 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python']}>
<Tabs.Tab>
```typescript
import { ethers } from 'ethers'
import SafeApiKit from '@safe-global/api-kit'
import Safe, { EthersAdapter } from '@safe-global/protocol-kit'
import Safe from '@safe-global/protocol-kit'
import {
MetaTransactionData,
OperationType
Expand All @@ -69,18 +68,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
const ethProvider = new ethers.JsonRpcProvider(config.RPC_URL)

// Instantiate an EthAdapter with Owner A
const ownerA = new ethers.Wallet(config.OWNER_A_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerA = new EthersAdapter({
ethers,
signerOrProvider: ownerA
})

// Initialize the Protocol Kit with Owner A
const protocolKitOwnerA = await Safe.create({
ethAdapter: ethAdapterOwnerA,
const protocolKitOwnerA = await Safe.init({
provider: config.RPC_URL,
signer: config.OWNER_A_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down Expand Up @@ -176,14 +167,12 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
chainId: 11155111n
})

const senderAddress = await ownerA.getAddress()

// Send the transaction to the Transaction Service with the signature from Owner A
await apiKit.proposeTransaction({
safeAddress: config.SAFE_ADDRESS,
safeTransactionData: safeTransaction.data,
safeTxHash,
senderAddress,
senderAddress: config.OWNER_A_ADDRESS,
senderSignature: signatureOwnerA.data
})
```
Expand Down Expand Up @@ -242,16 +231,10 @@ The different steps are implemented using [Curl](https://github.com/curl/curl) r
<Tabs items={['TypeScript', 'Python', 'Curl']}>
<Tabs.Tab>
```typescript
// Instantiate an EthAdapter with Owner B
const ownerB = new ethers.Wallet(config.OWNER_B_PRIVATE_KEY, ethProvider)
const ethAdapterOwnerB = new EthersAdapter({
ethers,
signerOrProvider: ownerB
})

// Initialize the Protocol Kit with Owner B
const protocolKitOwnerB = await Safe.create({
ethAdapter: ethAdapterOwnerB,
const protocolKitOwnerB = await Safe.init({
provider: config.RPC_URL,
signer: config.OWNER_B_PRIVATE_KEY,
safeAddress: config.SAFE_ADDRESS
})

Expand Down
6 changes: 3 additions & 3 deletions pages/core-api/transaction-service-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import Reference from '../../assets/svg/reference.svg'

# Safe Transaction Service API

The Safe Transaction Service API offers REST endpoints to keep track of transactions sent via Safe contracts. It also offers endpoints to send transactions to allow off-chain collecting of signatures or informing the owners about a pending transaction to be sent to the blockchain.
The Safe Transaction Service offers a REST API to track transactions sent via the Safe Smart Account. It also provides endpoints to send transactions, allow off-chain collecting of signatures, or informing the owners about a pending transaction to be sent to the blockchain.

We also offer the [API Kit](../sdk/api-kit), a TypeScript client for the Safe Transaction Service API in the Safe\{Core\} SDK.
Additionally, the Safe\{Core\} SDK provides the [API Kit](../sdk/api-kit), a TypeScript client for the Safe Transaction Service API.

<Cards>
<Card icon={<Guides />} title="Guides" href="./transaction-service-guides/transactions" />
Expand All @@ -15,4 +15,4 @@ We also offer the [API Kit](../sdk/api-kit), a TypeScript client for the Safe Tr

## Getting started

Are you new to our API and not sure where to get started? We recommend heading over to the guides on the [Safe Transaction Service API](../core-api/transaction-service-guides/transactions.mdx).
Are you new to our API and not sure where to get started? We recommend heading over to the [guides](../core-api/transaction-service-guides/transactions.mdx) on the Safe Transaction Service API.
Loading

0 comments on commit 9998bc9

Please sign in to comment.