chore: WIP

This commit is contained in:
nikdementev 2021-06-08 19:08:11 +03:00 committed by 0xZick 地方分権化
parent f770855c0a
commit a8ba9fe2cb
18 changed files with 336 additions and 4 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
node_modules
build
generated

5
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/tornado-subgraph.iml" filepath="$PROJECT_DIR$/.idea/tornado-subgraph.iml" />
</modules>
</component>
</project>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

89
mustache/bsc.js Normal file
View File

@ -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',
}
},
],
};

View File

@ -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}}

View File

@ -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',
},
},
],
};

View File

@ -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,
}

View File

@ -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;

View File

@ -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<string, string>();${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 })
});
},
};

View File

@ -0,0 +1,4 @@
module.exports = {
description: 'Instance',
schemaFile: './schema.graphql',
};

View File

@ -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;

View File

@ -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 })
});
},
};

View File

@ -0,0 +1,4 @@
module.exports = {
description: 'Proxy',
schemaFile: './schema.graphql',
};

View File

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

View File

@ -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];

View File

@ -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