-
Notifications
You must be signed in to change notification settings - Fork 4
/
indexerBalanceValue.ts
60 lines (55 loc) · 1.64 KB
/
indexerBalanceValue.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { BigDecimal } from '@vertex-protocol/utils';
import { IndexerPerpBalance, IndexerSpotBalance } from '../types';
import { calcLpTokenValue, Market } from '@vertex-protocol/contracts';
/**
* Most of these calculations take oraclePrice as a separate parameter. This allows us to not rely on the Snapshot
* interfaces to give clients the optionality to pass either the pre or post balance
*/
/**
* Calculates the quote value of an indexer spot balance
*
* @param balance
* @param oraclePrice
*/
export function calcIndexerSpotBalanceValue(
balance: IndexerSpotBalance,
oraclePrice: BigDecimal,
): BigDecimal {
return balance.amount.multipliedBy(oraclePrice);
}
/**
* Calculates the notional value of an indexer perp balance
*
* @param balance
* @param oraclePrice
*/
export function calcIndexerPerpBalanceNotionalValue(
balance: IndexerPerpBalance,
oraclePrice: BigDecimal,
): BigDecimal {
return balance.amount.multipliedBy(oraclePrice).abs();
}
/**
* Calculates the true quote value of a indexer perp balance, which is the same as its unrealized pnl / unsettled quote
*
* @param balance
* @param oraclePrice
*/
export function calcIndexerPerpBalanceValue(
balance: IndexerPerpBalance,
oraclePrice: BigDecimal,
): BigDecimal {
return balance.amount.multipliedBy(oraclePrice).plus(balance.vQuoteBalance);
}
/**
* Calculates the implied value of an LP indexer balance, in terms of quote units
*
* @param balance
* @param market
*/
export function calcIndexerLpBalanceValue(
balance: IndexerSpotBalance | IndexerPerpBalance,
market: Market,
): BigDecimal {
return calcLpTokenValue(market.product).times(balance.lpAmount);
}