# Account Model

{% embed url="<https://whimsical.com/exchange-usdc-FkTYk5zrcvtgEGLSPbykbS>" %}

## Exchange Account

#### PDA Seeds

```
["exchange", exchange_id: u64]
```

#### Account

<table><thead><tr><th width="210">Value</th><th width="413">Definition</th><th></th></tr></thead><tbody><tr><td>accounting</td><td>Struct holding exchange accounting values (see below)</td><td></td></tr><tr><td>settings</td><td>Struct holding exchange settings  (see below)</td><td></td></tr><tr><td>id</td><td>unique id for exchange account used in PDA</td><td></td></tr><tr><td>market_ids</td><td>Set of ids corresponding to the exchange's active markets </td><td></td></tr><tr><td>oracle_configs</td><td>Set of authorized oracle programs</td><td></td></tr><tr><td>status</td><td>Bitmask where bits are paused actions for the exchange. Actions include DepositMargin, WithdrawMargin, AddLiquidity, RemoveLiquidity, IncreasePosition, DecreasePosition, Liquidate, ProcessSettlementRequests</td><td></td></tr><tr><td>collateral_expo</td><td>Collateral token's decimals stored as i16</td><td></td></tr><tr><td>collateral_mint</td><td>Collateral token mint address</td><td></td></tr><tr><td>collateral_vault</td><td>Exchange's collateral token account </td><td></td></tr><tr><td>admin</td><td>Exchange's admin address</td><td></td></tr><tr><td>nominated_admin</td><td>Staged new admin address</td><td></td></tr><tr><td>authorized_settler</td><td>Address of authorized account that does not accept settlement tips</td><td></td></tr><tr><td>authorized_protocol_fees_collector</td><td>Address of account authorized to collect protocol fees on admin's behalf</td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### Exchange Accounting

<table><thead><tr><th width="287">Value</th><th>Definition</th><th></th></tr></thead><tbody><tr><td>notional_open_interest</td><td>Notional collateral value of open interest across all markets</td><td></td></tr><tr><td>unrealized_pnl</td><td>Last cached unrealized pnl estimate</td><td></td></tr><tr><td>last_time_locked_open_interest_accounting_refreshed</td><td>Last unix timestamp when unrealized pnl and notional oi were refreshed</td><td></td></tr><tr><td>balance</td><td>The exchange's collateral balance. This value increases and decreases with trader pnl and trading fees</td><td></td></tr><tr><td>margin_balance</td><td>Total deposited margin collateral</td><td></td></tr><tr><td>lp_balance</td><td>Total deposited LP collateral</td><td></td></tr><tr><td>lp_shares</td><td>Total shares outstanding</td><td></td></tr><tr><td>protocol_fees</td><td>Uncollected protocol fees</td><td></td></tr><tr><td>unsettled_collateral_amount</td><td>Total withdrawn collateral amount that is pending settlement</td><td></td></tr></tbody></table>

### Exchange Settings

<table><thead><tr><th width="293">Value</th><th width="444">Definition</th><th></th></tr></thead><tbody><tr><td>min_lp_duration</td><td>The minimum amount of time in seconds an LP must hold their LP deposit </td><td></td></tr><tr><td>settlement_delay</td><td>The amount of time used to set a settlement request's maturity field during withdraw_margin or remove_liquidity instructions. Used for settlement request validation in process_settlement_requests</td><td></td></tr><tr><td>min_liquidation_fee</td><td>If liquidation fee is smaller than this collateral value, then use this value. </td><td></td></tr><tr><td>max_liquidation_fee</td><td>If liquidation fee is larger than this collateral value, then use this value. </td><td></td></tr><tr><td>locked_open_interest_staleness_threshold</td><td>Max staleness tolerance in seconds for refreshing unrealized pnl and notional oi cache </td><td></td></tr><tr><td>protocol_fee_rate</td><td>Protocol's percentage share of each trading fee </td><td></td></tr><tr><td>locked_open_interest_ratio</td><td>Percentage of notional oi that LPs must maintain. </td><td></td></tr><tr><td>max_keeper_tip_rate</td><td>The maximum keeper tip percentage of collateral to settle.</td><td></td></tr></tbody></table>

## Market Account

#### PDA Seeds

```
["market", exchange_address: Pubkey, market_id: u32]
```

