Skip to content

Commit d9414c5

Browse files
authored
chore: improved stats (#240)
1 parent 0f5e225 commit d9414c5

File tree

13 files changed

+52
-82
lines changed

13 files changed

+52
-82
lines changed

generated/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export interface RegistryChain<N extends number, C extends string> {
3232
network?: string;
3333
batchLimit?: number;
3434
safeAdmin?: string;
35+
baseRpcUrl?: string;
3536
};
3637
adapters: unknown;
3738
contracts: ChainContracts<C>;

src/api/index.ts

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,8 @@ import schema from "ponder:schema";
22
import { db } from "ponder:api";
33
import { Hono } from "hono";
44
import { 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";
236
import { formatBigIntToDecimal } from "../helpers/formatter";
24-
import { AdapterParticipationService } from "../services/AdapterParticipationService";
257

268
const app = new Hono();
279
const context = { db };
@@ -36,12 +18,12 @@ const jsonDefaultHeaders = {
3618
};
3719
app.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

5941
app.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

7556
app.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

src/handlers/holdingsHandlers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { multiMapper } from "../helpers/multiMapper";
22
import { logEvent, serviceError } from "../helpers/logger";
3-
import { HoldingService } from "../services/HoldingService";
4-
import { HoldingAccountService } from "../services/HoldingAccountService";
3+
import { HoldingService, HoldingAccountService } from "../services";
54
import { HoldingAccountTypes, HoldingSnapshot } from "ponder:schema";
6-
import { BlockchainService } from "../services/BlockchainService";
5+
import { BlockchainService } from "../services";
76
import { snapshotter } from "../helpers/snapshotter";
87

98
multiMapper("holdings:Initialize", async ({ event, context }) => {

src/handlers/hubHandlers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { multiMapper } from "../helpers/multiMapper";
22
import { logEvent, serviceError } from "../helpers/logger";
3-
import { WhitelistedInvestorService, TokenService } from "../services";
4-
import { PoolSpokeBlockchainService } from "../services/PoolSpokeBlockchainService";
3+
import { WhitelistedInvestorService, TokenService, PoolSpokeBlockchainService } from "../services";
54

65
multiMapper("hub:NotifyPool", async ({ event, context }) => {
76
logEvent(event, context, "hub:NotifyPool");

src/handlers/hubRegistryHandlers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { multiMapper } from "../helpers/multiMapper";
2-
import { PoolService } from "../services/PoolService";
2+
33
import { logEvent, serviceError } from "../helpers/logger";
44
import {
55
AccountService,
66
AssetRegistrationService,
77
AssetService,
88
PoolManagerService,
9+
BlockchainService,
10+
PoolService,
911
} from "../services";
10-
import { BlockchainService } from "../services/BlockchainService";
1112
import { fetchFromIpfs } from "../helpers/ipfs";
1213
import { isoCurrencies } from "../helpers/isoCurrencies";
1314

src/handlers/multiAdapterHandlers.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
import { multiMapper } from "../helpers/multiMapper";
22
import { expandInlineObject, logEvent, serviceError, serviceLog } from "../helpers/logger";
3-
import { BlockchainService } from "../services/BlockchainService";
43
import {
4+
BlockchainService,
5+
AdapterService,
6+
AdapterParticipationService,
7+
AdapterWiringService,
58
CrosschainMessageService,
9+
CrosschainPayloadService,
610
getMessageId,
711
getMessageHash,
8-
} from "../services/CrosschainMessageService";
9-
import {
10-
CrosschainPayloadService,
1112
extractMessagesFromPayload,
12-
} from "../services/CrosschainPayloadService";
13-
import { AdapterService } from "../services/AdapterService";
14-
import { AdapterParticipationService } from "../services/AdapterParticipationService";
15-
import { AdapterWiringService } from "../services";
13+
} from "../services";
1614
import { timestamper } from "../helpers/timestamper";
1715
import { getVersionIndexForContract } from "../contracts";
1816

src/handlers/poolEscrowFactoryHandlers.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { multiMapper } from "../helpers/multiMapper";
22
import { logEvent } from "../helpers/logger";
3-
import { BlockchainService } from "../services/BlockchainService";
4-
import { EscrowService } from "../services/EscrowService";
3+
import { BlockchainService, EscrowService } from "../services";
54

65
multiMapper("poolEscrowFactory:DeployPoolEscrow", async ({ event, context }) => {
76
logEvent(event, context, "poolEscrowFactory:DeployPoolEscrow");

src/handlers/tokenInstanceHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
TokenService,
1010
InvestorTransactionService,
1111
} from "../services";
12-
import { initialisePosition } from "../services/TokenInstancePositionService";
12+
import { initialisePosition } from "../services";
1313

1414
multiMapper("tokenInstance:Transfer", async ({ event, context }) => {
1515
logEvent(event, context, "tokenInstance:Transfer");

src/handlers/vaultHandlers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { InvestorTransactionService, VaultService } from "../services";
1616
import { OutstandingInvestService } from "../services"; // TODO: DEPRECATED to be deleted in future releases
1717
import { OutstandingRedeemService } from "../services"; // TODO: DEPRECATED to be deleted in future releases
18-
import { initialisePosition } from "../services/TokenInstancePositionService";
18+
import { initialisePosition } from "../services";
1919
import { timestamper } from "../helpers/timestamper";
2020

2121
multiMapper("vault:DepositRequest", async ({ event, context }) => {

src/helpers/snapshotter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Service } from "../services/Service";
1+
import { Service } from "../services/Service.js";
22
import { ponder } from "ponder:registry";
33
import type { Context, Event } from "ponder:registry";
44
import { PgTableWithColumns } from "drizzle-orm/pg-core";

0 commit comments

Comments
 (0)