@sonarwatch/portfolio-plugins 0.14.134 → 0.14.135

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,10 @@
2
2
 
3
3
  This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
4
 
5
+ ## [0.14.135](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.134...plugins-0.14.135) (2025-02-28)
6
+
7
+
8
+
5
9
  ## [0.14.134](https://github.com/sonarwatch/portfolio/compare/plugins-0.14.133...plugins-0.14.134) (2025-02-28)
6
10
 
7
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonarwatch/portfolio-plugins",
3
- "version": "0.14.134",
3
+ "version": "0.14.135",
4
4
  "type": "commonjs",
5
5
  "types": "./src/index.d.ts",
6
6
  "peerDependencies": {
@@ -17,27 +17,34 @@ class ElementTradeBuilder extends ElementBuilder_1.ElementBuilder {
17
17
  this.params = params;
18
18
  }
19
19
  tokenAddresses() {
20
- var _a, _b;
20
+ if (!this.params)
21
+ return [];
21
22
  const mints = [];
22
- if ((_a = this.params) === null || _a === void 0 ? void 0 : _a.inputAsset)
23
- mints.push(...new AssetTokenBuilder_1.AssetTokenBuilder(this.params.inputAsset).tokenAddresses());
24
- if ((_b = this.params) === null || _b === void 0 ? void 0 : _b.outputAsset)
23
+ if (this.params.inputAsset)
24
+ mints.push(this.params.inputAsset.address.toString());
25
+ if (this.params.outputAsset)
25
26
  mints.push(this.params.outputAsset.address.toString());
26
27
  return mints;
27
28
  }
28
29
  get(networkId, platformId, tokenPrices) {
29
- var _a, _b, _c;
30
+ var _a, _b, _c, _d, _e, _f, _g;
30
31
  if (!this.params)
31
32
  return null;
32
- const inputAsset = new AssetTokenBuilder_1.AssetTokenBuilder(this.params.inputAsset).get(networkId, tokenPrices);
33
- if (!(inputAsset === null || inputAsset === void 0 ? void 0 : inputAsset.data.amount))
33
+ if ((!this.params.inputAsset.amount ||
34
+ ((_a = this.params.inputAsset.amount) === null || _a === void 0 ? void 0 : _a.toString()) === '0') &&
35
+ (!this.params.outputAsset.amount ||
36
+ ((_b = this.params.outputAsset.amount) === null || _b === void 0 ? void 0 : _b.toString()) === '0'))
34
37
  return null;
35
- const outputAsset = new bignumber_js_1.default(this.params.outputAsset.amount || 0).gt(0)
36
- ? new AssetTokenBuilder_1.AssetTokenBuilder({
37
- address: this.params.outputAsset.address.toString(),
38
- amount: new bignumber_js_1.default(this.params.outputAsset.amount || 0).toNumber(),
39
- }).get(networkId, tokenPrices)
40
- : null;
38
+ const inputAmount = new bignumber_js_1.default(((_c = this.params.inputAsset) === null || _c === void 0 ? void 0 : _c.amount) || 0);
39
+ const outputAmount = new bignumber_js_1.default(((_d = this.params.outputAsset) === null || _d === void 0 ? void 0 : _d.amount) || 0);
40
+ const inputAsset = new AssetTokenBuilder_1.AssetTokenBuilder({
41
+ address: this.params.inputAsset.address.toString(),
42
+ amount: inputAmount.toNumber(),
43
+ }).get(networkId, tokenPrices);
44
+ const outputAsset = new AssetTokenBuilder_1.AssetTokenBuilder({
45
+ address: this.params.outputAsset.address.toString(),
46
+ amount: outputAmount.toNumber(),
47
+ }).get(networkId, tokenPrices);
41
48
  const inputPrice = tokenPrices.get(this.params.inputAsset.address.toString());
42
49
  const outputPrice = tokenPrices.get(this.params.outputAsset.address.toString());
43
50
  if (!inputPrice)
@@ -69,17 +76,17 @@ class ElementTradeBuilder extends ElementBuilder_1.ElementBuilder {
69
76
  .toNumber()
70
77
  : undefined,
71
78
  filledPercentage: new bignumber_js_1.default(1)
72
- .minus(new bignumber_js_1.default(inputAsset.data.amount).dividedBy(initialInputAmount))
79
+ .minus(new bignumber_js_1.default((inputAsset === null || inputAsset === void 0 ? void 0 : inputAsset.data.amount) || 0).dividedBy(initialInputAmount))
73
80
  .toNumber(),
74
81
  inputPrice: inputPrice.price,
75
82
  outputPrice: (outputPrice === null || outputPrice === void 0 ? void 0 : outputPrice.price) || null,
76
- createdAt: (_a = this.params) === null || _a === void 0 ? void 0 : _a.createdAt,
77
- expireAt: (_b = this.params) === null || _b === void 0 ? void 0 : _b.expireAt,
78
- ref: (_c = this.ref) === null || _c === void 0 ? void 0 : _c.toString(),
83
+ createdAt: (_e = this.params) === null || _e === void 0 ? void 0 : _e.createdAt,
84
+ expireAt: (_f = this.params) === null || _f === void 0 ? void 0 : _f.expireAt,
85
+ ref: (_g = this.ref) === null || _g === void 0 ? void 0 : _g.toString(),
79
86
  sourceRefs: this.sourceRefs,
80
87
  link: this.link,
81
88
  },
82
- value: (0, portfolio_core_1.getUsdValueSum)([inputAsset.value, (outputAsset === null || outputAsset === void 0 ? void 0 : outputAsset.value) || 0]),
89
+ value: (0, portfolio_core_1.getUsdValueSum)([(inputAsset === null || inputAsset === void 0 ? void 0 : inputAsset.value) || 0, (outputAsset === null || outputAsset === void 0 ? void 0 : outputAsset.value) || 0]),
83
90
  };
84
91
  }
