Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candles v2 (time windows) #128

Merged
merged 7 commits into from
Nov 6, 2024
Merged

Candles v2 (time windows) #128

merged 7 commits into from
Nov 6, 2024

Conversation

grod220
Copy link
Contributor

@grod220 grod220 commented Nov 5, 2024

Closes prax-wallet/prax#229
Closes #92

  • Adds new db query to get window-based candles from new db
  • Removes old candle route + dependency on old events-based db
  • Assortment of refactoring
  • Note the design is not quite like the figma. Follow up UI work will be needed.
compressed.mov


export const useBook = (symbol1: string | undefined, symbol2: string | undefined) => {
export const useBook = () => {
const { baseSymbol, quoteSymbol } = usePathSymbols();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realizing a few hooks are relying upon async data fetching for the path symbols. This is not necessary because they are synchronously available. So created a new usePathSymbols(); for that.

Comment on lines +20 to +23
const jsonRes = (await res.json()) as RouteBookApiResponse;
if ('error' in jsonRes) {
throw new Error(jsonRes.error);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because nextjs can return an error field, we need to parse it and re-throw if we see it

Comment on lines +24 to +38
export const RedirectToPair = () => {
const { data, isLoading, error } = useQuery({
queryKey: ['redirectSymbols'],
retry: 1,
queryFn: redirectSymbolsQueryFn,
});

if (error) {
return <div className='text-red-600'>{String(error)}</div>;
} else if (isLoading || !data) {
return <div className='text-white'>Loading...</div>;
} else {
redirect(`/trade/${data.baseAsset}/${data.quoteAsset}`);
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was finding it a bit annoying that we had a hard-coded pair here. This causes issues when going back and forth between testnet/mainnet. When ahead and created a hook to pull the highest priority pair and show that as the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea, looks like this'd resolve #92 too. However when testing locally I get a pretty bizarre error that looks like the assets are being interpolated incorrectly:

dex-explorer-validator-bug

Locally I was using commit c507d1b and had updated my env vars to point to a pindexer db, rather than the old cometbft db.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely a bug in the implementation. I should have been filtering out delegation tokens, fixed! Also, added some sample priority scores: prax-wallet/registry#109.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, confirming resolved on my end:

dex-explorer-getting-better

Looks like the styling is sub-optimal but we can handle that in time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but we have an issue for that: #107

Comment on lines -8 to -10
// TODO: Delete when possible, this is deprecated
export class IndexerQuerier {
private pool: Pool;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bye bye old db client

@@ -72,10 +74,10 @@ export async function GET(req: NextRequest): Promise<NextResponse<AllResponses>>
output: baseAssetMetadata.penumbraAssetId,
});

const simQuerier = new SimulationQuerier({ grpcEndpoint });
const client = createClient(grpcEndpoint, SimulationService);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding the query classes to be unnecessary, we can just create a client in line when we want to query

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nearly this whole file was copied over from the previous implementation

Comment on lines 45 to 61
async candles(
baseAsset: AssetId,
quoteAsset: AssetId,
start: Date,
end: Date,
window: DurationWindow,
) {
return this.db
.selectFrom('dex_ex_price_charts')
.innerJoin('dex_ex_candlesticks', 'candlestick_id', 'dex_ex_candlesticks.id')
.select(['start_time', 'open', 'close', 'low', 'high', 'swap_volume', 'direct_volume'])
.where('the_window', '=', window)
.where('asset_start', '=', Buffer.from(baseAsset.inner))
.where('asset_end', '=', Buffer.from(quoteAsset.inner))
.where('start_time', '<', start)
.where('start_time', '>=', end)
.execute();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grod220
Copy link
Contributor Author

grod220 commented Nov 5, 2024

@conorsch after this is merged, the nextjs app will no longer have a dependency on the old database and only on the new one fyi.

@grod220 grod220 requested a review from a team November 5, 2024 19:27
Copy link
Contributor

@conorsch conorsch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Encountered one large bug related to the initial route redirect, see screenshot shared above. Standing by to assist with backend changes once we're happy with the diff.

import { OhlcData } from 'lightweight-charts';
import { DurationWindow } from '@/shared/database/schema.ts';

const DEX_ENABLED_DATE = '2024-08-01';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DEX_ENABLED_DATE const is applicable only to the penumbra-1 chain; in general I'd prefer to avoid assumptions about chain id in any of the frontend code bases. Practically speaking, I don't expect this specific assumption to have adverse affects for e.g. testnet chains, but at the same time, are we really gaining anything from it? The genesis date is not far behind the dex-enable date for penumbra-1, and as time goes on, the comparative savings on the query will be minuscule.

Is the motivation for this cut-off date to make queries more efficient, or does the cut-off date avoid the need for error handling or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. We should make this chain agnostic. Given we have such little data, it's hard for me to determine what is the upper bound for this query. Aka, should we only be pulling data from the last year? Alas, I'm going to remove the start/end date logic and just pull whatever candlestick data is in the database. Think it's worthwhile revisiting this topic in a year.

Comment on lines +24 to +38
export const RedirectToPair = () => {
const { data, isLoading, error } = useQuery({
queryKey: ['redirectSymbols'],
retry: 1,
queryFn: redirectSymbolsQueryFn,
});

if (error) {
return <div className='text-red-600'>{String(error)}</div>;
} else if (isLoading || !data) {
return <div className='text-white'>Loading...</div>;
} else {
redirect(`/trade/${data.baseAsset}/${data.quoteAsset}`);
}
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the idea, looks like this'd resolve #92 too. However when testing locally I get a pretty bizarre error that looks like the assets are being interpolated incorrectly:

dex-explorer-validator-bug

Locally I was using commit c507d1b and had updated my env vars to point to a pindexer db, rather than the old cometbft db.

@grod220
Copy link
Contributor Author

grod220 commented Nov 6, 2024

(@conorsch OOO today, but gave the approval ✅ offline)

@grod220 grod220 merged commit b245695 into main Nov 6, 2024
2 checks passed
@grod220 grod220 deleted the candle-refactor branch November 6, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Candles from Pindexer for chart Make initial route redirect configurable
2 participants