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
package/dist/create-ponder.mjs
DELETED
|
@@ -1,914 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/bin/create-ponder.ts
|
|
4
|
-
import { cac } from "cac";
|
|
5
|
-
import path7 from "node:path";
|
|
6
|
-
import prompts from "prompts";
|
|
7
|
-
|
|
8
|
-
// src/index.ts
|
|
9
|
-
import { execSync as execSync2 } from "node:child_process";
|
|
10
|
-
import { mkdirSync, readFileSync as readFileSync2, writeFileSync as writeFileSync5 } from "node:fs";
|
|
11
|
-
import path6 from "node:path";
|
|
12
|
-
import pico from "picocolors";
|
|
13
|
-
import prettier5 from "prettier";
|
|
14
|
-
|
|
15
|
-
// src/helpers/getPackageManager.ts
|
|
16
|
-
import { detect } from "detect-package-manager";
|
|
17
|
-
function getPackageManager() {
|
|
18
|
-
const userAgent = process.env.npm_config_user_agent;
|
|
19
|
-
if (userAgent) {
|
|
20
|
-
if (userAgent.includes("pnpm"))
|
|
21
|
-
return "pnpm";
|
|
22
|
-
if (userAgent.includes("npm"))
|
|
23
|
-
return "npm";
|
|
24
|
-
if (userAgent.includes("yarn"))
|
|
25
|
-
return "yarn";
|
|
26
|
-
}
|
|
27
|
-
return detect();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// src/helpers/git.ts
|
|
31
|
-
import { execSync } from "child_process";
|
|
32
|
-
import path from "path";
|
|
33
|
-
import rimraf from "rimraf";
|
|
34
|
-
function isInGitRepository() {
|
|
35
|
-
try {
|
|
36
|
-
execSync("git rev-parse --is-inside-work-tree", { stdio: "ignore" });
|
|
37
|
-
return true;
|
|
38
|
-
} catch (_) {
|
|
39
|
-
}
|
|
40
|
-
return false;
|
|
41
|
-
}
|
|
42
|
-
function isInMercurialRepository() {
|
|
43
|
-
try {
|
|
44
|
-
execSync("hg --cwd . root", { stdio: "ignore" });
|
|
45
|
-
return true;
|
|
46
|
-
} catch (_) {
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
function tryGitInit(root) {
|
|
51
|
-
let didInit = false;
|
|
52
|
-
try {
|
|
53
|
-
execSync("git --version", { stdio: "ignore" });
|
|
54
|
-
if (isInGitRepository() || isInMercurialRepository()) {
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
execSync("git init", { stdio: "ignore" });
|
|
58
|
-
didInit = true;
|
|
59
|
-
execSync("git checkout -b main", { stdio: "ignore" });
|
|
60
|
-
execSync("git add -A", { stdio: "ignore" });
|
|
61
|
-
execSync('git commit -m "chore: initial commit from create-ponder"', {
|
|
62
|
-
stdio: "ignore"
|
|
63
|
-
});
|
|
64
|
-
return true;
|
|
65
|
-
} catch (e) {
|
|
66
|
-
if (didInit) {
|
|
67
|
-
try {
|
|
68
|
-
rimraf.sync(path.join(root, ".git"));
|
|
69
|
-
} catch (_) {
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// src/templates/basic.ts
|
|
77
|
-
import { writeFileSync } from "node:fs";
|
|
78
|
-
import path2 from "node:path";
|
|
79
|
-
import prettier from "prettier";
|
|
80
|
-
var fromBasic = ({ rootDir }) => {
|
|
81
|
-
const abiFileContents = `[]`;
|
|
82
|
-
const abiRelativePath = "./abis/ExampleContract.json";
|
|
83
|
-
const abiAbsolutePath = path2.join(rootDir, abiRelativePath);
|
|
84
|
-
writeFileSync(abiAbsolutePath, abiFileContents);
|
|
85
|
-
const schemaGraphqlFileContents = `
|
|
86
|
-
# The entity types defined below map to database tables.
|
|
87
|
-
# The functions you write as event handlers inside the \`src/\` directory are responsible for creating and updating records in those tables.
|
|
88
|
-
# Your schema will be more flexible and powerful if it accurately models the logical relationships in your application's domain.
|
|
89
|
-
# 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.
|
|
90
|
-
|
|
91
|
-
type ExampleToken @entity {
|
|
92
|
-
id: String!
|
|
93
|
-
tokenId: Int!
|
|
94
|
-
trait: TokenTrait!
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
enum TokenTrait {
|
|
98
|
-
GOOD
|
|
99
|
-
BAD
|
|
100
|
-
}
|
|
101
|
-
`;
|
|
102
|
-
const ponderSchemaFilePath = path2.join(rootDir, "schema.graphql");
|
|
103
|
-
writeFileSync(
|
|
104
|
-
ponderSchemaFilePath,
|
|
105
|
-
prettier.format(schemaGraphqlFileContents, { parser: "graphql" })
|
|
106
|
-
);
|
|
107
|
-
const config = {
|
|
108
|
-
networks: [
|
|
109
|
-
{
|
|
110
|
-
name: "mainnet",
|
|
111
|
-
chainId: 1,
|
|
112
|
-
rpcUrl: `process.env.PONDER_RPC_URL_1`
|
|
113
|
-
}
|
|
114
|
-
],
|
|
115
|
-
contracts: [
|
|
116
|
-
{
|
|
117
|
-
name: "ExampleContract",
|
|
118
|
-
network: "mainnet",
|
|
119
|
-
address: "0x0",
|
|
120
|
-
abi: abiRelativePath,
|
|
121
|
-
startBlock: 1234567
|
|
122
|
-
}
|
|
123
|
-
]
|
|
124
|
-
};
|
|
125
|
-
return config;
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
// src/templates/etherscan.ts
|
|
129
|
-
import { writeFileSync as writeFileSync2 } from "node:fs";
|
|
130
|
-
import path3 from "node:path";
|
|
131
|
-
import fetch from "node-fetch";
|
|
132
|
-
import prettier2 from "prettier";
|
|
133
|
-
|
|
134
|
-
// src/helpers/getEtherscanChainId.ts
|
|
135
|
-
var networkByEtherscanHostname = {
|
|
136
|
-
"etherscan.io": {
|
|
137
|
-
name: "mainnet",
|
|
138
|
-
chainId: 1,
|
|
139
|
-
apiUrl: "https://api.etherscan.io/api"
|
|
140
|
-
},
|
|
141
|
-
"ropsten.etherscan.io": {
|
|
142
|
-
name: "ropsten",
|
|
143
|
-
chainId: 3,
|
|
144
|
-
apiUrl: "https://api-ropsten.etherscan.io/api"
|
|
145
|
-
},
|
|
146
|
-
"rinkeby.etherscan.io": {
|
|
147
|
-
name: "rinkeby",
|
|
148
|
-
chainId: 4,
|
|
149
|
-
apiUrl: "https://api-rinkeby.etherscan.io/api"
|
|
150
|
-
},
|
|
151
|
-
"goerli.etherscan.io": {
|
|
152
|
-
name: "goerli",
|
|
153
|
-
chainId: 5,
|
|
154
|
-
apiUrl: "https://api-goerli.etherscan.io/api"
|
|
155
|
-
},
|
|
156
|
-
"kovan.etherscan.io": {
|
|
157
|
-
name: "kovan",
|
|
158
|
-
chainId: 42,
|
|
159
|
-
apiUrl: "https://api-kovan.etherscan.io/api"
|
|
160
|
-
},
|
|
161
|
-
"sepolia.etherscan.io": {
|
|
162
|
-
name: "sepolia",
|
|
163
|
-
chainId: 11155111,
|
|
164
|
-
apiUrl: "https://api-sepolia.etherscan.io/api"
|
|
165
|
-
},
|
|
166
|
-
"optimistic.etherscan.io": {
|
|
167
|
-
name: "optimism",
|
|
168
|
-
chainId: 10,
|
|
169
|
-
apiUrl: "https://api-optimistic.etherscan.io/api"
|
|
170
|
-
},
|
|
171
|
-
"goerli-optimism.etherscan.io": {
|
|
172
|
-
name: "optimism-goerli",
|
|
173
|
-
chainId: 420,
|
|
174
|
-
apiUrl: "https://api-goerli-optimistic.etherscan.io/api"
|
|
175
|
-
},
|
|
176
|
-
"polygonscan.com": {
|
|
177
|
-
name: "polygon",
|
|
178
|
-
chainId: 137,
|
|
179
|
-
apiUrl: "https://api.polygonscan.com/api"
|
|
180
|
-
},
|
|
181
|
-
"mumbai.polygonscan.com": {
|
|
182
|
-
name: "polygon-mumbai",
|
|
183
|
-
chainId: 80001,
|
|
184
|
-
apiUrl: "https://api-testnet.polygonscan.com/api"
|
|
185
|
-
},
|
|
186
|
-
"arbiscan.io": {
|
|
187
|
-
name: "arbitrum",
|
|
188
|
-
chainId: 42161,
|
|
189
|
-
apiUrl: "https://api.arbiscan.io/api"
|
|
190
|
-
},
|
|
191
|
-
"goerli.arbiscan.io": {
|
|
192
|
-
name: "arbitrum-goerli",
|
|
193
|
-
chainId: 421613,
|
|
194
|
-
apiUrl: "https://api-goerli.arbiscan.io/api"
|
|
195
|
-
},
|
|
196
|
-
"explorer.zora.energy": {
|
|
197
|
-
name: "zora",
|
|
198
|
-
chainId: 7777777,
|
|
199
|
-
apiUrl: "https://explorer.zora.energy/api"
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
var getNetworkByEtherscanHostname = (hostname) => {
|
|
203
|
-
return networkByEtherscanHostname[hostname];
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
// src/helpers/wait.ts
|
|
207
|
-
var wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
208
|
-
|
|
209
|
-
// src/templates/etherscan.ts
|
|
210
|
-
var fromEtherscan = async ({
|
|
211
|
-
rootDir,
|
|
212
|
-
etherscanLink,
|
|
213
|
-
etherscanApiKey
|
|
214
|
-
}) => {
|
|
215
|
-
const apiKey = etherscanApiKey || process.env.ETHERSCAN_API_KEY;
|
|
216
|
-
const url = new URL(etherscanLink);
|
|
217
|
-
const network = getNetworkByEtherscanHostname(url.hostname);
|
|
218
|
-
if (!network) {
|
|
219
|
-
throw new Error(`Unrecognized etherscan hostname: ${url.hostname}`);
|
|
220
|
-
}
|
|
221
|
-
const { name, chainId, apiUrl } = network;
|
|
222
|
-
const contractAddress = url.pathname.slice(1).split("/")[1];
|
|
223
|
-
let blockNumber = void 0;
|
|
224
|
-
try {
|
|
225
|
-
const txHash = await getContractCreationTxn(
|
|
226
|
-
contractAddress,
|
|
227
|
-
apiUrl,
|
|
228
|
-
apiKey
|
|
229
|
-
);
|
|
230
|
-
if (!apiKey) {
|
|
231
|
-
console.log("\n(1/n) Waiting 5 seconds for Etherscan API rate limit");
|
|
232
|
-
await wait(5e3);
|
|
233
|
-
}
|
|
234
|
-
const contractCreationBlockNumber = await getTxBlockNumber(
|
|
235
|
-
txHash,
|
|
236
|
-
apiUrl,
|
|
237
|
-
apiKey
|
|
238
|
-
);
|
|
239
|
-
blockNumber = contractCreationBlockNumber;
|
|
240
|
-
} catch (error) {
|
|
241
|
-
}
|
|
242
|
-
if (!apiKey) {
|
|
243
|
-
console.log("(2/n) Waiting 5 seconds for Etherscan API rate limit");
|
|
244
|
-
await wait(5e3);
|
|
245
|
-
}
|
|
246
|
-
const abis = [];
|
|
247
|
-
const { abi, contractName } = await getContractAbiAndName(
|
|
248
|
-
contractAddress,
|
|
249
|
-
apiUrl,
|
|
250
|
-
apiKey
|
|
251
|
-
);
|
|
252
|
-
abis.push({ abi, contractName });
|
|
253
|
-
if (JSON.parse(abi).find(
|
|
254
|
-
(item) => item.type === "event" && item.name === "Upgraded" && item.inputs[0].name === "implementation"
|
|
255
|
-
)) {
|
|
256
|
-
console.log(
|
|
257
|
-
"Detected EIP-1967 proxy, fetching implementation contract ABIs"
|
|
258
|
-
);
|
|
259
|
-
if (!apiKey) {
|
|
260
|
-
console.log("(3/n) Waiting 5 seconds for Etherscan API rate limit");
|
|
261
|
-
await wait(5e3);
|
|
262
|
-
}
|
|
263
|
-
const { implAddresses } = await getProxyImplementationAddresses({
|
|
264
|
-
contractAddress,
|
|
265
|
-
apiUrl,
|
|
266
|
-
fromBlock: blockNumber,
|
|
267
|
-
apiKey
|
|
268
|
-
});
|
|
269
|
-
for (const [index, implAddress] of implAddresses.entries()) {
|
|
270
|
-
console.log(`Fetching ABI for implementation contract: ${implAddress}`);
|
|
271
|
-
if (!apiKey) {
|
|
272
|
-
console.log(
|
|
273
|
-
`(${4 + index}/${4 + implAddresses.length - 1}) Waiting 5 seconds for Etherscan API rate limit`
|
|
274
|
-
);
|
|
275
|
-
await wait(5e3);
|
|
276
|
-
}
|
|
277
|
-
const { abi: abi2, contractName: contractName2 } = await getContractAbiAndName(
|
|
278
|
-
implAddress,
|
|
279
|
-
apiUrl,
|
|
280
|
-
apiKey
|
|
281
|
-
);
|
|
282
|
-
abis.push({
|
|
283
|
-
abi: abi2,
|
|
284
|
-
contractName: `${contractName2}_${implAddress.slice(0, 6)}`
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
let abiConfig;
|
|
289
|
-
abis.forEach(({ abi: abi2, contractName: contractName2 }) => {
|
|
290
|
-
const abiRelativePath = `./abis/${contractName2}.json`;
|
|
291
|
-
const abiAbsolutePath = path3.join(rootDir, abiRelativePath);
|
|
292
|
-
writeFileSync2(abiAbsolutePath, prettier2.format(abi2, { parser: "json" }));
|
|
293
|
-
if (abis.length === 1) {
|
|
294
|
-
abiConfig = abiRelativePath;
|
|
295
|
-
} else {
|
|
296
|
-
abiConfig ||= [];
|
|
297
|
-
abiConfig.push(abiRelativePath);
|
|
298
|
-
}
|
|
299
|
-
});
|
|
300
|
-
const schemaGraphqlFileContents = `
|
|
301
|
-
type ExampleEntity @entity {
|
|
302
|
-
id: String!
|
|
303
|
-
name: String!
|
|
304
|
-
}
|
|
305
|
-
`;
|
|
306
|
-
const ponderSchemaFilePath = path3.join(rootDir, "schema.graphql");
|
|
307
|
-
writeFileSync2(
|
|
308
|
-
ponderSchemaFilePath,
|
|
309
|
-
prettier2.format(schemaGraphqlFileContents, { parser: "graphql" })
|
|
310
|
-
);
|
|
311
|
-
const config = {
|
|
312
|
-
networks: [
|
|
313
|
-
{
|
|
314
|
-
name,
|
|
315
|
-
chainId,
|
|
316
|
-
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`
|
|
317
|
-
}
|
|
318
|
-
],
|
|
319
|
-
contracts: [
|
|
320
|
-
{
|
|
321
|
-
name: contractName,
|
|
322
|
-
network: name,
|
|
323
|
-
abi: abiConfig,
|
|
324
|
-
address: contractAddress,
|
|
325
|
-
startBlock: blockNumber ?? void 0
|
|
326
|
-
}
|
|
327
|
-
]
|
|
328
|
-
};
|
|
329
|
-
return config;
|
|
330
|
-
};
|
|
331
|
-
var fetchEtherscan = async (url) => {
|
|
332
|
-
const maxRetries = 5;
|
|
333
|
-
let retryCount = 0;
|
|
334
|
-
while (retryCount <= maxRetries) {
|
|
335
|
-
try {
|
|
336
|
-
const response = await fetch(url);
|
|
337
|
-
const data = await response.json();
|
|
338
|
-
if (data.status === "0") {
|
|
339
|
-
throw new Error(`Etherscan API error: ${data.result}`);
|
|
340
|
-
}
|
|
341
|
-
return data;
|
|
342
|
-
} catch (error) {
|
|
343
|
-
retryCount++;
|
|
344
|
-
if (retryCount > maxRetries) {
|
|
345
|
-
throw new Error(`Max retries reached: ${error.message}`);
|
|
346
|
-
}
|
|
347
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
var getContractCreationTxn = async (contractAddress, apiUrl, apiKey) => {
|
|
352
|
-
const searchParams = new URLSearchParams({
|
|
353
|
-
module: "contract",
|
|
354
|
-
action: "getcontractcreation",
|
|
355
|
-
contractaddresses: contractAddress
|
|
356
|
-
});
|
|
357
|
-
if (apiKey)
|
|
358
|
-
searchParams.append("apikey", apiKey);
|
|
359
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
360
|
-
return data.result[0].txHash;
|
|
361
|
-
};
|
|
362
|
-
var getTxBlockNumber = async (txHash, apiUrl, apiKey) => {
|
|
363
|
-
const searchParams = new URLSearchParams({
|
|
364
|
-
module: "proxy",
|
|
365
|
-
action: "eth_getTransactionByHash",
|
|
366
|
-
txhash: txHash
|
|
367
|
-
});
|
|
368
|
-
if (apiKey)
|
|
369
|
-
searchParams.append("apikey", apiKey);
|
|
370
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
371
|
-
const hexBlockNumber = data.result.blockNumber;
|
|
372
|
-
return parseInt(hexBlockNumber.slice(2), 16);
|
|
373
|
-
};
|
|
374
|
-
var getContractAbiAndName = async (contractAddress, apiUrl, apiKey) => {
|
|
375
|
-
const searchParams = new URLSearchParams({
|
|
376
|
-
module: "contract",
|
|
377
|
-
action: "getsourcecode",
|
|
378
|
-
address: contractAddress
|
|
379
|
-
});
|
|
380
|
-
if (apiKey)
|
|
381
|
-
searchParams.append("apikey", apiKey);
|
|
382
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
383
|
-
const abi = data.result[0].ABI;
|
|
384
|
-
const contractName = data.result[0].ContractName;
|
|
385
|
-
return { abi, contractName };
|
|
386
|
-
};
|
|
387
|
-
var getProxyImplementationAddresses = async ({
|
|
388
|
-
contractAddress,
|
|
389
|
-
apiUrl,
|
|
390
|
-
fromBlock,
|
|
391
|
-
apiKey
|
|
392
|
-
}) => {
|
|
393
|
-
const searchParams = new URLSearchParams({
|
|
394
|
-
module: "logs",
|
|
395
|
-
action: "getLogs",
|
|
396
|
-
address: contractAddress,
|
|
397
|
-
fromBlock: fromBlock ? String(fromBlock) : "0",
|
|
398
|
-
toBlock: "latest",
|
|
399
|
-
topic0: "0xbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b"
|
|
400
|
-
});
|
|
401
|
-
if (apiKey)
|
|
402
|
-
searchParams.append("apikey", apiKey);
|
|
403
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
404
|
-
const logs = data.result;
|
|
405
|
-
const implAddresses = logs.map((log) => {
|
|
406
|
-
if (log.topics[0] && log.topics[1]) {
|
|
407
|
-
return `0x${log.topics[1].slice(26)}`;
|
|
408
|
-
} else {
|
|
409
|
-
return `0x${log.data.slice(26)}`;
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
return { implAddresses };
|
|
413
|
-
};
|
|
414
|
-
|
|
415
|
-
// src/templates/subgraphId.ts
|
|
416
|
-
import { writeFileSync as writeFileSync3 } from "node:fs";
|
|
417
|
-
import path4 from "node:path";
|
|
418
|
-
import fetch2 from "node-fetch";
|
|
419
|
-
import prettier3 from "prettier";
|
|
420
|
-
import { parse } from "yaml";
|
|
421
|
-
|
|
422
|
-
// src/helpers/getGraphProtocolChainId.ts
|
|
423
|
-
var chainIdByGraphNetwork = {
|
|
424
|
-
mainnet: 1,
|
|
425
|
-
kovan: 42,
|
|
426
|
-
rinkeby: 4,
|
|
427
|
-
ropsten: 3,
|
|
428
|
-
goerli: 5,
|
|
429
|
-
"poa-core": 99,
|
|
430
|
-
"poa-sokol": 77,
|
|
431
|
-
xdai: 100,
|
|
432
|
-
matic: 137,
|
|
433
|
-
mumbai: 80001,
|
|
434
|
-
fantom: 250,
|
|
435
|
-
"fantom-testnet": 4002,
|
|
436
|
-
bsc: 56,
|
|
437
|
-
chapel: -1,
|
|
438
|
-
clover: 0,
|
|
439
|
-
avalanche: 43114,
|
|
440
|
-
fuji: 43113,
|
|
441
|
-
celo: 42220,
|
|
442
|
-
"celo-alfajores": 44787,
|
|
443
|
-
fuse: 122,
|
|
444
|
-
moonbeam: 1284,
|
|
445
|
-
moonriver: 1285,
|
|
446
|
-
mbase: -1,
|
|
447
|
-
"arbitrum-one": 42161,
|
|
448
|
-
"arbitrum-rinkeby": 421611,
|
|
449
|
-
optimism: 10,
|
|
450
|
-
"optimism-kovan": 69,
|
|
451
|
-
aurora: 1313161554,
|
|
452
|
-
"aurora-testnet": 1313161555
|
|
453
|
-
};
|
|
454
|
-
var getGraphProtocolChainId = (networkName) => {
|
|
455
|
-
return chainIdByGraphNetwork[networkName];
|
|
456
|
-
};
|
|
457
|
-
var subgraphYamlFileNames = ["subgraph.yaml"].concat(
|
|
458
|
-
Object.keys(chainIdByGraphNetwork).map((n) => `subgraph-${n}.yaml`)
|
|
459
|
-
);
|
|
460
|
-
|
|
461
|
-
// src/helpers/validateGraphProtocolSource.ts
|
|
462
|
-
var validateGraphProtocolSource = (source) => {
|
|
463
|
-
return source;
|
|
464
|
-
};
|
|
465
|
-
|
|
466
|
-
// src/templates/subgraphId.ts
|
|
467
|
-
var fetchIpfsFile = async (cid) => {
|
|
468
|
-
const url = `https://ipfs.network.thegraph.com/api/v0/cat?arg=${cid}`;
|
|
469
|
-
const response = await fetch2(url);
|
|
470
|
-
const contentRaw = await response.text();
|
|
471
|
-
return contentRaw;
|
|
472
|
-
};
|
|
473
|
-
var fromSubgraphId = async ({
|
|
474
|
-
rootDir,
|
|
475
|
-
subgraphId
|
|
476
|
-
}) => {
|
|
477
|
-
const ponderNetworks = [];
|
|
478
|
-
let ponderContracts = [];
|
|
479
|
-
const manifestRaw = await fetchIpfsFile(subgraphId);
|
|
480
|
-
const manifest = parse(manifestRaw);
|
|
481
|
-
const schemaCid = manifest.schema.file["/"].slice(6);
|
|
482
|
-
const schemaRaw = await fetchIpfsFile(schemaCid);
|
|
483
|
-
const schemaCleaned = schemaRaw.replaceAll(": ID!", ": String!").replaceAll("BigDecimal", "Float");
|
|
484
|
-
const ponderSchemaFilePath = path4.join(rootDir, "schema.graphql");
|
|
485
|
-
writeFileSync3(
|
|
486
|
-
ponderSchemaFilePath,
|
|
487
|
-
prettier3.format(schemaCleaned, { parser: "graphql" })
|
|
488
|
-
);
|
|
489
|
-
const dataSources = manifest.dataSources.map(
|
|
490
|
-
validateGraphProtocolSource
|
|
491
|
-
);
|
|
492
|
-
const abiFiles = dataSources.map((source) => source.mapping.abis).flat().filter(
|
|
493
|
-
(source, idx, arr) => arr.findIndex((s) => s.name === source.name) === idx
|
|
494
|
-
);
|
|
495
|
-
await Promise.all(
|
|
496
|
-
abiFiles.map(async (abi) => {
|
|
497
|
-
const abiContent = await fetchIpfsFile(abi.file["/"].slice(6));
|
|
498
|
-
const abiPath = path4.join(rootDir, `./abis/${abi.name}.json`);
|
|
499
|
-
writeFileSync3(abiPath, prettier3.format(abiContent, { parser: "json" }));
|
|
500
|
-
})
|
|
501
|
-
);
|
|
502
|
-
ponderContracts = dataSources.map((source) => {
|
|
503
|
-
const network = source.network || "mainnet";
|
|
504
|
-
const chainId = getGraphProtocolChainId(network);
|
|
505
|
-
if (!chainId || chainId === -1) {
|
|
506
|
-
throw new Error(`Unhandled network name: ${network}`);
|
|
507
|
-
}
|
|
508
|
-
if (!ponderNetworks.map((n) => n.name).includes(network)) {
|
|
509
|
-
ponderNetworks.push({
|
|
510
|
-
name: network,
|
|
511
|
-
chainId,
|
|
512
|
-
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`
|
|
513
|
-
});
|
|
514
|
-
}
|
|
515
|
-
const abiRelativePath = `./abis/${source.source.abi}.json`;
|
|
516
|
-
return {
|
|
517
|
-
name: source.name,
|
|
518
|
-
network,
|
|
519
|
-
address: source.source.address,
|
|
520
|
-
abi: abiRelativePath,
|
|
521
|
-
startBlock: source.source.startBlock
|
|
522
|
-
};
|
|
523
|
-
});
|
|
524
|
-
const config = {
|
|
525
|
-
networks: ponderNetworks,
|
|
526
|
-
contracts: ponderContracts
|
|
527
|
-
};
|
|
528
|
-
return config;
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
// src/templates/subgraphRepo.ts
|
|
532
|
-
import { copyFileSync, readFileSync, writeFileSync as writeFileSync4 } from "node:fs";
|
|
533
|
-
import path5 from "node:path";
|
|
534
|
-
import prettier4 from "prettier";
|
|
535
|
-
import { parse as parse2 } from "yaml";
|
|
536
|
-
var fromSubgraphRepo = ({
|
|
537
|
-
rootDir,
|
|
538
|
-
subgraphPath
|
|
539
|
-
}) => {
|
|
540
|
-
const subgraphRootDir = path5.resolve(subgraphPath);
|
|
541
|
-
const ponderNetworks = [];
|
|
542
|
-
let ponderContracts = [];
|
|
543
|
-
const subgraphRootDirPath = path5.resolve(subgraphRootDir);
|
|
544
|
-
let subgraphYamlRaw = "";
|
|
545
|
-
for (const subgraphYamlFileName of subgraphYamlFileNames) {
|
|
546
|
-
try {
|
|
547
|
-
subgraphYamlRaw = readFileSync(
|
|
548
|
-
path5.join(subgraphRootDirPath, subgraphYamlFileName),
|
|
549
|
-
{
|
|
550
|
-
encoding: "utf-8"
|
|
551
|
-
}
|
|
552
|
-
);
|
|
553
|
-
break;
|
|
554
|
-
} catch (e) {
|
|
555
|
-
continue;
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (subgraphYamlRaw === "") {
|
|
559
|
-
throw new Error(`subgraph.yaml file not found`);
|
|
560
|
-
}
|
|
561
|
-
const subgraphYaml = parse2(subgraphYamlRaw);
|
|
562
|
-
const schemaRaw = readFileSync(
|
|
563
|
-
path5.join(subgraphRootDirPath, subgraphYaml.schema.file),
|
|
564
|
-
{
|
|
565
|
-
encoding: "utf-8"
|
|
566
|
-
}
|
|
567
|
-
);
|
|
568
|
-
const schemaCleaned = schemaRaw.replaceAll(": ID!", ": String!").replaceAll("BigDecimal", "Float");
|
|
569
|
-
writeFileSync4(
|
|
570
|
-
path5.join(rootDir, "schema.graphql"),
|
|
571
|
-
prettier4.format(schemaCleaned, { parser: "graphql" })
|
|
572
|
-
);
|
|
573
|
-
ponderContracts = subgraphYaml.dataSources.map(validateGraphProtocolSource).map((source) => {
|
|
574
|
-
const abiPath = source.mapping.abis.find(
|
|
575
|
-
(abi) => abi.name === source.name
|
|
576
|
-
)?.file;
|
|
577
|
-
if (!abiPath) {
|
|
578
|
-
throw new Error(`ABI path not found for source: ${source.name}`);
|
|
579
|
-
}
|
|
580
|
-
const network = source.network || "mainnet";
|
|
581
|
-
const chainId = getGraphProtocolChainId(network);
|
|
582
|
-
if (!chainId || chainId === -1) {
|
|
583
|
-
throw new Error(`Unhandled network name: ${network}`);
|
|
584
|
-
}
|
|
585
|
-
if (!ponderNetworks.map((n) => n.name).includes(network)) {
|
|
586
|
-
ponderNetworks.push({
|
|
587
|
-
name: network,
|
|
588
|
-
chainId,
|
|
589
|
-
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`
|
|
590
|
-
});
|
|
591
|
-
}
|
|
592
|
-
const abiAbsolutePath = path5.join(subgraphRootDirPath, abiPath);
|
|
593
|
-
const abiFileName = path5.basename(abiPath);
|
|
594
|
-
const ponderAbiRelativePath = `./abis/${abiFileName}`;
|
|
595
|
-
const ponderAbiAbsolutePath = path5.join(rootDir, ponderAbiRelativePath);
|
|
596
|
-
copyFileSync(abiAbsolutePath, ponderAbiAbsolutePath);
|
|
597
|
-
return {
|
|
598
|
-
name: source.name,
|
|
599
|
-
network,
|
|
600
|
-
address: source.source.address,
|
|
601
|
-
abi: ponderAbiRelativePath,
|
|
602
|
-
startBlock: source.source.startBlock
|
|
603
|
-
};
|
|
604
|
-
});
|
|
605
|
-
const config = {
|
|
606
|
-
networks: ponderNetworks,
|
|
607
|
-
contracts: ponderContracts
|
|
608
|
-
};
|
|
609
|
-
return config;
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
// src/index.ts
|
|
613
|
-
var run = async (options, overrides = {}) => {
|
|
614
|
-
const { rootDir } = options;
|
|
615
|
-
mkdirSync(path6.join(rootDir, "abis"), { recursive: true });
|
|
616
|
-
mkdirSync(path6.join(rootDir, "src"), { recursive: true });
|
|
617
|
-
let config;
|
|
618
|
-
console.log(
|
|
619
|
-
`
|
|
620
|
-
Creating a new Ponder app in ${pico.bold(pico.green(rootDir))}.`
|
|
621
|
-
);
|
|
622
|
-
switch (options.template?.kind) {
|
|
623
|
-
case 1 /* ETHERSCAN */: {
|
|
624
|
-
console.log(`
|
|
625
|
-
Using ${pico.cyan("Etherscan contract link")} template.`);
|
|
626
|
-
config = await fromEtherscan({
|
|
627
|
-
rootDir,
|
|
628
|
-
etherscanLink: options.template.link,
|
|
629
|
-
etherscanApiKey: options.etherscanApiKey
|
|
630
|
-
});
|
|
631
|
-
break;
|
|
632
|
-
}
|
|
633
|
-
case 2 /* SUBGRAPH_ID */: {
|
|
634
|
-
console.log(`
|
|
635
|
-
Using ${pico.cyan("Subgraph ID")} template.`);
|
|
636
|
-
config = await fromSubgraphId({
|
|
637
|
-
rootDir,
|
|
638
|
-
subgraphId: options.template.id
|
|
639
|
-
});
|
|
640
|
-
break;
|
|
641
|
-
}
|
|
642
|
-
case 3 /* SUBGRAPH_REPO */: {
|
|
643
|
-
console.log(`
|
|
644
|
-
Using ${pico.cyan("Subgraph repository")} template.`);
|
|
645
|
-
config = fromSubgraphRepo({
|
|
646
|
-
rootDir,
|
|
647
|
-
subgraphPath: options.template.path
|
|
648
|
-
});
|
|
649
|
-
break;
|
|
650
|
-
}
|
|
651
|
-
default: {
|
|
652
|
-
config = fromBasic({ rootDir });
|
|
653
|
-
break;
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
config.contracts.forEach((contract) => {
|
|
657
|
-
let abi;
|
|
658
|
-
if (Array.isArray(contract.abi)) {
|
|
659
|
-
const abiString = readFileSync2(path6.join(rootDir, contract.abi[1]), {
|
|
660
|
-
encoding: "utf-8"
|
|
661
|
-
});
|
|
662
|
-
abi = JSON.parse(abiString);
|
|
663
|
-
} else {
|
|
664
|
-
const abiString = readFileSync2(path6.join(rootDir, contract.abi), {
|
|
665
|
-
encoding: "utf-8"
|
|
666
|
-
});
|
|
667
|
-
abi = JSON.parse(abiString);
|
|
668
|
-
}
|
|
669
|
-
const abiEvents = abi.filter(
|
|
670
|
-
(item) => item.type === "event"
|
|
671
|
-
);
|
|
672
|
-
const eventNamesToWrite = abiEvents.map((event) => event.name).slice(0, 2);
|
|
673
|
-
const handlerFileContents = `
|
|
674
|
-
import { ponder } from '@/generated'
|
|
675
|
-
|
|
676
|
-
${eventNamesToWrite.map(
|
|
677
|
-
(eventName) => `
|
|
678
|
-
ponder.on("${contract.name}:${eventName}", async ({ event, context }) => {
|
|
679
|
-
console.log(event.params)
|
|
680
|
-
})`
|
|
681
|
-
).join("\n")}
|
|
682
|
-
`;
|
|
683
|
-
writeFileSync5(
|
|
684
|
-
path6.join(rootDir, `./src/${contract.name}.ts`),
|
|
685
|
-
prettier5.format(handlerFileContents, { parser: "typescript" })
|
|
686
|
-
);
|
|
687
|
-
});
|
|
688
|
-
const finalConfig = `
|
|
689
|
-
import type { Config } from "@ponder/core";
|
|
690
|
-
|
|
691
|
-
export const config: Config = {
|
|
692
|
-
networks: ${JSON.stringify(config.networks).replaceAll(
|
|
693
|
-
/"process.env.PONDER_RPC_URL_(.*?)"/g,
|
|
694
|
-
"process.env.PONDER_RPC_URL_$1"
|
|
695
|
-
)},
|
|
696
|
-
contracts: ${JSON.stringify(config.contracts)},
|
|
697
|
-
};
|
|
698
|
-
`;
|
|
699
|
-
writeFileSync5(
|
|
700
|
-
path6.join(rootDir, "ponder.config.ts"),
|
|
701
|
-
prettier5.format(finalConfig, { parser: "babel" })
|
|
702
|
-
);
|
|
703
|
-
const uniqueChainIds = Array.from(
|
|
704
|
-
new Set(config.networks.map((n) => n.chainId))
|
|
705
|
-
);
|
|
706
|
-
const envLocal = `${uniqueChainIds.map(
|
|
707
|
-
(chainId) => `PONDER_RPC_URL_${chainId}=""
|
|
708
|
-
`
|
|
709
|
-
)}`;
|
|
710
|
-
writeFileSync5(path6.join(rootDir, ".env.local"), envLocal);
|
|
711
|
-
const packageJson = `
|
|
712
|
-
{
|
|
713
|
-
"private": true,
|
|
714
|
-
"scripts": {
|
|
715
|
-
"dev": "ponder dev",
|
|
716
|
-
"start": "ponder start",
|
|
717
|
-
"codegen": "ponder codegen"
|
|
718
|
-
},
|
|
719
|
-
"dependencies": {
|
|
720
|
-
"@ponder/core": "latest"
|
|
721
|
-
},
|
|
722
|
-
"devDependencies": {
|
|
723
|
-
"@types/node": "^18.11.18",
|
|
724
|
-
"abitype": "^0.8.11",
|
|
725
|
-
"typescript": "^5.1.3",
|
|
726
|
-
"viem": "^1.2.6"
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
`;
|
|
730
|
-
writeFileSync5(
|
|
731
|
-
path6.join(rootDir, "package.json"),
|
|
732
|
-
prettier5.format(packageJson, { parser: "json" })
|
|
733
|
-
);
|
|
734
|
-
const tsConfig = `
|
|
735
|
-
{
|
|
736
|
-
"compilerOptions": {
|
|
737
|
-
"target": "ESNext",
|
|
738
|
-
"module": "ESNext",
|
|
739
|
-
"moduleResolution": "node",
|
|
740
|
-
"resolveJsonModule": true,
|
|
741
|
-
"esModuleInterop": true,
|
|
742
|
-
"strict": true,
|
|
743
|
-
"rootDir": ".",
|
|
744
|
-
"paths": {
|
|
745
|
-
"@/generated": ["./generated/index.ts"]
|
|
746
|
-
}
|
|
747
|
-
},
|
|
748
|
-
"include": ["./**/*.ts"],
|
|
749
|
-
"exclude": ["node_modules"]
|
|
750
|
-
}
|
|
751
|
-
`;
|
|
752
|
-
writeFileSync5(
|
|
753
|
-
path6.join(rootDir, "tsconfig.json"),
|
|
754
|
-
prettier5.format(tsConfig, { parser: "json" })
|
|
755
|
-
);
|
|
756
|
-
writeFileSync5(
|
|
757
|
-
path6.join(rootDir, ".gitignore"),
|
|
758
|
-
`node_modules/
|
|
759
|
-
.DS_Store
|
|
760
|
-
|
|
761
|
-
.env.local
|
|
762
|
-
.ponder/
|
|
763
|
-
generated/`
|
|
764
|
-
);
|
|
765
|
-
const packageManager = await getPackageManager();
|
|
766
|
-
console.log(pico.bold(`
|
|
767
|
-
Installing with ${packageManager}.`));
|
|
768
|
-
const installCommand = overrides.installCommand ? overrides.installCommand : `${packageManager} ${packageManager === "npm" ? "--quiet" : "--silent"} install`;
|
|
769
|
-
execSync2(installCommand, {
|
|
770
|
-
cwd: rootDir,
|
|
771
|
-
stdio: "inherit"
|
|
772
|
-
});
|
|
773
|
-
process.chdir(rootDir);
|
|
774
|
-
tryGitInit(rootDir);
|
|
775
|
-
console.log(`
|
|
776
|
-
Initialized a git repository.`);
|
|
777
|
-
const runCommand = `${packageManager === "npm" ? `npm --quiet run` : `${packageManager} --silent`} codegen`;
|
|
778
|
-
execSync2(runCommand, {
|
|
779
|
-
cwd: rootDir,
|
|
780
|
-
stdio: "inherit"
|
|
781
|
-
});
|
|
782
|
-
console.log(`
|
|
783
|
-
Generated types.`);
|
|
784
|
-
console.log(
|
|
785
|
-
pico.green("\nSuccess! ") + `Created ${options.projectName} at ${rootDir}`
|
|
786
|
-
);
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
// package.json
|
|
790
|
-
var package_default = {
|
|
791
|
-
name: "create-ponder",
|
|
792
|
-
version: "0.0.77",
|
|
793
|
-
description: "Tool to bootstrap a Ponder project",
|
|
794
|
-
license: "MIT",
|
|
795
|
-
author: "olias.eth",
|
|
796
|
-
files: [
|
|
797
|
-
"dist"
|
|
798
|
-
],
|
|
799
|
-
bin: {
|
|
800
|
-
"create-ponder": "dist/create-ponder.js"
|
|
801
|
-
},
|
|
802
|
-
scripts: {
|
|
803
|
-
build: "tsup-node",
|
|
804
|
-
test: "export $(grep -v '^#' .env.local | xargs) && vitest --no-threads",
|
|
805
|
-
"test:ci": "vitest --no-threads",
|
|
806
|
-
typecheck: "tsc --noEmit"
|
|
807
|
-
},
|
|
808
|
-
dependencies: {
|
|
809
|
-
cac: "^6.7.14",
|
|
810
|
-
"detect-package-manager": "^2.0.1",
|
|
811
|
-
execa: "5",
|
|
812
|
-
"node-fetch": "^2.6.7",
|
|
813
|
-
picocolors: "^1.0.0",
|
|
814
|
-
prettier: "^2.6.2",
|
|
815
|
-
prompts: "^2.4.2",
|
|
816
|
-
rimraf: "^5.0.1",
|
|
817
|
-
yaml: "^2.1.1"
|
|
818
|
-
},
|
|
819
|
-
devDependencies: {
|
|
820
|
-
"@ponder/core": "workspace:*",
|
|
821
|
-
"@types/node": "^18.7.8",
|
|
822
|
-
"@types/node-fetch": "2",
|
|
823
|
-
"@types/prettier": "^2.7.1",
|
|
824
|
-
"@types/prompts": "^2.4.2",
|
|
825
|
-
abitype: "^0.6.7",
|
|
826
|
-
tsup: "^6.6.3",
|
|
827
|
-
typescript: "^4.5.5",
|
|
828
|
-
vitest: "^0.29.2"
|
|
829
|
-
}
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
// src/bin/create-ponder.ts
|
|
833
|
-
var createPonder = async () => {
|
|
834
|
-
const cli = cac(package_default.name).version(package_default.version).usage("[options]").help().option("--dir [path]", "Path to directory for generated project").option("--from-subgraph-id [id]", "Subgraph deployment ID").option("--from-subgraph-repo [path]", "Path to subgraph repository").option("--from-etherscan [url]", "Link to etherscan contract page").option("--etherscan-api-key [key]", "Etherscan API key");
|
|
835
|
-
const parsed = cli.parse(process.argv);
|
|
836
|
-
const options = parsed.options;
|
|
837
|
-
if (options.help) {
|
|
838
|
-
process.exit(0);
|
|
839
|
-
}
|
|
840
|
-
const { fromEtherscan: fromEtherscan2, fromSubgraphId: fromSubgraphId2, fromSubgraphRepo: fromSubgraphRepo2 } = options;
|
|
841
|
-
if (fromSubgraphId2 && fromSubgraphRepo2 || fromSubgraphId2 && fromEtherscan2 || fromSubgraphRepo2 && fromEtherscan2) {
|
|
842
|
-
throw new Error(
|
|
843
|
-
`Cannot specify more than one "--from" option:
|
|
844
|
-
--from-subgraph
|
|
845
|
-
--from-etherscan-id
|
|
846
|
-
--from-etherscan-repo`
|
|
847
|
-
);
|
|
848
|
-
}
|
|
849
|
-
const { projectName } = await prompts({
|
|
850
|
-
type: "text",
|
|
851
|
-
name: "projectName",
|
|
852
|
-
message: "What is your project named?",
|
|
853
|
-
initial: "my-app"
|
|
854
|
-
});
|
|
855
|
-
let template = void 0;
|
|
856
|
-
if (fromEtherscan2) {
|
|
857
|
-
template = { kind: 1 /* ETHERSCAN */, link: fromEtherscan2 };
|
|
858
|
-
}
|
|
859
|
-
if (fromSubgraphId2) {
|
|
860
|
-
template = { kind: 2 /* SUBGRAPH_ID */, id: fromSubgraphId2 };
|
|
861
|
-
}
|
|
862
|
-
if (fromSubgraphRepo2) {
|
|
863
|
-
template = { kind: 3 /* SUBGRAPH_REPO */, path: fromSubgraphRepo2 };
|
|
864
|
-
}
|
|
865
|
-
if (!fromSubgraphId2 && !fromSubgraphRepo2 && !fromEtherscan2) {
|
|
866
|
-
const { template: templateKind } = await prompts({
|
|
867
|
-
type: "select",
|
|
868
|
-
name: "template",
|
|
869
|
-
message: "Would you like to use a template for this project?",
|
|
870
|
-
choices: [
|
|
871
|
-
{ title: "None" },
|
|
872
|
-
{ title: "Etherscan contract link" },
|
|
873
|
-
{ title: "Subgraph ID" },
|
|
874
|
-
{ title: "Subgraph repository" }
|
|
875
|
-
]
|
|
876
|
-
});
|
|
877
|
-
if (templateKind === 1 /* ETHERSCAN */) {
|
|
878
|
-
const { link } = await prompts({
|
|
879
|
-
type: "text",
|
|
880
|
-
name: "link",
|
|
881
|
-
message: "Enter an Etherscan contract link",
|
|
882
|
-
initial: "https://etherscan.io/address/0x97..."
|
|
883
|
-
});
|
|
884
|
-
template = { kind: 1 /* ETHERSCAN */, link };
|
|
885
|
-
}
|
|
886
|
-
if (templateKind === 2 /* SUBGRAPH_ID */) {
|
|
887
|
-
const { id } = await prompts({
|
|
888
|
-
type: "text",
|
|
889
|
-
name: "id",
|
|
890
|
-
message: "Enter a subgraph deployment ID",
|
|
891
|
-
initial: "QmNus..."
|
|
892
|
-
});
|
|
893
|
-
template = { kind: 2 /* SUBGRAPH_ID */, id };
|
|
894
|
-
}
|
|
895
|
-
if (templateKind === 3 /* SUBGRAPH_REPO */) {
|
|
896
|
-
const { path: path8 } = await prompts({
|
|
897
|
-
type: "text",
|
|
898
|
-
name: "path",
|
|
899
|
-
message: "Enter a path to a subgraph repository",
|
|
900
|
-
initial: "../subgraph"
|
|
901
|
-
});
|
|
902
|
-
template = { kind: 3 /* SUBGRAPH_REPO */, path: path8 };
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
const validatedOptions = {
|
|
906
|
-
projectName,
|
|
907
|
-
rootDir: path7.resolve(".", options.dir ? options.dir : projectName),
|
|
908
|
-
template,
|
|
909
|
-
etherscanApiKey: options.etherscanApiKey
|
|
910
|
-
};
|
|
911
|
-
await run(validatedOptions);
|
|
912
|
-
};
|
|
913
|
-
createPonder();
|
|
914
|
-
//# sourceMappingURL=create-ponder.mjs.map
|