create-ponder 0.0.37 → 0.0.38
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/bin/create-ponder.d.ts → create-ponder.d.ts} +0 -1
- package/dist/create-ponder.js +862 -0
- package/dist/create-ponder.js.map +1 -0
- package/dist/create-ponder.mjs +839 -0
- package/dist/create-ponder.mjs.map +1 -0
- package/package.json +9 -8
- package/dist/src/bin/create-ponder.js +0 -103
- package/dist/src/common.d.ts +0 -22
- package/dist/src/common.js +0 -10
- package/dist/src/helpers/detectPackageManager.d.ts +0 -5
- package/dist/src/helpers/detectPackageManager.js +0 -78
- package/dist/src/helpers/getEtherscanChainId.d.ts +0 -5
- package/dist/src/helpers/getEtherscanChainId.js +0 -69
- package/dist/src/helpers/getGraphProtocolChainId.d.ts +0 -2
- package/dist/src/helpers/getGraphProtocolChainId.js +0 -41
- package/dist/src/helpers/git.d.ts +0 -1
- package/dist/src/helpers/git.js +0 -55
- package/dist/src/helpers/validateGraphProtocolSource.d.ts +0 -27
- package/dist/src/helpers/validateGraphProtocolSource.js +0 -7
- package/dist/src/helpers/wait.d.ts +0 -1
- package/dist/src/helpers/wait.js +0 -5
- package/dist/src/index.d.ts +0 -23
- package/dist/src/index.js +0 -154
- package/dist/src/templates/basic.d.ts +0 -4
- package/dist/src/templates/basic.js +0 -50
- package/dist/src/templates/etherscan.d.ts +0 -6
- package/dist/src/templates/etherscan.js +0 -112
- package/dist/src/templates/subgraphId.d.ts +0 -5
- package/dist/src/templates/subgraphId.js +0 -72
- package/dist/src/templates/subgraphRepo.d.ts +0 -5
- package/dist/src/templates/subgraphRepo.js +0 -80
package/dist/src/index.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
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 ethers_1 = require("ethers");
|
|
8
|
-
const node_child_process_1 = require("node:child_process");
|
|
9
|
-
const node_fs_1 = require("node:fs");
|
|
10
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const picocolors_1 = __importDefault(require("picocolors"));
|
|
12
|
-
const prettier_1 = __importDefault(require("prettier"));
|
|
13
|
-
const common_1 = require("./common");
|
|
14
|
-
const detectPackageManager_1 = require("./helpers/detectPackageManager");
|
|
15
|
-
const git_1 = require("./helpers/git");
|
|
16
|
-
const basic_1 = require("./templates/basic");
|
|
17
|
-
const etherscan_1 = require("./templates/etherscan");
|
|
18
|
-
const subgraphId_1 = require("./templates/subgraphId");
|
|
19
|
-
const subgraphRepo_1 = require("./templates/subgraphRepo");
|
|
20
|
-
const run = async (options, overrides = {}) => {
|
|
21
|
-
const { rootDir } = options;
|
|
22
|
-
// Create required directories.
|
|
23
|
-
(0, node_fs_1.mkdirSync)(node_path_1.default.join(rootDir, "abis"), { recursive: true });
|
|
24
|
-
(0, node_fs_1.mkdirSync)(node_path_1.default.join(rootDir, "src"), { recursive: true });
|
|
25
|
-
let ponderConfig;
|
|
26
|
-
console.log(`\nCreating a new Ponder app in ${picocolors_1.default.bold(picocolors_1.default.green(rootDir))}.`);
|
|
27
|
-
switch (options.template?.kind) {
|
|
28
|
-
case common_1.TemplateKind.ETHERSCAN: {
|
|
29
|
-
console.log(`\nUsing ${picocolors_1.default.cyan("Etherscan contract link")} template.`);
|
|
30
|
-
ponderConfig = await (0, etherscan_1.fromEtherscan)({
|
|
31
|
-
rootDir,
|
|
32
|
-
etherscanLink: options.template.link,
|
|
33
|
-
etherscanApiKey: options.etherscanApiKey,
|
|
34
|
-
});
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
case common_1.TemplateKind.SUBGRAPH_ID: {
|
|
38
|
-
console.log(`\nUsing ${picocolors_1.default.cyan("Subgraph ID")} template.`);
|
|
39
|
-
ponderConfig = await (0, subgraphId_1.fromSubgraphId)({
|
|
40
|
-
rootDir,
|
|
41
|
-
subgraphId: options.template.id,
|
|
42
|
-
});
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
case common_1.TemplateKind.SUBGRAPH_REPO: {
|
|
46
|
-
console.log(`\nUsing ${picocolors_1.default.cyan("Subgraph repository")} template.`);
|
|
47
|
-
ponderConfig = (0, subgraphRepo_1.fromSubgraphRepo)({
|
|
48
|
-
rootDir,
|
|
49
|
-
subgraphPath: options.template.path,
|
|
50
|
-
});
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
default: {
|
|
54
|
-
ponderConfig = (0, basic_1.fromBasic)({ rootDir });
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Write the handler ts files.
|
|
59
|
-
ponderConfig.contracts.forEach((contract) => {
|
|
60
|
-
const abi = (0, node_fs_1.readFileSync)(node_path_1.default.join(rootDir, contract.abi), {
|
|
61
|
-
encoding: "utf-8",
|
|
62
|
-
});
|
|
63
|
-
const abiInterface = new ethers_1.ethers.utils.Interface(abi);
|
|
64
|
-
const eventNames = Object.keys(abiInterface.events).map((signature) => signature.slice(0, signature.indexOf("(")));
|
|
65
|
-
const eventNamesToWrite = eventNames.slice(0, 2);
|
|
66
|
-
const handlerFileContents = `
|
|
67
|
-
import { ponder } from '../generated'
|
|
68
|
-
|
|
69
|
-
${eventNamesToWrite
|
|
70
|
-
.map((eventName) => `
|
|
71
|
-
ponder.on("${contract.name}:${eventName}", async ({ event, context }) => {
|
|
72
|
-
console.log(event.params)
|
|
73
|
-
})`)
|
|
74
|
-
.join("\n")}
|
|
75
|
-
`;
|
|
76
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, `./src/${contract.name}.ts`), prettier_1.default.format(handlerFileContents, { parser: "typescript" }));
|
|
77
|
-
});
|
|
78
|
-
// Write the ponder.config.ts file.
|
|
79
|
-
const finalPonderConfig = `
|
|
80
|
-
import type { PonderConfig } from "@ponder/core";
|
|
81
|
-
|
|
82
|
-
export const config: PonderConfig = {
|
|
83
|
-
networks: ${JSON.stringify(ponderConfig.networks).replaceAll(/"process.env.PONDER_RPC_URL_(.*?)"/g, "process.env.PONDER_RPC_URL_$1")},
|
|
84
|
-
contracts: ${JSON.stringify(ponderConfig.contracts)},
|
|
85
|
-
};
|
|
86
|
-
`;
|
|
87
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "ponder.config.ts"), prettier_1.default.format(finalPonderConfig, { parser: "babel" }));
|
|
88
|
-
// Write the .env.local file.
|
|
89
|
-
const uniqueChainIds = Array.from(new Set(ponderConfig.networks.map((n) => n.chainId)));
|
|
90
|
-
const envLocal = `${uniqueChainIds.map((chainId) => `PONDER_RPC_URL_${chainId}=""\n`)}`;
|
|
91
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, ".env.local"), envLocal);
|
|
92
|
-
// Write the package.json file.
|
|
93
|
-
const packageJson = `
|
|
94
|
-
{
|
|
95
|
-
"private": true,
|
|
96
|
-
"scripts": {
|
|
97
|
-
"dev": "ponder dev",
|
|
98
|
-
"start": "ponder start",
|
|
99
|
-
"codegen": "ponder codegen"
|
|
100
|
-
},
|
|
101
|
-
"dependencies": {
|
|
102
|
-
"@ponder/core": "latest"
|
|
103
|
-
},
|
|
104
|
-
"devDependencies": {
|
|
105
|
-
"@types/node": "^18.11.18",
|
|
106
|
-
"ethers": "^5.6.9"
|
|
107
|
-
},
|
|
108
|
-
"engines": {
|
|
109
|
-
"node": ">=16.0.0 <19.0.0"
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
`;
|
|
113
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "package.json"), prettier_1.default.format(packageJson, { parser: "json" }));
|
|
114
|
-
// Write the tsconfig.json file.
|
|
115
|
-
const tsConfig = `
|
|
116
|
-
{
|
|
117
|
-
"compilerOptions": {
|
|
118
|
-
"target": "esnext",
|
|
119
|
-
"module": "esnext",
|
|
120
|
-
"esModuleInterop": true,
|
|
121
|
-
"strict": true,
|
|
122
|
-
"moduleResolution": "node"
|
|
123
|
-
},
|
|
124
|
-
"include": ["./**/*.ts"],
|
|
125
|
-
"exclude": ["node_modules"]
|
|
126
|
-
}
|
|
127
|
-
`;
|
|
128
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, "tsconfig.json"), prettier_1.default.format(tsConfig, { parser: "json" }));
|
|
129
|
-
// Write the .gitignore file.
|
|
130
|
-
(0, node_fs_1.writeFileSync)(node_path_1.default.join(rootDir, ".gitignore"), `node_modules/\n.DS_Store\n\n.env.local\n.ponder/\ngenerated/`);
|
|
131
|
-
const packageManager = await (0, detectPackageManager_1.detect)();
|
|
132
|
-
const runCommand = packageManager === "npm" ? `${packageManager} run` : packageManager;
|
|
133
|
-
// Install packages.
|
|
134
|
-
console.log(picocolors_1.default.bold(`\nInstalling with ${packageManager}.`));
|
|
135
|
-
const installCommand = overrides.installCommand
|
|
136
|
-
? overrides.installCommand
|
|
137
|
-
: `${packageManager} install`;
|
|
138
|
-
(0, node_child_process_1.execSync)(installCommand, {
|
|
139
|
-
cwd: rootDir,
|
|
140
|
-
stdio: "inherit",
|
|
141
|
-
});
|
|
142
|
-
// Intialize git repository
|
|
143
|
-
process.chdir(rootDir);
|
|
144
|
-
(0, git_1.tryGitInit)(rootDir);
|
|
145
|
-
console.log(`\nInitialized a git repository.`);
|
|
146
|
-
// Run codegen.
|
|
147
|
-
(0, node_child_process_1.execSync)(`${runCommand} --silent codegen --silent`, {
|
|
148
|
-
cwd: rootDir,
|
|
149
|
-
stdio: "inherit",
|
|
150
|
-
});
|
|
151
|
-
console.log(`\nGenerated types.`);
|
|
152
|
-
console.log(picocolors_1.default.green("\nSuccess! ") + `Created ${options.projectName} at ${rootDir}`);
|
|
153
|
-
};
|
|
154
|
-
exports.run = run;
|
|
@@ -1,50 +0,0 @@
|
|
|
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
|
-
type ExampleToken @entity {
|
|
17
|
-
id: ID!
|
|
18
|
-
tokenId: Int!
|
|
19
|
-
trait: TokenTrait!
|
|
20
|
-
}
|
|
21
|
-
enum TokenTrait {
|
|
22
|
-
GOOD
|
|
23
|
-
BAD
|
|
24
|
-
}
|
|
25
|
-
`;
|
|
26
|
-
// Generate the schema.graphql file.
|
|
27
|
-
const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
|
|
28
|
-
(0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaGraphqlFileContents, { parser: "graphql" }));
|
|
29
|
-
// Build the partial ponder config.
|
|
30
|
-
const ponderConfig = {
|
|
31
|
-
networks: [
|
|
32
|
-
{
|
|
33
|
-
name: "mainnet",
|
|
34
|
-
chainId: 1,
|
|
35
|
-
rpcUrl: `process.env.PONDER_RPC_URL_1`,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
contracts: [
|
|
39
|
-
{
|
|
40
|
-
name: "ExampleContract",
|
|
41
|
-
network: "mainnet",
|
|
42
|
-
address: "0x0",
|
|
43
|
-
abi: abiRelativePath,
|
|
44
|
-
startBlock: 1234567,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
47
|
-
};
|
|
48
|
-
return ponderConfig;
|
|
49
|
-
};
|
|
50
|
-
exports.fromBasic = fromBasic;
|
|
@@ -1,112 +0,0 @@
|
|
|
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
|
-
const txHash = await getContractCreationTxn(contractAddress, apiUrl, apiKey);
|
|
24
|
-
if (!apiKey) {
|
|
25
|
-
console.log("\n(1/2) Waiting 5 seconds for Etherscan API rate limit");
|
|
26
|
-
await (0, wait_1.wait)(5000);
|
|
27
|
-
}
|
|
28
|
-
const blockNumber = await getTxBlockNumber(txHash, apiUrl, apiKey);
|
|
29
|
-
if (!apiKey) {
|
|
30
|
-
console.log("(2/2) Waiting 5 seconds for Etherscan API rate limit");
|
|
31
|
-
await (0, wait_1.wait)(5000);
|
|
32
|
-
}
|
|
33
|
-
const { abi, contractName } = await getContractAbiAndName(contractAddress, apiUrl, apiKey);
|
|
34
|
-
// Write contract ABI file.
|
|
35
|
-
const abiRelativePath = `./abis/${contractName}.json`;
|
|
36
|
-
const abiAbsolutePath = node_path_1.default.join(rootDir, abiRelativePath);
|
|
37
|
-
(0, node_fs_1.writeFileSync)(abiAbsolutePath, prettier_1.default.format(abi, { parser: "json" }));
|
|
38
|
-
const schemaGraphqlFileContents = `
|
|
39
|
-
type ExampleEntity @entity {
|
|
40
|
-
id: ID!
|
|
41
|
-
name: String!
|
|
42
|
-
}
|
|
43
|
-
`;
|
|
44
|
-
// Generate the schema.graphql file.
|
|
45
|
-
const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
|
|
46
|
-
(0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaGraphqlFileContents, { parser: "graphql" }));
|
|
47
|
-
// Build and return the partial ponder config.
|
|
48
|
-
const ponderConfig = {
|
|
49
|
-
networks: [
|
|
50
|
-
{
|
|
51
|
-
name: name,
|
|
52
|
-
chainId: chainId,
|
|
53
|
-
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
contracts: [
|
|
57
|
-
{
|
|
58
|
-
name: contractName,
|
|
59
|
-
network: name,
|
|
60
|
-
abi: abiRelativePath,
|
|
61
|
-
address: contractAddress,
|
|
62
|
-
startBlock: blockNumber,
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
};
|
|
66
|
-
return ponderConfig;
|
|
67
|
-
};
|
|
68
|
-
exports.fromEtherscan = fromEtherscan;
|
|
69
|
-
const fetchEtherscan = async (url) => {
|
|
70
|
-
const response = await (0, node_fetch_1.default)(url);
|
|
71
|
-
const data = await response.json();
|
|
72
|
-
if (data.status === "0") {
|
|
73
|
-
throw new Error(`Etherscan API error: ${data.result}`);
|
|
74
|
-
}
|
|
75
|
-
return data;
|
|
76
|
-
};
|
|
77
|
-
const getContractCreationTxn = async (contractAddress, apiUrl, apiKey) => {
|
|
78
|
-
const searchParams = new URLSearchParams({
|
|
79
|
-
module: "contract",
|
|
80
|
-
action: "getcontractcreation",
|
|
81
|
-
contractaddresses: contractAddress,
|
|
82
|
-
});
|
|
83
|
-
if (apiKey)
|
|
84
|
-
searchParams.append("apikey", apiKey);
|
|
85
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
86
|
-
return data.result[0].txHash;
|
|
87
|
-
};
|
|
88
|
-
const getTxBlockNumber = async (txHash, apiUrl, apiKey) => {
|
|
89
|
-
const searchParams = new URLSearchParams({
|
|
90
|
-
module: "proxy",
|
|
91
|
-
action: "eth_getTransactionByHash",
|
|
92
|
-
txhash: txHash,
|
|
93
|
-
});
|
|
94
|
-
if (apiKey)
|
|
95
|
-
searchParams.append("apikey", apiKey);
|
|
96
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
97
|
-
const hexBlockNumber = data.result.blockNumber;
|
|
98
|
-
return parseInt(hexBlockNumber.slice(2), 16);
|
|
99
|
-
};
|
|
100
|
-
const getContractAbiAndName = async (contractAddress, apiUrl, apiKey) => {
|
|
101
|
-
const searchParams = new URLSearchParams({
|
|
102
|
-
module: "contract",
|
|
103
|
-
action: "getsourcecode",
|
|
104
|
-
address: contractAddress,
|
|
105
|
-
});
|
|
106
|
-
if (apiKey)
|
|
107
|
-
searchParams.append("apikey", apiKey);
|
|
108
|
-
const data = await fetchEtherscan(`${apiUrl}?${searchParams.toString()}`);
|
|
109
|
-
const abi = data.result[0].ABI;
|
|
110
|
-
const contractName = data.result[0].ContractName;
|
|
111
|
-
return { abi, contractName };
|
|
112
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
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 ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
|
|
30
|
-
(0, node_fs_1.writeFileSync)(ponderSchemaFilePath, prettier_1.default.format(schemaRaw, { parser: "graphql" }));
|
|
31
|
-
const dataSources = manifest.dataSources.map(validateGraphProtocolSource_1.validateGraphProtocolSource);
|
|
32
|
-
// Fetch and write all referenced ABIs.
|
|
33
|
-
const abiFiles = dataSources
|
|
34
|
-
.map((source) => source.mapping.abis)
|
|
35
|
-
.flat()
|
|
36
|
-
.filter((source, idx, arr) => arr.findIndex((s) => s.name === source.name) === idx);
|
|
37
|
-
await Promise.all(abiFiles.map(async (abi) => {
|
|
38
|
-
const abiContent = await fetchIpfsFile(abi.file["/"].slice(6));
|
|
39
|
-
const abiPath = node_path_1.default.join(rootDir, `./abis/${abi.name}.json`);
|
|
40
|
-
(0, node_fs_1.writeFileSync)(abiPath, prettier_1.default.format(abiContent, { parser: "json" }));
|
|
41
|
-
}));
|
|
42
|
-
// Build the ponder sources.
|
|
43
|
-
ponderContracts = dataSources.map((source) => {
|
|
44
|
-
const network = source.network || "mainnet";
|
|
45
|
-
const chainId = (0, getGraphProtocolChainId_1.getGraphProtocolChainId)(network);
|
|
46
|
-
if (!chainId || chainId === -1) {
|
|
47
|
-
throw new Error(`Unhandled network name: ${network}`);
|
|
48
|
-
}
|
|
49
|
-
if (!ponderNetworks.map((n) => n.name).includes(network)) {
|
|
50
|
-
ponderNetworks.push({
|
|
51
|
-
name: network,
|
|
52
|
-
chainId: chainId,
|
|
53
|
-
rpcUrl: `process.env.PONDER_RPC_URL_${chainId}`,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
const abiRelativePath = `./abis/${source.source.abi}.json`;
|
|
57
|
-
return {
|
|
58
|
-
name: source.name,
|
|
59
|
-
network: network,
|
|
60
|
-
address: source.source.address,
|
|
61
|
-
abi: abiRelativePath,
|
|
62
|
-
startBlock: source.source.startBlock,
|
|
63
|
-
};
|
|
64
|
-
});
|
|
65
|
-
// Build the partial ponder config.
|
|
66
|
-
const ponderConfig = {
|
|
67
|
-
networks: ponderNetworks,
|
|
68
|
-
contracts: ponderContracts,
|
|
69
|
-
};
|
|
70
|
-
return ponderConfig;
|
|
71
|
-
};
|
|
72
|
-
exports.fromSubgraphId = fromSubgraphId;
|
|
@@ -1,80 +0,0 @@
|
|
|
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.fromSubgraphRepo = void 0;
|
|
7
|
-
const node_fs_1 = require("node:fs");
|
|
8
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
-
const yaml_1 = require("yaml");
|
|
10
|
-
const getGraphProtocolChainId_1 = require("../helpers/getGraphProtocolChainId");
|
|
11
|
-
const validateGraphProtocolSource_1 = require("../helpers/validateGraphProtocolSource");
|
|
12
|
-
const fromSubgraphRepo = ({ rootDir, subgraphPath, }) => {
|
|
13
|
-
const subgraphRootDir = node_path_1.default.resolve(subgraphPath);
|
|
14
|
-
const ponderNetworks = [];
|
|
15
|
-
let ponderContracts = [];
|
|
16
|
-
// If the `--from-subgraph` option was passed, parse subgraph files
|
|
17
|
-
const subgraphRootDirPath = node_path_1.default.resolve(subgraphRootDir);
|
|
18
|
-
// Read and parse the subgraph YAML file.
|
|
19
|
-
let subgraphYamlRaw = "";
|
|
20
|
-
for (const subgraphYamlFileName of getGraphProtocolChainId_1.subgraphYamlFileNames) {
|
|
21
|
-
try {
|
|
22
|
-
subgraphYamlRaw = (0, node_fs_1.readFileSync)(node_path_1.default.join(subgraphRootDirPath, subgraphYamlFileName), {
|
|
23
|
-
encoding: "utf-8",
|
|
24
|
-
});
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
catch (e) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (subgraphYamlRaw === "") {
|
|
32
|
-
throw new Error(`subgraph.yaml file not found`);
|
|
33
|
-
}
|
|
34
|
-
const subgraphYaml = (0, yaml_1.parse)(subgraphYamlRaw);
|
|
35
|
-
// Copy over the schema.graphql file.
|
|
36
|
-
const subgraphSchemaFilePath = node_path_1.default.join(subgraphRootDirPath, subgraphYaml.schema.file);
|
|
37
|
-
const ponderSchemaFilePath = node_path_1.default.join(rootDir, "schema.graphql");
|
|
38
|
-
(0, node_fs_1.copyFileSync)(subgraphSchemaFilePath, ponderSchemaFilePath);
|
|
39
|
-
// Build the ponder sources. Also copy over the ABI files for each source.
|
|
40
|
-
ponderContracts = subgraphYaml.dataSources
|
|
41
|
-
.map(validateGraphProtocolSource_1.validateGraphProtocolSource)
|
|
42
|
-
.map((source) => {
|
|
43
|
-
const abiPath = source.mapping.abis.find((abi) => abi.name === source.name)?.file;
|
|
44
|
-
if (!abiPath) {
|
|
45
|
-
throw new Error(`ABI path not found for source: ${source.name}`);
|
|
46
|
-
}
|
|
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
|
-
// Copy the ABI file.
|
|
60
|
-
const abiAbsolutePath = node_path_1.default.join(subgraphRootDirPath, abiPath);
|
|
61
|
-
const abiFileName = node_path_1.default.basename(abiPath);
|
|
62
|
-
const ponderAbiRelativePath = `./abis/${abiFileName}`;
|
|
63
|
-
const ponderAbiAbsolutePath = node_path_1.default.join(rootDir, ponderAbiRelativePath);
|
|
64
|
-
(0, node_fs_1.copyFileSync)(abiAbsolutePath, ponderAbiAbsolutePath);
|
|
65
|
-
return {
|
|
66
|
-
name: source.name,
|
|
67
|
-
network: network,
|
|
68
|
-
address: source.source.address,
|
|
69
|
-
abi: ponderAbiRelativePath,
|
|
70
|
-
startBlock: source.source.startBlock,
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
// Build the partial ponder config.
|
|
74
|
-
const ponderConfig = {
|
|
75
|
-
networks: ponderNetworks,
|
|
76
|
-
contracts: ponderContracts,
|
|
77
|
-
};
|
|
78
|
-
return ponderConfig;
|
|
79
|
-
};
|
|
80
|
-
exports.fromSubgraphRepo = fromSubgraphRepo;
|