@morpho-org/blue-sdk 6.0.1 → 6.2.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 +225 -0
  2. package/lib/cjs/addresses.js +140 -0
  3. package/lib/cjs/chain.d.ts +108 -1
  4. package/lib/cjs/chain.js +94 -0
  5. package/lib/cjs/errors.d.ts +39 -0
  6. package/lib/cjs/errors.js +38 -1
  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 +52 -2
  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 +9 -0
  47. package/lib/cjs/vault/Vault.js +14 -1
  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 +51 -2
  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 +3 -1
  66. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  67. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
  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 +225 -0
  71. package/lib/esm/addresses.js +140 -0
  72. package/lib/esm/chain.d.ts +108 -1
  73. package/lib/esm/chain.js +94 -0
  74. package/lib/esm/errors.d.ts +39 -0
  75. package/lib/esm/errors.js +36 -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 +52 -2
  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 +9 -0
  116. package/lib/esm/vault/Vault.js +14 -1
  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 +51 -2
  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 +3 -1
  135. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  136. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
  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 +4 -4
package/lib/cjs/chain.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ChainUtils = exports.ChainId = void 0;
4
+ /** Supported EIP-155 chain ids with Morpho Blue deployments or registry metadata. */
4
5
  var ChainId;
5
6
  (function (ChainId) {
6
7
  ChainId[ChainId["EthMainnet"] = 1] = "EthMainnet";
@@ -42,25 +43,97 @@ var ChainId;
42
43
  ChainId[ChainId["FlareMainnet"] = 14] = "FlareMainnet";
43
44
  ChainId[ChainId["XdcMainnet"] = 50] = "XdcMainnet";
44
45
  ChainId[ChainId["KaiaMainnet"] = 8217] = "KaiaMainnet";
46
+ ChainId[ChainId["ArcMainnet"] = 5042] = "ArcMainnet";
47
+ ChainId[ChainId["MorphMainnet"] = 2818] = "MorphMainnet";
48
+ ChainId[ChainId["MegaEthMainnet"] = 4326] = "MegaEthMainnet";
45
49
  })(ChainId || (exports.ChainId = ChainId = {}));
50
+ /** Chain metadata helpers and registries. */
46
51
  var ChainUtils;
