@sentio/sdk 2.10.0-rc.1 → 2.10.0-rc.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/lib/core/yaml-contract-config.d.ts +5 -0
- package/lib/core/yaml-contract-config.js +2 -0
- package/lib/core/yaml-contract-config.js.map +1 -0
- package/lib/eth/codegen/codegen.d.ts +2 -1
- package/lib/eth/codegen/codegen.js +4 -4
- package/lib/eth/codegen/codegen.js.map +1 -1
- package/lib/eth/codegen/ethers-sentio.d.ts +3 -2
- package/lib/eth/codegen/ethers-sentio.js +31 -6
- package/lib/eth/codegen/ethers-sentio.js.map +1 -1
- package/lib/eth/codegen/run.js +1 -1
- package/lib/eth/codegen/run.js.map +1 -1
- package/package.json +6 -5
- package/src/core/yaml-contract-config.ts +5 -0
- package/src/eth/codegen/codegen.ts +9 -4
- package/src/eth/codegen/ethers-sentio.ts +40 -9
- package/src/eth/codegen/run.ts +1 -1
- package/src/eth/codegen/tsconfig.json +1 -1
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"yaml-contract-config.js","sourceRoot":"","sources":["../../src/core/yaml-contract-config.ts"],"names":[],"mappings":"","sourcesContent":["export interface YamlContractConfig {\n address: string\n chain: string\n name: string\n}\n"]}
|
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
import { YamlContractConfig } from '../../core/yaml-contract-config.js';
|
2
|
+
export declare function codegen(abisDir: string, outDir: string, contractsToGenExample?: YamlContractConfig[]): Promise<void>;
|
@@ -5,13 +5,13 @@ import EthersSentio from './ethers-sentio.js';
|
|
5
5
|
import * as prettier from 'prettier';
|
6
6
|
import path from 'path';
|
7
7
|
import mkdirp from 'mkdirp';
|
8
|
-
export async function codegen(abisDir, outDir,
|
8
|
+
export async function codegen(abisDir, outDir, contractsToGenExample = []) {
|
9
9
|
if (!fs.existsSync(abisDir)) {
|
10
10
|
return;
|
11
11
|
}
|
12
|
-
console.log('Generated', await codegenInternal(abisDir, outDir,
|
12
|
+
console.log('Generated', await codegenInternal(abisDir, outDir, contractsToGenExample), 'files');
|
13
13
|
}
|
14
|
-
async function codegenInternal(abisDir, outDir,
|
14
|
+
async function codegenInternal(abisDir, outDir, contractsToGenExample) {
|
15
15
|
let allFiles = fs.readdirSync(abisDir);
|
16
16
|
if (allFiles.length === 0) {
|
17
17
|
return 0;
|
@@ -34,7 +34,7 @@ async function codegenInternal(abisDir, outDir, genUsage) {
|
|
34
34
|
outDir: outInternal,
|
35
35
|
allFiles: allFiles,
|
36
36
|
filesToProcess: allFiles,
|
37
|
-
|
37
|
+
contractsToGenExample: contractsToGenExample,
|
38
38
|
};
|
39
39
|
const services = {
|
40
40
|
fs,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/eth/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnG,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,aAAa,EAAY,MAAM,WAAW,CAAA;AACnD,OAAO,YAAoC,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AACpC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,MAAM,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"codegen.js","sourceRoot":"","sources":["../../../src/eth/codegen/codegen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAA;AACnG,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,aAAa,EAAY,MAAM,WAAW,CAAA;AACnD,OAAO,YAAoC,MAAM,oBAAoB,CAAA;AACrE,OAAO,KAAK,QAAQ,MAAM,UAAU,CAAA;AACpC,OAAO,IAAI,MAAM,MAAM,CAAA;AACv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AClB,cAAc,EAAE,QAAQ;QACxB,qBAAqB,EAAE,qBAAqB;KAC7C,CAAA;IACD,MAAM,QAAQ,GAAa;QACzB,EAAE;QACF,sBAAsB;QACtB,kCAAkC;QAClC,QAAQ;QACR,MAAM,EAAE,MAAM,CAAC,IAAI;KACpB,CAAA;IACD,IAAI,cAAc,GAAG,CAAC,CAAA;IAEtB,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAA;IAEvC,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,QAAQ,EAAE,MAAM,CAAC,cAAc,CAAC,CAAA;IAE9E,cAAc,IAAI,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC,CAAA;IAE3E,KAAK,MAAM,EAAE,IAAI,gBAAgB,EAAE;QACjC,cAAc,IAAI,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC,CAAA;KAClF;IAED,cAAc,IAAI,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAA;IAEpE,OAAO,cAAc,CAAA;AACvB,CAAC","sourcesContent":["import { loadFileDescriptions, processOutput, skipEmptyAbis } from 'typechain/dist/typechain/io.js'\nimport * as fs from 'fs'\nimport { DEFAULT_FLAGS, Services } from 'typechain'\nimport EthersSentio, { SentioEthersConfig } from './ethers-sentio.js'\nimport * as prettier from 'prettier'\nimport path from 'path'\nimport mkdirp from 'mkdirp'\nimport { YamlContractConfig } from '../../core/yaml-contract-config.js'\n\nexport async function codegen(abisDir: string, outDir: string, contractsToGenExample: YamlContractConfig[] = []) {\n if (!fs.existsSync(abisDir)) {\n return\n }\n console.log('Generated', await codegenInternal(abisDir, outDir, contractsToGenExample), 'files')\n}\n\nasync function codegenInternal(\n abisDir: string,\n outDir: string,\n contractsToGenExample: YamlContractConfig[]\n): Promise<number> {\n let allFiles = fs.readdirSync(abisDir)\n if (allFiles.length === 0) {\n return 0\n }\n allFiles = allFiles.map((f) => path.resolve(abisDir, f))\n\n allFiles = skipEmptyAbis(allFiles)\n if (allFiles.length === 0) {\n return 0\n }\n const outInternal = path.resolve(outDir, 'internal')\n if (!fs.existsSync(outInternal)) {\n fs.mkdirSync(outInternal, { recursive: true })\n }\n\n // skip empty paths\n const config: SentioEthersConfig = {\n cwd: process.cwd(),\n flags: DEFAULT_FLAGS,\n inputDir: abisDir,\n target: '',\n outDir: outInternal,\n allFiles: allFiles,\n filesToProcess: allFiles,\n contractsToGenExample: contractsToGenExample,\n }\n const services: Services = {\n fs,\n // @ts-ignore for test\n // prettier: { format: (s) => s },\n prettier,\n mkdirp: mkdirp.sync,\n }\n let filesGenerated = 0\n\n const target = new EthersSentio(config)\n\n const fileDescriptions = loadFileDescriptions(services, config.filesToProcess)\n\n filesGenerated += processOutput(services, config, await target.beforeRun())\n\n for (const fd of fileDescriptions) {\n filesGenerated += processOutput(services, config, await target.transformFile(fd))\n }\n\n filesGenerated += processOutput(services, config, target.afterRun())\n\n return filesGenerated\n}\n"]}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import Ethers from '@sentio/ethers-v6';
|
2
2
|
import { Config, FileDescription } from 'typechain';
|
3
|
+
import { YamlContractConfig } from '../../core/yaml-contract-config.js';
|
3
4
|
export interface SentioEthersConfig extends Config {
|
4
|
-
|
5
|
+
contractsToGenExample: YamlContractConfig[];
|
5
6
|
}
|
6
7
|
export default class EthersSentio extends Ethers.default {
|
7
8
|
constructor(config: SentioEthersConfig);
|
8
|
-
private
|
9
|
+
private processedABIs;
|
9
10
|
transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void;
|
10
11
|
afterRun(): FileDescription[];
|
11
12
|
}
|
@@ -9,7 +9,7 @@ export default class EthersSentio extends Ethers.default {
|
|
9
9
|
}
|
10
10
|
super(config);
|
11
11
|
}
|
12
|
-
|
12
|
+
processedABIs = [];
|
13
13
|
// TODO(pc): also have to override transformBinFile, transformFile
|
14
14
|
transformAbiOrFullJsonFile(file) {
|
15
15
|
const abi = extractAbi(file.contents);
|
@@ -20,7 +20,7 @@ export default class EthersSentio extends Ethers.default {
|
|
20
20
|
const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles));
|
21
21
|
const contract = parse(abi, jsonPath, documentation);
|
22
22
|
const files = super.transformAbiOrFullJsonFile(file);
|
23
|
-
this.
|
23
|
+
this.processedABIs.push(contract);
|
24
24
|
if (files !== undefined) {
|
25
25
|
// files.forEach(this.transformFilePath)
|
26
26
|
// for (const file of files) {
|
@@ -56,18 +56,43 @@ export default class EthersSentio extends Ethers.default {
|
|
56
56
|
}
|
57
57
|
}
|
58
58
|
let indexContent = '';
|
59
|
-
for (const contract of this.
|
60
|
-
|
61
|
-
indexContent +
|
62
|
-
`
|
59
|
+
for (const contract of this.processedABIs) {
|
60
|
+
const content = `
|
63
61
|
export * as ${contract.name.toLowerCase().replaceAll('-', '_')} from './${contract.name.toLowerCase()}.js'
|
64
62
|
export { ${contract.name}Processor, ${contract.name}ProcessorTemplate } from './${contract.name.toLowerCase()}.js'
|
65
63
|
`;
|
64
|
+
indexContent += content;
|
66
65
|
}
|
67
66
|
files.push({
|
68
67
|
path: join(dirname(files[0].path), '../index.ts'),
|
69
68
|
contents: indexContent,
|
70
69
|
});
|
70
|
+
const rootDir = join(dirname(files[0].path), '../../..');
|
71
|
+
const contractsToGenExample = this.cfg.contractsToGenExample;
|
72
|
+
if (contractsToGenExample.length > 0) {
|
73
|
+
const processors = this.processedABIs.map((abi) => `${abi.name}Processor`).join(',');
|
74
|
+
let exampleContent = `import { ${processors} } from './types/eth/index.js'`;
|
75
|
+
for (const contract of contractsToGenExample) {
|
76
|
+
const chainId = parseInt(contract.chain);
|
77
|
+
if (isNaN(chainId) || !isFinite(chainId)) {
|
78
|
+
continue;
|
79
|
+
}
|
80
|
+
const content = `
|
81
|
+
|
82
|
+
${contract.name}Processor.bind({ address: '${contract.address}', network: ${contract.chain} })
|
83
|
+
.onAllEvents((evt, ctx) => {
|
84
|
+
ctx.meter.Counter('event_count').add(1, { name: evt.name })
|
85
|
+
ctx.eventLogger.emit(evt.name, {
|
86
|
+
...evt.args.toObject(),
|
87
|
+
})
|
88
|
+
})`;
|
89
|
+
exampleContent += content;
|
90
|
+
}
|
91
|
+
files.push({
|
92
|
+
path: join(rootDir, 'processor.eth.example.ts'),
|
93
|
+
contents: exampleContent,
|
94
|
+
});
|
95
|
+
}
|
71
96
|
return files;
|
72
97
|
}
|
73
98
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ethers-sentio.js","sourceRoot":"","sources":["../../../src/eth/codegen/ethers-sentio.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAEL,UAAU,EACV,oBAAoB,EAEpB,KAAK,EACL,uBAAuB,GAExB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;
|
1
|
+
{"version":3,"file":"ethers-sentio.js","sourceRoot":"","sources":["../../../src/eth/codegen/ethers-sentio.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,mBAAmB,CAAA;AACtC,OAAO,EAEL,UAAU,EACV,oBAAoB,EAEpB,KAAK,EACL,uBAAuB,GAExB,MAAM,WAAW,CAAA;AAClB,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAC9C,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAOjF,MAAM,CAAC,OAAO,OAAO,YAAa,SAAQ,MAAM,CAAC,OAAO;IACtD,YAAY,MAA0B;QACpC,IAAI,CAAC,MAAM,CAAC,M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v6'\nimport {\n Config,\n extractAbi,\n extractDocumentation,\n FileDescription,\n parse,\n shortenFullJsonFilePath,\n Contract,\n} from 'typechain'\nimport { dirname, join, relative } from 'path'\nimport { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './file.js'\nimport { YamlContractConfig } from '../../core/yaml-contract-config.js'\n\nexport interface SentioEthersConfig extends Config {\n contractsToGenExample: YamlContractConfig[]\n}\n\nexport default class EthersSentio extends Ethers.default {\n constructor(config: SentioEthersConfig) {\n if (!config.outDir) {\n throw new Error('Out put path not specificed')\n }\n super(config)\n }\n\n private processedABIs: Contract[] = []\n\n // TODO(pc): also have to override transformBinFile, transformFile\n override transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void {\n const abi = extractAbi(file.contents)\n if (abi.length === 0) {\n return\n }\n\n const documentation = extractDocumentation(file.contents)\n\n const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles))\n const contract = parse(abi, jsonPath, documentation)\n const files = super.transformAbiOrFullJsonFile(file)\n this.processedABIs.push(contract)\n\n if (files !== undefined) {\n // files.forEach(this.transformFilePath)\n // for (const file of files) {\n // this.transformFilePath(file)\n // }\n\n return [\n ...files,\n {\n path: join(dirname(files[0].path), `${contract.name.toLowerCase()}-processor.ts`),\n contents: codeGenSentioFile(contract),\n },\n {\n path: join(dirname(files[0].path), '..', `${contract.name.toLowerCase()}.ts`),\n contents: codeGenIndex(contract),\n },\n {\n path: join(dirname(files[0].path), `${contract.name.toLowerCase()}-test-utils.ts`),\n contents: codeGenTestUtilsFile(contract),\n },\n ]\n }\n }\n\n override afterRun() {\n const files = super.afterRun()\n for (const [idx, file] of files.entries()) {\n if (file.path.endsWith('__factory.ts')) {\n file.contents = '// @ts-nocheck\\n' + file.contents\n } else if (file.path.endsWith('factories/index.ts')) {\n file.contents = file.contents.replaceAll(\"__factory'\", \"__factory.js'\")\n } else if (file.path.endsWith('_processor.ts')) {\n }\n }\n let indexContent = ''\n for (const contract of this.processedABIs) {\n const content = `\n export * as ${contract.name.toLowerCase().replaceAll('-', '_')} from './${contract.name.toLowerCase()}.js'\n export { ${contract.name}Processor, ${\n contract.name\n }ProcessorTemplate } from './${contract.name.toLowerCase()}.js'\n `\n indexContent += content\n }\n files.push({\n path: join(dirname(files[0].path), '../index.ts'),\n contents: indexContent,\n })\n\n const rootDir = join(dirname(files[0].path), '../../..')\n\n const contractsToGenExample = (this.cfg as SentioEthersConfig).contractsToGenExample\n if (contractsToGenExample.length > 0) {\n const processors = this.processedABIs.map((abi) => `${abi.name}Processor`).join(',')\n let exampleContent = `import { ${processors} } from './types/eth/index.js'`\n\n for (const contract of contractsToGenExample) {\n const chainId = parseInt(contract.chain)\n if (isNaN(chainId) || !isFinite(chainId)) {\n continue\n }\n\n const content = `\n\n${contract.name}Processor.bind({ address: '${contract.address}', network: ${contract.chain} })\n .onAllEvents((evt, ctx) => {\n ctx.meter.Counter('event_count').add(1, { name: evt.name })\n ctx.eventLogger.emit(evt.name, {\n ...evt.args.toObject(),\n })\n})`\n exampleContent += content\n }\n\n files.push({\n path: join(rootDir, 'processor.eth.example.ts'),\n contents: exampleContent,\n })\n }\n return files\n }\n}\n"]}
|
package/lib/eth/codegen/run.js
CHANGED
@@ -3,7 +3,7 @@ import { codegen } from './index.js';
|
|
3
3
|
if (process.argv.length > 3) {
|
4
4
|
const abisDir = process.argv[2];
|
5
5
|
const targetDir = process.argv[3];
|
6
|
-
await codegen(abisDir, targetDir,
|
6
|
+
await codegen(abisDir, targetDir, []);
|
7
7
|
}
|
8
8
|
else {
|
9
9
|
console.error('Not enough argument');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/eth/codegen/run.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjC,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../../src/eth/codegen/run.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AAEpC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;IAC3B,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACjC,MAAM,OAAO,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;CACtC;KAAM;IACL,OAAO,CAAC,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;CAChB","sourcesContent":["#!/usr/bin/env node\n\nimport { codegen } from './index.js'\n\nif (process.argv.length > 3) {\n const abisDir = process.argv[2]\n const targetDir = process.argv[3]\n await codegen(abisDir, targetDir, [])\n} else {\n console.error('Not enough argument')\n process.exit(1)\n}\n"]}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@sentio/sdk",
|
3
3
|
"license": "Apache-2.0",
|
4
|
-
"version": "2.10.0-rc.
|
4
|
+
"version": "2.10.0-rc.2",
|
5
5
|
"type": "module",
|
6
6
|
"scripts": {
|
7
7
|
"compile": "tsc && cp src/utils/*.csv lib/utils && cp src/tsup.config.ts lib",
|
@@ -23,8 +23,8 @@
|
|
23
23
|
"@project-serum/anchor": "^0.26.0",
|
24
24
|
"@sentio/bigdecimal": "^9.1.1-patch.3",
|
25
25
|
"@sentio/ethers-v6": "^1.0.25",
|
26
|
-
"@sentio/protos": "^2.10.0-rc.
|
27
|
-
"@sentio/runtime": "^2.10.0-rc.
|
26
|
+
"@sentio/protos": "^2.10.0-rc.2",
|
27
|
+
"@sentio/runtime": "^2.10.0-rc.2",
|
28
28
|
"@solana/web3.js": "^1.73.2",
|
29
29
|
"@types/prettier": "^2.7.2",
|
30
30
|
"aptos-sdk": "npm:aptos@^1.7.1",
|
@@ -37,7 +37,8 @@
|
|
37
37
|
"node-fetch": "^3.3.1",
|
38
38
|
"p-queue": "^7.3.4",
|
39
39
|
"prettier": "^2.8.4",
|
40
|
-
"typechain": "^8.0.0"
|
40
|
+
"typechain": "^8.0.0",
|
41
|
+
"yaml": "^2.2.1"
|
41
42
|
},
|
42
43
|
"devDependencies": {
|
43
44
|
"@certusone/wormhole-sdk": "^0.9.10",
|
@@ -80,5 +81,5 @@
|
|
80
81
|
"engines": {
|
81
82
|
"node": ">=16"
|
82
83
|
},
|
83
|
-
"gitHead": "
|
84
|
+
"gitHead": "6eae0493b0bec4e4022ba0621ad775736fcae8fc"
|
84
85
|
}
|
@@ -5,15 +5,20 @@ import EthersSentio, { SentioEthersConfig } from './ethers-sentio.js'
|
|
5
5
|
import * as prettier from 'prettier'
|
6
6
|
import path from 'path'
|
7
7
|
import mkdirp from 'mkdirp'
|
8
|
+
import { YamlContractConfig } from '../../core/yaml-contract-config.js'
|
8
9
|
|
9
|
-
export async function codegen(abisDir: string, outDir: string,
|
10
|
+
export async function codegen(abisDir: string, outDir: string, contractsToGenExample: YamlContractConfig[] = []) {
|
10
11
|
if (!fs.existsSync(abisDir)) {
|
11
12
|
return
|
12
13
|
}
|
13
|
-
console.log('Generated', await codegenInternal(abisDir, outDir,
|
14
|
+
console.log('Generated', await codegenInternal(abisDir, outDir, contractsToGenExample), 'files')
|
14
15
|
}
|
15
16
|
|
16
|
-
async function codegenInternal(
|
17
|
+
async function codegenInternal(
|
18
|
+
abisDir: string,
|
19
|
+
outDir: string,
|
20
|
+
contractsToGenExample: YamlContractConfig[]
|
21
|
+
): Promise<number> {
|
17
22
|
let allFiles = fs.readdirSync(abisDir)
|
18
23
|
if (allFiles.length === 0) {
|
19
24
|
return 0
|
@@ -38,7 +43,7 @@ async function codegenInternal(abisDir: string, outDir: string, genUsage: boolea
|
|
38
43
|
outDir: outInternal,
|
39
44
|
allFiles: allFiles,
|
40
45
|
filesToProcess: allFiles,
|
41
|
-
|
46
|
+
contractsToGenExample: contractsToGenExample,
|
42
47
|
}
|
43
48
|
const services: Services = {
|
44
49
|
fs,
|
@@ -10,9 +10,10 @@ import {
|
|
10
10
|
} from 'typechain'
|
11
11
|
import { dirname, join, relative } from 'path'
|
12
12
|
import { codeGenIndex, codeGenSentioFile, codeGenTestUtilsFile } from './file.js'
|
13
|
+
import { YamlContractConfig } from '../../core/yaml-contract-config.js'
|
13
14
|
|
14
15
|
export interface SentioEthersConfig extends Config {
|
15
|
-
|
16
|
+
contractsToGenExample: YamlContractConfig[]
|
16
17
|
}
|
17
18
|
|
18
19
|
export default class EthersSentio extends Ethers.default {
|
@@ -23,7 +24,7 @@ export default class EthersSentio extends Ethers.default {
|
|
23
24
|
super(config)
|
24
25
|
}
|
25
26
|
|
26
|
-
private
|
27
|
+
private processedABIs: Contract[] = []
|
27
28
|
|
28
29
|
// TODO(pc): also have to override transformBinFile, transformFile
|
29
30
|
override transformAbiOrFullJsonFile(file: FileDescription): FileDescription[] | void {
|
@@ -37,7 +38,7 @@ export default class EthersSentio extends Ethers.default {
|
|
37
38
|
const jsonPath = relative(this.cfg.inputDir, shortenFullJsonFilePath(file.path, this.cfg.allFiles))
|
38
39
|
const contract = parse(abi, jsonPath, documentation)
|
39
40
|
const files = super.transformAbiOrFullJsonFile(file)
|
40
|
-
this.
|
41
|
+
this.processedABIs.push(contract)
|
41
42
|
|
42
43
|
if (files !== undefined) {
|
43
44
|
// files.forEach(this.transformFilePath)
|
@@ -74,20 +75,50 @@ export default class EthersSentio extends Ethers.default {
|
|
74
75
|
}
|
75
76
|
}
|
76
77
|
let indexContent = ''
|
77
|
-
for (const contract of this.
|
78
|
-
|
79
|
-
indexContent +
|
80
|
-
`
|
78
|
+
for (const contract of this.processedABIs) {
|
79
|
+
const content = `
|
81
80
|
export * as ${contract.name.toLowerCase().replaceAll('-', '_')} from './${contract.name.toLowerCase()}.js'
|
82
81
|
export { ${contract.name}Processor, ${
|
83
|
-
|
84
|
-
|
82
|
+
contract.name
|
83
|
+
}ProcessorTemplate } from './${contract.name.toLowerCase()}.js'
|
85
84
|
`
|
85
|
+
indexContent += content
|
86
86
|
}
|
87
87
|
files.push({
|
88
88
|
path: join(dirname(files[0].path), '../index.ts'),
|
89
89
|
contents: indexContent,
|
90
90
|
})
|
91
|
+
|
92
|
+
const rootDir = join(dirname(files[0].path), '../../..')
|
93
|
+
|
94
|
+
const contractsToGenExample = (this.cfg as SentioEthersConfig).contractsToGenExample
|
95
|
+
if (contractsToGenExample.length > 0) {
|
96
|
+
const processors = this.processedABIs.map((abi) => `${abi.name}Processor`).join(',')
|
97
|
+
let exampleContent = `import { ${processors} } from './types/eth/index.js'`
|
98
|
+
|
99
|
+
for (const contract of contractsToGenExample) {
|
100
|
+
const chainId = parseInt(contract.chain)
|
101
|
+
if (isNaN(chainId) || !isFinite(chainId)) {
|
102
|
+
continue
|
103
|
+
}
|
104
|
+
|
105
|
+
const content = `
|
106
|
+
|
107
|
+
${contract.name}Processor.bind({ address: '${contract.address}', network: ${contract.chain} })
|
108
|
+
.onAllEvents((evt, ctx) => {
|
109
|
+
ctx.meter.Counter('event_count').add(1, { name: evt.name })
|
110
|
+
ctx.eventLogger.emit(evt.name, {
|
111
|
+
...evt.args.toObject(),
|
112
|
+
})
|
113
|
+
})`
|
114
|
+
exampleContent += content
|
115
|
+
}
|
116
|
+
|
117
|
+
files.push({
|
118
|
+
path: join(rootDir, 'processor.eth.example.ts'),
|
119
|
+
contents: exampleContent,
|
120
|
+
})
|
121
|
+
}
|
91
122
|
return files
|
92
123
|
}
|
93
124
|
}
|
package/src/eth/codegen/run.ts
CHANGED
@@ -5,7 +5,7 @@ import { codegen } from './index.js'
|
|
5
5
|
if (process.argv.length > 3) {
|
6
6
|
const abisDir = process.argv[2]
|
7
7
|
const targetDir = process.argv[3]
|
8
|
-
await codegen(abisDir, targetDir,
|
8
|
+
await codegen(abisDir, targetDir, [])
|
9
9
|
} else {
|
10
10
|
console.error('Not enough argument')
|
11
11
|
process.exit(1)
|