From d04e6fc174c7c65c441b62ab3d310e629f4dee37 Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 17 Sep 2025 17:18:43 -0400 Subject: [PATCH 1/3] program: let anotehr signer deposit on user behalf --- programs/drift/src/instructions/admin.rs | 1 + programs/drift/src/instructions/user.rs | 16 ++++++++++++++-- programs/drift/src/state/events.rs | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/programs/drift/src/instructions/admin.rs b/programs/drift/src/instructions/admin.rs index a4ecc2f8d1..cfdca1810a 100644 --- a/programs/drift/src/instructions/admin.rs +++ b/programs/drift/src/instructions/admin.rs @@ -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); diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index e6d13d6fec..db9578d669 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -653,6 +653,11 @@ pub fn handle_deposit<'c: 'info, 'info>( } else { DepositExplanation::None }; + let signer = if ctx.accounts.authority.key() == user.authority { + Some(ctx.accounts.authority.key()) + } else { + None + }; let deposit_record = DepositRecord { ts: now, deposit_record_id, @@ -670,6 +675,7 @@ pub fn handle_deposit<'c: 'info, 'info>( market_index, explanation, transfer_user: None, + signer, }; emit!(deposit_record); @@ -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); @@ -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); } @@ -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); } @@ -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); @@ -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); } @@ -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); @@ -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); } @@ -4140,8 +4153,7 @@ pub struct InitializeReferrerName<'info> { pub struct Deposit<'info> { pub state: Box>, #[account( - mut, - constraint = can_sign_for_user(&user, &authority)? + mut )] pub user: AccountLoader<'info, User>, #[account( diff --git a/programs/drift/src/state/events.rs b/programs/drift/src/state/events.rs index f4806fa5be..d193e17c83 100644 --- a/programs/drift/src/state/events.rs +++ b/programs/drift/src/state/events.rs @@ -51,6 +51,7 @@ pub struct DepositRecord { pub total_withdraws_after: u64, pub explanation: DepositExplanation, pub transfer_user: Option, + pub signer: Option, } #[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)] From 69130152a2313dfd9c40e47ba93b7b818474dcfd Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 1 Oct 2025 09:32:01 +0800 Subject: [PATCH 2/3] fix bug --- programs/drift/src/instructions/user.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index db9578d669..d3ec7cc666 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -653,7 +653,7 @@ pub fn handle_deposit<'c: 'info, 'info>( } else { DepositExplanation::None }; - let signer = if ctx.accounts.authority.key() == user.authority { + let signer = if ctx.accounts.authority.key() != user.authority { Some(ctx.accounts.authority.key()) } else { None From 2df49ea5726d9edefbacf37d88dc97f3cde927db Mon Sep 17 00:00:00 2001 From: Chris Heaney Date: Wed, 1 Oct 2025 09:32:49 +0800 Subject: [PATCH 3/3] cargo fmt -- --- programs/drift/src/instructions/user.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/programs/drift/src/instructions/user.rs b/programs/drift/src/instructions/user.rs index d3ec7cc666..ac60cb0d26 100644 --- a/programs/drift/src/instructions/user.rs +++ b/programs/drift/src/instructions/user.rs @@ -4152,9 +4152,7 @@ pub struct InitializeReferrerName<'info> { #[instruction(market_index: u16,)] pub struct Deposit<'info> { pub state: Box>, - #[account( - mut - )] + #[account(mut)] pub user: AccountLoader<'info, User>, #[account( mut,