Skip to content

Commit

Permalink
🐛 Fix: generate sidebar for consistent sidebar (#1488)
Browse files Browse the repository at this point in the history
## Description

_Concise description of proposed changes_

## Testing

Explain the quality checks that have been done on the code changes

## Additional Information

- [ ] I read the [contributing docs](../docs/contributing.md) (if this
is your first contribution)

Your ENS/address:



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a sidebar configuration for improved navigation in
documentation.
- Added new documentation files for enhanced clarity on using Tevm with
Solidity.
- New script for generating sidebar configuration based on markdown
files.

- **Documentation Updates**
- Enhanced several documents with new sections and examples to improve
user understanding of Tevm functionalities.
- Updated metadata for various documents to improve organization and
navigation.

- **Bug Fixes**
- Removed deprecated constants and plugins from the configuration to
streamline setup.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
roninjin10 authored Oct 21, 2024
1 parent e605859 commit af75280
Show file tree
Hide file tree
Showing 17 changed files with 443 additions and 275 deletions.
156 changes: 2 additions & 154 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
[![Tevm Bundler Downloads](https://img.shields.io/npm/dm/@tevm/base-bundler.svg)](https://www.npmjs.com/package/@tevm/base-bundler)
[![Minzipped Size](https://badgen.net/bundlephobia/minzip/tevm)](https://bundlephobia.com/package/tevm@latest)

Any token claiming to be tevm is a scam. be careful.

# tevm-monorepo

Tevm tools include an Ethereum devnet that can run in the Browser and Node.js along with a solidity bundler that allows you to import solidity directly into TypeScript files. All built on top of the viem API.
Expand All @@ -35,21 +33,6 @@ const balance = await client.readContract(
)
```

## Table of Contents
- [Overview](#overview)
- [Examples](#examples)
- [MemoryClient](#memoryclient)
- [MemoryClient Example](#memoryclient-example)
- [Tevm Bundler + LSP](#tevm-bundler--lsp)
- [Tevm Bundler](#tevm-bundler)
- [Tevm LSP](#tevm-lsp)
- [Tevm Contracts](#tevm-contracts)
- [Tevm Scripting](#tevm-scripting)
- [Join Telegram](#join-telegram)
- [Visit Docs](#visit-docs)
- [Contributing](#contributing)
- [License](#license)

## Overview

Tevm is modular, easy to pick up, and built on top of [viem](https://viem.sh).
Expand All @@ -60,150 +43,15 @@ Tevm consists of the following modular tools:
- Tevm Contracts
- Tevm Bundler

These tools are modular and can be used by themselves but they also compose very well together with each other and with viem/wagmi.

## Examples

- For a tutorial of all of Tevm's major features, check out the [getting started guide](https://tevm.sh/getting-started/getting-started/).
- For a minimal live example you can edit in the browser, check out the [live StackBlitz](https://stackblitz.com/~/github.com/evmts/quick-start?file=src/main.ts).
- Try out [svvy.sh](https://svvy.sh/) by [0xpolarzero](https://x.com/0xpolarzero) for an example of using Tevm and [whatsabi](https://github.com/shazow/whatsabi) to build a network forking and transaction simulating tool. Forked code from it is kept up to date with the latest release [here](https://github.com/evmts/tevm-monorepo/tree/main/examples/next).

[<img width="1494" alt="ethereum simulator preview" src="https://github.com/evmts/quick-start/assets/35039927/b7fca77e-9542-42ad-894a-3fe5eb838fed">](https://svvy.sh/)

## MemoryClient

[MemoryClient](https://tevm.sh/learn/clients/) is an [anvil-like Ethereum devnet](https://github.com/foundry-rs/foundry/tree/master/crates/anvil) specially crafted for TypeScript applications and tests.

&nbsp;Built on top of viem and supports all Viem APIs<br/>
&nbsp;Runs in the browser, Node.js, and Bun<br/>
&nbsp;Supports forking akin to [anvil --fork-url](https://github.com/foundry-rs/foundry/tree/master/crates/anvil)<br/>
&nbsp;Can generate EVM traces and access lists<br/>
&nbsp;HTTP handlers for [running as a server](https://tevm.sh/learn/clients/#using-tevm-over-http) in tests or backends<br/>
&nbsp;Full support for the Ethereum JSON-RPC API and anvil_ API<br/>

With MemoryClient, you can easily solve a lot of previously tough-to-solve problems:

- Executing contract logic locally
- Simulating the result of one or more transactions
- Submitting impersonated transactions before estimating gas for a future transaction. E.g., mock approving a token before estimating the cost of transferring it.
- Executing view methods that you wrote yourself and don't exist on the contract
- Running the EVM in the browser without the need for a backend RPC
- And more

### MemoryClient Example

```typescript
import { createMemoryClient, http } from 'tevm'
import { optimism } from 'tevm/common'

// To start the MemoryClient, simply call `createMemoryClient`
const client = createMemoryClient({
// MemoryClient supports anvil-like forking
fork: { transport: http('https://mainnet.optimism.io') },
common: optimism,
})

// MemoryClient supports the entire viem API
const blockNumber = await client.getBlockNumber()

// MemoryClient can arbitrarily modify accounts
client.tevmSetAccount({
address: `0x${'69'.repeat(20)}`,
nonce: 9,
balance: 420n,
deployedBytecode: '0x...',
// ...
})

const { data, errors, events, executionGasUsed, logs } = client.tevmContract({
createTransaction: true,
// MemoryClient can impersonate any account
from: `0x${'69'.repeat(20)}`,
abi: [...],
functionName: 'transferFrom',
args: [...],
})

const { blockHash } = await client.tevmMine()
```

## Tevm Bundler + LSP

### Tevm Bundler

The Tevm Bundler is the next-generation build-time tool version of tools like Typechain. The Tevm Bundler removes the need to copy-paste ABIs or set up complicated build pipelines. With the Bundler, you can directly import Solidity contracts into your TypeScript files. This brings a TRPC-like experience to Contract-TypeScript code.

Tevm also supports code-generation of TypeScript from Solidity contracts, similar to TypeChain.

The Tevm Bundler builds Contracts and Scripts that modularly work with Viem, Wagmi, and Tevm.

```typescript
// Import Solidity directly into TypeScript. The Tevm Bundler will compile the contracts to TevmContracts and TevmScripts
import { ERC20 } from '@openzeppelin/contracts/token/ERC20/ERC20.sol'
## [Join Telegram](https://t.me/+ANThR9bHDLAwMjUx)

console.log(ERC20.abi)
console.log(ERC20.humanReadableAbi)

// Use the contracts with Wagmi, Viem, or Tevm. In this example, Wagmi
const { data } = useReadContract(
ERC20.read.balanceOf(`0x${'01'.repeat(20)}`)
)
```
## Visit [Docs (under heavy construction)](https://tevm.sh/) for docs, guides, API, and more! 📄

![image](https://github.com/evmts/tevm-monorepo/assets/35039927/705cace8-b7bf-4877-9ea3-dee526daffd6)
![image](https://github.com/evmts/tevm-monorepo/assets/35039927/bbff1710-ab5a-41b4-9e88-ade2f04d1568)
![image](https://github.com/evmts/tevm-monorepo/assets/35039927/8e3ad2bf-0959-4aac-a30d-1bed29d10dfd)

### Tevm LSP

The Tevm LSP is a ts-plugin that allows your code editor to pick up types from your Solidity imports if using the Tevm Bundler.

- Enables end-to-end type safety with Solidity and TypeScript
- Shows contract NatSpec on hover in your TypeScript files
- Go-to-definition takes you directly to the contract definition

![image](https://github.com/evmts/tevm-monorepo/assets/35039927/dc196aa2-d446-4518-aceb-5529f81fbd89)

## Tevm Contracts

Tevm contracts are an extremely lightweight modular abstraction for interacting with viem, wagmi, and tevm. They are created automatically if using the Tevm Bundler via importing Solidity but can also be created manually.

They can also be used with ethers to create type-safe contracts.

```typescript
import { createContract } from 'tevm/contract'

const script = createContract({
name: 'MyScript',
humanReadableAbi: ['function exampleRead() returns (uint256)', ...],
bytecode: '0x123...',
deployedBytecode: '0x123...',
address: '0x123...'
})

// Use with Wagmi
useReadContract(script.read.exampleRead())

// Use with Viem/Tevm
client.readContract(script.read.exampleRead())

// Even use with ethers to create a type-safe contract
import { Contract } from '@tevm/ethers'
const contract = new Contract(script.address, script.abi, provider)
// This will be type-safe
const res = await contract.read()
```

## Tevm Scripting

Tevm scripting allows arbitrary Solidity execution similar to Forge scripts. Instead of cheat codes, Tevm allows you to very easily bring your own cheat codes via executing arbitrary JavaScript. See the [Tevm scripting guide](https://tevm.sh/learn/scripting/) for information on how to build scripts.

Because Tevm also allows scripts to execute arbitrary JavaScript, scripts can be extremely powerful. For example, one could [build a library for writing servers in Solidity](https://x.com/FUCORY/status/1794839755693453457).

## [Join Telegram](https://t.me/+ANThR9bHDLAwMjUx)

## Visit [Docs (under construction)](https://tevm.sh/) for docs, guides, API, and more! 📄

## Contributing 💻

Contributions are encouraged, but please open an issue before making any major changes to ensure your changes will be accepted.
Expand Down
123 changes: 4 additions & 119 deletions docs/astro.config.mjs
Original file line number Diff line number Diff line change
@@ -1,124 +1,9 @@
import starlight from '@astrojs/starlight'
import { defineConfig } from 'astro/config'
import starlightBlogPlugin from 'starlight-blog'
import starlightLinksValidatorPlugin from 'starlight-links-validator'
import starlightTypeDoc, { typeDocSidebarGroup } from 'starlight-typedoc'

// TODO fix this
const ENABLE_LINK_CHECKER = false
import { defineConfig } from 'astro/config';
import { starlightConfig } from './astro.starlight.config.mjs';

// https://astro.build/config
export default defineConfig({
integrations: [
starlight({
logo: {
light: './src/assets/tevm-logo-light.png',
dark: './src/assets/tevm-logo-dark.png',
},
lastUpdated: true,
customCss: ['./src/styles/custom.css'],
editLink: {
baseUrl: 'https://github.com/evmts/tevm-monorepo/edit/main/docs',
},
tableOfContents: true,
favicon: './src/assets/tevm-logo-dark.png',
plugins: [
starlightBlogPlugin(),
...(ENABLE_LINK_CHECKER
? [
starlightLinksValidatorPlugin({
errorOnRelativeLinks: true,
}),
]
: []),
starlightTypeDoc({
entryPoints: [
'../packages/actions',
'../packages/node',
'../packages/block',
'../packages/blockchain',
'../packages/client-types',
'../packages/common',
'../packages/contract',
'../packages/decorators',
'../packages/evm',
'../packages/errors',
'../extensions/ethers',
'../packages/evm',
'../packages/http-client',
'../packages/jsonrpc',
'../packages/logger',
'../packages/memory-client',
'../packages/precompiles/',
'../packages/predeploys',
'../packages/receipt-manager',
'../packages/rlp',
'../packages/server',
'../packages/state',
'../packages/sync-storage-persister',
'../test/test-utils',
'../packages/trie',
'../packages/tx',
'../packages/txpool',
'../packages/utils',
'../extensions/viem',
'../packages/vm',
'../bundler-packages/base-bundler',
'../bundler-packages/bun',
'../bundler-packages/bundler-cache',
'../bundler-packages/compiler',
'../bundler-packages/config',
'../bundler-packages/esbuild',
'../packages/address',
'../packages/effect',
'../bundler-packages/resolutions',
'../bundler-packages/rollup',
'../bundler-packages/rspack',
'../bundler-packages/runtime',
'../bundler-packages/solc',
'../bundler-packages/unplugin',
'../bundler-packages/ts-plugin',
'../bundler-packages/vite',
'../bundler-packages/webpack',
],
tsconfig: '../tevm/tsconfig.json',
output: 'reference',
sidebar: {
label: 'Reference (auto-generated)',
collapsed: true,
},
typeDoc: {
gitRevision: 'main',
entryPointStrategy: 'packages',
},
}),
],
title: 'Tevm Docs',
social: {
github: 'https://github.com/evmts/tevm-monorepo',
twitter: 'https://twitter.com/FUCORY',
telegram: 'https://t.me/+ANThR9bHDLAwMjUx',
},
sidebar: [
{
label: 'Getting Started',
items: [{ label: 'Getting Started Guide', link: '/getting-started/getting-started/' }],
},
{
label: 'Learn',
items: [
{ label: 'Clients', link: '/learn/clients/' },
{ label: 'Actions', link: '/learn/actions/' },
{ label: 'Low-level API', link: '/learn/low-level-api/' },
{ label: 'JSON RPC', link: '/learn/json-rpc/' },
{ label: 'Contracts', link: '/learn/contracts/' },
{ label: 'Bundler', link: '/learn/solidity-imports/' },
{ label: 'Advanced Scripting', link: '/learn/scripting/' },
{ label: 'Reference', link: '/learn/reference/' },
],
},
typeDocSidebarGroup,
],
}),
starlightConfig,
],
})
});
Loading

0 comments on commit af75280

Please sign in to comment.