<table><thead><tr><th>Value</th><th width="357">Definition</th><th></th></tr></thead><tbody><tr><td>settings</td><td>Struct holding exchange settings (see below)</td><td></td></tr><tr><td>accounting</td><td>Struct holding exchange accounting values (see below)</td><td></td></tr><tr><td>id</td><td>Unique market id used in PDA</td><td></td></tr><tr><td>exchange</td><td>Exchange address</td><td></td></tr><tr><td>price_feed</td><td>Price feed address</td><td></td></tr><tr><td>status</td><td>Bitmask where bits are paused actions for this market. Actions include IncreasePosition and DecreasePosition</td><td></td></tr></tbody></table>

### Market Accounting

<table><thead><tr><th width="359">Value</th><th width="375">Definition</th><th></th></tr></thead><tbody><tr><td>weighted_position_price</td><td>Weighted average price for all open positions using position base asset units for weighting. Used in unrealized pnl estimates</td><td></td></tr><tr><td>last_utilized_liquidation_capacity</td><td>Amount of notional oi that has been utilized in the current epoch</td><td></td></tr><tr><td>size</td><td>Market's total open interest measured in base asset units. </td><td></td></tr><tr><td>skew</td><td>Market's skew measured in base asset units. Signed where positive means long skew and negative means short skew.</td><td></td></tr><tr><td>weighted_position_funding_per_unit</td><td>Weighted average funding per unit for all open positions using position base asset units for weighting. Used in unrealized pnl estimates</td><td></td></tr><tr><td>last_funding_rate</td><td>Latest funding rate accumulation. Stored as a PreciseInt.</td><td></td></tr><tr><td>last_funding_per_unit</td><td>Latest funding per unit accumulation. Stored as a PreciseInt.</td><td></td></tr><tr><td>last_time_funding_updated</td><td>Unix timestamp updated with the current timestamp each time an instruction cranks funding  </td><td></td></tr><tr><td>first_liquidation_epoch_start_time</td><td>Tracks the start of the liquidation epochs for discrete epoch index calculations</td><td></td></tr><tr><td>last_liquidation_epoch_index</td><td>Last seen liquidation epoch index which reflects which discrete period the market is in  </td><td></td></tr><tr><td>last_time_liquidation_capacity_updated</td><td>Unix timestamp marking last time a liquidate instruction updated the epoch's capacity</td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

### Market Settings

<table><thead><tr><th width="329">Value</th><th width="401">Definition</th><th></th></tr></thead><tbody><tr><td>min_position_margin</td><td>Smallest margin amount a position must maintain</td><td></td></tr><tr><td>skew_scale</td><td>Normalization scaler for skew </td><td></td></tr><tr><td>max_side_size</td><td>Open interest cap per side of the market</td><td></td></tr><tr><td>max_liquidation_limit_accumulation_multiplier</td><td>Multiplier used in determining liquidation epoch capacity</td><td></td></tr><tr><td>max_seconds_in_liquidation_epoch</td><td>Max length of a liquidation epoch. Each liquidation epoch has a maximum amount of capacity that can be liquidated. </td><td></td></tr><tr><td>initial_margin_ratio</td><td>The percentage applied to the position's size normalized by skew_scale</td><td></td></tr><tr><td>maker_fee_rate</td><td>Percentage fee rate applied to the notional maker portion of a trade  </td><td></td></tr><tr><td>taker_fee_rate</td><td>Percentage fee rate applied to the notional taker portion of a trade</td><td></td></tr><tr><td>max_funding_velocity</td><td>Max possible rate of change per day for the funding rate if skew is 100% of skew_scale</td><td></td></tr><tr><td>liquidation_fee_rate</td><td>Percentage fee rate applied to notional liquidation amounts paid to liquidator's margin account</td><td></td></tr><tr><td>min_initial_margin_ratio</td><td>The constant initial margin percentage added to the dynamic portion. Sets the maximum leverage multiple.</td><td></td></tr><tr><td>maintenance_margin_proportion</td><td>Percentage applied to computed initial margin ratio</td><td></td></tr><tr><td>max_liquidation_pd</td><td>Premium/discount (skew/skew_scale) percentage that the market tolerates for liquidation capacity being used even if epoch capacity is depleted.</td><td></td></tr><tr><td>authorized_liquidator</td><td>Address of the market's authorized account that can optionally skip liquidation epoch capacity and fully liquidate eligible accounts. This account does not accept liquidation fees. </td><td></td></tr></tbody></table>

## LP Position

#### PDA Seeds

```
["lp_position", exchange_address: Pubkey, owner_address: Pubkey, lp_position_id: u64]
```

