chore: WIP
This commit is contained in:
parent
f770855c0a
commit
a8ba9fe2cb
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
node_modules
|
||||
build
|
||||
generated
|
5
.idea/.gitignore
generated
vendored
Normal file
5
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal 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>
|
12
.idea/tornado-subgraph.iml
generated
Normal file
12
.idea/tornado-subgraph.iml
generated
Normal 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
generated
Normal file
6
.idea/vcs.xml
generated
Normal 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
89
mustache/bsc.js
Normal 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',
|
||||
}
|
||||
},
|
||||
],
|
||||
};
|
36
mustache/subgraph.mustache
Normal file
36
mustache/subgraph.mustache
Normal 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}}
|
15
mustache/templates/base/index.js
Normal file
15
mustache/templates/base/index.js
Normal 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',
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
17
mustache/templates/common.js
Normal file
17
mustache/templates/common.js
Normal 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,
|
||||
}
|
21
mustache/templates/instance/contracts.js
Normal file
21
mustache/templates/instance/contracts.js
Normal 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;
|
56
mustache/templates/instance/create-yaml.js
Normal file
56
mustache/templates/instance/create-yaml.js
Normal 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 })
|
||||
});
|
||||
},
|
||||
};
|
4
mustache/templates/instance/index.js
Normal file
4
mustache/templates/instance/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
description: 'Instance',
|
||||
schemaFile: './schema.graphql',
|
||||
};
|
16
mustache/templates/proxy/contracts.js
Normal file
16
mustache/templates/proxy/contracts.js
Normal 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;
|
36
mustache/templates/proxy/create-yaml.js
Normal file
36
mustache/templates/proxy/create-yaml.js
Normal 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 })
|
||||
});
|
||||
},
|
||||
};
|
4
mustache/templates/proxy/index.js
Normal file
4
mustache/templates/proxy/index.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
description: 'Proxy',
|
||||
schemaFile: './schema.graphql',
|
||||
};
|
4
src/contractsToInstances.ts
Normal file
4
src/contractsToInstances.ts
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
export let contractsToInstances = new Map<string, string>();
|
||||
|
||||
contractsToInstances.set('0x0ce22770451a8acad1220d9d1678656b4fae4a1d', 'bnb-0.1');
|
@ -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];
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user