Skip to content

Commit 4e4694b

Browse files
committed
Checking that token vault is empty and belogs to the token program
1 parent 0abe52c commit 4e4694b

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

token-lending/program/src/processor/liquidity_mining.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -242,21 +242,21 @@ mod add_pool_reward {
242242
/// Use [Self::new] to validate the parameters.
243243
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
244244
pub(super) struct AddPoolRewardParams {
245-
_priv: (),
246245
pub(super) position_kind: PositionKind,
247246
/// At least the current timestamp.
248247
pub(super) start_time_secs: u64,
249248
/// Larger than [MIN_REWARD_PERIOD_SECS].
250249
pub(super) duration_secs: u32,
251250
/// Larger than zero.
252251
pub(super) reward_token_amount: u64,
252+
253+
_priv: (),
253254
}
254255

255256
/// Use [Self::from_unchecked_iter] to validate the accounts except for
256257
/// * `reward_token_vault_info`
257258
/// * `rent_info`
258259
pub(super) struct AddPoolRewardAccounts<'a, 'info> {
259-
_priv: (),
260260
/// ✅ belongs to this program
261261
/// ✅ unpacks
262262
/// ✅ belongs to `lending_market_info`
@@ -269,6 +269,8 @@ mod add_pool_reward {
269269
pub(super) reward_token_source_info: &'a AccountInfo<'info>,
270270
/// ✅ seed of `lending_market_info`, `reserve_info`, `reward_mint_info`
271271
pub(super) reward_authority_info: &'a AccountInfo<'info>,
272+
/// ✅ belongs to the token program
273+
/// ✅ has no data
272274
/// ❓ we don't yet know whether it's rent exempt
273275
pub(super) reward_token_vault_info: &'a AccountInfo<'info>,
274276
/// ✅ belongs to this program
@@ -285,6 +287,8 @@ mod add_pool_reward {
285287
pub(super) token_program_info: &'a AccountInfo<'info>,
286288

287289
pub(super) reserve: Box<Reserve>,
290+
291+
_priv: (),
288292
}
289293

290294
impl AddPoolRewardParams {
@@ -322,12 +326,12 @@ mod add_pool_reward {
322326
}
323327

324328
Ok(Self {
325-
_priv: (),
326-
327329
position_kind,
328330
start_time_secs,
329331
duration_secs,
330332
reward_token_amount,
333+
334+
_priv: (),
331335
})
332336
}
333337
}
@@ -377,9 +381,16 @@ mod add_pool_reward {
377381
return Err(LendingError::InvalidAccountInput.into());
378382
}
379383

380-
Ok(Self {
381-
_priv: (),
384+
if reward_token_vault_info.owner != token_program_info.key {
385+
msg!("Reward token vault provided must be owned by the token program");
386+
return Err(LendingError::InvalidTokenOwner.into());
387+
}
388+
if !reward_token_vault_info.data.borrow().is_empty() {
389+
msg!("Reward token vault provided must be empty");
390+
return Err(LendingError::InvalidAccountInput.into());
391+
}
382392

393+
Ok(Self {
383394
reserve_info,
384395
reward_mint_info,
385396
reward_token_source_info,
@@ -391,6 +402,8 @@ mod add_pool_reward {
391402
token_program_info,
392403

393404
reserve,
405+
406+
_priv: (),
394407
})
395408
}
396409
}
@@ -400,16 +413,14 @@ mod cancel_pool_reward {
400413
use super::*;
401414

402415
pub(super) struct CancelPoolRewardParams {
403-
_priv: (),
404-
405416
position_kind: PositionKind,
406417
pool_reward_index: u64,
418+
419+
_priv: (),
407420
}
408421

409422
/// Use [Self::from_unchecked_iter] to validate the accounts.
410423
pub(super) struct CancelPoolRewardAccounts<'a, 'info> {
411-
_priv: (),
412-
413424
/// ✅ belongs to this program
414425
/// ✅ unpacks
415426
/// ✅ belongs to `lending_market_info`
@@ -433,6 +444,8 @@ mod cancel_pool_reward {
433444
pub(super) token_program_info: &'a AccountInfo<'info>,
434445

435446
pub(super) reserve: Box<Reserve>,
447+
448+
_priv: (),
436449
}
437450

438451
impl<'a, 'info> CancelPoolRewardAccounts<'a, 'info> {
@@ -498,10 +511,10 @@ mod cancel_pool_reward {
498511
impl CancelPoolRewardParams {
499512
pub(super) fn new(position_kind: PositionKind, pool_reward_index: u64) -> Self {
500513
Self {
501-
_priv: (),
502-
503514
position_kind,
504515
pool_reward_index,
516+
517+
_priv: (),
505518
}
506519
}
507520
}
@@ -511,10 +524,10 @@ mod close_pool_reward {
511524
use super::*;
512525

513526
pub(super) struct ClosePoolRewardParams {
514-
_priv: (),
515-
516527
position_kind: PositionKind,
517528
pool_reward_index: u64,
529+
530+
_priv: (),
518531
}
519532

520533
/// Use [Self::from_unchecked_iter] to validate the accounts.
@@ -590,8 +603,6 @@ mod close_pool_reward {
590603
}
591604

592605
Ok(Self {
593-
_priv: (),
594-
595606
reserve_info,
596607
reward_mint_info,
597608
reward_token_destination_info,
@@ -602,17 +613,19 @@ mod close_pool_reward {
602613
token_program_info,
603614

604615
reserve,
616+
617+
_priv: (),
605618
})
606619
}
607620
}
608621

609622
impl ClosePoolRewardParams {
610623
pub(super) fn new(position_kind: PositionKind, pool_reward_index: u64) -> Self {
611624
Self {
612-
_priv: (),
613-
614625
position_kind,
615626
pool_reward_index,
627+
628+
_priv: (),
616629
}
617630
}
618631
}

0 commit comments

Comments
 (0)