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

Query and store old OpenBook orders into our DB #248

Open
LukasDeco opened this issue Aug 19, 2024 · 4 comments
Open

Query and store old OpenBook orders into our DB #248

LukasDeco opened this issue Aug 19, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@LukasDeco
Copy link
Contributor

LukasDeco commented Aug 19, 2024

We want to query these OpenBook programs and store the orders accordingly in our table. There are some functions and classes in the futarchy-indexer repo as well as accompanying tables that could allow this to be done with a lot of the initial setup taken care of.

You can use the transaction_watchers table with the Openbook Twap program account to index all transactions from this program. If you set the checked_up_to_slot column to 0, it should in theory re-index all of the transactions. You shouldn't get many new txns in the `transactions' table, but you will be able to run any new indexing logic you have built on these transactions.

Here are all the program account IDs you want "watch"/query transactions from:

twAP5sArq2vDS1mZCT7f4qRLwzTfHvf5Ay5R5Q5df1m
TWAPrdhADy2aTKN5iFZtNnkQYXERD9NvKjPFVPMSCNN
TWAP7frdvD3ia7TWc8e9SxZMmrpd2Yf3ifSPAHS8VG3

Definitely for staging, you will have to insert records in the transaction_watchers table with the checked_up_to_slot field at 0 and then set the first_tx_sig to null.

In the DB, if txns already are in there, you might need to delete those or maybe not.

An unfilled order record can be built from a placeOrder instruction based off the args:
Max Base Lots = unfilled base amount
Price Lots = quotePrice * 10 **6

a following cancelOrderByClientId ix will often let us know that the order is cancelled. BUT this will be tricky. We don't store the clientID of the order... so you might need to figure things out in a roundabout way. You might be able to use the openOrdersAccount pubkey on this tx to find the data you need. Here is an example: https://solscan.io/tx/3JbFRjRfXNNP1FDFE5zK1AwDzfuXw8qRNa8ULR6eSga76Tt46QseUesw2Q2xe2bYjm3z7rcqj1fQzh82pZ6soZaS

This is the openOrdersAccount tied to that txn: https://solscan.io/account/FSBrxyZWoaXGomRH2cyfAjHhfbzDGV9DdD2Q3gK7g2kA
you can find the original placeOrders ix that created the account and that would be able to potentially tell you which order in our orders table you need to update.

Example program account for openbook on devnet: https://explorer.solana.com/address/TWAPrdhADy2aTKN5iFZtNnkQYXERD9NvKjPFVPMSCNN?cluster=devnet

@LukasDeco LukasDeco converted this from a draft issue Aug 19, 2024
@LukasDeco LukasDeco added the enhancement New feature or request label Aug 19, 2024
@LukasDeco
Copy link
Contributor Author

How to handle different IXs coming through:

  • placeOrder -> (insert into orders table)
  • cancelOrderByClientId -> mark order as cancelled

Arcana market: https://app.arcana.markets/data/CciLvCtXAkGS5TMKNRDYBPFzfWWL7fwCQi79NRx5kTHz

@LukasDeco
Copy link
Contributor Author

@LukasDeco
Copy link
Contributor Author

Notes on convo with @R-K-H regarding actual trades(takes and makes):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants