Skip to content

Commit

Permalink
update apr math (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
sashimi36 authored May 14, 2022
1 parent 5c61374 commit 062140c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
20 changes: 10 additions & 10 deletions hooks/usePoolLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 15 additions & 12 deletions queries/tokenToTokenPriceQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 062140c

Please sign in to comment.