@morpho-org/blue-sdk 1.0.1 → 1.0.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 (151) hide show
  1. package/package.json +10 -6
  2. package/src/addresses.ts +261 -0
  3. package/src/chain/chain.constants.ts +235 -0
  4. package/src/chain/chain.test.ts +51 -0
  5. package/src/chain/chain.types.ts +42 -0
  6. package/src/chain/chain.utils.ts +44 -0
  7. package/src/constants.ts +18 -0
  8. package/src/errors.ts +75 -0
  9. package/src/ethers/ethers.test.ts +17 -0
  10. package/src/ethers/safeGetAddress.ts +4 -0
  11. package/src/ethers/safeParseUnits.ts +29 -0
  12. package/src/evm.ts +172 -0
  13. package/src/helpers/format/format.test.ts +340 -0
  14. package/src/helpers/format/format.ts +416 -0
  15. package/src/helpers/getChecksumedAddress.ts +15 -0
  16. package/{lib/helpers/isZeroAddressOrUnset.d.ts → src/helpers/isZeroAddressOrUnset.ts} +7 -1
  17. package/src/helpers/locale.ts +108 -0
  18. package/src/holding/Holding.ts +109 -0
  19. package/src/market/Market.ts +479 -0
  20. package/src/market/MarketConfig.ts +108 -0
  21. package/src/market/MarketUtils.test.ts +25 -0
  22. package/src/market/MarketUtils.ts +467 -0
  23. package/src/maths/AdaptiveCurveIrmLib.ts +143 -0
  24. package/src/maths/MathLib.ts +208 -0
  25. package/src/maths/MathUtils.ts +31 -0
  26. package/src/maths/SharesMath.ts +40 -0
  27. package/src/notifications.ts +167 -0
  28. package/src/position/Position.ts +251 -0
  29. package/src/signatures/index.ts +18 -0
  30. package/src/signatures/manager.ts +50 -0
  31. package/src/signatures/permit.ts +126 -0
  32. package/src/signatures/permit2.ts +120 -0
  33. package/src/signatures/types.ts +18 -0
  34. package/src/signatures/utils.ts +83 -0
  35. package/src/tests/mocks/markets.ts +110 -0
  36. package/src/token/ERC20Metadata.ts +124 -0
  37. package/src/token/Token.ts +83 -0
  38. package/src/token/TokenNamespace.ts +76 -0
  39. package/src/token/WrappedToken.ts +142 -0
  40. package/src/types.ts +37 -0
  41. package/src/user/User.ts +32 -0
  42. package/src/user/user.types.ts +23 -0
  43. package/src/vault/Vault.ts +370 -0
  44. package/src/vault/VaultAllocation.ts +58 -0
  45. package/src/vault/VaultConfig.ts +55 -0
  46. package/src/vault/VaultUtils.ts +47 -0
  47. package/lib/addresses.d.ts +0 -168
  48. package/lib/addresses.js +0 -169
  49. package/lib/chain/chain.constants.d.ts +0 -3
  50. package/lib/chain/chain.constants.js +0 -232
  51. package/lib/chain/chain.types.d.ts +0 -20
  52. package/lib/chain/chain.types.js +0 -30
  53. package/lib/chain/chain.utils.d.ts +0 -14
  54. package/lib/chain/chain.utils.js +0 -30
  55. package/lib/chain/index.js +0 -18
  56. package/lib/constants.d.ts +0 -8
  57. package/lib/constants.js +0 -13
  58. package/lib/errors.d.ts +0 -37
  59. package/lib/errors.js +0 -71
  60. package/lib/ethers/index.js +0 -18
  61. package/lib/ethers/safeGetAddress.d.ts +0 -1
  62. package/lib/ethers/safeGetAddress.js +0 -6
  63. package/lib/ethers/safeParseUnits.d.ts +0 -2
  64. package/lib/ethers/safeParseUnits.js +0 -25
  65. package/lib/evm.d.ts +0 -36
  66. package/lib/evm.js +0 -113
  67. package/lib/helpers/format/format.d.ts +0 -98
  68. package/lib/helpers/format/format.js +0 -301
  69. package/lib/helpers/format/index.js +0 -17
  70. package/lib/helpers/getChecksumedAddress.d.ts +0 -7
  71. package/lib/helpers/getChecksumedAddress.js +0 -17
  72. package/lib/helpers/index.js +0 -20
  73. package/lib/helpers/isZeroAddressOrUnset.js +0 -14
  74. package/lib/helpers/locale.d.ts +0 -36
  75. package/lib/helpers/locale.js +0 -86
  76. package/lib/holding/Holding.d.ts +0 -60
  77. package/lib/holding/Holding.js +0 -31
  78. package/lib/holding/index.js +0 -17
  79. package/lib/index.d.ts +0 -33
  80. package/lib/index.js +0 -62
  81. package/lib/market/Market.d.ts +0 -159
  82. package/lib/market/Market.js +0 -240
  83. package/lib/market/MarketConfig.d.ts +0 -44
  84. package/lib/market/MarketConfig.js +0 -56
  85. package/lib/market/MarketUtils.d.ts +0 -165
  86. package/lib/market/MarketUtils.js +0 -182
  87. package/lib/market/index.js +0 -19
  88. package/lib/maths/AdaptiveCurveIrmLib.d.ts +0 -37
  89. package/lib/maths/AdaptiveCurveIrmLib.js +0 -116
  90. package/lib/maths/MathLib.d.ts +0 -94
  91. package/lib/maths/MathLib.js +0 -153
  92. package/lib/maths/MathUtils.d.ts +0 -15
  93. package/lib/maths/MathUtils.js +0 -33
  94. package/lib/maths/SharesMath.d.ts +0 -12
  95. package/lib/maths/SharesMath.js +0 -22
  96. package/lib/maths/index.js +0 -20
  97. package/lib/notifications.d.ts +0 -98
  98. package/lib/notifications.js +0 -52
  99. package/lib/position/Position.d.ts +0 -118
  100. package/lib/position/Position.js +0 -145
  101. package/lib/position/index.js +0 -17
  102. package/lib/signatures/index.d.ts +0 -12
  103. package/lib/signatures/index.js +0 -39
  104. package/lib/signatures/manager.d.ts +0 -10
  105. package/lib/signatures/manager.js +0 -37
  106. package/lib/signatures/permit.d.ts +0 -21
  107. package/lib/signatures/permit.js +0 -101
  108. package/lib/signatures/permit2.d.ts +0 -20
  109. package/lib/signatures/permit2.js +0 -91
  110. package/lib/signatures/types.d.ts +0 -13
  111. package/lib/signatures/types.js +0 -2
  112. package/lib/signatures/utils.d.ts +0 -6
  113. package/lib/signatures/utils.js +0 -44
  114. package/lib/tests/mocks/markets.d.ts +0 -17
  115. package/lib/tests/mocks/markets.js +0 -108
  116. package/lib/token/ERC20Metadata.d.ts +0 -249
  117. package/lib/token/ERC20Metadata.js +0 -81
  118. package/lib/token/Token.d.ts +0 -45
  119. package/lib/token/Token.js +0 -39
  120. package/lib/token/TokenNamespace.d.ts +0 -18
  121. package/lib/token/TokenNamespace.js +0 -55
  122. package/lib/token/WrappedToken.d.ts +0 -42
  123. package/lib/token/WrappedToken.js +0 -87
  124. package/lib/token/index.js +0 -18
  125. package/lib/types.d.ts +0 -29
  126. package/lib/types.js +0 -23
  127. package/lib/user/User.d.ts +0 -20
  128. package/lib/user/User.js +0 -11
  129. package/lib/user/index.js +0 -18
  130. package/lib/user/user.types.d.ts +0 -18
  131. package/lib/user/user.types.js +0 -2
  132. package/lib/vault/Vault.d.ts +0 -167
  133. package/lib/vault/Vault.js +0 -156
  134. package/lib/vault/VaultAllocation.d.ts +0 -38
  135. package/lib/vault/VaultAllocation.js +0 -18
  136. package/lib/vault/VaultConfig.d.ts +0 -23
  137. package/lib/vault/VaultConfig.js +0 -26
  138. package/lib/vault/VaultUtils.d.ts +0 -17
  139. package/lib/vault/VaultUtils.js +0 -17
  140. package/lib/vault/index.js +0 -20
  141. /package/{lib/chain/index.d.ts → src/chain/index.ts} +0 -0
  142. /package/{lib/ethers/index.d.ts → src/ethers/index.ts} +0 -0
  143. /package/{lib/helpers/format/index.d.ts → src/helpers/format/index.ts} +0 -0
  144. /package/{lib/helpers/index.d.ts → src/helpers/index.ts} +0 -0
  145. /package/{lib/holding/index.d.ts → src/holding/index.ts} +0 -0
  146. /package/{lib/market/index.d.ts → src/market/index.ts} +0 -0
  147. /package/{lib/maths/index.d.ts → src/maths/index.ts} +0 -0
  148. /package/{lib/position/index.d.ts → src/position/index.ts} +0 -0
  149. /package/{lib/token/index.d.ts → src/token/index.ts} +0 -0
  150. /package/{lib/user/index.d.ts → src/user/index.ts} +0 -0
  151. /package/{lib/vault/index.d.ts → src/vault/index.ts} +0 -0
