From 062140cad14922f61291dee46ec03554040404bf Mon Sep 17 00:00:00 2001 From: Sashimi <93623541+sashimi36@users.noreply.github.com> Date: Sat, 14 May 2022 13:03:02 -0500 Subject: [PATCH] update apr math (#211) --- hooks/usePoolLiquidity.tsx | 20 ++++++++++---------- queries/tokenToTokenPriceQuery.ts | 27 +++++++++++++++------------ 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/hooks/usePoolLiquidity.tsx b/hooks/usePoolLiquidity.tsx index db6f167b..b121df8d 100644 --- a/hooks/usePoolLiquidity.tsx +++ b/hooks/usePoolLiquidity.tsx @@ -200,17 +200,17 @@ export const useMultiplePoolsLiquidity = ({ tokenAmountInMicroDenom: rewardsInfo.totalStakedInMicroDenom, }) || 1 + const totalRewardRatePerYearInDollarValue = + rewardsContracts.contracts.reduce((value, rewardsContract) => { + return ( + value + rewardsContract.rewardRate.ratePerYear.dollarValue + ) + }, 0) + rewardsInfo.yieldPercentageReturn = - rewardsContracts.contracts.reduce( - (yieldReturnValue, rewardsContract) => { - return ( - yieldReturnValue + - rewardsContract.rewardRate.ratePerYear.dollarValue / - rewardsInfo.totalStakedDollarValue - ) - }, - 0 - ) + (totalRewardRatePerYearInDollarValue / + rewardsInfo.totalStakedDollarValue) * + 100 } return { diff --git a/queries/tokenToTokenPriceQuery.ts b/queries/tokenToTokenPriceQuery.ts index 6cef8b75..9064d15d 100644 --- a/queries/tokenToTokenPriceQuery.ts +++ b/queries/tokenToTokenPriceQuery.ts @@ -27,18 +27,21 @@ export async function tokenToTokenPriceQuery({ return 1 } - if (fromTokenInfo.symbol === baseToken.symbol && toTokenInfo.swap_address) { - return formatPrice( - await getToken1ForToken2Price({ - nativeAmount: convertedTokenAmount, - swapAddress: toTokenInfo.swap_address, - rpcEndpoint: chainInfo.rpc, - }) - ) - } else if ( - toTokenInfo.symbol === baseToken.symbol && - fromTokenInfo.swap_address - ) { + const shouldQueryBaseTokenForTokenB = + fromTokenInfo.symbol === baseToken.symbol && toTokenInfo.swap_address + + const shouldQueryTokenBForBaseToken = + toTokenInfo.symbol === baseToken.symbol && fromTokenInfo.swap_address + + if (shouldQueryBaseTokenForTokenB) { + const resp = await getToken1ForToken2Price({ + nativeAmount: convertedTokenAmount, + swapAddress: toTokenInfo.swap_address, + rpcEndpoint: chainInfo.rpc, + }) + + return formatPrice(resp) + } else if (shouldQueryTokenBForBaseToken) { return formatPrice( await getToken2ForToken1Price({ tokenAmount: convertedTokenAmount,