From 06c780e721192cb8bf041e755e8370ed60cb0f75 Mon Sep 17 00:00:00 2001 From: Konsta Purtsi Date: Sun, 8 Dec 2024 17:10:39 +0200 Subject: [PATCH] feat: Combine PoolState into one endpoint --- contracts/loan_pool/src/contract.rs | 10 ++++++++ contracts/loan_pool/src/dto.rs | 9 ++++++++ contracts/loan_pool/src/lib.rs | 1 + src/components/AssetsModal/AssetsModal.tsx | 10 ++++---- src/components/AssetsModal/PositionsView.tsx | 2 +- src/components/WalletCard/LoansModal.tsx | 2 +- src/contexts/pool-context.tsx | 24 ++++++++++++-------- src/pages/_borrow/BorrowModal/BorrowStep.tsx | 4 ++-- src/pages/_borrow/BorrowableAsset.tsx | 4 +++- src/pages/_lend/LendableAsset.tsx | 4 ++-- 10 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 contracts/loan_pool/src/dto.rs diff --git a/contracts/loan_pool/src/contract.rs b/contracts/loan_pool/src/contract.rs index 283aa7b..5976617 100644 --- a/contracts/loan_pool/src/contract.rs +++ b/contracts/loan_pool/src/contract.rs @@ -1,3 +1,4 @@ +use crate::dto::PoolState; use crate::interest::{self, get_interest}; use crate::pool::Currency; use crate::positions; @@ -223,6 +224,15 @@ impl LoanPoolContract { interest::get_interest(e) } + pub fn get_pool_state(e: Env) -> PoolState { + PoolState { + total_balance: pool::read_total_balance(&e), + available_balance: pool::read_available_balance(&e), + total_shares: pool::read_total_shares(&e), + annual_interest_rate: interest::get_interest(e), + } + } + pub fn increase_liabilities(e: Env, user: Address, amount: i128) { let loan_manager_addr = pool::read_loan_manager_addr(&e); loan_manager_addr.require_auth(); diff --git a/contracts/loan_pool/src/dto.rs b/contracts/loan_pool/src/dto.rs new file mode 100644 index 0000000..b06118d --- /dev/null +++ b/contracts/loan_pool/src/dto.rs @@ -0,0 +1,9 @@ +use soroban_sdk::contracttype; + +#[contracttype] +pub struct PoolState { + pub total_balance: i128, + pub available_balance: i128, + pub total_shares: i128, + pub annual_interest_rate: i128, +} diff --git a/contracts/loan_pool/src/lib.rs b/contracts/loan_pool/src/lib.rs index fe7fb24..94df465 100644 --- a/contracts/loan_pool/src/lib.rs +++ b/contracts/loan_pool/src/lib.rs @@ -2,6 +2,7 @@ #![allow(clippy::unused_unit)] mod contract; +mod dto; mod interest; mod pool; mod positions; diff --git a/src/components/AssetsModal/AssetsModal.tsx b/src/components/AssetsModal/AssetsModal.tsx index 364dc6f..35b609f 100644 --- a/src/components/AssetsModal/AssetsModal.tsx +++ b/src/components/AssetsModal/AssetsModal.tsx @@ -53,12 +53,12 @@ const AssetsModal = ({ modalId, onClose }: AssetsModalProps) => { ) : ( )} -
- -
+
+ +
); }; diff --git a/src/components/AssetsModal/PositionsView.tsx b/src/components/AssetsModal/PositionsView.tsx index 131f06c..05d2fd7 100644 --- a/src/components/AssetsModal/PositionsView.tsx +++ b/src/components/AssetsModal/PositionsView.tsx @@ -80,7 +80,7 @@ const TableRow = ({ receivables, ticker, onWithdraw }: TableRowProps) => {

{formatAmount(receivables)}

{!isNil(price) && toDollarsFormatted(price, receivables)}

- {pool && formatAPY(pool.apr)} + {pool && formatAPY(pool.annualInterestRate)} diff --git a/src/components/WalletCard/LoansModal.tsx b/src/components/WalletCard/LoansModal.tsx index ec2b22f..db6dc23 100644 --- a/src/components/WalletCard/LoansModal.tsx +++ b/src/components/WalletCard/LoansModal.tsx @@ -104,7 +104,7 @@ const TableRow = ({ liabilities, ticker }: TableRowProps) => {

{formatAmount(liabilities)}

{!isNil(price) && toDollarsFormatted(price, liabilities)}

- {pool ? formatAPR(pool.apr) : null} + {pool ? formatAPR(pool.annualInterestRate) : null} {isRepaying ? (