create-ponder 0.0.77 → 0.0.79

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.
Files changed (72) hide show
  1. package/LICENSE +1 -1
  2. package/dist/bin/create-ponder.d.ts +3 -0
  3. package/dist/bin/create-ponder.d.ts.map +1 -0
  4. package/dist/bin/create-ponder.js +105 -0
  5. package/dist/bin/create-ponder.js.map +1 -0
  6. package/dist/common.d.ts +23 -0
  7. package/dist/common.d.ts.map +1 -0
  8. package/dist/common.js +11 -0
  9. package/dist/common.js.map +1 -0
  10. package/dist/helpers/getEtherscanChainId.d.ts +6 -0
  11. package/dist/helpers/getEtherscanChainId.d.ts.map +1 -0
  12. package/dist/helpers/getEtherscanChainId.js +75 -0
  13. package/dist/helpers/getEtherscanChainId.js.map +1 -0
  14. package/dist/helpers/getGraphProtocolChainId.d.ts +3 -0
  15. package/dist/helpers/getGraphProtocolChainId.d.ts.map +1 -0
  16. package/dist/helpers/getGraphProtocolChainId.js +42 -0
  17. package/dist/helpers/getGraphProtocolChainId.js.map +1 -0
  18. package/dist/helpers/getPackageManager.d.ts +2 -0
  19. package/dist/helpers/getPackageManager.d.ts.map +1 -0
  20. package/dist/helpers/getPackageManager.js +18 -0
  21. package/dist/helpers/getPackageManager.js.map +1 -0
  22. package/dist/helpers/git.d.ts +2 -0
  23. package/dist/helpers/git.d.ts.map +1 -0
  24. package/dist/helpers/git.js +56 -0
  25. package/dist/helpers/git.js.map +1 -0
  26. package/dist/helpers/validateGraphProtocolSource.d.ts +28 -0
  27. package/dist/helpers/validateGraphProtocolSource.d.ts.map +1 -0
  28. package/dist/helpers/validateGraphProtocolSource.js +8 -0
  29. package/dist/helpers/validateGraphProtocolSource.js.map +1 -0
  30. package/dist/helpers/wait.d.ts +2 -0
  31. package/dist/helpers/wait.d.ts.map +1 -0
  32. package/dist/helpers/wait.js +6 -0
  33. package/dist/helpers/wait.js.map +1 -0
  34. package/dist/index.d.ts +24 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +168 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/templates/basic.d.ts +5 -0
  39. package/dist/templates/basic.d.ts.map +1 -0
  40. package/dist/templates/basic.js +57 -0
  41. package/dist/templates/basic.js.map +1 -0
  42. package/dist/templates/etherscan.d.ts +7 -0
  43. package/dist/templates/etherscan.d.ts.map +1 -0
  44. package/dist/templates/etherscan.js +199 -0
  45. package/dist/templates/etherscan.js.map +1 -0
  46. package/dist/templates/subgraphId.d.ts +6 -0
  47. package/dist/templates/subgraphId.d.ts.map +1 -0
  48. package/dist/templates/subgraphId.js +76 -0
  49. package/dist/templates/subgraphId.js.map +1 -0
  50. package/dist/templates/subgraphRepo.d.ts +6 -0
  51. package/dist/templates/subgraphRepo.d.ts.map +1 -0
  52. package/dist/templates/subgraphRepo.js +86 -0
  53. package/dist/templates/subgraphRepo.js.map +1 -0
  54. package/package.json +15 -11
  55. package/src/bin/create-ponder.ts +127 -0
  56. package/src/common.ts +27 -0
  57. package/src/helpers/getEtherscanChainId.ts +74 -0
  58. package/src/helpers/getGraphProtocolChainId.ts +41 -0
  59. package/src/helpers/getPackageManager.ts +11 -0
  60. package/src/helpers/git.ts +51 -0
  61. package/src/helpers/validateGraphProtocolSource.ts +42 -0
  62. package/src/helpers/wait.ts +2 -0
  63. package/src/index.ts +244 -0
  64. package/src/templates/basic.ts +60 -0
  65. package/src/templates/etherscan.ts +276 -0
  66. package/src/templates/subgraphId.ts +97 -0
  67. package/src/templates/subgraphRepo.ts +116 -0
  68. package/dist/create-ponder.d.ts +0 -1
  69. package/dist/create-ponder.js +0 -937
  70. package/dist/create-ponder.js.map +0 -1
  71. package/dist/create-ponder.mjs +0 -914
  72. package/dist/create-ponder.mjs.map +0 -1
