Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4764,6 +4764,7 @@ pub fn handle_admin_deposit<'c: 'info, 'info>(
market_index,
explanation: DepositExplanation::Reward,
transfer_user: None,
signer: Some(ctx.accounts.admin.key()),
};
emit!(deposit_record);

Expand Down
16 changes: 14 additions & 2 deletions programs/drift/src/instructions/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,11 @@ pub fn handle_deposit<'c: 'info, 'info>(
} else {
DepositExplanation::None
};
let signer = if ctx.accounts.authority.key() == user.authority {
Copy link
Member

Choose a reason for hiding this comment

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

i think you want to flip this and log if it's a third party making the deposit?

Suggested change
let signer = if ctx.accounts.authority.key() == user.authority {
let signer = if ctx.accounts.authority.key() != user.authority {

Copy link
Member

Choose a reason for hiding this comment

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

should this be a newly named instruction to lower chance of accidental deposit into wrong account?

Some(ctx.accounts.authority.key())
} else {
None
Copy link
Member

@wphan wphan Sep 18, 2025

Choose a reason for hiding this comment

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

should this just always be ctx.accounts.authority? i guess that would make all events larger

Copy link
Member

Choose a reason for hiding this comment

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

prefer keeping it None for normal deposit to match historical schema

};
let deposit_record = DepositRecord {
ts: now,
deposit_record_id,
Expand All @@ -670,6 +675,7 @@ pub fn handle_deposit<'c: 'info, 'info>(
market_index,
explanation,
transfer_user: None,
signer,
};
emit!(deposit_record);

Expand Down Expand Up @@ -825,6 +831,7 @@ pub fn handle_withdraw<'c: 'info, 'info>(
total_withdraws_after: user.total_withdraws,
explanation: deposit_explanation,
transfer_user: None,
signer: None,
};
emit!(deposit_record);

Expand Down Expand Up @@ -995,6 +1002,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>(
total_withdraws_after: from_user.total_withdraws,
explanation: DepositExplanation::Transfer,
transfer_user: Some(to_user_key),
signer: None,
};
emit!(deposit_record);
}
Expand Down Expand Up @@ -1059,6 +1067,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>(
total_withdraws_after,
explanation: DepositExplanation::Transfer,
transfer_user: Some(from_user_key),
signer: None,
};
emit!(deposit_record);
}
Expand Down Expand Up @@ -1271,6 +1280,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
total_withdraws_after: from_user.total_withdraws,
explanation: DepositExplanation::Transfer,
transfer_user: Some(to_user_key),
signer: None,
};
emit!(deposit_record);

Expand Down Expand Up @@ -1305,6 +1315,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
total_withdraws_after: to_user.total_withdraws,
explanation: DepositExplanation::Transfer,
transfer_user: Some(from_user_key),
signer: None,
};
emit!(deposit_record);
}
Expand Down Expand Up @@ -1371,6 +1382,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
total_withdraws_after: from_user.total_withdraws,
explanation: DepositExplanation::Transfer,
transfer_user: Some(to_user_key),
signer: None,
};
emit!(deposit_record);

Expand Down Expand Up @@ -1405,6 +1417,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
total_withdraws_after: to_user.total_withdraws,
explanation: DepositExplanation::Transfer,
transfer_user: Some(from_user_key),
signer: None,
};
emit!(deposit_record);
}
Expand Down Expand Up @@ -4140,8 +4153,7 @@ pub struct InitializeReferrerName<'info> {
pub struct Deposit<'info> {
pub state: Box<Account<'info, State>>,
#[account(
mut,
constraint = can_sign_for_user(&user, &authority)?
mut
)]
pub user: AccountLoader<'info, User>,
#[account(
Expand Down
1 change: 1 addition & 0 deletions programs/drift/src/state/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct DepositRecord {
pub total_withdraws_after: u64,
pub explanation: DepositExplanation,
pub transfer_user: Option<Pubkey>,
pub signer: Option<Pubkey>,
}

#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)]
Expand Down
Loading