polymorpher / otc-country

0 stars 0 forks source link

Page showing recently created offers (last 1h, 24h, 7d, 30d), accepted offers, and filter them by assets #11

Closed jwst9 closed 2 weeks ago

jwst9 commented 1 month ago

From @polymorpher on July 3, 2024 via Telegram:

we need to have a page to show recently created offers (last 1h, 24h, 7d, 30d), accepted offers, and filter them by assets

You can do the filtering in frontend to keep it simple. But we also need a backend to index all these data. You can do a subgraph definition and have the subgraph node to monitor offer events, and inserts offers into Google Datastore or a postgres database. Then do a simple backend server that allows unauthenticated lookups based on duration or filter criteria). Or instead of doing subgraph, just have the backend to listen to contract events, and have a script that scans from block X to Y for all such events and insert missing entries to database (make sure no duplicate is inserted)

0xvgd commented 1 month ago

How about querying onchain events directly from the frontend instead of backend & db? and cache the result in local storage

polymorpher commented 1 month ago

You can't query events from nodes for longer than 1024 blocks, which is less than 1 hour

0xvgd commented 1 month ago

Sorry, I was able to query events 18 days ago using viem's createContractEventFilter. I think it's technically feasible to query events as much long as we want because events are stored on blocks

polymorpher commented 1 month ago

Each query can't span more than 1024 blocks, it is hard coded in RPC node code. Frontend would have to do over a thousand queries to get latest data without a backend index

0xvgd commented 1 month ago

You are right. I can't know how long ago we have to query the block following my approach.

0xvgd commented 1 month ago

Can you invite me to your google datastore?

0xvgd commented 1 month ago

show offer details when clicking it?

polymorpher commented 1 month ago

Clickable link (new window) to the domain

0xvgd commented 1 month ago

What should each event (created and accepted) show before clicking?

polymorpher commented 1 month ago

Source and destination asset, source amount, accept amount, exchange rate (based on current price), domain name, creation time, age

0xvgd commented 1 month ago

Should accepted offer show exchange rate based on the rate at the time of accepted? (instead of current price)

polymorpher commented 1 month ago

Yes. Show both if possible

0xvgd commented 1 month ago

It's hard to achieve pagination using gcp datastore / firestore as it doesn't fully support limit and "or where" How about switching to supabase (postgres)?

polymorpher commented 1 month ago

Postgres is fine.

Datastore limit query is https://cloud.google.com/datastore/docs/samples/datastore-limit#datastore_limit-nodejs . It also supports cursor and scan

where is by using filter, see https://github.com/polymorpher/sms-wallet/blob/e2c089e88b90cad226bc4389b8db5186e16e4bb2/server/src/data/generic.ts#L37 and related code for example.