@sonarwatch/portfolio-core 0.8.113 → 0.8.115
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 +10 -2
- package/package.json +1 -1
- package/src/Lock.d.ts +1 -1
- package/src/Lock.js +1 -1
- package/src/Lock.js.map +1 -1
- package/src/Portfolio.d.ts +2 -1
- package/src/utils/getElementLendingValues.d.ts +2 -2
- package/src/utils/getElementLendingValues.js +18 -12
- package/src/utils/getElementLendingValues.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,14 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
-
## [0.8.
|
|
5
|
+
## [0.8.115](https://github.com/sonarwatch/portfolio/compare/core-0.8.114...core-0.8.115) (2023-11-30)
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
## [0.8.
|
|
9
|
+
## [0.8.114](https://github.com/sonarwatch/portfolio/compare/core-0.8.113...core-0.8.114) (2023-11-30)
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
|
|
13
|
+
## [0.8.113](https://github.com/sonarwatch/portfolio/compare/core-0.8.112...core-0.8.113) (2023-11-29)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## [0.8.112](https://github.com/sonarwatch/portfolio/compare/core-0.8.111...core-0.8.112) (2023-11-29)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
13
21
|
## [0.8.111](https://github.com/sonarwatch/portfolio/compare/core-0.8.110...core-0.8.111) (2023-11-28)
|
|
14
22
|
|
|
15
23
|
|
package/package.json
CHANGED
package/src/Lock.d.ts
CHANGED
package/src/Lock.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createStandardLock = exports.createUnbondingLock = void 0;
|
|
4
4
|
const createUnbondingLock = (periodMs, startedTs) => ({
|
|
5
|
-
type: '
|
|
5
|
+
type: 'unbonding',
|
|
6
6
|
data: {
|
|
7
7
|
periodMs,
|
|
8
8
|
startedTs: startedTs || undefined,
|
package/src/Lock.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Lock.js","sourceRoot":"","sources":["../../../../packages/core/src/Lock.ts"],"names":[],"mappings":";;;AAkBO,MAAM,mBAAmB,GAAG,CACjC,QAAgB,EAChB,SAAkB,EACH,EAAE,CAAC,CAAC;IACnB,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"Lock.js","sourceRoot":"","sources":["../../../../packages/core/src/Lock.ts"],"names":[],"mappings":";;;AAkBO,MAAM,mBAAmB,GAAG,CACjC,QAAgB,EAChB,SAAkB,EACH,EAAE,CAAC,CAAC;IACnB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE;QACJ,QAAQ;QACR,SAAS,EAAE,SAAS,IAAI,SAAS;QACjC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,SAAS;KACpD;CACF,CAAC,CAAC;AAVU,QAAA,mBAAmB,uBAU7B;AAEI,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAgB,EAAE,CAAC,CAAC;IAClE,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE;QACJ,KAAK;KACN;CACF,CAAC,CAAC;AALU,QAAA,kBAAkB,sBAK5B"}
|
package/src/Portfolio.d.ts
CHANGED
|
@@ -70,6 +70,7 @@ export type PortfolioElementCommon = {
|
|
|
70
70
|
name?: string;
|
|
71
71
|
tags?: string[];
|
|
72
72
|
proxyInfo?: ProxyInfo;
|
|
73
|
+
lockedUntil?: number;
|
|
73
74
|
};
|
|
74
75
|
export type PortfolioElementSingleData = {
|
|
75
76
|
asset: PortfolioAsset;
|
|
@@ -110,7 +111,7 @@ export type PortfolioElementBorrowLendData = {
|
|
|
110
111
|
suppliedYields: Yield[][];
|
|
111
112
|
borrowedYields: Yield[][];
|
|
112
113
|
collateralRatio: number | null;
|
|
113
|
-
healthRatio
|
|
114
|
+
healthRatio: number | null;
|
|
114
115
|
};
|
|
115
116
|
export type PortfolioElementBorrowLend = PortfolioElementCommon & {
|
|
116
117
|
type: 'borrowlend';
|
|
@@ -1,10 +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
|
+
healthRatio: number | null;
|
|
9
9
|
value: number | null;
|
|
10
10
|
};
|
|
@@ -11,22 +11,28 @@ function getCollateralRatio(suppliedValue, borrowedValue) {
|
|
|
11
11
|
}
|
|
12
12
|
return collateralRatio;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
14
|
+
function getHealthRatio(suppliedAssets, borrowedAssets, suppliedLtvs, borrowedWeights) {
|
|
15
|
+
if (!suppliedLtvs)
|
|
16
|
+
return null;
|
|
17
|
+
if (suppliedLtvs && suppliedLtvs.length !== suppliedAssets.length)
|
|
18
|
+
throw new Error('suppliedLtvs length doesnt match suppliedAssets');
|
|
19
|
+
const fBorrowedWeights = borrowedWeights || new Array(borrowedAssets.length).fill(1);
|
|
20
|
+
if (fBorrowedWeights.length !== borrowedAssets.length)
|
|
21
|
+
throw new Error('borrowedWeights length doesnt match borrowedAssets');
|
|
22
|
+
const suppliesWeightedValue = suppliedAssets.reduce((acc, asset, index) => acc !== null && asset.value !== null
|
|
23
|
+
? acc + asset.value * suppliedLtvs[index]
|
|
24
|
+
: 0, 0);
|
|
25
|
+
const borrowsWeightedValue = borrowedAssets.reduce((acc, asset, index) => acc !== null && asset.value !== null
|
|
26
|
+
? acc + asset.value * fBorrowedWeights[index]
|
|
27
|
+
: 0, 0);
|
|
28
|
+
return (suppliesWeightedValue - borrowsWeightedValue) / suppliesWeightedValue;
|
|
29
|
+
}
|
|
30
|
+
function getElementLendingValues(suppliedAssets, borrowedAssets, rewardAssets, suppliedLtvs, borrowedWeights) {
|
|
15
31
|
const rewardsValue = rewardAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
|
|
16
32
|
const suppliedValue = suppliedAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
|
|
17
33
|
const borrowedValue = borrowedAssets.reduce((acc, asset) => acc !== null && asset.value !== null ? acc + asset.value : null, 0);
|
|
18
34
|
const collateralRatio = getCollateralRatio(suppliedValue, borrowedValue);
|
|
19
|
-
|
|
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
|
-
}
|
|
35
|
+
const healthRatio = getHealthRatio(suppliedAssets, borrowedAssets, suppliedLtvs, borrowedWeights);
|
|
30
36
|
// Total value
|
|
31
37
|
let value = suppliedValue !== null && borrowedValue !== null
|
|
32
38
|
? suppliedValue - borrowedValue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getElementLendingValues.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/getElementLendingValues.ts"],"names":[],"mappings":";;;AAGA,SAAS,kBAAkB,
|
|
1
|
+
{"version":3,"file":"getElementLendingValues.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/getElementLendingValues.ts"],"names":[],"mappings":";;;AAGA,SAAS,kBAAkB,CACzB,aAAuB,EACvB,aAAuB;IAEvB,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,SAAS,cAAc,CACrB,cAAgC,EAChC,cAAgC,EAChC,YAAuB,EACvB,eAA0B;IAE1B,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAC;IAC/B,IAAI,YAAY,IAAI,YAAY,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;QAC/D,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAErE,MAAM,gBAAgB,GACpB,eAAe,IAAI,IAAI,KAAK,CAAS,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACtE,IAAI,gBAAgB,CAAC,MAAM,KAAK,cAAc,CAAC,MAAM;QACnD,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;IAExE,MAAM,qBAAqB,GAAW,cAAc,CAAC,MAAM,CACzD,CAAC,GAAW,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAC5B,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,KAAK,KAAK,IAAI;QAClC,CAAC,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC;QACzC,CAAC,CAAC,CAAC,EACP,CAAC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