@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/esm/errors.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { formatUnits } from "viem";
2
+ /** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
2
3
  export class InvalidMarketParamsError extends Error {
3
4
  data;
4
5
  constructor(data) {
@@ -6,8 +7,10 @@ export class InvalidMarketParamsError extends Error {
6
7
  this.data = data;
7
8
  }
8
9
  }
10
+ /** Base error for optional data lookups that were not available. */
9
11
  export class UnknownDataError extends Error {
10
12
  }
13
+ /** Error thrown when token metadata is unavailable for an address. */
11
14
  export class UnknownTokenError extends UnknownDataError {
12
15
  address;
13
16
  constructor(address) {
@@ -15,6 +18,7 @@ export class UnknownTokenError extends UnknownDataError {
15
18
  this.address = address;
16
19
  }
17
20
  }
21
+ /** Error thrown when a token price is unavailable for an address. */
18
22
  export class UnknownTokenPriceError extends UnknownDataError {
19
23
  address;
20
24
  constructor(address) {
@@ -22,6 +26,7 @@ export class UnknownTokenPriceError extends UnknownDataError {
22
26
  this.address = address;
23
27
  }
24
28
  }
29
+ /** Error thrown when market params are unavailable for a market id. */
25
30
  export class UnknownMarketParamsError extends UnknownDataError {
26
31
  marketId;
27
32
  constructor(marketId) {
@@ -29,6 +34,7 @@ export class UnknownMarketParamsError extends UnknownDataError {
29
34
  this.marketId = marketId;
30
35
  }
31
36
  }
37
+ /** Error thrown when vault config is unavailable for a vault address. */
32
38
  export class UnknownVaultConfigError extends UnknownDataError {
33
39
  vault;
34
40
  constructor(vault) {
@@ -36,6 +42,15 @@ export class UnknownVaultConfigError extends UnknownDataError {
36
42
  this.vault = vault;
37
43
  }
38
44
  }
45
+ /** Error thrown when a vault withdraw queue references a market without an allocation. */
46
+ export class UnknownMarketAllocationError extends UnknownDataError {
47
+ marketId;
48
+ constructor(marketId) {
49
+ super(`unknown allocation for market ${marketId}`);
50
+ this.marketId = marketId;
51
+ }
52
+ }
53
+ /** Error thrown when a chain id has no configured SDK registry entry. */
39
54
  export class UnsupportedChainIdError extends Error {
40
55
  chainId;
41
56
  constructor(chainId) {
@@ -43,6 +58,7 @@ export class UnsupportedChainIdError extends Error {
43
58
  this.chainId = chainId;
44
59
  }
45
60
  }
61
+ /** Error thrown when no default pre-liquidation params exist for an LLTV. */
46
62
  export class UnsupportedPreLiquidationParamsError extends Error {
47
63
  lltv;
48
64
  constructor(lltv) {
@@ -50,6 +66,7 @@ export class UnsupportedPreLiquidationParamsError extends Error {
50
66
  this.lltv = lltv;
51
67
  }
52
68
  }
69
+ /** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
53
70
  export class UnsupportedVaultV2AdapterError extends Error {
54
71
  address;
55
72
  constructor(address) {
@@ -57,8 +74,10 @@ export class UnsupportedVaultV2AdapterError extends Error {
57
74
  this.address = address;
58
75
  }
59
76
  }
77
+ /** Morpho Blue protocol simulation errors. */
60
78
  export var BlueErrors;
61
79
  (function (BlueErrors) {
80
+ /** Error thrown when a value that must be set once is already set. */
62
81
  class AlreadySet extends Error {
63
82
  name;
64
83
  value;
@@ -69,6 +88,7 @@ export var BlueErrors;
69
88
  }
70
89
  }
71
90
  BlueErrors.AlreadySet = AlreadySet;
91
+ /** Error thrown when market interest accrual is requested before `lastUpdate`. */
72
92
  class InvalidInterestAccrual extends Error {
73
93
  marketId;
74
94
  timestamp;
@@ -82,6 +102,7 @@ export var BlueErrors;
82
102
  }
83
103
  }
84
104
  BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
105
+ /** Error thrown when asset and share inputs describe inconsistent values. */
85
106
  class InconsistentInput extends Error {
86
107
  assets;
87
108
  shares;
@@ -92,6 +113,7 @@ export var BlueErrors;
92
113
  }
93
114
  }
94
115
  BlueErrors.InconsistentInput = InconsistentInput;
116
+ /** Error thrown when a market has insufficient liquidity for an operation. */
95
117
  class InsufficientLiquidity extends Error {
96
118
  marketId;
97
119
  constructor(marketId) {
@@ -100,6 +122,7 @@ export var BlueErrors;
100
122
  }
101
123
  }
102
124
  BlueErrors.InsufficientLiquidity = InsufficientLiquidity;
125
+ /** Error thrown when a market oracle price is unavailable. */
103
126
  class UnknownOraclePrice extends Error {
104
127
  marketId;
105
128
  constructor(marketId) {
@@ -108,6 +131,7 @@ export var BlueErrors;
108
131
  }
109
132
  }
110
133
  BlueErrors.UnknownOraclePrice = UnknownOraclePrice;
134
+ /** Error thrown when a user position is too small for an operation. */
111
135
  class InsufficientPosition extends Error {
112
136
  user;
113
137
  marketId;
@@ -118,6 +142,7 @@ export var BlueErrors;
118
142
  }
119
143
  }
120
144
  BlueErrors.InsufficientPosition = InsufficientPosition;
145
+ /** Error thrown when a user position lacks required collateral. */
121
146
  class InsufficientCollateral extends Error {
122
147
  user;
123
148
  marketId;
@@ -128,6 +153,7 @@ export var BlueErrors;
128
153
  }
129
154
  }
130
155
  BlueErrors.InsufficientCollateral = InsufficientCollateral;
156
+ /** Error thrown when a signature deadline has expired. */
131
157
  class ExpiredSignature extends Error {
132
158
  deadline;
133
159
  constructor(deadline) {
@@ -137,8 +163,10 @@ export var BlueErrors;
137
163
  }
138
164
  BlueErrors.ExpiredSignature = ExpiredSignature;
139
165
  })(BlueErrors || (BlueErrors = {}));
166
+ /** Morpho Vault V2 simulation errors. */
140
167
  export var VaultV2Errors;
141
168
  (function (VaultV2Errors) {
169
+ /** Error thrown when vault interest accrual is requested before `lastUpdate`. */
142
170
  class InvalidInterestAccrual extends Error {
143
171
  vault;
144
172
  timestamp;
@@ -152,6 +180,7 @@ export var VaultV2Errors;
152
180
  }
153
181
  }
154
182
  VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
183
+ /** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
155
184
  class UnsupportedLiquidityAdapter extends Error {
156
185
  address;
157
186
  constructor(address) {
@@ -161,11 +190,13 @@ export var VaultV2Errors;
161
190
  }
162
191
  VaultV2Errors.UnsupportedLiquidityAdapter = UnsupportedLiquidityAdapter;
163
192
  })(VaultV2Errors || (VaultV2Errors = {}));
193
+ /** Error thrown when a factory address is unavailable. */
164
194
  export class UnknownFactory extends Error {
165
195
  constructor() {
166
196
  super(`unknown factory`);
167
197
  }
168
198
  }
199
+ /** Error thrown when an address is not deployed by the expected factory. */
169
200
  export class UnknownOfFactory extends Error {
170
201
  factory;
171
202
  address;
@@ -175,6 +206,11 @@ export class UnknownOfFactory extends Error {
175
206
  this.address = address;
176
207
  }
177
208
  }
209
+ /**
210
+ * Runs an accessor and returns `undefined` for expected lookup errors.
211
+ *
212
+ * @internal
213
+ */
178
214
  export function _try(accessor, ...errorClasses) {
179
215
  const maybeCatchError = (error) => {
180
216
  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,3 +1,4 @@
1
+ /** Aggregates balances across a requested token and related peripheral tokens. */
1
2
  export class AssetBalances {
2
3
  /**
3
4
  * 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.
@@ -1,9 +1,11 @@
1
1
  import { entries, fromEntries } from "@morpho-org/morpho-ts";
2
+ /** Address registry labels that may receive ERC-20 allowances from a user. */
2
3
  export const ERC20_ALLOWANCE_RECIPIENTS = [
3
4
  "morpho",
4
5
  "permit2",
5
6
  "bundler3.generalAdapter1",
6
7
  ];
8
+ /** Represents a user's balance and allowance state for one token. */
7
9
  export class Holding {
8
10
  /**
9
11
  * 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 [{
@@ -2,6 +2,7 @@ import { ZERO_ADDRESS } from "@morpho-org/morpho-ts";
2
2
  import { decodeAbiParameters } from "viem";
3
3
  import { InvalidMarketParamsError, UnknownMarketParamsError, } from "../errors.js";
4
4
  import { MarketUtils } from "./MarketUtils.js";
5
+ /** ABI tuple definition for Morpho Blue market params. */
5
6
  export const marketParamsAbi = {
6
7
  type: "tuple",
7
8
  components: [