add deposits and borrows fn to mangoAccount

This commit is contained in:
tjs 2022-06-29 15:55:39 -04:00
parent 1c02ccd21d
commit 273b8dd597
2 changed files with 25 additions and 1 deletions

View File

@ -89,6 +89,16 @@ export class MangoAccount {
return ta ? ta.ui(bank) : 0;
}
deposits(bank: Bank): number {
const ta = this.findToken(bank.tokenIndex);
return ta ? ta.uiDeposits(bank) : 0;
}
borrows(bank: Bank): number {
const ta = this.findToken(bank.tokenIndex);
return ta ? ta.uiBorrows(bank) : 0;
}
tokens_active(): TokenPosition[] {
return this.tokens.filter((token) => token.isActive());
}
@ -155,6 +165,20 @@ export class TokenPosition {
return nativeI80F48ToUi(this.native(bank), bank.mintDecimals).toNumber();
}
public uiDeposits(bank: Bank): number {
return nativeI80F48ToUi(
bank.depositIndex.mul(this.indexedPosition),
bank.mintDecimals,
).toNumber();
}
public uiBorrows(bank: Bank): number {
return nativeI80F48ToUi(
bank.borrowIndex.mul(this.indexedPosition),
bank.mintDecimals,
).toNumber();
}
public toString(group?: Group): String {
let extra: string = '';
if (group) {

View File

@ -553,7 +553,7 @@ export class MangoClient {
({ pubkey: pk, isWritable: false, isSigner: false } as AccountMeta),
),
)
.rpc();
.rpc({ skipPreflight: true });
}
// Serum