@morpho-org/blue-sdk 6.0.1 → 6.1.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.
Files changed (139) hide show
  1. package/lib/cjs/addresses.d.ts +105 -0
  2. package/lib/cjs/addresses.js +74 -0
  3. package/lib/cjs/chain.d.ts +84 -1
  4. package/lib/cjs/chain.js +78 -0
  5. package/lib/cjs/errors.d.ts +34 -0
  6. package/lib/cjs/errors.js +28 -0
  7. package/lib/cjs/holding/AssetBalances.d.ts +3 -0
  8. package/lib/cjs/holding/AssetBalances.js +1 -0
  9. package/lib/cjs/holding/Holding.d.ts +6 -0
  10. package/lib/cjs/holding/Holding.js +2 -0
  11. package/lib/cjs/market/Market.d.ts +4 -0
  12. package/lib/cjs/market/MarketParams.d.ts +3 -0
  13. package/lib/cjs/market/MarketParams.js +1 -0
  14. package/lib/cjs/market/MarketUtils.d.ts +397 -0
  15. package/lib/cjs/market/MarketUtils.js +397 -2
  16. package/lib/cjs/math/AdaptiveCurveIrmLib.d.ts +51 -1
  17. package/lib/cjs/math/AdaptiveCurveIrmLib.js +51 -1
  18. package/lib/cjs/math/MathLib.d.ts +152 -4
  19. package/lib/cjs/math/MathLib.js +151 -4
  20. package/lib/cjs/math/SharesMath.d.ts +34 -0
  21. package/lib/cjs/math/SharesMath.js +34 -0
  22. package/lib/cjs/position/Position.d.ts +4 -0
  23. package/lib/cjs/position/Position.js +2 -0
  24. package/lib/cjs/position/PreLiquidationPosition.d.ts +4 -0
  25. package/lib/cjs/position/PreLiquidationPosition.js +2 -0
  26. package/lib/cjs/preLiquidation.d.ts +16 -0
  27. package/lib/cjs/preLiquidation.js +16 -0
  28. package/lib/cjs/token/ConstantWrappedToken.d.ts +1 -0
  29. package/lib/cjs/token/ConstantWrappedToken.js +1 -0
  30. package/lib/cjs/token/Eip5267Domain.d.ts +4 -0
  31. package/lib/cjs/token/Eip5267Domain.js +2 -0
  32. package/lib/cjs/token/ExchangeRateWrappedToken.d.ts +1 -0
  33. package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
  34. package/lib/cjs/token/Token.d.ts +2 -0
  35. package/lib/cjs/token/Token.js +1 -0
  36. package/lib/cjs/token/VaultToken.d.ts +2 -0
  37. package/lib/cjs/token/VaultToken.js +1 -0
  38. package/lib/cjs/token/WrappedToken.d.ts +1 -0
  39. package/lib/cjs/token/WrappedToken.js +1 -0
  40. package/lib/cjs/types.d.ts +17 -0
  41. package/lib/cjs/types.js +13 -0
  42. package/lib/cjs/user/User.d.ts +1 -0
  43. package/lib/cjs/user/User.js +1 -0
  44. package/lib/cjs/utils.d.ts +2 -0
  45. package/lib/cjs/utils.js +1 -0
  46. package/lib/cjs/vault/Vault.d.ts +7 -0
  47. package/lib/cjs/vault/Vault.js +2 -0
  48. package/lib/cjs/vault/VaultConfig.d.ts +2 -0
  49. package/lib/cjs/vault/VaultConfig.js +1 -0
  50. package/lib/cjs/vault/VaultMarketAllocation.d.ts +2 -0
  51. package/lib/cjs/vault/VaultMarketAllocation.js +1 -0
  52. package/lib/cjs/vault/VaultMarketConfig.d.ts +2 -0
  53. package/lib/cjs/vault/VaultMarketConfig.js +1 -0
  54. package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
  55. package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.js +1 -0
  56. package/lib/cjs/vault/VaultUser.d.ts +2 -0
  57. package/lib/cjs/vault/VaultUser.js +1 -0
  58. package/lib/cjs/vault/VaultUtils.d.ts +49 -0
  59. package/lib/cjs/vault/VaultUtils.js +49 -0
  60. package/lib/cjs/vault/v2/VaultV2.d.ts +5 -0
  61. package/lib/cjs/vault/v2/VaultV2.js +2 -0
  62. package/lib/cjs/vault/v2/VaultV2Adapter.d.ts +3 -0
  63. package/lib/cjs/vault/v2/VaultV2Adapter.js +1 -0
  64. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
  65. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
  66. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  67. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
  68. package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
  69. package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
  70. package/lib/esm/addresses.d.ts +105 -0
  71. package/lib/esm/addresses.js +74 -0
  72. package/lib/esm/chain.d.ts +84 -1
  73. package/lib/esm/chain.js +78 -0
  74. package/lib/esm/errors.d.ts +34 -0
  75. package/lib/esm/errors.js +28 -0
  76. package/lib/esm/holding/AssetBalances.d.ts +3 -0
  77. package/lib/esm/holding/AssetBalances.js +1 -0
  78. package/lib/esm/holding/Holding.d.ts +6 -0
  79. package/lib/esm/holding/Holding.js +2 -0
  80. package/lib/esm/market/Market.d.ts +4 -0
  81. package/lib/esm/market/MarketParams.d.ts +3 -0
  82. package/lib/esm/market/MarketParams.js +1 -0
  83. package/lib/esm/market/MarketUtils.d.ts +397 -0
  84. package/lib/esm/market/MarketUtils.js +397 -2
  85. package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +51 -1
  86. package/lib/esm/math/AdaptiveCurveIrmLib.js +51 -1
  87. package/lib/esm/math/MathLib.d.ts +152 -4
  88. package/lib/esm/math/MathLib.js +151 -4
  89. package/lib/esm/math/SharesMath.d.ts +34 -0
  90. package/lib/esm/math/SharesMath.js +34 -0
  91. package/lib/esm/position/Position.d.ts +4 -0
  92. package/lib/esm/position/Position.js +2 -0
  93. package/lib/esm/position/PreLiquidationPosition.d.ts +4 -0
  94. package/lib/esm/position/PreLiquidationPosition.js +2 -0
  95. package/lib/esm/preLiquidation.d.ts +16 -0
  96. package/lib/esm/preLiquidation.js +16 -0
  97. package/lib/esm/token/ConstantWrappedToken.d.ts +1 -0
  98. package/lib/esm/token/ConstantWrappedToken.js +1 -0
  99. package/lib/esm/token/Eip5267Domain.d.ts +4 -0
  100. package/lib/esm/token/Eip5267Domain.js +2 -0
  101. package/lib/esm/token/ExchangeRateWrappedToken.d.ts +1 -0
  102. package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
  103. package/lib/esm/token/Token.d.ts +2 -0
  104. package/lib/esm/token/Token.js +1 -0
  105. package/lib/esm/token/VaultToken.d.ts +2 -0
  106. package/lib/esm/token/VaultToken.js +1 -0
  107. package/lib/esm/token/WrappedToken.d.ts +1 -0
  108. package/lib/esm/token/WrappedToken.js +1 -0
  109. package/lib/esm/types.d.ts +17 -0
  110. package/lib/esm/types.js +13 -0
  111. package/lib/esm/user/User.d.ts +1 -0
  112. package/lib/esm/user/User.js +1 -0
  113. package/lib/esm/utils.d.ts +2 -0
  114. package/lib/esm/utils.js +1 -0
  115. package/lib/esm/vault/Vault.d.ts +7 -0
  116. package/lib/esm/vault/Vault.js +2 -0
  117. package/lib/esm/vault/VaultConfig.d.ts +2 -0
  118. package/lib/esm/vault/VaultConfig.js +1 -0
  119. package/lib/esm/vault/VaultMarketAllocation.d.ts +2 -0
  120. package/lib/esm/vault/VaultMarketAllocation.js +1 -0
  121. package/lib/esm/vault/VaultMarketConfig.d.ts +2 -0
  122. package/lib/esm/vault/VaultMarketConfig.js +1 -0
  123. package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
  124. package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +1 -0
  125. package/lib/esm/vault/VaultUser.d.ts +2 -0
  126. package/lib/esm/vault/VaultUser.js +1 -0
  127. package/lib/esm/vault/VaultUtils.d.ts +49 -0
  128. package/lib/esm/vault/VaultUtils.js +49 -0
  129. package/lib/esm/vault/v2/VaultV2.d.ts +5 -0
  130. package/lib/esm/vault/v2/VaultV2.js +2 -0
  131. package/lib/esm/vault/v2/VaultV2Adapter.d.ts +3 -0
  132. package/lib/esm/vault/v2/VaultV2Adapter.js +1 -0
  133. package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
  134. package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
  135. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  136. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
  137. package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
  138. package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
  139. package/package.json +2 -2
