@morpho-org/blue-sdk 1.4.5 → 1.4.6-alpha.0

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.
@@ -0,0 +1,46 @@
1
+ import { Token } from "../token/Token";
2
+ export type PeripheralBalanceType = "base" | "wrapped" | "staked-wrapped" | "vault" | "wrapped-vault" | "unwrapped-staked-wrapped";
3
+ /**
4
+ * Represents the balance of a requested token and the balance quoted in the corresponding source token:
5
+ * ```{
6
+ * type: "staked-wrapped",
7
+ * srcToken: ETH,
8
+ * srcAmount: 1 ETH,
9
+ * dstAmount: 1.2 wstETH
10
+ * }```
11
+ */
12
+ export interface PeripheralBalance {
13
+ /**
14
+ * The type of balance conversion.
15
+ */
16
+ type: PeripheralBalanceType;
17
+ /**
18
+ * The source token held corresponding to the type of balance conversion.
19
+ */
20
+ srcToken: Token;
21
+ /**
22
+ * The source amount of source token held.
23
+ */
24
+ srcAmount: bigint;
25
+ /**
26
+ * The corresponding amount of token held after conversion of the whole balance `srcAmount`.
27
+ */
28
+ dstAmount: bigint;
29
+ }
30
+ export declare class AssetBalances {
31
+ /**
32
+ * The total balance of all types of related tokens.
33
+ */
34
+ total: bigint;
35
+ /**
36
+ * The balance of each type of related tokens and the corresponding underlying balance.
37
+ */
38
+ allocations: {
39
+ base: PeripheralBalance;
40
+ } & {
41
+ [T in Exclude<PeripheralBalanceType, "base">]?: PeripheralBalance;
42
+ };
43
+ constructor(balance: PeripheralBalance);
44
+ add(balance: PeripheralBalance): this;
45
+ sub(balance: PeripheralBalance): this;
46
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AssetBalances = void 0;
4
+ class AssetBalances {
5
+ /**
6
+ * The total balance of all types of related tokens.
7
+ */
8
+ total;
9
+ /**
10
+ * The balance of each type of related tokens and the corresponding underlying balance.
11
+ */
12
+ allocations;
13
+ constructor(balance) {
14
+ this.total = balance.dstAmount;
15
+ this.allocations = { base: balance };
16
+ }
17
+ add(balance) {
18
+ this.total += balance.dstAmount;
19
+ const allocation = (this.allocations[balance.type] ??= {
20
+ ...balance,
21
+ srcAmount: 0n,
22
+ dstAmount: 0n,
23
+ });
24
+ allocation.srcAmount += balance.srcAmount;
25
+ allocation.dstAmount += balance.dstAmount;
26
+ return this;
27
+ }
28
+ sub(balance) {
29
+ this.total -= balance.dstAmount;
30
+ const allocation = (this.allocations[balance.type] ??= {
31
+ ...balance,
32
+ srcAmount: 0n,
33
+ dstAmount: 0n,
34
+ });
35
+ allocation.srcAmount -= balance.srcAmount;
36
+ allocation.dstAmount -= balance.dstAmount;
37
+ return this;
38
+ }
39
+ }
40
+ exports.AssetBalances = AssetBalances;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morpho-org/blue-sdk",
3
- "version": "1.4.5",
3
+ "version": "1.4.6-alpha.0",
4
4
  "author": "Morpho Association <contact@morpho.org>",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -16,16 +16,16 @@
16
16
  "keccak256": "^1.0.6"
17
17
  },
18
18
  "devDependencies": {
19
- "@morpho-org/morpho-test": "^1.4.5",
20
- "@morpho-org/morpho-ts": "^1.4.5",
19
+ "@morpho-org/morpho-test": "^1.4.6-alpha.0",
20
+ "@morpho-org/morpho-ts": "^1.4.6-alpha.0",
21
21
  "@types/jest": "^29.5.12",
22
- "@types/node": "^22.0.0",
22
+ "@types/node": "^22.1.0",
23
23
  "jest": "^29.7.0",
24
24
  "ts-jest": "^29.2.2",
25
25
  "typescript": "^5.4.5"
26
26
  },
27
27
  "peerDependencies": {
28
- "@morpho-org/morpho-ts": "^1.4.5"
28
+ "@morpho-org/morpho-ts": "^1.4.6-alpha.0"
29
29
  },
30
30
  "publishConfig": {
31
31
  "access": "public"
@@ -49,5 +49,5 @@
49
49
  ],
50
50
  "preset": "ts-jest"
51
51
  },
52
- "gitHead": "ccdff72b67bf77ef55d340d70106305bb8bbe4c2"
52
+ "gitHead": "369f239808e8e7edc3b45f6f81d2d8b74f871cb6"
53
53
  }