create-ponder 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,7 +10,7 @@ const networkByEtherscanHostname = {
10
10
  "ropsten.etherscan.io": {
11
11
  name: "ropsten",
12
12
  chainId: 3,
13
- apiUrl: "https://api-ropsten.etherscan.io//api",
13
+ apiUrl: "https://api-ropsten.etherscan.io/api",
14
14
  },
15
15
  "rinkeby.etherscan.io": {
16
16
  name: "rinkeby",
@@ -5,7 +5,7 @@ export declare type PonderNetwork = {
5
5
  chainId: number;
6
6
  rpcUrl: string;
7
7
  };
8
- export declare type PonderSource = {
8
+ export declare type PonderContract = {
9
9
  kind?: "evm";
10
10
  name: string;
11
11
  network: string;
@@ -19,7 +19,7 @@ export declare type PartialPonderConfig = {
19
19
  kind: string;
20
20
  };
21
21
  networks: PonderNetwork[];
22
- sources: PonderSource[];
22
+ contracts: PonderContract[];
23
23
  };
24
24
  export declare const run: (options: CreatePonderOptions, overrides?: {
25
25
  installCommand?: string;
package/dist/src/index.js CHANGED
@@ -18,7 +18,7 @@ const run = async (options, overrides = {}) => {
18
18
  const { ponderRootDir } = options;
19
19
  // Create required directories.
20
20
  (0, node_fs_1.mkdirSync)(node_path_1.default.join(ponderRootDir, "abis"), { recursive: true });
21
- (0, node_fs_1.mkdirSync)(node_path_1.default.join(ponderRootDir, "handlers"), { recursive: true });
21
+ (0, node_fs_1.mkdirSync)(node_path_1.default.join(ponderRootDir, "src"), { recursive: true });
22
22
  let ponderConfig;
23
23
  if (options.fromSubgraph) {
24
24
  console.log(picocolors_1.default.cyan("[create-ponder] ") + `Bootstrapping from subgraph`);
@@ -32,48 +32,26 @@ const run = async (options, overrides = {}) => {
32
32
  ponderConfig = (0, basic_1.fromBasic)(options);
33
33
  }
34
34
  // Write the handler ts files.
35
- ponderConfig.sources.forEach((source) => {
36
- const abi = (0, node_fs_1.readFileSync)(node_path_1.default.join(ponderRootDir, source.abi), {
35
+ ponderConfig.contracts.forEach((contract) => {
36
+ const abi = (0, node_fs_1.readFileSync)(node_path_1.default.join(ponderRootDir, contract.abi), {
37
37
  encoding: "utf-8",
38
38
  });
39
39
  const abiInterface = new ethers_1.ethers.utils.Interface(abi);
40
40
  const eventNames = Object.keys(abiInterface.events);
41
- const handlers = eventNames.map((eventName) => {
42
- const eventBaseName = eventName.split("(")[0];
43
- const handlerFunctionType = `${eventBaseName}Handler`;
44
- const handlerFunctionName = `handle${eventBaseName}`;
45
- return {
46
- handlerFunctionType,
47
- handlerFunction: `const ${handlerFunctionName}: ${handlerFunctionType} = async (event, context) => { return }\n`,
48
- handlerExport: `${eventBaseName}: ${handlerFunctionName}`,
49
- };
50
- });
41
+ const eventNamesToWrite = eventNames.slice(3);
51
42
  const handlerFileContents = `
52
- import { ${handlers.map((h) => h.handlerFunctionType).join(",")} }
53
- from '../generated/handlers'
43
+ import { ponder } from '../generated'
54
44
 
55
- ${handlers.map((h) => h.handlerFunction).join("\n")}
56
-
57
- export const ${source.name} = {
58
- ${handlers.map((h) => h.handlerExport).join(",")}
59
- }
45
+ ${eventNamesToWrite
46
+ .map((eventName) => `
47
+ ponder.on("${contract.name}:${eventName}", async ({ event, context }) => {
48
+ console.log(event.params)
49
+ })`)
50
+ .join("\n")}
60
51
  `;
61
- (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, `./handlers/${source.name}.ts`), prettier_1.default.format(handlerFileContents, { parser: "typescript" }));
52
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, `./src/${contract.name}.ts`), prettier_1.default.format(handlerFileContents, { parser: "typescript" }));
62
53
  });
63
- // Write the handler index.ts file.
64
- const handlerIndexFileContents = `
65
- ${ponderConfig.sources
66
- .map((source) => `import { ${source.name} } from "./${source.name}"`)
67
- .join("\n")}
68
-
69
- export default {
70
- ${ponderConfig.sources
71
- .map((source) => `${source.name}: ${source.name}`)
72
- .join(",")}
73
- }
74
- `;
75
- (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, `./handlers/index.ts`), prettier_1.default.format(handlerIndexFileContents, { parser: "typescript" }));
76
- // Write the ponder.ts file.
54
+ // Write the ponder.config.ts file.
77
55
  const finalPonderConfig = `
78
56
  import type { PonderConfig } from "@ponder/core";
79
57
  import { graphqlPlugin } from "@ponder/graphql";
@@ -81,10 +59,10 @@ const run = async (options, overrides = {}) => {
81
59
  export const config: PonderConfig = {
82
60
  plugins: [graphqlPlugin()],
83
61
  networks: ${JSON.stringify(ponderConfig.networks).replaceAll(/"process.env.PONDER_RPC_URL_(.*?)"/g, "process.env.PONDER_RPC_URL_$1")},
84
- sources: ${JSON.stringify(ponderConfig.sources)},
62
+ contracts: ${JSON.stringify(ponderConfig.contracts)},
85
63
  };
86
64
  `;
87
- (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, "ponder.ts"), prettier_1.default.format(finalPonderConfig, { parser: "babel" }));
65
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(ponderRootDir, "ponder.config.ts"), prettier_1.default.format(finalPonderConfig, { parser: "babel" }));
88
66
  // Write the .env.local file.
89
67
  const uniqueChainIds = Array.from(new Set(ponderConfig.networks.map((n) => n.chainId)));
90
68
  const envLocal = `${uniqueChainIds.map((chainId) => `PONDER_RPC_URL_${chainId}=""\n`)}`;
@@ -103,6 +81,7 @@ const run = async (options, overrides = {}) => {
103
81
  "@ponder/graphql": "latest"
104
82
  },
105
83
  "devDependencies": {
84
+ "@types/node": "^18.11.18",
106
85
  "ethers": "^5.6.9"
107
86
  },
108
87
  "engines": {
@@ -131,7 +110,7 @@ const run = async (options, overrides = {}) => {
131
110
  const packageManager = await (0, detectPackageManager_1.detect)();
132
111
  const runCommand = packageManager === "npm" ? `${packageManager} run` : packageManager;
133
112
  // Install packages.
134
- console.log(picocolors_1.default.cyan("[create-ponder] ") + `Installing using ${packageManager}`);
113
+ console.log(picocolors_1.default.cyan("[create-ponder] ") + `Installing with ${packageManager}`);
135
114
  const installCommand = overrides.installCommand
136
115
  ? overrides.installCommand
137
116
  : `${packageManager} install`;
@@ -40,7 +40,7 @@ const fromBasic = (options) => {
40
40
  rpcUrl: `process.env.PONDER_RPC_URL_1`,
41
41
  },
42
42
  ],
43
- sources: [
43
+ contracts: [
44
44
  {
45
45
  name: "ExampleContract",
46
46
  network: "mainnet",
@@ -61,7 +61,7 @@ const fromEtherscan = async (options) => {
61
61
  rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
62
62
  },
63
63
  ],
64
- sources: [
64
+ contracts: [
65
65
  {
66
66
  name: contractName,
67
67
  network: name,
@@ -16,7 +16,7 @@ const fromSubgraph = (options) => {
16
16
  const { ponderRootDir } = options;
17
17
  const subgraphRootDir = node_path_1.default.resolve(options.fromSubgraph);
18
18
  const ponderNetworks = [];
19
- let ponderSources = [];
19
+ let ponderContracts = [];
20
20
  // If the `--from-subgraph` option was passed, parse subgraph files
21
21
  const subgraphRootDirPath = node_path_1.default.resolve(subgraphRootDir);
22
22
  // Read and parse the subgraph YAML file.
@@ -41,7 +41,7 @@ const fromSubgraph = (options) => {
41
41
  const ponderSchemaFilePath = node_path_1.default.join(ponderRootDir, "schema.graphql");
42
42
  (0, node_fs_1.copyFileSync)(subgraphSchemaFilePath, ponderSchemaFilePath);
43
43
  // Build the ponder sources. Also copy over the ABI files for each source.
44
- ponderSources = subgraphYaml.dataSources
44
+ ponderContracts = subgraphYaml.dataSources
45
45
  .map(validateGraphProtocolSource_1.validateGraphProtocolSource)
46
46
  .map((source) => {
47
47
  const abiPath = source.mapping.abis.find((abi) => abi.name === source.name)?.file;
@@ -81,7 +81,7 @@ const fromSubgraph = (options) => {
81
81
  kind: "sqlite",
82
82
  },
83
83
  networks: ponderNetworks,
84
- sources: ponderSources,
84
+ contracts: ponderContracts,
85
85
  };
86
86
  return ponderConfig;
87
87
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ponder",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "Tool to bootstrap a Ponder project",
5
5
  "license": "MIT",
6
6
  "author": "olias.eth",
@@ -29,7 +29,7 @@
29
29
  "jest": "^29.3.1",
30
30
  "tsconfig-replace-paths": "^0.0.11",
31
31
  "typescript": "^4.5.5",
32
- "@ponder/core": "0.0.24"
32
+ "@ponder/core": "0.0.25"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "rm -rf dist && tsc && tsconfig-replace-paths --src . && mv dist/src/bin/create-ponder.js dist/src/bin/create-ponder",