@morpho-org/blue-sdk 2.0.0-alpha.6 → 2.0.0-next.2

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -21
  3. package/lib/addresses.d.ts +58 -54
  4. package/lib/addresses.js +60 -66
  5. package/lib/chain.d.ts +1 -1
  6. package/lib/chain.js +7 -10
  7. package/lib/constants.js +9 -12
  8. package/lib/errors.d.ts +1 -1
  9. package/lib/errors.js +9 -19
  10. package/lib/holding/AssetBalances.d.ts +1 -1
  11. package/lib/holding/AssetBalances.js +1 -5
  12. package/lib/holding/Holding.d.ts +1 -1
  13. package/lib/holding/Holding.js +5 -9
  14. package/lib/holding/index.d.ts +2 -2
  15. package/lib/holding/index.js +2 -18
  16. package/lib/index.d.ts +12 -23
  17. package/lib/index.js +12 -52
  18. package/lib/market/Market.d.ts +8 -6
  19. package/lib/market/Market.js +51 -53
  20. package/lib/market/MarketConfig.d.ts +1 -1
  21. package/lib/market/MarketConfig.js +10 -13
  22. package/lib/market/MarketUtils.d.ts +8 -7
  23. package/lib/market/MarketUtils.js +48 -54
  24. package/lib/market/index.d.ts +3 -3
  25. package/lib/market/index.js +3 -19
  26. package/lib/{maths → math}/AdaptiveCurveIrmLib.d.ts +1 -1
  27. package/lib/{maths → math}/AdaptiveCurveIrmLib.js +22 -25
  28. package/lib/{maths → math}/MathLib.d.ts +25 -28
  29. package/lib/{maths → math}/MathLib.js +51 -40
  30. package/lib/{maths → math}/SharesMath.d.ts +2 -2
  31. package/lib/{maths → math}/SharesMath.js +5 -8
  32. package/lib/math/index.d.ts +3 -0
  33. package/lib/math/index.js +3 -0
  34. package/lib/position/Position.d.ts +11 -10
  35. package/lib/position/Position.js +15 -19
  36. package/lib/position/index.d.ts +1 -1
  37. package/lib/position/index.js +1 -17
  38. package/lib/token/ConstantWrappedToken.d.ts +4 -4
  39. package/lib/token/ConstantWrappedToken.js +5 -9
  40. package/lib/token/ExchangeRateWrappedToken.d.ts +4 -4
  41. package/lib/token/ExchangeRateWrappedToken.js +5 -9
  42. package/lib/token/Token.d.ts +3 -3
  43. package/lib/token/Token.js +9 -14
  44. package/lib/token/VaultToken.d.ts +20 -11
  45. package/lib/token/VaultToken.js +14 -10
  46. package/lib/token/WrappedToken.d.ts +3 -3
  47. package/lib/token/WrappedToken.js +7 -11
  48. package/lib/token/index.d.ts +5 -5
  49. package/lib/token/index.js +5 -21
  50. package/lib/types.d.ts +1 -1
  51. package/lib/types.js +4 -9
  52. package/lib/user/User.d.ts +1 -1
  53. package/lib/user/User.js +1 -5
  54. package/lib/user/index.d.ts +1 -1
  55. package/lib/user/index.js +1 -17
  56. package/lib/vault/Vault.d.ts +8 -22
  57. package/lib/vault/Vault.js +38 -51
  58. package/lib/vault/VaultConfig.d.ts +2 -2
  59. package/lib/vault/VaultConfig.js +3 -7
  60. package/lib/vault/VaultMarketAllocation.d.ts +3 -3
  61. package/lib/vault/VaultMarketAllocation.js +4 -8
  62. package/lib/vault/VaultMarketConfig.d.ts +3 -3
  63. package/lib/vault/VaultMarketConfig.js +1 -5
  64. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -1
  65. package/lib/vault/VaultMarketPublicAllocatorConfig.js +1 -5
  66. package/lib/vault/VaultUser.d.ts +1 -1
  67. package/lib/vault/VaultUser.js +1 -5
  68. package/lib/vault/VaultUtils.d.ts +4 -6
  69. package/lib/vault/VaultUtils.js +8 -11
  70. package/lib/vault/index.d.ts +7 -7
  71. package/lib/vault/index.js +7 -23
  72. package/package.json +46 -33
  73. package/lib/helpers/format/format.d.ts +0 -122
  74. package/lib/helpers/format/format.js +0 -286
  75. package/lib/helpers/locale.d.ts +0 -46
  76. package/lib/helpers/locale.js +0 -96
  77. package/lib/maths/index.d.ts +0 -3
  78. package/lib/maths/index.js +0 -19
  79. package/lib/tests/mocks/markets.d.ts +0 -19
  80. package/lib/tests/mocks/markets.js +0 -121
