mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-02-02 08:12:49 +00:00
Fix codegen for creating subgraph watcher for Sushiswap (#432)
* Fix EthClient import in codegen and graph-node package * Fix codegen for resolving common events between contracts
This commit is contained in:
parent
72ccaa0381
commit
f8d5404c25
@ -53,6 +53,7 @@ Steps:
|
|||||||
port: 3008
|
port: 3008
|
||||||
|
|
||||||
# Solc version to use (optional)
|
# Solc version to use (optional)
|
||||||
|
# Use longVersion prefixed with v from the release list https://binaries.soliditylang.org/bin/list.json
|
||||||
# If not defined, uses solc version listed in dependencies
|
# If not defined, uses solc version listed in dependencies
|
||||||
solc: v0.8.0+commit.c7dfd78e
|
solc: v0.8.0+commit.c7dfd78e
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ export class Client {
|
|||||||
|
|
||||||
queryObject.params = queryObject.params.map((param) => {
|
queryObject.params = queryObject.params.map((param) => {
|
||||||
const gqlParamType = getGqlForSol(param.type);
|
const gqlParamType = getGqlForSol(param.type);
|
||||||
assert(gqlParamType);
|
|
||||||
const tsParamType = getTsForGql(gqlParamType);
|
const tsParamType = getTsForGql(gqlParamType);
|
||||||
assert(tsParamType);
|
assert(tsParamType);
|
||||||
param.type = tsParamType;
|
param.type = tsParamType;
|
||||||
|
@ -64,7 +64,6 @@ export class Database {
|
|||||||
|
|
||||||
queryObject.params = queryObject.params.map((param) => {
|
queryObject.params = queryObject.params.map((param) => {
|
||||||
const gqlParamType = getGqlForSol(param.type);
|
const gqlParamType = getGqlForSol(param.type);
|
||||||
assert(gqlParamType);
|
|
||||||
const tsParamType = getTsForGql(gqlParamType);
|
const tsParamType = getTsForGql(gqlParamType);
|
||||||
assert(tsParamType);
|
assert(tsParamType);
|
||||||
param.type = tsParamType;
|
param.type = tsParamType;
|
||||||
|
@ -113,7 +113,6 @@ export class Entity {
|
|||||||
const name = param.name;
|
const name = param.name;
|
||||||
|
|
||||||
const gqlType = getGqlForSol(param.type);
|
const gqlType = getGqlForSol(param.type);
|
||||||
assert(gqlType);
|
|
||||||
const tsType = getTsForGql(gqlType);
|
const tsType = getTsForGql(gqlType);
|
||||||
assert(tsType);
|
assert(tsType);
|
||||||
const pgType = getPgForTs(tsType);
|
const pgType = getPgForTs(tsType);
|
||||||
@ -153,7 +152,6 @@ export class Entity {
|
|||||||
const baseType = getBaseType(typeName);
|
const baseType = getBaseType(typeName);
|
||||||
assert(baseType);
|
assert(baseType);
|
||||||
const gqlReturnType = getGqlForSol(baseType);
|
const gqlReturnType = getGqlForSol(baseType);
|
||||||
assert(gqlReturnType);
|
|
||||||
let tsReturnType = getTsForGql(gqlReturnType);
|
let tsReturnType = getTsForGql(gqlReturnType);
|
||||||
assert(tsReturnType);
|
assert(tsReturnType);
|
||||||
const pgReturnType = getPgForTs(tsReturnType);
|
const pgReturnType = getPgForTs(tsReturnType);
|
||||||
|
@ -69,7 +69,6 @@ export class Indexer {
|
|||||||
const baseType = getBaseType(typeName);
|
const baseType = getBaseType(typeName);
|
||||||
assert(baseType);
|
assert(baseType);
|
||||||
const gqlReturnType = getGqlForSol(baseType);
|
const gqlReturnType = getGqlForSol(baseType);
|
||||||
assert(gqlReturnType);
|
|
||||||
let tsReturnType = getTsForGql(gqlReturnType);
|
let tsReturnType = getTsForGql(gqlReturnType);
|
||||||
assert(tsReturnType);
|
assert(tsReturnType);
|
||||||
|
|
||||||
@ -107,7 +106,6 @@ export class Indexer {
|
|||||||
|
|
||||||
queryObject.params = queryObject.params.map((param) => {
|
queryObject.params = queryObject.params.map((param) => {
|
||||||
const gqlParamType = getGqlForSol(param.type);
|
const gqlParamType = getGqlForSol(param.type);
|
||||||
assert(gqlParamType);
|
|
||||||
const tsParamType = getTsForGql(gqlParamType);
|
const tsParamType = getTsForGql(gqlParamType);
|
||||||
assert(tsParamType);
|
assert(tsParamType);
|
||||||
param.type = tsParamType;
|
param.type = tsParamType;
|
||||||
|
@ -43,7 +43,6 @@ export class Resolvers {
|
|||||||
|
|
||||||
queryObject.params = queryObject.params.map((param) => {
|
queryObject.params = queryObject.params.map((param) => {
|
||||||
const gqlParamType = getGqlForSol(param.type);
|
const gqlParamType = getGqlForSol(param.type);
|
||||||
assert(gqlParamType);
|
|
||||||
const tsParamType = getTsForGql(gqlParamType);
|
const tsParamType = getTsForGql(gqlParamType);
|
||||||
assert(tsParamType);
|
assert(tsParamType);
|
||||||
param.type = tsParamType;
|
param.type = tsParamType;
|
||||||
|
@ -9,7 +9,7 @@ import { Writable } from 'stream';
|
|||||||
import { utils } from 'ethers';
|
import { utils } from 'ethers';
|
||||||
import { VariableDeclaration } from '@solidity-parser/parser/dist/src/ast-types';
|
import { VariableDeclaration } from '@solidity-parser/parser/dist/src/ast-types';
|
||||||
|
|
||||||
import { getGqlForTs, getGqlForSol } from './utils/type-mappings';
|
import { getGqlForSol } from './utils/type-mappings';
|
||||||
import { Param } from './utils/types';
|
import { Param } from './utils/types';
|
||||||
import { getBaseType, isArrayType } from './utils/helpers';
|
import { getBaseType, isArrayType } from './utils/helpers';
|
||||||
|
|
||||||
@ -251,7 +251,6 @@ export class Schema {
|
|||||||
assert(baseTypeName);
|
assert(baseTypeName);
|
||||||
|
|
||||||
const gqlReturnType = getGqlForSol(baseTypeName);
|
const gqlReturnType = getGqlForSol(baseTypeName);
|
||||||
assert(gqlReturnType, `gql type for sol type ${baseTypeName} for ${functionName} not found`);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: gqlReturnType,
|
type: gqlReturnType,
|
||||||
@ -510,7 +509,7 @@ export class Schema {
|
|||||||
const newFields: any = {};
|
const newFields: any = {};
|
||||||
params.forEach((param: Param) => {
|
params.forEach((param: Param) => {
|
||||||
if (!commonFields.includes(param.name)) {
|
if (!commonFields.includes(param.name)) {
|
||||||
newFields[param.name] = `${getGqlForTs(param.type)}`;
|
newFields[param.name] = `${getGqlForSol(param.type)}`;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ import { SelectionNode } from 'graphql';
|
|||||||
|
|
||||||
import { JsonFragment } from '@ethersproject/abi';
|
import { JsonFragment } from '@ethersproject/abi';
|
||||||
import { BaseProvider } from '@ethersproject/providers';
|
import { BaseProvider } from '@ethersproject/providers';
|
||||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
|
||||||
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
||||||
import {
|
import {
|
||||||
Indexer as BaseIndexer,
|
Indexer as BaseIndexer,
|
||||||
@ -42,7 +41,8 @@ import {
|
|||||||
ResultEvent,
|
ResultEvent,
|
||||||
getResultEvent,
|
getResultEvent,
|
||||||
DatabaseInterface,
|
DatabaseInterface,
|
||||||
Clients
|
Clients,
|
||||||
|
EthClient
|
||||||
} from '@cerc-io/util';
|
} from '@cerc-io/util';
|
||||||
{{#if (subgraphPath)}}
|
{{#if (subgraphPath)}}
|
||||||
import { GraphWatcher } from '@cerc-io/graph-node';
|
import { GraphWatcher } from '@cerc-io/graph-node';
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
// Copyright 2021 Vulcanize, Inc.
|
// Copyright 2021 Vulcanize, Inc.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
import { solToGql } from './solToGql';
|
import { solToGql } from './solToGql';
|
||||||
|
|
||||||
const _tsToGql: Map<string, string> = new Map();
|
const _tsToGql: Map<string, string> = new Map();
|
||||||
@ -29,8 +31,11 @@ _gqlToTs.set('Boolean', 'boolean');
|
|||||||
_gqlToTs.set('BigDecimal', 'Decimal');
|
_gqlToTs.set('BigDecimal', 'Decimal');
|
||||||
_gqlToTs.set('Bytes', 'string');
|
_gqlToTs.set('Bytes', 'string');
|
||||||
|
|
||||||
function getGqlForSol (solType: string): string | undefined {
|
function getGqlForSol (solType: string): string {
|
||||||
return solToGql.get(solType);
|
const gqlType = solToGql.get(solType);
|
||||||
|
assert(gqlType, `GQL type for SOL type ${solType} not found`);
|
||||||
|
|
||||||
|
return gqlType;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGqlForTs (tsType: string): string | undefined {
|
function getGqlForTs (tsType: string): string | undefined {
|
||||||
|
@ -11,7 +11,6 @@ import { ContractInterface, utils, providers } from 'ethers';
|
|||||||
import { SelectionNode } from 'graphql';
|
import { SelectionNode } from 'graphql';
|
||||||
|
|
||||||
import { ResultObject } from '@cerc-io/assemblyscript/lib/loader';
|
import { ResultObject } from '@cerc-io/assemblyscript/lib/loader';
|
||||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
|
||||||
import {
|
import {
|
||||||
getFullBlock,
|
getFullBlock,
|
||||||
BlockHeight,
|
BlockHeight,
|
||||||
@ -27,6 +26,7 @@ import {
|
|||||||
createEvent,
|
createEvent,
|
||||||
getSubgraphConfig,
|
getSubgraphConfig,
|
||||||
Transaction,
|
Transaction,
|
||||||
|
EthClient,
|
||||||
DEFAULT_LIMIT
|
DEFAULT_LIMIT
|
||||||
} from '@cerc-io/util';
|
} from '@cerc-io/util';
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ import {
|
|||||||
StateInterface,
|
StateInterface,
|
||||||
getResultEvent,
|
getResultEvent,
|
||||||
ResultEvent,
|
ResultEvent,
|
||||||
StateKind
|
StateKind,
|
||||||
|
EthClient
|
||||||
} from '@cerc-io/util';
|
} from '@cerc-io/util';
|
||||||
import { EthClient } from '@cerc-io/ipld-eth-client';
|
|
||||||
import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
|
||||||
|
|
||||||
export class Indexer implements IndexerInterface {
|
export class Indexer implements IndexerInterface {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@apollo/client": "^3.7.1",
|
"@apollo/client": "^3.7.1",
|
||||||
"@cerc-io/cache": "^0.2.66",
|
"@cerc-io/cache": "^0.2.66",
|
||||||
|
"@cerc-io/util": "^0.2.66",
|
||||||
"cross-fetch": "^3.1.4",
|
"cross-fetch": "^3.1.4",
|
||||||
"debug": "^4.3.1",
|
"debug": "^4.3.1",
|
||||||
"ethers": "^5.4.4",
|
"ethers": "^5.4.4",
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import assert from 'assert';
|
import assert from 'assert';
|
||||||
|
|
||||||
import { Cache } from '@cerc-io/cache';
|
import { Cache } from '@cerc-io/cache';
|
||||||
|
import { EthClient as EthClientInterface } from '@cerc-io/util';
|
||||||
|
|
||||||
import ethQueries from './eth-queries';
|
import ethQueries from './eth-queries';
|
||||||
import { padKey } from './utils';
|
import { padKey } from './utils';
|
||||||
@ -22,7 +23,7 @@ interface Vars {
|
|||||||
addresses?: string[];
|
addresses?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EthClient {
|
export class EthClient implements EthClientInterface {
|
||||||
_graphqlClient: GraphQLClient;
|
_graphqlClient: GraphQLClient;
|
||||||
_cache: Cache | undefined;
|
_cache: Cache | undefined;
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { errors, providers, utils } from 'ethers';
|
|||||||
import { TransactionReceipt } from '@ethersproject/abstract-provider';
|
import { TransactionReceipt } from '@ethersproject/abstract-provider';
|
||||||
|
|
||||||
import { Cache } from '@cerc-io/cache';
|
import { Cache } from '@cerc-io/cache';
|
||||||
import { encodeHeader, escapeHexString, getRawTransaction } from '@cerc-io/util';
|
import { encodeHeader, escapeHexString, getRawTransaction, EthClient as EthClientInterface } from '@cerc-io/util';
|
||||||
import { padKey } from '@cerc-io/ipld-eth-client';
|
import { padKey } from '@cerc-io/ipld-eth-client';
|
||||||
|
|
||||||
export interface Config {
|
export interface Config {
|
||||||
@ -23,7 +23,7 @@ interface Vars {
|
|||||||
addresses?: string[];
|
addresses?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EthClient {
|
export class EthClient implements EthClientInterface {
|
||||||
_provider: providers.JsonRpcProvider;
|
_provider: providers.JsonRpcProvider;
|
||||||
_cache: Cache | undefined;
|
_cache: Cache | undefined;
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cerc-io/ipld-eth-client": "^0.2.66",
|
|
||||||
"@ethersproject/abi": "^5.3.0",
|
"@ethersproject/abi": "^5.3.0",
|
||||||
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
"@nomiclabs/hardhat-ethers": "^2.0.2",
|
||||||
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
"@nomiclabs/hardhat-waffle": "^2.0.1",
|
||||||
|
Loading…
Reference in New Issue
Block a user