From 3381a88b751aab23906e5a95df6a5e012d45ca69 Mon Sep 17 00:00:00 2001 From: teolhyn Date: Thu, 5 Sep 2024 10:42:30 +0300 Subject: [PATCH] chore: clean up some storage reads that used try_from_val() --- contracts/loan_manager/src/contract.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/contracts/loan_manager/src/contract.rs b/contracts/loan_manager/src/contract.rs index 0875f990..23ff0983 100644 --- a/contracts/loan_manager/src/contract.rs +++ b/contracts/loan_manager/src/contract.rs @@ -5,9 +5,7 @@ use crate::storage_types::{ Loan, LoansDataKey, DAY_IN_LEDGERS, POSITIONS_BUMP_AMOUNT, POSITIONS_LIFETIME_THRESHOLD, }; -use soroban_sdk::{ - contract, contractimpl, vec, Address, Env, IntoVal, String, Symbol, TryFromVal, Val, Vec, -}; +use soroban_sdk::{contract, contractimpl, vec, Address, Env, IntoVal, String, Symbol, Val, Vec}; mod loan_pool { soroban_sdk::contractimport!( @@ -124,20 +122,16 @@ impl LoansTrait for LoansContract { let current_ledger = e.ledger().sequence(); let key: LoansDataKey = LoansDataKey::LastUpdated; - let previous_ledger_val: Val = e + let previous_ledger: u32 = e .storage() .persistent() .get(&key) .unwrap_or(current_ledger.into_val(&e)); // If there is no previous ledger, use current. - let previous_ledger: u32 = - u32::try_from_val(&e, &previous_ledger_val).expect("Failed to convert Val to u32"); let ledgers_since_update: u32 = current_ledger - previous_ledger; // Currently unused but is a placeholder for interest calculations. Now time is handled. let ledger_ratio: i128 = (i128::from(ledgers_since_update) * DECIMAL) / (i128::from(DAY_IN_LEDGERS * 365)); - // Update current ledger as the new 'last time' - // Iterate over loans and add interest to capital borrowed. // In the same iteration add the amount to the liabilities of the lending pool. // First, lets retrieve the list of addresses with loans @@ -149,14 +143,7 @@ impl LoansTrait for LoansContract { for user in addresses.iter() { let key = (Symbol::new(&e, "Loan"), user.clone()); - let loan_val: Val = e - .storage() - .persistent() - .get::<(Symbol, Address), Val>(&key) - .unwrap(); - - let mut loan: Loan = - Loan::try_from_val(&e, &loan_val).expect("Failed to convert Val to Loan"); + let mut loan: Loan = e.storage().persistent().get(&key).unwrap(); let borrowed: i128 = loan.borrowed_amount;