Skip to content

Commit

Permalink
fix: update liquidity calculations and historical price data fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
vuonghuuhung committed Dec 2, 2024
1 parent e2fef8c commit 34e1fcf
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/libs/contractSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export function simulateIncentiveAprPosition(

// calculate APR for the best, position liquidity is 10% of total liquidity
let sumMaxIncentivesApr = 0;
const positionLiquidity = 10 ** 24;
const positionLiquidity = Number(pool.liquidity);
// const totalPositionLiquidity = (totalLiquidity * 0.5) / 100;
const tick_spacing = poolKey.fee_tier.tick_spacing;

Expand Down Expand Up @@ -792,7 +792,7 @@ export function simulateIncentiveAprPosition(

// calculate APR for the worst, position liquidity is 2% of total liquidity
let sumMinIncentivesApr = 0;
const positionLiquidity2 = 10 ** 24;
const positionLiquidity2 = Number(pool.liquidity);

const res2 = calculateAmountDelta(
pool.current_tick_index,
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Pool-V3/hooks/useCreatePositionForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ const useCreatePositionForm = (
time,
price: close
}));

data.push({
time: Date.now(),
price: currentPrice
})

const padding = 0.1;

const prices = data.map((d) => d.price);
Expand Down
12 changes: 6 additions & 6 deletions src/reducer/poolDetailV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ const initialState: PoolDetailV3State = {
tokenY: null,
isXToY: true,
historicalRange: '7d',
cache7Day: null,
cache1Month: null,
cache3Month: null,
cache1Year: null,
historicalChartData: null,
cache7Day: [],
cache1Month: [],
cache3Month: [],
cache1Year: [],
historicalChartData: [],
fullRange: false,
xRange: null,
yRange: null,
Expand Down Expand Up @@ -329,7 +329,7 @@ export const fetchHistoricalPriceData3M = createAsyncThunk(
export const fetchHistoricalPriceData7D = createAsyncThunk(
'poolDetailV3/fetchHistoricalPriceData7D',
async (poolId: string) => {
return await getHistoricalPriceDataInHour(poolId, '7d');
return await getHistoricalPriceDataInDay(poolId, '7d');
}
);

Expand Down
5 changes: 4 additions & 1 deletion src/rest/graphClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ export const getHistoricalPriceDataInDay = async (
default:
dayIndex = currentIndex - 7;
}

// create array of chunkOffset: [dayIndex, dayIndex + CHUNK_QUERY, ...] to current Index
const length = Math.ceil((currentIndex - dayIndex) / CHUNK_QUERY);
const chunkOffset = Array.from({ length }, (_, i) => dayIndex + i * CHUNK_QUERY);
Expand Down Expand Up @@ -750,6 +750,9 @@ export const getHistoricalPriceDataInDay = async (
poolId
};

// remove the last record and use the latest price
res.data.pop();

return res;
} catch (error) {
console.log('error getHistoricalPriceData', error);
Expand Down

0 comments on commit 34e1fcf

Please sign in to comment.