@sonarwatch/portfolio-core 0.16.3 → 0.16.5

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,6 +2,26 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.16.5](https://github.com/sonarwatch/portfolio/compare/core-0.16.4...core-0.16.5) (2025-07-07)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * **core:** handle empty yield items and correct revenue calculations in calcYieldSummary ([39ba5f3](https://github.com/sonarwatch/portfolio/commit/39ba5f3b6bb334b970e7b8e146cf80d24d45293c))
11
+
12
+
13
+ ### Features
14
+
15
+ * **core:** add calcYieldSummary utility and FetcherResult types to enhance yield data calculations and integration ([9c26a0f](https://github.com/sonarwatch/portfolio/commit/9c26a0f618826a8dbec19ff7cf7685182aff27e5))
16
+ * **core:** add optional error field to FetcherResult ([76e3b84](https://github.com/sonarwatch/portfolio/commit/76e3b84bfb8ab07a42d3c238e256611885bd2b52))
17
+ * **plugins:** add netApy support across element builders and simplify yield calculations ([f0c97b7](https://github.com/sonarwatch/portfolio/commit/f0c97b74727e320370fcc6a298ff14eb7b74c256))
18
+
19
+
20
+
21
+ ## [0.16.4](https://github.com/sonarwatch/portfolio/compare/core-0.16.3...core-0.16.4) (2025-07-04)
22
+
23
+
24
+
5
25
  ## [0.16.3](https://github.com/sonarwatch/portfolio/compare/core-0.16.2...core-0.16.3) (2025-07-04)
6
26
 
7
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonarwatch/portfolio-core",
3
- "version": "0.16.3",
3
+ "version": "0.16.5",
4
4
  "type": "commonjs",
5
5
  "types": "./src/index.d.ts",
6
6
  "dependencies": {
@@ -0,0 +1,38 @@
1
+ import { NetworkIdType } from './Network';
2
+ import { AddressSystemType } from './Address';
3
+ import { UsdValue } from './UsdValue';
4
+ import { TokenInfo } from './TokenList';
5
+ import { PortfolioElement } from './Portfolio';
6
+ /**
7
+ * Represents the result of a fetcher.
8
+ */
9
+ export type FetcherResult = {
10
+ owner: string;
11
+ fetcherId: string;
12
+ networdkId: NetworkIdType;
13
+ duration: number;
14
+ elements: PortfolioElement[];
15
+ error?: string;
16
+ };
17
+ /**
18
+ * Represents the report of a fetcher.
19
+ */
20
+ export type FetcherReport = {
21
+ id: string;
22
+ status: 'succeeded' | 'failed';
23
+ duration?: number;
24
+ error?: string;
25
+ };
26
+ /**
27
+ * Represents the result of multiple fetchers.
28
+ */
29
+ export type FetchersResult = {
30
+ date: number;
31
+ owner: string;
32
+ addressSystem: AddressSystemType;
33
+ fetcherReports: FetcherReport[];
34
+ value: UsdValue;
35
+ elements: PortfolioElement[];
36
+ duration: number;
37
+ tokenInfo?: Partial<Record<NetworkIdType, Record<string, TokenInfo>>>;
38
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=FetcherResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FetcherResult.js","sourceRoot":"","sources":["../../../../packages/core/src/FetcherResult.ts"],"names":[],"mappings":""}
@@ -1,8 +1,6 @@
1
1
  import { UsdValue } from './UsdValue';
2
2
  import { NetworkIdType } from './Network';
3
3
  import { Yield } from './Yield';
4
- import { AddressSystemType } from './Address';
5
- import { TokenInfo } from './TokenList';
6
4
  /**
7
5
  * Represents the type of portfolio asset.
8
6
  */
@@ -154,6 +152,13 @@ export type PortfolioElementCommon = {
154
152
  name?: string;
155
153
  tags?: string[];
156
154
  proxyInfo?: ProxyInfo;
155
+ /**
156
+ * Net APY (Annual Percentage Yield) as fraction.
157
+ * Includes internal token yields
158
+ * 0.28 means 28% APY
159
+ * -0.28 means -28% APR
160
+ */
161
+ netApy?: number;
157
162
  };
158
163
  /**
159
164
  * Represents the data of a multiple portfolio element.
@@ -391,36 +396,3 @@ export type PortfolioElementBorrowLend = PortfolioElementCommon & {
391
396
  * Represents a portfolio element.
392
397
  */
393
398
  export type PortfolioElement = PortfolioElementMultiple | PortfolioElementLiquidity | PortfolioElementLeverage | PortfolioElementBorrowLend | PortfolioElementTrade;
394
- /**
395
- * Represents the result of a fetcher.
396
- */
397
- export type FetcherResult = {
398
- owner: string;
399
- fetcherId: string;
400
- networdkId: NetworkIdType;
401
- duration: number;
402
- elements: PortfolioElement[];
403
- error?: string;
404
- };
405
- /**
406
- * Represents the report of a fetcher.
407
- */
408
- export type FetcherReport = {
409
- id: string;
410
- status: 'succeeded' | 'failed';
411
- duration?: number;
412
- error?: string;
413
- };
414
- /**
415
- * Represents the result of multiple fetchers.
416
- */
417
- export type FetchersResult = {
418
- date: number;
419
- owner: string;
420
- addressSystem: AddressSystemType;
421
- fetcherReports: FetcherReport[];
422
- value: UsdValue;
423
- elements: PortfolioElement[];
424
- duration: number;
425
- tokenInfo?: Partial<Record<NetworkIdType, Record<string, TokenInfo>>>;
426
- };
@@ -1 +1 @@
1
- {"version":3,"file":"Portfolio.js","sourceRoot":"","sources":["../../../../packages/core/src/Portfolio.ts"],"names":[],"mappings":";;;AAMA;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAClB,CAAC;AA6CX;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACN,CAAC;AA2OX,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,+BAAe,CAAA;AACjB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
1
+ {"version":3,"file":"Portfolio.js","sourceRoot":"","sources":["../../../../packages/core/src/Portfolio.ts"],"names":[],"mappings":";;;AAIA;;GAEG;AACU,QAAA,kBAAkB,GAAG;IAChC,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,OAAO;IACd,WAAW,EAAE,aAAa;CAClB,CAAC;AA6CX;;GAEG;AACU,QAAA,oBAAoB,GAAG;IAClC,QAAQ,EAAE,UAAU;IACpB,SAAS,EAAE,WAAW;IACtB,UAAU,EAAE,YAAY;IACxB,QAAQ,EAAE,UAAU;IACpB,KAAK,EAAE,OAAO;CACN,CAAC;AAkPX,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,6BAAa,CAAA;IACb,+BAAe,CAAA;AACjB,CAAC,EAHW,YAAY,4BAAZ,YAAY,QAGvB"}
package/src/Yield.d.ts CHANGED
@@ -42,3 +42,7 @@ export declare const yieldFromApr: (apr: number) => Yield;
42
42
  * @returns The Yield object with the calculated APR.
43
43
  */
44
44
  export declare const yieldFromApy: (apy: number) => Yield;
45
+ export type YieldElement = {
46
+ apy: number;
47
+ value: number;
48
+ };
package/src/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export * from './TokenYield';
15
15
  export * from './Yield';
16
16
  export * from './BorrowLendRate';
17
17
  export * from './Transaction';
18
+ export * from './FetcherResult';
package/src/index.js CHANGED
@@ -31,4 +31,5 @@ __exportStar(require("./TokenYield"), exports);
31
31
  __exportStar(require("./Yield"), exports);
32
32
  __exportStar(require("./BorrowLendRate"), exports);
33
33
  __exportStar(require("./Transaction"), exports);
34
+ __exportStar(require("./FetcherResult"), exports);
34
35
  //# sourceMappingURL=index.js.map
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,+CAA6B;AAC7B,0CAAwB;AACxB,mDAAiC;AACjC,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA4B;AAC5B,2CAAyB;AACzB,iDAA+B;AAC/B,0CAAwB;AACxB,0CAAwB;AACxB,4CAA0B;AAC1B,4CAA0B;AAC1B,6CAA2B;AAC3B,2CAAyB;AACzB,4CAA0B;AAC1B,8CAA4B;AAC5B,8CAA4B;AAC5B,+CAA6B;AAC7B,+CAA6B;AAC7B,0CAAwB;AACxB,mDAAiC;AACjC,gDAA8B;AAC9B,kDAAgC"}
@@ -48,3 +48,4 @@ export * from './getIsVerifiedFromAsset';
48
48
  export * from './TokenPriceMap';
49
49
  export * from './applyPricesToElements';
50
50
  export * from './fixUsdValue';
51
+ export * from './reduceYieldElements';
@@ -64,4 +64,5 @@ __exportStar(require("./getIsVerifiedFromAsset"), exports);
64
64
  __exportStar(require("./TokenPriceMap"), exports);
65
65
  __exportStar(require("./applyPricesToElements"), exports);
66
66
  __exportStar(require("./fixUsdValue"), exports);
67
+ __exportStar(require("./reduceYieldElements"), exports);
67
68
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,oDAAkC;AAClC,kEAAgD;AAChD,sDAAoC;AACpC,iDAA+B;AAC/B,sDAAoC;AACpC,kDAAgC;AAChC,uDAAqC;AACrC,4DAA0C;AAC1C,+DAA6C;AAC7C,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,wDAAsC;AACtC,qDAAmC;AACnC,+DAA6C;AAC7C,2DAAyC;AACzC,uDAAqC;AACrC,mDAAiC;AACjC,wDAAsC;AACtC,2DAAyC;AACzC,+DAA6C;AAC7C,kEAAgD;AAChD,yDAAuC;AACvC,0DAAwC;AACxC,4DAA0C;AAC1C,8DAA4C;AAC5C,mDAAiC;AACjC,yDAAuC;AACvC,mEAAiD;AACjD,oEAAkD;AAClD,+CAA6B;AAC7B,yDAAuC;AACvC,0DAAwC;AACxC,4DAA0C;AAC1C,wDAAsC;AACtC,2DAAyC;AACzC,sDAAoC;AACpC,uDAAqC;AACrC,uDAAqC;AACrC,sDAAoC;AACpC,uDAAqC;AACrC,8DAA4C;AAC5C,8DAA4C;AAC5C,mDAAiC;AACjC,uDAAqC;AACrC,2DAAyC;AACzC,kDAAgC;AAChC,0DAAwC;AACxC,gDAA8B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB;AACvB,oDAAkC;AAClC,kEAAgD;AAChD,sDAAoC;AACpC,iDAA+B;AAC/B,sDAAoC;AACpC,kDAAgC;AAChC,uDAAqC;AACrC,4DAA0C;AAC1C,+DAA6C;AAC7C,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,wDAAsC;AACtC,qDAAmC;AACnC,+DAA6C;AAC7C,2DAAyC;AACzC,uDAAqC;AACrC,mDAAiC;AACjC,wDAAsC;AACtC,2DAAyC;AACzC,+DAA6C;AAC7C,kEAAgD;AAChD,yDAAuC;AACvC,0DAAwC;AACxC,4DAA0C;AAC1C,8DAA4C;AAC5C,mDAAiC;AACjC,yDAAuC;AACvC,mEAAiD;AACjD,oEAAkD;AAClD,+CAA6B;AAC7B,yDAAuC;AACvC,0DAAwC;AACxC,4DAA0C;AAC1C,wDAAsC;AACtC,2DAAyC;AACzC,sDAAoC;AACpC,uDAAqC;AACrC,uDAAqC;AACrC,sDAAoC;AACpC,uDAAqC;AACrC,8DAA4C;AAC5C,8DAA4C;AAC5C,mDAAiC;AACjC,uDAAqC;AACrC,2DAAyC;AACzC,kDAAgC;AAChC,0DAAwC;AACxC,gDAA8B;AAC9B,wDAAsC"}
@@ -0,0 +1,2 @@
1
+ import { YieldElement } from '../Yield';
2
+ export declare const reduceYieldElements: (yieldItems: YieldElement[]) => number;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.reduceYieldElements = void 0;
4
+ const getUsdValueSum_1 = require("./getUsdValueSum");
5
+ const reduceYieldElements = (yieldItems) => {
6
+ const totalValue = (0, getUsdValueSum_1.getUsdValueSum)(yieldItems.map((ye) => ye.value));
7
+ return yieldItems
8
+ .filter((ye) => ye.apy !== 0)
9
+ .reduce((sum, ye) => sum + (ye.apy * ye.value) / totalValue, 0);
10
+ };
11
+ exports.reduceYieldElements = reduceYieldElements;
12
+ //# sourceMappingURL=reduceYieldElements.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduceYieldElements.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/reduceYieldElements.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAG3C,MAAM,mBAAmB,GAAG,CAAC,UAA0B,EAAE,EAAE;IAChE,MAAM,UAAU,GAAG,IAAA,+BAAc,EAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;IACpE,OAAO,UAAU;SACd,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC;SAC5B,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC;AALW,QAAA,mBAAmB,uBAK9B"}