85
92
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ElementTradeBuilder.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/elementbuilder/ElementTradeBuilder.ts"],"names":[],"mappings":";;;;;;AAAA,+DAKoC;AACpC,gEAAqC;AACrC,qDAAkD;AAGlD,2DAAwD;AAExD,MAAa,mBAAoB,SAAQ,+BAAc;IAGrD,qEAAqE;IACrE,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,MAAmB;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,cAAc;;QACZ,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,IAAI,MAAA,IAAI,CAAC,MAAM,0CAAE,UAAU;YACzB,KAAK,CAAC,IAAI,CACR,GAAG,IAAI,qCAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,cAAc,EAAE,CAClE,CAAC;QACJ,IAAI,M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,CAAC,CAAC,CAAC;qBAC/B,KAAK,CACJ,IAAI,sBAAS,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,kBAAkB,CAAC,CACpE;qBACA,QAAQ,EAAE;gBACb,UAAU,EAAE,UAAU,CAAC,KAAK;gBAC5B,WAAW,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,KAAI,IAAI;gBACvC,SAAS,EAAE,MAAA,IAAI,CAAC,MAAM,0CAAE,SAAS;gBACjC,QAAQ,EAAE,MAAA,IAAI,CAAC,MAAM,0CAAE,QAAQ;gBAC/B,GAAG,EAAE,MAAA,IAAI,CAAC,GAAG,0CAAE,QAAQ,EAAE;gBACzB,UAAU,EAAE,IAAI,CAAC,UAAU;gBAC3B,IAAI,EAAE,IAAI,CAAC,IAAI;aAChB;YACD,KAAK,EAAE,IAAA,+BAAc,EAAC,CAAC,UAAU,CAAC,KAAK,EAAE,CAAA,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,KAAK,KAAI,CAAC,CAAC,CAAC;SACnE,CAAC;IACJ,CAAC;CACF;AAnGD,kDAmGC"}
1
+ {"version":3,"file":"ElementTradeBuilder.js","sourceRoot":"","sources":["../../../../../../packages/plugins/src/utils/elementbuilder/ElementTradeBuilder.ts"],"names":[],"mappings":";;;;;;AAAA,+DAKoC;AACpC,gEAAqC;AACrC,qDAAkD;AAGlD,2DAAwD;AAExD,MAAa,mBAAoB,SAAQ,+BAAc;IAGrD,qEAAqE;IACrE,YAAY,MAAc;QACxB,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED,QAAQ,CAAC,MAAmB;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,cAAc;QACZ,IAAI,CAAC,IAAI,CAAC,MAAM;YAAE,OAAO,EAAE,CAAC;QAE5B,MAAM,KAAK,GAAG,EAAE,CAAC;QACjB,IAAI,IAAI,CAAC,MAAM,CA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CAAC;SACzE,CAAC;IACJ,CAAC;CACF;AA7GD,kDA6GC"}
@@ -72,9 +72,10 @@ export type PortfolioAssetTokenParams = {
72
72
  link?: string;
73
73
  };
74
74
  export type TradeParams = {
75
- inputAsset: PortfolioAssetTokenParams;
76
- outputAsset: {
77
- address: string | PublicKey;
75
+ inputAsset: Omit<PortfolioAssetTokenParams, 'amount'> & {
76
+ amount?: number | BigNumber | string;
77
+ };
78
+ outputAsset: Omit<PortfolioAssetTokenParams, 'amount'> & {
78
79
  amount?: number | BigNumber | string;
79
80
  };
80
81
  initialInputAmount: number | BigNumber | string;