Skip to content

Commit 4ddba81

Browse files
authored
BQ: add daily coin price (#2224)
Signed-off-by: Itai Segall <itai.segall@digitalasset.com>
1 parent 4aa1187 commit 4ddba81

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

apps/app/src/test/scala/org/lfdecentralizedtrust/splice/integration/tests/ScanTotalSupplyBigQueryIntegrationTest.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ class ScanTotalSupplyBigQueryIntegrationTest
4343
.withScanDisabledMiningRoundsCache()
4444
.withAmuletPrice(walletAmuletPrice)
4545

46-
override def walletAmuletPrice = SpliceUtil.damlDecimal(0.00001)
46+
def coinPrice = BigDecimal(0.00001)
47+
override def walletAmuletPrice = SpliceUtil.damlDecimal(coinPrice)
4748

4849
override protected def runTokenStandardCliSanityCheck = false
4950

@@ -553,6 +554,9 @@ class ScanTotalSupplyBigQueryIntegrationTest
553554
numActiveValidators: Long,
554555
avgTps: Double,
555556
peakTps: Double,
557+
minCoinPrice: BigDecimal,
558+
maxCoinPrice: BigDecimal,
559+
avgCoinPrice: BigDecimal,
556560
)
557561

558562
private def parseQueryResults(result: bq.TableResult) = {
@@ -593,6 +597,9 @@ class ScanTotalSupplyBigQueryIntegrationTest
593597
numActiveValidators = int("num_active_validators"),
594598
avgTps = float("average_tps"),
595599
peakTps = float("peak_tps"),
600+
minCoinPrice = bd("daily_min_coin_price"),
601+
maxCoinPrice = bd("daily_max_coin_price"),
602+
avgCoinPrice = bd("daily_avg_coin_price"),
596603
)
597604
}
598605

@@ -612,6 +619,9 @@ class ScanTotalSupplyBigQueryIntegrationTest
612619
("current_supply_total", results.currentSupplyTotal, lockedAmount + unlockedAmount),
613620
("num_amulet_holders", results.numAmuletHolders, amuletHolders),
614621
("num_active_validators", results.numActiveValidators, validators),
622+
("daily_min_coin_price", results.minCoinPrice, coinPrice),
623+
("daily_max_coin_price", results.maxCoinPrice, coinPrice),
624+
("daily_avg_coin_price", results.avgCoinPrice, coinPrice),
615625
)
616626
) { case (clue, actual, expected) =>
617627
actual shouldBe expected withClue clue

cluster/pulumi/canton-network/src/bigQuery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ function installDashboardsDataset(): gcp.bigquery.Dataset {
225225
{ name: 'num_active_validators', type: 'INT64' },
226226
{ name: 'average_tps', type: 'FLOAT64' },
227227
{ name: 'peak_tps', type: 'FLOAT64' },
228+
{ name: 'daily_min_coin_price', type: 'BIGNUMERIC' },
229+
{ name: 'daily_max_coin_price', type: 'BIGNUMERIC' },
230+
{ name: 'daily_avg_coin_price', type: 'BIGNUMERIC' },
228231
]),
229232
},
230233
{ dependsOn: [dataset] }

