@morpho-org/blue-sdk 2.0.0-next.17 → 2.0.0-next.19
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.
- package/lib/addresses.js +62 -57
- package/lib/chain.js +9 -6
- package/lib/constants.js +12 -9
- package/lib/errors.js +19 -9
- package/lib/holding/AssetBalances.js +5 -1
- package/lib/holding/Holding.js +9 -5
- package/lib/holding/index.js +18 -2
- package/lib/index.js +28 -12
- package/lib/market/Market.js +51 -47
- package/lib/market/MarketParams.js +14 -10
- package/lib/market/MarketUtils.js +45 -42
- package/lib/market/index.js +19 -3
- package/lib/math/AdaptiveCurveIrmLib.js +25 -22
- package/lib/math/MathLib.js +11 -8
- package/lib/math/SharesMath.js +8 -5
- package/lib/math/index.js +19 -3
- package/lib/position/Position.js +17 -12
- package/lib/position/index.js +17 -1
- package/lib/token/ConstantWrappedToken.js +9 -5
- package/lib/token/ExchangeRateWrappedToken.js +9 -5
- package/lib/token/Token.js +12 -8
- package/lib/token/VaultToken.js +9 -5
- package/lib/token/WrappedToken.js +11 -7
- package/lib/token/index.js +21 -5
- package/lib/types.js +9 -4
- package/lib/user/User.js +5 -1
- package/lib/user/index.js +17 -1
- package/lib/vault/Vault.js +23 -18
- package/lib/vault/VaultConfig.js +7 -3
- package/lib/vault/VaultMarketAllocation.js +8 -4
- package/lib/vault/VaultMarketConfig.js +5 -1
- package/lib/vault/VaultMarketPublicAllocatorConfig.js +5 -1
- package/lib/vault/VaultUser.js +5 -1
- package/lib/vault/VaultUtils.js +9 -6
- package/lib/vault/index.js +23 -7
- package/package.json +5 -13
package/lib/vault/Vault.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVault = exports.Vault = void 0;
|
|
4
|
+
const index_js_1 = require("../market/index.js");
|
|
5
|
+
const index_js_2 = require("../math/index.js");
|
|
6
|
+
const index_js_3 = require("../token/index.js");
|
|
7
|
+
const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
|
|
8
|
+
class Vault extends index_js_3.VaultToken {
|
|
6
9
|
/**
|
|
7
10
|
* The MetaMorpho vault's owner address.
|
|
8
11
|
*/
|
|
@@ -83,7 +86,7 @@ export class Vault extends VaultToken {
|
|
|
83
86
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
84
87
|
*/
|
|
85
88
|
get totalInterest() {
|
|
86
|
-
return MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
89
|
+
return index_js_2.MathLib.zeroFloorSub(this.totalAssets, this.lastTotalAssets);
|
|
87
90
|
}
|
|
88
91
|
toAssets(shares, rounding) {
|
|
89
92
|
return this._unwrap(shares, rounding);
|
|
@@ -92,7 +95,8 @@ export class Vault extends VaultToken {
|
|
|
92
95
|
return this._wrap(assets, rounding);
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
|
|
98
|
+
exports.Vault = Vault;
|
|
99
|
+
class AccrualVault extends Vault {
|
|
96
100
|
/**
|
|
97
101
|
* The allocation of the vault on each market enabled.
|
|
98
102
|
*/
|
|
@@ -114,7 +118,7 @@ export class AccrualVault extends Vault {
|
|
|
114
118
|
});
|
|
115
119
|
this.allocations = new Map(allocations.map((allocation) => [
|
|
116
120
|
allocation.position.market.id,
|
|
117
|
-
new VaultMarketAllocation(allocation),
|
|
121
|
+
new VaultMarketAllocation_js_1.VaultMarketAllocation(allocation),
|
|
118
122
|
]));
|
|
119
123
|
this.collateralAllocations = new Map();
|
|
120
124
|
for (const { marketId, position } of this.allocations.values()) {
|
|
@@ -156,7 +160,7 @@ export class AccrualVault extends Vault {
|
|
|
156
160
|
* The MetaMorpho vault's average APY on its assets, excluding the performance fee.
|
|
157
161
|
*/
|
|
158
162
|
get netApy() {
|
|
159
|
-
return MathLib.wMulDown(this.avgApy, MathLib.WAD - this.fee);
|
|
163
|
+
return index_js_2.MathLib.wMulDown(this.avgApy, index_js_2.MathLib.WAD - this.fee);
|
|
160
164
|
}
|
|
161
165
|
getAllocationProportion(marketId) {
|
|
162
166
|
if (this.totalAssets === 0n)
|
|
@@ -164,23 +168,23 @@ export class AccrualVault extends Vault {
|
|
|
164
168
|
const allocation = this.allocations.get(marketId);
|
|
165
169
|
if (!allocation)
|
|
166
170
|
return 0n;
|
|
167
|
-
return MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
171
|
+
return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
168
172
|
}
|
|
169
173
|
getDepositCapacityLimit(assets) {
|
|
170
174
|
const suppliable = this.allocations
|
|
171
175
|
.values()
|
|
172
|
-
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => MathLib.min(total +
|
|
176
|
+
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
|
|
173
177
|
(this.supplyQueue.includes(marketId)
|
|
174
|
-
? MathLib.zeroFloorSub(cap, supplyAssets)
|
|
175
|
-
: 0n), MathLib.MAX_UINT_256), 0n);
|
|
178
|
+
? index_js_2.MathLib.zeroFloorSub(cap, supplyAssets)
|
|
179
|
+
: 0n), index_js_2.MathLib.MAX_UINT_256), 0n);
|
|
176
180
|
if (assets > suppliable)
|
|
177
181
|
return {
|
|
178
182
|
value: suppliable,
|
|
179
|
-
limiter: CapacityLimitReason.cap,
|
|
183
|
+
limiter: index_js_1.CapacityLimitReason.cap,
|
|
180
184
|
};
|
|
181
185
|
return {
|
|
182
186
|
value: assets,
|
|
183
|
-
limiter: CapacityLimitReason.balance,
|
|
187
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
184
188
|
};
|
|
185
189
|
}
|
|
186
190
|
getWithdrawCapacityLimit(shares) {
|
|
@@ -189,11 +193,11 @@ export class AccrualVault extends Vault {
|
|
|
189
193
|
if (assets > liquidity)
|
|
190
194
|
return {
|
|
191
195
|
value: liquidity,
|
|
192
|
-
limiter: CapacityLimitReason.liquidity,
|
|
196
|
+
limiter: index_js_1.CapacityLimitReason.liquidity,
|
|
193
197
|
};
|
|
194
198
|
return {
|
|
195
199
|
value: assets,
|
|
196
|
-
limiter: CapacityLimitReason.balance,
|
|
200
|
+
limiter: index_js_1.CapacityLimitReason.balance,
|
|
197
201
|
};
|
|
198
202
|
}
|
|
199
203
|
/**
|
|
@@ -210,7 +214,7 @@ export class AccrualVault extends Vault {
|
|
|
210
214
|
position: position.accrueInterest(timestamp),
|
|
211
215
|
};
|
|
212
216
|
}));
|
|
213
|
-
const feeAssets = MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
217
|
+
const feeAssets = index_js_2.MathLib.wMulDown(vault.totalInterest, vault.fee);
|
|
214
218
|
vault.totalAssets -= feeAssets;
|
|
215
219
|
const feeShares = vault.toShares(feeAssets, "Down");
|
|
216
220
|
vault.totalAssets += feeAssets;
|
|
@@ -219,3 +223,4 @@ export class AccrualVault extends Vault {
|
|
|
219
223
|
return vault;
|
|
220
224
|
}
|
|
221
225
|
}
|
|
226
|
+
exports.AccrualVault = AccrualVault;
|
package/lib/vault/VaultConfig.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultConfig = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
|
+
class VaultConfig {
|
|
3
6
|
chainId;
|
|
4
7
|
static _CACHE = {};
|
|
5
8
|
static get(address, chainId) {
|
|
6
9
|
const config = VaultConfig._CACHE[chainId]?.[address];
|
|
7
10
|
if (!config)
|
|
8
|
-
throw new UnknownVaultConfigError(address);
|
|
11
|
+
throw new errors_js_1.UnknownVaultConfigError(address);
|
|
9
12
|
return config;
|
|
10
13
|
}
|
|
11
14
|
address;
|
|
@@ -26,3 +29,4 @@ export class VaultConfig {
|
|
|
26
29
|
(VaultConfig._CACHE[chainId] ??= {})[address] = this;
|
|
27
30
|
}
|
|
28
31
|
}
|
|
32
|
+
exports.VaultConfig = VaultConfig;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultMarketAllocation = void 0;
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
|
+
class VaultMarketAllocation {
|
|
3
6
|
/**
|
|
4
7
|
* The vault's configuration on the corresponding market.
|
|
5
8
|
*/
|
|
@@ -20,7 +23,8 @@ export class VaultMarketAllocation {
|
|
|
20
23
|
}
|
|
21
24
|
get utilization() {
|
|
22
25
|
if (this.config.cap === 0n)
|
|
23
|
-
return MathLib.MAX_UINT_256;
|
|
24
|
-
return MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
26
|
+
return index_js_1.MathLib.MAX_UINT_256;
|
|
27
|
+
return index_js_1.MathLib.wDivDown(this.position.supplyAssets, this.config.cap);
|
|
25
28
|
}
|
|
26
29
|
}
|
|
30
|
+
exports.VaultMarketAllocation = VaultMarketAllocation;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultMarketConfig = void 0;
|
|
4
|
+
class VaultMarketConfig {
|
|
2
5
|
/**
|
|
3
6
|
* The vault's address.
|
|
4
7
|
*/
|
|
@@ -37,3 +40,4 @@ export class VaultMarketConfig {
|
|
|
37
40
|
this.publicAllocatorConfig = publicAllocatorConfig;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
exports.VaultMarketConfig = VaultMarketConfig;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultMarketPublicAllocatorConfig = void 0;
|
|
4
|
+
class VaultMarketPublicAllocatorConfig {
|
|
2
5
|
/**
|
|
3
6
|
* The vault's address.
|
|
4
7
|
*/
|
|
@@ -22,3 +25,4 @@ export class VaultMarketPublicAllocatorConfig {
|
|
|
22
25
|
this.maxOut = maxOut;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.VaultMarketPublicAllocatorConfig = VaultMarketPublicAllocatorConfig;
|
package/lib/vault/VaultUser.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultUser = void 0;
|
|
4
|
+
class VaultUser {
|
|
2
5
|
/**
|
|
3
6
|
* The vault's address.
|
|
4
7
|
*/
|
|
@@ -22,3 +25,4 @@ export class VaultUser {
|
|
|
22
25
|
this.allowance = allowance;
|
|
23
26
|
}
|
|
24
27
|
}
|
|
28
|
+
exports.VaultUser = VaultUser;
|
package/lib/vault/VaultUtils.js
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultUtils = void 0;
|
|
4
|
+
const index_js_1 = require("../math/index.js");
|
|
5
|
+
var VaultUtils;
|
|
3
6
|
(function (VaultUtils) {
|
|
4
7
|
VaultUtils.VIRTUAL_ASSETS = 1n;
|
|
5
8
|
function decimalsOffset(decimals) {
|
|
6
|
-
return MathLib.zeroFloorSub(18n, decimals);
|
|
9
|
+
return index_js_1.MathLib.zeroFloorSub(18n, decimals);
|
|
7
10
|
}
|
|
8
11
|
VaultUtils.decimalsOffset = decimalsOffset;
|
|
9
12
|
function toAssets(shares, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Down") {
|
|
10
|
-
return MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
|
|
13
|
+
return index_js_1.MathLib.mulDiv(shares, BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), rounding);
|
|
11
14
|
}
|
|
12
15
|
VaultUtils.toAssets = toAssets;
|
|
13
16
|
function toShares(assets, { totalAssets, totalSupply, decimalsOffset, }, rounding = "Up") {
|
|
14
|
-
return MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
|
|
17
|
+
return index_js_1.MathLib.mulDiv(assets, BigInt(totalSupply) + 10n ** BigInt(decimalsOffset), BigInt(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
|
|
15
18
|
}
|
|
16
19
|
VaultUtils.toShares = toShares;
|
|
17
|
-
})(VaultUtils || (VaultUtils = {}));
|
|
20
|
+
})(VaultUtils || (exports.VaultUtils = VaultUtils = {}));
|
package/lib/vault/index.js
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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("./VaultUtils.js"), exports);
|
|
18
|
+
__exportStar(require("./VaultConfig.js"), exports);
|
|
19
|
+
__exportStar(require("./VaultMarketAllocation.js"), exports);
|
|
20
|
+
__exportStar(require("./VaultMarketConfig.js"), exports);
|
|
21
|
+
__exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
|
|
22
|
+
__exportStar(require("./VaultUser.js"), exports);
|
|
23
|
+
__exportStar(require("./Vault.js"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morpho-org/blue-sdk",
|
|
3
3
|
"description": "Framework-agnostic package that defines Morpho-related entity classes (such as `Market`, `Token`, `Vault`).",
|
|
4
|
-
"version": "2.0.0-next.
|
|
4
|
+
"version": "2.0.0-next.19",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"email": "contact@morpho.org"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"type": "module",
|
|
17
16
|
"main": "lib/index.js",
|
|
18
17
|
"files": [
|
|
19
18
|
"lib"
|
|
@@ -22,27 +21,20 @@
|
|
|
22
21
|
"@noble/hashes": "^1.5.0"
|
|
23
22
|
},
|
|
24
23
|
"peerDependencies": {
|
|
25
|
-
"@morpho-org/morpho-ts": "^2.0.0-next.
|
|
24
|
+
"@morpho-org/morpho-ts": "^2.0.0-next.10"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
27
|
"@types/node": "^22.7.8",
|
|
29
28
|
"typescript": "^5.6.3",
|
|
30
29
|
"viem": "^2.21.32",
|
|
31
|
-
"viem-deal": "^2.0.1",
|
|
32
30
|
"vitest": "^2.1.3",
|
|
33
|
-
"@morpho-org/morpho-ts": "^2.0.0-next.
|
|
34
|
-
"@morpho-org/test": "^2.0.0-next.
|
|
31
|
+
"@morpho-org/morpho-ts": "^2.0.0-next.10",
|
|
32
|
+
"@morpho-org/test": "^2.0.0-next.16"
|
|
35
33
|
},
|
|
36
34
|
"scripts": {
|
|
37
35
|
"prepublish": "$npm_execpath build",
|
|
38
36
|
"build": "tsc --build tsconfig.build.json",
|
|
39
37
|
"test": "vitest"
|
|
40
38
|
},
|
|
41
|
-
"types": "lib/index.d.ts"
|
|
42
|
-
"exports": {
|
|
43
|
-
".": {
|
|
44
|
-
"types": "./lib/index.d.ts",
|
|
45
|
-
"default": "./lib/index.js"
|
|
46
|
-
}
|
|
47
|
-
}
|
|
39
|
+
"types": "lib/index.d.ts"
|
|
48
40
|
}
|