<table><thead><tr><th width="276">Value</th><th width="391">Definition</th><th></th></tr></thead><tbody><tr><td>id</td><td>Unique id for lp position account used in PDA</td><td></td></tr><tr><td>liquidity</td><td>Total collateral amount deposited as exchange liquidity</td><td></td></tr><tr><td>shares</td><td>Total LP shares owned by this account </td><td></td></tr><tr><td>maturity</td><td>Unix timestamp after which this position's liquidity can be can be partially or fully removed. </td><td></td></tr><tr><td>exchange</td><td>Exchange address</td><td></td></tr><tr><td>owner</td><td>Position owner's address</td><td></td></tr></tbody></table>

## Margin Account

#### PDA Seeds

```
["margin_account", exchange_address: Pubkey, owner_address: Pubkey, margin_account_id: u32]
```

<table><thead><tr><th width="199">Value</th><th width="476">Definition</th><th></th></tr></thead><tbody><tr><td>positions</td><td>Set of active positions (see below)</td><td></td></tr><tr><td>margin</td><td>Total margin collateral deposited. This value increases and decreases with settled pnl</td><td></td></tr><tr><td>max_liquidation_fee</td><td>Set during the first liquidation ix for this account and updatd in subsequent liquidaitons, if there are any. Used to cap liquidation fees over potentially multiple ixs. </td><td></td></tr><tr><td>id</td><td>Unique id for the account used in PDA</td><td></td></tr><tr><td>exchange</td><td>Exchange address</td><td></td></tr><tr><td>owner</td><td>Account owner's address</td><td></td></tr><tr><td>delegate</td><td>Delegate's address. Delegate is set and unset by owner. Delegate can sign for deposit_margin ix and modify_position ix but cannot sign for any other margin account ixs.</td><td></td></tr><tr><td>in_liquidation</td><td>Flag marking the account is currently in liquidation. This means the account is being liquidated across multiple liquidation ixs.</td><td></td></tr></tbody></table>

### Position

<table><thead><tr><th width="303">Value</th><th width="334">Definition</th><th></th></tr></thead><tbody><tr><td>size</td><td>Size of the position in base asset units. Signed where positive means long position and negative means short position</td><td></td></tr><tr><td>last_interaction_price</td><td>Fill price of last trade. Subtracted from current fill price in next pnl calculation</td><td></td></tr><tr><td>last_interaction_funding_per_unit</td><td>Associated market's funding per unit during last trade. Subtracted from current funding per unit in next pnl calculation   </td><td></td></tr><tr><td>market_id</td><td>Id of the market this position belongs to</td><td></td></tr></tbody></table>

## Settlement Request

#### PDA Seeds

```
["settlement_request", owner_address: Pubkey, settlement_request_id: u64]
```

<table><thead><tr><th>Value</th><th width="314">Definition</th><th></th></tr></thead><tbody><tr><td>id</td><td>Unique id for request used in PDA</td><td></td></tr><tr><td>maturity</td><td>Unix timestamp when the request can be processed and settled. </td><td></td></tr><tr><td>amount</td><td>The collateral amount that will be transferred to request.owner_token_account during settlement.</td><td></td></tr><tr><td>keeper_tip</td><td>Collateral tip that the owner has allocated to the keeper who processes the settlement request once it has reached maturity calling the process_settlement_requests ix. Tip is a percentage of request.amount. This percentage cannot exceed the exchange's max tip percentage setting.</td><td></td></tr><tr><td>exchange</td><td>Address of the associated exchange</td><td></td></tr><tr><td>owner</td><td>Address of the request's owner who is the authority of the request.owner_token_account</td><td></td></tr><tr><td>owner_token_account</td><td>Destination token account address for settled collateral transfer. Protocol enforces must be ata.</td><td></td></tr><tr><td></td><td></td><td></td></tr></tbody></table>

## LP Account (deprecated)

<table><thead><tr><th width="276">Value</th><th width="391">Definition</th><th></th></tr></thead><tbody><tr><td>liquidity</td><td>Total collateral amount deposited as exchange liquidity</td><td></td></tr><tr><td>shares</td><td>Total LP shares controlled by this account </td><td></td></tr><tr><td>last_add_liquidity_timestamp</td><td>Weighted average unix timestamp using liquidity deposits for weighting. Validated against exchange.min_lp_duration in remove_liquidity ix</td><td></td></tr><tr><td>exchange</td><td>Exchange address</td><td></td></tr><tr><td>owner</td><td>Account owner's address</td><td></td></tr><tr><td>delegate</td><td>Delegate's address. Delegate is set and unset by owner. Delegate can sign for add_liquidity ix but cannot sign for any other LP account ixs.</td><td></td></tr></tbody></table>
