Skip to content

Commit

Permalink
Merge pull request #37 from axone-protocol/fix/update-bonded-tokens-f…
Browse files Browse the repository at this point in the history
…ormula

fix: updated bonded tokens formula
  • Loading branch information
yevhen-burkovskyi authored Jun 19, 2024
2 parents a3f960a + 8f9705c commit 656d0f0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/core/lib/okp4/enums/endpoints.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export enum Endpoints {
GOV_PARAMS = 'cosmos/gov/v1/params/:params_type',
GOV_PROPOSALS = 'cosmos/gov/v1/proposals',
GOV_PROPOSAL = 'cosmos/gov/v1/proposals/:proposal_id',
STAKING_POOL = 'cosmos/staking/v1beta1/pool',
}
7 changes: 6 additions & 1 deletion src/core/lib/okp4/okp4.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { DelegatorValidatorsResponse } from "./responses/delegators-validators.r
import { DelegatorsRewardsResponse } from "./responses/delegators-rewards.response";
import { SpendableBalancesResponse } from "./responses/spendable-balances.response";
import { SupplyResponse } from "./responses/supply.response";
import { ValidatorStatus } from "./enums/validator-status.enum";
import { ValidatorDelegationsResponse } from "./responses/validator-delegations.response";
import { fromBase64, toBase64, fromHex, toHex } from "@cosmjs/encoding";
import { sha256 } from "@cosmjs/crypto";
Expand All @@ -24,6 +23,8 @@ import { GovType } from "./enums/gov-type.enum";
import { GovParamsResponse } from "./responses/gov-params.response";
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";

@Injectable()
export class Okp4Service {
Expand Down Expand Up @@ -240,4 +241,8 @@ export class Okp4Service {
): response is FailedResponse {
return (response as FailedResponse).message !== undefined;
}

async getStakingPool(): Promise<StakingPoolResponse> {
return this.getWithErrorHandling(this.constructUrl(Endpoints.STAKING_POOL));
}
}
6 changes: 6 additions & 0 deletions src/core/lib/okp4/responses/staking-pool.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface StakingPoolResponse {
pool: {
not_bonded_tokens: string;
bonded_tokens: string;
};
}
3 changes: 2 additions & 1 deletion src/modules/staking/services/staking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export class StakingService implements OnModuleInit {
this.okp4Service.getBondValidators(),
this.osmosisService.getStakingApr(),
this.fetchTotalSupply(),
this.okp4Service.getStakingPool(),
]);

const totalStaked = this.calculateTotalStaked(rez[0].validators);
Expand All @@ -163,7 +164,7 @@ export class StakingService implements OnModuleInit {
totalValidators: rez[0].pagination.total,
apr: rez[1],
totalStaked,
bondedTokens: Big(totalStaked).div(rez[2]!.amount).toString(),
bondedTokens: Big(rez[3].pool.bonded_tokens).div(rez[2]!.amount).toString(),
};

await this.cache.setGlobalStakedOverview(dto);
Expand Down

0 comments on commit 656d0f0

Please sign in to comment.