Skip to content

Commit

Permalink
WIP add draft pages
Browse files Browse the repository at this point in the history
  • Loading branch information
valle-xyz committed Jan 16, 2025
1 parent 15370a3 commit d9e41e1
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pages/advanced/_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"title": "Reference",
"href": "/reference-smart-account/overview"
},
"-- AI": {
"type": "separator",
"title": "AI"
},
"ai-overview": "Overview",
"ai-quickstart": "Quick Start",
"ai-advanced-setups": "Advanced Setups",
"-- Features": {
"type": "separator",
"title": "Features"
Expand Down
86 changes: 86 additions & 0 deletions pages/advanced/ai-advanced-setups.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Advanced Safe Smart Account Setups for AI Agents

Here you find advanced setups for Safe Smart Accounts for AI agents.

* Agent proposes transactions, human executes them
* Multi-agent setup
* Agent manages a certain amount of funds
* Agent is scoped to selected actions

## Agent proposes transactions, human executes them

In this setup, the AI agent proposes transactions, but one or more required human signers are needed to execute them.
This adds an additional layer of security, as the AI agent cannot execute transactions without human approval.

For this setup, we recommend a 2-out-of-3, 3-out-of-5, or 5-out-of-7 threshold.
The important considerations are:

* The AI agent should be one signer
* The threshold should be two more, so at least one human approval is required
* The amount of signers should be higher than the threshold to make sure the Safe Smart Account is functional when one key is lost

Here is an example setup:

```typescript
import { createSafeClient } from '@safe-global/sd

k-starter-kit'
const AGENT_ADDRESS = // ...
const AGENT_PRIVATE_KEY = // ...
const HUMAN_SIGNER_1_ADDRESS = // ...
const HUMAN_SIGNER_2_ADDRESS = // ...
const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: AGENT_PRIVATE_KEY,
safeOptions: {
owners: [AGENT_ADDRESS, HUMAN_SIGNER_1_ADDRESS, HUMAN_SIGNER_2_ADDRESS],
threshold: 2
}
})
```

Here, the AI agent creates the Safe Smart Account and adds two human signers for a 2-out-of-3 setup.

## Multi-agent setup

In this setup, the Safe Smart Account is managed by multiple agents.
When one agent proposes a transaction, it needs to be approved by at least one other agent.
We recommend to have human signers as well, so that the Safe Smart Account is functional even without the AI agents.

Here is an example with a 2-out-of-4 setup:

```typescript
import { createSafeClient } from '@safe-global/sdk-starter-kit'

const AGENT_1_ADDRESS = // ...
const AGENT_1_PRIVATE_KEY = // ...
const AGENT_2_ADDRESS = // ...
const HUMAN_SIGNER_1_ADDRESS = // ...
const HUMAN_SIGNER_2_ADDRESS = // ...
const RPC_URL = 'https://rpc.ankr.com/eth_sepolia'

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: AGENT_1_PRIVATE_KEY,
safeOptions: {
owners: [AGENT_1_ADDRESS, AGENT_2_ADDRESS, HUMAN_SIGNER_1_ADDRESS, HUMAN_SIGNER_2_ADDRESS],
threshold: 2
}
})
```

This setup is similar to the previous one.
The AI agents can make autonomous decisions, and the human signers can do so, too.

## Agent manages a certain amount of funds

This setup is used by DAO's or other organizations that want to utilize AI agents to manage their funds.




## Agent is scoped to selected actions

27 changes: 27 additions & 0 deletions pages/advanced/ai-overview.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## AI Agents Powered by Safe Smart Accounts

The intersection of AI and blockchain technology is evolving rapidly.
This section provides a fast-track guide to getting started with AI agents that leverage Safe Smart Accounts for blockchain interactions.

### Why Use Safe Smart Accounts for AI Agents?

Safe Smart Accounts offer a secure and modular solution for enabling AI agents to interact with the blockchain.
While other options include giving an AI agent a private key, using Multi-Party Computation (MPC), relying on custodial services with an API, or manually sending transactions from a user's wallet, Safe Smart Accounts offer distinct advantages.

### Key Benefits of Safe Smart Accounts for AI Agents:

1. **Enhanced Security**: Safe Smart Accounts offer robust security features, making them one of the most secure methods for blockchain interactions.
Signers retain control of private keys, and signers can be replaced if necessary. Additional security measures, such as spending limits, timelocks, and whitelists, can be easily added to safeguard transactions.

Check failure on line 14 in pages/advanced/ai-overview.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'timelocks'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'timelocks'?", "location": {"path": "pages/advanced/ai-overview.mdx", "range": {"start": {"line": 14, "column": 138}}}, "severity": "ERROR"}
*This is especially crucial since many AI agents can be influenced by specific prompts.*

2. **True Self-Custody**: With Safe Smart Accounts, there's no reliance on third-party intermediaries.
This reduces costs and eliminates single points of failure, aligning with blockchain's core principle of decentralization.

3. **Modular Design**: Safe Smart Accounts provide unmatched modularity. Native and third-party modules extend functionality, allowing you to customize accounts based on your project's needs.

4. **Flexibility**: Multiple signers can propose transactions within a Safe Smart Account.
This allows your AI agent to propose transactions while maintaining your control over the account, with the option to withdraw funds or intervene at any point.

5. **Multi-Signer Setup**: Some use cases involve multiple AI agents acting as signers on a single Smart Account.
These agents must reach consensus before a transaction is signed, adding an extra layer of security and decentralization.

84 changes: 84 additions & 0 deletions pages/advanced/ai-quickstart.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# AI Quick Start Guide

Get started with Safe AI integration in just a few steps.

This guide will help you set up a Safe Smart Account with the AI agent as the only signer.
This 1-out-of-1 signer setup is discouraged by Safe, as it is not secure.
However, many projects choose this setup for simplicity.

## Prerequisites

- tbd

Check failure on line 11 in pages/advanced/ai-quickstart.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'tbd'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'tbd'?", "location": {"path": "pages/advanced/ai-quickstart.mdx", "range": {"start": {"line": 11, "column": 3}}}, "severity": "ERROR"}

## Installation

First, add the Safe SDK to your project:

```bash
pnpm add @safe-global/sdk-starter-kit
```

## Creating a Safe Smart Account for your AI Agent

When your AI agent is ready to interact with the blockchain, you can create a Safe Smart Account for it.

```typescript
import { createSafeClient } from '@safe-global/sdk-starter-kit'

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

const safeClient = await createSafeClient({
provider: RPC_URL,
signer: SIGNER_PRIVATE_KEY,
safeOptions: {
owners: [SIGNER_ADDRESS],
threshold: 1
}
})
```

This creates a Safe Smart Account, but the actual smart contract will be deployed when you send the first transaction.

## Send transactions

```typescript
// Smart Account transactions are always batched transactions.
// This means that the AI agent can propose multiple transactions at once.
const transactions = [{
to: '0x...',
data: '0x',
value: '0'
}]

const txResult = await safeClient.send({ transactions })

const safeTxHash = txResult.transactions?.safeTxHash

```

## Example: Buy an ERC20 token

```typescript


```

## Example: Sell an ERC20 token

```typescript

```

## Example: Buy an NFT

```typescript

```

## Example: Buy a token on Virtuals

Check failure on line 80 in pages/advanced/ai-quickstart.mdx

View workflow job for this annotation

GitHub Actions / vale-docs

[vale] reported by reviewdog 🐶 [Vale.Spelling] Did you really mean 'Virtuals'? Raw Output: {"message": "[Vale.Spelling] Did you really mean 'Virtuals'?", "location": {"path": "pages/advanced/ai-quickstart.mdx", "range": {"start": {"line": 80, "column": 28}}}, "severity": "ERROR"}

```typescript

```

0 comments on commit d9e41e1

Please sign in to comment.