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

feat: opstack (part one) #1469

Merged
merged 29 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
VITE_ANVIL_FORK_URL=
VITE_ANVIL_BLOCK_TIME=1
VITE_ANVIL_BLOCK_NUMBER=16280770
VITE_NETWORK_TRANSPORT_MODE=http
VITE_ANVIL_PORT=8545
VITE_BATCH_JSON_RPC=false
VITE_BATCH_MULTICALL=false
VITE_ANVIL_PORT=8545
VITE_NETWORK_TRANSPORT_MODE=http
VITE_RPC_URL_OPTIMISM=
53 changes: 52 additions & 1 deletion site/.vitepress/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ export const sidebar: DefaultTheme.Sidebar = {
},
{
text: 'OP Stack',
link: '/docs/chains/op-stack',
link: '/docs/op-stack/getting-started',
},
{
text: 'zkSync',
Expand Down Expand Up @@ -911,4 +911,55 @@ export const sidebar: DefaultTheme.Sidebar = {
],
},
],
'/docs/op-stack/': [
{ text: '← Go back', link: '/docs/getting-started' },
{
text: 'OP Stack',
items: [
{
text: 'Getting started',
link: '/docs/op-stack/getting-started',
},
{ text: 'Client', link: '/docs/op-stack/client' },
{ text: 'Chains', link: '/docs/op-stack/chains' },
],
},
{
text: 'Public Actions',
items: [
{
text: 'estimateContractL1Fee',
link: '/docs/op-stack/estimateContractL1Fee',
},
{
text: 'estimateContractL1Gas',
link: '/docs/op-stack/estimateContractL1Gas',
},
{
text: 'estimateContractTotalFee',
link: '/docs/op-stack/estimateContractTotalFee',
},
{
text: 'estimateContractTotalGas',
link: '/docs/op-stack/estimateContractTotalGas',
},
{
text: 'estimateL1Fee',
link: '/docs/op-stack/estimateL1Fee',
},
{
text: 'estimateL1Gas',
link: '/docs/op-stack/estimateL1Gas',
},
{
text: 'estimateTotalFee',
link: '/docs/op-stack/estimateTotalFee',
},
{
text: 'estimateTotalGas',
link: '/docs/op-stack/estimateTotalGas',
},
],
},
],
}
4 changes: 4 additions & 0 deletions site/.vitepress/theme/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ h3.vp-sponsor-tier {
.vp-doc a:hover {
text-decoration: underline;
}

.VPSidebarItem.level-0 {
padding-bottom: 12px !important;
}
86 changes: 86 additions & 0 deletions site/docs/chains/celo.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,88 @@
---
head:
- - meta
- property: og:title
content: Celo
- - meta
- name: description
content: Integrating with Celo in Viem
- - meta
- property: og:description
content: Integrating with Celo in Viem
---

# Celo

Viem provides first-class support for chains implemented on [Celo](https://celo.org/).

## Chains

The following Viem chains are implemented on Celo:

```ts
import {
celo, // [!code hl]
celoAlfajores, // [!code hl]
celoCannoli, // [!code hl]
} from 'viem/chains'
```

### Configuration

Viem exports Celo's chain [formatters](/docs/chains/formatters) & [serializers](/docs/chains/serializers) via `chainConfig`. This is useful if you need to define another chain which is implemented on Celo.

```ts
import { defineChain } from 'viem'
import { chainConfig } from 'viem/celo'

export const celoExample = defineChain({
...chainConfig,
name: 'Celo Example',
// ...
})
```

## Utilities

### `parseTransaction`

Parses a serialized RLP-encoded transaction. Supports signed & unsigned CIP-42, CIP-64, EIP-1559, EIP-2930 and Legacy Transactions.

Celo-flavored version of [Viem's `parseTransaction`](/docs/utilities/parseTransaction).

#### Parameters

- `serializedTransaction` (`Hex`): The serialized transaction.

```ts
import { parseTransaction } from 'viem/celo'

const transaction = parseTransaction('0x7cf84682a4ec80847735940084773594008094765de816845861e75a25fca122bb6898b8b1282a808094f39fd6e51aad88f6f4ce6ab8827279cfffb92266880de0b6b3a764000080c0')
```

### `serializeTransaction`

Serializes a transaction object. Supports CIP-42, CIP-64, EIP-1559, EIP-2930, and Legacy transactions.

Celo-flavored version of [Viem's `serializeTransaction`](/docs/utilities/serializeTransaction).

#### Parameters

- `transaction` (`TransactionSerializable`): The transaction object to serialize.
- `signature` (`Signature`): Optional signature to include.

```ts
import { serializeTransaction } from 'viem/celo'

const serialized = serializeTransaction({
chainId: 1,
gas: 21001n,
gatewayFee: parseGwei('3'),
gatewayFeeRecipient: '0x1234512345123451234512345123451234512345',
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
nonce: 69,
to: '0x1234512345123451234512345123451234512345',
value: parseEther('0.01'),
})
```
13 changes: 13 additions & 0 deletions site/docs/chains/fees.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
---
head:
- - meta
- property: og:title
content: Fees
- - meta
- name: description
content: Configure chain-based fee data in Viem
- - meta
- property: og:description
content: Configure chain-based fee data in Viem
---

# Fees

You can modify how fees are derived by using the `fees` property on the Chain.
Expand Down
13 changes: 13 additions & 0 deletions site/docs/chains/formatters.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
---
head:
- - meta
- property: og:title
content: Formatters
- - meta
- name: description
content: Configure chain-based formatters in Viem
- - meta
- property: og:description
content: Configure chain-based formatters in Viem
---

# Formatters

You can modify how Blocks & Transactions are formatted by using the `formatters` property on the Chain.
Expand Down
1 change: 0 additions & 1 deletion site/docs/chains/op-stack.md

This file was deleted.

13 changes: 13 additions & 0 deletions site/docs/chains/serializers.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
---
head:
- - meta
- property: og:title
content: Serializers
- - meta
- name: description
content: Configure chain-based serializers in Viem
- - meta
- property: og:description
content: Configure chain-based serializers in Viem
---

# Serializers

## Usage
Expand Down
74 changes: 73 additions & 1 deletion site/docs/chains/zksync.md
Original file line number Diff line number Diff line change
@@ -1 +1,73 @@
# zkSync
---
head:
- - meta
- property: og:title
content: zkSync
- - meta
- name: description
content: Integrating with zkSync in Viem
- - meta
- property: og:description
content: Integrating with zkSync in Viem
---

# zkSync

Viem provides first-class support for chains implemented on [zkSync](https://zksync.io/).

## Chains

The following Viem chains are implemented on zkSync:

```ts
import {
zkSync, // [!code hl]
zkSyncTestnet, // [!code hl]
} from 'viem/chains'
```

### Configuration

Viem exports zkSync's chain [formatters](/docs/chains/formatters) & [serializers](/docs/chains/serializers) via `chainConfig`. This is useful if you need to define another chain which is implemented on zkSync.

```ts
import { defineChain } from 'viem'
import { chainConfig } from 'viem/zkSync'

export const zkSyncExample = defineChain({
...chainConfig,
name: 'zkSync Example',
// ...
})
```

## Utilities

### `serializeTransaction`

Serializes a transaction object. Supports EIP-712, EIP-1559, EIP-2930, and Legacy transactions.

zkSync-flavored version of [Viem's `serializeTransaction`](/docs/utilities/serializeTransaction).

#### Parameters

- `transaction` (`TransactionSerializable`): The transaction object to serialize.
- `signature` (`Signature`): Optional signature to include.

```ts
import { serializeTransaction } from 'viem/celo'

const serialized = serializeTransaction({
chainId: 1,
gas: 21001n,
maxFeePerGas: parseGwei('20'),
maxPriorityFeePerGas: parseGwei('2'),
nonce: 69,
paymaster: '0x4B5DF730c2e6b28E17013A1485E5d9BC41Efe021',
paymasterInput:
'0x8c5a344500000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000',
to: '0x1234512345123451234512345123451234512345',
type: 'eip712',
value: parseEther('0.01'),
})
```
29 changes: 29 additions & 0 deletions site/docs/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,35 @@ import { // [!code ++]
} from 'viem' // [!code ++]
```

### Moved chain-specific exports in `viem/chains/utils`

Chain-specific exports in `viem/chains/utils` have been moved to `viem/utils/{celo|opStack|zkSync}`:

```diff
import {
- parseTransactionCelo,
+ parseTransaction
- serializeTransactionCelo,
+ serializeTransaction
...
-} from 'viem/chains/utils'
+} from 'viem/celo'

import {
...
-} from 'viem/chains/utils'
+} from 'viem/op-stack'

import {
- parseTransactionZkSync,
+ parseTransaction,
- serializeTransactionZkSync,
+ serializeTransaction,
...
-} from 'viem/chains/utils'
+} from 'viem/zkSync'
```

### Actions: `getBlockNumber`

The `maxAge` parameter has been removed in favor of `cacheTime`.
Expand Down
32 changes: 32 additions & 0 deletions site/docs/op-stack/chains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Chains

The following Viem chains are implemented on the OP Stack:

```ts
import {
base, // [!code hl]
baseGoerli, // [!code hl]
baseSepolia, // [!code hl]
optimism, // [!code hl]
optimismGoerli, // [!code hl]
optimismSepolia, // [!code hl]
zora, // [!code hl]
zoraSepolia, // [!code hl]
zoraTestnet, // [!code hl]
} from 'viem/chains'
Comment on lines +6 to +16
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could see this becoming unwieldy to keep up to date. I have an early project idea of making a simple node cli application that uses the superchain registry as source of truth and then can be composed with other tools to generate code and documentation based on all the supported chains. It could be used to generate the op stack specific chain objects for example too

If this sounds useful to you let me know so we can prioritize it

```

## Configuration

Viem exports OP Stack's chain [formatters](/docs/chains/formatters) & [serializers](/docs/chains/serializers) via `chainConfig`. This is useful if you need to define another chain which is implemented on the OP Stack.

```ts
import { defineChain } from 'viem'
import { chainConfig } from 'viem/op-stack'

export const opStackExample = defineChain({
...chainConfig,
name: 'OP Stack Example',
// ...
})
```
Loading
Loading