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.
- package/LICENSE +1 -1
- package/dist/bin/create-ponder.d.ts +3 -0
- package/dist/bin/create-ponder.d.ts.map +1 -0
- package/dist/bin/create-ponder.js +105 -0
- package/dist/bin/create-ponder.js.map +1 -0
- package/dist/common.d.ts +23 -0
- package/dist/common.d.ts.map +1 -0
- package/dist/common.js +11 -0
- package/dist/common.js.map +1 -0
- package/dist/helpers/getEtherscanChainId.d.ts +6 -0
- package/dist/helpers/getEtherscanChainId.d.ts.map +1 -0
- package/dist/helpers/getEtherscanChainId.js +75 -0
- package/dist/helpers/getEtherscanChainId.js.map +1 -0
- package/dist/helpers/getGraphProtocolChainId.d.ts +3 -0
- package/dist/helpers/getGraphProtocolChainId.d.ts.map +1 -0
- package/dist/helpers/getGraphProtocolChainId.js +42 -0
- package/dist/helpers/getGraphProtocolChainId.js.map +1 -0
- package/dist/helpers/getPackageManager.d.ts +2 -0
- package/dist/helpers/getPackageManager.d.ts.map +1 -0
- package/dist/helpers/getPackageManager.js +18 -0
- package/dist/helpers/getPackageManager.js.map +1 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.d.ts.map +1 -0
- package/dist/helpers/git.js +56 -0
- package/dist/helpers/git.js.map +1 -0
- package/dist/helpers/validateGraphProtocolSource.d.ts +28 -0
- package/dist/helpers/validateGraphProtocolSource.d.ts.map +1 -0
- package/dist/helpers/validateGraphProtocolSource.js +8 -0
- package/dist/helpers/validateGraphProtocolSource.js.map +1 -0
- package/dist/helpers/wait.d.ts +2 -0
- package/dist/helpers/wait.d.ts.map +1 -0
- package/dist/helpers/wait.js +6 -0
- package/dist/helpers/wait.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +168 -0
- package/dist/index.js.map +1 -0
- package/dist/templates/basic.d.ts +5 -0
- package/dist/templates/basic.d.ts.map +1 -0
- package/dist/templates/basic.js +57 -0
- package/dist/templates/basic.js.map +1 -0
- package/dist/templates/etherscan.d.ts +7 -0
- package/dist/templates/etherscan.d.ts.map +1 -0
- package/dist/templates/etherscan.js +199 -0
- package/dist/templates/etherscan.js.map +1 -0
- package/dist/templates/subgraphId.d.ts +6 -0
- package/dist/templates/subgraphId.d.ts.map +1 -0
- package/dist/templates/subgraphId.js +76 -0
- package/dist/templates/subgraphId.js.map +1 -0
- package/dist/templates/subgraphRepo.d.ts +6 -0
- package/dist/templates/subgraphRepo.d.ts.map +1 -0
- package/dist/templates/subgraphRepo.js +86 -0
- package/dist/templates/subgraphRepo.js.map +1 -0
- package/package.json +15 -11
- package/src/bin/create-ponder.ts +127 -0
- package/src/common.ts +27 -0
- package/src/helpers/getEtherscanChainId.ts +74 -0
- package/src/helpers/getGraphProtocolChainId.ts +41 -0
- package/src/helpers/getPackageManager.ts +11 -0
- package/src/helpers/git.ts +51 -0
- package/src/helpers/validateGraphProtocolSource.ts +42 -0
- package/src/helpers/wait.ts +2 -0
- package/src/index.ts +244 -0
- package/src/templates/basic.ts +60 -0
- package/src/templates/etherscan.ts +276 -0
- package/src/templates/subgraphId.ts +97 -0
- package/src/templates/subgraphRepo.ts +116 -0
- package/dist/create-ponder.d.ts +0 -1
- package/dist/create-ponder.js +0 -937
- package/dist/create-ponder.js.map +0 -1
- package/dist/create-ponder.mjs +0 -914
- package/dist/create-ponder.mjs.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { copyFileSync, readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import prettier from "prettier";
|
|
4
|
+
import { parse } from "yaml";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
getGraphProtocolChainId,
|
|
8
|
+
subgraphYamlFileNames,
|
|
9
|
+
} from "@/helpers/getGraphProtocolChainId";
|
|
10
|
+
import { validateGraphProtocolSource } from "@/helpers/validateGraphProtocolSource";
|
|
11
|
+
import type { Contract, Network, PartialConfig } from "@/index";
|
|
12
|
+
|
|
13
|
+
export const fromSubgraphRepo = ({
|
|
14
|
+
rootDir,
|
|
15
|
+
subgraphPath,
|
|
16
|
+
}: {
|
|
17
|
+
rootDir: string;
|
|
18
|
+
subgraphPath: string;
|
|
19
|
+
}) => {
|
|
20
|
+
const subgraphRootDir = path.resolve(subgraphPath);
|
|
21
|
+
|
|
22
|
+
const ponderNetworks: Network[] = [];
|
|
23
|
+
let ponderContracts: Contract[] = [];
|
|
24
|
+
|
|
25
|
+
// If the `--from-subgraph` option was passed, parse subgraph files
|
|
26
|
+
const subgraphRootDirPath = path.resolve(subgraphRootDir);
|
|
27
|
+
|
|
28
|
+
// Read and parse the subgraph YAML file.
|
|
29
|
+
let subgraphYamlRaw = "";
|
|
30
|
+
|
|
31
|
+
for (const subgraphYamlFileName of subgraphYamlFileNames) {
|
|
32
|
+
try {
|
|
33
|
+
subgraphYamlRaw = readFileSync(
|
|
34
|
+
path.join(subgraphRootDirPath, subgraphYamlFileName),
|
|
35
|
+
{
|
|
36
|
+
encoding: "utf-8",
|
|
37
|
+
}
|
|
38
|
+
);
|
|
39
|
+
break;
|
|
40
|
+
} catch (e) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (subgraphYamlRaw === "") {
|
|
46
|
+
throw new Error(`subgraph.yaml file not found`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const subgraphYaml = parse(subgraphYamlRaw);
|
|
50
|
+
|
|
51
|
+
// Copy over the schema.graphql file.
|
|
52
|
+
const schemaRaw = readFileSync(
|
|
53
|
+
path.join(subgraphRootDirPath, subgraphYaml.schema.file),
|
|
54
|
+
{
|
|
55
|
+
encoding: "utf-8",
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
const schemaCleaned = schemaRaw
|
|
59
|
+
.replaceAll(": ID!", ": String!")
|
|
60
|
+
.replaceAll("BigDecimal", "Float");
|
|
61
|
+
writeFileSync(
|
|
62
|
+
path.join(rootDir, "schema.graphql"),
|
|
63
|
+
prettier.format(schemaCleaned, { parser: "graphql" })
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
// Build the ponder sources. Also copy over the ABI files for each source.
|
|
67
|
+
ponderContracts = (subgraphYaml.dataSources as unknown[])
|
|
68
|
+
.map(validateGraphProtocolSource)
|
|
69
|
+
.map((source) => {
|
|
70
|
+
const abiPath = source.mapping.abis.find(
|
|
71
|
+
(abi) => abi.name === source.name
|
|
72
|
+
)?.file;
|
|
73
|
+
if (!abiPath) {
|
|
74
|
+
throw new Error(`ABI path not found for source: ${source.name}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const network = source.network || "mainnet";
|
|
78
|
+
const chainId = getGraphProtocolChainId(network);
|
|
79
|
+
if (!chainId || chainId === -1) {
|
|
80
|
+
throw new Error(`Unhandled network name: ${network}`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (!ponderNetworks.map((n) => n.name).includes(network)) {
|
|
84
|
+
ponderNetworks.push({
|
|
85
|
+
name: network,
|
|
86
|
+
chainId: chainId,
|
|
87
|
+
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Copy the ABI file.
|
|
92
|
+
const abiAbsolutePath = path.join(subgraphRootDirPath, abiPath);
|
|
93
|
+
const abiFileName = path.basename(abiPath);
|
|
94
|
+
|
|
95
|
+
const ponderAbiRelativePath = `./abis/${abiFileName}`;
|
|
96
|
+
const ponderAbiAbsolutePath = path.join(rootDir, ponderAbiRelativePath);
|
|
97
|
+
|
|
98
|
+
copyFileSync(abiAbsolutePath, ponderAbiAbsolutePath);
|
|
99
|
+
|
|
100
|
+
return <Contract>{
|
|
101
|
+
name: source.name,
|
|
102
|
+
network: network,
|
|
103
|
+
address: source.source.address,
|
|
104
|
+
abi: ponderAbiRelativePath,
|
|
105
|
+
startBlock: source.source.startBlock,
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Build the partial ponder config.
|
|
110
|
+
const config: PartialConfig = {
|
|
111
|
+
networks: ponderNetworks,
|
|
112
|
+
contracts: ponderContracts,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
return config;
|
|
116
|
+
};
|
package/dist/create-ponder.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|