@pear-protocol/utils
Advanced tools
@@ -7,5 +7,1 @@ import type { InstrumentId, Side } from '@pear-protocol/types'; | ||
| }; | ||
| export type BasketIndexLeg = { | ||
| symbol: InstrumentId; | ||
| weight: number; | ||
| }; |
| import type { InstrumentId } from '@pear-protocol/types'; | ||
| import BigNumber from 'bignumber.js'; | ||
| import type { BasketIndexLeg, BasketLeg } from './basket.types'; | ||
| import type { BasketLeg } from './basket.types'; | ||
| type PriceMap = Record<InstrumentId, string>; | ||
@@ -15,3 +15,2 @@ /** | ||
| export declare function computeBasketWeightedRatioV1(basket: BasketLeg[], priceMap: PriceMap): BigNumber | null; | ||
| export declare function computeBasketIndexV1(basket: BasketIndexLeg[], priceMap: PriceMap): BigNumber | null; | ||
| export {}; |
+1
-12
@@ -137,13 +137,2 @@ import BigNumber7, { BigNumber } from 'bignumber.js'; | ||
| } | ||
| function computeBasketIndexV1(basket, priceMap) { | ||
| let logSum = 0; | ||
| for (const leg of basket) { | ||
| const price = priceMap[leg.symbol]; | ||
| if (!price) return null; | ||
| const priceNum = Number(price); | ||
| if (priceNum <= 0) return null; | ||
| logSum += leg.weight * Math.log(priceNum); | ||
| } | ||
| return exponentiate(logSum); | ||
| } | ||
| function contractsToBase(contracts, contractSize) { | ||
@@ -618,2 +607,2 @@ return new BigNumber7(contracts).times(contractSize); | ||
| export { baseToContracts, computeAssetEntryNotional, computeAssetGrossRealizedPnL, computeAssetRealizedPnLs, computeAssetUnrealizedPnL, computeAssetUnrealizedPnLs, computeBasketIndexV1, computeBasketWeightedRatioV1, computeEntryPriceForAsset, computeRealizedPositionState, computeSyncPayload, computeUnrealizedPositionState, contractsToBase, countDecimals, exponentiate, precisePrice, preciseQuantity, validateLeverage, validateQuantity }; | ||
| export { baseToContracts, computeAssetEntryNotional, computeAssetGrossRealizedPnL, computeAssetRealizedPnLs, computeAssetUnrealizedPnL, computeAssetUnrealizedPnLs, computeBasketWeightedRatioV1, computeEntryPriceForAsset, computeRealizedPositionState, computeSyncPayload, computeUnrealizedPositionState, contractsToBase, countDecimals, exponentiate, precisePrice, preciseQuantity, validateLeverage, validateQuantity }; |
+2
-2
| { | ||
| "name": "@pear-protocol/utils", | ||
| "version": "0.0.18", | ||
| "version": "0.0.19", | ||
| "description": "Pear Protocol Utility functions", | ||
@@ -29,3 +29,3 @@ "private": false, | ||
| "dependencies": { | ||
| "@pear-protocol/types": "^0.0.18", | ||
| "@pear-protocol/types": "^0.0.19", | ||
| "bignumber.js": "9.3.1" | ||
@@ -32,0 +32,0 @@ }, |
35927
-1.51%869
-1.81%+ Added
- Removed
Updated