package/dist/index.js ADDED
@@ -0,0 +1,168 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.run = void 0;
7
+ const node_child_process_1 = require("node:child_process");
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const picocolors_1 = __importDefault(require("picocolors"));
11
+ const prettier_1 = __importDefault(require("prettier"));
12
+ const common_1 = require("./common");
13
+ const getPackageManager_1 = require("./helpers/getPackageManager");
14
+ const git_1 = require("./helpers/git");
15
+ const basic_1 = require("./templates/basic");
16
+ const etherscan_1 = require("./templates/etherscan");
17
+ const subgraphId_1 = require("./templates/subgraphId");
18
+ const subgraphRepo_1 = require("./templates/subgraphRepo");
19
+ const run = async (options, overrides = {}) => {
20
+ const { rootDir } = options;
21
+ // Create required directories.
22
+ (0, node_fs_1.mkdirSync)(node_path_1.default.join(rootDir, "abis"), { recursive: true });
23
+ (0, node_fs_1.mkdirSync)(node_path_1.default.join(rootDir, "src"), { recursive: true });
24
+ let config;
25
+ console.log(`\nCreating a new Ponder app in ${picocolors_1.default.bold(picocolors_1.default.green(rootDir))}.`);
26
+ switch (options.template?.kind) {
27
+ case common_1.TemplateKind.ETHERSCAN: {
28
+ console.log(`\nUsing ${picocolors_1.default.cyan("Etherscan contract link")} template.`);
29
+ config = await (0, etherscan_1.fromEtherscan)({
30
+ rootDir,
31
+ etherscanLink: options.template.link,
32
+ etherscanApiKey: options.etherscanApiKey,
33
+ });
34
+ break;
35
+ }
36
+ case common_1.TemplateKind.SUBGRAPH_ID: {
37
+ console.log(`\nUsing ${picocolors_1.default.cyan("Subgraph ID")} template.`);
38
+ config = await (0, subgraphId_1.fromSubgraphId)({
39
+ rootDir,
40
+ subgraphId: options.template.id,
41
+ });
42
+ break;
43
+ }
44
+ case common_1.TemplateKind.SUBGRAPH_REPO: {
45
+ console.log(`\nUsing ${picocolors_1.default.cyan("Subgraph repository")} template.`);
46
+ config = (0, subgraphRepo_1.fromSubgraphRepo)({
47
+ rootDir,
48
+ subgraphPath: options.template.path,
49
+ });
50
+ break;
51
+ }
52
+ default: {
53
+ config = (0, basic_1.fromBasic)({ rootDir });
54
+ break;
55
+ }
56
+ }
57
+ // Write the handler ts files.
58
+ config.contracts.forEach((contract) => {
59
+ let abi;
60
+ if (Array.isArray(contract.abi)) {
61
+ // If it's an array of ABIs, use the 2nd one (the implementation ABI).
62
+ const abiString = (0, node_fs_1.readFileSync)(node_path_1.default.join(rootDir, contract.abi[1]), {
63
+ encoding: "utf-8",
64
+ });
65
+ abi = JSON.parse(abiString);
66
+ }
67
+ else {
68
+ const abiString = (0, node_fs_1.readFileSync)(node_path_1.default.join(rootDir, contract.abi), {
69
+ encoding: "utf-8",
70
+ });
71
+ abi = JSON.parse(abiString);
72
+ }
73
+ const abiEvents = abi.filter((item) => item.type === "event");
74
+ const eventNamesToWrite = abiEvents.map((event) => event.name).slice(0, 2);
75
+ const handlerFileContents = `
76
+ import { ponder } from '@/generated'
77
+
78
+ ${eventNamesToWrite
79
+ .map((eventName) => `
80
+ ponder.on("${contract.name}:${eventName}", async ({ event, context }) => {
81
+ console.log(event.params)
82
+ })`)
83
+ .join("\n")}
84
+ `;
85
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, `./src/${contract.name}.ts`), prettier_1.default.format(handlerFileContents, { parser: "typescript" }));
86
+ });
87
+ // Write the ponder.config.ts file.
88
+ const finalConfig = `
89
+ import type { Config } from "@ponder/core";
90
+
91
+ export const config: Config = {
92
+ networks: ${JSON.stringify(config.networks).replaceAll(/"process.env.PONDER_RPC_URL_(.*?)"/g, "process.env.PONDER_RPC_URL_$1")},
93
+ contracts: ${JSON.stringify(config.contracts)},
94
+ };
95
+ `;
96
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "ponder.config.ts"), prettier_1.default.format(finalConfig, { parser: "babel" }));
97
+ // Write the .env.local file.
98
+ const uniqueChainIds = Array.from(new Set(config.networks.map((n) => n.chainId)));
99
+ const envLocal = `${uniqueChainIds.map((chainId) => `PONDER_RPC_URL_${chainId}=""\n`)}`;
100
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, ".env.local"), envLocal);
101
+ // Write the package.json file.
102
+ const packageJson = `
103
+ {
104
+ "private": true,
105
+ "scripts": {
106
+ "dev": "ponder dev",
107
+ "start": "ponder start",
108
+ "codegen": "ponder codegen"
109
+ },
110
+ "dependencies": {
111
+ "@ponder/core": "latest"
112
+ },
113
+ "devDependencies": {
114
+ "@types/node": "^18.11.18",
115
+ "abitype": "^0.8.11",
116
+ "typescript": "^5.1.3",
117
+ "viem": "^1.2.6"
118
+ }
119
+ }
120
+ `;
121
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "package.json"), prettier_1.default.format(packageJson, { parser: "json" }));
122
+ // Write the tsconfig.json file.
123
+ const tsConfig = `
124
+ {
125
+ "compilerOptions": {
126
+ "target": "ESNext",
127
+ "module": "ESNext",
128
+ "moduleResolution": "node",
129
+ "resolveJsonModule": true,
130
+ "esModuleInterop": true,
131
+ "strict": true,
132
+ "rootDir": ".",
133
+ "paths": {
134
+ "@/generated": ["./generated/index.ts"]
135
+ }
136
+ },
137
+ "include": ["./**/*.ts"],
138
+ "exclude": ["node_modules"]
139
+ }
140
+ `;
141
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "tsconfig.json"), prettier_1.default.format(tsConfig, { parser: "json" }));
142
+ // Write the .gitignore file.
143
+ (0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, ".gitignore"), `node_modules/\n.DS_Store\n\n.env.local\n.ponder/\ngenerated/`);
144
+ const packageManager = await (0, getPackageManager_1.getPackageManager)();
145
+ // Install packages.
146
+ console.log(picocolors_1.default.bold(`\nInstalling with ${packageManager}.`));
147
+ const installCommand = overrides.installCommand
148
+ ? overrides.installCommand
149
+ : `${packageManager} ${packageManager === "npm" ? "--quiet" : "--silent"} install`;
150
+ (0, node_child_process_1.execSync)(installCommand, {
151
+ cwd: rootDir,
152
+ stdio: "inherit",
153
+ });
154
+ // Intialize git repository
155
+ process.chdir(rootDir);
156
+ (0, git_1.tryGitInit)(rootDir);
157
+ console.log(`\nInitialized a git repository.`);
158
+ // Run codegen.
159
+ const runCommand = `${packageManager === "npm" ? `npm --quiet run` : `${packageManager} --silent`} codegen`;
160
+ (0, node_child_process_1.execSync)(runCommand, {
161
+ cwd: rootDir,
162
+ stdio: "inherit",
163
+ });
164
+ console.log(`\nGenerated types.`);
165
+ console.log(picocolors_1.default.green("\nSuccess! ") + `Created ${options.projectName} at ${rootDir}`);
166
+ };
167
+ exports.run = run;
168
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AACA,2DAA8C;AAC9C,qCAAiE;AACjE,0DAA6B;AAC7B,4DAA8B;AAC9B,wDAAgC;AAEhC,qCAA6D;AAC7D,mEAAgE;AAChE,uCAA2C;AAC3C,6CAA8C;AAC9C,qDAAsD;AACtD,uDAAwD;AACxD,2DAA4D;AAwBrD,MAAM,GAAG,GAAG,KAAK,EACtB,OAA4B,EAC5B,YAAyC,EAAE,EAC3C,EAAE;IACF,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAE5B,+BAA+B;IAC/B,IAAA,mBAAS,EAAC,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,IAAA,mBAAS,EAAC,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE1D,IAAI,MAAqB,CAAC;IAE1B,OAAO,CAAC,GAAG,CACT,kCAAkC,oBAAI,CAAC,IAAI,CAAC,oBAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CACpE,CAAC;IAEF,QAAQ,OAAO,CAAC,QAAQ,EAAE,IAAI,EAAE;QAC9B,KAAK,qBAAY,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F,MAAM,cAAc,GAAG,MAAM,IAAA,qCAAiB,GAAE,CAAC;IAEjD,oBAAoB;IACpB,OAAO,CAAC,GAAG,CAAC,oBAAI,CAAC,IAAI,CAAC,qBAAqB,cAAc,GAAG,CAAC,CAAC,CAAC;IAE/D,MAAM,cAAc,GAAG,SAAS,CAAC,cAAc;QAC7C,CAAC,CAAC,SAAS,CAAC,cAAc;QAC1B,CAAC,CAAC,GAAG,cAAc,IACf,cAAc,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UACzC,UAAU,CAAC;IAEf,IAAA,6BAAQ,EAAC,cAAc,EAAE;QACvB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IAEH,2BAA2B;IAC3B,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACvB,IAAA,gBAAU,EAAC,OAAO,CAAC,CAAC;IACpB,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IAE/C,eAAe;IACf,MAAM,UAAU,GAAG,GACjB,cAAc,KAAK,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,GAAG,cAAc,WAClE,UAAU,CAAC;IACX,IAAA,6BAAQ,EAAC,UAAU,EAAE;QACnB,GAAG,EAAE,OAAO;QACZ,KAAK,EAAE,SAAS;KACjB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC;IAElC,OAAO,CAAC,GAAG,CACT,oBAAI,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,WAAW,OAAO,CAAC,WAAW,OAAO,OAAO,EAAE,CAC3E,CAAC;AACJ,CAAC,CAAC;AA9MW,QAAA,GAAG,OA8Md"}
@@ -0,0 +1,5 @@
1
+ import type { PartialConfig } from "../index";
2
+ export declare const fromBasic: ({ rootDir }: {
3
+ rootDir: string;
4
+ }) => PartialConfig;
5
+ //# sourceMappingURL=basic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../src/templates/basic.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAE7C,eAAO,MAAM,SAAS;aAA4B,MAAM;mBAqDvD,CAAC"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fromBasic = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const prettier_1 = __importDefault(require("prettier"));
10
+ const fromBasic = ({ rootDir }) => {
11
+ const abiFileContents = `[]`;
12
+ const abiRelativePath = "./abis/ExampleContract.json";
13
+ const abiAbsolutePath = node_path_1.default.join(rootDir, abiRelativePath);
14
+ (0, node_fs_1.writeFileSync)(abiAbsolutePath, abiFileContents);
15
+ const schemaGraphqlFileContents = `
16
+ # The entity types defined below map to database tables.
17
+ # The functions you write as event handlers inside the \`src/\` directory are responsible for creating and updating records in those tables.
18
+ # Your schema will be more flexible and powerful if it accurately models the logical relationships in your application's domain.
19
+ # Visit the [documentation](https://ponder.sh/guides/design-your-schema) or the [\`examples/\`](https://github.com/0xOlias/ponder/tree/main/examples) directory for further guidance on designing your schema.
20
+
21
+ type ExampleToken @entity {
22
+ id: String!
23
+ tokenId: Int!
24
+ trait: TokenTrait!
25
+ }
26
+
27
+ enum TokenTrait {
28
+ GOOD
29
+ BAD
30
+ }
31
+ `;
32
+ // Generate the schema.graphql file.
33
+ const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
34
+ (0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaGraphqlFileContents, { parser: "graphql" }));
35
+ // Build the partial ponder config.
36
+ const config = {
37
+ networks: [
38
+ {
39
+ name: "mainnet",
40
+ chainId: 1,
41
+ rpcUrl: `process.env.PONDER_RPC_URL_1`,
42
+ },
43
+ ],
44
+ contracts: [
45
+ {
46
+ name: "ExampleContract",
47
+ network: "mainnet",
48
+ address: "0x0",
49
+ abi: abiRelativePath,
50
+ startBlock: 1234567,
51
+ },
52
+ ],
53
+ };
54
+ return config;
55
+ };
56
+ exports.fromBasic = fromBasic;
57
+ //# sourceMappingURL=basic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basic.js","sourceRoot":"","sources":["../../src/templates/basic.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAwC;AACxC,0DAA6B;AAC7B,wDAAgC;AAIzB,MAAM,SAAS,GAAG,CAAC,EAAE,OAAO,EAAuB,EAAE,EAAE;IAC5D,MAAM,eAAe,GAAG,IAAI,CAAC;IAE7B,MAAM,eAAe,GAAG,6BAA6B,CAAC;IACtD,MAAM,eAAe,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAC5D,IAAA,uBAAa,EAAC,eAAe,EAAE,eAAe,CAAC,CAAC;IAEhD,MAAM,yBAAyB,GAAG;;;;;;;;;;;;;;;;CAgBnC,CAAC;IAEA,oCAAoC;IACpC,MAAM,oBAAoB,GAAG,mBAAI,CAAC,IAAI,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;IAClE,IAAA,uBAAa,EACX,oBAAoB,EACpB,kBAAQ,CAAC,MAAM,CAAC,yBAAyB,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAClE,CAAC;IAEF,mCAAmC;IACnC,MAAM,MAAM,GAAkB;QAC5B,QAAQ,EAAE;YACR;gBACE,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,CAAC;gBACV,MAAM,EAAE,8BAA8B;aACvC;SACF;QACD,SAAS,EAAE;YACT;gBACE,IAAI,EAAE,iBAAiB;gBACvB,OAAO,EAAE,SAAS;gBAClB,OAAO,EAAE,KAAK;gBACd,GAAG,EAAE,eAAe;gBACpB,UAAU,EAAE,OAAO;aACpB;SACF;KACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AArDW,QAAA,SAAS,aAqDpB"}
@@ -0,0 +1,7 @@
1
+ import type { PartialConfig } from "src/index";
2
+ export declare const fromEtherscan: ({ rootDir, etherscanLink, etherscanApiKey, }: {
3
+ rootDir: string;
4
+ etherscanLink: string;
5
+ etherscanApiKey?: string | undefined;
6
+ }) => Promise<PartialConfig>;
7
+ //# sourceMappingURL=etherscan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"etherscan.d.ts","sourceRoot":"","sources":["../../src/templates/etherscan.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAK/C,eAAO,MAAM,aAAa;aAKf,MAAM;mBACA,MAAM;;4BAkJtB,CAAC"}
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fromEtherscan = void 0;
7
+ /* eslint-disable @typescript-eslint/ban-ts-comment */
8
+ const node_fs_1 = require("node:fs");
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const node_fetch_1 = __importDefault(require("node-fetch"));
11
+ const prettier_1 = __importDefault(require("prettier"));
12
+ const getEtherscanChainId_1 = require("../helpers/getEtherscanChainId");
13
+ const wait_1 = require("../helpers/wait");
14
+ const fromEtherscan = async ({ rootDir, etherscanLink, etherscanApiKey, }) => {
15
+ const apiKey = etherscanApiKey || process.env.ETHERSCAN_API_KEY;
16
+ const url = new URL(etherscanLink);
17
+ const network = (0, getEtherscanChainId_1.getNetworkByEtherscanHostname)(url.hostname);
18
+ if (!network) {
19
+ throw new Error(`Unrecognized etherscan hostname: ${url.hostname}`);
20
+ }
21
+ const { name, chainId, apiUrl } = network;
22
+ const contractAddress = url.pathname.slice(1).split("/")[1];
23
+ let blockNumber = undefined;
24
+ try {
25
+ const txHash = await getContractCreationTxn(contractAddress, apiUrl, apiKey);
26
+ if (!apiKey) {
27
+ console.log("\n(1/n) Waiting 5 seconds for Etherscan API rate limit");
28
+ await (0, wait_1.wait)(5000);
29
+ }
30
+ const contractCreationBlockNumber = await getTxBlockNumber(txHash, apiUrl, apiKey);
31
+ blockNumber = contractCreationBlockNumber;
32
+ }
33
+ catch (error) {
34
+ // Do nothing, blockNumber won't be set.
35
+ }
36
+ if (!apiKey) {
37
+ console.log("(2/n) Waiting 5 seconds for Etherscan API rate limit");
38
+ await (0, wait_1.wait)(5000);
39
+ }
40
+ const abis = [];
41
+ const { abi, contractName } = await getContractAbiAndName(contractAddress, apiUrl, apiKey);
42
+ abis.push({ abi, contractName });
43
+ // If the contract is an EIP-1967 proxy, get the implementation contract ABIs.
44
+ if (JSON.parse(abi).find((item) => item.type === "event" &&
45
+ item.name === "Upgraded" &&
46
+ item.inputs[0].name === "implementation")) {
47
+ console.log("Detected EIP-1967 proxy, fetching implementation contract ABIs");
48
+ if (!apiKey) {
49
+ console.log("(3/n) Waiting 5 seconds for Etherscan API rate limit");
50
+ await (0, wait_1.wait)(5000);
51
+ }
52
+ const { implAddresses } = await getProxyImplementationAddresses({
53
+ contractAddress,
54
+ apiUrl,
55
+ fromBlock: blockNumber,
56
+ apiKey,
57
+ });
58
+ for (const [index, implAddress] of implAddresses.entries()) {
59
+ console.log(`Fetching ABI for implementation contract: ${implAddress}`);
60
+ if (!apiKey) {
61
+ console.log(`(${4 + index}/${4 + implAddresses.length - 1}) Waiting 5 seconds for Etherscan API rate limit`);
62
+ await (0, wait_1.wait)(5000);
63
+ }
64
+ const { abi, contractName } = await getContractAbiAndName(implAddress, apiUrl, apiKey);
65
+ abis.push({
66
+ abi,
67
+ contractName: `${contractName}_${implAddress.slice(0, 6)}`,
68
+ });
69
+ }
70
+ }
71
+ // Write ABI files.
72
+ let abiConfig;
73
+ abis.forEach(({ abi, contractName }) => {
74
+ const abiRelativePath = `./abis/${contractName}.json`;
75
+ const abiAbsolutePath = node_path_1.default.join(rootDir, abiRelativePath);
76
+ (0, node_fs_1.writeFileSync)(abiAbsolutePath, prettier_1.default.format(abi, { parser: "json" }));
77
+ if (abis.length === 1) {
78
+ abiConfig = abiRelativePath;
79
+ }
80
+ else {
81
+ abiConfig ||= [];
82
+ abiConfig.push(abiRelativePath);
83
+ }
84
+ });
85
+ const schemaGraphqlFileContents = `
86
+ type ExampleEntity @entity {
87
+ id: String!
88
+ name: String!
89
+ }
90
+ `;
91
+ // Generate the schema.graphql file.
92
+ const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
93
+ (0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaGraphqlFileContents, { parser: "graphql" }));
94
+ // Build and return the partial ponder config.
95
+ const config = {
96
+ networks: [
97
+ {
98
+ name: name,
99
+ chainId: chainId,
100
+ rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
101
+ },
102
+ ],
103
+ contracts: [
104
+ {
105
+ name: contractName,
106
+ network: name,
107
+ abi: abiConfig,
108
+ address: contractAddress,
109
+ startBlock: blockNumber ?? undefined,
110
+ },
111
+ ],
112
+ };
113
+ return config;
114
+ };
115
+ exports.fromEtherscan = fromEtherscan;
116
+ const fetchEtherscan = async (url) => {
117
+ const maxRetries = 5;
118
+ let retryCount = 0;
119
+ while (retryCount <= maxRetries) {
120
+ try {
121
+ const response = await (0, node_fetch_1.default)(url);
122
+ const data = await response.json();
123
+ if (data.status === "0") {
124
+ throw new Error(`Etherscan API error: ${data.result}`);
125
+ }
126
+ return data;
127
+ }
128
+ catch (error) {
129
+ retryCount++;
130
+ if (retryCount > maxRetries) {
131
+ throw new Error(`Max retries reached: ${error.message}`);
132
+ }
133
+ await new Promise((resolve) => setTimeout(resolve, 100));
134
+ }
135
+ }
136
+ };
137
+ const getContractCreationTxn = async (contractAddress, apiUrl, apiKey) => {
138
+ const searchParams = new URLSearchParams({
139
+ module: "contract",
140
+ action: "getcontractcreation",
141
+ contractaddresses: contractAddress,
142
+ });
143
+ if (apiKey)
144
+ searchParams.append("apikey", apiKey);
145
+ const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
146
+ return data.result[0].txHash;
147
+ };
148
+ const getTxBlockNumber = async (txHash, apiUrl, apiKey) => {
149
+ const searchParams = new URLSearchParams({
150
+ module: "proxy",
151
+ action: "eth_getTransactionByHash",
152
+ txhash: txHash,
153
+ });
154
+ if (apiKey)
155
+ searchParams.append("apikey", apiKey);
156
+ const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
157
+ const hexBlockNumber = data.result.blockNumber;
158
+ return parseInt(hexBlockNumber.slice(2), 16);
159
+ };
160
+ const getContractAbiAndName = async (contractAddress, apiUrl, apiKey) => {
161
+ const searchParams = new URLSearchParams({
162
+ module: "contract",
163
+ action: "getsourcecode",
164
+ address: contractAddress,
165
+ });
166
+ if (apiKey)
167
+ searchParams.append("apikey", apiKey);
168
+ const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
169
+ const abi = data.result[0].ABI;
170
+ const contractName = data.result[0].ContractName;
171
+ return { abi, contractName };
172
+ };
173
+ const getProxyImplementationAddresses = async ({ contractAddress, apiUrl, fromBlock, apiKey, }) => {
174
+ const searchParams = new URLSearchParams({
175
+ module: "logs",
176
+ action: "getLogs",
177
+ address: contractAddress,
178
+ fromBlock: fromBlock ? String(fromBlock) : "0",
179
+ toBlock: "latest",
180
+ topic0: "0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b",
181
+ });
182
+ if (apiKey)
183
+ searchParams.append("apikey", apiKey);
184
+ const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
185
+ const logs = data.result;
186
+ const implAddresses = logs.map((log) => {
187
+ if (log.topics[0] && log.topics[1]) {
188
+ // If there are two topics, this is a compliant EIP-1967 proxy and the address is indexed.
189
+ return `0x${log.topics[1].slice(26)}`;
190
+ }
191
+ else {
192
+ // If there's only one topic, this might be a non-compliant proxy and the address is not indexed.
193
+ // USDC is an example of this: https://etherscan.io/address/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48#code#L118
194
+ return `0x${log.data.slice(26)}`;
195
+ }
196
+ });
197
+ return { implAddresses };
198
+ };
199
+ //# sourceMappingURL=etherscan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"etherscan.js","sourceRoot":"","sources":["../../src/templates/etherscan.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAsD;AACtD,qCAAwC;AACxC,0DAA6B;AAC7B,4DAA+B;AAC/B,wDAAgC;AAGhC,uEAA8E;AAC9E,yCAAsC;AAE/B,MAAM,aAAa,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,aAAa,EACb,eAAe,GAKhB,EAAE,EAAE;IACH,MAAM,MAAM,GAAG,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC;IAEhE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,aAAa,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,IAAA,mDAA6B,EAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC5D,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,oCAAoC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;KACrE;IAED,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAC1C,MAAM,eAAe,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IAE5D,IAAI,WAAW,GAAuB,SAAS,CAAC;IAEhD,IAAI;QACF,MAAM,MAAM,GAAG,MAAM,sBAAsB,CACzC,eAAe,EACf,MAAM,EACN,MAAM,CACP,CAAC;QAEF,IAAI,CAAC,MAAM,EAAE;YACX,OAAO,CAAC,GAAG,CAAC,w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AAC,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE;YAClC,0FAA0F;YAC1F,OAAO,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;SACvC;aAAM;YACL,iGAAiG;YACjG,gHAAgH;YAChH,OAAO,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,CAAC;SAClC;IACH,CAAC,CAAa,CAAC;IAEf,OAAO,EAAE,aAAa,EAAE,CAAC;AAC3B,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { PartialConfig } from "src/index";
2
+ export declare const fromSubgraphId: ({ rootDir, subgraphId, }: {
3
+ rootDir: string;
4
+ subgraphId: string;
5
+ }) => Promise<PartialConfig>;
6
+ //# sourceMappingURL=subgraphId.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraphId.d.ts","sourceRoot":"","sources":["../../src/templates/subgraphId.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,WAAW,CAAC;AAalE,eAAO,MAAM,cAAc;aAIhB,MAAM;gBACH,MAAM;4BA0EnB,CAAC"}
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.fromSubgraphId = void 0;
7
+ const node_fs_1 = require("node:fs");
8
+ const node_path_1 = __importDefault(require("node:path"));
9
+ const node_fetch_1 = __importDefault(require("node-fetch"));
10
+ const prettier_1 = __importDefault(require("prettier"));
11
+ const yaml_1 = require("yaml");
12
+ const getGraphProtocolChainId_1 = require("../helpers/getGraphProtocolChainId");
13
+ const validateGraphProtocolSource_1 = require("../helpers/validateGraphProtocolSource");
14
+ const fetchIpfsFile = async (cid) => {
15
+ const url = `https://ipfs.network.thegraph.com/api/v0/cat?arg=${cid}`;
16
+ const response = await (0, node_fetch_1.default)(url);
17
+ const contentRaw = await response.text();
18
+ return contentRaw;
19
+ };
20
+ const fromSubgraphId = async ({ rootDir, subgraphId, }) => {
21
+ const ponderNetworks = [];
22
+ let ponderContracts = [];
23
+ // Fetch the manifest file.
24
+ const manifestRaw = await fetchIpfsFile(subgraphId);
25
+ const manifest = (0, yaml_1.parse)(manifestRaw);
26
+ // Fetch and write the schema.graphql file.
27
+ const schemaCid = manifest.schema.file["/"].slice(6);
28
+ const schemaRaw = await fetchIpfsFile(schemaCid);
29
+ const schemaCleaned = schemaRaw
30
+ .replaceAll(": ID!", ": String!")
31
+ .replaceAll("BigDecimal", "Float");
32
+ const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
33
+ (0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaCleaned, { parser: "graphql" }));
34
+ const dataSources = manifest.dataSources.map(validateGraphProtocolSource_1.validateGraphProtocolSource);
35
+ // Fetch and write all referenced ABIs.
36
+ const abiFiles = dataSources
37
+ .map((source) => source.mapping.abis)
38
+ .flat()
39
+ .filter((source, idx, arr) => arr.findIndex((s) => s.name === source.name) === idx);
40
+ await Promise.all(abiFiles.map(async (abi) => {
41
+ const abiContent = await fetchIpfsFile(abi.file["/"].slice(6));
42
+ const abiPath = node_path_1.default.join(rootDir, `./abis/${abi.name}.json`);
43
+ (0, node_fs_1.writeFileSync)(abiPath, prettier_1.default.format(abiContent, { parser: "json" }));
44
+ }));
45
+ // Build the ponder sources.
46
+ ponderContracts = dataSources.map((source) => {
47
+ const network = source.network || "mainnet";
48
+ const chainId = (0, getGraphProtocolChainId_1.getGraphProtocolChainId)(network);
49
+ if (!chainId || chainId === -1) {
50
+ throw new Error(`Unhandled network name: ${network}`);
51
+ }
52
+ if (!ponderNetworks.map((n) => n.name).includes(network)) {
53
+ ponderNetworks.push({
54
+ name: network,
55
+ chainId: chainId,
56
+ rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
57
+ });
58
+ }
59
+ const abiRelativePath = `./abis/${source.source.abi}.json`;
60
+ return {
61
+ name: source.name,
62
+ network: network,
63
+ address: source.source.address,
64
+ abi: abiRelativePath,
65
+ startBlock: source.source.startBlock,
66
+ };
67
+ });
68
+ // Build the partial ponder config.
69
+ const config = {
70
+ networks: ponderNetworks,
71
+ contracts: ponderContracts,
72
+ };
73
+ return config;
74
+ };
75
+ exports.fromSubgraphId = fromSubgraphId;
76
+ //# sourceMappingURL=subgraphId.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraphId.js","sourceRoot":"","sources":["../../src/templates/subgraphId.ts"],"names":[],"mappings":";;;;;;AAAA,qCAAwC;AACxC,0DAA6B;AAC7B,4DAA+B;AAC/B,wDAAgC;AAEhC,+BAA6B;AAE7B,+EAA4E;AAC5E,uFAAoF;AAEpF,MAAM,aAAa,GAAG,KAAK,EAAE,GAAW,EAAE,EAAE;IAC1C,MAAM,GAAG,GAAG,oDAAoD,GAAG,EAAE,CAAC;IACtE,MAAM,QAAQ,GAAG,MAAM,IAAA,oBAAK,EAAC,GAAG,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACzC,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEK,MAAM,cAAc,GAAG,KAAK,EAAE,EACnC,OAAO,EACP,UAAU,GAIX,EAAE,EAAE;IACH,MAAM,cAAc,GAAc,EAAE,CAAC;IACrC,IAAI,eAAe,GAAe,EAAE,CAAC;IAErC,2BAA2B;IAC3B,MAAM,WAAW,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,QAAQ,GAAG,IAAA,YAAK,EAAC,WAAW,CAAC,CAAC;IAEpC,2CAA2C;IAC3C,MAAM,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC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epo: ({ rootDir, subgraphPath, }: {
3
+ rootDir: string;
4
+ subgraphPath: string;
5
+ }) => PartialConfig;
6
+ //# sourceMappingURL=subgraphRepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subgraphRepo.d.ts","sourceRoot":"","sources":["../../src/templates/subgraphRepo.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAqB,aAAa,EAAE,MAAM,SAAS,CAAC;AAEhE,eAAO,MAAM,gBAAgB;aAIlB,MAAM;kBACD,MAAM;mBAkGrB,CAAC"}