diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0f8b703
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+node_modules
+build
+generated
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..b58b603
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,5 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..314b3fc
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/tornado-subgraph.iml b/.idea/tornado-subgraph.iml
new file mode 100644
index 0000000..0c8867d
--- /dev/null
+++ b/.idea/tornado-subgraph.iml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/mustache/bsc.js b/mustache/bsc.js
new file mode 100644
index 0000000..dd60732
--- /dev/null
+++ b/mustache/bsc.js
@@ -0,0 +1,89 @@
+
+module.exports = {
+ base: {
+ specVersion: '0.0.2',
+ description: '',
+ repository: 'https://github.com/tornadocash/bsc-tornado-subgraph',
+ network: 'bsc',
+ },
+ dataSources: [
+ {
+ name: 'Instance',
+ network: 'bsc',
+ dataSourceKind: 'ethereum/contract',
+ address: "0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7",
+ abi: 'Instance',
+ startBlock: 7941563,
+ mapping: {
+ kind: 'ethereum/events',
+ apiVersion: '0.0.4',
+ language: 'wasm/assemblyscript',
+ entities: ['Deposit', 'Withdrawal'],
+ abis: {
+ name: 'Instance',
+ file: './abis/Instance.json',
+ },
+ eventHandlers: [
+ {
+ event: 'Deposit(indexed bytes32,uint32,uint256)',
+ handler: 'handleDeposit',
+ },
+ {
+ event: 'Withdrawal(address,bytes32,indexed address,uint256)',
+ handler: 'handleWithdrawal',
+ }
+ ],
+ file: './src/mapping-proxy.ts',
+ }
+ },
+ {
+ name: 'Echoer',
+ network: 'bsc',
+ dataSourceKind: 'ethereum/contract',
+ address: "0x60eaCBd5535ADB86955A0154E44Aded78F161643",
+ abi: 'Echoer',
+ startBlock: 7941563,
+ mapping: {
+ kind: 'ethereum/events',
+ apiVersion: '0.0.4',
+ language: 'wasm/assemblyscript',
+ entities: ['NoteAccount'],
+ abis: {
+ name: 'Echoer',
+ file: './abis/Echoer.json',
+ },
+ eventHandlers: [
+ {
+ event: 'Echo(indexed address,bytes)',
+ handler: 'handleEcho',
+ },
+ ],
+ file: './src/mapping-echo-account.ts',
+ }
+ },
+ {
+ name: 'Proxy',
+ dataSourceKind: 'ethereum/contract',
+ address: "0x0Ce22770451A8acAD1220D9d1678656b4fAe4a1d",
+ abi: 'Proxy',
+ startBlock: 7941563,
+ mapping: {
+ kind: 'ethereum/events',
+ apiVersion: '0.0.4',
+ language: 'wasm/assemblyscript',
+ entities: ['EncryptedNote'],
+ abis: {
+ name: 'Proxy',
+ file: './abis/Proxy.json',
+ },
+ eventHandlers: [
+ {
+ event: 'EncryptedNote(indexed address,bytes)',
+ handler: 'handleEncryptedNote',
+ },
+ ],
+ file: './src/mapping-encrypted-note.ts',
+ }
+ },
+ ],
+};
diff --git a/mustache/subgraph.mustache b/mustache/subgraph.mustache
new file mode 100644
index 0000000..10600e6
--- /dev/null
+++ b/mustache/subgraph.mustache
@@ -0,0 +1,36 @@
+{{#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/base/index.js b/mustache/templates/base/index.js
new file mode 100644
index 0000000..252c832
--- /dev/null
+++ b/mustache/templates/base/index.js
@@ -0,0 +1,15 @@
+module.exports = {
+ yaml: [
+ {
+ specVersion: '0.0.2',
+ repository: 'https://github.com/Synthetixio/synthetix-subgraph',
+ dataSourceKind: 'ethereum/contract',
+ network: 'mainnet',
+ mapping: {
+ kind: 'ethereum/events',
+ version: '0.0.4',
+ language: 'wasm/assemblyscript',
+ },
+ },
+ ],
+};
diff --git a/mustache/templates/common.js b/mustache/templates/common.js
new file mode 100644
index 0000000..c4f19e8
--- /dev/null
+++ b/mustache/templates/common.js
@@ -0,0 +1,17 @@
+const createStartBlock = (blocks, env) => {
+ if (env === 'test') {
+ return blocks.exchanger
+ ? blocks.exchanger.test
+ ? blocks.exchanger.test
+ : blocks.exchanger.prod
+ : blocks.test || blocks.prod
+ } else if (env === 'prod') {
+ return blocks.exchanger && blocks.exchanger.prod ? blocks.exchanger.prod : blocks.prod
+ } else {
+ throw new Error('Invalid env for creating a yaml file')
+ }
+}
+
+module.exports = {
+ createStartBlock,
+}
diff --git a/mustache/templates/instance/contracts.js b/mustache/templates/instance/contracts.js
new file mode 100644
index 0000000..ea6b361
--- /dev/null
+++ b/mustache/templates/instance/contracts.js
@@ -0,0 +1,21 @@
+const duplicateStartBlocks = {
+ one: 10773070,
+ two: 10873070,
+};
+
+const contracts = [
+ {
+ prod: 9715469,
+ name: 'Proxy',
+ exchanger: duplicateStartBlocks.one,
+ address: "'0x565C9EB432f4AE9633e50e1213AB4f23D8f31f54'",
+ },
+ {
+ prod: 9715469,
+ name: 'Proxy',
+ exchanger: duplicateStartBlocks.one,
+ address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'",
+ },
+]
+
+module.exports = contracts;
diff --git a/mustache/templates/instance/create-yaml.js b/mustache/templates/instance/create-yaml.js
new file mode 100644
index 0000000..9900f2d
--- /dev/null
+++ b/mustache/templates/instance/create-yaml.js
@@ -0,0 +1,56 @@
+const fs = require('fs');
+const path = require('path');
+
+const Contracts = require('./contracts');
+const { createStartBlock } = require('../common');
+
+module.exports = {
+ createYaml: (env) => {
+
+ const createInstanceBlock = ({ name, startBlocks, address }) => ({
+ name,
+ mappingFile: '../src/mapping-instance.ts',
+ startBlock: createStartBlock(startBlocks, env),
+ address,
+ entities: ['Deposit', 'Withdrawal'],
+ abis: [
+ {
+ name: 'Instance',
+ file: './abis/Instance.json'
+ }
+ ],
+ events: [
+ {
+ event: 'Deposit(indexed bytes32,uint32,uint256)',
+ handler: 'handleDeposit',
+ },
+ {
+ event: 'Withdrawal(address,bytes32,indexed address,uint256)',
+ handler: 'handleWithdrawal',
+ }
+ ],
+ });
+
+ const newLine = '\n';
+ const readOnlyComment = `// this is a read only file generated by manual inputs to file mustache/templates/rates/contracts.js.${newLine}`;
+ const space = '\xa0';
+ const doubleSpace = space + space;
+ let contractsToInstancesContent = `${readOnlyComment}export let contractsToInstances = new Map();${newLine}`;
+
+ Contracts.forEach(({ address, name, amount, currency }) => {
+ if (address != null) {
+ contractsToInstancesContent += `contractsToInstances.set(${address.toLowerCase()},${space}//${space}${name}-${currency}-${amount}${newLine}${doubleSpace}${amount}${'-'}${currency}${newLine});${newLine}`;
+ }
+ });
+
+ contractsToInstancesContent += readOnlyComment;
+ const targetFile = path.join(__dirname, '../../../src/', 'contractsToInstances.ts');
+ fs.writeFileSync(targetFile, contractsToInstancesContent, 'utf8');
+
+ return Contracts.map(({ type, prod, test, name, address }) => {
+ const startBlocks = { prod, test };
+
+ return createInstanceBlock({ name, startBlocks, address })
+ });
+ },
+};
diff --git a/mustache/templates/instance/index.js b/mustache/templates/instance/index.js
new file mode 100644
index 0000000..6c87df4
--- /dev/null
+++ b/mustache/templates/instance/index.js
@@ -0,0 +1,4 @@
+module.exports = {
+ description: 'Instance',
+ schemaFile: './schema.graphql',
+};
diff --git a/mustache/templates/proxy/contracts.js b/mustache/templates/proxy/contracts.js
new file mode 100644
index 0000000..293af3f
--- /dev/null
+++ b/mustache/templates/proxy/contracts.js
@@ -0,0 +1,16 @@
+const duplicateStartBlocks = {
+ one: 10773070,
+ two: 10873070,
+};
+
+const contracts = [
+ {
+ prod: 9715469,
+ amount: '0.1',
+ name: 'Instance',
+ exchanger: duplicateStartBlocks.one,
+ address: "'0x5D595DB16eb6d074E0e7E7f0bE37E7e75f23BEc7'",
+ },
+]
+
+module.exports = contracts;
diff --git a/mustache/templates/proxy/create-yaml.js b/mustache/templates/proxy/create-yaml.js
new file mode 100644
index 0000000..00d576e
--- /dev/null
+++ b/mustache/templates/proxy/create-yaml.js
@@ -0,0 +1,36 @@
+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 }) => ({
+ name,
+ mappingFile: '../src/mapping-encrypted-note.ts',
+ startBlock: createStartBlock(startBlocks, env),
+ address,
+ entities: ['EncryptedNote'],
+ abis: [
+ {
+ event: 'Proxy',
+ file: '../abis/Proxy.json'
+ }
+ ],
+ events: [
+ {
+ event: 'EncryptedNote(indexed address,bytes)',
+ handler: 'handleEncryptedNote',
+ }
+ ],
+ });
+
+ return Contracts.map(({ type, prod, test, name, address }) => {
+ const startBlocks = { prod, test };
+
+ return createProxyBlock({ name, startBlocks, address })
+ });
+ },
+};
diff --git a/mustache/templates/proxy/index.js b/mustache/templates/proxy/index.js
new file mode 100644
index 0000000..3046f6a
--- /dev/null
+++ b/mustache/templates/proxy/index.js
@@ -0,0 +1,4 @@
+module.exports = {
+ description: 'Proxy',
+ schemaFile: './schema.graphql',
+};
diff --git a/src/contractsToInstances.ts b/src/contractsToInstances.ts
new file mode 100644
index 0000000..2109076
--- /dev/null
+++ b/src/contractsToInstances.ts
@@ -0,0 +1,4 @@
+
+export let contractsToInstances = new Map();
+
+contractsToInstances.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', 'bnb-0.1');
diff --git a/src/mapping-instance.ts b/src/mapping-instance.ts
index dbc5946..666d605 100644
--- a/src/mapping-instance.ts
+++ b/src/mapping-instance.ts
@@ -1,12 +1,12 @@
import { Withdrawal, Deposit } from '../generated'
import { Withdrawal as WithdrawalEntity, Deposit as DepositEntity } from '../generated/schema'
-import { contractMaps } from './contractsData'
+import { contractsToInstances } from './contractsToInstances'
export function handleWithdrawal(event: Withdrawal): void {
let entity = new WithdrawalEntity(event.transaction.hash.toHex() + '-' + event.logIndex.toString());
- let result = contractMaps.get(event.address.toHexString()).split('-');
+ let result = contractsToInstances.get(event.address.toHexString()).split('-');
entity.amount = result[1];
entity.currency = result[0];
@@ -25,7 +25,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 result = contractMaps.get(event.address.toHexString()).split('-');
+ let result = contractsToInstances.get(event.address.toHexString()).split('-');
entity.amount = result[1];
entity.currency = result[0];
diff --git a/subgraph.yaml b/subgraph.yaml
index 0a37c74..824e67c 100644
--- a/subgraph.yaml
+++ b/subgraph.yaml
@@ -64,4 +64,4 @@ dataSources:
handler: handleDeposit
- event: Withdrawal(address,bytes32,indexed address,uint256)
handler: handleWithdrawal
- file: ./src/mapping-instance.ts
+ file: ./src/mapping-proxy.ts