diff --git a/benchmarks/.eslintrc b/benchmarks/.eslintrc index 359e2bbfa..11160cf4e 100644 --- a/benchmarks/.eslintrc +++ b/benchmarks/.eslintrc @@ -1,3 +1,4 @@ { - "extends": "ponder" + "extends": "ponder", + "ignorePatterns": ["run-subgraph.sh"] } diff --git a/benchmarks/.gitignore b/benchmarks/.gitignore index 86c965837..d7d4a1f62 100644 --- a/benchmarks/.gitignore +++ b/benchmarks/.gitignore @@ -2,4 +2,6 @@ data/ dist/ .ponder/ generated/ +!apps/subgraph-reth/generated/ +!apps/subgraph-univ2/generated/ .env.local \ No newline at end of file diff --git a/benchmarks/README.md b/benchmarks/README.md index 0c727349f..891f4d487 100644 --- a/benchmarks/README.md +++ b/benchmarks/README.md @@ -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). diff --git a/benchmarks/ponder/abis/RocketTokenRETH.ts b/benchmarks/apps/ponder-reth/abis/RocketTokenRETH.ts similarity index 100% rename from benchmarks/ponder/abis/RocketTokenRETH.ts rename to benchmarks/apps/ponder-reth/abis/RocketTokenRETH.ts diff --git a/benchmarks/ponder/ponder.config.ts b/benchmarks/apps/ponder-reth/ponder.config.ts similarity index 93% rename from benchmarks/ponder/ponder.config.ts rename to benchmarks/apps/ponder-reth/ponder.config.ts index 15a4bcc0f..4f70abb52 100644 --- a/benchmarks/ponder/ponder.config.ts +++ b/benchmarks/apps/ponder-reth/ponder.config.ts @@ -8,7 +8,7 @@ export default createConfig({ mainnet: { chainId: 1, transport: http(process.env.PONDER_RPC_URL_1), - maxRpcRequestConcurrency: 10, + maxRpcRequestConcurrency: 20, }, }, contracts: { diff --git a/benchmarks/ponder/ponder.schema.ts b/benchmarks/apps/ponder-reth/ponder.schema.ts similarity index 100% rename from benchmarks/ponder/ponder.schema.ts rename to benchmarks/apps/ponder-reth/ponder.schema.ts diff --git a/benchmarks/ponder/src/index.ts b/benchmarks/apps/ponder-reth/src/index.ts similarity index 89% rename from benchmarks/ponder/src/index.ts rename to benchmarks/apps/ponder-reth/src/index.ts index 6910d05f7..6e5ede614 100644 --- a/benchmarks/ponder/src/index.ts +++ b/benchmarks/apps/ponder-reth/src/index.ts @@ -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; diff --git a/benchmarks/apps/ponder-univ2/abis/FactoryAbi.ts b/benchmarks/apps/ponder-univ2/abis/FactoryAbi.ts new file mode 100644 index 000000000..914329393 --- /dev/null +++ b/benchmarks/apps/ponder-univ2/abis/FactoryAbi.ts @@ -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; diff --git a/benchmarks/apps/ponder-univ2/abis/PairAbi.ts b/benchmarks/apps/ponder-univ2/abis/PairAbi.ts new file mode 100644 index 000000000..a68880a8f --- /dev/null +++ b/benchmarks/apps/ponder-univ2/abis/PairAbi.ts @@ -0,0 +1,713 @@ +export const PairAbi = [ + { + inputs: [], + payable: false, + stateMutability: "nonpayable", + type: "constructor", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Approval", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount0", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amount1", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "Burn", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount0", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amount1", + type: "uint256", + }, + ], + name: "Mint", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "sender", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "amount0In", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amount1In", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amount0Out", + type: "uint256", + }, + { + indexed: false, + internalType: "uint256", + name: "amount1Out", + type: "uint256", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "Swap", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint112", + name: "reserve0", + type: "uint112", + }, + { + indexed: false, + internalType: "uint112", + name: "reserve1", + type: "uint112", + }, + ], + name: "Sync", + type: "event", + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address", + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address", + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "Transfer", + type: "event", + }, + { + constant: true, + inputs: [], + name: "DOMAIN_SEPARATOR", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "MINIMUM_LIQUIDITY", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "PERMIT_TYPEHASH", + outputs: [ + { + internalType: "bytes32", + name: "", + type: "bytes32", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "burn", + outputs: [ + { + internalType: "uint256", + name: "amount0", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount1", + type: "uint256", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "decimals", + outputs: [ + { + internalType: "uint8", + name: "", + type: "uint8", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "factory", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "getReserves", + outputs: [ + { + internalType: "uint112", + name: "_reserve0", + type: "uint112", + }, + { + internalType: "uint112", + name: "_reserve1", + type: "uint112", + }, + { + internalType: "uint32", + name: "_blockTimestampLast", + type: "uint32", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "_token0", + type: "address", + }, + { + internalType: "address", + name: "_token1", + type: "address", + }, + ], + name: "initialize", + outputs: [], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "kLast", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "mint", + outputs: [ + { + internalType: "uint256", + name: "liquidity", + type: "uint256", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "name", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + name: "nonces", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "owner", + type: "address", + }, + { + internalType: "address", + name: "spender", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + { + internalType: "uint256", + name: "deadline", + type: "uint256", + }, + { + internalType: "uint8", + name: "v", + type: "uint8", + }, + { + internalType: "bytes32", + name: "r", + type: "bytes32", + }, + { + internalType: "bytes32", + name: "s", + type: "bytes32", + }, + ], + name: "permit", + outputs: [], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "price0CumulativeLast", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "price1CumulativeLast", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + ], + name: "skim", + outputs: [], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "uint256", + name: "amount0Out", + type: "uint256", + }, + { + internalType: "uint256", + name: "amount1Out", + type: "uint256", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "bytes", + name: "data", + type: "bytes", + }, + ], + name: "swap", + outputs: [], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "symbol", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [], + name: "sync", + outputs: [], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: true, + inputs: [], + name: "token0", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "token1", + outputs: [ + { + internalType: "address", + name: "", + type: "address", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: true, + inputs: [], + name: "totalSupply", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256", + }, + ], + payable: false, + stateMutability: "view", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "transfer", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, + { + constant: false, + inputs: [ + { + internalType: "address", + name: "from", + type: "address", + }, + { + internalType: "address", + name: "to", + type: "address", + }, + { + internalType: "uint256", + name: "value", + type: "uint256", + }, + ], + name: "transferFrom", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool", + }, + ], + payable: false, + stateMutability: "nonpayable", + type: "function", + }, +] as const; diff --git a/benchmarks/apps/ponder-univ2/ponder.config.ts b/benchmarks/apps/ponder-univ2/ponder.config.ts new file mode 100644 index 000000000..cfd845a9e --- /dev/null +++ b/benchmarks/apps/ponder-univ2/ponder.config.ts @@ -0,0 +1,33 @@ +import { createConfig } from "@ponder/core"; +import { getAbiItem, getAddress, http } from "viem"; + +import { FactoryAbi } from "./abis/FactoryAbi"; +import { PairAbi } from "./abis/PairAbi"; + +export default createConfig({ + networks: { + mainnet: { + chainId: 1, + transport: http(process.env.PONDER_RPC_URL_1), + maxRpcRequestConcurrency: 20, + }, + }, + contracts: { + Factory: { + network: "mainnet", + abi: FactoryAbi, + address: getAddress("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"), + startBlock: 18700000, + }, + Pair: { + network: "mainnet", + abi: PairAbi, + factory: { + address: getAddress("0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"), + event: getAbiItem({ abi: FactoryAbi, name: "PairCreated" }), + parameter: "pair", + }, + startBlock: 18700000, + }, + }, +}); diff --git a/benchmarks/apps/ponder-univ2/ponder.schema.ts b/benchmarks/apps/ponder-univ2/ponder.schema.ts new file mode 100644 index 000000000..09c1c5240 --- /dev/null +++ b/benchmarks/apps/ponder-univ2/ponder.schema.ts @@ -0,0 +1,66 @@ +import { createSchema } from "@ponder/core"; + +export default createSchema((p) => ({ + UniswapFactory: p.createTable({ + id: p.string(), + pairCount: p.int(), + txCount: p.int(), + }), + + Pair: p.createTable({ + id: p.string(), + + token0: p.string(), + token1: p.string(), + reserve0: p.bigint(), + reserve1: p.bigint(), + totalSupply: p.bigint(), + + txCount: p.int(), + + createdAtTimestamp: p.bigint(), + createdAtBlockNumber: p.bigint(), + + mints: p.many("Mint.pair"), + burns: p.many("Burn.pair"), + swaps: p.many("Swap.pair"), + }), + Mint: p.createTable({ + id: p.string(), + timestamp: p.bigint(), + pair: p.string().references("Pair.id"), + + sender: p.string(), + amount0: p.bigint(), + amount1: p.bigint(), + + logIndex: p.int(), + }), + Burn: p.createTable({ + id: p.string(), + timestamp: p.bigint(), + pair: p.string().references("Pair.id"), + + sender: p.string(), + amount0: p.bigint(), + amount1: p.bigint(), + to: p.string(), + + logIndex: p.int(), + }), + Swap: p.createTable({ + id: p.string(), + timestamp: p.bigint(), + pair: p.string().references("Pair.id"), + + sender: p.string(), + from: p.string(), + amount0In: p.bigint(), + amount1In: p.bigint(), + amount0Out: p.bigint(), + amount1Out: p.bigint(), + to: p.string(), + + logIndex: p.int(), + }), +})); diff --git a/benchmarks/apps/ponder-univ2/src/index.ts b/benchmarks/apps/ponder-univ2/src/index.ts new file mode 100644 index 000000000..b8ce43f00 --- /dev/null +++ b/benchmarks/apps/ponder-univ2/src/index.ts @@ -0,0 +1,136 @@ +import { getAddress } from "viem"; + +// 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("Factory:PairCreated", async ({ event, context }) => { + const { UniswapFactory, Pair } = context.db; + + await UniswapFactory.upsert({ + id: getAddress(context.contracts.Factory.address), + create: { + pairCount: 0, + txCount: 0, + }, + update: ({ current }) => ({ + pairCount: current.pairCount + 1, + txCount: current.pairCount + 1, + }), + }); + + await Pair.create({ + id: getAddress(event.args.pair), + data: { + token0: event.args.token0, + token1: event.args.token1, + totalSupply: 0n, + reserve0: 0n, + reserve1: 0n, + txCount: 0, + createdAtBlockNumber: event.block.number, + createdAtTimestamp: event.block.timestamp, + }, + }); +}); + +ponder.on("Pair:Sync", async ({ event, context }) => { + await context.db.Pair.update({ + id: getAddress(event.log.address), + data: { reserve0: event.args.reserve0, reserve1: event.args.reserve1 }, + }); +}); + +ponder.on("Pair:Mint", async ({ event, context }) => { + await context.db.UniswapFactory.update({ + id: getAddress(context.contracts.Factory.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Pair.update({ + id: getAddress(event.log.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Mint.create({ + id: event.log.id, + data: { + pair: getAddress(event.log.address), + timestamp: event.block.timestamp, + sender: event.args.sender, + amount0: event.args.amount0, + amount1: event.args.amount1, + logIndex: event.log.logIndex, + }, + }); +}); + +ponder.on("Pair:Burn", async ({ event, context }) => { + await context.db.UniswapFactory.update({ + id: getAddress(context.contracts.Factory.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Pair.update({ + id: getAddress(event.log.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Burn.create({ + id: event.log.id, + data: { + pair: getAddress(event.log.address), + timestamp: event.block.timestamp, + sender: event.args.sender, + to: event.args.sender, + amount0: event.args.amount0, + amount1: event.args.amount1, + logIndex: event.log.logIndex, + }, + }); +}); + +ponder.on("Pair:Swap", async ({ event, context }) => { + await context.db.UniswapFactory.update({ + id: getAddress(context.contracts.Factory.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Pair.update({ + id: getAddress(event.log.address), + data: ({ current }) => ({ + txCount: current.txCount + 1, + }), + }); + + await context.db.Swap.create({ + id: event.log.id, + data: { + pair: getAddress(event.log.address), + timestamp: event.block.timestamp, + sender: event.args.sender, + from: event.transaction.from, + to: event.args.sender, + amount0In: event.args.amount0In, + amount1In: event.args.amount1In, + amount0Out: event.args.amount0Out, + amount1Out: event.args.amount1Out, + logIndex: event.log.logIndex, + }, + }); +}); diff --git a/benchmarks/subgraph/.gitignore b/benchmarks/apps/subgraph-reth/.gitignore similarity index 100% rename from benchmarks/subgraph/.gitignore rename to benchmarks/apps/subgraph-reth/.gitignore diff --git a/benchmarks/subgraph/abis/RocketTokenRETH.json b/benchmarks/apps/subgraph-reth/abis/RocketTokenRETH.json similarity index 100% rename from benchmarks/subgraph/abis/RocketTokenRETH.json rename to benchmarks/apps/subgraph-reth/abis/RocketTokenRETH.json diff --git a/benchmarks/apps/subgraph-reth/generated/RocketTokenRETH/RocketTokenRETH.ts b/benchmarks/apps/subgraph-reth/generated/RocketTokenRETH/RocketTokenRETH.ts new file mode 100644 index 000000000..f5655b8be --- /dev/null +++ b/benchmarks/apps/subgraph-reth/generated/RocketTokenRETH/RocketTokenRETH.ts @@ -0,0 +1,867 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class Approval extends ethereum.Event { + get params(): Approval__Params { + return new Approval__Params(this); + } +} + +export class Approval__Params { + _event: Approval; + + constructor(event: Approval) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get spender(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class EtherDeposited extends ethereum.Event { + get params(): EtherDeposited__Params { + return new EtherDeposited__Params(this); + } +} + +export class EtherDeposited__Params { + _event: EtherDeposited; + + constructor(event: EtherDeposited) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get time(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class TokensBurned extends ethereum.Event { + get params(): TokensBurned__Params { + return new TokensBurned__Params(this); + } +} + +export class TokensBurned__Params { + _event: TokensBurned; + + constructor(event: TokensBurned) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get ethAmount(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get time(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } +} + +export class TokensMinted extends ethereum.Event { + get params(): TokensMinted__Params { + return new TokensMinted__Params(this); + } +} + +export class TokensMinted__Params { + _event: TokensMinted; + + constructor(event: TokensMinted) { + this._event = event; + } + + get to(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get ethAmount(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get time(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } +} + +export class Transfer extends ethereum.Event { + get params(): Transfer__Params { + return new Transfer__Params(this); + } +} + +export class Transfer__Params { + _event: Transfer; + + constructor(event: Transfer) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class RocketTokenRETH extends ethereum.SmartContract { + static bind(address: Address): RocketTokenRETH { + return new RocketTokenRETH("RocketTokenRETH", address); + } + + allowance(owner: Address, spender: Address): BigInt { + let result = super.call( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(owner), ethereum.Value.fromAddress(spender)] + ); + + return result[0].toBigInt(); + } + + try_allowance(owner: Address, spender: Address): ethereum.CallResult { + let result = super.tryCall( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(owner), ethereum.Value.fromAddress(spender)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + approve(spender: Address, amount: BigInt): boolean { + let result = super.call("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(amount) + ]); + + return result[0].toBoolean(); + } + + try_approve(spender: Address, amount: BigInt): ethereum.CallResult { + let result = super.tryCall("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(amount) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + balanceOf(account: Address): BigInt { + let result = super.call("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(account) + ]); + + return result[0].toBigInt(); + } + + try_balanceOf(account: Address): ethereum.CallResult { + let result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(account) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + decimals(): i32 { + let result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + let result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + decreaseAllowance(spender: Address, subtractedValue: BigInt): boolean { + let result = super.call( + "decreaseAllowance", + "decreaseAllowance(address,uint256):(bool)", + [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(subtractedValue) + ] + ); + + return result[0].toBoolean(); + } + + try_decreaseAllowance( + spender: Address, + subtractedValue: BigInt + ): ethereum.CallResult { + let result = super.tryCall( + "decreaseAllowance", + "decreaseAllowance(address,uint256):(bool)", + [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(subtractedValue) + ] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + getCollateralRate(): BigInt { + let result = super.call( + "getCollateralRate", + "getCollateralRate():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_getCollateralRate(): ethereum.CallResult { + let result = super.tryCall( + "getCollateralRate", + "getCollateralRate():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + getEthValue(_rethAmount: BigInt): BigInt { + let result = super.call("getEthValue", "getEthValue(uint256):(uint256)", [ + ethereum.Value.fromUnsignedBigInt(_rethAmount) + ]); + + return result[0].toBigInt(); + } + + try_getEthValue(_rethAmount: BigInt): ethereum.CallResult { + let result = super.tryCall( + "getEthValue", + "getEthValue(uint256):(uint256)", + [ethereum.Value.fromUnsignedBigInt(_rethAmount)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + getExchangeRate(): BigInt { + let result = super.call( + "getExchangeRate", + "getExchangeRate():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_getExchangeRate(): ethereum.CallResult { + let result = super.tryCall( + "getExchangeRate", + "getExchangeRate():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + getRethValue(_ethAmount: BigInt): BigInt { + let result = super.call("getRethValue", "getRethValue(uint256):(uint256)", [ + ethereum.Value.fromUnsignedBigInt(_ethAmount) + ]); + + return result[0].toBigInt(); + } + + try_getRethValue(_ethAmount: BigInt): ethereum.CallResult { + let result = super.tryCall( + "getRethValue", + "getRethValue(uint256):(uint256)", + [ethereum.Value.fromUnsignedBigInt(_ethAmount)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + getTotalCollateral(): BigInt { + let result = super.call( + "getTotalCollateral", + "getTotalCollateral():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_getTotalCollateral(): ethereum.CallResult { + let result = super.tryCall( + "getTotalCollateral", + "getTotalCollateral():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + increaseAllowance(spender: Address, addedValue: BigInt): boolean { + let result = super.call( + "increaseAllowance", + "increaseAllowance(address,uint256):(bool)", + [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(addedValue) + ] + ); + + return result[0].toBoolean(); + } + + try_increaseAllowance( + spender: Address, + addedValue: BigInt + ): ethereum.CallResult { + let result = super.tryCall( + "increaseAllowance", + "increaseAllowance(address,uint256):(bool)", + [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(addedValue) + ] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + name(): string { + let result = super.call("name", "name():(string)", []); + + return result[0].toString(); + } + + try_name(): ethereum.CallResult { + let result = super.tryCall("name", "name():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + symbol(): string { + let result = super.call("symbol", "symbol():(string)", []); + + return result[0].toString(); + } + + try_symbol(): ethereum.CallResult { + let result = super.tryCall("symbol", "symbol():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + totalSupply(): BigInt { + let result = super.call("totalSupply", "totalSupply():(uint256)", []); + + return result[0].toBigInt(); + } + + try_totalSupply(): ethereum.CallResult { + let result = super.tryCall("totalSupply", "totalSupply():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + transfer(recipient: Address, amount: BigInt): boolean { + let result = super.call("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount) + ]); + + return result[0].toBoolean(); + } + + try_transfer( + recipient: Address, + amount: BigInt + ): ethereum.CallResult { + let result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + transferFrom(sender: Address, recipient: Address, amount: BigInt): boolean { + let result = super.call( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(sender), + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount) + ] + ); + + return result[0].toBoolean(); + } + + try_transferFrom( + sender: Address, + recipient: Address, + amount: BigInt + ): ethereum.CallResult { + let result = super.tryCall( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(sender), + ethereum.Value.fromAddress(recipient), + ethereum.Value.fromUnsignedBigInt(amount) + ] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + version(): i32 { + let result = super.call("version", "version():(uint8)", []); + + return result[0].toI32(); + } + + try_version(): ethereum.CallResult { + let result = super.tryCall("version", "version():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } + + get _rocketStorageAddress(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ApproveCall extends ethereum.Call { + get inputs(): ApproveCall__Inputs { + return new ApproveCall__Inputs(this); + } + + get outputs(): ApproveCall__Outputs { + return new ApproveCall__Outputs(this); + } +} + +export class ApproveCall__Inputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get amount(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class ApproveCall__Outputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class BurnCall extends ethereum.Call { + get inputs(): BurnCall__Inputs { + return new BurnCall__Inputs(this); + } + + get outputs(): BurnCall__Outputs { + return new BurnCall__Outputs(this); + } +} + +export class BurnCall__Inputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get _rethAmount(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } +} + +export class BurnCall__Outputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } +} + +export class DecreaseAllowanceCall extends ethereum.Call { + get inputs(): DecreaseAllowanceCall__Inputs { + return new DecreaseAllowanceCall__Inputs(this); + } + + get outputs(): DecreaseAllowanceCall__Outputs { + return new DecreaseAllowanceCall__Outputs(this); + } +} + +export class DecreaseAllowanceCall__Inputs { + _call: DecreaseAllowanceCall; + + constructor(call: DecreaseAllowanceCall) { + this._call = call; + } + + get spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get subtractedValue(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class DecreaseAllowanceCall__Outputs { + _call: DecreaseAllowanceCall; + + constructor(call: DecreaseAllowanceCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class DepositExcessCall extends ethereum.Call { + get inputs(): DepositExcessCall__Inputs { + return new DepositExcessCall__Inputs(this); + } + + get outputs(): DepositExcessCall__Outputs { + return new DepositExcessCall__Outputs(this); + } +} + +export class DepositExcessCall__Inputs { + _call: DepositExcessCall; + + constructor(call: DepositExcessCall) { + this._call = call; + } +} + +export class DepositExcessCall__Outputs { + _call: DepositExcessCall; + + constructor(call: DepositExcessCall) { + this._call = call; + } +} + +export class DepositExcessCollateralCall extends ethereum.Call { + get inputs(): DepositExcessCollateralCall__Inputs { + return new DepositExcessCollateralCall__Inputs(this); + } + + get outputs(): DepositExcessCollateralCall__Outputs { + return new DepositExcessCollateralCall__Outputs(this); + } +} + +export class DepositExcessCollateralCall__Inputs { + _call: DepositExcessCollateralCall; + + constructor(call: DepositExcessCollateralCall) { + this._call = call; + } +} + +export class DepositExcessCollateralCall__Outputs { + _call: DepositExcessCollateralCall; + + constructor(call: DepositExcessCollateralCall) { + this._call = call; + } +} + +export class IncreaseAllowanceCall extends ethereum.Call { + get inputs(): IncreaseAllowanceCall__Inputs { + return new IncreaseAllowanceCall__Inputs(this); + } + + get outputs(): IncreaseAllowanceCall__Outputs { + return new IncreaseAllowanceCall__Outputs(this); + } +} + +export class IncreaseAllowanceCall__Inputs { + _call: IncreaseAllowanceCall; + + constructor(call: IncreaseAllowanceCall) { + this._call = call; + } + + get spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get addedValue(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class IncreaseAllowanceCall__Outputs { + _call: IncreaseAllowanceCall; + + constructor(call: IncreaseAllowanceCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class MintCall extends ethereum.Call { + get inputs(): MintCall__Inputs { + return new MintCall__Inputs(this); + } + + get outputs(): MintCall__Outputs { + return new MintCall__Outputs(this); + } +} + +export class MintCall__Inputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get _ethAmount(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get _to(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class MintCall__Outputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } +} + +export class TransferCall extends ethereum.Call { + get inputs(): TransferCall__Inputs { + return new TransferCall__Inputs(this); + } + + get outputs(): TransferCall__Outputs { + return new TransferCall__Outputs(this); + } +} + +export class TransferCall__Inputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get recipient(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get amount(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class TransferCall__Outputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferFromCall extends ethereum.Call { + get inputs(): TransferFromCall__Inputs { + return new TransferFromCall__Inputs(this); + } + + get outputs(): TransferFromCall__Outputs { + return new TransferFromCall__Outputs(this); + } +} + +export class TransferFromCall__Inputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get sender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get recipient(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get amount(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class TransferFromCall__Outputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} diff --git a/benchmarks/subgraph/generated/schema.ts b/benchmarks/apps/subgraph-reth/generated/schema.ts similarity index 100% rename from benchmarks/subgraph/generated/schema.ts rename to benchmarks/apps/subgraph-reth/generated/schema.ts diff --git a/benchmarks/subgraph/schema.graphql b/benchmarks/apps/subgraph-reth/schema.graphql similarity index 100% rename from benchmarks/subgraph/schema.graphql rename to benchmarks/apps/subgraph-reth/schema.graphql diff --git a/benchmarks/subgraph/src/mapping.ts b/benchmarks/apps/subgraph-reth/src/mapping.ts similarity index 96% rename from benchmarks/subgraph/src/mapping.ts rename to benchmarks/apps/subgraph-reth/src/mapping.ts index f3d2ff679..33d986a07 100644 --- a/benchmarks/subgraph/src/mapping.ts +++ b/benchmarks/apps/subgraph-reth/src/mapping.ts @@ -4,7 +4,7 @@ import { BigInt } from "@graphprotocol/graph-ts"; import { Approval as TApprovalEvent, Transfer as TTransferEvent, -} from "../../generated/RocketTokenRETH/RocketTokenRETH"; +} from "../generated/RocketTokenRETH/RocketTokenRETH"; import { Account, Approval, @@ -12,7 +12,7 @@ import { TransferEvent, } from "../generated/schema"; -const delim = "dif:+"; +const delim = "dif:-"; export function handleTransfer(event: TTransferEvent): void { // Create an Account for the sender, or update the balance if it already exists. diff --git a/benchmarks/subgraph/subgraph.yaml b/benchmarks/apps/subgraph-reth/subgraph.yaml similarity index 100% rename from benchmarks/subgraph/subgraph.yaml rename to benchmarks/apps/subgraph-reth/subgraph.yaml diff --git a/benchmarks/subgraph/tsconfig.json b/benchmarks/apps/subgraph-reth/tsconfig.json similarity index 100% rename from benchmarks/subgraph/tsconfig.json rename to benchmarks/apps/subgraph-reth/tsconfig.json diff --git a/benchmarks/apps/subgraph-univ2/.gitignore b/benchmarks/apps/subgraph-univ2/.gitignore new file mode 100644 index 000000000..c795b054e --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/.gitignore @@ -0,0 +1 @@ +build \ No newline at end of file diff --git a/benchmarks/apps/subgraph-univ2/abis/factory.json b/benchmarks/apps/subgraph-univ2/abis/factory.json new file mode 100644 index 000000000..a2f132767 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/abis/factory.json @@ -0,0 +1,193 @@ +[ + { + "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": "", + "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" + } +] diff --git a/benchmarks/apps/subgraph-univ2/abis/pair.json b/benchmarks/apps/subgraph-univ2/abis/pair.json new file mode 100644 index 000000000..53582c1ed --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/abis/pair.json @@ -0,0 +1,713 @@ +[ + { + "inputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Burn", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "name": "Mint", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1In", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "Swap", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint112", + "name": "reserve0", + "type": "uint112" + }, + { + "indexed": false, + "internalType": "uint112", + "name": "reserve1", + "type": "uint112" + } + ], + "name": "Sync", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "constant": true, + "inputs": [], + "name": "DOMAIN_SEPARATOR", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "MINIMUM_LIQUIDITY", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "PERMIT_TYPEHASH", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + }, + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "burn", + "outputs": [ + { + "internalType": "uint256", + "name": "amount0", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "factory", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "getReserves", + "outputs": [ + { + "internalType": "uint112", + "name": "_reserve0", + "type": "uint112" + }, + { + "internalType": "uint112", + "name": "_reserve1", + "type": "uint112" + }, + { + "internalType": "uint32", + "name": "_blockTimestampLast", + "type": "uint32" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "_token0", + "type": "address" + }, + { + "internalType": "address", + "name": "_token1", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "kLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "mint", + "outputs": [ + { + "internalType": "uint256", + "name": "liquidity", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "name": "nonces", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "deadline", + "type": "uint256" + }, + { + "internalType": "uint8", + "name": "v", + "type": "uint8" + }, + { + "internalType": "bytes32", + "name": "r", + "type": "bytes32" + }, + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "permit", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price0CumulativeLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "price1CumulativeLast", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + } + ], + "name": "skim", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "uint256", + "name": "amount0Out", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amount1Out", + "type": "uint256" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "swap", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [], + "name": "sync", + "outputs": [], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token0", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "token1", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": true, + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "payable": false, + "stateMutability": "view", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + }, + { + "constant": false, + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "payable": false, + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20.ts b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20.ts new file mode 100644 index 000000000..b57845f12 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20.ts @@ -0,0 +1,395 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class Approval extends ethereum.Event { + get params(): Approval__Params { + return new Approval__Params(this); + } +} + +export class Approval__Params { + _event: Approval; + + constructor(event: Approval) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get spender(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Transfer extends ethereum.Event { + get params(): Transfer__Params { + return new Transfer__Params(this); + } +} + +export class Transfer__Params { + _event: Transfer; + + constructor(event: Transfer) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class ERC20 extends ethereum.SmartContract { + static bind(address: Address): ERC20 { + return new ERC20("ERC20", address); + } + + name(): string { + let result = super.call("name", "name():(string)", []); + + return result[0].toString(); + } + + try_name(): ethereum.CallResult { + let result = super.tryCall("name", "name():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + approve(_spender: Address, _value: BigInt): boolean { + let result = super.call("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_spender), + ethereum.Value.fromUnsignedBigInt(_value) + ]); + + return result[0].toBoolean(); + } + + try_approve(_spender: Address, _value: BigInt): ethereum.CallResult { + let result = super.tryCall("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_spender), + ethereum.Value.fromUnsignedBigInt(_value) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + totalSupply(): BigInt { + let result = super.call("totalSupply", "totalSupply():(uint256)", []); + + return result[0].toBigInt(); + } + + try_totalSupply(): ethereum.CallResult { + let result = super.tryCall("totalSupply", "totalSupply():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + transferFrom(_from: Address, _to: Address, _value: BigInt): boolean { + let result = super.call( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(_from), + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value) + ] + ); + + return result[0].toBoolean(); + } + + try_transferFrom( + _from: Address, + _to: Address, + _value: BigInt + ): ethereum.CallResult { + let result = super.tryCall( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(_from), + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value) + ] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + decimals(): i32 { + let result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + let result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + balanceOf(_owner: Address): BigInt { + let result = super.call("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(_owner) + ]); + + return result[0].toBigInt(); + } + + try_balanceOf(_owner: Address): ethereum.CallResult { + let result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(_owner) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + symbol(): string { + let result = super.call("symbol", "symbol():(string)", []); + + return result[0].toString(); + } + + try_symbol(): ethereum.CallResult { + let result = super.tryCall("symbol", "symbol():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + transfer(_to: Address, _value: BigInt): boolean { + let result = super.call("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value) + ]); + + return result[0].toBoolean(); + } + + try_transfer(_to: Address, _value: BigInt): ethereum.CallResult { + let result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(_to), + ethereum.Value.fromUnsignedBigInt(_value) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + allowance(_owner: Address, _spender: Address): BigInt { + let result = super.call( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(_owner), ethereum.Value.fromAddress(_spender)] + ); + + return result[0].toBigInt(); + } + + try_allowance( + _owner: Address, + _spender: Address + ): ethereum.CallResult { + let result = super.tryCall( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(_owner), ethereum.Value.fromAddress(_spender)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } +} + +export class ApproveCall extends ethereum.Call { + get inputs(): ApproveCall__Inputs { + return new ApproveCall__Inputs(this); + } + + get outputs(): ApproveCall__Outputs { + return new ApproveCall__Outputs(this); + } +} + +export class ApproveCall__Inputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get _spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class ApproveCall__Outputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferFromCall extends ethereum.Call { + get inputs(): TransferFromCall__Inputs { + return new TransferFromCall__Inputs(this); + } + + get outputs(): TransferFromCall__Outputs { + return new TransferFromCall__Outputs(this); + } +} + +export class TransferFromCall__Inputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get _from(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _to(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class TransferFromCall__Outputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferCall extends ethereum.Call { + get inputs(): TransferCall__Inputs { + return new TransferCall__Inputs(this); + } + + get outputs(): TransferCall__Outputs { + return new TransferCall__Outputs(this); + } +} + +export class TransferCall__Inputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get _to(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class TransferCall__Outputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class DefaultCall extends ethereum.Call { + get inputs(): DefaultCall__Inputs { + return new DefaultCall__Inputs(this); + } + + get outputs(): DefaultCall__Outputs { + return new DefaultCall__Outputs(this); + } +} + +export class DefaultCall__Inputs { + _call: DefaultCall; + + constructor(call: DefaultCall) { + this._call = call; + } +} + +export class DefaultCall__Outputs { + _call: DefaultCall; + + constructor(call: DefaultCall) { + this._call = call; + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20NameBytes.ts b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20NameBytes.ts new file mode 100644 index 000000000..8111bb611 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20NameBytes.ts @@ -0,0 +1,32 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class ERC20NameBytes extends ethereum.SmartContract { + static bind(address: Address): ERC20NameBytes { + return new ERC20NameBytes("ERC20NameBytes", address); + } + + name(): Bytes { + let result = super.call("name", "name():(bytes32)", []); + + return result[0].toBytes(); + } + + try_name(): ethereum.CallResult { + let result = super.tryCall("name", "name():(bytes32)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20SymbolBytes.ts b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20SymbolBytes.ts new file mode 100644 index 000000000..3c8db334c --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/Factory/ERC20SymbolBytes.ts @@ -0,0 +1,32 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class ERC20SymbolBytes extends ethereum.SmartContract { + static bind(address: Address): ERC20SymbolBytes { + return new ERC20SymbolBytes("ERC20SymbolBytes", address); + } + + symbol(): Bytes { + let result = super.call("symbol", "symbol():(bytes32)", []); + + return result[0].toBytes(); + } + + try_symbol(): ethereum.CallResult { + let result = super.tryCall("symbol", "symbol():(bytes32)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/Factory/Factory.ts b/benchmarks/apps/subgraph-univ2/generated/Factory/Factory.ts new file mode 100644 index 000000000..2229676f6 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/Factory/Factory.ts @@ -0,0 +1,291 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class PairCreated extends ethereum.Event { + get params(): PairCreated__Params { + return new PairCreated__Params(this); + } +} + +export class PairCreated__Params { + _event: PairCreated; + + constructor(event: PairCreated) { + this._event = event; + } + + get token0(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get token1(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get pair(): Address { + return this._event.parameters[2].value.toAddress(); + } + + get param3(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } +} + +export class Factory extends ethereum.SmartContract { + static bind(address: Address): Factory { + return new Factory("Factory", address); + } + + allPairs(param0: BigInt): Address { + let result = super.call("allPairs", "allPairs(uint256):(address)", [ + ethereum.Value.fromUnsignedBigInt(param0) + ]); + + return result[0].toAddress(); + } + + try_allPairs(param0: BigInt): ethereum.CallResult
{ + let result = super.tryCall("allPairs", "allPairs(uint256):(address)", [ + ethereum.Value.fromUnsignedBigInt(param0) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + allPairsLength(): BigInt { + let result = super.call("allPairsLength", "allPairsLength():(uint256)", []); + + return result[0].toBigInt(); + } + + try_allPairsLength(): ethereum.CallResult { + let result = super.tryCall( + "allPairsLength", + "allPairsLength():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + createPair(tokenA: Address, tokenB: Address): Address { + let result = super.call( + "createPair", + "createPair(address,address):(address)", + [ethereum.Value.fromAddress(tokenA), ethereum.Value.fromAddress(tokenB)] + ); + + return result[0].toAddress(); + } + + try_createPair( + tokenA: Address, + tokenB: Address + ): ethereum.CallResult
{ + let result = super.tryCall( + "createPair", + "createPair(address,address):(address)", + [ethereum.Value.fromAddress(tokenA), ethereum.Value.fromAddress(tokenB)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + feeTo(): Address { + let result = super.call("feeTo", "feeTo():(address)", []); + + return result[0].toAddress(); + } + + try_feeTo(): ethereum.CallResult
{ + let result = super.tryCall("feeTo", "feeTo():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + feeToSetter(): Address { + let result = super.call("feeToSetter", "feeToSetter():(address)", []); + + return result[0].toAddress(); + } + + try_feeToSetter(): ethereum.CallResult
{ + let result = super.tryCall("feeToSetter", "feeToSetter():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + getPair(param0: Address, param1: Address): Address { + let result = super.call("getPair", "getPair(address,address):(address)", [ + ethereum.Value.fromAddress(param0), + ethereum.Value.fromAddress(param1) + ]); + + return result[0].toAddress(); + } + + try_getPair(param0: Address, param1: Address): ethereum.CallResult
{ + let result = super.tryCall( + "getPair", + "getPair(address,address):(address)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } + + get _feeToSetter(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class CreatePairCall extends ethereum.Call { + get inputs(): CreatePairCall__Inputs { + return new CreatePairCall__Inputs(this); + } + + get outputs(): CreatePairCall__Outputs { + return new CreatePairCall__Outputs(this); + } +} + +export class CreatePairCall__Inputs { + _call: CreatePairCall; + + constructor(call: CreatePairCall) { + this._call = call; + } + + get tokenA(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get tokenB(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class CreatePairCall__Outputs { + _call: CreatePairCall; + + constructor(call: CreatePairCall) { + this._call = call; + } + + get pair(): Address { + return this._call.outputValues[0].value.toAddress(); + } +} + +export class SetFeeToCall extends ethereum.Call { + get inputs(): SetFeeToCall__Inputs { + return new SetFeeToCall__Inputs(this); + } + + get outputs(): SetFeeToCall__Outputs { + return new SetFeeToCall__Outputs(this); + } +} + +export class SetFeeToCall__Inputs { + _call: SetFeeToCall; + + constructor(call: SetFeeToCall) { + this._call = call; + } + + get _feeTo(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetFeeToCall__Outputs { + _call: SetFeeToCall; + + constructor(call: SetFeeToCall) { + this._call = call; + } +} + +export class SetFeeToSetterCall extends ethereum.Call { + get inputs(): SetFeeToSetterCall__Inputs { + return new SetFeeToSetterCall__Inputs(this); + } + + get outputs(): SetFeeToSetterCall__Outputs { + return new SetFeeToSetterCall__Outputs(this); + } +} + +export class SetFeeToSetterCall__Inputs { + _call: SetFeeToSetterCall; + + constructor(call: SetFeeToSetterCall) { + this._call = call; + } + + get _feeToSetter(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetFeeToSetterCall__Outputs { + _call: SetFeeToSetterCall; + + constructor(call: SetFeeToSetterCall) { + this._call = call; + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/schema.ts b/benchmarks/apps/subgraph-univ2/generated/schema.ts new file mode 100644 index 000000000..3b048026e --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/schema.ts @@ -0,0 +1,709 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + TypedMap, + Entity, + Value, + ValueKind, + store, + Bytes, + BigInt, + BigDecimal +} from "@graphprotocol/graph-ts"; + +export class UniswapFactory extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save UniswapFactory entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type UniswapFactory must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("UniswapFactory", id.toString(), this); + } + } + + static loadInBlock(id: string): UniswapFactory | null { + return changetype( + store.get_in_block("UniswapFactory", id) + ); + } + + static load(id: string): UniswapFactory | null { + return changetype(store.get("UniswapFactory", id)); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get pairCount(): i32 { + let value = this.get("pairCount"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set pairCount(value: i32) { + this.set("pairCount", Value.fromI32(value)); + } + + get txCount(): i32 { + let value = this.get("txCount"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set txCount(value: i32) { + this.set("txCount", Value.fromI32(value)); + } +} + +export class Pair extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Pair entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type Pair must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("Pair", id.toString(), this); + } + } + + static loadInBlock(id: string): Pair | null { + return changetype(store.get_in_block("Pair", id)); + } + + static load(id: string): Pair | null { + return changetype(store.get("Pair", id)); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get token0(): Bytes { + let value = this.get("token0"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set token0(value: Bytes) { + this.set("token0", Value.fromBytes(value)); + } + + get token1(): Bytes { + let value = this.get("token1"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set token1(value: Bytes) { + this.set("token1", Value.fromBytes(value)); + } + + get reserve0(): BigInt { + let value = this.get("reserve0"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set reserve0(value: BigInt) { + this.set("reserve0", Value.fromBigInt(value)); + } + + get reserve1(): BigInt { + let value = this.get("reserve1"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set reserve1(value: BigInt) { + this.set("reserve1", Value.fromBigInt(value)); + } + + get totalSupply(): BigInt { + let value = this.get("totalSupply"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set totalSupply(value: BigInt) { + this.set("totalSupply", Value.fromBigInt(value)); + } + + get txCount(): i32 { + let value = this.get("txCount"); + if (!value || value.kind == ValueKind.NULL) { + return 0; + } else { + return value.toI32(); + } + } + + set txCount(value: i32) { + this.set("txCount", Value.fromI32(value)); + } + + get createdAtTimestamp(): BigInt { + let value = this.get("createdAtTimestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set createdAtTimestamp(value: BigInt) { + this.set("createdAtTimestamp", Value.fromBigInt(value)); + } + + get createdAtBlockNumber(): BigInt { + let value = this.get("createdAtBlockNumber"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set createdAtBlockNumber(value: BigInt) { + this.set("createdAtBlockNumber", Value.fromBigInt(value)); + } + + get mints(): MintLoader { + return new MintLoader("Pair", this.get("id")!.toString(), "mints"); + } + + get burns(): BurnLoader { + return new BurnLoader("Pair", this.get("id")!.toString(), "burns"); + } + + get swaps(): SwapLoader { + return new SwapLoader("Pair", this.get("id")!.toString(), "swaps"); + } +} + +export class Mint extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Mint entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type Mint must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("Mint", id.toString(), this); + } + } + + static loadInBlock(id: string): Mint | null { + return changetype(store.get_in_block("Mint", id)); + } + + static load(id: string): Mint | null { + return changetype(store.get("Mint", id)); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get timestamp(): BigInt { + let value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get pair(): string { + let value = this.get("pair"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set pair(value: string) { + this.set("pair", Value.fromString(value)); + } + + get sender(): Bytes { + let value = this.get("sender"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set sender(value: Bytes) { + this.set("sender", Value.fromBytes(value)); + } + + get amount0(): BigInt { + let value = this.get("amount0"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount0(value: BigInt) { + this.set("amount0", Value.fromBigInt(value)); + } + + get amount1(): BigInt { + let value = this.get("amount1"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount1(value: BigInt) { + this.set("amount1", Value.fromBigInt(value)); + } + + get logIndex(): BigInt { + let value = this.get("logIndex"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set logIndex(value: BigInt) { + this.set("logIndex", Value.fromBigInt(value)); + } +} + +export class Burn extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Burn entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type Burn must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("Burn", id.toString(), this); + } + } + + static loadInBlock(id: string): Burn | null { + return changetype(store.get_in_block("Burn", id)); + } + + static load(id: string): Burn | null { + return changetype(store.get("Burn", id)); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get timestamp(): BigInt { + let value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get pair(): string { + let value = this.get("pair"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set pair(value: string) { + this.set("pair", Value.fromString(value)); + } + + get sender(): Bytes { + let value = this.get("sender"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set sender(value: Bytes) { + this.set("sender", Value.fromBytes(value)); + } + + get amount0(): BigInt { + let value = this.get("amount0"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount0(value: BigInt) { + this.set("amount0", Value.fromBigInt(value)); + } + + get amount1(): BigInt { + let value = this.get("amount1"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount1(value: BigInt) { + this.set("amount1", Value.fromBigInt(value)); + } + + get to(): Bytes { + let value = this.get("to"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set to(value: Bytes) { + this.set("to", Value.fromBytes(value)); + } + + get logIndex(): BigInt { + let value = this.get("logIndex"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set logIndex(value: BigInt) { + this.set("logIndex", Value.fromBigInt(value)); + } +} + +export class Swap extends Entity { + constructor(id: string) { + super(); + this.set("id", Value.fromString(id)); + } + + save(): void { + let id = this.get("id"); + assert(id != null, "Cannot save Swap entity without an ID"); + if (id) { + assert( + id.kind == ValueKind.STRING, + `Entities of type Swap must have an ID of type String but the id '${id.displayData()}' is of type ${id.displayKind()}` + ); + store.set("Swap", id.toString(), this); + } + } + + static loadInBlock(id: string): Swap | null { + return changetype(store.get_in_block("Swap", id)); + } + + static load(id: string): Swap | null { + return changetype(store.get("Swap", id)); + } + + get id(): string { + let value = this.get("id"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set id(value: string) { + this.set("id", Value.fromString(value)); + } + + get timestamp(): BigInt { + let value = this.get("timestamp"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set timestamp(value: BigInt) { + this.set("timestamp", Value.fromBigInt(value)); + } + + get pair(): string { + let value = this.get("pair"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toString(); + } + } + + set pair(value: string) { + this.set("pair", Value.fromString(value)); + } + + get sender(): Bytes { + let value = this.get("sender"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set sender(value: Bytes) { + this.set("sender", Value.fromBytes(value)); + } + + get from(): Bytes { + let value = this.get("from"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set from(value: Bytes) { + this.set("from", Value.fromBytes(value)); + } + + get amount0In(): BigInt { + let value = this.get("amount0In"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount0In(value: BigInt) { + this.set("amount0In", Value.fromBigInt(value)); + } + + get amount1In(): BigInt { + let value = this.get("amount1In"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount1In(value: BigInt) { + this.set("amount1In", Value.fromBigInt(value)); + } + + get amount0Out(): BigInt { + let value = this.get("amount0Out"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount0Out(value: BigInt) { + this.set("amount0Out", Value.fromBigInt(value)); + } + + get amount1Out(): BigInt { + let value = this.get("amount1Out"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set amount1Out(value: BigInt) { + this.set("amount1Out", Value.fromBigInt(value)); + } + + get to(): Bytes { + let value = this.get("to"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBytes(); + } + } + + set to(value: Bytes) { + this.set("to", Value.fromBytes(value)); + } + + get logIndex(): BigInt { + let value = this.get("logIndex"); + if (!value || value.kind == ValueKind.NULL) { + throw new Error("Cannot return null for a required field."); + } else { + return value.toBigInt(); + } + } + + set logIndex(value: BigInt) { + this.set("logIndex", Value.fromBigInt(value)); + } +} + +export class MintLoader extends Entity { + _entity: string; + _field: string; + _id: string; + + constructor(entity: string, id: string, field: string) { + super(); + this._entity = entity; + this._id = id; + this._field = field; + } + + load(): Mint[] { + let value = store.loadRelated(this._entity, this._id, this._field); + return changetype(value); + } +} + +export class BurnLoader extends Entity { + _entity: string; + _field: string; + _id: string; + + constructor(entity: string, id: string, field: string) { + super(); + this._entity = entity; + this._id = id; + this._field = field; + } + + load(): Burn[] { + let value = store.loadRelated(this._entity, this._id, this._field); + return changetype(value); + } +} + +export class SwapLoader extends Entity { + _entity: string; + _field: string; + _id: string; + + constructor(entity: string, id: string, field: string) { + super(); + this._entity = entity; + this._id = id; + this._field = field; + } + + load(): Swap[] { + let value = store.loadRelated(this._entity, this._id, this._field); + return changetype(value); + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/templates.ts b/benchmarks/apps/subgraph-univ2/generated/templates.ts new file mode 100644 index 000000000..9dff55883 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/templates.ts @@ -0,0 +1,17 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + Address, + DataSourceTemplate, + DataSourceContext +} from "@graphprotocol/graph-ts"; + +export class Pair extends DataSourceTemplate { + static create(address: Address): void { + DataSourceTemplate.create("Pair", [address.toHex()]); + } + + static createWithContext(address: Address, context: DataSourceContext): void { + DataSourceTemplate.createWithContext("Pair", [address.toHex()], context); + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Factory.ts b/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Factory.ts new file mode 100644 index 000000000..2229676f6 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Factory.ts @@ -0,0 +1,291 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class PairCreated extends ethereum.Event { + get params(): PairCreated__Params { + return new PairCreated__Params(this); + } +} + +export class PairCreated__Params { + _event: PairCreated; + + constructor(event: PairCreated) { + this._event = event; + } + + get token0(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get token1(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get pair(): Address { + return this._event.parameters[2].value.toAddress(); + } + + get param3(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } +} + +export class Factory extends ethereum.SmartContract { + static bind(address: Address): Factory { + return new Factory("Factory", address); + } + + allPairs(param0: BigInt): Address { + let result = super.call("allPairs", "allPairs(uint256):(address)", [ + ethereum.Value.fromUnsignedBigInt(param0) + ]); + + return result[0].toAddress(); + } + + try_allPairs(param0: BigInt): ethereum.CallResult
{ + let result = super.tryCall("allPairs", "allPairs(uint256):(address)", [ + ethereum.Value.fromUnsignedBigInt(param0) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + allPairsLength(): BigInt { + let result = super.call("allPairsLength", "allPairsLength():(uint256)", []); + + return result[0].toBigInt(); + } + + try_allPairsLength(): ethereum.CallResult { + let result = super.tryCall( + "allPairsLength", + "allPairsLength():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + createPair(tokenA: Address, tokenB: Address): Address { + let result = super.call( + "createPair", + "createPair(address,address):(address)", + [ethereum.Value.fromAddress(tokenA), ethereum.Value.fromAddress(tokenB)] + ); + + return result[0].toAddress(); + } + + try_createPair( + tokenA: Address, + tokenB: Address + ): ethereum.CallResult
{ + let result = super.tryCall( + "createPair", + "createPair(address,address):(address)", + [ethereum.Value.fromAddress(tokenA), ethereum.Value.fromAddress(tokenB)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + feeTo(): Address { + let result = super.call("feeTo", "feeTo():(address)", []); + + return result[0].toAddress(); + } + + try_feeTo(): ethereum.CallResult
{ + let result = super.tryCall("feeTo", "feeTo():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + feeToSetter(): Address { + let result = super.call("feeToSetter", "feeToSetter():(address)", []); + + return result[0].toAddress(); + } + + try_feeToSetter(): ethereum.CallResult
{ + let result = super.tryCall("feeToSetter", "feeToSetter():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + getPair(param0: Address, param1: Address): Address { + let result = super.call("getPair", "getPair(address,address):(address)", [ + ethereum.Value.fromAddress(param0), + ethereum.Value.fromAddress(param1) + ]); + + return result[0].toAddress(); + } + + try_getPair(param0: Address, param1: Address): ethereum.CallResult
{ + let result = super.tryCall( + "getPair", + "getPair(address,address):(address)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } + + get _feeToSetter(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class CreatePairCall extends ethereum.Call { + get inputs(): CreatePairCall__Inputs { + return new CreatePairCall__Inputs(this); + } + + get outputs(): CreatePairCall__Outputs { + return new CreatePairCall__Outputs(this); + } +} + +export class CreatePairCall__Inputs { + _call: CreatePairCall; + + constructor(call: CreatePairCall) { + this._call = call; + } + + get tokenA(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get tokenB(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class CreatePairCall__Outputs { + _call: CreatePairCall; + + constructor(call: CreatePairCall) { + this._call = call; + } + + get pair(): Address { + return this._call.outputValues[0].value.toAddress(); + } +} + +export class SetFeeToCall extends ethereum.Call { + get inputs(): SetFeeToCall__Inputs { + return new SetFeeToCall__Inputs(this); + } + + get outputs(): SetFeeToCall__Outputs { + return new SetFeeToCall__Outputs(this); + } +} + +export class SetFeeToCall__Inputs { + _call: SetFeeToCall; + + constructor(call: SetFeeToCall) { + this._call = call; + } + + get _feeTo(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetFeeToCall__Outputs { + _call: SetFeeToCall; + + constructor(call: SetFeeToCall) { + this._call = call; + } +} + +export class SetFeeToSetterCall extends ethereum.Call { + get inputs(): SetFeeToSetterCall__Inputs { + return new SetFeeToSetterCall__Inputs(this); + } + + get outputs(): SetFeeToSetterCall__Outputs { + return new SetFeeToSetterCall__Outputs(this); + } +} + +export class SetFeeToSetterCall__Inputs { + _call: SetFeeToSetterCall; + + constructor(call: SetFeeToSetterCall) { + this._call = call; + } + + get _feeToSetter(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SetFeeToSetterCall__Outputs { + _call: SetFeeToSetterCall; + + constructor(call: SetFeeToSetterCall) { + this._call = call; + } +} diff --git a/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Pair.ts b/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Pair.ts new file mode 100644 index 000000000..19afda6b7 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/generated/templates/Pair/Pair.ts @@ -0,0 +1,1090 @@ +// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. + +import { + ethereum, + JSONValue, + TypedMap, + Entity, + Bytes, + Address, + BigInt +} from "@graphprotocol/graph-ts"; + +export class Approval extends ethereum.Event { + get params(): Approval__Params { + return new Approval__Params(this); + } +} + +export class Approval__Params { + _event: Approval; + + constructor(event: Approval) { + this._event = event; + } + + get owner(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get spender(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Burn extends ethereum.Event { + get params(): Burn__Params { + return new Burn__Params(this); + } +} + +export class Burn__Params { + _event: Burn; + + constructor(event: Burn) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get to(): Address { + return this._event.parameters[3].value.toAddress(); + } +} + +export class Mint extends ethereum.Event { + get params(): Mint__Params { + return new Mint__Params(this); + } +} + +export class Mint__Params { + _event: Mint; + + constructor(event: Mint) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Swap extends ethereum.Event { + get params(): Swap__Params { + return new Swap__Params(this); + } +} + +export class Swap__Params { + _event: Swap; + + constructor(event: Swap) { + this._event = event; + } + + get sender(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get amount0In(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } + + get amount1In(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } + + get amount0Out(): BigInt { + return this._event.parameters[3].value.toBigInt(); + } + + get amount1Out(): BigInt { + return this._event.parameters[4].value.toBigInt(); + } + + get to(): Address { + return this._event.parameters[5].value.toAddress(); + } +} + +export class Sync extends ethereum.Event { + get params(): Sync__Params { + return new Sync__Params(this); + } +} + +export class Sync__Params { + _event: Sync; + + constructor(event: Sync) { + this._event = event; + } + + get reserve0(): BigInt { + return this._event.parameters[0].value.toBigInt(); + } + + get reserve1(): BigInt { + return this._event.parameters[1].value.toBigInt(); + } +} + +export class Transfer extends ethereum.Event { + get params(): Transfer__Params { + return new Transfer__Params(this); + } +} + +export class Transfer__Params { + _event: Transfer; + + constructor(event: Transfer) { + this._event = event; + } + + get from(): Address { + return this._event.parameters[0].value.toAddress(); + } + + get to(): Address { + return this._event.parameters[1].value.toAddress(); + } + + get value(): BigInt { + return this._event.parameters[2].value.toBigInt(); + } +} + +export class Pair__burnResult { + value0: BigInt; + value1: BigInt; + + constructor(value0: BigInt, value1: BigInt) { + this.value0 = value0; + this.value1 = value1; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + return map; + } + + getAmount0(): BigInt { + return this.value0; + } + + getAmount1(): BigInt { + return this.value1; + } +} + +export class Pair__getReservesResult { + value0: BigInt; + value1: BigInt; + value2: BigInt; + + constructor(value0: BigInt, value1: BigInt, value2: BigInt) { + this.value0 = value0; + this.value1 = value1; + this.value2 = value2; + } + + toMap(): TypedMap { + let map = new TypedMap(); + map.set("value0", ethereum.Value.fromUnsignedBigInt(this.value0)); + map.set("value1", ethereum.Value.fromUnsignedBigInt(this.value1)); + map.set("value2", ethereum.Value.fromUnsignedBigInt(this.value2)); + return map; + } + + get_reserve0(): BigInt { + return this.value0; + } + + get_reserve1(): BigInt { + return this.value1; + } + + get_blockTimestampLast(): BigInt { + return this.value2; + } +} + +export class Pair extends ethereum.SmartContract { + static bind(address: Address): Pair { + return new Pair("Pair", address); + } + + DOMAIN_SEPARATOR(): Bytes { + let result = super.call( + "DOMAIN_SEPARATOR", + "DOMAIN_SEPARATOR():(bytes32)", + [] + ); + + return result[0].toBytes(); + } + + try_DOMAIN_SEPARATOR(): ethereum.CallResult { + let result = super.tryCall( + "DOMAIN_SEPARATOR", + "DOMAIN_SEPARATOR():(bytes32)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + MINIMUM_LIQUIDITY(): BigInt { + let result = super.call( + "MINIMUM_LIQUIDITY", + "MINIMUM_LIQUIDITY():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_MINIMUM_LIQUIDITY(): ethereum.CallResult { + let result = super.tryCall( + "MINIMUM_LIQUIDITY", + "MINIMUM_LIQUIDITY():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + PERMIT_TYPEHASH(): Bytes { + let result = super.call( + "PERMIT_TYPEHASH", + "PERMIT_TYPEHASH():(bytes32)", + [] + ); + + return result[0].toBytes(); + } + + try_PERMIT_TYPEHASH(): ethereum.CallResult { + let result = super.tryCall( + "PERMIT_TYPEHASH", + "PERMIT_TYPEHASH():(bytes32)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBytes()); + } + + allowance(param0: Address, param1: Address): BigInt { + let result = super.call( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)] + ); + + return result[0].toBigInt(); + } + + try_allowance(param0: Address, param1: Address): ethereum.CallResult { + let result = super.tryCall( + "allowance", + "allowance(address,address):(uint256)", + [ethereum.Value.fromAddress(param0), ethereum.Value.fromAddress(param1)] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + approve(spender: Address, value: BigInt): boolean { + let result = super.call("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(value) + ]); + + return result[0].toBoolean(); + } + + try_approve(spender: Address, value: BigInt): ethereum.CallResult { + let result = super.tryCall("approve", "approve(address,uint256):(bool)", [ + ethereum.Value.fromAddress(spender), + ethereum.Value.fromUnsignedBigInt(value) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + balanceOf(param0: Address): BigInt { + let result = super.call("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(param0) + ]); + + return result[0].toBigInt(); + } + + try_balanceOf(param0: Address): ethereum.CallResult { + let result = super.tryCall("balanceOf", "balanceOf(address):(uint256)", [ + ethereum.Value.fromAddress(param0) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + burn(to: Address): Pair__burnResult { + let result = super.call("burn", "burn(address):(uint256,uint256)", [ + ethereum.Value.fromAddress(to) + ]); + + return new Pair__burnResult(result[0].toBigInt(), result[1].toBigInt()); + } + + try_burn(to: Address): ethereum.CallResult { + let result = super.tryCall("burn", "burn(address):(uint256,uint256)", [ + ethereum.Value.fromAddress(to) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Pair__burnResult(value[0].toBigInt(), value[1].toBigInt()) + ); + } + + decimals(): i32 { + let result = super.call("decimals", "decimals():(uint8)", []); + + return result[0].toI32(); + } + + try_decimals(): ethereum.CallResult { + let result = super.tryCall("decimals", "decimals():(uint8)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toI32()); + } + + factory(): Address { + let result = super.call("factory", "factory():(address)", []); + + return result[0].toAddress(); + } + + try_factory(): ethereum.CallResult
{ + let result = super.tryCall("factory", "factory():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + getReserves(): Pair__getReservesResult { + let result = super.call( + "getReserves", + "getReserves():(uint112,uint112,uint32)", + [] + ); + + return new Pair__getReservesResult( + result[0].toBigInt(), + result[1].toBigInt(), + result[2].toBigInt() + ); + } + + try_getReserves(): ethereum.CallResult { + let result = super.tryCall( + "getReserves", + "getReserves():(uint112,uint112,uint32)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue( + new Pair__getReservesResult( + value[0].toBigInt(), + value[1].toBigInt(), + value[2].toBigInt() + ) + ); + } + + kLast(): BigInt { + let result = super.call("kLast", "kLast():(uint256)", []); + + return result[0].toBigInt(); + } + + try_kLast(): ethereum.CallResult { + let result = super.tryCall("kLast", "kLast():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + mint(to: Address): BigInt { + let result = super.call("mint", "mint(address):(uint256)", [ + ethereum.Value.fromAddress(to) + ]); + + return result[0].toBigInt(); + } + + try_mint(to: Address): ethereum.CallResult { + let result = super.tryCall("mint", "mint(address):(uint256)", [ + ethereum.Value.fromAddress(to) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + name(): string { + let result = super.call("name", "name():(string)", []); + + return result[0].toString(); + } + + try_name(): ethereum.CallResult { + let result = super.tryCall("name", "name():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + nonces(param0: Address): BigInt { + let result = super.call("nonces", "nonces(address):(uint256)", [ + ethereum.Value.fromAddress(param0) + ]); + + return result[0].toBigInt(); + } + + try_nonces(param0: Address): ethereum.CallResult { + let result = super.tryCall("nonces", "nonces(address):(uint256)", [ + ethereum.Value.fromAddress(param0) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + price0CumulativeLast(): BigInt { + let result = super.call( + "price0CumulativeLast", + "price0CumulativeLast():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_price0CumulativeLast(): ethereum.CallResult { + let result = super.tryCall( + "price0CumulativeLast", + "price0CumulativeLast():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + price1CumulativeLast(): BigInt { + let result = super.call( + "price1CumulativeLast", + "price1CumulativeLast():(uint256)", + [] + ); + + return result[0].toBigInt(); + } + + try_price1CumulativeLast(): ethereum.CallResult { + let result = super.tryCall( + "price1CumulativeLast", + "price1CumulativeLast():(uint256)", + [] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + symbol(): string { + let result = super.call("symbol", "symbol():(string)", []); + + return result[0].toString(); + } + + try_symbol(): ethereum.CallResult { + let result = super.tryCall("symbol", "symbol():(string)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toString()); + } + + token0(): Address { + let result = super.call("token0", "token0():(address)", []); + + return result[0].toAddress(); + } + + try_token0(): ethereum.CallResult
{ + let result = super.tryCall("token0", "token0():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + token1(): Address { + let result = super.call("token1", "token1():(address)", []); + + return result[0].toAddress(); + } + + try_token1(): ethereum.CallResult
{ + let result = super.tryCall("token1", "token1():(address)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toAddress()); + } + + totalSupply(): BigInt { + let result = super.call("totalSupply", "totalSupply():(uint256)", []); + + return result[0].toBigInt(); + } + + try_totalSupply(): ethereum.CallResult { + let result = super.tryCall("totalSupply", "totalSupply():(uint256)", []); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBigInt()); + } + + transfer(to: Address, value: BigInt): boolean { + let result = super.call("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value) + ]); + + return result[0].toBoolean(); + } + + try_transfer(to: Address, value: BigInt): ethereum.CallResult { + let result = super.tryCall("transfer", "transfer(address,uint256):(bool)", [ + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value) + ]); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } + + transferFrom(from: Address, to: Address, value: BigInt): boolean { + let result = super.call( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(from), + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value) + ] + ); + + return result[0].toBoolean(); + } + + try_transferFrom( + from: Address, + to: Address, + value: BigInt + ): ethereum.CallResult { + let result = super.tryCall( + "transferFrom", + "transferFrom(address,address,uint256):(bool)", + [ + ethereum.Value.fromAddress(from), + ethereum.Value.fromAddress(to), + ethereum.Value.fromUnsignedBigInt(value) + ] + ); + if (result.reverted) { + return new ethereum.CallResult(); + } + let value = result.value; + return ethereum.CallResult.fromValue(value[0].toBoolean()); + } +} + +export class ConstructorCall extends ethereum.Call { + get inputs(): ConstructorCall__Inputs { + return new ConstructorCall__Inputs(this); + } + + get outputs(): ConstructorCall__Outputs { + return new ConstructorCall__Outputs(this); + } +} + +export class ConstructorCall__Inputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ConstructorCall__Outputs { + _call: ConstructorCall; + + constructor(call: ConstructorCall) { + this._call = call; + } +} + +export class ApproveCall extends ethereum.Call { + get inputs(): ApproveCall__Inputs { + return new ApproveCall__Inputs(this); + } + + get outputs(): ApproveCall__Outputs { + return new ApproveCall__Outputs(this); + } +} + +export class ApproveCall__Inputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get spender(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class ApproveCall__Outputs { + _call: ApproveCall; + + constructor(call: ApproveCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class BurnCall extends ethereum.Call { + get inputs(): BurnCall__Inputs { + return new BurnCall__Inputs(this); + } + + get outputs(): BurnCall__Outputs { + return new BurnCall__Outputs(this); + } +} + +export class BurnCall__Inputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class BurnCall__Outputs { + _call: BurnCall; + + constructor(call: BurnCall) { + this._call = call; + } + + get amount0(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } + + get amount1(): BigInt { + return this._call.outputValues[1].value.toBigInt(); + } +} + +export class InitializeCall extends ethereum.Call { + get inputs(): InitializeCall__Inputs { + return new InitializeCall__Inputs(this); + } + + get outputs(): InitializeCall__Outputs { + return new InitializeCall__Outputs(this); + } +} + +export class InitializeCall__Inputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } + + get _token0(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get _token1(): Address { + return this._call.inputValues[1].value.toAddress(); + } +} + +export class InitializeCall__Outputs { + _call: InitializeCall; + + constructor(call: InitializeCall) { + this._call = call; + } +} + +export class MintCall extends ethereum.Call { + get inputs(): MintCall__Inputs { + return new MintCall__Inputs(this); + } + + get outputs(): MintCall__Outputs { + return new MintCall__Outputs(this); + } +} + +export class MintCall__Inputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class MintCall__Outputs { + _call: MintCall; + + constructor(call: MintCall) { + this._call = call; + } + + get liquidity(): BigInt { + return this._call.outputValues[0].value.toBigInt(); + } +} + +export class PermitCall extends ethereum.Call { + get inputs(): PermitCall__Inputs { + return new PermitCall__Inputs(this); + } + + get outputs(): PermitCall__Outputs { + return new PermitCall__Outputs(this); + } +} + +export class PermitCall__Inputs { + _call: PermitCall; + + constructor(call: PermitCall) { + this._call = call; + } + + get owner(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get spender(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } + + get deadline(): BigInt { + return this._call.inputValues[3].value.toBigInt(); + } + + get v(): i32 { + return this._call.inputValues[4].value.toI32(); + } + + get r(): Bytes { + return this._call.inputValues[5].value.toBytes(); + } + + get s(): Bytes { + return this._call.inputValues[6].value.toBytes(); + } +} + +export class PermitCall__Outputs { + _call: PermitCall; + + constructor(call: PermitCall) { + this._call = call; + } +} + +export class SkimCall extends ethereum.Call { + get inputs(): SkimCall__Inputs { + return new SkimCall__Inputs(this); + } + + get outputs(): SkimCall__Outputs { + return new SkimCall__Outputs(this); + } +} + +export class SkimCall__Inputs { + _call: SkimCall; + + constructor(call: SkimCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } +} + +export class SkimCall__Outputs { + _call: SkimCall; + + constructor(call: SkimCall) { + this._call = call; + } +} + +export class SwapCall extends ethereum.Call { + get inputs(): SwapCall__Inputs { + return new SwapCall__Inputs(this); + } + + get outputs(): SwapCall__Outputs { + return new SwapCall__Outputs(this); + } +} + +export class SwapCall__Inputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } + + get amount0Out(): BigInt { + return this._call.inputValues[0].value.toBigInt(); + } + + get amount1Out(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } + + get to(): Address { + return this._call.inputValues[2].value.toAddress(); + } + + get data(): Bytes { + return this._call.inputValues[3].value.toBytes(); + } +} + +export class SwapCall__Outputs { + _call: SwapCall; + + constructor(call: SwapCall) { + this._call = call; + } +} + +export class SyncCall extends ethereum.Call { + get inputs(): SyncCall__Inputs { + return new SyncCall__Inputs(this); + } + + get outputs(): SyncCall__Outputs { + return new SyncCall__Outputs(this); + } +} + +export class SyncCall__Inputs { + _call: SyncCall; + + constructor(call: SyncCall) { + this._call = call; + } +} + +export class SyncCall__Outputs { + _call: SyncCall; + + constructor(call: SyncCall) { + this._call = call; + } +} + +export class TransferCall extends ethereum.Call { + get inputs(): TransferCall__Inputs { + return new TransferCall__Inputs(this); + } + + get outputs(): TransferCall__Outputs { + return new TransferCall__Outputs(this); + } +} + +export class TransferCall__Inputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get to(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[1].value.toBigInt(); + } +} + +export class TransferCall__Outputs { + _call: TransferCall; + + constructor(call: TransferCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} + +export class TransferFromCall extends ethereum.Call { + get inputs(): TransferFromCall__Inputs { + return new TransferFromCall__Inputs(this); + } + + get outputs(): TransferFromCall__Outputs { + return new TransferFromCall__Outputs(this); + } +} + +export class TransferFromCall__Inputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get from(): Address { + return this._call.inputValues[0].value.toAddress(); + } + + get to(): Address { + return this._call.inputValues[1].value.toAddress(); + } + + get value(): BigInt { + return this._call.inputValues[2].value.toBigInt(); + } +} + +export class TransferFromCall__Outputs { + _call: TransferFromCall; + + constructor(call: TransferFromCall) { + this._call = call; + } + + get value0(): boolean { + return this._call.outputValues[0].value.toBoolean(); + } +} diff --git a/benchmarks/apps/subgraph-univ2/schema.graphql b/benchmarks/apps/subgraph-univ2/schema.graphql new file mode 100644 index 000000000..331725337 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/schema.graphql @@ -0,0 +1,77 @@ +type UniswapFactory @entity { + # factory address + id: ID! + + # pair info + pairCount: Int! + + # transactions + txCount: Int! +} + +type Pair @entity { + # pair address + id: ID! + + # mirrored from the smart contract + token0: Bytes! + token1: Bytes! + reserve0: BigInt! + reserve1: BigInt! + totalSupply: BigInt! + + txCount: Int! + + # creation stats + createdAtTimestamp: BigInt! + createdAtBlockNumber: BigInt! + + # Fields used to help derived relationship + mints: [Mint!]! @derivedFrom(field: "pair") + burns: [Burn!]! @derivedFrom(field: "pair") + swaps: [Swap!]! @derivedFrom(field: "pair") +} + +type Mint @entity { + # transaction hash + "-" + index in mints Transaction array + id: ID! + timestamp: BigInt! # need this to pull recent txns for specific token or pair + pair: Pair! + + # populated from the Mint event + sender: Bytes! + amount0: BigInt! + amount1: BigInt! + logIndex: BigInt! +} + +type Burn @entity { + # transaction hash + "-" + index in mints Transaction array + id: ID! + timestamp: BigInt! # need this to pull recent txns for specific token or pair + pair: Pair! + + # populated from the Burn event + sender: Bytes! + amount0: BigInt! + amount1: BigInt! + to: Bytes! + logIndex: BigInt! +} + +type Swap @entity { + # transaction hash + "-" + index in swaps Transaction array + id: ID! + timestamp: BigInt! # need this to pull recent txns for specific token or pair + pair: Pair! + + # populated from the Swap event + sender: Bytes! + from: Bytes! + amount0In: BigInt! + amount1In: BigInt! + amount0Out: BigInt! + amount1Out: BigInt! + to: Bytes! + logIndex: BigInt! +} diff --git a/benchmarks/apps/subgraph-univ2/src/mappings/core.ts b/benchmarks/apps/subgraph-univ2/src/mappings/core.ts new file mode 100644 index 000000000..d9e237f24 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/src/mappings/core.ts @@ -0,0 +1,123 @@ +/* eslint-disable prefer-const */ +import { + Burn as BurnEvent, + Mint as MintEvent, + Pair, + Swap as SwapEvent, + UniswapFactory, +} from "../../generated/schema"; +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +import { Burn, Mint, Swap, Sync } from "../../generated/templates/Pair/Pair"; +import { FACTORY_ADDRESS } from "./helpers"; + +export function handleSync(event: Sync): void { + let pair = Pair.load(event.address.toHex())!; + + pair.reserve0 = event.params.reserve0; + pair.reserve1 = event.params.reserve1; + + pair.save(); +} + +export function handleMint(event: Mint): void { + let mint = new MintEvent( + event.transaction.hash + .toHexString() + .concat("-") + .concat(event.logIndex.toHexString()), + ); + + let pair = Pair.load(event.address.toHex())!; + let uniswap = UniswapFactory.load(FACTORY_ADDRESS)!; + + // update exchange info (except balances, sync will cover that) + let token0Amount = event.params.amount0; + let token1Amount = event.params.amount1; + + // update txn counts + pair.txCount = pair.txCount + 1; + uniswap.txCount = uniswap.txCount + 1; + + // save entities + pair.save(); + uniswap.save(); + + mint.timestamp = event.block.timestamp; + mint.sender = event.params.sender; + mint.amount0 = token0Amount; + mint.amount1 = token1Amount; + mint.logIndex = event.logIndex; + mint.save(); +} + +export function handleBurn(event: Burn): void { + let burn = new BurnEvent( + event.transaction.hash + .toHexString() + .concat("-") + .concat(event.logIndex.toHexString()), + ); + + let pair = Pair.load(event.address.toHex())!; + let uniswap = UniswapFactory.load(FACTORY_ADDRESS)!; + + //update token info + let token0Amount = event.params.amount0; + let token1Amount = event.params.amount1; + + // update txn counts + uniswap.txCount = uniswap.txCount + 1; + pair.txCount = pair.txCount + 1; + + // update global counter and save + pair.save(); + uniswap.save(); + + // update burn + burn.sender = event.params.sender; + burn.timestamp = event.block.timestamp; + burn.amount0 = token0Amount; + burn.amount1 = token1Amount; + burn.to = event.params.to; + burn.logIndex = event.logIndex; + burn.save(); +} + +export function handleSwap(event: Swap): void { + let pair = Pair.load(event.address.toHexString())!; + let amount0In = event.params.amount0In; + let amount1In = event.params.amount1In; + let amount0Out = event.params.amount0Out; + let amount1Out = event.params.amount1Out; + + pair.txCount = pair.txCount + 1; + + // update global values, only used tracked amounts for volume + let uniswap = UniswapFactory.load(FACTORY_ADDRESS)!; + uniswap.txCount = uniswap.txCount + 1; + + // save entities + pair.save(); + uniswap.save(); + + let swap = new SwapEvent( + event.transaction.hash + .toHexString() + .concat("-") + .concat(event.logIndex.toHexString()), + ); + + // update swap event + swap.pair = pair.id; + swap.timestamp = event.block.timestamp; + swap.sender = event.params.sender; + swap.amount0In = amount0In; + swap.amount1In = amount1In; + swap.amount0Out = amount0Out; + swap.amount1Out = amount1Out; + swap.to = event.params.to; + swap.from = event.transaction.from; + swap.logIndex = event.logIndex; + + swap.save(); +} diff --git a/benchmarks/apps/subgraph-univ2/src/mappings/factory.ts b/benchmarks/apps/subgraph-univ2/src/mappings/factory.ts new file mode 100644 index 000000000..c40b61d87 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/src/mappings/factory.ts @@ -0,0 +1,37 @@ +/* eslint-disable prefer-const */ +// eslint-disable-next-line @typescript-eslint/consistent-type-imports +import { PairCreated } from "../../generated/Factory/Factory"; +import { Pair, UniswapFactory } from "../../generated/schema"; +import { Pair as PairTemplate } from "../../generated/templates"; +import { FACTORY_ADDRESS, ZERO_BI } from "./helpers"; + +export function handleNewPair(event: PairCreated): void { + // load factory (create if first exchange) + let factory = UniswapFactory.load(FACTORY_ADDRESS); + if (factory === null) { + factory = new UniswapFactory(FACTORY_ADDRESS); + factory.pairCount = 0; + factory.txCount = 0; + } + factory.pairCount = factory.pairCount + 1; + factory.save(); + + let pair = new Pair(event.params.pair.toHexString()) as Pair; + pair.token0 = event.params.token0; + pair.token1 = event.params.token1; + pair.createdAtTimestamp = event.block.timestamp; + pair.createdAtBlockNumber = event.block.number; + pair.txCount = 0; + pair.reserve0 = ZERO_BI; + pair.reserve1 = ZERO_BI; + + pair.totalSupply = ZERO_BI; + + // create the tracked contract based on the template + PairTemplate.create(event.params.pair); + + // save updated values + + pair.save(); + factory.save(); +} diff --git a/benchmarks/apps/subgraph-univ2/src/mappings/helpers.ts b/benchmarks/apps/subgraph-univ2/src/mappings/helpers.ts new file mode 100644 index 000000000..8f9ae29ab --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/src/mappings/helpers.ts @@ -0,0 +1,7 @@ +/* eslint-disable prefer-const */ +import { BigInt } from "@graphprotocol/graph-ts"; + +export const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000"; +export const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"; + +export let ZERO_BI = BigInt.fromI32(0); diff --git a/benchmarks/apps/subgraph-univ2/subgraph.yaml b/benchmarks/apps/subgraph-univ2/subgraph.yaml new file mode 100644 index 000000000..8973915d7 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/subgraph.yaml @@ -0,0 +1,57 @@ +specVersion: 0.0.5 +description: Uniswap is a decentralized protocol for automated token exchange on Ethereum. +repository: https://github.com/Uniswap/uniswap-v2-subgraph +schema: + file: ./schema.graphql +dataSources: + - kind: ethereum/contract + name: Factory + network: mainnet + source: + address: "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f" + abi: Factory + startBlock: 18600000 + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + file: ./src/mappings/factory.ts + entities: + - Pair + - Token + abis: + - name: Factory + file: ./abis/factory.json + eventHandlers: + - event: PairCreated(indexed address,indexed address,address,uint256) + handler: handleNewPair +templates: + - kind: ethereum/contract + name: Pair + network: mainnet + source: + abi: Pair + mapping: + kind: ethereum/events + apiVersion: 0.0.6 + language: wasm/assemblyscript + file: ./src/mappings/core.ts + entities: + - Pair + - Token + abis: + - name: Pair + file: ./abis/pair.json + - name: Factory + file: ./abis/factory.json + eventHandlers: + - event: Mint(indexed address,uint256,uint256) + handler: handleMint + - event: Burn(indexed address,uint256,uint256,indexed address) + handler: handleBurn + - event: Swap(indexed address,uint256,uint256,uint256,uint256,indexed address) + handler: handleSwap + - event: Transfer(indexed address,indexed address,uint256) + handler: handleTransfer + - event: Sync(uint112,uint112) + handler: handleSync diff --git a/benchmarks/apps/subgraph-univ2/tsconfig.json b/benchmarks/apps/subgraph-univ2/tsconfig.json new file mode 100644 index 000000000..5c5d17c92 --- /dev/null +++ b/benchmarks/apps/subgraph-univ2/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "@graphprotocol/graph-ts/types/tsconfig.base.json", + "include": ["src"] +} diff --git a/benchmarks/package.json b/benchmarks/package.json index c8839fbee..e37a73195 100644 --- a/benchmarks/package.json +++ b/benchmarks/package.json @@ -4,7 +4,7 @@ "type": "module", "scripts": { "bench:ponder": "bun src/ponder.ts", - "bench:subgraph": "export $(grep -v '^#' .env.local | xargs) && rm -rf data/ && docker-compose up --detach && tsup-node && (node dist/subgraph.js || true) && docker-compose down" + "bench:subgraph": "./run-subgraph.sh" }, "devDependencies": { "@graphprotocol/graph-cli": "0.61.0", diff --git a/benchmarks/ponder/ponder-env.d.ts b/benchmarks/ponder/ponder-env.d.ts deleted file mode 100644 index 036eb225e..000000000 --- a/benchmarks/ponder/ponder-env.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -declare module "@/generated" { - import type { ExtractContext, PonderApp } from "@ponder/core"; - - type Config = typeof import("./ponder.config.ts").default; - type Schema = typeof import("./ponder.schema.ts").default; - - export const ponder: PonderApp; - - export type Context = ExtractContext; -} diff --git a/benchmarks/run-subgraph.sh b/benchmarks/run-subgraph.sh new file mode 100755 index 000000000..a3e0baf69 --- /dev/null +++ b/benchmarks/run-subgraph.sh @@ -0,0 +1 @@ +export $(grep -v '^#' .env.local | xargs) && rm -rf data/ && docker-compose up --detach && tsup-node && (node dist/subgraph.js $1 || true) && docker-compose down \ No newline at end of file diff --git a/benchmarks/src/ponder.ts b/benchmarks/src/ponder.ts index bc7a36142..f6a8c6c78 100644 --- a/benchmarks/src/ponder.ts +++ b/benchmarks/src/ponder.ts @@ -1,5 +1,6 @@ import { rmSync } from "node:fs"; import os from "node:os"; +import path from "node:path"; import { execa } from "execa"; @@ -79,7 +80,7 @@ const ponder = async () => { const subprocess = execa( "../packages/core/dist/bin/ponder.js", - ["start", `--root-dir=ponder`], + ["start", `--root-dir=${process.argv[2]}`], { stdio: "inherit", detached: true, @@ -98,11 +99,11 @@ const ponder = async () => { }; const bench = async () => { - rmSync("./ponder/.ponder/", { + rmSync(path.join(process.argv[2]!, ".ponder"), { recursive: true, force: true, }); - rmSync("./ponder/generated/", { + rmSync(path.join(process.argv[2]!, "generated"), { recursive: true, force: true, }); diff --git a/benchmarks/src/subgraph.ts b/benchmarks/src/subgraph.ts index d4361dbd8..4af124815 100644 --- a/benchmarks/src/subgraph.ts +++ b/benchmarks/src/subgraph.ts @@ -88,6 +88,8 @@ const subgraph = async () => { console.log(`Waiting for Graph Node to be ready...`); const setupDuration = await waitForGraphNode(); + console.log(process.argv[2]); + console.log("Registering subgraph..."); await execa( "graph", @@ -104,8 +106,8 @@ const subgraph = async () => { [ "deploy", "ponder-benchmarks/subgraph", - "./subgraph/subgraph.yaml", - "--output-dir=./subgraph/build", + `./${process.argv[2]}/subgraph.yaml`, + `--output-dir=./${process.argv[2]}/build`, "--ipfs=http://localhost:5001", "--node=http://localhost:8020", "--version-label=v0.0.1", @@ -126,12 +128,19 @@ const subgraph = async () => { }; const changeMappingFileDelim = (delim: string) => { - let mappingFileContents = readFileSync("./subgraph/src/mapping.ts", { - encoding: "utf-8", - }); + let mappingFileContents = readFileSync( + "./apps/subgraph-reth/src/mapping.ts", + { + encoding: "utf-8", + }, + ); mappingFileContents = mappingFileContents.replace(/(dif:.)/g, `dif:${delim}`); - writeFileSync("./subgraph/src/mapping.ts", mappingFileContents, "utf-8"); + writeFileSync( + "./apps/subgraph-reth/src/mapping.ts", + mappingFileContents, + "utf-8", + ); }; const bench = async () => {