Skip to content

Commit 484c4e1

Browse files
authored
Update supply stats (0LNetworkCommunity#99)
* Get comprehensive supply number * Add unlocked supply stat * Update stats for new supply data * Update chart labels
1 parent e80eddd commit 484c4e1

7 files changed

Lines changed: 31 additions & 18 deletions

File tree

api/src/ol/ol.service.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,18 @@ export class OlService {
3939
type_arguments: [],
4040
arguments: [],
4141
});
42+
const circulatingResult = await this.aptosClient.view({
43+
function: '0x1::supply::get_circulating',
44+
type_arguments: [],
45+
arguments: [],
46+
});
4247
return {
4348
totalSupply: parseFloat(supplyStats[0] as string) / 1e6,
4449
slowLockedSupply: parseFloat(supplyStats[1] as string) / 1e6,
4550
cwSupply: parseFloat(supplyStats[2] as string) / 1e6,
4651
infraEscrowSupply: parseFloat(supplyStats[3] as string) / 1e6,
47-
circulatingSupply: parseFloat(supplyStats[4] as string) / 1e6,
52+
unlockedSupply: parseFloat(supplyStats[4] as string) / 1e6,
53+
circulatingSupply: parseFloat(circulatingResult[0] as string) / 1e6,
4854
};
4955
}
5056

api/src/ol/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export interface SupplyStats {
2323
slowLockedSupply: number;
2424
cwSupply: number;
2525
infraEscrowSupply: number;
26-
circulatingSupply: number;
26+
unlockedSupply: number;
27+
circulatingSupply: number; // unlocked supply plus funds available from CWs
2728
}
2829

2930
export interface ConsensusReward {

api/src/stats/interfaces/stats.interface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export interface SupplyStats {
1414
cwSupply: number;
1515
infraEscrowSupply: number;
1616
circulatingSupply: number;
17+
unlockedSupply: number;
1718
}
1819

1920
export interface WalletBalance {
@@ -60,6 +61,7 @@ export interface Stats {
6061
avgTotalVestingTime: BinRange[];
6162
};
6263
circulatingSupply: RelativeValue;
64+
unlockedSupply: RelativeValue;
6365
totalBurned: RelativeValue;
6466
communityWalletsBalance: RelativeValue;
6567
currentSlowWalletsCount: number;

api/src/stats/stats.service.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ export class StatsService {
7979
percentage: parseFloat(((supplyStats.circulatingSupply / totalSupply) * 100).toFixed(3)),
8080
};
8181

82+
const unlockedSupply = {
83+
nominal: parseFloat(supplyStats.unlockedSupply.toFixed(3)),
84+
percentage: parseFloat(((supplyStats.unlockedSupply / totalSupply) * 100).toFixed(3)),
85+
};
86+
8287
const communityWalletsBalance = {
8388
nominal: parseFloat(supplyStats.cwSupply.toFixed(3)),
8489
percentage: parseFloat(((supplyStats.cwSupply / totalSupply) * 100).toFixed(3)),
@@ -169,6 +174,7 @@ export class StatsService {
169174

170175
// kpis
171176
circulatingSupply,
177+
unlockedSupply,
172178
totalBurned,
173179
communityWalletsBalance,
174180
currentSlowWalletsCount: slowWalletsCountOverTime[slowWalletsCountOverTime.length - 1].value,
@@ -267,22 +273,26 @@ export class StatsService {
267273
communityCapital: NameValue[];
268274
}> {
269275
const totalSupply = supplyStats.totalSupply;
276+
const unlocked = supplyStats.unlockedSupply;
270277
const circulating = supplyStats.circulatingSupply;
278+
271279
const communityWalletsBalances = supplyStats.cwSupply;
272280
const infraEscrowBalance = supplyStats.infraEscrowSupply;
273281
const slowLocked = supplyStats.slowLockedSupply;
282+
const cwCredit = circulating - unlocked;
274283

275284
try {
276285
const supplyAllocation = [
277-
{ name: 'Community Wallets', value: communityWalletsBalances },
286+
{ name: 'Community Wallets net of credit', value: communityWalletsBalances - cwCredit },
278287
{ name: 'Locked', value: slowLocked },
279288
{ name: 'Infrastructure escrow', value: infraEscrowBalance },
280-
{ name: 'Circulating', value: circulating },
289+
{ name: 'Unlocked', value: unlocked },
290+
{ name: 'CW credit', value: cwCredit },
281291
];
282292

283293
const individualsCapital = [
284294
{ name: 'Locked', value: slowLocked },
285-
{ name: 'Circulating', value: circulating },
295+
{ name: 'Unlocked', value: unlocked },
286296
];
287297

288298
const communityCapital = [

api/src/stats/utils/stats.utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { Injectable } from '@nestjs/common';
22
import { ClickhouseService } from '../../clickhouse/clickhouse.service.js';
3+
import { Logger } from '@nestjs/common';
34

45
@Injectable()
56
export class StatsUtils {
67
constructor(private readonly clickhouseService: ClickhouseService) {}
8+
private readonly logger = new Logger("StatsUtils");
79

810
chunkArray<T>(array: T[], chunkSize: number): T[][] {
911
const results: T[][] = [];

web-app/src/modules/core/routes/Stats/Stats.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ const Coinstats = () => {
6363
<dl className="mt-5 grid grid-cols-1 gap-5 lg:grid-cols-3">
6464
<ChartComponent
6565
type="PieChart"
66-
title="Individuals capital"
66+
title="User allocation"
6767
data={data.individualsCapital}
6868
/>
6969

web-app/src/modules/ol/index.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,22 @@ export const useTotalSupply = (): Money | undefined => {
114114
return value;
115115
};
116116

117-
// Code below copied from api/src/ol/ol.service.ts
118-
// TODO: fold this function into a common library used by both web-app and api
119117
export const useCirculatingSupply = (): Money | undefined => {
120118
const aptos = useAptos();
121119
const [value, setValue] = useState<Money>();
122120

123121
useEffect(() => {
124122
const load = async () => {
125-
const supplyStats = await aptos.view({
126-
function: '0x1::supply::get_stats',
123+
const supplyResponse = await aptos.view({
124+
function: '0x1::supply::get_circulating',
127125
type_arguments: [],
128126
arguments: [],
129127
});
130128

131-
const supplyInfo = {
132-
totalSupply: parseFloat(supplyStats[0] as string) / 1e6,
133-
slowLockedSupply: parseFloat(supplyStats[1] as string) / 1e6,
134-
cwSupply: parseFloat(supplyStats[2] as string) / 1e6,
135-
infraEscrowSupply: parseFloat(supplyStats[3] as string) / 1e6,
136-
circulatingSupply: parseFloat(supplyStats[4] as string) / 1e6,
137-
}
129+
const circulatingSupply = parseFloat(supplyResponse[0] as string) / 1e6
138130

139131
setValue({
140-
amount: supplyInfo.circulatingSupply,
132+
amount: circulatingSupply,
141133
symbol: "LIBRA",
142134
});
143135
};

0 commit comments

Comments
 (0)