@@ -9,7 +9,7 @@ use crate::{
9
9
CalculateBorrowResult , CalculateLiquidationResult , CalculateRepayResult ,
10
10
InitLendingMarketParams , InitObligationParams , InitReserveParams , LendingMarket ,
11
11
NewReserveCollateralParams , NewReserveLiquidityParams , Obligation , Reserve ,
12
- ReserveCollateral , ReserveConfig , ReserveLiquidity ,
12
+ ReserveCollateral , ReserveConfig , ReserveConfigKey , ReserveLiquidity ,
13
13
} ,
14
14
} ;
15
15
use num_traits:: FromPrimitive ;
@@ -114,13 +114,25 @@ pub fn process_instruction(
114
114
LendingInstruction :: WithdrawObligationCollateralAndRedeemReserveCollateral {
115
115
collateral_amount,
116
116
} => {
117
- msg ! ( "Instruction: Withdraw Obligation Collateral and Redeem Reserve Collateral " ) ;
117
+ msg ! ( "Instruction: Withdraw Obligation Collateral and Redeem Reserve Collateral" ) ;
118
118
process_withdraw_obligation_collateral_and_redeem_reserve_liquidity (
119
119
program_id,
120
120
collateral_amount,
121
121
accounts,
122
122
)
123
123
}
124
+ LendingInstruction :: UpdateReserveConfig {
125
+ config_enum,
126
+ new_value,
127
+ } => {
128
+ msg ! ( "Instruction: UpdateReserveConfig" ) ;
129
+ process_update_reserve_config (
130
+ program_id,
131
+ ReserveConfigKey :: from_u8 ( config_enum) ?,
132
+ new_value,
133
+ accounts,
134
+ )
135
+ }
124
136
}
125
137
}
126
138
@@ -1994,6 +2006,68 @@ fn process_withdraw_obligation_collateral_and_redeem_reserve_liquidity(
1994
2006
)
1995
2007
}
1996
2008
2009
+ #[ inline( never) ] // avoid stack frame limit
2010
+ fn process_update_reserve_config (
2011
+ program_id : & Pubkey ,
2012
+ config_enum : ReserveConfigKey ,
2013
+ new_value : u8 ,
2014
+ accounts : & [ AccountInfo ] ,
2015
+ ) -> ProgramResult {
2016
+ let account_info_iter = & mut accounts. iter ( ) . peekable ( ) ;
2017
+ let reserve_info = next_account_info ( account_info_iter) ?;
2018
+ let lending_market_info = next_account_info ( account_info_iter) ?;
2019
+ let lending_market_authority_info = next_account_info ( account_info_iter) ?;
2020
+ let lending_market_owner_info = next_account_info ( account_info_iter) ?;
2021
+
2022
+ let mut reserve = assert_uninitialized :: < Reserve > ( reserve_info) ?;
2023
+ if reserve_info. owner != program_id {
2024
+ msg ! (
2025
+ "Reserve provided is not owned by the lending program {} != {}" ,
2026
+ & reserve_info. owner. to_string( ) ,
2027
+ & program_id. to_string( ) ,
2028
+ ) ;
2029
+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
2030
+ }
2031
+
2032
+ let lending_market = LendingMarket :: unpack ( & lending_market_info. data . borrow ( ) ) ?;
2033
+ if lending_market_info. owner != program_id {
2034
+ msg ! (
2035
+ "Lending market provided is not owned by the lending program {} != {}" ,
2036
+ & lending_market_info. owner. to_string( ) ,
2037
+ & program_id. to_string( ) ,
2038
+ ) ;
2039
+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
2040
+ }
2041
+ if & lending_market. owner != lending_market_owner_info. key {
2042
+ msg ! ( "Lending market owner does not match the lending market owner provided" ) ;
2043
+ return Err ( LendingError :: InvalidMarketOwner . into ( ) ) ;
2044
+ }
2045
+ if !lending_market_owner_info. is_signer {
2046
+ msg ! ( "Lending market owner provided must be a signer" ) ;
2047
+ return Err ( LendingError :: InvalidSigner . into ( ) ) ;
2048
+ }
2049
+
2050
+ let authority_signer_seeds = & [
2051
+ lending_market_info. key . as_ref ( ) ,
2052
+ & [ lending_market. bump_seed ] ,
2053
+ ] ;
2054
+ let lending_market_authority_pubkey =
2055
+ Pubkey :: create_program_address ( authority_signer_seeds, program_id) ?;
2056
+ if & lending_market_authority_pubkey != lending_market_authority_info. key {
2057
+ msg ! (
2058
+ "Derived lending market authority does not match the lending market authority provided"
2059
+ ) ;
2060
+ return Err ( LendingError :: InvalidMarketAuthority . into ( ) ) ;
2061
+ }
2062
+ match config_enum {
2063
+ ReserveConfigKey :: LoanToValueRatio => {
2064
+ reserve. config . loan_to_value_ratio = new_value;
2065
+ }
2066
+ } ;
2067
+ Reserve :: pack ( reserve, & mut reserve_info. data . borrow_mut ( ) ) ?;
2068
+ Ok ( ( ) )
2069
+ }
2070
+
1997
2071
fn assert_rent_exempt ( rent : & Rent , account_info : & AccountInfo ) -> ProgramResult {
1998
2072
if !rent. is_exempt ( account_info. lamports ( ) , account_info. data_len ( ) ) {
1999
2073
msg ! (
0 commit comments