# Refactor sdk-serum interface ## Current State Flat interface with low to none security checks. ```go type Queries interface { GetMarketsStats(programId string) ([]solana.Account[MarketStatus], error) GetMarketStats(address string) (solana.Account[MarketStatus], error) GetOrderBook(address string) (solana.Account[OrderBook], error) LoadOrdersForOwner(owner string, market string) ([]OrderBook, error) GetOpenOrders(market string, owner string) ([]solana.PKAccount[solana.Account[OpenOrders]], error) GetFillsByMarket(market string) ([]FillEvent, error) LoadOrdersByOpenOrders(openOrdersAddresses []string, market string) ([][]OrderBook, error) } ``` ## Proposal Object oriented interface with the following interfaces. ### Client A client is created per serum deploy. We understand a serum deploy to be a tuple (network, programId) where network represents a solana network (devnet, mainnet-beta...) and programId is the address of the executable account "containing" the serum deploy. ```go type ISolanaRpc interface { GetAccountInfo(string, *solana.GetAccountInfoOptions) (solana.GetAccountInfoResult, error) GetProgramAccounts(string, *solana.GetProgramAccountsOptions) (solana.GetProgramAccountsResult, error) GetMultipleAccounts(pubkeys []string, options *solana.GetMultipleAccountsOptions) (solana.GetMultipleAccountsResult, error) } func New(connection ISolanaRpc, programId string) SerumSDK func (s SerumSDK) GetMarket(marketAddress string) (m Market, err error) ``` #### GetMarket Uses GetAccountInfo from ISolanaRpc and will do the following security checks when parsing account data: - [ ] check serum header - [x] check flag bits to verify it is a market account - [x] account owner coincides with expected programId - [x] marketAddress coincides with OwnAddress data field ### Market ```go type IMarket interface { LoadBids() (ob Orderbook, err error) LoadAsks() (ob Orderbook, err error) FindOpenOrdersAccountsForOwner(ownerAddress string) (oos []OpenOrders, err error) LoadOrdersForOwner(ownerAddress string) (os []Order, err error) LoadFills() (es []Event, err error) FilterForOpenOrders(bids Orderbook, asks Orderbook, openOrdersAccount []OpenOrders) (os []Order, err error) } ``` ## Serum Program Versions | Network | Address | Layout Version | Documentation | |:-------:|:-------:|:--------------:|:-------------:| | mainnet-beta | 4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn | 1 | [serum-ts](https://github.com/project-serum/serum-ts/blob/ec11b30fd373336806cd8e2df1873ac887c4e6e2/packages/serum/src/tokens_and_markets.ts#L12) | | mainnet-beta |BJ3jrUzddfuSrZHXSCxMUUQsjKEyLmuuyZebkcaFp2fg | 1 | [serum-ts](https://github.com/project-serum/serum-ts/blob/ec11b30fd373336806cd8e2df1873ac887c4e6e2/packages/serum/src/tokens_and_markets.ts#L12) | | mainnet-beta | EUqojwWA2rd19FZrzeBncJsm38Jm1hEhE3zsmX3bRc2o | 2 | [serum-ts](https://github.com/project-serum/serum-ts/blob/ec11b30fd373336806cd8e2df1873ac887c4e6e2/packages/serum/src/tokens_and_markets.ts#L12) | | mainnet-beta | 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin | 3 | [serum-ts](https://github.com/project-serum/serum-ts/blob/ec11b30fd373336806cd8e2df1873ac887c4e6e2/packages/serum/src/tokens_and_markets.ts#L12) | | devnet | DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY | 3 | [serum-dex](https://github.com/project-serum/serum-dex#program-deployments) |