416
416
ce.epoch_id
417
417
, case when fe.protocol_version='v4' then fe.pool
418
418
else cebs.pool_id end
419
- as pool_id
419
+ as pool_id
420
420
, COUNT(*) AS num_fills
421
421
, SUM(fe.protocol_fee_paid) / 1e18 AS protocol_fees
422
422
FROM events.native_fills fe
439
439
ELSE 0.00
440
440
END) AS total_staked
441
441
FROM current_epoch_beginning_status cebs
442
- LEFT JOIN current_epoch_fills_by_pool fbp ON fbp.epoch_id = cebs.epoch_id AND fbp.pool_id = cebs.pool_id
442
+ LEFT JOIN current_epoch_fills_by_pool fbp ON fbp.epoch_id = cebs.epoch_id AND fbp.pool_id = cebs.pool_id
443
443
)
444
444
, total_fees AS (
445
445
SELECT
@@ -452,24 +452,30 @@ WITH
452
452
, cebs.maker_addresses AS maker_addresses
453
453
, cebs.operator_share AS operator_share
454
454
, cebs.zrx_delegated AS zrx_staked
455
- , ts.total_staked
456
455
, cebs.operator_zrx_delegated AS operator_zrx_staked
457
456
, cebs.member_zrx_delegated AS member_zrx_staked
458
- , cebs.zrx_delegated / NULLIF(ts.total_staked,0) AS share_of_stake
457
+ , ts.total_staked
458
+ , CASE
459
+ WHEN ts.total_staked = 0 THEN
460
+ NULL
461
+ ELSE
462
+ cebs.zrx_delegated / ts.total_staked
463
+ END AS share_of_stake
459
464
, fbp.protocol_fees AS total_protocol_fees_generated_in_eth
460
465
, fbp.num_fills AS number_of_fills
461
466
, CASE
462
- WHEN tf.total_protocol_fees = 0 THEN
463
- NULL
464
- ELSE fbp.protocol_fees / tf.total_protocol_fees
465
- END AS share_of_fees
467
+ WHEN tf.total_protocol_fees = 0 THEN
468
+ NULL
469
+ ELSE
470
+ fbp.protocol_fees / tf.total_protocol_fees
471
+ END AS share_of_fees
466
472
, fbp.num_fills::FLOAT / tf.total_fills::FLOAT AS share_of_fills
467
473
, CASE
468
- WHEN tf.total_protocol_fees = 0 THEN
469
- NULL
470
- ELSE
471
- (cebs.zrx_delegated / NULLIF( ts.total_staked,0) )
472
- / NULLIF((COALESCE( fbp.protocol_fees,0) / tf.total_protocol_fees),0 )
474
+ WHEN tf.total_protocol_fees = 0 THEN
475
+ NULL
476
+ ELSE
477
+ (cebs.zrx_delegated / ts.total_staked)
478
+ / ( fbp.protocol_fees / tf.total_protocol_fees)
473
479
END AS approximate_stake_ratio
474
480
FROM events.staking_pool_created_events pce
475
481
LEFT JOIN current_epoch_beginning_status cebs ON cebs.pool_id = pce.pool_id
@@ -530,14 +536,27 @@ export const currentEpochPoolStatsQuery = `
530
536
, cebs.operator_zrx_delegated AS operator_zrx_staked
531
537
, cebs.member_zrx_delegated AS member_zrx_staked
532
538
, ts.total_staked
533
- , cebs.zrx_delegated / NULLIF(ts.total_staked,0) AS share_of_stake
539
+ , CASE
540
+ WHEN ts.total_staked = 0 THEN
541
+ NULL
542
+ ELSE
543
+ cebs.zrx_delegated / ts.total_staked
544
+ END AS share_of_stake
534
545
, fbp.protocol_fees AS total_protocol_fees_generated_in_eth
535
546
, fbp.num_fills AS number_of_fills
536
- , fbp.protocol_fees / tf.total_protocol_fees AS share_of_fees
537
- , fbp.num_fills::FLOAT / tf.total_fills::FLOAT AS share_of_fills
538
- , (cebs.zrx_delegated / NULLIF(ts.total_staked,0))
539
- / (fbp.protocol_fees / tf.total_protocol_fees)
540
- AS approximate_stake_ratio
547
+ , CASE
548
+ WHEN tf.total_protocol_fees = 0 THEN
549
+ NULL
550
+ ELSE
551
+ fbp.protocol_fees / tf.total_protocol_fees
552
+ END AS share_of_fees
553
+ , CASE
554
+ WHEN tf.total_protocol_fees = 0 THEN
555
+ NULL
556
+ ELSE
557
+ (cebs.zrx_delegated / ts.total_staked)
558
+ / (fbp.protocol_fees / tf.total_protocol_fees)
559
+ END AS approximate_stake_ratio
541
560
FROM events.staking_pool_created_events pce
542
561
LEFT JOIN current_epoch_beginning_status cebs ON cebs.pool_id = pce.pool_id
543
562
LEFT JOIN current_epoch_fills_by_pool fbp ON fbp.epoch_id = cebs.epoch_id AND fbp.pool_id = cebs.pool_id
0 commit comments