Skip to content

Commit

Permalink
Fix codegen for creating subgraph watcher for Sushiswap (#432)
Browse files Browse the repository at this point in the history
* Fix EthClient import in codegen and graph-node package

* Fix codegen for resolving common events between contracts
  • Loading branch information
nikugogoi authored Oct 23, 2023
1 parent 72ccaa0 commit f8d5404
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 21 deletions.
1 change: 1 addition & 0 deletions packages/codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/codegen/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/codegen/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions packages/codegen/src/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions packages/codegen/src/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages/codegen/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions packages/codegen/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)}`;
}
});

Expand Down
4 changes: 2 additions & 2 deletions packages/codegen/src/templates/indexer-template.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -42,7 +41,8 @@ import {
ResultEvent,
getResultEvent,
DatabaseInterface,
Clients
Clients,
EthClient
} from '@cerc-io/util';
{{#if (subgraphPath)}}
import { GraphWatcher } from '@cerc-io/graph-node';
Expand Down
9 changes: 7 additions & 2 deletions packages/codegen/src/utils/type-mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright 2021 Vulcanize, Inc.
//

import assert from 'assert';

import { solToGql } from './solToGql';

const _tsToGql: Map<string, string> = new Map();
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/graph-node/src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +26,7 @@ import {
createEvent,
getSubgraphConfig,
Transaction,
EthClient,
DEFAULT_LIMIT
} from '@cerc-io/util';

Expand Down
4 changes: 2 additions & 2 deletions packages/graph-node/test/utils/indexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions packages/ipld-eth-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion packages/ipld-eth-client/src/eth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -22,7 +23,7 @@ interface Vars {
addresses?: string[];
}

export class EthClient {
export class EthClient implements EthClientInterface {
_graphqlClient: GraphQLClient;
_cache: Cache | undefined;

Expand Down
4 changes: 2 additions & 2 deletions packages/rpc-eth-client/src/eth-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,7 +23,7 @@ interface Vars {
addresses?: string[];
}

export class EthClient {
export class EthClient implements EthClientInterface {
_provider: providers.JsonRpcProvider;
_cache: Cache | undefined;

Expand Down
1 change: 0 additions & 1 deletion packages/solidity-mapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit f8d5404

Please sign in to comment.