feat: lint

This commit is contained in:
nikdementev 2021-06-09 17:39:13 +03:00 committed by 0xZick 地方分権化
parent e41ccc05a4
commit f48236f744
20 changed files with 1281 additions and 203 deletions

46
.eslintrc.js Normal file
View File

@ -0,0 +1,46 @@
module.exports = {
env: {
es6: true,
node: true,
},
plugins: ['import'],
extends: [
'eslint:recommended',
'plugin:import/errors',
'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:prettier/recommended', // Enables eslint-plugin-prettier and eslint-config-prettier. This will display prettier errors as ESLint errors. Make sure this is always the last configuration in the extends array.
],
parserOptions: {
ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
},
settings: {
'import/parsers': {
'@typescript-eslint/parser': ['.ts', '.tsx'],
},
'import/resolver': {
// use <root>/tsconfig.json
typescript: {
alwaysTryTypes: true, // always try to resolve types under `<roo/>@types` directory even it doesn't contain any source code, like `@types/unist`
},
},
},
ignorePatterns: ['**/generated/**/*', '**/build/**/*'],
rules: {
quotes: ['error', 'single'],
'import/no-unresolved': 2,
'no-undef': 2,
'prefer-const': 0,
semi: ['error', 'always'],
'no-console': 0,
'@typescript-eslint/explicit-member-accessibility': 0,
'@typescript-eslint/camelcase': 0,
'@typescript-eslint/class-name-casing': 0,
'@typescript-eslint/no-var-requires': 0,
},
};

7
.prettierrc.js Normal file
View File

@ -0,0 +1,7 @@
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
tabWidth: 2,
};

View File

@ -21,9 +21,7 @@ program
const dataSourcesPath = path.join(__dirname, 'mustache', 'templates', subgraph, 'create-yaml.js');
const subgraphDataSourcesData = require(dataSourcesPath);
const dataSourcesData = [
...subgraphDataSourcesData.createYaml(env),
];
const dataSourcesData = [...subgraphDataSourcesData.createYaml(env)];
const indexData = require(baseIndexPath);

View File

@ -1,14 +1,6 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
import { ethereum, JSONValue, TypedMap, Entity, Bytes, Address, BigInt } from '@graphprotocol/graph-ts';
export class Echo extends ethereum.Event {
get params(): Echo__Params {
@ -34,6 +26,6 @@ export class Echo__Params {
export class Echoer extends ethereum.SmartContract {
static bind(address: Address): Echoer {
return new Echoer("Echoer", address);
return new Echoer('Echoer', address);
}
}

View File

@ -1,14 +1,6 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
import { ethereum, JSONValue, TypedMap, Entity, Bytes, Address, BigInt } from '@graphprotocol/graph-ts';
export class Deposit extends ethereum.Event {
get params(): Deposit__Params {
@ -68,6 +60,6 @@ export class Withdrawal__Params {
export class Instance extends ethereum.SmartContract {
static bind(address: Address): Instance {
return new Instance("Instance", address);
return new Instance('Instance', address);
}
}

View File

@ -1,14 +1,6 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
ethereum,
JSONValue,
TypedMap,
Entity,
Bytes,
Address,
BigInt
} from "@graphprotocol/graph-ts";
import { ethereum, JSONValue, TypedMap, Entity, Bytes, Address, BigInt } from '@graphprotocol/graph-ts';
export class EncryptedNote extends ethereum.Event {
get params(): EncryptedNote__Params {
@ -34,6 +26,6 @@ export class EncryptedNote__Params {
export class Proxy extends ethereum.SmartContract {
static bind(address: Address): Proxy {
return new Proxy("Proxy", address);
return new Proxy('Proxy', address);
}
}

View File

@ -1,3 +1,3 @@
export * from './Proxy/Proxy'
export * from './Echoer/Echoer'
export * from './Instance/Instance'
export * from './Proxy/Proxy';
export * from './Echoer/Echoer';
export * from './Instance/Instance';

View File

@ -1,344 +1,333 @@
// THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
import {
TypedMap,
Entity,
Value,
ValueKind,
store,
Address,
Bytes,
BigInt,
BigDecimal
} from "@graphprotocol/graph-ts";
import { TypedMap, Entity, Value, ValueKind, store, Address, Bytes, BigInt, BigDecimal } from '@graphprotocol/graph-ts';
export class Deposit extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
this.set('id', Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save Deposit entity without an ID");
let id = this.get('id');
assert(id !== null, 'Cannot save Deposit entity without an ID');
assert(
id.kind == ValueKind.STRING,
"Cannot save Deposit entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
'Cannot save Deposit entity with non-string ID. ' + 'Considering using .toHex() to convert the "id" to a string.',
);
store.set("Deposit", id.toString(), this);
store.set('Deposit', id.toString(), this);
}
static load(id: string): Deposit | null {
return store.get("Deposit", id) as Deposit | null;
return store.get('Deposit', id) as Deposit | null;
}
get id(): string {
let value = this.get("id");
let value = this.get('id');
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
this.set('id', Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
let value = this.get('index');
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
this.set('index', Value.fromBigInt(value));
}
get amount(): string {
let value = this.get("amount");
let value = this.get('amount');
return value.toString();
}
set amount(value: string) {
this.set("amount", Value.fromString(value));
this.set('amount', Value.fromString(value));
}
get currency(): string {
let value = this.get("currency");
let value = this.get('currency');
return value.toString();
}
set currency(value: string) {
this.set("currency", Value.fromString(value));
this.set('currency', Value.fromString(value));
}
get commitment(): Bytes {
let value = this.get("commitment");
let value = this.get('commitment');
return value.toBytes();
}
set commitment(value: Bytes) {
this.set("commitment", Value.fromBytes(value));
this.set('commitment', Value.fromBytes(value));
}
get timestamp(): BigInt {
let value = this.get("timestamp");
let value = this.get('timestamp');
return value.toBigInt();
}
set timestamp(value: BigInt) {
this.set("timestamp", Value.fromBigInt(value));
this.set('timestamp', Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
let value = this.get('blockNumber');
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
this.set('blockNumber', Value.fromBigInt(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
let value = this.get('transactionHash');
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
this.set('transactionHash', Value.fromBytes(value));
}
}
export class Withdrawal extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
this.set('id', Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save Withdrawal entity without an ID");
let id = this.get('id');
assert(id !== null, 'Cannot save Withdrawal entity without an ID');
assert(
id.kind == ValueKind.STRING,
"Cannot save Withdrawal entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
'Cannot save Withdrawal entity with non-string ID. ' +
'Considering using .toHex() to convert the "id" to a string.',
);
store.set("Withdrawal", id.toString(), this);
store.set('Withdrawal', id.toString(), this);
}
static load(id: string): Withdrawal | null {
return store.get("Withdrawal", id) as Withdrawal | null;
return store.get('Withdrawal', id) as Withdrawal | null;
}
get id(): string {
let value = this.get("id");
let value = this.get('id');
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
this.set('id', Value.fromString(value));
}
get to(): Bytes {
let value = this.get("to");
let value = this.get('to');
return value.toBytes();
}
set to(value: Bytes) {
this.set("to", Value.fromBytes(value));
this.set('to', Value.fromBytes(value));
}
get fee(): BigInt {
let value = this.get("fee");
let value = this.get('fee');
return value.toBigInt();
}
set fee(value: BigInt) {
this.set("fee", Value.fromBigInt(value));
this.set('fee', Value.fromBigInt(value));
}
get index(): BigInt {
let value = this.get("index");
let value = this.get('index');
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
this.set('index', Value.fromBigInt(value));
}
get amount(): string {
let value = this.get("amount");
let value = this.get('amount');
return value.toString();
}
set amount(value: string) {
this.set("amount", Value.fromString(value));
this.set('amount', Value.fromString(value));
}
get currency(): string {
let value = this.get("currency");
let value = this.get('currency');
return value.toString();
}
set currency(value: string) {
this.set("currency", Value.fromString(value));
this.set('currency', Value.fromString(value));
}
get nullifier(): Bytes {
let value = this.get("nullifier");
let value = this.get('nullifier');
return value.toBytes();
}
set nullifier(value: Bytes) {
this.set("nullifier", Value.fromBytes(value));
this.set('nullifier', Value.fromBytes(value));
}
get timestamp(): BigInt {
let value = this.get("timestamp");
let value = this.get('timestamp');
return value.toBigInt();
}
set timestamp(value: BigInt) {
this.set("timestamp", Value.fromBigInt(value));
this.set('timestamp', Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
let value = this.get('blockNumber');
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
this.set('blockNumber', Value.fromBigInt(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
let value = this.get('transactionHash');
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
this.set('transactionHash', Value.fromBytes(value));
}
}
export class EncryptedNote extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
this.set('id', Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save EncryptedNote entity without an ID");
let id = this.get('id');
assert(id !== null, 'Cannot save EncryptedNote entity without an ID');
assert(
id.kind == ValueKind.STRING,
"Cannot save EncryptedNote entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
'Cannot save EncryptedNote entity with non-string ID. ' +
'Considering using .toHex() to convert the "id" to a string.',
);
store.set("EncryptedNote", id.toString(), this);
store.set('EncryptedNote', id.toString(), this);
}
static load(id: string): EncryptedNote | null {
return store.get("EncryptedNote", id) as EncryptedNote | null;
return store.get('EncryptedNote', id) as EncryptedNote | null;
}
get id(): string {
let value = this.get("id");
let value = this.get('id');
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
this.set('id', Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
let value = this.get('index');
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
this.set('index', Value.fromBigInt(value));
}
get blockNumber(): BigInt {
let value = this.get("blockNumber");
let value = this.get('blockNumber');
return value.toBigInt();
}
set blockNumber(value: BigInt) {
this.set("blockNumber", Value.fromBigInt(value));
this.set('blockNumber', Value.fromBigInt(value));
}
get encryptedNote(): Bytes {
let value = this.get("encryptedNote");
let value = this.get('encryptedNote');
return value.toBytes();
}
set encryptedNote(value: Bytes) {
this.set("encryptedNote", Value.fromBytes(value));
this.set('encryptedNote', Value.fromBytes(value));
}
get transactionHash(): Bytes {
let value = this.get("transactionHash");
let value = this.get('transactionHash');
return value.toBytes();
}
set transactionHash(value: Bytes) {
this.set("transactionHash", Value.fromBytes(value));
this.set('transactionHash', Value.fromBytes(value));
}
}
export class NoteAccount extends Entity {
constructor(id: string) {
super();
this.set("id", Value.fromString(id));
this.set('id', Value.fromString(id));
}
save(): void {
let id = this.get("id");
assert(id !== null, "Cannot save NoteAccount entity without an ID");
let id = this.get('id');
assert(id !== null, 'Cannot save NoteAccount entity without an ID');
assert(
id.kind == ValueKind.STRING,
"Cannot save NoteAccount entity with non-string ID. " +
'Considering using .toHex() to convert the "id" to a string.'
'Cannot save NoteAccount entity with non-string ID. ' +
'Considering using .toHex() to convert the "id" to a string.',
);
store.set("NoteAccount", id.toString(), this);
store.set('NoteAccount', id.toString(), this);
}
static load(id: string): NoteAccount | null {
return store.get("NoteAccount", id) as NoteAccount | null;
return store.get('NoteAccount', id) as NoteAccount | null;
}
get id(): string {
let value = this.get("id");
let value = this.get('id');
return value.toString();
}
set id(value: string) {
this.set("id", Value.fromString(value));
this.set('id', Value.fromString(value));
}
get index(): BigInt {
let value = this.get("index");
let value = this.get('index');
return value.toBigInt();
}
set index(value: BigInt) {
this.set("index", Value.fromBigInt(value));
this.set('index', Value.fromBigInt(value));
}
get address(): Bytes {
let value = this.get("address");
let value = this.get('address');
return value.toBytes();
}
set address(value: Bytes) {
this.set("address", Value.fromBytes(value));
this.set('address', Value.fromBytes(value));
}
get encryptedAccount(): Bytes {
let value = this.get("encryptedAccount");
let value = this.get('encryptedAccount');
return value.toBytes();
}
set encryptedAccount(value: Bytes) {
this.set("encryptedAccount", Value.fromBytes(value));
this.set('encryptedAccount', Value.fromBytes(value));
}
}

View File

@ -1,4 +1,3 @@
module.exports = {
base: {
specVersion: '0.0.2',
@ -11,7 +10,7 @@ module.exports = {
name: 'Instance',
network: 'bsc',
dataSourceKind: 'ethereum/contract',
address: "0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7",
address: '0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7',
abi: 'Instance',
startBlock: 7941563,
mapping: {
@ -31,16 +30,16 @@ module.exports = {
{
event: 'Withdrawal(address,bytes32,indexed address,uint256)',
handler: 'handleWithdrawal',
}
},
],
file: './src/mapping-proxy.ts',
}
},
},
{
name: 'Echoer',
network: 'bsc',
dataSourceKind: 'ethereum/contract',
address: "0x60eaCBd5535ADB86955A0154E44Aded78F161643",
address: '0x60eaCBd5535ADB86955A0154E44Aded78F161643',
abi: 'Echoer',
startBlock: 7941563,
mapping: {
@ -59,12 +58,12 @@ module.exports = {
},
],
file: './src/mapping-echo-account.ts',
}
},
},
{
name: 'Proxy',
dataSourceKind: 'ethereum/contract',
address: "0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d",
address: '0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d',
abi: 'Proxy',
startBlock: 7941563,
mapping: {
@ -83,7 +82,7 @@ module.exports = {
},
],
file: './src/mapping-encrypted-note.ts',
}
},
},
],
};

View File

@ -1,17 +1,17 @@
const createStartBlock = (blocks, env) => {
if (env === 'test') {
return blocks.exchanger
? blocks.exchanger.test
? blocks.exchanger.test
? blocks.exchanger.test
: blocks.exchanger.prod
: blocks.test || blocks.prod
: blocks.exchanger.prod
: blocks.test || blocks.prod;
} else if (env === 'prod') {
return blocks.exchanger && blocks.exchanger.prod ? blocks.exchanger.prod : blocks.prod
return blocks.exchanger && blocks.exchanger.prod ? blocks.exchanger.prod : blocks.prod;
} else {
throw new Error('Invalid env for creating a yaml file')
throw new Error('Invalid env for creating a yaml file');
}
}
};
module.exports = {
createStartBlock,
}
};

View File

@ -1,8 +1,3 @@
const duplicateStartBlocks = {
one: 10773070,
two: 10873070,
};
const contracts = [
{
prod: 7942402,
@ -10,8 +5,8 @@ const contracts = [
network: 'bsc',
currency: 'bsc',
name: 'Instance',
address: "'0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d'",
address: '0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d',
},
]
];
module.exports = contracts;

View File

@ -5,7 +5,6 @@ const Contracts = require('./contracts');
module.exports = {
createYaml: (env) => {
const createInstanceBlock = ({ name, network, startBlocks, address }) => ({
name,
network,
@ -17,8 +16,8 @@ module.exports = {
abis: [
{
name: 'Instance',
path: '../abis/Instance.json'
}
path: '../abis/Instance.json',
},
],
events: [
{
@ -28,7 +27,7 @@ module.exports = {
{
event: 'Withdrawal(address,bytes32,indexed address,uint256)',
handler: 'handleWithdrawal',
}
},
],
});
@ -51,8 +50,8 @@ module.exports = {
return Contracts.map(({ prod, name, network, address }) => {
const startBlocks = { prod };
if (network === env) {
return createInstanceBlock({ name, startBlocks, network, address })
return createInstanceBlock({ name, startBlocks, network, address });
}
}).filter(e => e !== undefined);
}).filter((e) => e !== undefined);
},
};

View File

@ -1,15 +1,10 @@
const duplicateStartBlocks = {
one: 10773070,
two: 10873070,
};
const contracts = [
{
prod: 7942402,
name: 'Proxy',
network: 'bsc',
address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'",
address: '0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7',
},
]
];
module.exports = contracts;

View File

@ -2,7 +2,6 @@ const Contracts = require('./contracts');
module.exports = {
createYaml: (env) => {
const createProxyBlock = ({ name, network, address }) => ({
name,
network,
@ -14,22 +13,22 @@ module.exports = {
abis: [
{
event: 'Proxy',
path: '../abis/Proxy.json'
}
path: '../abis/Proxy.json',
},
],
events: [
{
event: 'EncryptedNote(indexed address,bytes)',
handler: 'handleEncryptedNote',
}
},
],
});
return Contracts.map(({ prod, name, network, address }) => {
const startBlocks = { prod };
if (network === env) {
return createProxyBlock({ name, startBlocks, network, address })
return createProxyBlock({ name, startBlocks, network, address });
}
}).filter(e => e !== undefined);
}).filter((e) => e !== undefined);
},
};

View File

@ -2,6 +2,7 @@
"name": "sub-graph-proxy",
"license": "UNLICENSED",
"scripts": {
"lint": "eslint .",
"yaml:proxy": "node ./create-yaml-file create-yaml -s proxy -e bsc | mustache - mustache/yaml.mustache > subgraphs/proxy-tornado-subgraph.yaml",
"yaml:instance": "node ./create-yaml-file create-yaml -s instance -e bsc | mustache - mustache/yaml.mustache > subgraphs/instance-tornado-subgraph.yaml",
"codegen": "graph codegen",
@ -19,7 +20,16 @@
"@graphprotocol/graph-ts": "0.20.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^4.26.1",
"@typescript-eslint/parser": "^4.26.1",
"commander": "^7.2.0",
"mustache": "^4.2.0"
"eslint": "^7.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-import-resolver-typescript": "^2.4.0",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"mustache": "^4.2.0",
"prettier": "^2.3.1",
"typescript": "^4.3.2"
}
}