47
52
  (function (ChainUtils) {
53
+ /**
54
+ * Returns whether native token balances are reliable on a chain.
55
+ *
56
+ * @param chainId - The EIP-155 chain id to inspect.
57
+ * @returns `false` only for chains whose metadata marks native balances as unreliable.
58
+ * @example
59
+ * ```ts
60
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
61
+ *
62
+ * const reliable = ChainUtils.hasReliableNativeBalance(ChainId.EthMainnet);
63
+ * // reliable === true
64
+ * ```
65
+ */
48
66
  ChainUtils.hasReliableNativeBalance = (chainId) => {
49
67
  return (ChainUtils.CHAIN_METADATA[chainId]
50
68
  ?.hasReliableNativeBalance ?? true);
51
69
  };
70
+ /**
71
+ * Converts a supported chain id to its hexadecimal JSON-RPC form.
72
+ *
73
+ * @param chainId - The supported chain id.
74
+ * @returns The chain id as a `0x`-prefixed hexadecimal string.
75
+ * @example
76
+ * ```ts
77
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
78
+ *
79
+ * const hexChainId = ChainUtils.toHexChainId(ChainId.EthMainnet);
80
+ * // hexChainId === "0x1"
81
+ * ```
82
+ */
52
83
  ChainUtils.toHexChainId = (chainId) => {
53
84
  return `0x${chainId.toString(16)}`;
54
85
  };
86
+ /**
87
+ * Returns the block explorer base URL for a supported chain.
88
+ *
89
+ * @param chainId - The supported chain id.
90
+ * @returns The chain's configured block explorer base URL.
91
+ * @example
92
+ * ```ts
93
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
94
+ *
95
+ * const explorerUrl = ChainUtils.getExplorerUrl(ChainId.EthMainnet);
96
+ * // explorerUrl === "https://etherscan.io"
97
+ * ```
98
+ */
55
99
  ChainUtils.getExplorerUrl = (chainId) => {
56
100
  return ChainUtils.CHAIN_METADATA[chainId].explorerUrl;
57
101
  };
102
+ /**
103
+ * Returns a block explorer address URL for a supported chain.
104
+ *
105
+ * @param chainId - The supported chain id.
106
+ * @param address - The address to link to.
107
+ * @returns The block explorer URL for `address`.
108
+ * @example
109
+ * ```ts
110
+ * import { ChainId, ChainUtils, NATIVE_ADDRESS } from "@morpho-org/blue-sdk";
111
+ *
112
+ * const url = ChainUtils.getExplorerAddressUrl(ChainId.EthMainnet, NATIVE_ADDRESS);
113
+ * // url satisfies string
114
+ * ```
115
+ */
58
116
  ChainUtils.getExplorerAddressUrl = (chainId, address) => {
59
117
  return `${ChainUtils.getExplorerUrl(chainId)}/address/${address}`;
60
118
  };
119
+ /**
120
+ * Returns a block explorer transaction URL for a supported chain.
121
+ *
122
+ * @param chainId - The supported chain id.
123
+ * @param tx - The transaction hash to link to.
124
+ * @returns The block explorer URL for `tx`.
125
+ * @example
126
+ * ```ts
127
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
128
+ *
129
+ * const url = ChainUtils.getExplorerTransactionUrl(ChainId.EthMainnet, "0xabc");
130
+ * // url satisfies string
131
+ * ```
132
+ */
61
133
  ChainUtils.getExplorerTransactionUrl = (chainId, tx) => {
62
134
  return `${ChainUtils.getExplorerUrl(chainId)}/tx/${tx}`;
63
135
  };
136
+ /** Metadata for each supported chain, keyed by `ChainId`. */
64
137
  ChainUtils.CHAIN_METADATA = {
65
138
  [ChainId.EthMainnet]: {
66
139
  name: "Ethereum",
@@ -336,5 +409,26 @@ var ChainUtils;
336
409
  explorerUrl: "https://kaiascan.io",
337
410
  identifier: "kaia",
338
411
  },
412
+ [ChainId.ArcMainnet]: {
413
+ name: "Arc",
414
+ id: ChainId.ArcMainnet,
415
+ nativeCurrency: { name: "USDC", symbol: "USDC", decimals: 18 },
416
+ explorerUrl: "http://explorer.arc.io/",
417
+ identifier: "arc",
418
+ },
419
+ [ChainId.MorphMainnet]: {
420
+ name: "Morph",
421
+ id: ChainId.MorphMainnet,
422
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
423
+ explorerUrl: "https://explorer.morphl2.io",
424
+ identifier: "morph",
425
+ },
426
+ [ChainId.MegaEthMainnet]: {
427
+ name: "MegaETH",
428
+ id: ChainId.MegaEthMainnet,
429
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
430
+ explorerUrl: "https://mega.etherscan.io",
431
+ identifier: "megaeth",
432
+ },
339
433
  };
340
434
  })(ChainUtils || (exports.ChainUtils = ChainUtils = {}));
@@ -1,101 +1,140 @@
1
1
  import { type Hex } from "viem";
2
2
  import type { Address, MarketId } from "./types.js";
3
+ /** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
3
4
  export declare class InvalidMarketParamsError extends Error {
4
5
  readonly data: Hex;
5
6
  constructor(data: Hex);
6
7
  }
8
+ /** Base error for optional data lookups that were not available. */
7
9
  export declare class UnknownDataError extends Error {
8
10
  }
11
+ /** Error thrown when token metadata is unavailable for an address. */
9
12
  export declare class UnknownTokenError extends UnknownDataError {
10
13
  readonly address: Address;
11
14
  constructor(address: Address);
12
15
  }
