@@ -2,26 +2,8 @@ import schema from "ponder:schema";
22import { db } from "ponder:api" ;
33import { Hono } from "hono" ;
44import { graphql , client } from "ponder" ;
5- import {
6- AccountService ,
7- AdapterService ,
8- AssetRegistrationService ,
9- AssetService ,
10- CrosschainMessageService ,
11- CrosschainPayloadService ,
12- DeploymentService ,
13- EpochInvestOrderService ,
14- EpochRedeemOrderService ,
15- HoldingService ,
16- InvestOrderService ,
17- InvestorTransactionService ,
18- PoolService ,
19- RedeemOrderService ,
20- TokenInstanceService ,
21- TokenService ,
22- } from "../services" ;
5+ import * as Services from "../services" ;
236import { formatBigIntToDecimal } from "../helpers/formatter" ;
24- import { AdapterParticipationService } from "../services/AdapterParticipationService" ;
257
268const app = new Hono ( ) ;
279const context = { db } ;
@@ -36,12 +18,12 @@ const jsonDefaultHeaders = {
3618} ;
3719app . get ( "/tokens/:address/total-issuance" , async ( c ) => {
3820 const address = c . req . param ( "address" ) as `0x${string } `;
39- const tokenInstance = await TokenInstanceService . get ( context , { address } ) ;
21+ const tokenInstance = await Services . TokenInstanceService . get ( context , { address } ) ;
4022 if ( ! tokenInstance )
4123 return c . json ( { error : "TokenInstance address not found" } , 404 , jsonDefaultHeaders ) ;
4224 const { tokenId } = tokenInstance . read ( ) ;
4325
44- const token = await TokenService . get ( context , { id : tokenId } ) ;
26+ const token = await Services . TokenService . get ( context , { id : tokenId } ) ;
4527 if ( ! token ) return c . json ( { error : "Token not found" } , 404 , jsonDefaultHeaders ) ;
4628
4729 const { totalIssuance, decimals } = token . read ( ) ;
@@ -58,12 +40,11 @@ app.get("/tokens/:address/total-issuance", async (c) => {
5840
5941app . get ( "/tokens/:address/price" , async ( c ) => {
6042 const address = c . req . param ( "address" ) as `0x${string } `;
61-
62- const tokenInstance = await TokenInstanceService . get ( context , { address } ) ;
43+ const tokenInstance = await Services . TokenInstanceService . get ( context , { address } ) ;
6344 if ( ! tokenInstance ) return c . json ( { error : "TokenInstance not found" } , 404 , jsonDefaultHeaders ) ;
6445 const { tokenId } = tokenInstance . read ( ) ;
6546
66- const token = await TokenService . get ( context , { id : tokenId } ) ;
47+ const token = await Services . TokenService . get ( context , { id : tokenId } ) ;
6748 if ( ! token ) return c . json ( { error : "Token not found" } , 404 , jsonDefaultHeaders ) ;
6849
6950 const { tokenPrice } = token . read ( ) ;
@@ -73,46 +54,21 @@ app.get("/tokens/:address/price", async (c) => {
7354} ) ;
7455
7556app . get ( "/stats" , async ( c ) => {
76- const tvl = await TokenService . getNormalisedTvl ( context ) ;
77- const pools = await PoolService . count ( context , { isActive : true } ) ;
78- const tokens = await TokenService . count ( context , { isActive : true } ) ;
79- const tokenInstances = await TokenInstanceService . count ( context , {
80- isActive : true ,
81- } ) ;
82- const assets = await AssetService . count ( context , { } ) ;
83- const assetRegistrations = await AssetRegistrationService . count ( context , { } ) ;
84- const adapters = await AdapterService . count ( context , { } ) ;
85- const adapterParticipations = await AdapterParticipationService . count ( context , { } ) ;
86- const investorTransactions = await InvestorTransactionService . count ( context , { } ) ;
87- const investOrders = await InvestOrderService . count ( context , { } ) ;
88- const redeemOrders = await RedeemOrderService . count ( context , { } ) ;
89- const epochInvestOrders = await EpochInvestOrderService . count ( context , { } ) ;
90- const epochRedeemOrders = await EpochRedeemOrderService . count ( context , { } ) ;
91- const crosschainMessages = await CrosschainMessageService . count ( context , { } ) ;
92- const crosschainPayloads = await CrosschainPayloadService . count ( context , { } ) ;
93- const accounts = await AccountService . count ( context , { } ) ;
94- const holdings = await HoldingService . count ( context , { } ) ;
95- const deployments = await DeploymentService . count ( context , { } ) ;
57+ const tvl = await Services . TokenService . getNormalisedTvl ( context ) ;
58+ const aggregatedSupply = await Services . TokenService . getNormalisedAggregatedSupply ( context ) ;
59+ const services = Object . values ( Services ) . filter ( ( service ) => "count" in service ) ;
60+ const entityNames = services . map (
61+ ( service ) => service . name . substring ( 0 , service . name . length - "Service" . length ) + "s"
62+ ) ;
63+ const entityCounts = await Promise . all ( services . map ( ( service ) => service . count ( context , { } ) ) ) ;
64+ const response = Object . fromEntries (
65+ entityNames . map ( ( name , index ) => [ name , entityCounts [ index ] ] )
66+ ) ;
9667 return c . json (
9768 {
9869 tvl : formatBigIntToDecimal ( tvl ) ,
99- pools,
100- tokens,
101- tokenInstances,
102- assets,
103- assetRegistrations,
104- adapters,
105- adapterParticipations,
106- investorTransactions,
107- investOrders,
108- redeemOrders,
109- epochInvestOrders,
110- epochRedeemOrders,
111- crosschainMessages,
112- crosschainPayloads,
113- accounts,
114- holdings,
115- deployments,
70+ aggregatedSupply : formatBigIntToDecimal ( aggregatedSupply ) ,
71+ ...response ,
11672 } ,
11773 200 ,
11874 jsonDefaultHeaders
0 commit comments