@typus/typus-perp-sdk 1.1.43 → 1.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,5 +41,5 @@ interface tlpComparison {
41
41
  tlp_price: number;
42
42
  }
43
43
  export declare function getUserPnlFromSentio(startTimestamp: number, endTimestamp: number, userAddress?: string): Promise<any[]>;
44
- export declare function getLeaderboardFromSentio(startTs: number, endTs: number): Promise<any[]>;
44
+ export declare function getLeaderboardFromSentio(startTs: number, endTs: number, checkRwaOnly?: boolean): Promise<any[]>;
45
45
  export {};
@@ -674,34 +674,31 @@ async function getUserPnlFromSentio(startTimestamp, endTimestamp, userAddress) {
674
674
  return [];
675
675
  }
676
676
  }
677
- async function getLeaderboardFromSentio(startTs, endTs) {
677
+ async function getLeaderboardFromSentio(startTs, endTs, checkRwaOnly = false) {
678
678
  let apiUrl = "https://app.sentio.xyz/api/v1/analytics/typus/typus_perp/sql/execute";
679
- let size = (10 * (endTs - startTs)) / 60 / 60 / 24; // day * 10
679
+ let size = 10;
680
680
  let requestData = {
681
681
  sqlQuery: {
682
682
  sql: `
683
683
  WITH
684
684
  event AS (
685
685
  SELECT
686
- timestamp,
687
- toDate(timestamp - INTERVAL 3 HOUR) AS logical_date,
688
- toDate(timestamp - INTERVAL 3 HOUR) AS date,
689
686
  score/power(10, 9) AS volume,
690
687
  distinct_id
691
688
  FROM Score
689
+ WHERE timestamp >= ${startTs} AND timestamp < ${endTs}
692
690
  ),
693
691
  sum_vol AS (
694
692
  SELECT
695
- logical_date,
696
693
  distinct_id,
697
694
  sum(volume) AS total_volume
698
695
  FROM event
699
- GROUP BY logical_date, distinct_id
696
+ GROUP BY distinct_id
700
697
  ),
701
698
  ranked AS (
702
699
  SELECT
703
700
  *,
704
- row_number() OVER (PARTITION BY logical_date ORDER BY total_volume DESC) AS rk
701
+ row_number() OVER (ORDER BY total_volume DESC) AS rk
705
702
  FROM sum_vol
706
703
  ),
707
704
  top10 AS (
@@ -711,29 +708,76 @@ async function getLeaderboardFromSentio(startTs, endTs) {
711
708
  ),
712
709
  top10_sum AS (
713
710
  SELECT
714
- logical_date,
715
711
  sum(total_volume) AS top10_total_volume
716
712
  FROM top10
717
- GROUP BY logical_date
718
713
  )
719
714
  SELECT
720
- toDateTime(logical_date + INTERVAL 3 HOUR) AS Date,
721
715
  t.distinct_id as Address,
722
716
  t.total_volume as Trading_Vol,
723
717
  cast(t.total_volume AS Decimal256(18)) / cast(s.top10_total_volume AS Decimal256(18)) AS Volume_Share_Top10,
724
718
  Volume_Share_Top10 * 350 as PrizePool_Share
725
719
  FROM top10 t
726
- JOIN top10_sum s ON t.logical_date = s.logical_date
727
- WHERE Date >= ${startTs} AND Date < ${endTs}
720
+ CROSS JOIN top10_sum s
728
721
  ORDER BY
729
- Date DESC,
730
- t.rk ASC,
731
- Volume_Share_Top10
732
-
722
+ t.rk ASC
733
723
  `,
734
724
  size,
735
725
  },
736
726
  };
727
+ if (checkRwaOnly) {
728
+ requestData = {
729
+ sqlQuery: {
730
+ sql: `
731
+ WITH
732
+ event AS (
733
+ SELECT
734
+ s.score / power(10, 9) AS volume,
735
+ s.distinct_id
736
+ FROM Score s
737
+ LEFT JOIN OrderFilled o ON s.transaction_hash = o.transaction_hash
738
+ WHERE o.base_token IN (
739
+ 'XAU', 'XAG', 'USOIL', 'JPY', 'SPYX', 'QQQX',
740
+ 'TSLAX', 'NVDAX', 'AAPLX', 'GOOGLX', 'METAX'
741
+ )
742
+ AND s.timestamp >= ${startTs} AND s.timestamp < ${endTs}
743
+ ),
744
+ sum_vol AS (
745
+ SELECT
746
+ distinct_id,
747
+ sum(volume) AS total_volume
748
+ FROM event
749
+ GROUP BY distinct_id
750
+ ),
751
+ ranked AS (
752
+ SELECT
753
+ *,
754
+ row_number() OVER (ORDER BY total_volume DESC) AS rk
755
+ FROM sum_vol
756
+ ),
757
+ top10 AS (
758
+ SELECT *
759
+ FROM ranked
760
+ WHERE rk <= 10
761
+ ),
762
+ top10_sum AS (
763
+ SELECT
764
+ sum(total_volume) AS top10_total_volume
765
+ FROM top10
766
+ )
767
+ SELECT
768
+ t.distinct_id AS Address,
769
+ t.total_volume AS Trading_Vol,
770
+ CAST(t.total_volume AS Decimal256(18)) / CAST(s.top10_total_volume AS Decimal256(18)) AS Volume_Share_Top10,
771
+ Volume_Share_Top10 * 350 AS PrizePool_Share
772
+ FROM top10 t
773
+ CROSS JOIN top10_sum s
774
+ ORDER BY
775
+ t.rk ASC
776
+ `,
777
+ size,
778
+ }
779
+ };
780
+ }
737
781
  let jsonData = JSON.stringify(requestData);
738
782
  let response = await fetch(apiUrl, {
739
783
  method: "POST",
@@ -741,7 +785,7 @@ async function getLeaderboardFromSentio(startTs, endTs) {
741
785
  body: jsonData,
742
786
  });
743
787
  let data = await response.json();
744
- // console.log(data);
788
+ // console.log(data.result.rows);
745
789
  if (data.result) {
746
790
  return data.result.rows;
747
791
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typus/typus-perp-sdk",
3
- "version": "1.1.43",
3
+ "version": "1.1.45",
4
4
  "repository": "https://github.com/Typus-Lab/typus-perp-sdk.git",
5
5
  "author": "Typus",
6
6
  "description": "typus perp sdk",
@@ -45,4 +45,4 @@
45
45
  },
46
46
  "homepage": "https://github.com/Typus-Lab/typus-perp-sdk#readme",
47
47
  "packageManager": "yarn@4.10.3+sha512.c38cafb5c7bb273f3926d04e55e1d8c9dfa7d9c3ea1f36a4868fa028b9e5f72298f0b7f401ad5eb921749eb012eb1c3bb74bf7503df3ee43fd600d14a018266f"
48
- }
48
+ }