Skip to content

Permissioned markets#150

Closed
armaniferrante wants to merge 5 commits into
masterfrom
armani/auth
Closed

Permissioned markets#150
armaniferrante wants to merge 5 commits into
masterfrom
armani/auth

Conversation

@armaniferrante

@armaniferrante armaniferrante commented Jul 13, 2021

Copy link
Copy Markdown
Contributor

Summary

Changes that provide the ability to host "permissioned markets" on the orderbook.

A permissioned market is a regular Serum market with an additional authority, which must sign every transaction to create an open orders account. In practice, what this means is that one can create a program that acts as this authority and that marks its own PDAs as the owner of all created open orders accounts, making the program the sole arbiter over who can trade on a given market and what trades can be made.

An example can be found here, where all trades that execute on the markets authorized by the program are required to both provide an identity token and set the referral to a hard coded address.

Accounts

Adds an authority and prune_authority field to the MarketState. To do this in a way that is not breaking, this PR

  • Creates a MarketStateV2 account layout that adds the new fields.
  • Creates a frontend Market enum that acts as a a unified interface for accessing the different market state versions.
  • When creating a market, if the authority doesn't exist, then creates a v1 market state account. Otherwise creates a v2 market state account.
  • When reading a market, check the data length. If it's equal to the v1 market state account, interpret as v1. Otherwise, interpret as v2.

Instructions

  • Adds a Prune instruction that removes all orders from the order book. This instruction must be authorized by the prune authority (optional).
  • Otherwise, no instruction data is changed.
  • Accounts list changes are made to InitializeMarket and InitOpenOrders instructions, where an optional account--the market authority and prune authority (for InitailizeMarket)--is_ added to each instruction.

Related Changes

Individual PRs.

For easier review, I've broken these changes into three PRs.

Breaking Changes

Although the program can be upgraded in a way such that existing accounts and composing programs on-chain will not break, there are some breaking changes made to the serum_dex crate.

  • MarketState::load method is removed. Programs and clients should switch to using Market::load.
  • instruction::init_open_orders has a new Option<&Pubkey> parameter added for the market authority.
  • instruction::initialize_market has a new Option<&Pubkey> parameter added for the market authority.

Comment thread dex/src/state.rs
fee_tier,
} = args;

let open_orders_mut = open_orders.deref_mut();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is required so that an open orders PDA can be the authority of itself. On CPI, solana_program::program::invoke will try to borrow the refcell, and so this borrow must be dropped prior to CPI.

Comment thread dex/src/state.rs
pub struct MarketStateV2 {
pub inner: MarketState,
pub authority: Pubkey,
pub prune_authority: Pubkey,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add padding so that we can add additional fields in the future.

@armaniferrante

Copy link
Copy Markdown
Contributor Author

I've broken this PR into three components that can be reviewed separately.

@armaniferrante

Copy link
Copy Markdown
Contributor Author

Closing. See the description above for subsequent changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant