From 1716d7464d77c9928fee7b641513126ea3d168ea Mon Sep 17 00:00:00 2001 From: benber86 Date: Wed, 10 Mar 2021 21:12:02 +1100 Subject: [PATCH 1/2] Fix fees not calculated for first account to provide liquidity on a pair --- src/utils/returns.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/returns.ts b/src/utils/returns.ts index a80845d..c03b278 100644 --- a/src/utils/returns.ts +++ b/src/utils/returns.ts @@ -109,8 +109,16 @@ export function getMetricsForPositionWindow(positionT0: Position, positionT1: Po positionT1 = formatPricesForEarlyTimestamps(positionT1) // calculate ownership at ends of window, for end of window we need original LP token balance / new total supply - const t0Ownership = positionT0.liquidityTokenBalance / positionT0.liquidityTokenTotalSupply - const t1Ownership = positionT0.liquidityTokenBalance / positionT1.liquidityTokenTotalSupply + // eslint-disable-next-line eqeqeq + const t0Ownership = + positionT0.liquidityTokenTotalSupply != 0 + ? positionT0.liquidityTokenBalance / positionT0.liquidityTokenTotalSupply + : 0 + // eslint-disable-next-line eqeqeq + const t1Ownership = + positionT1.liquidityTokenTotalSupply != 0 + ? positionT0.liquidityTokenBalance / positionT1.liquidityTokenTotalSupply + : 0 // get starting amounts of token0 and token1 deposited by LP const token0_amount_t0 = t0Ownership * positionT0.reserve0 From 79ac297d3037e8e908e993303d064a319c62aae1 Mon Sep 17 00:00:00 2001 From: benber86 Date: Sun, 14 Mar 2021 18:07:08 +1100 Subject: [PATCH 2/2] move price conversion inside useEffect to avoid race condition --- src/contexts/User.js | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/src/contexts/User.js b/src/contexts/User.js index c596e3d..047abfc 100644 --- a/src/contexts/User.js +++ b/src/contexts/User.js @@ -289,6 +289,17 @@ export function useUserPositionChart(position, account) { pairSnapshots, currentETHPrice ) + if (fetchedData) { + for (let j = 0; j < fetchedData.length; j++) { + let latestAvaxPrice + if (j === fetchedData.length - 1) { + latestAvaxPrice = await getCurrentEthPrice() + } else { + latestAvaxPrice = await getEthPriceAtDate(fetchedData[j].date) + } + fetchedData[j].usdValue = fetchedData[j].usdValue * latestAvaxPrice + } + } updateUserPairReturns(account, pairAddress, fetchedData) } if ( @@ -315,25 +326,6 @@ export function useUserPositionChart(position, account) { position.pair.id, ]) - const convertPrice = async function () { - if (formattedHistory) { - for (let j = 0; j < formattedHistory.length; j++) { - let latestAvaxPrice - if (j === formattedHistory.length - 1) { - latestAvaxPrice = await getCurrentEthPrice() - } else { - latestAvaxPrice = await getEthPriceAtDate(formattedHistory[j].date) - } - formattedHistory[j].usdValue = formattedHistory[j].usdValue * latestAvaxPrice - } - } - return formattedHistory - } - - if (formattedHistory) { - convertPrice().then(result => { console.log("Finished waiting") }) - } - return formattedHistory }