Skip to content

chore(smart-wallet-sdk): add docs #352

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
76 changes: 76 additions & 0 deletions sdks/smart-wallet-sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,82 @@ or
yarn add @uniswap/smart-wallet-sdk
```

## Quick Start

This example demonstrates how to batch multiple calls through a smart wallet:

```typescript
import { ChainId } from '@uniswap/sdk-core'
import { SmartWallet, CallPlanner } from '@uniswap/smart-wallet-sdk'

// 1. Initialize a CallPlanner to batch multiple contract calls
const planner = new CallPlanner()

// 2. Add calls to the planner
// Example: Add a token approval call
planner.add(
'0x1234567890123456789012345678901234567890', // token contract address
0n, // no ETH value sent
'0x095ea7b3000000000000000000000000abcdef0123456789abcdef0123456789abcdef01000000000000000000000000000000000000000000000000000000000000ffff' // encoded approve function call
)

// Example: Add a swap call
planner.add(
'0xabcdef0123456789abcdef0123456789abcdef01', // router contract address
0n, // no ETH value sent
'0x414bf389000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a0' // truncated swap function call
)

// 3. Encode calls using SmartWallet
const methodParameters = SmartWallet.encodeCalls(planner.calls)

// 4. Create the execute call that will be sent to the smart wallet
const executeCall = SmartWallet.createExecute(
methodParameters,
ChainId.MAINNET
)

// 5. The executeCall can now be sent as a transaction
console.log(executeCall)
// {
// to: '0x0000000000000000000000000000000000000000', // smart wallet address
// data: '0x7a9a1628...', // encoded execute function call
// value: 0n // total ETH value to send
// }
```

### Alternative: Add Calls Directly

You can also create calls and pass them directly to the SmartWallet class:

```typescript
import { ChainId } from '@uniswap/sdk-core'
import { SmartWallet } from '@uniswap/smart-wallet-sdk'

// Create an array of calls
const calls = [
{
to: '0x1234567890123456789012345678901234567890',
data: '0x095ea7b3000000000000000000000000abcdef0123456789abcdef0123456789abcdef01000000000000000000000000000000000000000000000000000000000000ffff',
value: 0n
},
{
to: '0xabcdef0123456789abcdef0123456789abcdef01',
data: '0x414bf389000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000a0',
value: 0n
}
]

// Encode calls using SmartWallet
const methodParameters = SmartWallet.encodeCalls(calls)

// Create the execute call
const executeCall = SmartWallet.createExecute(
methodParameters,
ChainId.MAINNET
)
```

## Documentation

Coming soon...
Expand Down
Loading