From f0dff030a7bc030b19e7de92d30954563f9b06d9 Mon Sep 17 00:00:00 2001 From: microwavedcola1 Date: Fri, 19 Aug 2022 11:58:10 +0200 Subject: [PATCH] functions for rates in bank in ui Signed-off-by: microwavedcola1 --- ts/client/src/accounts/bank.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ts/client/src/accounts/bank.ts b/ts/client/src/accounts/bank.ts index 76e197566..a002024b1 100644 --- a/ts/client/src/accounts/bank.ts +++ b/ts/client/src/accounts/bank.ts @@ -268,6 +268,10 @@ export class Bank { ).toNumber(); } + /** + * + * @returns borrow rate, 0 is 0% where 1 is 100% + */ getBorrowRate(): I80F48 { const totalBorrows = this.nativeBorrows(); const totalDeposits = this.nativeDeposits(); @@ -298,6 +302,18 @@ export class Bank { } } + /** + * + * @returns borrow rate percentage + */ + getBorrowRateUi(): number { + return this.getBorrowRate().toNumber() * 100; + } + + /** + * + * @returns deposit rate, 0 is 0% where 1 is 100% + */ getDepositRate(): I80F48 { const borrowRate = this.getBorrowRate(); const totalBorrows = this.nativeBorrows(); @@ -312,6 +328,14 @@ export class Bank { const utilization = totalBorrows.div(totalDeposits); return utilization.mul(borrowRate); } + + /** + * + * @returns deposit rate percentage + */ + getDepositRateUi(): number { + return this.getDepositRate().toNumber() * 100; + } } export class MintInfo {