@@ -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,24 @@ 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
+ }
124
135
}
125
136
}
126
137
@@ -1994,6 +2005,78 @@ fn process_withdraw_obligation_collateral_and_redeem_reserve_liquidity(
1994
2005
)
1995
2006
}
1996
2007
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
+
2017
+ let account_info_iter = & mut accounts. iter ( ) . peekable ( ) ;
2018
+ let reserve_info = next_account_info ( account_info_iter) ?;
2019
+ let lending_market_info = next_account_info ( account_info_iter) ?;
2020
+ let lending_market_authority_info = next_account_info ( account_info_iter) ?;
2021
+ let lending_market_owner_info = next_account_info ( account_info_iter) ?;
2022
+ let clock = & Clock :: from_account_info ( next_account_info ( account_info_iter) ?) ?;
2023
+
2024
+ let mut reserve = assert_uninitialized :: < Reserve > ( reserve_info) ?;
2025
+ if reserve_info. owner != program_id {
2026
+ msg ! (
2027
+ "Reserve provided is not owned by the lending program {} != {}" ,
2028
+ & reserve_info. owner. to_string( ) ,
2029
+ & program_id. to_string( ) ,
2030
+ ) ;
2031
+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
2032
+ }
2033
+
2034
+
2035
+ let lending_market = LendingMarket :: unpack ( & lending_market_info. data . borrow ( ) ) ?;
2036
+ if lending_market_info. owner != program_id {
2037
+ msg ! (
2038
+ "Lending market provided is not owned by the lending program {} != {}" ,
2039
+ & lending_market_info. owner. to_string( ) ,
2040
+ & program_id. to_string( ) ,
2041
+ ) ;
2042
+ return Err ( LendingError :: InvalidAccountOwner . into ( ) ) ;
2043
+ }
2044
+ if & lending_market. owner != lending_market_owner_info. key {
2045
+ msg ! ( "Lending market owner does not match the lending market owner provided" ) ;
2046
+ return Err ( LendingError :: InvalidMarketOwner . into ( ) ) ;
2047
+ }
2048
+ if !lending_market_owner_info. is_signer {
2049
+ msg ! ( "Lending market owner provided must be a signer" ) ;
2050
+ return Err ( LendingError :: InvalidSigner . into ( ) ) ;
2051
+ }
2052
+
2053
+ let authority_signer_seeds = & [
2054
+ lending_market_info. key . as_ref ( ) ,
2055
+ & [ lending_market. bump_seed ] ,
2056
+ ] ;
2057
+ let lending_market_authority_pubkey =
2058
+ Pubkey :: create_program_address ( authority_signer_seeds, program_id) ?;
2059
+ if & lending_market_authority_pubkey != lending_market_authority_info. key {
2060
+ msg ! (
2061
+ "Derived lending market authority does not match the lending market authority provided"
2062
+ ) ;
2063
+ return Err ( LendingError :: InvalidMarketAuthority . into ( ) ) ;
2064
+ }
2065
+ match config_enum {
2066
+ // Make this an enum, make this decimal friendly
2067
+ ReserveConfigKey :: LoanToValueRatio => {
2068
+ reserve. config . loan_to_value_ratio = new_value;
2069
+ }
2070
+ _ => {
2071
+ msg ! ( "Did not recognize reserve config key" ) ;
2072
+ return Err ( LendingError :: InvalidConfig . into ( ) ) ;
2073
+ }
2074
+ } ;
2075
+ Reserve :: pack ( reserve, & mut reserve_info. data . borrow_mut ( ) ) ?;
2076
+ Ok ( ( ) )
2077
+ }
2078
+
2079
+
1997
2080
fn assert_rent_exempt ( rent : & Rent , account_info : & AccountInfo ) -> ProgramResult {
1998
2081
if !rent. is_exempt ( account_info. lamports ( ) , account_info. data_len ( ) ) {
1999
2082
msg ! (
0 commit comments