-
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 Delete analytics/scripts/test_query.flux wip multiple fixes fix test wip fix queries fix unit-test due to query changes
- Loading branch information
1 parent
24c6683
commit d1949db
Showing
10 changed files
with
496 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,56 @@ | ||
import "date" | ||
|
||
|
||
calculateProtocolStats = (protocol,protocolVersion,taskCfg) => { | ||
|
||
totalValueTransferred = from(bucket: taskCfg.sourceBucket) | ||
|> range(start: taskCfg.since, stop:taskCfg.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: time(v:taskCfg.since)})) | ||
|> set(key: "_field", value: "total_value_transferred") | ||
|
||
totalMessages = from(bucket: taskCfg.sourceBucket) | ||
|> range(start: taskCfg.since, stop:taskCfg.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: time(v:taskCfg.since)})) | ||
|> set(key: "_field", value: "total_messages") | ||
|
||
return union(tables:[totalMessages,totalValueTransferred]) | ||
|> set(key: "app_id", value: protocol) | ||
|> set(key: "version", value: protocolVersion) | ||
|> set(key: "_measurement", value: taskCfg.destMeasurement) | ||
|> map(fn: (r) => ({r with _time: time(v:taskCfg.since)})) | ||
|>to(bucket: taskCfg.destBucket) | ||
} | ||
|
||
|
||
|
||
ts = date.truncate(t: now(), unit: 1d) | ||
bucketInfinite = "wormscan" | ||
bucket30d = "wormscan-30days" | ||
|
||
cfg = { | ||
sourceBucket:bucketInfinite, | ||
destBucket:bucketInfinite, | ||
destMeasurement:"core_protocols_stats_1d", | ||
since: date.sub(d: 1d, from: ts), | ||
ts:ts, | ||
} | ||
|
||
// Set this variable with the cfg of the desired task | ||
|
||
option task = { | ||
name: "cctp and portal_token_bridge metrics every day", | ||
every: 1d, | ||
} | ||
|
||
calculateProtocolStats(protocol:"CCTP_WORMHOLE_INTEGRATION",protocolVersion:"v1",taskCfg:cfg) | ||
|
||
calculateProtocolStats(protocol:"PORTAL_TOKEN_BRIDGE",protocolVersion:"v1",taskCfg:cfg) |
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,50 @@ | ||
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 = "core_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})) | ||
|> 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})) | ||
|> 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
Oops, something went wrong.