cluster/pulumi/canton-network/src/bigQuery_functions.ts

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,32 @@ const peak_tps = new BQScalarFunction(
558558
`
559559
);
560560

561+
const coin_price = new BQScalarFunction(
562+
'coin_price',
563+
time_window_args,
564+
new BQStruct([
565+
{ name: 'minPrice', type: BIGNUMERIC },
566+
{ name: 'maxPrice', type: BIGNUMERIC },
567+
{ name: 'avgPrice', type: BIGNUMERIC },
568+
]),
569+
`
570+
(SELECT AS
571+
STRUCT
572+
MIN(\`$$FUNCTIONS_DATASET$$.daml_record_numeric\`(c.create_arguments, [2])),
573+
MAX(\`$$FUNCTIONS_DATASET$$.daml_record_numeric\`(c.create_arguments, [2])),
574+
AVG(\`$$FUNCTIONS_DATASET$$.daml_record_numeric\`(c.create_arguments, [2]))
575+
FROM \`$$SCAN_DATASET$$.scan_sv_1_update_history_creates\` c
576+
WHERE template_id_entity_name = 'SummarizingMiningRound'
577+
AND c.template_id_module_name = 'Splice.Round'
578+
AND package_name = 'splice-amulet'
579+
AND \`$$FUNCTIONS_DATASET$$.in_time_window\`(
580+
start_record_time, start_migration_id,
581+
up_to_record_time, up_to_migration_id,
582+
c.record_time, c.migration_id
583+
))
584+
`
585+
);
586+
561587
const all_stats = new BQTableFunction(
562588
'all_stats',
563589
as_of_args,
@@ -577,6 +603,9 @@ const all_stats = new BQTableFunction(
577603
new BQColumn('num_active_validators', INT64),
578604
new BQColumn('average_tps', FLOAT64),
579605
new BQColumn('peak_tps', FLOAT64),
606+
new BQColumn('daily_min_coin_price', BIGNUMERIC),
607+
new BQColumn('daily_max_coin_price', BIGNUMERIC),
608+
new BQColumn('daily_avg_coin_price', BIGNUMERIC),
580609
],
581610
`
582611
SELECT
@@ -619,7 +648,25 @@ const all_stats = new BQTableFunction(
619648
\`$$FUNCTIONS_DATASET$$.num_amulet_holders\`(as_of_record_time, migration_id) as num_amulet_holders,
620649
\`$$FUNCTIONS_DATASET$$.num_active_validators\`(as_of_record_time, migration_id) as num_active_validators,
621650
IFNULL(\`$$FUNCTIONS_DATASET$$.average_tps\`(as_of_record_time, migration_id), 0.0) as average_tps,
622-
IFNULL(\`$$FUNCTIONS_DATASET$$.peak_tps\`(as_of_record_time, migration_id), 0.0) as peak_tps
651+
IFNULL(\`$$FUNCTIONS_DATASET$$.peak_tps\`(as_of_record_time, migration_id), 0.0) as peak_tps,
652+
\`$$FUNCTIONS_DATASET$$.coin_price\`(
653+
TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR),
654+
\`$$FUNCTIONS_DATASET$$.migration_id_at_time\`(TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR)),
655+
as_of_record_time,
656+
migration_id).minPrice
657+
AS daily_min_coin_price,
658+
\`$$FUNCTIONS_DATASET$$.coin_price\`(
659+
TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR),
660+
\`$$FUNCTIONS_DATASET$$.migration_id_at_time\`(TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR)),
661+
as_of_record_time,
662+
migration_id).maxPrice
663+
AS daily_max_coin_price,
664+
\`$$FUNCTIONS_DATASET$$.coin_price\`(
665+
TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR),
666+
\`$$FUNCTIONS_DATASET$$.migration_id_at_time\`(TIMESTAMP_SUB(as_of_record_time, INTERVAL 24 HOUR)),
667+
as_of_record_time,
668+
migration_id).avgPrice
669+
AS daily_avg_coin_price
623670
`
624671
);
625672

@@ -672,6 +719,9 @@ const days_with_missing_stats = new BQTableFunction(
672719
AND num_active_validators IS NOT NULL
673720
AND average_tps IS NOT NULL
674721
AND peak_tps IS NOT NULL
722+
AND daily_min_coin_price IS NOT NULL
723+
AND daily_max_coin_price IS NOT NULL
724+
AND daily_avg_coin_price IS NOT NULL
675725
`
676726
);
677727

@@ -716,6 +766,7 @@ export const allScanFunctions = [
716766
one_day_updates,
717767
average_tps,
718768
peak_tps,
769+
coin_price,
719770
all_stats,
720771
];
721772

0 commit comments

Comments
 (0)