Skip to content

Commit

Permalink
New endpoint: top chain pairs by number of transfers (#307)
Browse files Browse the repository at this point in the history
### Summary

Tracking issue: #275

This pull request implements the endpoint `GET /api/v1/top-chain-pairs-by-num-transfers`, which returns the chain pairs that have the most transfers.Internally, the endpoint uses data summarized daily to speed up query execution times.

This endpoint has a mandatory query parameter named timerange, which must be set to `7d`, `15d` or `30d`.
  • Loading branch information
agodnic committed May 12, 2023
1 parent 25a675f commit c25ebcb
Show file tree
Hide file tree
Showing 14 changed files with 530 additions and 42 deletions.
Expand Up @@ -8,12 +8,14 @@ option task = {
start = date.sub(from: now(), d: 24h)
stop = now()

from(bucket: "wormscan-24hours-mainnet-staging")
from(bucket: "wormscan")
|> range(start: start, stop: stop)
|> filter(fn: (r) => r["_measurement"] == "vaa_volume")
|> filter(fn: (r) => r["_field"] == "volume")
|> drop(columns: ["app_id", "destination_address", "destination_chain"])
|> group(columns: ["emitter_chain", "token_address", "token_chain"])
|> sum(column: "_value")
|> set(key: "_measurement", value: "vaa_volume_24h")
|> set(key: "_measurement", value: "asset_volumes_24h")
|> set(key: "_field", value: "volume")
|> map(fn: (r) => ({r with _time: start}))
|> to(bucket: "wormscan-30days-mainnet-staging")
|> to(bucket: "wormscan-30days")
21 changes: 21 additions & 0 deletions analytic/scripts/chain_pair_transfers_24h.flux
@@ -0,0 +1,21 @@
import "date"

option task = {
name: "chain pair transfers with 24-hour granularity",
every: 24h,
}

start = date.sub(from: now(), d: 24h)
stop = now()

from(bucket: "wormscan")
|> range(start: start, stop: stop)
|> filter(fn: (r) => r["_measurement"] == "vaa_volume")
|> filter(fn: (r) => r["_field"] == "volume")
|> drop(columns: ["app_id", "destination_address", "token_address", "token_chain", "_field"])
|> group(columns: ["emitter_chain", "destination_chain"])
|> count(column: "_value")
|> set(key: "_measurement", value: "chain_pair_transfers_24h")
|> set(key: "_field", value: "num_transfers")
|> map(fn: (r) => ({r with _time: start}))
|> to(bucket: "wormscan-30days")
112 changes: 112 additions & 0 deletions api/docs/docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

112 changes: 112 additions & 0 deletions api/docs/swagger.json
Expand Up @@ -936,6 +936,64 @@
}
}
},
"/api/v1/top-assets-by-volume": {
"get": {
"description": "Returns a list of the (emitter_chain, asset) pairs with the most volume.",
"tags": [
"Wormscan"
],
"operationId": "get-top-assets-by-volume",
"parameters": [
{
"type": "string",
"description": "Time span, supported values: 7d, 15d, 30d.",
"name": "timeSpan",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/transactions.TopAssetsResponse"
}
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/api/v1/top-chain-pairs-by-num-transfers": {
"get": {
"description": "Returns a list of the (emitter_chain, destination_chain) pairs with the highest number of transfers.",
"tags": [
"Wormscan"
],
"operationId": "get-top-chain-pairs-by-num-transfers",
"parameters": [
{
"type": "string",
"description": "Time span, supported values: 7d, 15d, 30d.",
"name": "timeSpan",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/transactions.TopChainPairsResponse"
}
},
"500": {
"description": "Internal Server Error"
}
}
}
},
"/api/v1/vaas/": {
"get": {
"description": "Returns all VAAs. Output is paginated and can also be be sorted.",
Expand Down Expand Up @@ -2294,6 +2352,20 @@
}
}
},
"transactions.AssetWithVolume": {
"type": "object",
"properties": {
"emitterChain": {
"$ref": "#/definitions/vaa.ChainID"
},
"symbol": {
"type": "string"
},
"volume": {
"type": "string"
}
}
},
"transactions.ChainActivity": {
"type": "object",
"properties": {
Expand All @@ -2305,6 +2377,20 @@
}
}
},
"transactions.ChainPair": {
"type": "object",
"properties": {
"destinationChain": {
"$ref": "#/definitions/vaa.ChainID"
},
"emitterChain": {
"$ref": "#/definitions/vaa.ChainID"
},
"numberOfTransfers": {
"type": "string"
}
}
},
"transactions.Destination": {
"type": "object",
"properties": {
Expand All @@ -2326,12 +2412,38 @@
"description": "Number of VAAs emitted in the last 24 hours (does not include Pyth messages).",
"type": "string"
},
"24h_volume": {
"description": "Volume transferred through the token bridge in the last 24 hours, in USD.",
"type": "string"
},
"total_tx_count": {
"description": "Number of VAAs emitted since the creation of the network (does not include Pyth messages)",
"type": "string"
}
}
},
"transactions.TopAssetsResponse": {
"type": "object",
"properties": {
"assets": {
"type": "array",
"items": {
"$ref": "#/definitions/transactions.AssetWithVolume"
}
}
}
},
"transactions.TopChainPairsResponse": {
"type": "object",
"properties": {
"chainPairs": {
"type": "array",
"items": {
"$ref": "#/definitions/transactions.ChainPair"
}
}
}
},
"transactions.TransactionCountResult": {
"type": "object",
"properties": {
Expand Down

0 comments on commit c25ebcb

Please sign in to comment.