@sonarwatch/portfolio-core 0.8.81 → 0.8.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,18 +2,26 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
- ## [0.8.81](https://github.com/sonarwatch/portfolio/compare/core-0.8.80...core-0.8.81) (2023-11-17)
6
-
7
-
8
-
9
- ## [0.8.80](https://github.com/sonarwatch/portfolio/compare/core-0.8.79...core-0.8.80) (2023-11-15)
10
-
11
-
12
-
13
- ## [0.8.79](https://github.com/sonarwatch/portfolio/compare/core-0.8.78...core-0.8.79) (2023-11-15)
5
+ ## [0.8.83](https://github.com/sonarwatch/portfolio/compare/core-0.8.82...core-0.8.83) (2023-11-19)
14
6
 
15
7
 
16
8
 
9
+ ## [0.8.82](https://github.com/sonarwatch/portfolio/compare/core-0.8.81...core-0.8.82) (2023-11-17)
10
+
11
+
12
+
13
+ ## [0.8.81](https://github.com/sonarwatch/portfolio/compare/core-0.8.80...core-0.8.81) (2023-11-17)
14
+
15
+
16
+
17
+ ## [0.8.80](https://github.com/sonarwatch/portfolio/compare/core-0.8.79...core-0.8.80) (2023-11-15)
18
+
19
+
20
+
21
+ ## [0.8.79](https://github.com/sonarwatch/portfolio/compare/core-0.8.78...core-0.8.79) (2023-11-15)
22
+
23
+
24
+
17
25
  ## [0.8.78](https://github.com/sonarwatch/portfolio/compare/core-0.8.77...core-0.8.78) (2023-11-14)
18
26
 
19
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonarwatch/portfolio-core",
3
- "version": "0.8.81",
3
+ "version": "0.8.83",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
6
  "@ethersproject/address": "^5.7.0",
@@ -110,6 +110,7 @@ export type PortfolioElementBorrowLendData = {
110
110
  suppliedYields: Yield[][];
111
111
  borrowedYields: Yield[][];
112
112
  collateralRatio: number | null;
113
+ healthRatio?: number | null;
113
114
  };
