@morpho-org/blue-sdk 1.0.0 → 1.0.1

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 (151) hide show
  1. package/lib/addresses.d.ts +168 -0
  2. package/lib/addresses.js +169 -0
  3. package/lib/chain/chain.constants.d.ts +3 -0
  4. package/lib/chain/chain.constants.js +232 -0
  5. package/lib/chain/chain.types.d.ts +20 -0
  6. package/lib/chain/chain.types.js +30 -0
  7. package/lib/chain/chain.utils.d.ts +14 -0
  8. package/lib/chain/chain.utils.js +30 -0
  9. package/lib/chain/index.js +18 -0
  10. package/lib/constants.d.ts +8 -0
  11. package/lib/constants.js +13 -0
  12. package/lib/errors.d.ts +37 -0
  13. package/lib/errors.js +71 -0
  14. package/lib/ethers/index.js +18 -0
  15. package/lib/ethers/safeGetAddress.d.ts +1 -0
  16. package/lib/ethers/safeGetAddress.js +6 -0
  17. package/lib/ethers/safeParseUnits.d.ts +2 -0
  18. package/lib/ethers/safeParseUnits.js +25 -0
  19. package/lib/evm.d.ts +36 -0
  20. package/lib/evm.js +113 -0
  21. package/lib/helpers/format/format.d.ts +98 -0
  22. package/lib/helpers/format/format.js +301 -0
  23. package/lib/helpers/format/index.js +17 -0
  24. package/lib/helpers/getChecksumedAddress.d.ts +7 -0
  25. package/lib/helpers/getChecksumedAddress.js +17 -0
  26. package/lib/helpers/index.js +20 -0
  27. package/{src/helpers/isZeroAddressOrUnset.ts → lib/helpers/isZeroAddressOrUnset.d.ts} +1 -7
  28. package/lib/helpers/isZeroAddressOrUnset.js +14 -0
  29. package/lib/helpers/locale.d.ts +36 -0
  30. package/lib/helpers/locale.js +86 -0
  31. package/lib/holding/Holding.d.ts +60 -0
  32. package/lib/holding/Holding.js +31 -0
  33. package/lib/holding/index.js +17 -0
  34. package/lib/index.d.ts +33 -0
  35. package/lib/index.js +62 -0
  36. package/lib/market/Market.d.ts +159 -0
  37. package/lib/market/Market.js +240 -0
  38. package/lib/market/MarketConfig.d.ts +44 -0
  39. package/lib/market/MarketConfig.js +56 -0
  40. package/lib/market/MarketUtils.d.ts +165 -0
  41. package/lib/market/MarketUtils.js +182 -0
  42. package/lib/market/index.js +19 -0
  43. package/lib/maths/AdaptiveCurveIrmLib.d.ts +37 -0
  44. package/lib/maths/AdaptiveCurveIrmLib.js +116 -0
  45. package/lib/maths/MathLib.d.ts +94 -0
  46. package/lib/maths/MathLib.js +153 -0
  47. package/lib/maths/MathUtils.d.ts +15 -0
  48. package/lib/maths/MathUtils.js +33 -0
  49. package/lib/maths/SharesMath.d.ts +12 -0
  50. package/lib/maths/SharesMath.js +22 -0
  51. package/lib/maths/index.js +20 -0
  52. package/lib/notifications.d.ts +98 -0
  53. package/lib/notifications.js +52 -0
  54. package/lib/position/Position.d.ts +118 -0
  55. package/lib/position/Position.js +145 -0
  56. package/lib/position/index.js +17 -0
  57. package/lib/signatures/index.d.ts +12 -0
  58. package/lib/signatures/index.js +39 -0
  59. package/lib/signatures/manager.d.ts +10 -0
  60. package/lib/signatures/manager.js +37 -0
  61. package/lib/signatures/permit.d.ts +21 -0
  62. package/lib/signatures/permit.js +101 -0
  63. package/lib/signatures/permit2.d.ts +20 -0
  64. package/lib/signatures/permit2.js +91 -0
  65. package/lib/signatures/types.d.ts +13 -0
  66. package/lib/signatures/types.js +2 -0
  67. package/lib/signatures/utils.d.ts +6 -0
  68. package/lib/signatures/utils.js +44 -0
  69. package/lib/tests/mocks/markets.d.ts +17 -0
  70. package/lib/tests/mocks/markets.js +108 -0
  71. package/lib/token/ERC20Metadata.d.ts +249 -0
  72. package/lib/token/ERC20Metadata.js +81 -0
  73. package/lib/token/Token.d.ts +45 -0
  74. package/lib/token/Token.js +39 -0
  75. package/lib/token/TokenNamespace.d.ts +18 -0
  76. package/lib/token/TokenNamespace.js +55 -0
  77. package/lib/token/WrappedToken.d.ts +42 -0
  78. package/lib/token/WrappedToken.js +87 -0
  79. package/lib/token/index.js +18 -0
  80. package/lib/types.d.ts +29 -0
  81. package/lib/types.js +23 -0
  82. package/lib/user/User.d.ts +20 -0
  83. package/lib/user/User.js +11 -0
  84. package/lib/user/index.js +18 -0
  85. package/lib/user/user.types.d.ts +18 -0
  86. package/lib/user/user.types.js +2 -0
  87. package/lib/vault/Vault.d.ts +167 -0
  88. package/lib/vault/Vault.js +156 -0
  89. package/lib/vault/VaultAllocation.d.ts +38 -0
  90. package/lib/vault/VaultAllocation.js +18 -0
  91. package/lib/vault/VaultConfig.d.ts +23 -0
  92. package/lib/vault/VaultConfig.js +26 -0
  93. package/lib/vault/VaultUtils.d.ts +17 -0
  94. package/lib/vault/VaultUtils.js +17 -0
  95. package/lib/vault/index.js +20 -0
  96. package/package.json +5 -5
  97. package/src/addresses.ts +0 -261
  98. package/src/chain/chain.constants.ts +0 -235
  99. package/src/chain/chain.test.ts +0 -51
  100. package/src/chain/chain.types.ts +0 -42
  101. package/src/chain/chain.utils.ts +0 -44
  102. package/src/constants.ts +0 -18
  103. package/src/errors.ts +0 -75
  104. package/src/ethers/ethers.test.ts +0 -17
  105. package/src/ethers/safeGetAddress.ts +0 -4
  106. package/src/ethers/safeParseUnits.ts +0 -29
  107. package/src/evm.ts +0 -172
  108. package/src/helpers/format/format.test.ts +0 -340
  109. package/src/helpers/format/format.ts +0 -416
  110. package/src/helpers/getChecksumedAddress.ts +0 -15
  111. package/src/helpers/locale.ts +0 -108
  112. package/src/holding/Holding.ts +0 -109
  113. package/src/market/Market.ts +0 -479
  114. package/src/market/MarketConfig.ts +0 -108
  115. package/src/market/MarketUtils.test.ts +0 -25
  116. package/src/market/MarketUtils.ts +0 -467
  117. package/src/maths/AdaptiveCurveIrmLib.ts +0 -143
  118. package/src/maths/MathLib.ts +0 -208
  119. package/src/maths/MathUtils.ts +0 -31
  120. package/src/maths/SharesMath.ts +0 -40
  121. package/src/notifications.ts +0 -167
  122. package/src/position/Position.ts +0 -251
  123. package/src/signatures/index.ts +0 -18
  124. package/src/signatures/manager.ts +0 -50
  125. package/src/signatures/permit.ts +0 -126
  126. package/src/signatures/permit2.ts +0 -120
  127. package/src/signatures/types.ts +0 -18
  128. package/src/signatures/utils.ts +0 -83
  129. package/src/tests/mocks/markets.ts +0 -110
  130. package/src/token/ERC20Metadata.ts +0 -124
  131. package/src/token/Token.ts +0 -83
  132. package/src/token/TokenNamespace.ts +0 -76
  133. package/src/token/WrappedToken.ts +0 -142
  134. package/src/types.ts +0 -37
  135. package/src/user/User.ts +0 -32
  136. package/src/user/user.types.ts +0 -23
  137. package/src/vault/Vault.ts +0 -370
  138. package/src/vault/VaultAllocation.ts +0 -58
  139. package/src/vault/VaultConfig.ts +0 -55
  140. package/src/vault/VaultUtils.ts +0 -47
  141. /package/{src/chain/index.ts → lib/chain/index.d.ts} +0 -0
  142. /package/{src/ethers/index.ts → lib/ethers/index.d.ts} +0 -0
  143. /package/{src/helpers/format/index.ts → lib/helpers/format/index.d.ts} +0 -0
  144. /package/{src/helpers/index.ts → lib/helpers/index.d.ts} +0 -0
  145. /package/{src/holding/index.ts → lib/holding/index.d.ts} +0 -0
  146. /package/{src/market/index.ts → lib/market/index.d.ts} +0 -0
  147. /package/{src/maths/index.ts → lib/maths/index.d.ts} +0 -0
  148. /package/{src/position/index.ts → lib/position/index.d.ts} +0 -0
  149. /package/{src/token/index.ts → lib/token/index.d.ts} +0 -0
  150. /package/{src/user/index.ts → lib/user/index.d.ts} +0 -0
  151. /package/{src/vault/index.ts → lib/vault/index.d.ts} +0 -0