16
+ /** Error thrown when a token price is unavailable for an address. */
13
17
  export declare class UnknownTokenPriceError extends UnknownDataError {
14
18
  readonly address: Address;
15
19
  constructor(address: Address);
16
20
  }
21
+ /** Error thrown when market params are unavailable for a market id. */
17
22
  export declare class UnknownMarketParamsError extends UnknownDataError {
18
23
  readonly marketId: MarketId;
19
24
  constructor(marketId: MarketId);
20
25
  }
26
+ /** Error thrown when vault config is unavailable for a vault address. */
21
27
  export declare class UnknownVaultConfigError extends UnknownDataError {
22
28
  readonly vault: Address;
23
29
  constructor(vault: Address);
24
30
  }
31
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
32
+ export declare class UnknownMarketAllocationError extends UnknownDataError {
33
+ readonly marketId: MarketId;
34
+ constructor(marketId: MarketId);
35
+ }
36
+ /** Error thrown when a chain id has no configured SDK registry entry. */
25
37
  export declare class UnsupportedChainIdError extends Error {
26
38
  readonly chainId: number;
27
39
  constructor(chainId: number);
28
40
  }
41
+ /** Error thrown when no default pre-liquidation params exist for an LLTV. */
29
42
  export declare class UnsupportedPreLiquidationParamsError extends Error {
30
43
  readonly lltv: bigint;
31
44
  constructor(lltv: bigint);
32
45
  }
46
+ /** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
33
47
  export declare class UnsupportedVaultV2AdapterError extends Error {
34
48
  readonly address: Address;
35
49
  constructor(address: Address);
36
50
  }
51
+ /** Morpho Blue protocol simulation errors. */
37
52
  export declare namespace BlueErrors {
53
+ /** Error thrown when a value that must be set once is already set. */
38
54
  class AlreadySet extends Error {
39
55
  readonly name: string;
40
56
  readonly value: string;
41
57
  constructor(name: string, value: string);
42
58
  }
59
+ /** Error thrown when market interest accrual is requested before `lastUpdate`. */
43
60
  class InvalidInterestAccrual extends Error {
44
61
  readonly marketId: MarketId;
45
62
  readonly timestamp: bigint;
46
63
  readonly lastUpdate: bigint;
47
64
  constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
48
65
  }
66
+ /** Error thrown when asset and share inputs describe inconsistent values. */
49
67
  class InconsistentInput extends Error {
50
68
  readonly assets: bigint;
51
69
  readonly shares: bigint;
52
70
  constructor(assets: bigint, shares: bigint);
53
71
  }
72
+ /** Error thrown when a market has insufficient liquidity for an operation. */
54
73
  class InsufficientLiquidity extends Error {
55
74
  readonly marketId: MarketId;
56
75
  constructor(marketId: MarketId);
57
76
  }
77
+ /** Error thrown when a market oracle price is unavailable. */
58
78
  class UnknownOraclePrice extends Error {
59
79
  readonly marketId: MarketId;
60
80
  constructor(marketId: MarketId);
61
81
  }
82
+ /** Error thrown when a user position is too small for an operation. */
62
83
  class InsufficientPosition extends Error {
63
84
  readonly user: Address;
64
85
  readonly marketId: MarketId;
65
86
  constructor(user: Address, marketId: MarketId);
66
87
  }
88
+ /** Error thrown when a user position lacks required collateral. */
67
89
  class InsufficientCollateral extends Error {
68
90
  readonly user: Address;
69
91
  readonly marketId: MarketId;
70
92
  constructor(user: Address, marketId: MarketId);
71
93
  }
94
+ /** Error thrown when a signature deadline has expired. */
72
95
  class ExpiredSignature extends Error {
73
96
  readonly deadline: bigint;
74
97
  constructor(deadline: bigint);
75
98
  }
76
99
  }
