Hop
Search…
TheGraph Subgraphs
Subgraph links and examples

Subgraph Links

Subgraph links

Examples

Transfers

Use these subgraphs for querying L2->L2 or L2->L1 transfers (query for transferSent entities)
  • hop-protocol/hop-polygon
  • hop-protocol/hop-xdai
  • hop-protocol/hop-arbitrum
  • hop-protocol/hop-optimism
Use this subgraph for L1->L2 transfers (query for transferSentToL2 entities)
  • hop-protocol/hop-mainnet

Get transfer root info

1
{
2
transfersCommitteds(
3
where: {
4
rootHash: "0xdda1a36c3cd03b88089659e3c949de2f7bc9e855cb1bdb08b754af765914b4f6"
5
}
6
) {
7
totalAmount
8
transactionHash
9
token
10
timestamp
11
}
12
}
Copied!

Get list of transfer roots

1
{
2
transfersCommitteds(
3
orderBy: timestamp,
4
orderDirection: desc
5
) {
6
totalAmount
7
transactionHash
8
token
9
timestamp
10
}
11
}
Copied!

Get source transfer info

L2->L1 or L2->L2
1
{
2
transferSents(
3
where: {
4
transferId: "0x696c75a27f70ae5210192164a0006a105e71a5b09c117340756bb09d85ddd9a5"
5
}
6
) {
7
timestamp
8
amount
9
bonderFee
10
transactionHash
11
token
12
from
13
recipient
14
}
15
}
Copied!
Getting transferId by transaction hash
1
{
2
transferSents(
3
where: {
4
transactionHash: "0xb61a2468312ed2d5af1ed288cdfafe64d97a4df56d929f44c039649bc8dec892"
5
}
6
) {
7
transferId
8
amount
9
bonderFee
10
transactionHash
11
token
12
timestamp
13
from
14
recipient
15
}
16
}
Copied!
Get list of transfers
L2->L2 or L2->L1
1
{
2
transferSents(
3
orderBy: timestamp,
4
orderDirection: desc
5
) {
6
timestamp
7
amount
8
bonderFee
9
transactionHash
10
token
11
from
12
recipient
13
}
14
}
Copied!
L1->L2
1
{
2
transferFromL1Completeds(
3
where: {
4
recipient: "0x7d5fda35a5f885a286da02ccc2fa4614eb3842da"
5
},
6
orderBy: timestamp,
7
orderDirection: desc
8
) {
9
amount
10
transactionHash
11
token
12
timestamp
13
from
14
}
15
}
Copied!

Get destination transfer info

L2->L1 or L2->L2
1
{
2
withdrawalBondeds(
3
where: {
4
transferId: "0x696c75a27f70ae5210192164a0006a105e71a5b09c117340756bb09d85ddd9a5"
5
}
6
) {
7
amount
8
transactionHash
9
token
10
timestamp
11
from
12
}
13
}
Copied!
L1->L2
There is no bonding sending L1-> so you need to check the event transferFromL1Completeds and not withdrawalBondeds.
There is no transferId when sending L1->L2 so you need to use something like recipient and amount in the where clause to match the origin transfer from the transferSentToL2s event.
1
{
2
transferFromL1Completeds(
3
where: {
4
recipient: "0x7d5fda35a5f885a286da02ccc2fa4614eb3842da"
5
},
6
orderBy: timestamp,
7
orderDirection: desc
8
) {
9
amount
10
transactionHash
11
token
12
timestamp
13
from
14
}
15
}
Copied!

Get list of transfers to a destination chain

L2->L2 or L2->L1
Use L2 subgraphs for these queries (the subgraph used is the origin chain)
1
{
2
transferSents(
3
where: {
4
timestamp_gt: 1650331530,
5
timestamp_lt: 1652898343,
6
destinationChainId: 42161
7
},
8
) {
9
transferId
10
amount
11
bonderFee
12
transactionHash
13
token
14
timestamp
15
from
16
recipient
17
}
18
}
Copied!
L1->L2
Use L1 mainnet subgraph for these queries (the L1 subgraph is the origin chain)
1
{
2
transferSentToL2S(
3
where: {
4
timestamp_gt: 1650331530,
5
timestamp_lt: 1652898343,
6
destinationChainId: 42161
7
},
8
) {
9
amount
10
relayerFee
11
transactionHash
12
token
13
timestamp
14
from
15
recipient
16
}
17
}
Copied!
Note: there is no transferId for L1->L2 transfers. The id is not the same as a transferId.