@@ -1,6 +1,6 @@
1
- import { RoundingDirection } from "../maths";
2
- import { Address } from "../types";
3
- import { InputToken, Token } from "./Token";
1
+ import { type RoundingDirection } from "../math/index.js";
2
+ import type { Address } from "../types.js";
3
+ import { type InputToken, Token } from "./Token.js";
4
4
  export declare abstract class WrappedToken extends Token {
5
5
  readonly underlying: Address;
6
6
  constructor(token: InputToken, underlying: Address);
@@ -1,9 +1,6 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WrappedToken = void 0;
4
- const maths_1 = require("../maths");
5
- const Token_1 = require("./Token");
6
- class WrappedToken extends Token_1.Token {
1
+ import { MathLib } from "../math/index.js";
2
+ import { Token } from "./Token.js";
3
+ export class WrappedToken extends Token {
7
4
  underlying;
8
5
  constructor(token, underlying) {
9
6
  super(token);
@@ -12,22 +9,21 @@ class WrappedToken extends Token_1.Token {
12
9
  /** The expected amount when wrapping `unwrappedAmount` */
13
10
  toWrappedExactAmountIn(unwrappedAmount, slippage = 0n, rounding = "Down") {
14
11
  const wrappedAmount = this._wrap(unwrappedAmount, rounding);
15
- return maths_1.MathLib.wMul(wrappedAmount, maths_1.MathLib.WAD - slippage, "Down");
12
+ return MathLib.wMul(wrappedAmount, MathLib.WAD - slippage, "Down");
16
13
  }
17
14
  /** The amount of unwrappedTokens that should be wrapped to receive `wrappedAmount` */
18
15
  toWrappedExactAmountOut(wrappedAmount, slippage = 0n, rounding = "Up") {
19
- const wAmountTarget = maths_1.MathLib.wDiv(wrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
16
+ const wAmountTarget = MathLib.wDiv(wrappedAmount, MathLib.WAD - slippage, rounding);
20
17
  return this._unwrap(wAmountTarget, rounding);
21
18
  }
22
19
  /** The expected amount when unwrapping `wrappedAmount` */
23
20
  toUnwrappedExactAmountIn(wrappedAmount, slippage = 0n, rounding = "Down") {
24
21
  const unwrappedAmount = this._unwrap(wrappedAmount, rounding);
25
- return maths_1.MathLib.wMul(unwrappedAmount, maths_1.MathLib.WAD - slippage, "Up");
22
+ return MathLib.wMul(unwrappedAmount, MathLib.WAD - slippage, "Up");
26
23
  }
27
24
  /** The amount of wrappedTokens that should be unwrapped to receive `unwrappedAmount` */
28
25
  toUnwrappedExactAmountOut(unwrappedAmount, slippage = 0n, rounding = "Up") {
29
- const unwrappedAmountToTarget = maths_1.MathLib.wDiv(unwrappedAmount, maths_1.MathLib.WAD - slippage, rounding);
26
+ const unwrappedAmountToTarget = MathLib.wDiv(unwrappedAmount, MathLib.WAD - slippage, rounding);
30
27
  return this._wrap(unwrappedAmountToTarget, rounding);
31
28
  }
32
29
  }
33
- exports.WrappedToken = WrappedToken;
@@ -1,5 +1,5 @@
1
- export * from "./Token";
2
- export * from "./WrappedToken";
3
- export * from "./ConstantWrappedToken";
4
- export * from "./ExchangeRateWrappedToken";
5
- export * from "./VaultToken";
1
+ export * from "./Token.js";
2
+ export * from "./WrappedToken.js";
3
+ export * from "./ConstantWrappedToken.js";
4
+ export * from "./ExchangeRateWrappedToken.js";
5
+ export * from "./VaultToken.js";
@@ -1,21 +1,5 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./Token"), exports);
18
- __exportStar(require("./WrappedToken"), exports);
19
- __exportStar(require("./ConstantWrappedToken"), exports);
20
- __exportStar(require("./ExchangeRateWrappedToken"), exports);
21
- __exportStar(require("./VaultToken"), exports);
1
+ export * from "./Token.js";
2
+ export * from "./WrappedToken.js";
3
+ export * from "./ConstantWrappedToken.js";
4
+ export * from "./ExchangeRateWrappedToken.js";
5
+ export * from "./VaultToken.js";
package/lib/types.d.ts CHANGED
@@ -24,4 +24,4 @@ export type Loadable<T> = T | undefined;
24
24
  export type Failable<T> = T | null;
25
25
  export type Fetchable<T> = Failable<Loadable<T>>;
26
26
  export declare function isFetched<T>(v: Fetchable<T>): v is T;
27
- export declare const isMarketId: (value: any) => value is MarketId;
27
+ export declare const isMarketId: (value: unknown) => value is MarketId;
package/lib/types.js CHANGED
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isMarketId = exports.TransactionType = void 0;
4
- exports.isFetched = isFetched;
5
1
  /**
6
2
  * The possible transaction type on the Blue contract
7
3
  */
8
- var TransactionType;
4
+ export var TransactionType;
9
5
  (function (TransactionType) {
10
6
  TransactionType["Supply"] = "Supply";
11
7
  TransactionType["SupplyCollateral"] = "Supply Collateral";
@@ -13,10 +9,9 @@ var TransactionType;
13
9
  TransactionType["WithdrawCollateral"] = "Withdraw Collateral";
14
10
  TransactionType["Borrow"] = "Borrow";
15
11
  TransactionType["Repay"] = "Repay";
16
- })(TransactionType || (exports.TransactionType = TransactionType = {}));
12
+ })(TransactionType || (TransactionType = {}));
17
13
  // TODO: replace with isDefined
18
- function isFetched(v) {
14
+ export function isFetched(v) {
19
15
  return v !== undefined && v !== null;
20
16
  }
21
- const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
22
- exports.isMarketId = isMarketId;
17
+ export const isMarketId = (value) => typeof value === "string" && /^0x[0-9A-Fa-f]{64}$/.test(value);
@@ -1,4 +1,4 @@
1
- import { Address } from "../types";
1
+ import type { Address } from "../types.js";
2
2
  export declare class User {
3
3
  /**
4
4
  * The user's address.
package/lib/user/User.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.User = void 0;
4
- class User {
1
+ export class User {
5
2
  /**
6
3
  * The user's address.
7
4
  */
@@ -20,4 +17,3 @@ class User {
20
17
  this.morphoNonce = morphoNonce;
21
18
  }
22
19
  }
23
- exports.User = User;
@@ -1 +1 @@
1
- export * from "./User";
1
+ export * from "./User.js";
package/lib/user/index.js CHANGED
@@ -1,17 +1 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./User"), exports);
1
+ export * from "./User.js";
@@ -1,9 +1,9 @@
1
- import { CapacityLimit } from "../market";
2
- import { RoundingDirection } from "../maths";
3
- import { VaultToken } from "../token";
4
- import { Address, BigIntish, MarketId } from "../types";
5
- import { VaultConfig } from "./VaultConfig";
6
- import { InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation";
1
+ import { type CapacityLimit } from "../market/index.js";
2
+ import { type RoundingDirection } from "../math/index.js";
3
+ import { VaultToken } from "../token/index.js";
4
+ import type { Address, BigIntish, MarketId } from "../types.js";
5
+ import type { InputVaultConfig } from "./VaultConfig.js";
6
+ import { type InputVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
7
7
  export interface Pending<T> {
8
8
  value: T;
9
9
  validAt: bigint;
@@ -22,8 +22,7 @@ export interface VaultPublicAllocatorConfig {
22
22
  */
23
23
  accruedFee: bigint;
24
24
  }
25
- export interface InputVault {
26
- config: VaultConfig;
25
+ export interface InputVault extends InputVaultConfig {
27
26
  curator: Address;
28
27
  owner: Address;
29
28
  guardian: Address;
@@ -42,10 +41,6 @@ export interface InputVault {
42
41
  publicAllocatorConfig?: VaultPublicAllocatorConfig;
43
42
  }
44
43
  export declare class Vault extends VaultToken implements InputVault {
45
- /**
46
- * The MetaMorpho vault's config.
47
- */
48
- readonly config: VaultConfig;
49
44
  /**
50
45
  * The MetaMorpho vault's owner address.
51
46
  */
@@ -94,14 +89,6 @@ export declare class Vault extends VaultToken implements InputVault {
94
89
  * The MetaMorpho vault's ordered withdraw queue.
95
90
  */
96
91
  withdrawQueue: MarketId[];
97
- /**
98
- * The ERC4626 vault's total supply of shares.
99
- */
100
- totalSupply: bigint;
101
- /**
102
- * The ERC4626 vault's total assets.
103
- */
104
- totalAssets: bigint;
105
92
  /**
106
93
  * The MetaMorpho vault's last total assets used to calculate performance fees.
107
94
  */
@@ -110,8 +97,7 @@ export declare class Vault extends VaultToken implements InputVault {
110
97
  * The MetaMorpho vault's public allocator configuration.
111
98
  */
112
99
  publicAllocatorConfig?: VaultPublicAllocatorConfig;
113
- constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }: InputVault);
114
- get asset(): `0x${string}`;
100
+ constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }: InputVault);
115
101
  /**
116
102
  * The amount of interest in assets accrued since the last interaction with the vault.
117
103
  */
@@ -1,16 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AccrualVault = exports.Vault = void 0;
4
- const market_1 = require("../market");
5
- const maths_1 = require("../maths");
6
- const token_1 = require("../token");
7
- const VaultMarketAllocation_1 = require("./VaultMarketAllocation");
8
- const VaultUtils_1 = require("./VaultUtils");
9
- class Vault extends token_1.VaultToken {
10
- /**
11
- * The MetaMorpho vault's config.
12
- */
13
- config;
1
+ import { CapacityLimitReason } from "../market/index.js";
2
+ import { MathLib } from "../math/index.js";
3
+ import { VaultToken } from "../token/index.js";
4
+ import { VaultMarketAllocation, } from "./VaultMarketAllocation.js";
5
+ export class Vault extends VaultToken {
14
6
  /**
15
7
  * The MetaMorpho vault's owner address.
16
8
  */
@@ -59,14 +51,6 @@ class Vault extends token_1.VaultToken {
59
51
  * The MetaMorpho vault's ordered withdraw queue.
60
52
  */
61
53
  withdrawQueue;
62
- /**
63
- * The ERC4626 vault's total supply of shares.
64
- */
65
- totalSupply;
66
- /**
67
- * The ERC4626 vault's total assets.
68
- */
69
- totalAssets;
70
54
  /**
71
55
  * The MetaMorpho vault's last total assets used to calculate performance fees.
72
56
  */
@@ -75,9 +59,8 @@ class Vault extends token_1.VaultToken {
75
59
  * The MetaMorpho vault's public allocator configuration.
76
60
  */
77
61
  publicAllocatorConfig;
78
- constructor({ config, curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, }) {
62
+ constructor({ curator, owner, guardian, publicAllocatorConfig, fee, feeRecipient, skimRecipient, pendingTimelock, pendingGuardian, pendingOwner, timelock, supplyQueue, withdrawQueue, totalSupply, totalAssets, lastTotalAssets, ...config }) {
79
63
  super(config, { totalAssets, totalSupply });
80
- this.config = config;
81
64
  this.curator = curator;
82
65
  this.owner = owner;
83
66
  this.guardian = guardian;
@@ -93,29 +76,23 @@ class Vault extends token_1.VaultToken {
93
76
  this.timelock = timelock;
94
77
  this.supplyQueue = supplyQueue;
95
78
  this.withdrawQueue = withdrawQueue;
96
- this.totalSupply = totalSupply;
97
- this.totalAssets = totalAssets;
98
79
  this.lastTotalAssets = lastTotalAssets;
99
80
  this.publicAllocatorConfig = publicAllocatorConfig;
100
81
  }
101
- get asset() {
102
- return this.config.asset;
103
- }
104
82
  /**
105
83
  * The amount of interest in assets accrued since the last interaction with the vault.
106
84
  */
107
85
  get totalInterest() {
108
- return maths_1.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
86
+ return MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
109
87
  }
110
88
  toAssets(shares, rounding) {
111
- return VaultUtils_1.VaultUtils.toAssets(shares, this, this.config, rounding);
89
+ return this._unwrap(shares, rounding);
112
90
  }
113
91
  toShares(assets, rounding) {
114
- return VaultUtils_1.VaultUtils.toShares(assets, this, this.config, rounding);
92
+ return this._wrap(assets, rounding);
115
93
  }
116
94
  }
117
- exports.Vault = Vault;
118
- class AccrualVault extends Vault {
95
+ export class AccrualVault extends Vault {
119
96
  /**
120
97
  * The allocation of the vault on each market enabled.
121
98
  */
@@ -137,7 +114,7 @@ class AccrualVault extends Vault {
137
114
  });
138
115
  this.allocations = new Map(allocations.map((allocation) => [
139
116
  allocation.position.market.id,
140
- new VaultMarketAllocation_1.VaultMarketAllocation(allocation),
117
+ new VaultMarketAllocation(allocation),
141
118
  ]));
142
119
  this.collateralAllocations = new Map();
143
120
  for (const { marketId, position } of this.allocations.values()) {
@@ -161,7 +138,9 @@ class AccrualVault extends Vault {
161
138
  * The vault's liquidity directly available from allocated markets.
162
139
  */
163
140
  get liquidity() {
164
- return Array.from(this.allocations.values()).reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
141
+ return this.allocations
142
+ .values()
143
+ .reduce((total, { position }) => total + position.withdrawCapacityLimit.value, 0n);
165
144
  }
166
145
  /**
167
146
  * The MetaMorpho vault's average APY on its assets, including the performance fee.
@@ -169,13 +148,15 @@ class AccrualVault extends Vault {
169
148
  get avgApy() {
170
149
  if (this.totalAssets === 0n)
171
150
  return 0n;
172
- return (Array.from(this.allocations.values()).reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
151
+ return (this.allocations
152
+ .values()
153
+ .reduce((total, { position }) => total + position.market.supplyApy * position.supplyAssets, 0n) / this.totalAssets);
173
154
  }
174
155
  /**
175
156
  * The MetaMorpho vault's average APY on its assets, excluding the performance fee.
176
157
  */
177
158
  get netApy() {
178
- return maths_1.MathLib.wMulDown(this.avgApy, maths_1.MathLib.WAD - this.fee);
159
+ return MathLib.wMulDown(this.avgApy, MathLib.WAD - this.fee);
179
160
  }
180
161
  getAllocationProportion(marketId) {
181
162
  if (this.totalAssets === 0n)
@@ -183,21 +164,23 @@ class AccrualVault extends Vault {
183
164
  const allocation = this.allocations.get(marketId);
184
165
  if (!allocation)
185
166
  return 0n;
186
- return maths_1.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
167
+ return MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
187
168
  }
188
169
  getDepositCapacityLimit(assets) {
189
- const suppliable = Array.from(this.allocations.values()).reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => maths_1.MathLib.min(total +
170
+ const suppliable = this.allocations
171
+ .values()
172
+ .reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => MathLib.min(total +
190
173
  (this.supplyQueue.includes(marketId)
191
- ? maths_1.MathLib.zeroFloorSub(cap, supplyAssets)
192
- : 0n), maths_1.MathLib.MAX_UINT_256), 0n);
174
+ ? MathLib.zeroFloorSub(cap, supplyAssets)
175
+ : 0n), MathLib.MAX_UINT_256), 0n);
193
176
  if (assets > suppliable)
194
177
  return {
195
178
  value: suppliable,
196
- limiter: market_1.CapacityLimitReason.cap,
179
+ limiter: CapacityLimitReason.cap,
197
180
  };
198
181
  return {
199
182
  value: assets,
200
- limiter: market_1.CapacityLimitReason.balance,
183
+ limiter: CapacityLimitReason.balance,
201
184
  };
202
185
  }
203
186
  getWithdrawCapacityLimit(shares) {
@@ -206,11 +189,11 @@ class AccrualVault extends Vault {
206
189
  if (assets > liquidity)
207
190
  return {
208
191
  value: liquidity,
209
- limiter: market_1.CapacityLimitReason.liquidity,
192
+ limiter: CapacityLimitReason.liquidity,
210
193
  };
211
194
  return {
212
195
  value: assets,
213
- limiter: market_1.CapacityLimitReason.balance,
196
+ limiter: CapacityLimitReason.balance,
214
197
  };
215
198
  }
216
199
  /**
@@ -218,11 +201,16 @@ class AccrualVault extends Vault {
218
201
  * @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
219
202
  */
220
203
  accrueInterest(timestamp) {
221
- const vault = new AccrualVault(this, Array.from(this.allocations.values(), ({ config, position }) => ({
222
- config,
223
- position: position.accrueInterest(timestamp),
224
- })));
225
- const feeAssets = maths_1.MathLib.wMulDown(vault.totalInterest, vault.fee);
204
+ const vault = new AccrualVault(this,
205
+ // Keep withdraw queue order.
206
+ this.withdrawQueue.map((marketId) => {
207
+ const { config, position } = this.allocations.get(marketId);
208
+ return {
209
+ config,
210
+ position: position.accrueInterest(timestamp),
211
+ };
212
+ }));
213
+ const feeAssets = MathLib.wMulDown(vault.totalInterest, vault.fee);
226
214
  vault.totalAssets -= feeAssets;
227
215
  const feeShares = vault.toShares(feeAssets, "Down");
228
216
  vault.totalAssets += feeAssets;
@@ -231,4 +219,3 @@ class AccrualVault extends Vault {
231
219
  return vault;
232
220
  }
233
221
  }
234
- exports.AccrualVault = AccrualVault;
@@ -1,5 +1,5 @@
1
- import { ChainId } from "../chain";
2
- import { Address, BigIntish } from "../types";
1
+ import type { ChainId } from "../chain.js";
2
+ import type { Address, BigIntish } from "../types.js";
3
3
  export interface InputVaultConfig {
4
4
  address: Address;
5
5
  decimals: BigIntish;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultConfig = void 0;
4
- const errors_1 = require("../errors");
5
- class VaultConfig {
1
+ import { UnknownVaultConfigError } from "../errors.js";
2
+ export class VaultConfig {
6
3
  chainId;
7
4
  static _CACHE = {};
8
5
  static get(address, chainId) {
9
6
  const config = VaultConfig._CACHE[chainId]?.[address];
10
7
  if (!config)
11
- throw new errors_1.UnknownVaultConfigError(address);
8
+ throw new UnknownVaultConfigError(address);
12
9
  return config;
13
10
  }
14
11
  address;
@@ -29,4 +26,3 @@ class VaultConfig {
29
26
  (VaultConfig._CACHE[chainId] ??= {})[address] = this;
30
27
  }
31
28
  }
32
- exports.VaultConfig = VaultConfig;
@@ -1,5 +1,5 @@
1
- import { AccrualPosition } from "../position";
2
- import { VaultMarketConfig } from "./VaultMarketConfig";
1
+ import type { AccrualPosition } from "../position/index.js";
2
+ import type { VaultMarketConfig } from "./VaultMarketConfig.js";
3
3
  export interface InputVaultMarketAllocation {
4
4
  config: VaultMarketConfig;
5
5
  position: AccrualPosition;
@@ -15,6 +15,6 @@ export declare class VaultMarketAllocation implements InputVaultMarketAllocation
15
15
  readonly position: AccrualPosition;
16
16
  constructor({ config, position }: InputVaultMarketAllocation);
17
17
  get vault(): `0x${string}`;
18
- get marketId(): import("..").MarketId;
18
+ get marketId(): import("../types.js").MarketId;
19
19
  get utilization(): bigint;
20
20
  }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultMarketAllocation = void 0;
4
- const maths_1 = require("../maths");
5
- class VaultMarketAllocation {
1
+ import { MathLib } from "../math/index.js";
2
+ export class VaultMarketAllocation {
6
3
  /**
7
4
  * The vault's configuration on the corresponding market.
8
5
  */
@@ -23,8 +20,7 @@ class VaultMarketAllocation {
23
20
  }
24
21
  get utilization() {
25
22
  if (this.config.cap === 0n)
26
- return maths_1.MathLib.MAX_UINT_256;
27
- return maths_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
23
+ return MathLib.MAX_UINT_256;
24
+ return MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
28
25
  }
29
26
  }
30
- exports.VaultMarketAllocation = VaultMarketAllocation;
@@ -1,6 +1,6 @@
1
- import { Address, MarketId } from "../types";
2
- import { Pending } from "./Vault";
3
- import { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig";
1
+ import type { Address, MarketId } from "../types.js";
2
+ import type { Pending } from "./Vault.js";
3
+ import type { VaultMarketPublicAllocatorConfig } from "./VaultMarketPublicAllocatorConfig.js";
4
4
  export interface InputVaultMarketConfig {
5
5
  vault: Address;
6
6
  marketId: MarketId;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultMarketConfig = void 0;
4
- class VaultMarketConfig {
1
+ export class VaultMarketConfig {
5
2
  /**
6
3
  * The vault's address.
7
4
  */
@@ -40,4 +37,3 @@ class VaultMarketConfig {
40
37
  this.publicAllocatorConfig = publicAllocatorConfig;
41
38
  }
42
39
  }
43
- exports.VaultMarketConfig = VaultMarketConfig;
@@ -1,4 +1,4 @@
1
- import { Address, MarketId } from "../types";
1
+ import type { Address, MarketId } from "../types.js";
2
2
  /**
3
3
  * The vault's configuration of a market on the PublicAllocator.
4
4
  */
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultMarketPublicAllocatorConfig = void 0;
4
- class VaultMarketPublicAllocatorConfig {
1
+ export class VaultMarketPublicAllocatorConfig {
5
2
  /**
6
3
  * The vault's address.
7
4
  */
@@ -25,4 +22,3 @@ class VaultMarketPublicAllocatorConfig {
25
22
  this.maxOut = maxOut;
26
23
  }
27
24
  }
28
- exports.VaultMarketPublicAllocatorConfig = VaultMarketPublicAllocatorConfig;
@@ -1,4 +1,4 @@
1
- import { Address } from "../types";
1
+ import type { Address } from "../types.js";
2
2
  export interface InputVaultUser {
3
3
  vault: Address;
4
4
  user: Address;
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultUser = void 0;
4
- class VaultUser {
1
+ export class VaultUser {
5
2
  /**
6
3
  * The vault's address.
7
4
  */
@@ -25,4 +22,3 @@ class VaultUser {
25
22
  this.allowance = allowance;
26
23
  }
27
24
  }
28
- exports.VaultUser = VaultUser;
@@ -1,18 +1,16 @@
1
- import { RoundingDirection } from "../maths";
2
- import { BigIntish } from "../types";
1
+ import { type RoundingDirection } from "../math/index.js";
2
+ import type { BigIntish } from "../types.js";
3
3
  export declare namespace VaultUtils {
4
4
  const VIRTUAL_ASSETS = 1n;
5
5
  function decimalsOffset(decimals: BigIntish): bigint;
6
- function toAssets(shares: BigIntish, { totalAssets, totalSupply, }: {
6
+ function toAssets(shares: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
7
7
  totalAssets: BigIntish;
8
8
  totalSupply: BigIntish;
9
- }, { decimalsOffset }: {
10
9
  decimalsOffset: BigIntish;
11
10
  }, rounding?: RoundingDirection): bigint;
12
- function toShares(assets: BigIntish, { totalAssets, totalSupply, }: {
11
+ function toShares(assets: BigIntish, { totalAssets, totalSupply, decimalsOffset, }: {
13
12
  totalAssets: BigIntish;
14
13
  totalSupply: BigIntish;
15
- }, { decimalsOffset }: {
16
14
  decimalsOffset: BigIntish;
17
15
  }, rounding?: RoundingDirection): bigint;
18
16
  }
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultUtils = void 0;
4
- const maths_1 = require("../maths");
5
- var VaultUtils;
1
+ import { MathLib } from "../math/index.js";
2
+ export var VaultUtils;
6
3
  (function (VaultUtils) {
7
4
  VaultUtils.VIRTUAL_ASSETS = 1n;
8
5
  function decimalsOffset(decimals) {
9
- return maths_1.MathLib.zeroFloorSub(18n, decimals);
6
+ return MathLib.zeroFloorSub(18n, decimals);
10
7
  }
11
8
  VaultUtils.decimalsOffset = decimalsOffset;
12
- function toAssets(shares, { totalAssets, totalSupply, }, { decimalsOffset }, rounding = "Down") {
13
- return maths_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
9
+ function toAssets(shares, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Down") {
10
+ return MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
14
11
  }
15
12
  VaultUtils.toAssets = toAssets;
16
- function toShares(assets, { totalAssets, totalSupply, }, { decimalsOffset }, rounding = "Up") {
17
- return maths_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
13
+ function toShares(assets, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Up") {
14
+ return MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
18
15
  }
19
16
  VaultUtils.toShares = toShares;
20
- })(VaultUtils || (exports.VaultUtils = VaultUtils = {}));
17
+ })(VaultUtils || (VaultUtils = {}));
@@ -1,7 +1,7 @@
1
- export * from "./VaultUtils";
2
- export * from "./VaultConfig";
3
- export * from "./VaultMarketAllocation";
4
- export * from "./VaultMarketConfig";
5
- export * from "./VaultMarketPublicAllocatorConfig";
6
- export * from "./VaultUser";
7
- export * from "./Vault";
1
+ export * from "./VaultUtils.js";
2
+ export * from "./VaultConfig.js";
3
+ export * from "./VaultMarketAllocation.js";
4
+ export * from "./VaultMarketConfig.js";
5
+ export * from "./VaultMarketPublicAllocatorConfig.js";
6
+ export * from "./VaultUser.js";
7
+ export * from "./Vault.js";