add helper method: settleTokenNativeToUi (#405)
* add helper method: settleTokenNativeToUi
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
* Revert "add helper method: settleTokenNativeToUi"
This reverts commit 43b19b3056
.
* we can assume that quote is always in usd
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
Signed-off-by: microwavedcola1 <microwavedcola@gmail.com>
This commit is contained in:
parent
800fe73a9c
commit
265f6a1a48
|
@ -985,10 +985,7 @@ export class MangoAccount {
|
||||||
'\n perps:' +
|
'\n perps:' +
|
||||||
JSON.stringify(
|
JSON.stringify(
|
||||||
this.perpActive().map((p) =>
|
this.perpActive().map((p) =>
|
||||||
p.toString(
|
p.toString(group?.getPerpMarketByMarketIndex(p.marketIndex)),
|
||||||
group,
|
|
||||||
group?.getPerpMarketByMarketIndex(p.marketIndex),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
4,
|
4,
|
||||||
|
@ -1288,15 +1285,12 @@ export class PerpPosition {
|
||||||
return ZERO_I80F48();
|
return ZERO_I80F48();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEquityUi(group: Group, perpMarket: PerpMarket): number {
|
public getEquityUi(perpMarket: PerpMarket): number {
|
||||||
if (perpMarket.perpMarketIndex !== this.marketIndex) {
|
if (perpMarket.perpMarketIndex !== this.marketIndex) {
|
||||||
throw new Error("PerpPosition doesn't belong to the given market!");
|
throw new Error("PerpPosition doesn't belong to the given market!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return toUiDecimals(
|
return toUiDecimalsForQuote(this.getEquity(perpMarket));
|
||||||
this.getEquity(perpMarket),
|
|
||||||
group.getMintDecimalsByTokenIndex(perpMarket.settleTokenIndex),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public getEquity(perpMarket: PerpMarket): I80F48 {
|
public getEquity(perpMarket: PerpMarket): I80F48 {
|
||||||
|
@ -1359,10 +1353,7 @@ export class PerpPosition {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public cumulativePnlOverPositionLifetimeUi(
|
public cumulativePnlOverPositionLifetimeUi(perpMarket: PerpMarket): number {
|
||||||
group: Group,
|
|
||||||
perpMarket: PerpMarket,
|
|
||||||
): number {
|
|
||||||
if (perpMarket.perpMarketIndex !== this.marketIndex) {
|
if (perpMarket.perpMarketIndex !== this.marketIndex) {
|
||||||
throw new Error("PerpPosition doesn't belong to the given market!");
|
throw new Error("PerpPosition doesn't belong to the given market!");
|
||||||
}
|
}
|
||||||
|
@ -1371,11 +1362,10 @@ export class PerpPosition {
|
||||||
this.getAverageEntryPrice(perpMarket),
|
this.getAverageEntryPrice(perpMarket),
|
||||||
);
|
);
|
||||||
|
|
||||||
return toUiDecimals(
|
return toUiDecimalsForQuote(
|
||||||
this.realizedPnlForPositionNative.add(
|
this.realizedPnlForPositionNative.add(
|
||||||
this.getBasePositionNative(perpMarket).mul(priceChange),
|
this.getBasePositionNative(perpMarket).mul(priceChange),
|
||||||
),
|
),
|
||||||
group.getMintDecimalsByTokenIndex(perpMarket.settleTokenIndex),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,11 +1379,8 @@ export class PerpPosition {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public getUnsettledPnlUi(group: Group, perpMarket: PerpMarket): number {
|
public getUnsettledPnlUi(perpMarket: PerpMarket): number {
|
||||||
return toUiDecimals(
|
return toUiDecimalsForQuote(this.getUnsettledPnl(perpMarket));
|
||||||
this.getUnsettledPnl(perpMarket),
|
|
||||||
group.getMintDecimalsByTokenIndex(perpMarket.settleTokenIndex),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateSettleLimit(perpMarket: PerpMarket): void {
|
public updateSettleLimit(perpMarket: PerpMarket): void {
|
||||||
|
@ -1482,17 +1469,14 @@ export class PerpPosition {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
toString(group?: Group, perpMarket?: PerpMarket): string {
|
toString(perpMarket?: PerpMarket): string {
|
||||||
return perpMarket && group
|
return perpMarket
|
||||||
? 'market - ' +
|
? 'market - ' +
|
||||||
perpMarket.name +
|
perpMarket.name +
|
||||||
', basePositionLots - ' +
|
', basePositionLots - ' +
|
||||||
perpMarket.baseLotsToUi(this.basePositionLots) +
|
perpMarket.baseLotsToUi(this.basePositionLots) +
|
||||||
', quotePositiveNative - ' +
|
', quotePositive - ' +
|
||||||
toUiDecimals(
|
toUiDecimalsForQuote(this.quotePositionNative.toNumber()) +
|
||||||
this.quotePositionNative.toNumber(),
|
|
||||||
group.getMintDecimalsByTokenIndex(perpMarket.settleTokenIndex),
|
|
||||||
) +
|
|
||||||
', bidsBaseLots - ' +
|
', bidsBaseLots - ' +
|
||||||
perpMarket.baseLotsToUi(this.bidsBaseLots) +
|
perpMarket.baseLotsToUi(this.bidsBaseLots) +
|
||||||
', asksBaseLots - ' +
|
', asksBaseLots - ' +
|
||||||
|
@ -1502,7 +1486,7 @@ export class PerpPosition {
|
||||||
', takerQuoteLots - ' +
|
', takerQuoteLots - ' +
|
||||||
perpMarket.quoteLotsToUi(this.takerQuoteLots) +
|
perpMarket.quoteLotsToUi(this.takerQuoteLots) +
|
||||||
', unsettled pnl - ' +
|
', unsettled pnl - ' +
|
||||||
this.getUnsettledPnlUi(group!, perpMarket!).toString()
|
this.getUnsettledPnlUi(perpMarket!).toString()
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue