feat: generate proxy

This commit is contained in:
nikdementev 2021-06-09 15:34:06 +03:00 committed by 0xZick 地方分権化
parent a8ba9fe2cb
commit 7328da948f
9 changed files with 101 additions and 63 deletions

38
create-yaml-file.js Normal file
View File

@ -0,0 +1,38 @@
'use strict';
const path = require('path');
const program = require('commander');
program
.command('create-yaml')
.description('Creates yaml files using the mustache templating engine')
.option(
'-s, --subgraph <value>',
'the subgraph for which you are creating the yaml file. Currently only "proxy", "instance" and "echoer" are supported',
)
.option(
'-e, --env <value>',
'defaults to "prod" and uses the prod start blocks config. Must set to "test" to use test start blocks config',
'prod',
)
.action(async ({ subgraph, env }) => {
const baseIndexPath = path.join(__dirname, 'mustache', 'templates', 'base', 'index.js');
const specificIndexPath = path.join(__dirname, 'mustache', 'templates', subgraph, 'index.js');
const dataSourcesPath = path.join(__dirname, 'mustache', 'templates', subgraph, 'create-yaml.js');
const subgraphDataSourcesData = require(dataSourcesPath);
const dataSourcesData = [
...subgraphDataSourcesData.createYaml(env),
];
const indexData = require(baseIndexPath);
const specificIndexData = require(specificIndexPath);
indexData.yaml[0] = { ...indexData.yaml[0], ...specificIndexData };
indexData.yaml[0].dataSources = dataSourcesData;
return console.log(JSON.stringify(indexData, null, 2) + '\n');
});
program.parse(process.argv);

View File

@ -1,36 +0,0 @@
{{#base}}
specVersion: {{specVersion}}
description: {{description}}
repository: {{&repository}}
schema:
file: {{&schemaFile}}
dataSources:
{{#dataSources}}
- kind: {{&dataSourceKind}}
name: {{name}}
network: {{network}}
source:
address: {{&address}}
abi: {{abi}}
startBlock: {{startBlock}}
mapping:
kind: {{&mapping.kind}}
apiVersion: {{mapping.version}}
language: {{&mapping.language}}
file: {{&mappingFile}}
entities:
{{#entities}}
- {{.}}
{{/entities}}
abis:
{{#abis}}
- name: {{name}}
file: {{&path}}
{{/abis}}
eventHandlers:
{{#events}}
- event: {{event}}
handler: {{handler}}
{{/events}}
{{/dataSources}}
{{/base}}

View File

@ -5,16 +5,10 @@ const duplicateStartBlocks = {
const contracts = [
{
prod: 9715469,
name: 'Proxy',
exchanger: duplicateStartBlocks.one,
address: "'0x565C9EB432f4AE9633e50e1213AB4f23D8f31f54'",
},
{
prod: 9715469,
name: 'Proxy',
exchanger: duplicateStartBlocks.one,
address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'",
prod: 7942402,
amount: '0.1',
name: 'Instance',
address: "'0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d'",
},
]

View File

@ -5,10 +5,8 @@ const duplicateStartBlocks = {
const contracts = [
{
prod: 9715469,
amount: '0.1',
name: 'Instance',
exchanger: duplicateStartBlocks.one,
prod: 7942402,
name: 'Proxy',
address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'",
},
]

View File

@ -1,22 +1,19 @@
const fs = require('fs');
const path = require('path');
const Contracts = require('./contracts');
const { createStartBlock } = require('../common');
module.exports = {
createYaml: (env) => {
const createProxyBlock = ({ name, startBlocks, address }) => ({
const createProxyBlock = ({ name, address }) => ({
name,
mappingFile: '../src/mapping-encrypted-note.ts',
startBlock: createStartBlock(startBlocks, env),
abi: 'Proxy',
startBlock: 7941563,
address,
entities: ['EncryptedNote'],
abis: [
{
event: 'Proxy',
file: '../abis/Proxy.json'
path: '../abis/Proxy.json'
}
],
events: [
@ -27,8 +24,8 @@ module.exports = {
],
});
return Contracts.map(({ type, prod, test, name, address }) => {
const startBlocks = { prod, test };
return Contracts.map(({ prod, name, address }) => {
const startBlocks = { prod };
return createProxyBlock({ name, startBlocks, address })
});

36
mustache/yaml.mustache Normal file
View File

@ -0,0 +1,36 @@
{{#yaml}}
specVersion: {{specVersion}}
description: {{description}}
repository: {{&repository}}
schema:
file: {{&schemaFile}}
dataSources:
{{#dataSources}}
- kind: {{&dataSourceKind}}
name: {{name}}
network: {{network}}
source:
address: {{&address}}
abi: {{abi}}
startBlock: {{startBlock}}
mapping:
kind: {{&mapping.kind}}
apiVersion: {{mapping.version}}
language: {{&mapping.language}}
file: {{&mappingFile}}
entities:
{{#entities}}
- {{.}}
{{/entities}}
abis:
{{#abis}}
- name: {{name}}
file: {{&path}}
{{/abis}}
eventHandlers:
{{#events}}
- event: {{event}}
handler: {{handler}}
{{/events}}
{{/dataSources}}
{{/yaml}}

View File

@ -4,10 +4,15 @@
"scripts": {
"codegen": "graph codegen",
"build": "graph build",
"yaml:proxy": "node ./create-yaml-file create-yaml -s proxy -e prod | mustache - mustache/yaml.mustache > subgraphs/proxy-tornado-subgraph.yaml",
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ tornadocash/bsc-tornado-subgraph"
},
"dependencies": {
"@graphprotocol/graph-cli": "0.20.0",
"@graphprotocol/graph-ts": "0.20.0"
},
"devDependencies": {
"commander": "^7.2.0",
"mustache": "^4.2.0"
}
}

View File

@ -1,4 +0,0 @@
export let contractMaps = new Map<string, string>();
contractMaps.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', 'bnb-0.1');

View File

@ -645,6 +645,11 @@ commander@^2.15.0, commander@^2.20.3:
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
commander@^7.2.0:
version "7.2.0"
resolved "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
concat-map@0.0.1:
version "0.0.1"
resolved "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b"
@ -2071,6 +2076,11 @@ murmurhash3js@^3.0.1:
resolved "https://registry.npmjs.org/murmurhash3js/-/murmurhash3js-3.0.1.tgz#3e983e5b47c2a06f43a713174e7e435ca044b998"
integrity sha1-Ppg+W0fCoG9DpxMXTn5DXKBEuZg=
mustache@^4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz#e5892324d60a12ec9c2a73359edca52972bf6f64"
integrity sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==
mute-stream@0.0.8:
version "0.0.8"
resolved "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"