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.
package/dist/src/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare type PonderNetwork = {
|
|
|
5
5
|
chainId: number;
|
|
6
6
|
rpcUrl: string;
|
|
7
7
|
};
|
|
8
|
-
export declare type
|
|
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
|
-
|
|
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, "
|
|
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.
|
|
36
|
-
const abi = (0, node_fs_1.readFileSync)(node_path_1.default.join(ponderRootDir,
|
|
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
|
|
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 {
|
|
53
|
-
from '../generated/handlers'
|
|
43
|
+
import { ponder } from '../generated'
|
|
54
44
|
|
|
55
|
-
${
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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, `./
|
|
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
|
|
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
|
-
|
|
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
|
|
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`;
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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",
|