openbook-dex / openbook-v2

openbook-v2 monorepo, contains solana program and ts client
Other
152 stars 83 forks source link

How to get market id? #275

Open winktool opened 3 months ago

winktool commented 3 months ago

I want to write a Solana smart contract to get the market id via Cross Program Invocation (CPI) by providing the address of the tokens ,is this achievable, is there a simple example please? Thanks.

riordanp commented 2 months ago

Hi, the market pubkey cannot be derived from the token mints. There can be many markets for a given pair. You would have to look it up off-chain using a getProgramAccounts RPC call with a memcmp filter or two to target the correct base_mint/quote_mint, then choose the best market for your pair by whatever criteria and pass that in to your program.