Get list of transfers that were bonded at destination chain

Use the destination chain subgraph for these queries
1
{
2
withdrawalBondeds {
3
amount
4
transferId
5
timestamp
6
transactionHash
7
}
8
}
Copied!
Note: The WithdrawalBonded event does not contain the recipient or the original sender, so a lookup using the transferId will need to be used on TransferSent (origin from L2) or TransferSentToL2 (origin from L1) to retrieve those values.

Volume

Cumulative volume

1
{
2
volumes {
3
amount
4
token
5
}
6
}
Copied!
Manual calculation
The amount on transferSents (xdai, polygon, arbitrum, optimism) and transferSentToL2S (mainnet) entities can be added up to get overall tx volume on each chain.
1
{
2
transferSents {
3
destinationChainId
4
amount
5
token
6
}
7
}
Copied!
1
{
2
transferSentToL2S {
3
destinationChainId
4
amount
5
token
6
}
7
}
Copied!

Daily volume

1
{
2
dailyVolumes(
3
where: {
4
token: "ETH",
5
date_gt: 1636416000,
6
date_lte: 1636583276
7
},
8
orderBy: date,
9
orderDirection: desc,
10
first: 1
11
) {
12
id
13
amount
14
token
15
date
16
}
17
}
Copied!
The date range is calculated as such:
1
const now = Math.floor(Date.now() / 1000)
2
const dayId = Math.floor(now / 86400)
3
const startDate = (dayId - 1) * 86400
4
const endDate = now
Copied!

TVL

⚠️ currently the TVL entities don't report fully accurate data because it's only using add/remove liquidity events instead of tracking transfer events. Use defillama to view accurate TVL.

Cumulative TVL

1
{
2
tvls {
3
amount
4
token
5
}
6
}
Copied!

Cumulative AMM TVL

1
{
2
ammTvls {
3
amount
4
token
5
}
6
}
Copied!

Fees

Cumulative AMM Fees

1
{
2
ammFees {
3
amount
4
token
5
}
6
}
Copied!

Cumulative Bonder fees

1
{
2
bonderFees {
3
amount
4
token
5
}
6
}
Copied!
Manual calculation
The bonder fee can be calculated by adding the bonderFee value from transferSents entities
1
{
2
transferSents {
3
bonderFee
4
destinationChainId
5
token
6
}
7
}
Copied!

LP fees

The LP fees can be calculated by adding up tokensSold*0.0004 from tokenSwaps entities
1
{
2
tokenSwaps {
3
tokensSold
4
token
5
}
6
}
Copied!

Pagination

See TheGraph API Pagination docs for example on how to paginate queries

JavaScript fetch example

1
async function queryFetch(url, query, variables) {
2
const res = await fetch(url, {
3
method: 'POST',
4
headers: {
5
'Content-Type': 'application/json',
6
Accept: 'application/json'
7
},
8
body: JSON.stringify({
9
query,
10
variables: variables || {}
11
})
12
})
13
const jsonRes = await res.json()
14
if (jsonRes.errors && json.errors.length) {
15
throw new Error(jsonRes.errors[0].message)
16
}
17
return jsonRes.data
18
}
19
20
async function main() {
21
const url = 'https://api.thegraph.com/subgraphs/name/hop-protocol/hop-mainnet'
22
const query = `
23
query TransferSentToL2($destinationChainId: Int) {
24
events: transferSentToL2S(
25
where: {
26
destinationChainId: $destinationChainId
27
},
28
orderBy: timestamp,
29
orderDirection: desc
30
) {
31
id
32
destinationChainId
33
amount
34
amountOutMin
35
relayerFee
36
recipient
37
deadline
38
transactionHash
39
timestamp
40
token
41
from
42
}
43
}
44
`
45
const variables = {
46
destinationChainId: 137
47
}
48
const result = await queryFetch(url, query, variables)
49
console.log(result)
50
}
51
52
main().catch(console.error)
Copied!

FAQ

Why are there multiple subgraphs?

At the moment a subgraph with TheGraph can only be tied to one chain meaning it doesn't have the context or events from the other chains, hence the chain specific subgraph urls. Maybe in the future TheGraph will support multi-chain subgraphs.