@@ -1,370 +0,0 @@
1
- import { BigNumberish, MaxUint256, toBigInt } from "ethers";
2
-
3
- import { CapacityLimit, CapacityLimitReason } from "../market";
4
- import { MathLib, MathUtils, RoundingDirection } from "../maths";
5
- import { Token } from "../token";
6
- import { Address, MarketId } from "../types";
7
-
8
- import { InputVaultAllocation, VaultAllocation } from "./VaultAllocation";
9
- import { VaultConfig } from "./VaultConfig";
10
- import { VaultUtils } from "./VaultUtils";
11
-
12
- export interface Pending<T> {
13
- value: T;
14
- validAt: bigint;
15
- }
16
-
17
- export interface VaultPublicAllocatorConfig {
18
- /**
19
- * The PublicAllocator's admin address.
20
- */
21
- admin: Address;
22
- /**
23
- * The PublicAllocator's reallocation fee (in native token).
24
- */
25
- fee: bigint;
26
- /**
27
- * The PublicAllocator's reallocation fee accrued so far (in native token).
28
- */
29
- accruedFee: bigint;
30
- }
31
-
32
- export interface InputVault {
33
- config: VaultConfig;
34
- curator: Address;
35
- owner: Address;
36
- guardian: Address;
37
- fee: BigNumberish;
38
- feeRecipient: Address;
39
- skimRecipient: Address;
40
- pendingTimelock: Pending<BigNumberish>;
41
- pendingGuardian: Pending<Address>;
42
- pendingOwner: Address;
43
- timelock: BigNumberish; // seconds
44
- supplyQueue: MarketId[];
45
- withdrawQueue: MarketId[];
46
- totalSupply: BigNumberish;
47
- totalAssets: BigNumberish;
48
- lastTotalAssets: BigNumberish;
49
- publicAllocatorConfig?: VaultPublicAllocatorConfig;
50
- }
51
-
52
- export class Vault implements InputVault {
53
- /**
54
- * The MetaMorpho vault's config.
55
- */
56
- public readonly config: VaultConfig;
57
-
58
- /**
59
- * The MetaMorpho vault's owner address.
60
- */
61
- owner: Address;
62
- /**
63
- * The MetaMorpho vault's curator address.
64
- */
65
- curator: Address;
66
- /**
67
- * The MetaMorpho vault's guardian address.
68
- */
69
- guardian: Address;
70
- /**
71
- * The MetaMorpho vault's skim recipient address (mostly used to skim reward tokens claimed to the vault).
72
- */
73
- skimRecipient: Address;
74
- /**
75
- * The MetaMorpho vault's fee recipient address.
76
- */
77
- feeRecipient: Address;
78
-
79
- /**
80
- * The MetaMorpho vault's timelock (in seconds).
81
- */
82
- timelock: bigint;
83
- /**
84
- * The MetaMorpho vault's fee.
85
- */
86
- fee: bigint;
87
-
88
- /**
89
- * The MetaMorpho vault's pending owner address and activation timestamp.
90
- */
91
- pendingOwner: Address;
92
- /**
93
- * The MetaMorpho vault's pending guardian address and activation timestamp.
94
- */
95
- pendingGuardian: Pending<Address>;
96
- /**
97
- * The MetaMorpho vault's pending timelock (in seconds) and activation timestamp.
98
- */
99
- pendingTimelock: Pending<bigint>;
100
-
101
- /**
102
- * The MetaMorpho vault's ordered supply queue.
103
- */
104
- supplyQueue: MarketId[];
105
- /**
106
- * The MetaMorpho vault's ordered withdraw queue.
107
- */
108
- withdrawQueue: MarketId[];
109
-
110
- /**
111
- * The ERC4626 vault's total supply of shares.
112
- */
113
- totalSupply: bigint;
114
- /**
115
- * The ERC4626 vault's total assets.
116
- */
117
- totalAssets: bigint;
118
- /**
119
- * The MetaMorpho vault's last total assets used to calculate performance fees.
120
- */
121
- lastTotalAssets: bigint;
122
-
123
- /**
124
- * The MetaMorpho vault's public allocator configuration.
125
- */
126
- publicAllocatorConfig?: VaultPublicAllocatorConfig;
127
-
128
- constructor({
129
- config,
130
- curator,
131
- owner,
132
- guardian,
133
- publicAllocatorConfig,
134
- fee,
135
- feeRecipient,
136
- skimRecipient,
137
- pendingTimelock,
138
- pendingGuardian,
139
- pendingOwner,
140
- timelock,
141
- supplyQueue,
142
- withdrawQueue,
143
- totalSupply,
144
- totalAssets,
145
- lastTotalAssets,
146
- }: InputVault) {
147
- this.config = config;
148
- this.curator = curator;
149
- this.owner = owner;
150
- this.guardian = guardian;
151
- this.fee = toBigInt(fee);
152
- this.feeRecipient = feeRecipient;
153
- this.skimRecipient = skimRecipient;
154
- this.pendingTimelock = {
155
- value: toBigInt(pendingTimelock.value),
156
- validAt: pendingTimelock.validAt,
157
- };
158
- this.pendingGuardian = pendingGuardian;
159
- this.pendingOwner = pendingOwner;
160
- this.timelock = toBigInt(timelock);
161
- this.supplyQueue = supplyQueue;
162
- this.withdrawQueue = withdrawQueue;
163
- this.totalSupply = toBigInt(totalSupply);
164
- this.totalAssets = toBigInt(totalAssets);
165
- this.lastTotalAssets = toBigInt(lastTotalAssets);
166
- this.publicAllocatorConfig = publicAllocatorConfig;
167
- }
168
-
169
- get address() {
170
- return this.config.address;
171
- }
172
-
173
- get asset() {
174
- return this.config.asset;
175
- }
176
-
177
- /**
178
- * The amount of interest in assets accrued since the last interaction with the vault.
179
- */
180
- get totalInterest() {
181
- return MathUtils.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
182
- }
183
-
184
- public toAssets(shares: BigNumberish, rounding?: RoundingDirection) {
185
- return VaultUtils.toAssets(shares, this, this.config, rounding);
186
- }
187
-
188
- public toShares(assets: BigNumberish, rounding?: RoundingDirection) {
189
- return VaultUtils.toShares(assets, this, this.config, rounding);
190
- }
191
- }
192
-
193
- export interface CollateralAllocation {
194
- address: Address;
195
- lltvs: Set<bigint>;
196
- oracles: Set<Address>;
197
- markets: Set<MarketId>;
198
- proportion: bigint;
199
- }
200
-
201
- export interface InputAccrualVault
202
- extends Omit<InputVault, "withdrawQueue" | "totalAssets"> {}
203
-
204
- export class AccrualVault extends Vault implements InputAccrualVault {
205
- /**
206
- * The allocation of the vault on each market enabled.
207
- */
208
- public readonly allocations: Map<MarketId, VaultAllocation>;
209
-
210
- /**
211
- * The ERC4626 vault's share token.
212
- */
213
- public token: Token;
214
-
215
- /**
216
- * The proportion of assets of the vault supplied to markets collateralized by each collateral asset.
217
- */
218
- public readonly collateralAllocations: Map<Address, CollateralAllocation>;
219
-
220
- constructor(
221
- vault: InputAccrualVault,
222
- /**
223
- * The allocation of the vault on each market of the withdraw queue,
224
- * in the same order as the withdraw queue.
225
- */
226
- allocations: Omit<InputVaultAllocation, "proportion">[]
227
- ) {
228
- super({
229
- ...vault,
230
- withdrawQueue: allocations.map(({ position }) => position.market.id),
231
- totalAssets: allocations.reduce(
232
- (total, { position }) => total + position.supplyAssets,
233
- 0n
234
- ),
235
- });
236
-
237
- this.allocations = new Map(
238
- allocations.map(({ config, position }) => [
239
- position.market.id,
240
- new VaultAllocation({
241
- config,
242
- position,
243
- proportion:
244
- this.totalAssets === 0n
245
- ? 0n
246
- : MathLib.wDivDown(position.supplyAssets, this.totalAssets),
247
- }),
248
- ])
249
- );
250
- this.token = new Token(this.config);
251
-
252
- this.collateralAllocations = new Map<Address, CollateralAllocation>();
253
-
254
- for (const { position, proportion } of this.allocations.values()) {
255
- const address = position.market.config.collateralToken;
256
-
257
- let exposure = this.collateralAllocations.get(address);
258
- if (!exposure)
259
- this.collateralAllocations.set(
260
- address,
261
- (exposure = {
262
- address,
263
- lltvs: new Set(),
264
- oracles: new Set(),
265
- markets: new Set(),
266
- proportion: 0n,
267
- })
268
- );
269
-
270
- exposure.lltvs.add(position.market.config.lltv);
271
- exposure.oracles.add(position.market.config.oracle);
272
- exposure.markets.add(position.market.id);
273
- exposure.proportion += proportion;
274
- }
275
- }
276
-
277
- /**
278
- * The vault's liquidity directly available from allocated markets.
279
- */
280
- get liquidity() {
281
- return Array.from(this.allocations.values()).reduce(
282
- (total, { position }) => total + position.withdrawCapacityLimit.value,
283
- 0n
284
- );
285
- }
286
-
287
- /**
288
- * The MetaMorpho vault's average APY on its assets, including the performance fee.
289
- */
290
- get avgApy() {
291
- if (this.totalAssets === 0n) return 0n;
292
- return (
293
- Array.from(this.allocations.values()).reduce(
294
- (total, { position }) =>
295
- total + position.market.supplyApy * position.supplyAssets,
296
- 0n
297
- ) / this.totalAssets
298
- );
299
- }
300
-
301
- /**
302
- * The MetaMorpho vault's average APY on its assets, excluding the performance fee.
303
- */
304
- get netApy() {
305
- return MathLib.wMulDown(this.avgApy, MathLib.WAD - this.fee);
306
- }
307
-
308
- public getDepositCapacityLimit(assets: bigint): CapacityLimit {
309
- const suppliable = Array.from(this.allocations.values()).reduce(
310
- (total, { config: { cap }, position: { marketId, supplyAssets } }) =>
311
- MathLib.min(
312
- total +
313
- (this.supplyQueue.includes(marketId)
314
- ? MathUtils.zeroFloorSub(cap, supplyAssets)
315
- : 0n),
316
- MaxUint256
317
- ),
318
- 0n
319
- );
320
-
321
- if (assets > suppliable)
322
- return {
323
- value: suppliable,
324
- limiter: CapacityLimitReason.cap,
325
- };
326
-
327
- return {
328
- value: assets,
329
- limiter: CapacityLimitReason.balance,
330
- };
331
- }
332
-
333
- public getWithdrawCapacityLimit(shares: bigint): CapacityLimit {
334
- const assets = this.toAssets(shares);
335
- const { liquidity } = this;
336
-
337
- if (assets > liquidity)
338
- return {
339
- value: liquidity,
340
- limiter: CapacityLimitReason.liquidity,
341
- };
342
-
343
- return {
344
- value: assets,
345
- limiter: CapacityLimitReason.balance,
346
- };
347
- }
348
-
349
- public accrueInterest(timestamp: bigint) {
350
- const vault = new AccrualVault(
351
- this,
352
- Array.from(this.allocations.values(), ({ config, position }) => ({
353
- config,
354
- position: position.accrueInterest(timestamp),
355
- }))
356
- );
357
-
358
- const feeAssets = MathLib.wMulDown(vault.totalInterest, vault.fee);
359
-
360
- vault.totalAssets -= feeAssets;
361
-
362
- const feeShares = vault.toShares(feeAssets, "Down");
363
-
364
- vault.totalAssets += feeAssets;
365
- vault.totalSupply += feeShares;
366
- vault.lastTotalAssets = vault.totalAssets;
367
-
368
- return vault;
369
- }
370
- }
@@ -1,58 +0,0 @@
1
- import { MaxUint256 } from "ethers";
2
-
3
- import { MathLib } from "../maths";
4
- import { AccrualPosition } from "../position";
5
-
6
- import { Pending } from "./Vault";
7
-
8
- /**
9
- * The vault's configuration of a market on the PublicAllocator.
10
- */
11
- export interface VaultMarketPublicAllocatorConfig {
12
- maxIn: bigint;
13
- maxOut: bigint;
14
- }
15
-
16
- export interface VaultMarketConfig {
17
- cap: bigint;
18
- pendingCap: Pending<bigint>;
19
- removableAt: bigint;
20
- enabled: boolean;
21
- readonly publicAllocatorConfig?: VaultMarketPublicAllocatorConfig;
22
- }
23
-
24
- export interface InputVaultAllocation {
25
- config: VaultMarketConfig;
26
- position: AccrualPosition;
27
- proportion: bigint;
28
- }
29
-
30
- export class VaultAllocation implements InputVaultAllocation {
31
- /**
32
- * The vault's configuration on the corresponding market.
33
- */
34
- public config: VaultMarketConfig;
35
-
36
- /**
37
- * The vault's position on the corresponding market.
38
- */
39
- public readonly position: AccrualPosition;
40
-
41
- /**
42
- * The vault's proportion of assets supplied on the corresponding market,
43
- * with regard to the total assets of the vault.
44
- */
45
- public readonly proportion: bigint;
46
-
47
- constructor({ config, position, proportion }: InputVaultAllocation) {
48
- this.config = config;
49
- this.position = position;
50
- this.proportion = proportion;
51
- }
52
-
53
- get utilization() {
54
- if (this.config.cap === 0n) return MaxUint256;
55
-
56
- return MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
57
- }
58
- }
@@ -1,55 +0,0 @@
1
- import { ChainId } from "../chain";
2
- import { UnknownVaultConfigError } from "../errors";
3
- import { Address } from "../types";
4
-
5
- interface InputVaultConfig {
6
- address: Address;
7
- decimals: number;
8
- decimalsOffset: bigint;
9
- symbol: string;
10
- name: string;
11
- asset: Address;
12
- }
13
-
14
- export class VaultConfig implements InputVaultConfig {
15
- protected static readonly _CACHE: Record<
16
- number,
17
- Record<Address, VaultConfig>
18
- > = {};
19
-
20
- static get(address: Address, chainId: ChainId) {
21
- const config = VaultConfig._CACHE[chainId]?.[address];
22
-
23
- if (!config) throw new UnknownVaultConfigError(address);
24
-
25
- return config;
26
- }
27
-
28
- public readonly address: Address;
29
- public readonly decimals: number;
30
- public readonly decimalsOffset: bigint;
31
- public readonly symbol: string;
32
- public readonly name: string;
33
- public readonly asset: Address;
34
-
35
- constructor(
36
- {
37
- address,
38
- decimals,
39
- decimalsOffset,
40
- symbol,
41
- name,
42
- asset,
43
- }: InputVaultConfig,
44
- public readonly chainId?: number
45
- ) {
46
- this.address = address;
47
- this.decimals = decimals;
48
- this.decimalsOffset = decimalsOffset;
49
- this.symbol = symbol;
50
- this.name = name;
51
- this.asset = asset;
52
-
53
- if (chainId != null) (VaultConfig._CACHE[chainId] ??= {})[address] = this;
54
- }
55
- }
@@ -1,47 +0,0 @@
1
- import { BigNumberish, toBigInt } from "ethers";
2
-
3
- import { MathLib, RoundingDirection } from "../maths";
4
-
5
- export namespace VaultUtils {
6
- export const VIRTUAL_ASSETS = 1n;
7
-
8
- export function toAssets(
9
- shares: BigNumberish,
10
- {
11
- totalAssets,
12
- totalSupply,
13
- }: {
14
- totalAssets: BigNumberish;
15
- totalSupply: BigNumberish;
16
- },
17
- { decimalsOffset }: { decimalsOffset: BigNumberish },
18
- rounding: RoundingDirection = "Down"
19
- ) {
20
- return MathLib.mulDiv(
21
- shares,
22
- toBigInt(totalAssets) + VIRTUAL_ASSETS,
23
- toBigInt(totalSupply) + 10n ** toBigInt(decimalsOffset),
24
- rounding
25
- );
26
- }
27
-
28
- export function toShares(
29
- assets: BigNumberish,
30
- {
31
- totalAssets,
32
- totalSupply,
33
- }: {
34
- totalAssets: BigNumberish;
35
- totalSupply: BigNumberish;
36
- },
37
- { decimalsOffset }: { decimalsOffset: BigNumberish },
38
- rounding: RoundingDirection = "Up"
39
- ) {
40
- return MathLib.mulDiv(
41
- assets,
42
- toBigInt(totalSupply) + 10n ** toBigInt(decimalsOffset),
43
- toBigInt(totalAssets) + VIRTUAL_ASSETS,
44
- rounding
45
- );
46
- }
47
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes