Skip to content

Commit

Permalink
feat: EIP-7702 (#2570)
Browse files Browse the repository at this point in the history
* wip: checkpoint

* chore: format

* wip: checkpoint

* wip: checkpoint

* chore: format

* wip: checkpoint

* wip: checkpoint

* wip: format

* wip: checkpoint

* wip: checkpoint

* wip: format

* wip: tweaks

* wip: docs

* wip: checkpoint

* wip: format

* chore: tweaks

* wip: checkpoint

* wip: format

* wip: checkpoint

* wip: checkpoint

* wip: format

* wip: docs

* wip: checkpoint

* wip: format

* wip: up

* wip: tweak

* wip: checkpoint

* wip: tweaks

* chore: tweak

* wip: tweak contract

* format

* wip: transaction types

* wip: estimateGas

* wip: format

* wip: tests

* wip: docs

* wip: docs

* docs: wip

* wip: docs

* wip: docs

* chore: changeset

* types

* test

* test

* format
  • Loading branch information
jxom committed Aug 5, 2024
1 parent 8570315 commit fee80a9
Show file tree
Hide file tree
Showing 97 changed files with 5,063 additions and 315 deletions.
5 changes: 5 additions & 0 deletions .changeset/metal-points-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": minor
---

**Experimental:** Added EIP-7702 Extension. [See Docs](https://viem.sh/experimental/eip7702)
10 changes: 2 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"javascript.preferences.autoImportFileExcludePatterns": [
"**/node_modules/**",
"**/_types/**"
],
"typescript.preferences.autoImportFileExcludePatterns": [
"**/node_modules/**",
"**/_types/**"
],
"javascript.preferences.autoImportFileExcludePatterns": ["**/_types/**"],
"typescript.preferences.autoImportFileExcludePatterns": ["**/_types/**"],
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
Expand Down
23 changes: 23 additions & 0 deletions contracts/src/test/BatchCallInvoker.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

contract BatchCallInvoker {
struct Call {
bytes data;
address to;
uint256 value;
}

event CallEmitted(address indexed to, uint256 value, bytes data);

function execute(Call[] calldata calls) external payable {
for (uint256 i = 0; i < calls.length; i++) {
Call memory call = calls[i];

(bool success, ) = call.to.call{value: call.value}(call.data);
require(success, "call reverted");

emit CallEmitted(call.to, call.value, call.data);
}
}
}
10 changes: 10 additions & 0 deletions contracts/src/test/Event.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.13;

contract Event {
event MessageEmitted(address indexed to, uint256 value, bytes data);

function execute() external payable {
emit MessageEmitted(msg.sender, msg.value, msg.data);
}
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"ethers": "^6.0.2",
"glob": "^10.4.1",
"knip": "^5.17.4",
"prool": "^0.0.15",
"prool": "^0.0.16",
"publint": "^0.2.8",
"sherif": "^0.8.4",
"simple-git-hooks": "^2.8.1",
Expand Down Expand Up @@ -187,7 +187,7 @@
{
"name": "import { getEnsAvatar } from 'viem/ens'",
"path": "./src/_esm/ens/index.js",
"limit": "22.7 kB",
"limit": "23 kB",
"import": "{ getEnsAvatar }"
},
{
Expand Down
59 changes: 33 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions site/pages/account-abstraction/guides/sending-user-operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,18 @@ Next, we will need to set up a Bundler Client. A Bundler is required to submit U

```ts twoslash
import { createPublicClient, http } from 'viem'
import { createBundlerClient } from 'viem/account-abstraction' // [!code focus]
import { createBundlerClient } from 'viem/account-abstraction' // [!code ++] // [!code focus]
import { mainnet } from 'viem/chains'

const client = createPublicClient({
chain: mainnet,
transport: http(),
})

const bundlerClient = createBundlerClient({ // [!code focus]
client, // [!code focus]
transport: http('https://public.pimlico.io/v2/1/rpc'), // [!code focus]
}) // [!code focus]
const bundlerClient = createBundlerClient({ // [!code ++] // [!code focus]
client, // [!code ++] // [!code focus]
transport: http('https://public.pimlico.io/v2/1/rpc'), // [!code ++] // [!code focus]
}) // [!code ++] // [!code focus]
```

:::info
Expand All @@ -107,7 +107,7 @@ We will also need to set up an Owner for the Smart Account which will be used to
import { createPublicClient, http } from 'viem'
import { createBundlerClient } from 'viem/account-abstraction'
import { mainnet } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts' // [!code focus]
import { privateKeyToAccount } from 'viem/accounts' // [!code ++] // [!code focus]
const client = createPublicClient({
chain: mainnet,
Expand All @@ -119,7 +119,7 @@ const bundlerClient = createBundlerClient({
transport: http('https://public.pimlico.io/v2/1/rpc'),
})

const owner = privateKeyToAccount('0x...') // [!code focus]
const owner = privateKeyToAccount('0x...') // [!code ++] // [!code focus]
```

[See `privateKeyToAccount` Docs](/docs/accounts/local/privateKeyToAccount)
Expand All @@ -131,10 +131,10 @@ Next, we will instantiate a Smart Account. For this example, we will use [`toCoi
```ts twoslash
// @noErrors
import { createPublicClient, http } from 'viem'
import { // [!code focus]
createBundlerClient, // [!code focus]
toCoinbaseSmartAccount // [!code focus]
} from 'viem/account-abstraction' // [!code focus]
import { // [!code ++] // [!code focus]
createBundlerClient, // [!code ++] // [!code focus]
toCoinbaseSmartAccount // [!code ++] // [!code focus]
} from 'viem/account-abstraction' // [!code ++] // [!code focus]
import { mainnet } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'

Expand All @@ -150,10 +150,10 @@ const bundlerClient = createBundlerClient({

const owner = privateKeyToAccount('0x...')

const account = await toCoinbaseSmartAccount({ // [!code focus]
client, // [!code focus]
owners: [owner] // [!code focus]
}) // [!code focus]
const account = await toCoinbaseSmartAccount({ // [!code ++] // [!code focus]
client, // [!code ++] // [!code focus]
owners: [owner] // [!code ++] // [!code focus]
}) // [!code ++] // [!code focus]
```

:::tip
Expand Down Expand Up @@ -192,15 +192,15 @@ const account = await toCoinbaseSmartAccount({
owners: [owner]
})

const hash = await bundlerClient.sendUserOperation({ // [!code focus]
account, // [!code focus]
calls: [{ // [!code focus]
to: '0xcb98643b8786950F0461f3B0edf99D88F274574D', // [!code focus]
value: parseEther('0.001') // [!code focus]
}] // [!code focus]
}) // [!code focus]
const hash = await bundlerClient.sendUserOperation({ // [!code ++] // [!code focus]
account, // [!code ++] // [!code focus]
calls: [{ // [!code ++] // [!code focus]
to: '0xcb98643b8786950F0461f3B0edf99D88F274574D', // [!code ++] // [!code focus]
value: parseEther('0.001') // [!code ++] // [!code focus]
}] // [!code ++] // [!code focus]
}) // [!code ++] // [!code focus]

const receipt = await bundlerClient.waitForUserOperationReceipt({ hash }) // [!code focus]
const receipt = await bundlerClient.waitForUserOperationReceipt({ hash }) // [!code ++] // [!code focus]
```

:::tip
Expand Down
24 changes: 23 additions & 1 deletion site/pages/docs/accounts/local/signTransaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,29 @@ const signature = await account.signTransaction({
storageKeys: ['0x1'],
},
],
type: 'eip1559'
chainId: 1,
})
```

### authorizationList (optional)

- **Type:** `AuthorizationList`

Signed EIP-7702 Authorization list.

```ts twoslash
import { privateKeyToAccount } from 'viem/accounts'
const account = privateKeyToAccount('0x...')
// ---cut---
const authorization = await account.experimental_signAuthorization({
address: '0x...',
chainId: 1,
nonce: 1,
})

const signature = await account.signTransaction({
authorizationList: [authorization], // [!code focus]
chainId: 1,
})
```

Expand Down
Loading

0 comments on commit fee80a9

Please sign in to comment.