@@ -20,6 +20,8 @@ use oracles::pyth::validate_pyth_keys;
2020use oracles:: switchboard:: validate_sb_on_demand_keys;
2121use oracles:: switchboard:: validate_switchboard_keys;
2222use oracles:: { get_oracle_type, pyth:: validate_pyth_price_account_info, OracleType } ;
23+ #[ cfg( not( feature = "test-bpf" ) ) ]
24+ use solana_program:: pubkey;
2325use solana_program:: {
2426 account_info:: { next_account_info, AccountInfo } ,
2527 entrypoint:: ProgramResult ,
@@ -196,6 +198,10 @@ pub fn process_instruction(
196198 msg ! ( "Instruction: Mark Obligation As Closable" ) ;
197199 process_set_obligation_closeability_status ( program_id, closeable, accounts)
198200 }
201+ LendingInstruction :: DonateToReserve { liquidity_amount } => {
202+ msg ! ( "Instruction: Donate To Reserve" ) ;
203+ process_donate_to_reserve ( program_id, liquidity_amount, accounts)
204+ }
199205 }
200206}
201207
@@ -3187,6 +3193,76 @@ pub fn process_set_obligation_closeability_status(
31873193 Ok ( ( ) )
31883194}
31893195
3196+ /// process donate to reserve
3197+ pub fn process_donate_to_reserve (
3198+ program_id : & Pubkey ,
3199+ liquidity_amount : u64 ,
3200+ accounts : & [ AccountInfo ] ,
3201+ ) -> ProgramResult {
3202+ let account_info_iter = & mut accounts. iter ( ) ;
3203+ let source_liquidity_info = next_account_info ( account_info_iter) ?;
3204+ let destination_liquidity_info = next_account_info ( account_info_iter) ?;
3205+ let reserve_info = next_account_info ( account_info_iter) ?;
3206+ let lending_market_info = next_account_info ( account_info_iter) ?;
3207+ let user_transfer_authority_info = next_account_info ( account_info_iter) ?;
3208+ let token_program_id = next_account_info ( account_info_iter) ?;
3209+ let clock = & Clock :: get ( ) ?;
3210+
3211+ let lending_market = LendingMarket :: unpack ( & lending_market_info. data . borrow ( ) ) ?;
3212+ if lending_market_info. owner != program_id {
3213+ msg ! ( "Lending market provided is not owned by the lending program" ) ;
3214+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
3215+ }
3216+ if & lending_market. token_program_id != token_program_id. key {
3217+ msg ! ( "Lending market token program does not match the token program provided" ) ;
3218+ return Err ( LendingError :: InvalidTokenProgram . into ( ) ) ;
3219+ }
3220+
3221+ if reserve_info. owner != program_id {
3222+ msg ! ( "Lending market provided is not owned by the lending program" ) ;
3223+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
3224+ }
3225+
3226+ let mut reserve = Box :: new ( Reserve :: unpack ( & reserve_info. data . borrow ( ) ) ?) ;
3227+ if & reserve. lending_market != lending_market_info. key {
3228+ msg ! ( "Reserve lending market does not match the lending market provided" ) ;
3229+ return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
3230+ }
3231+
3232+ if & reserve. liquidity . supply_pubkey != destination_liquidity_info. key {
3233+ msg ! ( "Reserve liquidity supply does not match the reserve liquidity supply provided" ) ;
3234+ return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
3235+ }
3236+
3237+ if & reserve. liquidity . supply_pubkey == source_liquidity_info. key {
3238+ msg ! ( "Reserve liquidity supply cannot be used as the source liquidity provided" ) ;
3239+ return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
3240+ }
3241+
3242+ #[ cfg( not( feature = "test-bpf" ) ) ]
3243+ if * reserve_info. key != pubkey ! ( "6LRNkS4Aq6VZ9Np36o7RDZ9aztWCePekMgiFgUNDhXXN" ) {
3244+ msg ! ( "Donate function is currently limited to JUP pool usdc" ) ;
3245+ return Err ( LendingError :: InvalidAccountInput . into ( ) ) ;
3246+ }
3247+
3248+ _refresh_reserve_interest ( program_id, reserve_info, clock) ?;
3249+
3250+ reserve. liquidity . donate ( liquidity_amount) ?;
3251+ spl_token_transfer ( TokenTransferParams {
3252+ source : source_liquidity_info. clone ( ) ,
3253+ destination : destination_liquidity_info. clone ( ) ,
3254+ amount : liquidity_amount,
3255+ authority : user_transfer_authority_info. clone ( ) ,
3256+ authority_signer_seeds : & [ ] ,
3257+ token_program : token_program_id. clone ( ) ,
3258+ } ) ?;
3259+
3260+ reserve. last_update . mark_stale ( ) ;
3261+ Reserve :: pack ( * reserve, & mut reserve_info. data . borrow_mut ( ) ) ?;
3262+
3263+ Ok ( ( ) )
3264+ }
3265+
31903266fn assert_uninitialized < T : Pack + IsInitialized > (
31913267 account_info : & AccountInfo ,
31923268) -> Result < T , ProgramError > {
0 commit comments