diff --git a/src/api/imperatorApi.ts b/src/api/imperatorApi.ts index d9a0a21..e4b636d 100644 --- a/src/api/imperatorApi.ts +++ b/src/api/imperatorApi.ts @@ -25,6 +25,15 @@ class ImperatorApi extends HttpClient { }, TokenModel, ); + + getOsmoApy = async () => + this.request( + { + url: '/apr/v2/staking', + method: 'GET', + }, + Number, + ); } export default ImperatorApi.getInstance(); diff --git a/src/redux/models/pools.ts b/src/redux/models/pools.ts index 8504d3c..0e3e4d6 100644 --- a/src/redux/models/pools.ts +++ b/src/redux/models/pools.ts @@ -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 '.'; @@ -171,18 +171,28 @@ export const pools = createModel()({ 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;