Skip to content

Commit 6f88e27

Browse files
committed
Merged renvm-volumes and renvm subgraphs
1 parent 20068de commit 6f88e27

16 files changed

+2319
-512
lines changed

abis/DarknodeRegistry.json

+1,143-1
Large diffs are not rendered by default.

abis/Contract.json abis/Gateway.json

+332-120
Large diffs are not rendered by default.

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
"scripts": {
55
"codegen": "graph codegen",
66
"build": "graph build",
7-
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ amcassetti/renvm",
8-
"create-local": "graph create --node http://localhost:8020/ amcassetti/renvm",
9-
"remove-local": "graph remove --node http://localhost:8020/ amcassetti/renvm",
10-
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 amcassetti/renvm"
7+
"deploy": "graph deploy --node https://api.thegraph.com/deploy/ --ipfs https://api.thegraph.com/ipfs/ noiach/renvm-volume",
8+
"create-local": "graph create --node http://localhost:8020/ noiach/renvm-volume",
9+
"remove-local": "graph remove --node http://localhost:8020/ noiach/renvm-volume",
10+
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 noiach/renvm-volume"
1111
},
1212
"dependencies": {
13-
"@graphprotocol/graph-cli": "0.17.1",
14-
"@graphprotocol/graph-ts": "0.17.0"
13+
"@graphprotocol/graph-cli": "0.18.0",
14+
"@graphprotocol/graph-ts": "0.18.1"
1515
}
16-
}
16+
}

schema.graphql

+102-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,113 @@
1+
enum TransactionType {
2+
mint
3+
burn
4+
}
5+
16
type Transaction @entity {
27
id: ID!
3-
_createdTimestamp: BigInt
4-
_asset: String!
5-
_type: String!
6-
_amount: BigInt!
7-
_feeRate: BigInt!
8-
_adapterAddress: Bytes
9-
_destination: Bytes
8+
createdTimestamp: BigInt
9+
asset: String!
10+
type: TransactionType!
11+
amount: BigInt!
12+
feeRate: BigInt!
13+
adapterAddress: Bytes
14+
destination: Bytes
15+
integrator: Bytes
1016
}
1117

1218
type Darknode @entity {
1319
id: ID!
14-
_operator: Bytes!
15-
_isRegistered: Boolean!
16-
_registeredTimestamp: BigInt
17-
_deregisteredTimestamp: BigInt
18-
_startBlock: BigInt
19-
_endBlock: BigInt
20+
operator: Bytes!
21+
isRegistered: Boolean!
22+
registeredTimestamp: BigInt
23+
deregisteredTimestamp: BigInt
24+
startBlock: BigInt
25+
endBlock: BigInt
2026
}
2127

2228
type Epoch @entity {
2329
id: ID!
24-
_createdTimestamp: BigInt
25-
_blockNumber: BigInt!
26-
_nextEpochBlockNumber: BigInt!
30+
createdTimestamp: BigInt
31+
blockNumber: BigInt!
32+
nextEpochBlockNumber: BigInt!
33+
}
34+
35+
# Data accumulated and condensed into day stats
36+
type Integrator @entity {
37+
id: ID!
38+
39+
contractAddress: Bytes!
40+
41+
totalTxCountBTC: BigInt!
42+
totalLockedBTC: BigInt!
43+
totalVolumeBTC: BigInt!
44+
45+
totalTxCountZEC: BigInt!
46+
totalLockedZEC: BigInt!
47+
totalVolumeZEC: BigInt!
48+
49+
totalTxCountBCH: BigInt!
50+
totalLockedBCH: BigInt!
51+
totalVolumeBCH: BigInt!
52+
}
53+
54+
# Data accumulated and condensed into day stats
55+
type RenVM @entity {
56+
id: ID! # fixed to '1'
57+
58+
totalTxCountBTC: BigInt!
59+
totalLockedBTC: BigInt!
60+
totalVolumeBTC: BigInt!
61+
62+
totalTxCountZEC: BigInt!
63+
totalLockedZEC: BigInt!
64+
totalVolumeZEC: BigInt!
65+
66+
totalTxCountBCH: BigInt!
67+
totalLockedBCH: BigInt!
68+
totalVolumeBCH: BigInt!
69+
}
70+
71+
enum PeriodType {
72+
HOUR
73+
DAY
74+
WEEK
75+
MONTH
76+
YEAR
77+
}
78+
79+
# Data accumulated and condensed into day stats
80+
type PeriodData @entity {
81+
id: ID! # timestamp rounded to current day by dividing by 86400 - should only be one per day
82+
date: Int!
83+
84+
type: PeriodType!
85+
86+
# total
87+
88+
totalTxCountBTC: BigInt!
89+
totalLockedBTC: BigInt!
90+
totalVolumeBTC: BigInt!
91+
92+
totalTxCountZEC: BigInt!
93+
totalLockedZEC: BigInt!
94+
totalVolumeZEC: BigInt!
95+
96+
totalTxCountBCH: BigInt!
97+
totalLockedBCH: BigInt!
98+
totalVolumeBCH: BigInt!
99+
100+
# period
101+
102+
periodTxCountBTC: BigInt!
103+
periodLockedBTC: BigInt!
104+
periodVolumeBTC: BigInt!
105+
106+
periodTxCountZEC: BigInt!
107+
periodLockedZEC: BigInt!
108+
periodVolumeZEC: BigInt!
109+
110+
periodTxCountBCH: BigInt!
111+
periodLockedBCH: BigInt!
112+
periodVolumeBCH: BigInt!
27113
}