114
115
  export type PortfolioElementBorrowLend = PortfolioElementCommon & {
115
116
  type: 'borrowlend';
@@ -1,9 +1,10 @@
1
1
  import { PortfolioAsset } from '../Portfolio';
2
2
  import { UsdValue } from '../UsdValue';
3
- export declare function getElementLendingValues(suppliedAssets: PortfolioAsset[], borrowedAssets: PortfolioAsset[], rewardAssets: PortfolioAsset[]): {
3
+ export declare function getElementLendingValues(suppliedAssets: PortfolioAsset[], borrowedAssets: PortfolioAsset[], rewardAssets: PortfolioAsset[], suppliedLTVs?: number[], borrowedWeights?: number[]): {
4
4
  borrowedValue: UsdValue;
5
5
  suppliedValue: UsdValue;
6
6
  rewardsValue: UsdValue;
7
7
  collateralRatio: number | null;
8
+ healthRatio: number;
8
9
  value: number | null;
9
10
  };
@@ -11,11 +11,22 @@ function getCollateralRatio(suppliedValue, borrowedValue) {
11
11
  }
12
12
  return collateralRatio;
13
13
  }
14
- function getElementLendingValues(suppliedAssets, borrowedAssets, rewardAssets) {
14
+ function getElementLendingValues(suppliedAssets, borrowedAssets, rewardAssets, suppliedLTVs, borrowedWeights) {
15
15
  const rewardsValue = rewardAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
16
16
  const suppliedValue = suppliedAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
17
17
  const borrowedValue = borrowedAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
18
18
  const collateralRatio = getCollateralRatio(suppliedValue, borrowedValue);
19
+ let healthRatio = -1;
20
+ if (borrowedWeights && suppliedLTVs) {
21
+ const suppliesWeightedValue = suppliedAssets.reduce((acc, asset, index) => acc !== null && asset.value !== null
22
+ ? acc + asset.value * suppliedLTVs[index]
23
+ : 0, 0);
24
+ const borrowsWeightedValue = borrowedAssets.reduce((acc, asset, index) => acc !== null && asset.value !== null
25
+ ? acc + asset.value * borrowedWeights[index]
26
+ : 0, 0);
27
+ healthRatio =
28
+ (suppliesWeightedValue - borrowsWeightedValue) / suppliesWeightedValue;
29
+ }
19
30
  // Total value
20
31
  let value = suppliedValue !== null && borrowedValue !== null
21
32
  ? suppliedValue - borrowedValue
@@ -27,6 +38,7 @@ function getElementLendingValues(suppliedAssets, borrowedAssets, rewardAssets) {
27
38
  suppliedValue,
28
39
  rewardsValue,
29
40
  collateralRatio,
41
+ healthRatio,
30
42
  value,
31
43
  };
32
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"getElementLendingValues.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/getElementLendingValues.ts"],"names":[],"mappings":";;;AAGA,SAAS,kBAAkB,CAAC,aAAuB,EAAE,aAAuB;IAC1E,IAAI,eAAe,GAAkB,IAAI,CAAC;IAC1C,IAAI,aAAa,KAAK,CAAC,EAAE;QACvB,eAAe,GAAG,CAAC,CAAC,CAAC;KACtB;SAAM,IAAI,aAAa,IAAI,aAAa,EAAE;QACzC,eAAe,GAAG,aAAa,GAAG,aAAa,CAAC;KACjD;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAgB,uBAAuB,CACrC,cAAgC,EAChC,cAAgC,EAChC,YAA8B;IAE9B,MAAM,YAAY,GAAa,YAAY,CAAC,MAAM,CAChD,CAAC,GAAa,EAAE,KAAK,EAAE,EAAE,CACvB,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EACjE,CAAC,CACF,CAAC;IACF,MAAM,aAAa,GAAa,cAAc,CAAC,MAAM,CACnD,CAAC,GAAa,EAAE,KAAK,EAAE,EAAE,CACvB,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EACjE,CAAC,CACF,CAAC;IACF,MAAM,aAAa,GAAa,cAAc,CAAC,MAAM,CACnD,CAAC,GAAa,EAAE,KAAK,EAAE,EAAE,CACvB,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EACjE,CAAC,CACF,CAAC;IACF,MAAM,eAAe,GAAkB,kBAAkB,CACvD,aAAa,EACb,aAAa,CACd,CAAC;IAEF,cAAc;IACd,IAAI,KAAK,GACP,aAAa,KAAK,IAAI,IAAI,aAAa,KAAK,IAAI;QAC9C,CAAC,CAAC,aAAa,GAAG,aAAa;QAC/B,CAAC,CAAC,IAAI,CAAC;IACX,IAAI,YAAY,KAAK,IAAI,IAAI,KAAK,KAAK,IAAI;QAAE,KAAK,IAAI,YAAY,CAAC;IAEnE,OAAO;QACL,aAAa;QACb,aAAa;QACb,YAAY;QACZ,eAAe;QACf,KAAK;KACN,CAAC;AACJ,CAAC;AAvCD,0DAuCC"}
1
+ {"version":3,"file":"getElementLendingValues.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/getElementLendingValues.ts"],"names":[],"mappings":";;;AAGA,SAAS,kBAAkB,CAAC,aAAuB,EAAE,aAAuB;IAC1E,IAAI,eAAe,GAAkB,IAAI,CAAC;IAC1C,IAAI,aAAa,KAAK,CAAC,EAAE;QACvB,eAAe,GAAG,CAAC,CAAC,CAAC;KACtB;SAAM,IAAI,aAAa,IAAI,aAAa,EAAE;QACzC,eAAe,GAAG,aAAa,GAAG,aAAa,CAAC;KACjD;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAgB,uBAAuB,CACrC,cAAgC,EAChC,cAAgC,EAChC,YAA8B,EAC9B,YAAuB,EACvB,eAA0B;IAE1B,MAAM,YAAY,GAAa,YAAY,CAAC,MAAM,CAChD,CAAC,GAAa,EAAE,KAAK,EAAE,EAAE,CACvB,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,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