Skip to content

Commit

Permalink
Add a benchmark for factory contracts (#481)
Browse files Browse the repository at this point in the history
* uni v2 factory benchmarks

* compiling subgraph

* scripting benchmarks

* run benchmarks

* update readme for the benchmarks

* remove unused abis
  • Loading branch information
kyscott18 authored Dec 6, 2023
1 parent aac522d commit c049c4a
Show file tree
Hide file tree
Showing 42 changed files with 6,116 additions and 40 deletions.
3 changes: 2 additions & 1 deletion benchmarks/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "ponder"
"extends": "ponder",
"ignorePatterns": ["run-subgraph.sh"]
}
2 changes: 2 additions & 0 deletions benchmarks/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ data/
dist/
.ponder/
generated/
!apps/subgraph-reth/generated/
!apps/subgraph-univ2/generated/
.env.local
20 changes: 4 additions & 16 deletions benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,26 @@ This directory contains tooling to benchmark Ponder against the Graph Protocol's

## Methodology

The benchmarks are run by sequentially running each indexer. Indexers must be run against Anvil in order to effectively notify TheGraph when to stop running. All dbs are cleared before the run. TheGraph indexing cache is busted by programmatically changing the hander function before each run. Ponder doesn't cache indexing function results so no actions are necessary.
The benchmarks are run by sequentially running each indexer.An indexer run is considered finished when the endpoint starts responding as healthy. All dbs are cleared before the run. TheGraph indexing cache is busted by programmatically changing the hander function before each run. Ponder doesn't cache indexing function results so no actions are necessary.

## Run Benchmarks

### Ponder

Ponder should be runnable out of the box with [Bun](https://bun.sh) by first starting an Anvil node
Ponder should be runnable out of the box with [Bun](https://bun.sh) by running

```sh
anvil --fork-url $ANVIL_FORK_URL --fork-block-number 17501000
```

and then, in a separate terminal running,

```sh
bun src/ponder.ts
bun bench:ponder apps/ponder-reth/
```

Ponder runs against a local build of Ponder, ensure it is built with `pnpm build` at the top level.

### TheGraph

First, the required TypeScript helpers must be generated:

```sh
pnpm graph codegen subgraph/subgraph.yaml
```

Docker is required. TheGraph benchmarks can be run with

```sh
pnpm bench:subgraph
pnpm bench:subgraph apps/subgraph-reth/
```

It is important to note that the default `graph-node` binary cannot be run on Apple silicon. Instead, `graph-node` must be built from source, following [these instructions](https://github.com/graphprotocol/graph-node/tree/master/docker#running-graph-node-on-an-macbook-m1).
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default createConfig({
mainnet: {
chainId: 1,
transport: http(process.env.PONDER_RPC_URL_1),
maxRpcRequestConcurrency: 10,
maxRpcRequestConcurrency: 20,
},
},
contracts: {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { ponder } from "@/generated";

declare const ponder: import("@ponder/core").PonderApp<
typeof import("../ponder.config.js").default,
typeof import("../ponder.schema.js").default
>;

ponder.on("RocketTokenRETH:Transfer", async ({ event, context }) => {
const { Account, TransferEvent } = context.db;

Expand Down
193 changes: 193 additions & 0 deletions benchmarks/apps/ponder-univ2/abis/FactoryAbi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
export const FactoryAbi = [
{
inputs: [
{
internalType: "address",
name: "_feeToSetter",
type: "address",
},
],
payable: false,
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: "address",
name: "token0",
type: "address",
},
{
indexed: true,
internalType: "address",
name: "token1",
type: "address",
},
{
indexed: false,
internalType: "address",
name: "pair",
type: "address",
},
{
indexed: false,
internalType: "uint256",
name: "totalPairs",
type: "uint256",
},
],
name: "PairCreated",
type: "event",
},
{
constant: true,
inputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
name: "allPairs",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "allPairsLength",
outputs: [
{
internalType: "uint256",
name: "",
type: "uint256",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{
internalType: "address",
name: "tokenA",
type: "address",
},
{
internalType: "address",
name: "tokenB",
type: "address",
},
],
name: "createPair",
outputs: [
{
internalType: "address",
name: "pair",
type: "address",
},
],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "feeTo",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "feeToSetter",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [
{
internalType: "address",
name: "",
type: "address",
},
{
internalType: "address",
name: "",
type: "address",
},
],
name: "getPair",
outputs: [
{
internalType: "address",
name: "",
type: "address",
},
],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{
internalType: "address",
name: "_feeTo",
type: "address",
},
],
name: "setFeeTo",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{
internalType: "address",
name: "_feeToSetter",
type: "address",
},
],
name: "setFeeToSetter",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
] as const;
Loading

1 comment on commit c049c4a

@vercel
Copy link

@vercel vercel bot commented on c049c4a Dec 6, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.