@@ -1,5 +1,6 @@
1
1
  import { type IMarket, Market, type MaxBorrowOptions, type MaxPositionCapacities, type MaxWithdrawCollateralOptions } from "../market/index.js";
2
2
  import type { Address, BigIntish, MarketId } from "../types.js";
3
+ /** Plain input shape for a user's Morpho Blue market position. */
3
4
  export interface IPosition {
4
5
  user: Address;
5
6
  marketId: MarketId;
@@ -7,6 +8,7 @@ export interface IPosition {
7
8
  borrowShares: bigint;
8
9
  collateral: bigint;
9
10
  }
11
+ /** Represents a user's supply, borrow, and collateral balances on one market. */
10
12
  export declare class Position implements IPosition {
11
13
  /**
12
14
  * The user holding this position.
@@ -30,8 +32,10 @@ export declare class Position implements IPosition {
30
32
  collateral: bigint;
31
33
  constructor({ user, marketId, supplyShares, borrowShares, collateral, }: IPosition);
32
34
  }
35
+ /** Plain input shape for a position paired with market state for accrual math. */
33
36
  export interface IAccrualPosition extends Omit<IPosition, "marketId"> {
34
37
  }
38
+ /** Represents a position paired with market state for derived and accrued values. */
35
39
  export declare class AccrualPosition extends Position implements IAccrualPosition {
36
40
  protected readonly _market: Market;
37
41
  constructor(position: IAccrualPosition, market: IMarket);
@@ -2,6 +2,7 @@ import { BlueErrors } from "../errors.js";
2
2
  import { Market, } from "../market/index.js";
3
3
  import { MathLib } from "../math/MathLib.js";
4
4
  import { CapacityLimitReason } from "../utils.js";
5
+ /** Represents a user's supply, borrow, and collateral balances on one market. */
5
6
  export class Position {
6
7
  /**
7
8
  * The user holding this position.
@@ -31,6 +32,7 @@ export class Position {
31
32
  this.collateral = collateral;
32
33
  }
33
34
  }
35
+ /** Represents a position paired with market state for derived and accrued values. */
34
36
  export class AccrualPosition extends Position {
35
37
  _market;
36
38
  constructor(position, market) {
@@ -2,6 +2,7 @@ import type { Address } from "viem";
2
2
  import { type IMarket, Market } from "../market/index.js";
3
3
  import type { BigIntish } from "../types.js";
4
4
  import { AccrualPosition, type IAccrualPosition } from "./Position.js";
5
+ /** Plain input shape for PreLiquidation contract parameters. */
5
6
  export interface IPreLiquidationParams {
6
7
  preLltv: BigIntish;
7
8
  preLCF1: BigIntish;
@@ -10,6 +11,7 @@ export interface IPreLiquidationParams {
10
11
  preLIF2: BigIntish;
11
12
  preLiquidationOracle: Address;
12
13
  }
14
+ /** Represents PreLiquidation contract parameters and factor interpolation helpers. */
13
15
  export declare class PreLiquidationParams implements IPreLiquidationParams {
14
16
  readonly preLltv: bigint;
15
17
  readonly preLCF1: bigint;
@@ -21,6 +23,7 @@ export declare class PreLiquidationParams implements IPreLiquidationParams {
21
23
  getCloseFactor(quotient: BigIntish): bigint;
22
24
  getIncentiveFactor(quotient: BigIntish): bigint;
23
25
  }
26
+ /** Plain input shape for a position associated with a PreLiquidation contract. */
24
27
  export interface IPreLiquidationPosition extends IAccrualPosition {
25
28
  /**
26
29
  * The pre-liquidation parameters of the associated PreLiquidation contract.
@@ -36,6 +39,7 @@ export interface IPreLiquidationPosition extends IAccrualPosition {
36
39
  */
37
40
  preLiquidationOraclePrice?: BigIntish;
38
41
  }
42
+ /** Represents a position evaluated under PreLiquidation-specific risk parameters. */
39
43
  export declare class PreLiquidationPosition extends AccrualPosition implements IPreLiquidationPosition {
40
44
  readonly preLiquidationParams: PreLiquidationParams;
41
45
  readonly preLiquidation: `0x${string}`;
@@ -2,6 +2,7 @@ import { ORACLE_PRICE_SCALE } from "../constants.js";
2
2
  import { Market } from "../market/index.js";
3
3
  import { MathLib, SharesMath } from "../math/index.js";
4
4
  import { AccrualPosition } from "./Position.js";
5
+ /** Represents PreLiquidation contract parameters and factor interpolation helpers. */
5
6
  export class PreLiquidationParams {
6
7
  preLltv;
7
8
  preLCF1;
@@ -24,6 +25,7 @@ export class PreLiquidationParams {
24
25
  return (this.preLIF1 + MathLib.wMulDown(quotient, this.preLIF2 - this.preLIF1));
25
26
  }
26
27
  }
28
+ /** Represents a position evaluated under PreLiquidation-specific risk parameters. */
27
29
  export class PreLiquidationPosition extends AccrualPosition {
28
30
  preLiquidationParams;
29
31
  preLiquidation;
@@ -1,4 +1,5 @@
1
1
  import type { BigIntish } from "./types.js";
2
+ /** Default PreLiquidation parameter registry keyed by Morpho Blue LLTV. */
2
3
  export declare const defaultPreLiquidationParamsRegistry: Map<bigint, {
3
4
  preLltv: bigint;
4
5
  preLCF1: bigint;
@@ -6,6 +7,21 @@ export declare const defaultPreLiquidationParamsRegistry: Map<bigint, {
6
7
  preLIF1: bigint;
7
8
  preLIF2: bigint;
8
9
  }>;
10
+ /**
11
+ * Returns default PreLiquidation params for a supported Morpho Blue LLTV.
12
+ *
13
+ * @param lltv - The Morpho Blue liquidation loan-to-value, scaled by WAD.
14
+ * @returns The default PreLiquidation parameter set for `lltv`.
15
+ * @throws {UnsupportedPreLiquidationParamsError} when no default parameters exist for `lltv`.
16
+ * @example
17
+ * ```ts
18
+ * import { getDefaultPreLiquidationParams } from "@morpho-org/blue-sdk";
19
+ * import { parseEther } from "viem";
20
+ *
21
+ * const params = getDefaultPreLiquidationParams(parseEther("0.86"));
22
+ * // params satisfies { preLltv: bigint; preLCF1: bigint; preLCF2: bigint; preLIF1: bigint; preLIF2: bigint }
23
+ * ```
24
+ */
9
25
  export declare const getDefaultPreLiquidationParams: (lltv: BigIntish) => {
10
26
  preLltv: bigint;
11
27
  preLCF1: bigint;
@@ -1,5 +1,6 @@
1
1
  import { parseEther } from "viem";
2
2
  import { UnsupportedPreLiquidationParamsError } from "./errors.js";
3
+ /** Default PreLiquidation parameter registry keyed by Morpho Blue LLTV. */
3
4
  export const defaultPreLiquidationParamsRegistry = new Map([
4
5
  [
5
6
  parseEther("0.385"),
@@ -82,6 +83,21 @@ export const defaultPreLiquidationParamsRegistry = new Map([
82
83
  },
83
84
  ],
84
85
  ]);
86
+ /**
87
+ * Returns default PreLiquidation params for a supported Morpho Blue LLTV.
88
+ *
89
+ * @param lltv - The Morpho Blue liquidation loan-to-value, scaled by WAD.
90
+ * @returns The default PreLiquidation parameter set for `lltv`.
91
+ * @throws {UnsupportedPreLiquidationParamsError} when no default parameters exist for `lltv`.
92
+ * @example
93
+ * ```ts
94
+ * import { getDefaultPreLiquidationParams } from "@morpho-org/blue-sdk";
95
+ * import { parseEther } from "viem";
96
+ *
97
+ * const params = getDefaultPreLiquidationParams(parseEther("0.86"));
98
+ * // params satisfies { preLltv: bigint; preLCF1: bigint; preLCF2: bigint; preLIF1: bigint; preLIF2: bigint }
99
+ * ```
100
+ */
85
101
  export const getDefaultPreLiquidationParams = (lltv) => {
86
102
  // biome-ignore lint/style/noParameterAssign: TODO refactor to avoid mutating parameter
87
103
  lltv = BigInt(lltv);
@@ -2,6 +2,7 @@ import { type RoundingDirection } from "../math/index.js";
2
2
  import type { Address, BigIntish } from "../types.js";
3
3
  import type { IToken } from "./Token.js";
4
4
  import { WrappedToken } from "./WrappedToken.js";
5
+ /** Represents a wrapped token with a constant decimals-based conversion rate. */
5
6
  export declare class ConstantWrappedToken extends WrappedToken {
6
7
  readonly underlyingDecimals: bigint;
7
8
  constructor(token: IToken, underlying: Address, underlyingDecimals?: BigIntish);
@@ -1,5 +1,6 @@
1
1
  import { MathLib } from "../math/index.js";
2
2
  import { WrappedToken } from "./WrappedToken.js";
3
+ /** Represents a wrapped token with a constant decimals-based conversion rate. */
3
4
  export class ConstantWrappedToken extends WrappedToken {
4
5
  underlyingDecimals;
5
6
  // biome-ignore lint/complexity/useMaxParams: TODO refactor to ≤2 params
@@ -1,6 +1,9 @@
1
1
  import type { Address } from "../types.js";
2
+ /** Ordered EIP-712 domain fields exposed by EIP-5267. */
2
3
  export declare const EIP_712_FIELDS: readonly ["name", "version", "chainId", "verifyingContract", "salt"];
4
+ /** EIP-712 domain field name exposed by EIP-5267. */
3
5
  export type Eip712Field = (typeof EIP_712_FIELDS)[number];
6
+ /** Plain input shape for an EIP-5267 signing domain. */
4
7
  export interface IEip5267Domain {
5
8
  fields: `0x${string}`;
6
9
  name: string;
@@ -10,6 +13,7 @@ export interface IEip5267Domain {
10
13
  salt: `0x${string}`;
11
14
  extensions: readonly bigint[];
12
15
  }
16
+ /** Represents an EIP-5267 signing domain and derived EIP-712 domain object. */
13
17
  export declare class Eip5267Domain implements IEip5267Domain {
14
18
  /**
15
19
  * A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4).
@@ -1,3 +1,4 @@
1
+ /** Ordered EIP-712 domain fields exposed by EIP-5267. */
1
2
  export const EIP_712_FIELDS = [
2
3
  "name",
3
4
  "version",
@@ -5,6 +6,7 @@ export const EIP_712_FIELDS = [
5
6
  "verifyingContract",
6
7
  "salt",
7
8
  ];
9
+ /** Represents an EIP-5267 signing domain and derived EIP-712 domain object. */
8
10
  export class Eip5267Domain {
9
11
  /**
10
12
  * A bit map where bit i is set to 1 if and only if domain field i is present (0 ≤ i ≤ 4).
@@ -2,6 +2,7 @@ import { type RoundingDirection } from "../math/index.js";
2
2
  import type { Address } from "../types.js";
3
3
  import type { IToken } from "./Token.js";
4
4
  import { WrappedToken } from "./WrappedToken.js";
5
+ /** Represents a wrapped token whose conversion uses a WAD-scaled exchange rate. */
5
6
  export declare class ExchangeRateWrappedToken extends WrappedToken {
6
7
  readonly underlying: Address;
7
8
  wrappedTokenExchangeRate: bigint;
@@ -1,5 +1,6 @@
1
1
  import { MathLib } from "../math/index.js";
2
2
  import { WrappedToken } from "./WrappedToken.js";
3
+ /** Represents a wrapped token whose conversion uses a WAD-scaled exchange rate. */
3
4
  export class ExchangeRateWrappedToken extends WrappedToken {
4
5
  underlying;
5
6
  wrappedTokenExchangeRate;
@@ -2,6 +2,7 @@ import { type ChainId } from "../chain.js";
2
2
  import { type RoundingDirection } from "../math/index.js";
3
3
  import type { Address, BigIntish } from "../types.js";
4
4
  import type { Eip5267Domain } from "./Eip5267Domain.js";
5
+ /** Plain input shape for an ERC-20-like token. */
5
6
  export interface IToken {
6
7
  address: Address;
7
8
  name?: string;
@@ -10,6 +11,7 @@ export interface IToken {
10
11
  price?: BigIntish;
11
12
  eip5267Domain?: Eip5267Domain;
12
13
  }
14
+ /** Represents an ERC-20-like token and optional price/signing metadata. */
13
15
  export declare class Token implements IToken {
14
16
  static native(chainId: ChainId): Token;
15
17
  /**
@@ -1,6 +1,7 @@
1
1
  import { NATIVE_ADDRESS } from "../addresses.js";
2
2
  import { ChainUtils } from "../chain.js";
3
3
  import { MathLib } from "../math/index.js";
4
+ /** Represents an ERC-20-like token and optional price/signing metadata. */
4
5
  export class Token {
5
6
  static native(chainId) {
6
7
  const currency = ChainUtils.CHAIN_METADATA[chainId].nativeCurrency;
@@ -2,10 +2,12 @@ import type { RoundingDirection } from "../math/index.js";
2
2
  import type { Address, BigIntish } from "../types.js";
3
3
  import type { IVaultConfig } from "../vault/VaultConfig.js";
4
4
  import { WrappedToken } from "./WrappedToken.js";
5
+ /** Plain input shape for ERC-4626-like vault token totals. */
5
6
  export interface IVaultToken {
6
7
  totalAssets: bigint;
7
8
  totalSupply: bigint;
8
9
  }
10
+ /** Represents an ERC-4626-like vault token with share and asset conversion math. */
9
11
  export declare class VaultToken extends WrappedToken implements IVaultToken {
10
12
  readonly asset: Address;
11
13
  readonly decimalsOffset: bigint;
@@ -1,5 +1,6 @@
1
1
  import { VaultUtils } from "../vault/VaultUtils.js";
2
2
  import { WrappedToken } from "./WrappedToken.js";
3
+ /** Represents an ERC-4626-like vault token with share and asset conversion math. */
3
4
  export class VaultToken extends WrappedToken {
4
5
  asset;
5
6
  decimalsOffset;
@@ -1,6 +1,7 @@
1
1
  import { type RoundingDirection } from "../math/index.js";
2
2
  import type { Address } from "../types.js";
3
3
  import { type IToken, Token } from "./Token.js";
4
+ /** Base class for tokens that wrap and unwrap another token. */
4
5
  export declare abstract class WrappedToken extends Token {
5
6
  readonly underlying: Address;
6
7
  constructor(token: IToken, underlying: Address);
@@ -1,5 +1,6 @@
1
1
  import { MathLib } from "../math/index.js";
2
2
  import { Token } from "./Token.js";
3
+ /** Base class for tokens that wrap and unwrap another token. */
3
4
  export class WrappedToken extends Token {
4
5
  underlying;
5
6
  constructor(token, underlying) {
@@ -8,6 +8,7 @@ export type Address = `0x${string}`;
8
8
  export type MarketId = `0x${string}` & {
9
9
  __TYPE__: "marketId";
10
10
  };
11
+ /** Primitive values accepted at SDK boundaries and normalized to `bigint`. */
11
12
  export type BigIntish = bigint | string | number | boolean;
12
13
  /**
13
14
  * The possible transaction type on the Blue contract
@@ -20,7 +21,23 @@ export declare enum TransactionType {
20
21
  Borrow = "Borrow",
21
22
  Repay = "Repay"
22
23
  }
24
+ /** Value that may not have been loaded yet. */
23
25
  export type Loadable<T> = T | undefined;
26
+ /** Value that may fail to resolve. */
24
27
  export type Failable<T> = T | null;
28
+ /** Value that may be unloaded or fail to resolve. */
25
29
  export type Fetchable<T> = Failable<Loadable<T>>;
30
+ /**
31
+ * Checks whether a value is a 32-byte Morpho Blue market id.
32
+ *
33
+ * @param value - The unknown value to inspect.
34
+ * @returns `true` when `value` is a `0x`-prefixed 32-byte hex string.
35
+ * @example
36
+ * ```ts
37
+ * import { isMarketId } from "@morpho-org/blue-sdk";
38
+ *
39
+ * const valid = isMarketId("0x0000000000000000000000000000000000000000000000000000000000000000");
40
+ * // valid satisfies boolean
41
+ * ```
42
+ */
26
43
  export declare const isMarketId: (value: unknown) => value is MarketId;
package/lib/esm/types.js CHANGED
@@ -10,4 +10,17 @@ export var TransactionType;
10
10
  TransactionType["Borrow"] = "Borrow";
11
11
  TransactionType["Repay"] = "Repay";
12
12
  })(TransactionType || (TransactionType = {}));
13
+ /**
14
+ * Checks whether a value is a 32-byte Morpho Blue market id.
15
+ *
16
+ * @param value - The unknown value to inspect.
17
+ * @returns `true` when `value` is a `0x`-prefixed 32-byte hex string.
18
+ * @example
19
+ * ```ts
20
+ * import { isMarketId } from "@morpho-org/blue-sdk";
21
+ *
22
+ * const valid = isMarketId("0x0000000000000000000000000000000000000000000000000000000000000000");
23
+ * // valid satisfies boolean
24
+ * ```
25
+ */
13
26
  export const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
@@ -1,4 +1,5 @@
1
1
  import type { Address } from "../types.js";
2
+ /** Represents a Morpho Blue user authorization and nonce state. */
2
3
  export declare class User {
3
4
  /**
4
5
  * The user's address.
@@ -1,3 +1,4 @@
1
+ /** Represents a Morpho Blue user authorization and nonce state. */
1
2
  export class User {
2
3
  /**
3
4
  * The user's address.
@@ -1,3 +1,4 @@
1
+ /** Reason why a capacity calculation is capped. */
1
2
  export declare enum CapacityLimitReason {
2
3
  liquidity = "Liquidity",
3
4
  balance = "Balance",
@@ -7,6 +8,7 @@ export declare enum CapacityLimitReason {
7
8
  vaultV2_absoluteCap = "VaultV2_AbsoluteCap",
8
9
  vaultV2_relativeCap = "VaultV2_RelativeCap"
9
10
  }
11
+ /** Bounded capacity value and the reason for the bound. */
10
12
  export interface CapacityLimit {
11
13
  value: bigint;
12
14
  limiter: CapacityLimitReason;
package/lib/esm/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ /** Reason why a capacity calculation is capped. */
1
2
  export var CapacityLimitReason;
2
3
  (function (CapacityLimitReason) {
3
4
  CapacityLimitReason["liquidity"] = "Liquidity";
@@ -4,10 +4,12 @@ import type { Address, BigIntish, MarketId } from "../types.js";
4
4
  import { type CapacityLimit } from "../utils.js";
5
5
  import type { IVaultConfig } from "./VaultConfig.js";
6
6
  import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
7
+ /** Pending governance value and the timestamp at which it becomes valid. */
7
8
  export interface Pending<T> {
8
9
  value: T;
9
10
  validAt: bigint;
10
11
  }
12
+ /** PublicAllocator configuration attached to a MetaMorpho vault. */
11
13
  export interface VaultPublicAllocatorConfig {
12
14
  /**
13
15
  * The PublicAllocator's admin address.
@@ -22,6 +24,7 @@ export interface VaultPublicAllocatorConfig {
22
24
  */
23
25
  accruedFee: bigint;
24
26
  }
27
+ /** Plain input shape for a MetaMorpho vault. */
25
28
  export interface IVault extends IVaultConfig {
26
29
  curator: Address;
27
30
  owner: Address;
@@ -41,6 +44,7 @@ export interface IVault extends IVaultConfig {
41
44
  lostAssets?: bigint;
42
45
  publicAllocatorConfig?: VaultPublicAllocatorConfig;
43
46
  }
47
+ /** Represents a MetaMorpho vault and its governance, queue, and accounting state. */
44
48
  export declare class Vault extends VaultToken implements IVault {
45
49
  /**
46
50
  * The vault's share token's name.
@@ -119,6 +123,7 @@ export declare class Vault extends VaultToken implements IVault {
119
123
  toAssets(shares: BigIntish, rounding?: RoundingDirection): bigint;
120
124
  toShares(assets: BigIntish, rounding?: RoundingDirection): bigint;
121
125
  }
126
+ /** Aggregated vault allocation exposure for one collateral asset. */
122
127
  export interface CollateralAllocation {
123
128
  address: Address;
124
129
  lltvs: Set<bigint>;
@@ -126,8 +131,10 @@ export interface CollateralAllocation {
126
131
  markets: Set<MarketId>;
127
132
  proportion: bigint;
128
133
  }
134
+ /** Plain input shape for a MetaMorpho vault paired with accrued market allocations. */
129
135
  export interface IAccrualVault extends Omit<IVault, "withdrawQueue" | "totalAssets"> {
130
136
  }
137
+ /** Represents a MetaMorpho vault with accrued market allocation state. */
131
138
  export declare class AccrualVault extends Vault implements IAccrualVault {
132
139
  /**
133
140
  * @inheritdoc
@@ -4,6 +4,7 @@ import { MathLib } from "../math/index.js";
4
4
  import { VaultToken } from "../token/index.js";
5
5
  import { CapacityLimitReason } from "../utils.js";
6
6
  import { VaultMarketAllocation, } from "./VaultMarketAllocation.js";
7
+ /** Represents a MetaMorpho vault and its governance, queue, and accounting state. */
7
8
  export class Vault extends VaultToken {
8
9
  /**
9
10
  * The MetaMorpho vault's owner address.
@@ -100,6 +101,7 @@ export class Vault extends VaultToken {
100
101
  return this._wrap(assets, rounding);
101
102
  }
102
103
  }
104
+ /** Represents a MetaMorpho vault with accrued market allocation state. */
103
105
  export class AccrualVault extends Vault {
104
106
  /**
105
107
  * The allocation of the vault on each market enabled.
@@ -1,9 +1,11 @@
1
1
  import { type IToken, Token } from "../token/Token.js";
2
2
  import type { Address, BigIntish } from "../types.js";
3
+ /** Plain input shape for immutable MetaMorpho vault token configuration. */
3
4
  export interface IVaultConfig extends Omit<IToken, "decimals"> {
4
5
  decimalsOffset: BigIntish;
5
6
  asset: Address;
6
7
  }
8
+ /** Represents immutable MetaMorpho vault token configuration. */
7
9
  export declare class VaultConfig extends Token implements IVaultConfig {
8
10
  readonly decimalsOffset: bigint;
9
11
  readonly asset: `0x${string}`;
@@ -1,4 +1,5 @@
1
1
  import { Token } from "../token/Token.js";
2
+ /** Represents immutable MetaMorpho vault token configuration. */
2
3
  export class VaultConfig extends Token {
3
4
  decimalsOffset;
4
5
  asset;
@@ -1,9 +1,11 @@
1
1
  import type { AccrualPosition } from "../position/index.js";
2
2
  import { type IVaultMarketConfig, VaultMarketConfig } from "./VaultMarketConfig.js";
3
+ /** Plain input shape for a vault allocation on one Morpho Blue market. */
3
4
  export interface IVaultMarketAllocation {
4
5
  config: IVaultMarketConfig;
5
6
  position: AccrualPosition;
6
7
  }
8
+ /** Represents a vault allocation on one Morpho Blue market. */
7
9
  export declare class VaultMarketAllocation implements IVaultMarketAllocation {
8
10
  /**
9
11
  * The vault's configuration on the corresponding market.
@@ -1,5 +1,6 @@
1
1
  import { MathLib } from "../math/index.js";
2
2
  import { VaultMarketConfig, } from "./VaultMarketConfig.js";
3
+ /** Represents a vault allocation on one Morpho Blue market. */
3
4
  export class VaultMarketAllocation {
4
5
  /**
5
6
  * The vault's configuration on the corresponding market.
@@ -1,6 +1,7 @@
1
1
  import type { Address, MarketId } from "../types.js";
2
2
  import type { Pending } from "./Vault.js";
3
3
  import type { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig.js";
4
+ /** Plain input shape for a vault's configuration on one Morpho Blue market. */
4
5
  export interface IVaultMarketConfig {
5
6
  vault: Address;
6
7
  marketId: MarketId;
@@ -10,6 +11,7 @@ export interface IVaultMarketConfig {
10
11
  enabled: boolean;
11
12
  publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
12
13
  }
14
+ /** Represents a vault's configuration on one Morpho Blue market. */
13
15
  export declare class VaultMarketConfig implements IVaultMarketConfig {
14
16
  /**
15
17
  * The vault's address.
@@ -1,3 +1,4 @@
1
+ /** Represents a vault's configuration on one Morpho Blue market. */
1
2
  export class VaultMarketConfig {
2
3
  /**
3
4
  * The vault's address.
@@ -8,6 +8,7 @@ export interface IVaultMarketPublicAllocatorConfig {
8
8
  maxIn: bigint;
9
9
  maxOut: bigint;
10
10
  }
11
+ /** Represents a vault market's PublicAllocator limits. */
11
12
  export declare class VaultMarketPublicAllocatorConfig implements IVaultMarketPublicAllocatorConfig {
12
13
  /**
13
14
  * The vault's address.
@@ -1,3 +1,4 @@
1
+ /** Represents a vault market's PublicAllocator limits. */
1
2
  export class VaultMarketPublicAllocatorConfig {
2
3
  /**
3
4
  * The vault's address.
@@ -1,10 +1,12 @@
1
1
  import type { Address } from "../types.js";
2
+ /** Plain input shape for a user's MetaMorpho vault state. */
2
3
  export interface IVaultUser {
3
4
  vault: Address;
4
5
  user: Address;
5
6
  isAllocator: boolean;
6
7
  allowance: bigint;
7
8
  }
9
+ /** Represents a user's MetaMorpho vault allocator and allowance state. */
8
10
  export declare class VaultUser implements IVaultUser {
9
11
  /**
10
12
  * The vault's address.
@@ -1,3 +1,4 @@
1
+ /** Represents a user's MetaMorpho vault allocator and allowance state. */
1
2
  export class VaultUser {
2
3
  /**
3
4
  * The vault's address.
@@ -1,13 +1,62 @@
1
1
  import { type RoundingDirection } from "../math/index.js";
2
2
  import type { BigIntish } from "../types.js";
3
+ /** ERC-4626 virtual share and asset conversion helpers for MetaMorpho vaults. */
3
4
  export declare namespace VaultUtils {
5
+ /** Virtual assets added to ERC-4626 total assets in conversion formulas. */
4
6
  const VIRTUAL_ASSETS = 1n;
7
+ /**
8
+ * Returns the decimals offset between 18-decimal vault shares and an asset.
9
+ *
10
+ * @param decimals - The asset decimals.
11
+ * @returns The non-negative decimals offset.
12
+ * @example
13
+ * ```ts
14
+ * import { VaultUtils } from "@morpho-org/blue-sdk";
15
+ *
16
+ * const offset = VaultUtils.decimalsOffset(6n);
17
+ * // offset === 12n
18
+ * ```
19
+ */
5
20
  function decimalsOffset(decimals: BigIntish): bigint;
21
+ /**
22
+ * Converts vault shares to underlying assets.
23
+ *
24
+ * @param shares - The amount of vault shares.
25
+ * @param vault.totalAssets - The vault's total assets.
26
+ * @param vault.totalSupply - The vault's total share supply.
27
+ * @param vault.decimalsOffset - The vault's decimals offset.
28
+ * @param rounding - Optional rounding direction. Defaults to `"Down"`.
29
+ * @returns The equivalent amount of underlying assets.
30
+ * @example
31
+ * ```ts
32
+ * import { VaultUtils } from "@morpho-org/blue-sdk";
33
+ *
34
+ * const assets = VaultUtils.toAssets(100n, { totalAssets: 1_000n, totalSupply: 100n, decimalsOffset: 0n });
35
+ * // assets satisfies bigint
36
+ * ```
37
+ */
6
38
  function toAssets(shares: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
7
39
  totalAssets: BigIntish;
8
40
  totalSupply: BigIntish;
9
41
  decimalsOffset: BigIntish;
10
42
  }, rounding?: RoundingDirection): bigint;
43
+ /**
44
+ * Converts underlying assets to vault shares.
45
+ *
46
+ * @param assets - The amount of underlying assets.
47
+ * @param vault.totalAssets - The vault's total assets.
48
+ * @param vault.totalSupply - The vault's total share supply.
49
+ * @param vault.decimalsOffset - The vault's decimals offset.
50
+ * @param rounding - Optional rounding direction. Defaults to `"Up"`.
51
+ * @returns The equivalent amount of vault shares.
52
+ * @example
53
+ * ```ts
54
+ * import { VaultUtils } from "@morpho-org/blue-sdk";
55
+ *
56
+ * const shares = VaultUtils.toShares(100n, { totalAssets: 1_000n, totalSupply: 100n, decimalsOffset: 0n });
57
+ * // shares satisfies bigint
58
+ * ```
59
+ */
11
60
  function toShares(assets: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
12
61
  totalAssets: BigIntish;
13
62
  totalSupply: BigIntish;