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:
Nabarun Gogoi 2023-10-23 09:23:20 +05:30 committed by GitHub
parent 72ccaa0381
commit f8d5404c25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 20 additions and 21 deletions

View File

@ -53,6 +53,7 @@ Steps:
port: 3008
# 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
solc: v0.8.0+commit.c7dfd78e

View File

@ -47,7 +47,6 @@ export class Client {
queryObject.params = queryObject.params.map((param) => {
const gqlParamType = getGqlForSol(param.type);
assert(gqlParamType);
const tsParamType = getTsForGql(gqlParamType);
assert(tsParamType);
param.type = tsParamType;

View File

@ -64,7 +64,6 @@ export class Database {
queryObject.params = queryObject.params.map((param) => {
const gqlParamType = getGqlForSol(param.type);
assert(gqlParamType);
const tsParamType = getTsForGql(gqlParamType);
assert(tsParamType);
param.type = tsParamType;

View File

@ -113,7 +113,6 @@ export class Entity {
const name = param.name;
const gqlType = getGqlForSol(param.type);
assert(gqlType);
const tsType = getTsForGql(gqlType);
assert(tsType);
const pgType = getPgForTs(tsType);
@ -153,7 +152,6 @@ export class Entity {
const baseType = getBaseType(typeName);
assert(baseType);
const gqlReturnType = getGqlForSol(baseType);
assert(gqlReturnType);
let tsReturnType = getTsForGql(gqlReturnType);
assert(tsReturnType);
const pgReturnType = getPgForTs(tsReturnType);

View File

@ -69,7 +69,6 @@ export class Indexer {
const baseType = getBaseType(typeName);
assert(baseType);
const gqlReturnType = getGqlForSol(baseType);
assert(gqlReturnType);
let tsReturnType = getTsForGql(gqlReturnType);
assert(tsReturnType);
@ -107,7 +106,6 @@ export class Indexer {
queryObject.params = queryObject.params.map((param) => {
const gqlParamType = getGqlForSol(param.type);
assert(gqlParamType);
const tsParamType = getTsForGql(gqlParamType);
assert(tsParamType);
param.type = tsParamType;

View File

@ -43,7 +43,6 @@ export class Resolvers {
queryObject.params = queryObject.params.map((param) => {
const gqlParamType = getGqlForSol(param.type);
assert(gqlParamType);
const tsParamType = getTsForGql(gqlParamType);
assert(tsParamType);
param.type = tsParamType;

View File

@ -9,7 +9,7 @@ import { Writable } from 'stream';
import { utils } from 'ethers';
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 { getBaseType, isArrayType } from './utils/helpers';
@ -251,7 +251,6 @@ export class Schema {
assert(baseTypeName);
const gqlReturnType = getGqlForSol(baseTypeName);
assert(gqlReturnType, `gql type for sol type ${baseTypeName} for ${functionName} not found`);
return {
type: gqlReturnType,
@ -510,7 +509,7 @@ export class Schema {
const newFields: any = {};
params.forEach((param: Param) => {
if (!commonFields.includes(param.name)) {
newFields[param.name] = `${getGqlForTs(param.type)}`;
newFields[param.name] = `${getGqlForSol(param.type)}`;
}
});

View File

@ -15,7 +15,6 @@ import { SelectionNode } from 'graphql';
import { JsonFragment } from '@ethersproject/abi';
import { BaseProvider } from '@ethersproject/providers';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
import {
Indexer as BaseIndexer,
@ -42,7 +41,8 @@ import {
ResultEvent,
getResultEvent,
DatabaseInterface,
Clients
Clients,
EthClient
} from '@cerc-io/util';
{{#if (subgraphPath)}}
import { GraphWatcher } from '@cerc-io/graph-node';

View File

@ -2,6 +2,8 @@
// Copyright 2021 Vulcanize, Inc.
//
import assert from 'assert';
import { solToGql } from './solToGql';
const _tsToGql: Map<string, string> = new Map();
@ -29,8 +31,11 @@ _gqlToTs.set('Boolean', 'boolean');
_gqlToTs.set('BigDecimal', 'Decimal');
_gqlToTs.set('Bytes', 'string');
function getGqlForSol (solType: string): string | undefined {
return solToGql.get(solType);
function getGqlForSol (solType: string): string {
const gqlType = solToGql.get(solType);
assert(gqlType, `GQL type for SOL type ${solType} not found`);
return gqlType;
}
function getGqlForTs (tsType: string): string | undefined {

View File

@ -11,7 +11,6 @@ import { ContractInterface, utils, providers } from 'ethers';
import { SelectionNode } from 'graphql';
import { ResultObject } from '@cerc-io/assemblyscript/lib/loader';
import { EthClient } from '@cerc-io/ipld-eth-client';
import {
getFullBlock,
BlockHeight,
@ -27,6 +26,7 @@ import {
createEvent,
getSubgraphConfig,
Transaction,
EthClient,
DEFAULT_LIMIT
} from '@cerc-io/util';

View File

@ -16,9 +16,9 @@ import {
StateInterface,
getResultEvent,
ResultEvent,
StateKind
StateKind,
EthClient
} from '@cerc-io/util';
import { EthClient } from '@cerc-io/ipld-eth-client';
import { GetStorageAt, getStorageValue, MappingKey, StorageLayout } from '@cerc-io/solidity-mapper';
export class Indexer implements IndexerInterface {

View File

@ -21,6 +21,7 @@
"dependencies": {
"@apollo/client": "^3.7.1",
"@cerc-io/cache": "^0.2.66",
"@cerc-io/util": "^0.2.66",
"cross-fetch": "^3.1.4",
"debug": "^4.3.1",
"ethers": "^5.4.4",

View File

@ -5,6 +5,7 @@
import assert from 'assert';
import { Cache } from '@cerc-io/cache';
import { EthClient as EthClientInterface } from '@cerc-io/util';
import ethQueries from './eth-queries';
import { padKey } from './utils';
@ -22,7 +23,7 @@ interface Vars {
addresses?: string[];
}
export class EthClient {
export class EthClient implements EthClientInterface {
_graphqlClient: GraphQLClient;
_cache: Cache | undefined;

View File

@ -7,7 +7,7 @@ import { errors, providers, utils } from 'ethers';
import { TransactionReceipt } from '@ethersproject/abstract-provider';
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';
export interface Config {
@ -23,7 +23,7 @@ interface Vars {
addresses?: string[];
}
export class EthClient {
export class EthClient implements EthClientInterface {
_provider: providers.JsonRpcProvider;
_cache: Cache | undefined;

View File

@ -4,7 +4,6 @@
"main": "dist/index.js",
"license": "AGPL-3.0",
"devDependencies": {
"@cerc-io/ipld-eth-client": "^0.2.66",
"@ethersproject/abi": "^5.3.0",
"@nomiclabs/hardhat-ethers": "^2.0.2",
"@nomiclabs/hardhat-waffle": "^2.0.1",