100
+ /** Morpho Vault V2 simulation errors. */
77
101
  export declare namespace VaultV2Errors {
102
+ /** Error thrown when vault interest accrual is requested before `lastUpdate`. */
78
103
  class InvalidInterestAccrual extends Error {
79
104
  readonly vault: Address;
80
105
  readonly timestamp: bigint;
81
106
  readonly lastUpdate: bigint;
82
107
  constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
83
108
  }
109
+ /** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
84
110
  class UnsupportedLiquidityAdapter extends Error {
85
111
  readonly address: Address;
86
112
  constructor(address: Address);
87
113
  }
88
114
  }
115
+ /** Error thrown when a factory address is unavailable. */
89
116
  export declare class UnknownFactory extends Error {
90
117
  constructor();
91
118
  }
119
+ /** Error thrown when an address is not deployed by the expected factory. */
92
120
  export declare class UnknownOfFactory extends Error {
93
121
  readonly factory: Address;
94
122
  readonly address: Address;
95
123
  constructor(factory: Address, address: Address);
96
124
  }
125
+ /** Constructor type for errors accepted by `_try`. */
97
126
  export interface ErrorClass<E extends Error = Error> {
98
127
  new (...args: any[]): E;
99
128
  }
129
+ /**
130
+ * Runs an async accessor and returns `undefined` for expected lookup errors.
131
+ *
132
+ * @internal
133
+ */
100
134
  export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => Promise<T>, ...errorClasses: ErrorClasses): Promise<T | undefined>;
135
+ /**
136
+ * Runs a sync accessor and returns `undefined` for expected lookup errors.
137
+ *
138
+ * @internal
139
+ */
101
140
  export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => T, ...errorClasses: ErrorClasses): T | undefined;
package/lib/cjs/errors.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnknownOfFactory = exports.UnknownFactory = exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
3
+ exports.UnknownOfFactory = exports.UnknownFactory = exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownMarketAllocationError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
4
4
  exports._try = _try;
5
5
  const viem_1 = require("viem");
6
+ /** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
6
7
  class InvalidMarketParamsError extends Error {
7
8
  data;
8
9
  constructor(data) {
@@ -11,9 +12,11 @@ class InvalidMarketParamsError extends Error {
11
12
  }
12
13
  }
13
14
  exports.InvalidMarketParamsError = InvalidMarketParamsError;
15
+ /** Base error for optional data lookups that were not available. */
14
16
  class UnknownDataError extends Error {
15
17
  }
16
18
  exports.UnknownDataError = UnknownDataError;