@@ -0,0 +1,370 @@
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
+ }
@@ -0,0 +1,58 @@
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
+ }
@@ -0,0 +1,55 @@
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
+ }
@@ -0,0 +1,47 @@
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
+ }
@@ -1,168 +0,0 @@
1
- import { ChainId } from "./chain";
2
- import { Address } from "./types";
3
- /** Address used to replicate an erc20-behaviour for native token.
4
- *
5
- * NB: data might differ from expected onchain native token data
6
- */
7
- export declare const NATIVE_ADDRESS = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
8
- export declare const addresses: {
9
- readonly 5: {
10
- readonly morpho: "0x64c7044050Ba0431252df24fEd4d9635a275CB41";
11
- readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
12
- readonly bundler: "0xCFFbEEAFCD79Fd68FD56Dbc31A419f290A2Fe9e0";
13
- readonly urd: "0x820755E757a590683dc43115290eb1Cb20a60405";
14
- readonly wNative: "0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6";
15
- readonly stEth: "0x1643E812aE58766192Cf7D2Cf9567dF2C37e9B7F";
16
- readonly wstEth: "0x6320cD32aA674d2898A68ec82e869385Fc5f7E2f";
17
- readonly rEth: "0x178E141a0E3b34152f73Ff610437A7bf9B83267A";
18
- readonly sDai: "0xD8134205b0328F5676aaeFb3B2a0DC15f4029d8C";
19
- readonly dai: "0x11fE4B6AE13d2a6055C8D9cF65c55bac32B5d844";
20
- readonly usdc: "0x62bD2A599664D421132d7C54AB4DbE3233f4f0Ae";
21
- readonly usdt: "0x576e379FA7B899b4De1E251e935B31543Df3e954";
22
- };
23
- readonly 1: {
24
- readonly morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb";
25
- readonly adaptiveCurveIrm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC";
26
- readonly publicAllocator: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D";
27
- readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
28
- readonly bundler: "0x4095F064B8d3c3548A3bebfd0Bbfd04750E30077";
29
- readonly aaveV3OptimizerBundler: "0x16F38d2E764E7BeBF625a8E995b34968226D2F9c";
30
- readonly aaveV2Bundler: "0xb3dCc75DB379925edFd3007511A8CE0cB4aa8e76";
31
- readonly aaveV3Bundler: "0x98ccB155E86bb478d514a827d16f58c6912f9BDC";
32
- readonly morphoToken: "0x9994E35Db50125E0DF82e4c2dde62496CE330999";
33
- readonly rEth: "0xae78736Cd615f374D3085123A210448E74Fc6393";
34
- readonly sDai: "0x83F20F44975D03b1b09e64809B757c47f942BEeA";
35
- readonly dai: "0x6B175474E89094C44Da98b954EedeAC495271d0F";
36
- readonly mkr: "0x9f8F72aA9304c8B593d555F12eF6589cC3A579A2";
37
- readonly wstEth: "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0";
38
- readonly wNative: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
39
- readonly stEth: "0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84";
40
- readonly USDe: "0x4c9EDD5852cd905f086C759E8383e09bff1E68B3";
41
- readonly sUSDe: "0x9D39A5DE30e57443BfF2A8307A4256c8797A3497";
42
- readonly bIB01: "0xCA30c93B02514f86d5C86a6e375E3A330B435Fb5";
43
- readonly wbIB01: "0xcA2A7068e551d5C4482eb34880b194E4b945712F";
44
- readonly bC3M: "0x2F123cF3F37CE3328CC9B5b8415f9EC5109b45e7";
45
- readonly wbC3M: "0x95D7337d43340E2721960Dc402D9b9117f0d81a2";
46
- readonly usdc: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
47
- readonly usdt: "0xdAC17F958D2ee523a2206206994597C13D831ec7";
48
- readonly wbtc: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599";
49
- readonly sWise: "0x48C3399719B582dD63eB5AADf12A40B4C3f52FA2";
50
- readonly osEth: "0xf1C9acDc66974dFB6dEcB12aA385b9cD01190E38";
51
- readonly weEth: "0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee";
52
- readonly ezEth: "0xbf5495Efe5DB9ce00f80364C8B423567e58d2110";
53
- readonly pyUsd: "0x6c3ea9036406852006290770BEdFcAbA0e23A0e8";
54
- readonly crvUsd: "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E";
55
- readonly morphoOperator: "0x640428D38189B11B844dAEBDBAAbbdfbd8aE0143";
56
- readonly butterfly: "0xc55126051B22eBb829D00368f4B12Bde432de5Da";
57
- readonly marketRewardsProgramRegistry: "0x5148bF15bb722E1854F66430Bc9FeD0E9FDaCE7D";
58
- readonly timeBoundedUrd: "0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb";
59
- readonly rsEth: "0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7";
60
- readonly "stkcvxcrvUSDTWBTCWETH-morpho": "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278";
61
- readonly crvUSDTWBTCWETH: "0xf5f5B97624542D72A9E06f04804Bf81baA15e2B4";
62
- readonly "stkcvxcrvUSDCWBTCWETH-morpho": "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e";
63
- readonly crvUSDCWBTCWETH: "0x7F86Bf177Dd4F3494b841a37e810A34dD56c829B";
64
- readonly "stkcvxcrvCRVUSDTBTCWSTETH-morpho": "0x3ce8Ec9f3d89aD0A2DdbCC3FDB8991BD241Fc82E";
65
- readonly crvCRVUSDTBTCWSTETH: "0x2889302a794dA87fBF1D6Db415C1492194663D13";
66
- readonly "stkcvxTryLSD-morpho": "0x6BA072F0d22806F2C52e9792AF47f2D59103BEBE";
67
- readonly tryLSD: "0x2570f1bD5D2735314FC102eb12Fc1aFe9e6E7193";
68
- readonly "stkcvxcrvUSDETHCRV-morpho": "0xAc904BAfBb5FB04Deb2b6198FdCEedE75a78Ce5a";
69
- readonly crvUSDETHCRV: "0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14";
70
- };
71
- readonly 8453: {
72
- readonly morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb";
73
- readonly permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3";
74
- readonly bundler: "0xb5D342521EB5b983aE6a6324A4D9eac87C9D1987";
75
- readonly wNative: "0x4200000000000000000000000000000000000006";
76
- readonly adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687";
77
- readonly publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467";
78
- readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
79
- readonly cbEth: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22";
80
- };
81
- };
82
- interface ChainAddresses {
83
- morpho: Address;
84
- permit2: Address;
85
- bundler: Address;
86
- wNative: Address;
87
- adaptiveCurveIrm?: Address;
88
- publicAllocator?: Address;
89
- morphoToken?: Address;
90
- wstEth?: Address;
91
- stEth?: Address;
92
- dai?: Address;
93
- mkr?: Address;
94
- rEth?: Address;
95
- sDai?: Address;
96
- usdc?: Address;
97
- usdt?: Address;
98
- bIB01?: Address;
99
- wbIB01?: Address;
100
- bC3M?: Address;
101
- wbC3M?: Address;
102
- wbtc?: Address;
103
- sWise?: Address;
104
- osEth?: Address;
105
- weEth?: Address;
106
- ezEth?: Address;
107
- pyUsd?: Address;
108
- sUSDe?: Address;
109
- USDe?: Address;
110
- marketRewardsProgramRegistry?: Address;
111
- timeBoundedUrd?: Address;
112
- rsEth?: Address;
113
- crvUsd?: Address;
114
- morphoOperator?: Address;
115
- butterfly?: Address;
116
- aaveV3OptimizerBundler?: Address;
117
- aaveV2Bundler?: Address;
118
- aaveV3Bundler?: Address;
119
- "stkcvxcrvUSDTWBTCWETH-morpho"?: Address;
120
- crvUSDTWBTCWETH?: Address;
121
- "stkcvxcrvUSDCWBTCWETH-morpho"?: Address;
122
- crvUSDCWBTCWETH?: Address;
123
- "stkcvxcrvCRVUSDTBTCWSTETH-morpho"?: Address;
124
- crvCRVUSDTBTCWSTETH?: Address;
125
- "stkcvxTryLSD-morpho"?: Address;
126
- tryLSD?: Address;
127
- "stkcvxcrvUSDETHCRV-morpho"?: Address;
128
- crvUSDETHCRV?: Address;
129
- }
130
- export type AddressLabel = keyof (typeof addresses)[ChainId];
131
- declare const _default: {
132
- 1: ChainAddresses;
133
- 5: ChainAddresses;
134
- 8453: ChainAddresses;
135
- };
136
- export default _default;
137
- export declare const getChainAddresses: (chainId: number) => ChainAddresses;
138
- export declare const wrapping: {
139
- [n in ChainId]: {
140
- [unwrapped: string]: string;
141
- };
142
- };
143
- export declare const reverseWrapping: {
144
- 1: {
145
- [unwrapped: string]: string;
146
- };
147
- 5: {
148
- [unwrapped: string]: string;
149
- };
150
- 8453: {
151
- [unwrapped: string]: string;
152
- };
153
- };
154
- export declare function getUnwrappedToken(wrappedToken: Address, chainId: ChainId): string | undefined;
155
- export declare function getWrappedToken(unWrappedToken: Address, chainId: ChainId): string | undefined;
156
- export declare const erc20WrapperTokens: {
157
- [id in ChainId]: Set<Address>;
158
- };
159
- export declare const wrappedBackedTokens: {
160
- [id in ChainId]: Set<Address>;
161
- };
162
- export declare const getWrappedBackedTokens: (chainId: number) => Set<string>;
163
- /** /!\ These tokens can not be listed in `erc20WrapperTokens` because the following specs are different:
164
- * - calling `depositFor` supplies on blue instead of minting wrapped token to the user
165
- */
166
- export declare const convexWrapperTokens: {
167
- [id in ChainId]: Set<Address>;
168
- };