add back getEquityUi for perp

This commit is contained in:
tjs 2022-12-08 14:12:57 -05:00
parent 4fc2b42f99
commit fb8eb59355
2 changed files with 14 additions and 3 deletions

View File

@ -388,9 +388,13 @@ export class Group {
}
public getMintDecimals(mintPk: PublicKey): number {
const banks = this.banksMapByMint.get(mintPk.toString());
if (!banks) throw new Error(`No bank found for mint ${mintPk}!`);
return banks[0].mintDecimals;
const bank = this.getFirstBankByMint(mintPk);
return bank.mintDecimals;
}
public getMintDecimalsByTokenIndex(tokenIndex: TokenIndex): number {
const bank = this.getFirstBankByTokenIndex(tokenIndex);
return bank.mintDecimals;
}
public getInsuranceMintDecimals(): number {

View File

@ -1219,6 +1219,13 @@ export class PerpPosition {
return ZERO_I80F48();
}
public getEquityUi(group: Group, perpMarket: PerpMarket): number {
return toUiDecimals(
this.getEquity(perpMarket),
group.getMintDecimalsByTokenIndex(perpMarket.settleTokenIndex),
);
}
public getEquity(perpMarket: PerpMarket): I80F48 {
const lotsToQuote = I80F48.fromI64(perpMarket.baseLotSize).mul(
perpMarket.price,