77//! implementation of the same feature.
88//!
99//! There are three admin-only ixs:
10- //! - [add_pool_reward]
11- //! - [cancel_pool_reward]
12- //! - [close_pool_reward]
10+ //! - [add_pool_reward] (TODO: add bpf tests)
11+ //! - [cancel_pool_reward] (TODO: add bpf tests)
12+ //! - [close_pool_reward] (TODO: add bpf tests)
1313//!
1414//! [suilend-lm]: https://github.com/solendprotocol/suilend/blob/dc53150416f352053ac3acbb320ee143409c4a5d/contracts/suilend/sources/liquidity_mining.move#L2
1515
@@ -33,6 +33,7 @@ use solana_program::{
3333 system_instruction,
3434 sysvar:: Sysvar ,
3535} ;
36+ use solend_sdk:: state:: discriminator:: AccountDiscriminator ;
3637use solend_sdk:: {
3738 error:: LendingError ,
3839 state:: { LendingMarket , PositionKind , Reserve } ,
@@ -282,9 +283,16 @@ pub(crate) fn upgrade_reserve(program_id: &Pubkey, accounts: &[AccountInfo]) ->
282283 // 3.
283284 //
284285
285- // sanity checks pack and unpack reserves is ok
286- let reserve = Reserve :: unpack ( & accounts. reserve_info . data . borrow ( ) ) ?;
287- Reserve :: pack ( reserve, & mut accounts. reserve_info . data . borrow_mut ( ) ) ?;
286+ // we upgrade discriminator as we've checked that the account is indeed
287+ // a reserve account in [UpgradeReserveAccounts::from_unchecked_iter]
288+ let mut data = accounts. reserve_info . data . borrow_mut ( ) ;
289+ data[ 0 ] = AccountDiscriminator :: Reserve as u8 ;
290+ // Now the reserve can unpack fine and doesn't have to worry about
291+ // migrations.
292+ // Instead it returns an error on an invalid discriminator.
293+ // This way a reserve cannot be mistaken for an obligation.
294+ let reserve = Reserve :: unpack ( & data) ?;
295+ Reserve :: pack ( reserve, & mut data) ?;
288296
289297 Ok ( ( ) )
290298}
0 commit comments