create-ponder 0.5.0 → 0.5.2

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/index.js CHANGED
@@ -16,7 +16,7 @@ import { default as prompts } from "prompts";
16
16
  // package.json
17
17
  var package_default = {
18
18
  name: "create-ponder",
19
- version: "0.5.0",
19
+ version: "0.5.2",
20
20
  type: "module",
21
21
  description: "A CLI tool to create Ponder apps",
22
22
  license: "MIT",
@@ -484,8 +484,6 @@ var chainIdByGraphNetwork = {
484
484
  fantom: 250,
485
485
  "fantom-testnet": 4002,
486
486
  bsc: 56,
487
- chapel: -1,
488
- clover: 0,
489
487
  avalanche: 43114,
490
488
  fuji: 43113,
491
489
  celo: 42220,
@@ -493,7 +491,6 @@ var chainIdByGraphNetwork = {
493
491
  fuse: 122,
494
492
  moonbeam: 1284,
495
493
  moonriver: 1285,
496
- mbase: -1,
497
494
  base: 8453,
498
495
  "base-sepolia": 84532,
499
496
  "arbitrum-one": 42161,
@@ -504,7 +501,7 @@ var chainIdByGraphNetwork = {
504
501
  "aurora-testnet": 1313161555
505
502
  };
506
503
  var getGraphProtocolChainId = (networkName) => {
507
- return chainIdByGraphNetwork[networkName];
504
+ return chainIdByGraphNetwork[networkName] ?? 0;
508
505
  };
509
506
  var subgraphYamlFileNames = ["subgraph.yaml"].concat(
510
507
  Object.keys(chainIdByGraphNetwork).map((n) => `subgraph-${n}.yaml`)
@@ -516,17 +513,38 @@ var validateGraphProtocolSource = (source) => {
516
513
  };
517
514
 
518
515
  // src/subgraph.ts
519
- var fetchIpfsFile = async (cid) => {
520
- const url = `https://ipfs.network.thegraph.com/api/v0/cat?arg=${cid}`;
521
- const response = await fetch(url);
522
- const contentRaw = await response.text();
523
- return contentRaw;
524
- };
516
+ var subgraphProviders = [
517
+ {
518
+ id: "thegraph",
519
+ name: "The Graph",
520
+ // Used to be https://ipfs.network.thegraph.com/api/v0/cat?arg=${cid}
521
+ // Also used to accept GET requests for some reason
522
+ fetchIpfs: async (cid) => {
523
+ const response = await fetch(
524
+ `https://api.thegraph.com/ipfs/api/v0/cat?arg=${cid}`,
525
+ { method: "POST" }
526
+ );
527
+ return await response.text();
528
+ }
529
+ },
530
+ {
531
+ id: "satsuma",
532
+ name: "Alchemy Subgraph (Satsuma)",
533
+ fetchIpfs: async (cid) => {
534
+ const response = await fetch(`https://ipfs.satsuma.xyz/ipfs/${cid}`);
535
+ return await response.text();
536
+ }
537
+ }
538
+ ];
525
539
  var fromSubgraphId = async ({
526
540
  rootDir,
527
- subgraphId
541
+ subgraphId,
542
+ subgraphProvider
528
543
  }) => {
529
- const manifestRaw = await fetchIpfsFile(subgraphId);
544
+ const provider = subgraphProviders.find((p) => p.id === subgraphProvider);
545
+ if (!provider)
546
+ throw new Error(`Unknown subgraph provider: ${subgraphProvider}`);
547
+ const manifestRaw = await provider.fetchIpfs(subgraphId);
530
548
  const manifest = parse(manifestRaw);
531
549
  const contracts = {};
532
550
  manifest.dataSources.forEach((d) => {
@@ -545,7 +563,7 @@ var fromSubgraphId = async ({
545
563
  const abis = {};
546
564
  await Promise.all(
547
565
  abiFiles.map(async (abi) => {
548
- const abiContent = await fetchIpfsFile(abi.file["/"].slice(6));
566
+ const abiContent = await provider.fetchIpfs(abi.file["/"].slice(6));
549
567
  const abiPath = path3.join(rootDir, `./abis/${abi.name}Abi.ts`);
550
568
  writeFileSync2(
551
569
  abiPath,
@@ -562,10 +580,6 @@ var fromSubgraphId = async ({
562
580
  const ponderContracts = dataSources.map((sourceInvalid) => {
563
581
  const source = validateGraphProtocolSource(sourceInvalid);
564
582
  const network = source.network || "mainnet";
565
- const chainId = getGraphProtocolChainId(network);
566
- if (!chainId || chainId === -1) {
567
- throw new Error(`Unhandled network name: ${network}`);
568
- }
569
583
  const abiRelativePath = `./abis/${source.source.abi}Abi.ts`;
570
584
  return {
571
585
  name: source.name,
@@ -582,10 +596,11 @@ var fromSubgraphId = async ({
582
596
  const contractsObject = {};
583
597
  const networksObject = {};
584
598
  ponderContracts.forEach((pc) => {
599
+ const chainId = getGraphProtocolChainId(pc.network);
585
600
  contractsObject[pc.name] = pc;
586
601
  networksObject[pc.network] = {
587
- chainId: getGraphProtocolChainId(pc.network),
588
- transport: `http(process.env.PONDER_RPC_URL_${getGraphProtocolChainId(pc.network)})`
602
+ chainId,
603
+ transport: `http(process.env.PONDER_RPC_URL_${chainId})`
589
604
  };
590
605
  contractsObject[pc.name].name = void 0;
591
606
  });
@@ -781,7 +796,20 @@ async function run({
781
796
  }
782
797
  }
783
798
  let subgraph = options.subgraph;
799
+ let subgraphProvider = options.subgraphProvider;
784
800
  if (templateMeta.id === "subgraph") {
801
+ if (subgraphProvider === void 0) {
802
+ const result = await prompts({
803
+ name: "subgraphProvider",
804
+ message: "Which provider is the subgraph deployed to?",
805
+ type: "select",
806
+ choices: subgraphProviders.map(({ id, name }) => ({
807
+ title: name,
808
+ value: id
809
+ }))
810
+ });
811
+ subgraphProvider = result.subgraphProvider;
812
+ }
785
813
  if (!subgraph) {
786
814
  const result = await prompts({
787
815
  type: "text",
@@ -816,7 +844,11 @@ async function run({
816
844
  }
817
845
  if (templateMeta.id === "subgraph") {
818
846
  const result = await oraPromise(
819
- fromSubgraphId({ rootDir: projectPath, subgraphId: subgraph }),
847
+ fromSubgraphId({
848
+ rootDir: projectPath,
849
+ subgraphId: subgraph,
850
+ subgraphProvider
851
+ }),
820
852
  {
821
853
  text: "Fetching subgraph metadata. This may take a few seconds.",
822
854
  failText: "Failed to fetch subgraph metadata.",
@@ -901,24 +933,26 @@ async function run({
901
933
  "install",
902
934
  packageManager === "npm" ? "--quiet" : "--silent"
903
935
  ];
904
- await oraPromise(
905
- execa(packageManager, installArgs, {
906
- cwd: projectPath,
907
- env: {
908
- ...process.env,
909
- ADBLOCK: "1",
910
- DISABLE_OPENCOLLECTIVE: "1",
911
- // we set NODE_ENV to development as pnpm skips dev
912
- // dependencies when production
913
- NODE_ENV: "development"
936
+ if (!options.skipInstall) {
937
+ await oraPromise(
938
+ execa(packageManager, installArgs, {
939
+ cwd: projectPath,
940
+ env: {
941
+ ...process.env,
942
+ ADBLOCK: "1",
943
+ DISABLE_OPENCOLLECTIVE: "1",
944
+ // we set NODE_ENV to development as pnpm skips dev
945
+ // dependencies when production
946
+ NODE_ENV: "development"
947
+ }
948
+ }),
949
+ {
950
+ text: `Installing packages with ${pico5.bold(packageManager)}. This may take a few seconds.`,
951
+ failText: "Failed to install packages.",
952
+ successText: `Installed packages with ${pico5.bold(packageManager)}.`
914
953
  }
915
- }),
916
- {
917
- text: `Installing packages with ${pico5.bold(packageManager)}. This may take a few seconds.`,
918
- failText: "Failed to install packages.",
919
- successText: `Installed packages with ${pico5.bold(packageManager)}.`
920
- }
921
- );
954
+ );
955
+ }
922
956
  if (!options.skipGit) {
923
957
  await oraPromise(
924
958
  async () => {
@@ -972,10 +1006,13 @@ async function run({
972
1006
  const cli = cac(package_default.name).version(package_default.version).usage(`${pico5.green("<directory>")} [options]`).option(
973
1007
  "-t, --template [id]",
974
1008
  `Use a template. Options: ${templates.map(({ id }) => id).join(", ")}`
975
- ).option("--etherscan [url]", "Use the Etherscan template").option("--subgraph [id]", "Use the subgraph template").option("--npm", "Use npm as your package manager").option("--pnpm", "Use pnpm as your package manager").option("--yarn", "Use yarn as your package manager").option("--skip-git", "Skip initializing a git repository").option(
1009
+ ).option("--etherscan [url]", "Use the Etherscan template").option(
976
1010
  "--etherscan-api-key [key]",
977
1011
  "Etherscan API key for Etherscan template"
978
- ).help();
1012
+ ).option("--subgraph [id]", "Use the subgraph template").option(
1013
+ "--subgraph-provider [provider]",
1014
+ `Specify the subgraph provider. Options: ${subgraphProviders.map(({ id }) => id).join(", ")}`
1015
+ ).option("--npm", "Use npm as your package manager").option("--pnpm", "Use pnpm as your package manager").option("--yarn", "Use yarn as your package manager").option("--skip-git", "Skip initializing a git repository").option("--skip-install", "Skip installing packages").help();
979
1016
  const _nodeVersion = process.version.split(".");
980
1017
  const nodeVersion = [
981
1018
  Number(_nodeVersion[0].slice(1)),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-ponder",
3
- "version": "0.5.0",
3
+ "version": "0.5.2",
4
4
  "type": "module",
5
5
  "description": "A CLI tool to create Ponder apps",
6
6
  "license": "MIT",
@@ -14,7 +14,7 @@ export default createConfig({
14
14
  ExampleContract: {
15
15
  network: "mainnet",
16
16
  abi: ExampleContractAbi,
17
- address: "0x0",
17
+ address: "0x0000000000000000000000000000000000000000",
18
18
  startBlock: 1234567,
19
19
  },
20
20
  },