Substrate processor for Reef DEXes based on Uniswap V2 contracts. Built upon squid Frontier EVM template and adapted to be used with Reef network.
# 1. Install dependencies
npm install
# 2. Compile typescript files
make build
# 3. Start target Postgres database and detach
# DB will be available at localhost:23799/evm_events
make up
# 4. Start the processor
make process
# 5. In a separate terminal, start graphql server
# GraphQL API will be available at http://localhost:4350/graphql
make serve
# 6. Stop and destroy target Postgres database
make downDelete migration files from db/migrations directory and define the schema of the target database via schema.graphql file, replacing the sample definition.
Schema definition consists of regular graphql type declarations annotated with custom directives.
Full description of schema.graphql dialect is available here.
Mapping developers use TypeORM EntityManager
to interact with target database during data processing. All necessary entity classes are
generated by the squid framework from schema.graphql. This is done by running the following command:
make codegenIt is necessary to import the respective ABI definition to decode EVM logs.
Delete all the contents in src/abi and insert the JSON ABI definition of the contract to index.
To generate a type-safe facade class to decode EVM logs execute the following command:
npx squid-evm-typegen src/abi src/abi/{YOUR_CONTRACT_NAME}.jsonAnd replace the following code in generated the generated abi.support.ts file:
let result = await this._chain.client.call('eth_call', [
{ to: this.address, data },
'0x' + this.blockHeight.toString(16)
])by
let result = await this._chain.client.call('evm_call', [
{to: this.address, data, from: undefined, storageLimit: 0}
])Squid tools assume a certain project layout.
- All compiled js files must reside in
liband all TypeScript sources insrc. The layout oflibmust reflectsrc. - All TypeORM classes must be exported by
src/model/index.ts(lib/modelmodule). - Database schema must be defined in
schema.graphql. - Database migrations must reside in
db/migrationsand must be plain js files. sqd(1)andsquid-*(1)executables consult.envfile for a number of environment variables.
It is possible to extend squid-graphql-server(1) with custom
type-graphql resolvers and to add request validation.
More details will be added later.
- To deploy a Squid execute
sqd deploy -m <path_to_manifest_file>.