src/bch-shifter.ts

-42
This file was deleted.

src/bchGateway.ts

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// tslint:disable: only-arrow-functions prefer-for-of
2+
3+
import { BigInt } from "@graphprotocol/graph-ts";
4+
5+
import { Gateway, LogBurn, LogMint } from "../generated/BCHGateway/Gateway";
6+
import { Transaction } from "../generated/schema";
7+
import { getDayData, getIntegrator, getRenVM, I32, oneBigInt } from "./common";
8+
9+
const periods: string[] = ["HOUR", "DAY", "WEEK", "MONTH", "YEAR"];
10+
11+
export function handleLogMint(event: LogMint): void {
12+
13+
const txid = event.transaction.hash.toHex() + "-" + event.logIndex.toString();
14+
const tx = new Transaction(txid);
15+
16+
const contract = Gateway.bind(event.address);
17+
const to = event.transaction.to;
18+
19+
tx.createdTimestamp = event.block.timestamp;
20+
tx.asset = "BCH";
21+
tx.amount = event.params._amount;
22+
tx.feeRate = BigInt.fromI32(contract.mintFee());
23+
tx.type = "mint";
24+
tx.adapterAddress = to;
25+
tx.save();
26+
27+
// Nov 2 2018 is 1541116800 for dayStartTimestamp and 17837 for dayID
28+
// Nov 3 2018 would be 1541116800 + 86400 and 17838. And so on, for each exchange
29+
const timestamp: I32 = event.block.timestamp.toI32();
30+
31+
// Update Global Values
32+
const renVM = getRenVM();
33+
renVM.totalTxCountBCH = renVM.totalTxCountBCH.plus(oneBigInt());
34+
renVM.totalVolumeBCH = renVM.totalVolumeBCH.plus(tx.amount);
35+
renVM.totalLockedBCH = renVM.totalLockedBCH.plus(tx.amount);
36+
renVM.save();
37+
38+
const integrator = getIntegrator(tx.adapterAddress);
39+
integrator.totalTxCountBCH = integrator.totalTxCountBCH.plus(oneBigInt());
40+
integrator.totalVolumeBCH = integrator.totalVolumeBCH.plus(tx.amount);
41+
integrator.totalLockedBCH = integrator.totalLockedBCH.plus(tx.amount);
42+
integrator.save();
43+
44+
for (let i = 0; i < periods.length; i++) {
45+
const dayData = getDayData(timestamp, periods[i]);
46+
47+
// save info
48+
dayData.periodTxCountBCH = dayData.periodTxCountBCH.plus(oneBigInt());
49+
dayData.periodVolumeBCH = dayData.periodVolumeBCH.plus(tx.amount);
50+
dayData.periodLockedBCH = dayData.periodLockedBCH.plus(tx.amount);
51+
52+
dayData.totalTxCountBCH = renVM.totalTxCountBCH;
53+
dayData.totalVolumeBCH = renVM.totalVolumeBCH;
54+
dayData.totalLockedBCH = renVM.totalLockedBCH;
55+
56+
dayData.save();
57+
}
58+
}
59+
60+
export function handleLogBurn(event: LogBurn): void {
61+
const txid = event.transaction.hash.toHex() + "-" + event.logIndex.toString();
62+
const tx = new Transaction(txid);
63+
64+
const contract = Gateway.bind(event.address);
65+
const to = event.transaction.to;
66+
67+
tx.createdTimestamp = event.block.timestamp;
68+
tx.asset = "RenBCH";
69+
tx.amount = event.params._amount;
70+
tx.feeRate = BigInt.fromI32(contract.burnFee());
71+
tx.type = "burn";
72+
tx.adapterAddress = to;
73+
tx.save();
74+
75+
// Nov 2 2018 is 1541116800 for dayStartTimestamp and 17837 for dayID
76+
// Nov 3 2018 would be 1541116800 + 86400 and 17838. And so on, for each exchange
77+
const timestamp: I32 = event.block.timestamp.toI32();
78+
79+
// Update Global Values
80+
const renVM = getRenVM();
81+
renVM.totalTxCountBCH = renVM.totalTxCountBCH.plus(oneBigInt());
82+
renVM.totalVolumeBCH = renVM.totalVolumeBCH.plus(tx.amount);
83+
renVM.totalLockedBCH = renVM.totalLockedBCH.minus(tx.amount);
84+
renVM.save();
85+
86+
for (let i = 0; i < periods.length; i++) {
87+
const dayData = getDayData(timestamp, periods[i]);
88+
89+
// save info
90+
dayData.periodTxCountBCH = dayData.periodTxCountBCH.plus(oneBigInt());
91+
dayData.periodVolumeBCH = dayData.periodVolumeBCH.plus(tx.amount);
92+
dayData.periodLockedBCH = dayData.periodLockedBCH.minus(tx.amount);
93+
94+
dayData.totalTxCountBCH = renVM.totalTxCountBCH;
95+
dayData.totalVolumeBCH = renVM.totalVolumeBCH;
96+
dayData.totalLockedBCH = renVM.totalLockedBCH;
97+
98+
dayData.save();
99+
}
100+
101+
}

0 commit comments

Comments
 (0)