Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 105 additions & 2 deletions programs/clearing_house/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::state::order_state::OrderState;
use crate::state::state::State;
use crate::state::user::{User, UserPositions};
use crate::state::user_orders::{OrderTriggerCondition, OrderType, UserOrders};
use crate::state::user_registry::UserRegistry;

#[derive(Accounts)]
#[instruction(
Expand Down Expand Up @@ -148,6 +149,68 @@ pub struct InitializeUserWithExplicitPayer<'info> {
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
#[instruction(user_registry_nonce: u8)]
pub struct InitializeUserRegistry<'info> {
#[account(
init,
seeds = [b"user_registry", authority.key.as_ref()],
bump = user_registry_nonce,
payer = authority
)]
pub user_registry: Box<Account<'info, UserRegistry>>,
#[account(mut)]
pub authority: Signer<'info>,
#[account(
has_one = authority,
)]
pub user: Box<Account<'info, User>>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
#[instruction(user_seed: u8, user_nonce: u8)]
pub struct AddUser<'info> {
#[account(
mut,
has_one = authority
)]
pub user_registry: Box<Account<'info, UserRegistry>>,
#[account(
init,
seeds = [
b"user",
user_seed.to_le_bytes().as_ref(),
authority.key.as_ref()
],
bump = user_nonce,
payer = authority
)]
pub user: Box<Account<'info, User>>,
pub state: Box<Account<'info, State>>,
#[account(
init,
payer = authority,
)]
pub user_positions: AccountLoader<'info, UserPositions>,
#[account(mut)]
pub authority: Signer<'info>,
pub rent: Sysvar<'info, Rent>,
pub system_program: Program<'info, System>,
}

#[derive(Accounts)]
pub struct UpdateUserName<'info> {
#[account(
mut,
has_one = authority
)]
pub user_registry: Box<Account<'info, UserRegistry>>,
#[account(mut)]
pub authority: Signer<'info>,
}

#[derive(Accounts)]
#[instruction(user_orders_nonce: u8)]
pub struct InitializeUserOrders<'info> {
Expand Down Expand Up @@ -236,7 +299,6 @@ pub struct InitializeMarket<'info> {

#[derive(Accounts)]
pub struct DepositCollateral<'info> {
#[account(mut)]
pub state: Box<Account<'info, State>>,
#[account(
mut,
Expand Down Expand Up @@ -276,7 +338,6 @@ pub struct DepositCollateral<'info> {

#[derive(Accounts)]
pub struct WithdrawCollateral<'info> {
#[account(mut)]
pub state: Box<Account<'info, State>>,
#[account(
mut,
Expand Down Expand Up @@ -327,6 +388,48 @@ pub struct WithdrawCollateral<'info> {
pub deposit_history: AccountLoader<'info, DepositHistory>,
}

#[derive(Accounts)]
pub struct TransferCollateral<'info> {
pub state: Box<Account<'info, State>>,
pub authority: Signer<'info>,
#[account(
mut,
has_one = authority,
constraint = &from_user.positions.eq(&from_user_positions.key())
)]
pub from_user: Box<Account<'info, User>>,
#[account(
mut,
constraint = &from_user_positions.load()?.user.eq(&from_user.key())
)]
pub from_user_positions: AccountLoader<'info, UserPositions>,
#[account(
mut,
has_one = authority,
constraint = &to_user.positions.eq(&to_user_positions.key())
)]
pub to_user: Box<Account<'info, User>>,
#[account(
mut,
constraint = &to_user_positions.load()?.user.eq(&to_user.key())
)]
pub to_user_positions: AccountLoader<'info, UserPositions>,
#[account(
constraint = &state.markets.eq(&markets.key())
)]
pub markets: AccountLoader<'info, Markets>,
#[account(
mut,
constraint = &state.funding_payment_history.eq(&funding_payment_history.key())
)]
pub funding_payment_history: AccountLoader<'info, FundingPaymentHistory>,
#[account(
mut,
constraint = &state.deposit_history.eq(&deposit_history.key())
)]
pub deposit_history: AccountLoader<'info, DepositHistory>,
}

#[derive(Accounts)]
pub struct WithdrawFees<'info> {
#[account(
Expand Down
Loading