Skip to content

Commit

Permalink
fetch tickmaps before ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
p6te committed May 6, 2024
1 parent 65afe38 commit ff32ad6
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions src/store/sagas/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,7 @@ export function* fetchTicksAndTickMaps(action: PayloadAction<FetchTicksAndTickMa

const pools = findPairs(tokenFrom, tokenTo, allPools)

const allTickMaps = yield* all([
...pools.map(pool =>
call(
[marketProgram, marketProgram.getTickmap],
new Pair(pool.tokenX, pool.tokenY, { fee: pool.fee.v, tickSpacing: pool.tickSpacing })
)
)
])

for (let i = 0; i < pools.length; i++) {
yield* put(
actions.setTickMaps({
index: pools[i].tickmap.toString(),
tickMapStructure: allTickMaps[i]
})
)
}
yield* call(fetchTickMaps, pools)

for (const pool of pools) {
const ticks = yield* call(
Expand All @@ -143,6 +127,30 @@ export function* fetchTicksAndTickMaps(action: PayloadAction<FetchTicksAndTickMa
}
}

function* fetchTickMaps(pools: PoolWithAddress[]) {
const networkType = yield* select(network)
const rpc = yield* select(rpcAddress)
const marketProgram = yield* call(getMarketProgram, networkType, rpc)

const allTickMaps = yield* all([
...pools.map(pool =>
call(
[marketProgram, marketProgram.getTickmap],
new Pair(pool.tokenX, pool.tokenY, { fee: pool.fee.v, tickSpacing: pool.tickSpacing })
)
)
])

for (let i = 0; i < pools.length; i++) {
yield* put(
actions.setTickMaps({
index: pools[i].tickmap.toString(),
tickMapStructure: allTickMaps[i]
})
)
}
}

export function* fetchNearestTicksForPair(action: PayloadAction<FetchTicksAndTickMaps>) {
const { tokenFrom, tokenTo, allPools } = action.payload
enum IsXtoY {
Expand All @@ -157,13 +165,15 @@ export function* fetchNearestTicksForPair(action: PayloadAction<FetchTicksAndTic

const pools = findPairs(tokenFrom, tokenTo, allPools)

yield* call(fetchTickMaps, pools)

const results = yield* all([
...pools.map(pool => {
const isXtoY = tokenFrom.equals(pool.tokenX)
return call(
[marketProgram, marketProgram.getClosestTicks],
new Pair(tokenFrom, tokenTo, { fee: pool.fee.v, tickSpacing: pool.tickSpacing }),
300,
21,
undefined,
isXtoY ? IsXtoY.Down : IsXtoY.Up
)
Expand Down

0 comments on commit ff32ad6

Please sign in to comment.