View File

@ -1,6 +1,7 @@
// this is a read only file generated by manual inputs to file mustache/templates/rates/contracts.js.
export let contractsToInstances = new Map<string, string>();
contractsToInstances.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', // Instance-bsc-0.1
  "0.1-bsc"
contractsToInstances.set(
'0x0ce22770451a8acad1220d9d1678656b4fae4a1d', // Instance-bsc-0.1
'0.1-bsc',
);
// this is a read only file generated by manual inputs to file mustache/templates/rates/contracts.js.

View File

@ -1,5 +1,5 @@
import { Echo } from '../generated'
import { NoteAccount as NoteAccountEntity } from '../generated/schema'
import { Echo } from '../generated';
import { NoteAccount as NoteAccountEntity } from '../generated/schema';
export function handleEcho(event: Echo): void {
let entity = new NoteAccountEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());

View File

@ -1,5 +1,5 @@
import { EncryptedNote } from '../generated'
import { EncryptedNote as EncryptedNoteEntity } from '../generated/schema'
import { EncryptedNote } from '../generated';
import { EncryptedNote as EncryptedNoteEntity } from '../generated/schema';
export function handleEncryptedNote(event: EncryptedNote): void {
let entity = new EncryptedNoteEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());

View File

@ -1,7 +1,7 @@
import { Withdrawal, Deposit } from '../generated'
import { Withdrawal as WithdrawalEntity, Deposit as DepositEntity } from '../generated/schema'
import { Withdrawal, Deposit } from '../generated';
import { Withdrawal as WithdrawalEntity, Deposit as DepositEntity } from '../generated/schema';
import { contractsToInstances } from './contractsToInstances'
import { contractsToInstances } from './contractsToInstances';
export function handleWithdrawal(event: Withdrawal): void {
let entity = new WithdrawalEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
@ -23,7 +23,7 @@ export function handleWithdrawal(event: Withdrawal): void {
}
export function handleDeposit(event: Deposit): void {
let entity = new DepositEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString())
let entity = new DepositEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
let result = contractsToInstances.get(event.address.toHexString()).split('-');
@ -36,5 +36,5 @@ export function handleDeposit(event: Deposit): void {
entity.commitment = event.params.commitment;
entity.transactionHash = event.transaction.hash;
entity.save()
entity.save();
}

1106
yarn.lock

File diff suppressed because it is too large Load Diff