19
+ /** Error thrown when token metadata is unavailable for an address. */
17
20
  class UnknownTokenError extends UnknownDataError {
18
21
  address;
19
22
  constructor(address) {
@@ -22,6 +25,7 @@ class UnknownTokenError extends UnknownDataError {
22
25
  }
23
26
  }
24
27
  exports.UnknownTokenError = UnknownTokenError;
28
+ /** Error thrown when a token price is unavailable for an address. */
25
29
  class UnknownTokenPriceError extends UnknownDataError {
26
30
  address;
27
31
  constructor(address) {
@@ -30,6 +34,7 @@ class UnknownTokenPriceError extends UnknownDataError {
30
34
  }
31
35
  }
32
36
  exports.UnknownTokenPriceError = UnknownTokenPriceError;
37
+ /** Error thrown when market params are unavailable for a market id. */
33
38
  class UnknownMarketParamsError extends UnknownDataError {
34
39
  marketId;
35
40
  constructor(marketId) {
@@ -38,6 +43,7 @@ class UnknownMarketParamsError extends UnknownDataError {
38
43
  }
39
44
  }
40
45
  exports.UnknownMarketParamsError = UnknownMarketParamsError;
46
+ /** Error thrown when vault config is unavailable for a vault address. */
41
47
  class UnknownVaultConfigError extends UnknownDataError {
42
48
  vault;
43
49
  constructor(vault) {
@@ -46,6 +52,16 @@ class UnknownVaultConfigError extends UnknownDataError {
46
52
  }
47
53
  }
48
54
  exports.UnknownVaultConfigError = UnknownVaultConfigError;
55
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
56
+ class UnknownMarketAllocationError extends UnknownDataError {
57
+ marketId;
58
+ constructor(marketId) {
59
+ super(`unknown allocation for market ${marketId}`);
60
+ this.marketId = marketId;
61
+ }
62
+ }
63
+ exports.UnknownMarketAllocationError = UnknownMarketAllocationError;
64
+ /** Error thrown when a chain id has no configured SDK registry entry. */
49
65
  class UnsupportedChainIdError extends Error {
50
66
  chainId;
51
67
  constructor(chainId) {
@@ -54,6 +70,7 @@ class UnsupportedChainIdError extends Error {
54
70
  }
55
71
  }
56
72
  exports.UnsupportedChainIdError = UnsupportedChainIdError;
73
+ /** Error thrown when no default pre-liquidation params exist for an LLTV. */
57
74
  class UnsupportedPreLiquidationParamsError extends Error {
58
75
  lltv;
59
76
  constructor(lltv) {
@@ -62,6 +79,7 @@ class UnsupportedPreLiquidationParamsError extends Error {
62
79
  }
63
80
  }
64
81
  exports.UnsupportedPreLiquidationParamsError = UnsupportedPreLiquidationParamsError;
82
+ /** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
65
83
  class UnsupportedVaultV2AdapterError extends Error {
66
84
  address;
67
85
  constructor(address) {
@@ -70,8 +88,10 @@ class UnsupportedVaultV2AdapterError extends Error {
70
88
  }
71
89
  }
72
90
  exports.UnsupportedVaultV2AdapterError = UnsupportedVaultV2AdapterError;
91
+ /** Morpho Blue protocol simulation errors. */
73
92
  var BlueErrors;
74
93
  (function (BlueErrors) {
94
+ /** Error thrown when a value that must be set once is already set. */
75
95
  class AlreadySet extends Error {
76
96
  name;
77
97
  value;
@@ -82,6 +102,7 @@ var BlueErrors;
82
102
  }
83
103
  }
84
104
  BlueErrors.AlreadySet = AlreadySet;
105
+ /** Error thrown when market interest accrual is requested before `lastUpdate`. */
85
106
  class InvalidInterestAccrual extends Error {
86
107
  marketId;
87
108
  timestamp;
@@ -95,6 +116,7 @@ var BlueErrors;
95
116
  }
96
117
  }
97
118
  BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
119
+ /** Error thrown when asset and share inputs describe inconsistent values. */
98
120
  class InconsistentInput extends Error {
99
121
  assets;
100
122
  shares;
@@ -105,6 +127,7 @@ var BlueErrors;
105
127
  }
106
128
  }
107
129
  BlueErrors.InconsistentInput = InconsistentInput;
130
+ /** Error thrown when a market has insufficient liquidity for an operation. */
108
131
  class InsufficientLiquidity extends Error {
109
132
  marketId;
110
133
  constructor(marketId) {
@@ -113,6 +136,7 @@ var BlueErrors;
113
136
  }
114
137
  }
115
138
  BlueErrors.InsufficientLiquidity = InsufficientLiquidity;
139
+ /** Error thrown when a market oracle price is unavailable. */
116
140
  class UnknownOraclePrice extends Error {
117
141
  marketId;
118
142
  constructor(marketId) {
@@ -121,6 +145,7 @@ var BlueErrors;
121
145
  }
122
146
  }
123
147
  BlueErrors.UnknownOraclePrice = UnknownOraclePrice;
148
+ /** Error thrown when a user position is too small for an operation. */
124
149
  class InsufficientPosition extends Error {
125
150
  user;
126
151
  marketId;
@@ -131,6 +156,7 @@ var BlueErrors;
131
156
  }
132
157
  }
133
158
  BlueErrors.InsufficientPosition = InsufficientPosition;
159
+ /** Error thrown when a user position lacks required collateral. */
134
160
  class InsufficientCollateral extends Error {
135
161
  user;
136
162
  marketId;
@@ -141,6 +167,7 @@ var BlueErrors;
141
167
  }
142
168
  }
143
169
  BlueErrors.InsufficientCollateral = InsufficientCollateral;
170
+ /** Error thrown when a signature deadline has expired. */
144
171
  class ExpiredSignature extends Error {
145
172
  deadline;
146
173
  constructor(deadline) {
@@ -150,8 +177,10 @@ var BlueErrors;
150
177
  }
151
178
  BlueErrors.ExpiredSignature = ExpiredSignature;
152
179
  })(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
180
+ /** Morpho Vault V2 simulation errors. */
153
181
  var VaultV2Errors;
154
182
  (function (VaultV2Errors) {
183
+ /** Error thrown when vault interest accrual is requested before `lastUpdate`. */
155
184
  class InvalidInterestAccrual extends Error {
156
185
  vault;
157
186
  timestamp;
@@ -165,6 +194,7 @@ var VaultV2Errors;
165
194
  }
166
195
  }
167
196
  VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
197
+ /** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
168
198
  class UnsupportedLiquidityAdapter extends Error {
169
199
  address;
170
200
  constructor(address) {
@@ -174,12 +204,14 @@ var VaultV2Errors;
174
204
  }
175
205
  VaultV2Errors.UnsupportedLiquidityAdapter = UnsupportedLiquidityAdapter;
176
206
  })(VaultV2Errors || (exports.VaultV2Errors = VaultV2Errors = {}));
207
+ /** Error thrown when a factory address is unavailable. */
177
208
  class UnknownFactory extends Error {
178
209
  constructor() {
179
210
  super(`unknown factory`);
180
211
  }
181
212
  }
182
213
  exports.UnknownFactory = UnknownFactory;
214
+ /** Error thrown when an address is not deployed by the expected factory. */
183
215
  class UnknownOfFactory extends Error {
184
216
  factory;
185
217
  address;
@@ -190,6 +222,11 @@ class UnknownOfFactory extends Error {
190
222
  }
191
223
  }
192
224
  exports.UnknownOfFactory = UnknownOfFactory;
225
+ /**
226
+ * Runs an accessor and returns `undefined` for expected lookup errors.
227
+ *
228
+ * @internal
229
+ */
193
230
  function _try(accessor, ...errorClasses) {
194
231
  const maybeCatchError = (error) => {
195
232
  if (errorClasses.length === 0 ||
@@ -1,4 +1,5 @@
1
1
  import type { Token } from "../token/Token.js";
2
+ /** Balance conversion category for a requested token and related peripheral tokens. */
2
3
  export type PeripheralBalanceType = "base" | "wrapped" | "staked-wrapped" | "vault" | "wrapped-vault" | "unwrapped-staked-wrapped";
3
4
  /**
4
5
  * Represents the balance of a requested token and the balance quoted in the corresponding source token:
@@ -27,8 +28,10 @@ export interface PeripheralBalance {
27
28
  */
28
29
  dstAmount: bigint;
29
30
  }
31
+ /** Constructor input for `AssetBalances`. */
30
32
  export interface IAssetBalances extends Omit<PeripheralBalance, "type"> {
31
33
  }
34
+ /** Aggregates balances across a requested token and related peripheral tokens. */
32
35
  export declare class AssetBalances {
33
36
  /**
34
37
  * The total balance of all types of related tokens.
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetBalances = void 0;
4
+ /** Aggregates balances across a requested token and related peripheral tokens. */
4
5
  class AssetBalances {
5
6
  /**
6
7
  * The total balance of all types of related tokens.
@@ -1,16 +1,21 @@
1
1
  import type { Address, BigIntish } from "../types.js";
2
+ /** Address registry labels that may receive ERC-20 allowances from a user. */
2
3
  export declare const ERC20_ALLOWANCE_RECIPIENTS: readonly ["morpho", "permit2", "bundler3.generalAdapter1"];
4
+ /** Address registry label that may receive an ERC-20 allowance from a user. */
3
5
  export type Erc20AllowanceRecipient = (typeof ERC20_ALLOWANCE_RECIPIENTS)[number];
6
+ /** Normalized Permit2 allowance values. */
4
7
  export interface Permit2Allowance {
5
8
  amount: bigint;
6
9
  expiration: bigint;
7
10
  nonce: bigint;
8
11
  }
12
+ /** Input shape for Permit2 allowance values before bigint normalization. */
9
13
  export interface IPermit2Allowance {
10
14
  amount: BigIntish;
11
15
  expiration: BigIntish;
12
16
  nonce: BigIntish;
13
17
  }
18
+ /** Input shape for a user's token holding and allowance state. */
14
19
  export interface IHolding {
15
20
  user: Address;
16
21
  token: Address;
@@ -22,6 +27,7 @@ export interface IHolding {
22
27
  canTransfer?: boolean;
23
28
  balance: bigint;
24
29
  }
30
+ /** Represents a user's balance and allowance state for one token. */
25
31
  export declare class Holding implements IHolding {
26
32
  /**
27
33
  * The user of this holding.
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Holding = exports.ERC20_ALLOWANCE_RECIPIENTS = void 0;
4
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ /** Address registry labels that may receive ERC-20 allowances from a user. */
5
6
  exports.ERC20_ALLOWANCE_RECIPIENTS = [
6
7
  "morpho",
7
8
  "permit2",
8
9
  "bundler3.generalAdapter1",
9
10
  ];
11
+ /** Represents a user's balance and allowance state for one token. */
10
12
  class Holding {
11
13
  /**
12
14
  * The user of this holding.
@@ -2,12 +2,15 @@ import { type RoundingDirection } from "../math/index.js";
2
2
  import type { BigIntish } from "../types.js";
3
3
  import { type CapacityLimit } from "../utils.js";
4
4
  import { type IMarketParams, MarketParams } from "./MarketParams.js";
5
+ /** Options for max borrow capacity calculations. */
5
6
  export interface MaxBorrowOptions {
6
7
  maxLtv?: bigint;
7
8
  }
9
+ /** Options for max withdraw collateral capacity calculations. */
8
10
  export interface MaxWithdrawCollateralOptions {
9
11
  maxLtv?: bigint;
10
12
  }
13
+ /** Capacity limits for each market operation available to a position. */
11
14
  export interface MaxPositionCapacities {
12
15
  supply: CapacityLimit;
13
16
  withdraw: CapacityLimit;
@@ -16,6 +19,7 @@ export interface MaxPositionCapacities {
16
19
  supplyCollateral: CapacityLimit;
17
20
  withdrawCollateral: CapacityLimit | undefined;
18
21
  }
22
+ /** Plain input shape for a Morpho Blue market. */
19
23
  export interface IMarket {
20
24
  params: IMarketParams;
21
25
  totalSupplyAssets: bigint;
@@ -1,5 +1,6 @@
1
1
  import { type Hex } from "viem";
2
2
  import type { Address, BigIntish, MarketId } from "../types.js";
3
+ /** Plain input shape for Morpho Blue market params. */
3
4
  export interface IMarketParams {
4
5
  loanToken: Address;
5
6
  collateralToken: Address;
@@ -7,7 +8,9 @@ export interface IMarketParams {
7
8
  irm: Address;
8
9
  lltv: BigIntish;
9
10
  }
11
+ /** Minimal market params shape accepted by SDK constructors and helpers. */
10
12
  export type InputMarketParams = Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
13
+ /** ABI tuple definition for Morpho Blue market params. */
11
14
  export declare const marketParamsAbi: {
12
15
  readonly type: "tuple";
13
16
  readonly components: readonly [{
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
5
  const viem_1 = require("viem");
6
6
  const errors_js_1 = require("../errors.js");
7
7
  const MarketUtils_js_1 = require("./MarketUtils.js");
8
+ /** ABI tuple definition for Morpho Blue market params. */
8
9
  exports.marketParamsAbi = {
9
10
  type: "tuple",
10
11
  components: [