Skip to content

Commit

Permalink
Fix osmosis apr
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultJRD committed Feb 27, 2024
1 parent b8ad2ac commit 419c427
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
9 changes: 9 additions & 0 deletions src/api/imperatorApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ class ImperatorApi extends HttpClient {
},
TokenModel,
);

getOsmoApy = async () =>
this.request<number>(
{
url: '/apr/v2/staking',
method: 'GET',
},
Number,
);
}

export default ImperatorApi.getInstance();
28 changes: 19 additions & 9 deletions src/redux/models/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import dayjs from 'dayjs';
import { MICRO_LUM_DENOM } from '@lum-network/sdk-javascript';
import { PoolState } from '@lum-network/sdk-javascript/build/codegen/lum/network/millions/pool';

import { LumApi } from 'api';
import { ImperatorApi, LumApi } from 'api';

import { RootModel } from '.';

Expand Down Expand Up @@ -171,18 +171,28 @@ export const pools = createModel<RootModel>()({
const feesStakers = pool.feeTakers.reduce((acc, taker) => acc + Number(taker.amount), 0);

// Calculate APY
const [bonding, supply, communityTaxRate, inflation] = await Promise.all([
client.getBonding(),
client.getSupply(pool.nativeDenom),
client.getCommunityTaxRate(),
client.getInflation(),
]);
let nativeApy = 0;

if (DenomsUtils.getNormalDenom(pool.nativeDenom) === 'osmo') {
const [osmoApy] = await ImperatorApi.getOsmoApy();

nativeApy = osmoApy / 100;
} else {
const [bonding, supply, communityTaxRate, inflation] = await Promise.all([
client.getBonding(),
client.getSupply(pool.nativeDenom),
client.getCommunityTaxRate(),
client.getInflation(),
]);

const stakingRatio = NumbersUtils.convertUnitNumber(bonding || '0') / NumbersUtils.convertUnitNumber(supply || '1');

nativeApy = ((inflation || 0) * (1 - (communityTaxRate || 0))) / stakingRatio;
}

const stakingRatio = NumbersUtils.convertUnitNumber(bonding || '0') / NumbersUtils.convertUnitNumber(supply || '1');
const poolTvl = NumbersUtils.convertUnitNumber(pool.tvlAmount);
const poolSponsorTvl = NumbersUtils.convertUnitNumber(pool.sponsorshipAmount);

const nativeApy = ((inflation || 0) * (1 - (communityTaxRate || 0))) / stakingRatio;
const variableApy = (nativeApy * (1 - (feesStakers || 0)) * poolTvl) / (poolTvl - poolSponsorTvl);

pool.apy = variableApy * 100;
Expand Down

0 comments on commit 419c427

Please sign in to comment.