diff --git a/src/core/lib/okp4/enums/endpoints.enum.ts b/src/core/lib/okp4/enums/endpoints.enum.ts index 856214e..3a92a4c 100644 --- a/src/core/lib/okp4/enums/endpoints.enum.ts +++ b/src/core/lib/okp4/enums/endpoints.enum.ts @@ -13,4 +13,6 @@ export enum Endpoints { GOV_PROPOSALS = 'cosmos/gov/v1/proposals', GOV_PROPOSAL = 'cosmos/gov/v1/proposals/:proposal_id', STAKING_POOL = 'cosmos/staking/v1beta1/pool', + INFLATION = '/cosmos/mint/v1beta1/inflation', + DISTRIBUTION_PARAMS = '/cosmos/distribution/v1beta1/params', } diff --git a/src/core/lib/okp4/okp4.service.ts b/src/core/lib/okp4/okp4.service.ts index e57ba72..1f63ce5 100644 --- a/src/core/lib/okp4/okp4.service.ts +++ b/src/core/lib/okp4/okp4.service.ts @@ -25,6 +25,9 @@ import { GetProposalsResponse } from "./responses/get-proposals.response"; import { GetProposalResponse } from "@core/lib/okp4/responses/get-proposal.response"; import { StakingPoolResponse } from "./responses/staking-pool.response"; import { ValidatorStatus } from "./enums/validator-status.enum"; +import { InflationResponse } from "./responses/inflation.response"; +import { DistributionParamsResponse } from "./responses/distribution-params.response"; +import Big from "big.js"; @Injectable() export class Okp4Service { @@ -245,4 +248,27 @@ export class Okp4Service { async getStakingPool(): Promise { return this.getWithErrorHandling(this.constructUrl(Endpoints.STAKING_POOL)); } + + async getApr() { + const promises = [ + this.getWithErrorHandling(this.constructUrl(Endpoints.INFLATION)), + this.getWithErrorHandling( + this.constructUrl(Endpoints.DISTRIBUTION_PARAMS) + ), + this.getStakingPool(), + ]; + const res = (await Promise.all(promises)) as [ + InflationResponse, + DistributionParamsResponse, + StakingPoolResponse + ]; + + if (res[2]?.pool?.bonded_tokens) { + Big(res[0].inflation) + .mul(Big(1).minus(res[1].params.community_tax)) + .div(res[2].pool.bonded_tokens) + .toString(); + } + return "0"; + } } diff --git a/src/core/lib/okp4/responses/distribution-params.response.ts b/src/core/lib/okp4/responses/distribution-params.response.ts new file mode 100644 index 0000000..460e014 --- /dev/null +++ b/src/core/lib/okp4/responses/distribution-params.response.ts @@ -0,0 +1,8 @@ +export interface DistributionParamsResponse { + params: { + community_tax: string; + base_proposer_reward: string; + bonus_proposer_reward: string; + withdraw_addr_enabled: boolean; + }; +} diff --git a/src/core/lib/okp4/responses/inflation.response.ts b/src/core/lib/okp4/responses/inflation.response.ts new file mode 100644 index 0000000..af36d7a --- /dev/null +++ b/src/core/lib/okp4/responses/inflation.response.ts @@ -0,0 +1,3 @@ +export interface InflationResponse { + inflation: string; +} diff --git a/src/modules/staking/services/staking.service.ts b/src/modules/staking/services/staking.service.ts index 7fd65d8..489e5b0 100644 --- a/src/modules/staking/services/staking.service.ts +++ b/src/modules/staking/services/staking.service.ts @@ -4,7 +4,6 @@ import { BadRequestException, Injectable, OnModuleInit } from "@nestjs/common"; import { StakingCache } from "./staking.cache"; import { config } from "@core/config/config"; import { MyStakedOverviewDto } from "../dtos/my-staked-overview.dto"; -import { OsmosisService } from "@core/lib/osmosis/osmosis.service"; import { Validator } from "@core/lib/okp4/responses/delegators-validators.response"; import Big from "big.js"; import { GlobalStakedOverviewDto } from "../dtos/global-staked-overview.dto"; @@ -35,7 +34,6 @@ export class StakingService implements OnModuleInit { constructor( private readonly okp4Service: Okp4Service, private readonly cache: StakingCache, - private readonly osmosisService: OsmosisService, private readonly keybaseService: KeybaseService, private eventEmitter: EventEmitter2 ) {} @@ -155,7 +153,7 @@ export class StakingService implements OnModuleInit { private async fetchAndCacheGlobalStakedOverview(): Promise { const rez = await Promise.all([ this.okp4Service.getBondValidators(), - this.osmosisService.getStakingApr(), + this.okp4Service.getApr(), this.fetchTotalSupply(), this.okp4Service.getStakingPool(), ]); diff --git a/src/modules/staking/staking.module.ts b/src/modules/staking/staking.module.ts index 1d47e9b..d7cdc7a 100644 --- a/src/modules/staking/staking.module.ts +++ b/src/modules/staking/staking.module.ts @@ -4,7 +4,6 @@ import { StakingService } from "./services/staking.service"; import { StakingController } from "./staking.controller"; import { HttpService } from "@core/lib/http.service"; import { StakingCache } from "./services/staking.cache"; -import { OsmosisService } from "@core/lib/osmosis/osmosis.service"; import { KeybaseService } from "@core/lib/keybase/keybase.service"; import { RedisService } from "@core/lib/redis.service"; import { StakingGateway } from "./staking.gateway"; @@ -13,7 +12,6 @@ import { StakingGateway } from "./staking.gateway"; imports: [], providers: [ Okp4Service, - OsmosisService, KeybaseService, RedisService, StakingService, @@ -21,8 +19,6 @@ import { StakingGateway } from "./staking.gateway"; HttpService, StakingGateway, ], - controllers: [ - StakingController, - ], + controllers: [StakingController], }) -export class StakingModule {} \ No newline at end of file +export class StakingModule {} diff --git a/src/modules/token/services/token.service.ts b/src/modules/token/services/token.service.ts index 9093820..efb255e 100644 --- a/src/modules/token/services/token.service.ts +++ b/src/modules/token/services/token.service.ts @@ -16,6 +16,7 @@ import { import { HistoricalPrice } from "../dtos/historical-price.dto"; import { TimeBucketDto } from "../dtos/time-bucket.dto"; import { Log } from "@core/loggers/log"; +import { Okp4Service } from "@core/lib/okp4/okp4.service"; @Injectable() export class TokenService implements OnModuleInit { @@ -23,6 +24,7 @@ export class TokenService implements OnModuleInit { constructor( private readonly osmosisService: OsmosisService, + private readonly okp4Service: Okp4Service, private readonly cache: TokenCache, private readonly prismaService: PrismaService ) { @@ -95,7 +97,7 @@ export class TokenService implements OnModuleInit { async fetchAndCacheTokenInfo() { const res = (await this.osmosisService.getTokenInfo(config.app.token))[0]; const mcap = await this.getMcapByOrder(); - const apr = await this.osmosisService.getStakingApr(); + const apr = await this.okp4Service.getApr(); const tokenInfoDto: TokenInfoDto = { price: { diff --git a/src/modules/token/token.module.ts b/src/modules/token/token.module.ts index d63a818..e46ab5d 100644 --- a/src/modules/token/token.module.ts +++ b/src/modules/token/token.module.ts @@ -7,6 +7,7 @@ import { TokenJobs } from "./services/token.jobs"; import { PrismaService } from "@core/lib/prisma.service"; import { TokenController } from "./token.controller"; import { RedisService } from "@core/lib/redis.service"; +import { Okp4Service } from "@core/lib/okp4/okp4.service"; @Module({ imports: [], @@ -14,13 +15,12 @@ import { RedisService } from "@core/lib/redis.service"; PrismaService, HttpService, OsmosisService, + Okp4Service, TokenService, TokenCache, TokenJobs, RedisService, ], - controllers: [ - TokenController, - ] + controllers: [TokenController], }) -export class TokenModule {} \ No newline at end of file +export class TokenModule {}