-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcirculating-supply.service.ts
More file actions
32 lines (30 loc) · 1.14 KB
/
circulating-supply.service.ts
File metadata and controls
32 lines (30 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Total } from '@entities/Total';
import { SdkService } from '@common/sdk/sdk.service';
import { getAmount } from '@common/utils';
@Injectable()
export class CirculatingSupplyService {
private logger: Logger;
constructor(
private sdkService: SdkService,
@InjectRepository(Total) private repo: Repository<Total>,
) {
this.logger = new Logger(CirculatingSupplyService.name);
}
async readCirculatingSupply(): Promise<any> {
const circulating = await this.repo.findOne({
where: { name: 'circulating_supply' },
});
const staked = await this.sdkService.getTotalStaked();
const circulatingTotal = BigInt(circulating.count) + BigInt(staked.json);
const total = await this.sdkService.getTotalSupply();
const count = BigInt(total.json).toString();
this.logger.log({ request: 'circulating supply', count, total, staked });
return {
circulatingSupply: Number(getAmount(circulatingTotal.toString())),
totalSupply: Number(getAmount(count)),
};
}
}