watcher-ts/packages/codegen
Ashwin Phatak 92b7967895
Generating eth_call based lazy watcher (#249)
* Add entity generation.

* Add resolvers generation.

* Add queries in resolvers generation.

* Add indexer generation.

* Extract helper code in utils.

* Add server and artifacts generation.

* Fix solidity-flattener issue.

* Update readme and cleanup misc files.

* Add queries to entity generation.

* Add database generation.

* Use snakecase in database.

* Add readme generation.

* Change template file names.

* Add method descriptions.

* Change mode to eth_call in readme.

Co-authored-by: prathamesh <prathamesh.musale0@gmail.com>
2021-09-23 16:55:46 +05:30
..
src Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
.eslintignore CLI to flatten and generate GQL schema from Solidity file (#245) 2021-09-16 17:06:10 +05:30
.eslintrc.json CLI to flatten and generate GQL schema from Solidity file (#245) 2021-09-16 17:06:10 +05:30
package.json Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
README.md Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30
tsconfig.json Generating eth_call based lazy watcher (#249) 2021-09-23 16:55:46 +05:30

Code Generator

Setup

  • Run the following command to install required packages:

    yarn
    

Run

  • Run the following command to generate a watcher from a contract file:

    yarn codegen --input-file <input-file-path> --contract-name <contract-name> --output-folder [output-folder] --mode [eth_call | storage] --flatten [true | false]
    
    • input-file(alias: i): Input contract file path or an URL (required).
    • contract-name(alias: c): Main contract name (required).
    • output-folder(alias: o): Output folder path. (logs output using stdout if not provided).
    • mode(alias: m): Code generation mode (default: storage).
    • flatten(alias: f): Flatten the input contract file (default: true).

    Note: When passed an URL as input-file, it is assumed that it points to an already flattened contract file.

    Examples:

    yarn codegen --input-file ./test/examples/contracts/ERC20.sol --contract-name ERC20 --output-folder ../my-erc20-watcher --mode eth_call
    
    yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../my-erc721-watcher --mode eth_call
    

Demo

  • Install required packages:

    yarn
    
  • Generate a watcher from a contract file:

    yarn codegen --input-file ../../node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol --contract-name ERC20 --output-folder ../demo-erc20-watcher --mode eth_call
    

    This will create a folder called demo-erc20-watcher containing the generated code at the specified path. Follow the steps in demo-erc20-watcher/README.md to setup and run the generated watcher.

  • Generate a watcher from a flattened contract file from an URL:

    yarn codegen --input-file https://git.io/Jupci --contract-name ERC721 --output-folder ../demo-erc721-watcher --mode eth_call
    

References

Known Issues

  • Currently, node-fetch v2.6.2 is being used to fetch from URLs as v3.0.0 is an ESM-only module and ts-node transpiles to import it using require.