Skip to content

Commit d04e6fc

Browse files
committed
program: let anotehr signer deposit on user behalf
1 parent 5b84861 commit d04e6fc

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

programs/drift/src/instructions/admin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,6 +4764,7 @@ pub fn handle_admin_deposit<'c: 'info, 'info>(
47644764
market_index,
47654765
explanation: DepositExplanation::Reward,
47664766
transfer_user: None,
4767+
signer: Some(ctx.accounts.admin.key()),
47674768
};
47684769
emit!(deposit_record);
47694770

programs/drift/src/instructions/user.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@ pub fn handle_deposit<'c: 'info, 'info>(
653653
} else {
654654
DepositExplanation::None
655655
};
656+
let signer = if ctx.accounts.authority.key() == user.authority {
657+
Some(ctx.accounts.authority.key())
658+
} else {
659+
None
660+
};
656661
let deposit_record = DepositRecord {
657662
ts: now,
658663
deposit_record_id,
@@ -670,6 +675,7 @@ pub fn handle_deposit<'c: 'info, 'info>(
670675
market_index,
671676
explanation,
672677
transfer_user: None,
678+
signer,
673679
};
674680
emit!(deposit_record);
675681

@@ -825,6 +831,7 @@ pub fn handle_withdraw<'c: 'info, 'info>(
825831
total_withdraws_after: user.total_withdraws,
826832
explanation: deposit_explanation,
827833
transfer_user: None,
834+
signer: None,
828835
};
829836
emit!(deposit_record);
830837

@@ -995,6 +1002,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>(
9951002
total_withdraws_after: from_user.total_withdraws,
9961003
explanation: DepositExplanation::Transfer,
9971004
transfer_user: Some(to_user_key),
1005+
signer: None,
9981006
};
9991007
emit!(deposit_record);
10001008
}
@@ -1059,6 +1067,7 @@ pub fn handle_transfer_deposit<'c: 'info, 'info>(
10591067
total_withdraws_after,
10601068
explanation: DepositExplanation::Transfer,
10611069
transfer_user: Some(from_user_key),
1070+
signer: None,
10621071
};
10631072
emit!(deposit_record);
10641073
}
@@ -1271,6 +1280,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
12711280
total_withdraws_after: from_user.total_withdraws,
12721281
explanation: DepositExplanation::Transfer,
12731282
transfer_user: Some(to_user_key),
1283+
signer: None,
12741284
};
12751285
emit!(deposit_record);
12761286

@@ -1305,6 +1315,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
13051315
total_withdraws_after: to_user.total_withdraws,
13061316
explanation: DepositExplanation::Transfer,
13071317
transfer_user: Some(from_user_key),
1318+
signer: None,
13081319
};
13091320
emit!(deposit_record);
13101321
}
@@ -1371,6 +1382,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
13711382
total_withdraws_after: from_user.total_withdraws,
13721383
explanation: DepositExplanation::Transfer,
13731384
transfer_user: Some(to_user_key),
1385+
signer: None,
13741386
};
13751387
emit!(deposit_record);
13761388

@@ -1405,6 +1417,7 @@ pub fn handle_transfer_pools<'c: 'info, 'info>(
14051417
total_withdraws_after: to_user.total_withdraws,
14061418
explanation: DepositExplanation::Transfer,
14071419
transfer_user: Some(from_user_key),
1420+
signer: None,
14081421
};
14091422
emit!(deposit_record);
14101423
}
@@ -4140,8 +4153,7 @@ pub struct InitializeReferrerName<'info> {
41404153
pub struct Deposit<'info> {
41414154
pub state: Box<Account<'info, State>>,
41424155
#[account(
4143-
mut,
4144-
constraint = can_sign_for_user(&user, &authority)?
4156+
mut
41454157
)]
41464158
pub user: AccountLoader<'info, User>,
41474159
#[account(

programs/drift/src/state/events.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ pub struct DepositRecord {
5151
pub total_withdraws_after: u64,
5252
pub explanation: DepositExplanation,
5353
pub transfer_user: Option<Pubkey>,
54+
pub signer: Option<Pubkey>,
5455
}
5556

5657
#[derive(Clone, Copy, BorshSerialize, BorshDeserialize, PartialEq, Eq, Default)]

0 commit comments

Comments
 (0)