Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/src/ol/ol.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ export class OlService {
type_arguments: [],
arguments: [],
});
const circulatingResult = await this.aptosClient.view({
function: '0x1::supply::get_circulating',
type_arguments: [],
arguments: [],
});
return {
totalSupply: parseFloat(supplyStats[0] as string) / 1e6,
slowLockedSupply: parseFloat(supplyStats[1] as string) / 1e6,
cwSupply: parseFloat(supplyStats[2] as string) / 1e6,
infraEscrowSupply: parseFloat(supplyStats[3] as string) / 1e6,
circulatingSupply: parseFloat(supplyStats[4] as string) / 1e6,
unlockedSupply: parseFloat(supplyStats[4] as string) / 1e6,
circulatingSupply: parseFloat(circulatingResult[0] as string) / 1e6,
};
}

Expand Down
3 changes: 2 additions & 1 deletion api/src/ol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export interface SupplyStats {
slowLockedSupply: number;
cwSupply: number;
infraEscrowSupply: number;
circulatingSupply: number;
unlockedSupply: number;
circulatingSupply: number; // unlocked supply plus funds available from CWs
}

export interface ConsensusReward {
Expand Down
2 changes: 2 additions & 0 deletions api/src/stats/interfaces/stats.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface SupplyStats {
cwSupply: number;
infraEscrowSupply: number;
circulatingSupply: number;
unlockedSupply: number;
}

export interface WalletBalance {
Expand Down Expand Up @@ -60,6 +61,7 @@ export interface Stats {
avgTotalVestingTime: BinRange[];
};
circulatingSupply: RelativeValue;
unlockedSupply: RelativeValue;
totalBurned: RelativeValue;
communityWalletsBalance: RelativeValue;
currentSlowWalletsCount: number;
Expand Down
16 changes: 13 additions & 3 deletions api/src/stats/stats.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ export class StatsService {
percentage: parseFloat(((supplyStats.circulatingSupply / totalSupply) * 100).toFixed(3)),
};

const unlockedSupply = {
nominal: parseFloat(supplyStats.unlockedSupply.toFixed(3)),
percentage: parseFloat(((supplyStats.unlockedSupply / totalSupply) * 100).toFixed(3)),
};

const communityWalletsBalance = {
nominal: parseFloat(supplyStats.cwSupply.toFixed(3)),
percentage: parseFloat(((supplyStats.cwSupply / totalSupply) * 100).toFixed(3)),
Expand Down Expand Up @@ -169,6 +174,7 @@ export class StatsService {

// kpis
circulatingSupply,
unlockedSupply,
totalBurned,
communityWalletsBalance,
currentSlowWalletsCount: slowWalletsCountOverTime[slowWalletsCountOverTime.length - 1].value,
Expand Down Expand Up @@ -267,22 +273,26 @@ export class StatsService {
communityCapital: NameValue[];
}> {
const totalSupply = supplyStats.totalSupply;
const unlocked = supplyStats.unlockedSupply;
const circulating = supplyStats.circulatingSupply;

const communityWalletsBalances = supplyStats.cwSupply;
const infraEscrowBalance = supplyStats.infraEscrowSupply;
const slowLocked = supplyStats.slowLockedSupply;
const cwCredit = circulating - unlocked;

try {
const supplyAllocation = [
{ name: 'Community Wallets', value: communityWalletsBalances },
{ name: 'Community Wallets net of credit', value: communityWalletsBalances - cwCredit },
{ name: 'Locked', value: slowLocked },
{ name: 'Infrastructure escrow', value: infraEscrowBalance },
{ name: 'Circulating', value: circulating },
{ name: 'Unlocked', value: unlocked },
{ name: 'CW credit', value: cwCredit },
];

const individualsCapital = [
{ name: 'Locked', value: slowLocked },
{ name: 'Circulating', value: circulating },
{ name: 'Unlocked', value: unlocked },
];

const communityCapital = [
Expand Down
2 changes: 2 additions & 0 deletions api/src/stats/utils/stats.utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Injectable } from '@nestjs/common';
import { ClickhouseService } from '../../clickhouse/clickhouse.service.js';
import { Logger } from '@nestjs/common';

@Injectable()
export class StatsUtils {
constructor(private readonly clickhouseService: ClickhouseService) {}
private readonly logger = new Logger("StatsUtils");

chunkArray<T>(array: T[], chunkSize: number): T[][] {
const results: T[][] = [];
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/modules/core/routes/Stats/Stats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const Coinstats = () => {
<dl className="mt-5 grid grid-cols-1 gap-5 lg:grid-cols-3">
<ChartComponent
type="PieChart"
title="Individuals capital"
title="User allocation"
data={data.individualsCapital}
/>

Expand Down
16 changes: 4 additions & 12 deletions web-app/src/modules/ol/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,30 +114,22 @@ export const useTotalSupply = (): Money | undefined => {
return value;
};

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

useEffect(() => {
const load = async () => {
const supplyStats = await aptos.view({
function: '0x1::supply::get_stats',
const supplyResponse = await aptos.view({
function: '0x1::supply::get_circulating',
type_arguments: [],
arguments: [],
});

const supplyInfo = {
totalSupply: parseFloat(supplyStats[0] as string) / 1e6,
slowLockedSupply: parseFloat(supplyStats[1] as string) / 1e6,
cwSupply: parseFloat(supplyStats[2] as string) / 1e6,
infraEscrowSupply: parseFloat(supplyStats[3] as string) / 1e6,
circulatingSupply: parseFloat(supplyStats[4] as string) / 1e6,
}
const circulatingSupply = parseFloat(supplyResponse[0] as string) / 1e6

setValue({
amount: supplyInfo.circulatingSupply,
amount: circulatingSupply,
symbol: "LIBRA",
});
};
Expand Down