-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cctp and portal_token_bridge stats to protocols-stats endpoint
changes indent more changes on the script new working approach on influx task indent script tested insert add 2 versions of the script multiple changes add 1day task add logic to retrieve internal protocols remove unecessary code readd empty script fix unit-tests and measurement namings fix queries fix alignment rename function task fix names improvements on influx task add .run config to gitignore add .run to gitignore fix task and rename working api multiple things Delete .run/wormscan api.run.xml
- Loading branch information
1 parent
2bec07b
commit 6a88f46
Showing
11 changed files
with
469 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import "date" | ||
|
||
option task = { | ||
name: "cctp and portal_token_bridge metrics every day", | ||
every: 1d, | ||
} | ||
|
||
|
||
calculateLastDayMetrics = (protocol,protocolVersion,ts) => { | ||
|
||
bucket30d = "wormscan-30days" | ||
bucketInfinite = "wormscan" | ||
measurement1d = "cctp_tb_stats_1d" | ||
yesterday = date.sub(d: 1d, from: ts) | ||
|
||
totalValueTransferred = from(bucket: bucket30d) | ||
|> range(start: yesterday, stop: ts) | ||
|> filter(fn: (r) => r._measurement == "cctp_tb_stats_1h" and r.app_id == protocol) | ||
|> filter(fn: (r) => r._field == "total_value_transferred") | ||
|> keep(columns: ["_value","_field","app_id","_measurement"]) | ||
|> group() | ||
|> sum() | ||
|> map(fn: (r) => ({r with _time: yesterday})) | ||
|> map(fn: (r) => ({r with _value: float(v:r._value)})) | ||
|> set(key: "_field", value: "total_value_transferred") | ||
|
||
totalMessages = from(bucket: bucket30d) | ||
|> range(start: yesterday, stop: ts) | ||
|> filter(fn: (r) => r._measurement == "cctp_tb_stats_1h" and r.app_id == protocol) | ||
|> filter(fn: (r) => r._field == "total_messages") | ||
|> keep(columns: ["_value","_field","app_id","_measurement"]) | ||
|> group() | ||
|> count() | ||
|> map(fn: (r) => ({r with _time: yesterday})) | ||
|> map(fn: (r) => ({r with _value: float(v:r._value)})) | ||
|> set(key: "_field", value: "total_value_transferred") | ||
|
||
lastDayTotals = union(tables:[totalMessages,totalValueTransferred]) | ||
|> set(key: "app_id", value: protocol) | ||
|> set(key: "version", value: protocolVersion) | ||
|> set(key: "_measurement", value: measurement1d) | ||
|> map(fn: (r) => ({r with _time: yesterday})) | ||
to(bucket:bucketInfinite) | ||
} | ||
|
||
ts = date.truncate(t: now(), unit: 1d) | ||
|
||
// execute function for CCTP_WORMHOLE_INTEGRATION | ||
calculateTotalMetrics(protocol:"CCTP_WORMHOLE_INTEGRATION",protocolVersion:"v1",ts:ts) | ||
|
||
|
||
// execute function for PORTAL_TOKEN_BRIDGE | ||
calculateTotalMetrics(protocol:"PORTAL_TOKEN_BRIDGE",protocolVersion:"v1",ts:ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import "date" | ||
|
||
option task = { | ||
name: "cctp and portal_token_bridge metrics every hour", | ||
every: 1h, | ||
} | ||
|
||
|
||
calculateLastHourMetrics = (protocol,protocolVersion,ts) => { | ||
|
||
since = date.sub(d: 1h, from: ts) | ||
sourceBucket = "wormscan" | ||
destMeasurement = "internal_protocols_stats_1h" | ||
bucket30d = "wormscan-30days" | ||
|
||
totalValueTransferred = from(bucket: sourceBucket) | ||
|> range(start: since, stop:ts) | ||
|> filter(fn: (r) => r._measurement == "vaa_volume_v2" and r.app_id == protocol) | ||
|> filter(fn: (r) => r._field == "volume" and r._value > 0) | ||
|> drop(columns:["destination_chain","emitter_chain","token_address","token_chain","version"]) | ||
|> group() | ||
|> sum() | ||
|> map(fn: (r) => ({r with _time: since})) | ||
|> map(fn: (r) => ({r with _value: float(v:r._value)})) //total_value_transferred:float | ||
|> set(key: "_field", value: "total_value_transferred") | ||
|
||
totalMessages = from(bucket: sourceBucket) | ||
|> range(start: since, stop:ts) | ||
|> filter(fn: (r) => r._measurement == "vaa_volume_v2" and r.app_id == protocol) | ||
|> filter(fn: (r) => r._field == "volume") | ||
|> group() | ||
|> count() | ||
|> map(fn: (r) => ({r with _time: since})) | ||
|> map(fn: (r) => ({r with _value: float(v:r._value)})) //total_messages:float | ||
|> set(key: "_field", value: "total_messages") | ||
|
||
return union(tables:[totalMessages,totalValueTransferred]) // if nothing happened during the last hour then union will result in empty and no point will be added. | ||
|> set(key: "app_id", value: protocol) | ||
|> set(key: "version", value: protocolVersion) | ||
|> set(key: "_measurement", value: destMeasurement) | ||
|> map(fn: (r) => ({r with _time: since})) | ||
|>to(bucket: bucket30d) | ||
} | ||
|
||
ts = date.truncate(t: now(), unit: 1h) | ||
|
||
// execute function for CCTP_WORMHOLE_INTEGRATION | ||
calculateLastHourMetrics(protocol:"CCTP_WORMHOLE_INTEGRATION",protocolVersion:"v1",ts:ts) | ||
|
||
|
||
// execute function for PORTAL_TOKEN_BRIDGE | ||
calculateLastHourMetrics(protocol:"PORTAL_TOKEN_BRIDGE",protocolVersion:"v1",ts:ts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from(bucket: "wormscan") | ||
|> range(start: 1970-01-01T00:00:00Z,stop:now()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.