From 7328da948f19b34bf842cb9c37a05ebe67c442f3 Mon Sep 17 00:00:00 2001 From: nikdementev Date: Wed, 9 Jun 2021 15:34:06 +0300 Subject: [PATCH] feat: generate proxy --- create-yaml-file.js | 38 ++++++++++++++++++++++++ mustache/subgraph.mustache | 36 ---------------------- mustache/templates/instance/contracts.js | 14 +++------ mustache/templates/proxy/contracts.js | 6 ++-- mustache/templates/proxy/create-yaml.js | 15 ++++------ mustache/yaml.mustache | 36 ++++++++++++++++++++++ package.json | 5 ++++ src/contractsData.ts | 4 --- yarn.lock | 10 +++++++ 9 files changed, 101 insertions(+), 63 deletions(-) create mode 100644 create-yaml-file.js delete mode 100644 mustache/subgraph.mustache create mode 100644 mustache/yaml.mustache delete mode 100644 src/contractsData.ts diff --git a/create-yaml-file.js b/create-yaml-file.js new file mode 100644 index 0000000..73e2738 --- /dev/null +++ b/create-yaml-file.js @@ -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 ', + 'the subgraph for which you are creating the yaml file. Currently only "proxy", "instance" and "echoer" are supported', + ) + .option( + '-e, --env ', + '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); diff --git a/mustache/subgraph.mustache b/mustache/subgraph.mustache deleted file mode 100644 index 10600e6..0000000 --- a/mustache/subgraph.mustache +++ /dev/null @@ -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}} diff --git a/mustache/templates/instance/contracts.js b/mustache/templates/instance/contracts.js index ea6b361..399d7bc 100644 --- a/mustache/templates/instance/contracts.js +++ b/mustache/templates/instance/contracts.js @@ -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'", }, ] diff --git a/mustache/templates/proxy/contracts.js b/mustache/templates/proxy/contracts.js index 293af3f..1af1225 100644 --- a/mustache/templates/proxy/contracts.js +++ b/mustache/templates/proxy/contracts.js @@ -5,10 +5,8 @@ const duplicateStartBlocks = { const contracts = [ { - prod: 9715469, - amount: '0.1', - name: 'Instance', - exchanger: duplicateStartBlocks.one, + prod: 7942402, + name: 'Proxy', address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'", }, ] diff --git a/mustache/templates/proxy/create-yaml.js b/mustache/templates/proxy/create-yaml.js index 00d576e..9452b58 100644 --- a/mustache/templates/proxy/create-yaml.js +++ b/mustache/templates/proxy/create-yaml.js @@ -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 }) }); diff --git a/mustache/yaml.mustache b/mustache/yaml.mustache new file mode 100644 index 0000000..83c8760 --- /dev/null +++ b/mustache/yaml.mustache @@ -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}} diff --git a/package.json b/package.json index 52a7166..1702f71 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/contractsData.ts b/src/contractsData.ts deleted file mode 100644 index 77a230d..0000000 --- a/src/contractsData.ts +++ /dev/null @@ -1,4 +0,0 @@ - -export let contractMaps = new Map(); - -contractMaps.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', 'bnb-0.1'); diff --git a/yarn.lock b/yarn.lock index 9948cbe..d93612c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"