openbook-dex / openbook-v2

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

Program Order ID Gen & OB Client Order ID Type Mismatch #271

Open wiseaidev opened 4 months ago

wiseaidev commented 4 months ago

Hello!

To generate order ids, we can utilize the built-in gen_order_id utility function: https://github.com/openbook-dex/openbook-v2/blob/b954445f532ee1b54fb404139ba3617ec12eb636/programs/openbook-v2/src/state/market.rs#L188

But the returned order_id type is u128, and when placing a new limit order, it is taking a u64 as order id type param: https://github.com/openbook-dex/openbook-v2/blob/b954445f532ee1b54fb404139ba3617ec12eb636/lib/client/src/client.rs#L388

Using the above function and downcasting the value to u64 can cause an overflow and returning the same order id each time a limit order is placed. Therefore, I suggest to either make the order id type u128, or make the gen_order_id function return a u64 id to match the order id type when placing, cancelling, etc orders.

Best!

riordanp commented 3 months ago

Sorry for the late reply, but these are two different fields. client_order_id is assigned by you and you can make it whatever you want (sequence number and timestamp are common). order_id is assigned by the program and it's not possible in all cases to know it before you submit your order. Hope this helps!