@morpho-org/blue-sdk 5.4.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/addresses.d.ts +68 -0
- package/lib/addresses.js +37 -0
- package/lib/chain.d.ts +12 -0
- package/lib/chain.js +8 -0
- package/lib/errors.d.ts +21 -0
- package/lib/errors.js +40 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/market/Market.d.ts +1 -11
- package/lib/market/Market.js +12 -19
- package/lib/market/MarketParams.d.ts +21 -0
- package/lib/market/MarketParams.js +21 -1
- package/lib/position/Position.d.ts +4 -4
- package/lib/position/Position.js +3 -2
- package/lib/token/VaultToken.d.ts +3 -3
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +13 -0
- package/lib/vault/Vault.d.ts +24 -4
- package/lib/vault/Vault.js +31 -5
- package/lib/vault/index.d.ts +1 -0
- package/lib/vault/index.js +1 -0
- package/lib/vault/v2/VaultV2.d.ts +87 -0
- package/lib/vault/v2/VaultV2.js +159 -0
- package/lib/vault/v2/VaultV2Adapter.d.ts +29 -0
- package/lib/vault/v2/VaultV2Adapter.js +16 -0
- package/lib/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +30 -0
- package/lib/vault/v2/VaultV2MorphoMarketV1Adapter.js +59 -0
- package/lib/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +24 -0
- package/lib/vault/v2/VaultV2MorphoVaultV1Adapter.js +41 -0
- package/lib/vault/v2/index.d.ts +4 -0
- package/lib/vault/v2/index.js +20 -0
- package/package.json +5 -5
package/lib/addresses.d.ts
CHANGED
|
@@ -450,6 +450,24 @@ declare const _addressesRegistry: {
|
|
|
450
450
|
readonly preLiquidationFactory: "0x534858821653467c2ae231dc027aa1F2c8D91802";
|
|
451
451
|
readonly wNative: "0x1Cd0690fF9a693f5EF2dD976660a8dAFc81A109c";
|
|
452
452
|
};
|
|
453
|
+
readonly 59144: {
|
|
454
|
+
readonly morpho: "0x6B0D716aC0A45536172308e08fC2C40387262c9F";
|
|
455
|
+
readonly bundler3: {
|
|
456
|
+
readonly bundler3: "0x1Ee8Ec299E8014760D50A4E3CfC3b44Cc2242625";
|
|
457
|
+
readonly generalAdapter1: "0x454dAb6ce9891245696b239b4845a1cDC268255d";
|
|
458
|
+
};
|
|
459
|
+
readonly adaptiveCurveIrm: "0x85C2Ef4Bd69f42D7Da19Fb9dcdD7Fb8d0F59cDeE";
|
|
460
|
+
readonly publicAllocator: "0x2d4cf00e18D48fD030d9b1E2FAAE6e0384C7610B";
|
|
461
|
+
readonly metaMorphoFactory: "0xA148a8223B622A72dC36472DE1492aBb5c089BA7";
|
|
462
|
+
readonly vaultV2Factory: "0x5DC11CF8BA4C39d1194F91218D35008d9F52A5d0";
|
|
463
|
+
readonly morphoMarketV1AdapterFactory: "0x3267BbdC94274B4BE081c01ffc6123dA12E8c043";
|
|
464
|
+
readonly morphoVaultV1AdapterFactory: "0x6FaF26DD640e22457cA4fd5DA702BA3E169eEd87";
|
|
465
|
+
readonly registryList: "0x122Ea8ff8888C29F8736665d576e3fAEF15D27D5";
|
|
466
|
+
readonly chainlinkOracleFactory: "0x3FFF726062B03BfD5BC485eeEEcc92CF1d8F0105";
|
|
467
|
+
readonly preLiquidationFactory: "0x05a0Ff4E564ED1ba6B42247E19edFf83545C3C40";
|
|
468
|
+
readonly wNative: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f";
|
|
469
|
+
readonly usdc: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff";
|
|
470
|
+
};
|
|
453
471
|
readonly 143: {
|
|
454
472
|
readonly morpho: "0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee";
|
|
455
473
|
readonly bundler3: {
|
|
@@ -816,6 +834,22 @@ declare const _deployments: {
|
|
|
816
834
|
readonly chainlinkOracleFactory: 7526768n;
|
|
817
835
|
readonly preLiquidationFactory: 7527649n;
|
|
818
836
|
};
|
|
837
|
+
readonly 59144: {
|
|
838
|
+
readonly morpho: 25072608n;
|
|
839
|
+
readonly bundler3: {
|
|
840
|
+
readonly bundler3: 25072853n;
|
|
841
|
+
readonly generalAdapter1: 25072853n;
|
|
842
|
+
};
|
|
843
|
+
readonly adaptiveCurveIrm: 25072608n;
|
|
844
|
+
readonly publicAllocator: 25072608n;
|
|
845
|
+
readonly metaMorphoFactory: 25072665n;
|
|
846
|
+
readonly vaultV2Factory: 25072951n;
|
|
847
|
+
readonly morphoMarketV1AdapterFactory: 25072951n;
|
|
848
|
+
readonly morphoVaultV1AdapterFactory: 25072951n;
|
|
849
|
+
readonly registryList: 25073088n;
|
|
850
|
+
readonly chainlinkOracleFactory: 25072665n;
|
|
851
|
+
readonly preLiquidationFactory: 25072853n;
|
|
852
|
+
};
|
|
819
853
|
readonly 143: {
|
|
820
854
|
readonly morpho: 31907457n;
|
|
821
855
|
readonly bundler3: {
|
|
@@ -1267,6 +1301,24 @@ export declare let addressesRegistry: {
|
|
|
1267
1301
|
readonly preLiquidationFactory: "0x534858821653467c2ae231dc027aa1F2c8D91802";
|
|
1268
1302
|
readonly wNative: "0x1Cd0690fF9a693f5EF2dD976660a8dAFc81A109c";
|
|
1269
1303
|
};
|
|
1304
|
+
readonly 59144: {
|
|
1305
|
+
readonly morpho: "0x6B0D716aC0A45536172308e08fC2C40387262c9F";
|
|
1306
|
+
readonly bundler3: {
|
|
1307
|
+
readonly bundler3: "0x1Ee8Ec299E8014760D50A4E3CfC3b44Cc2242625";
|
|
1308
|
+
readonly generalAdapter1: "0x454dAb6ce9891245696b239b4845a1cDC268255d";
|
|
1309
|
+
};
|
|
1310
|
+
readonly adaptiveCurveIrm: "0x85C2Ef4Bd69f42D7Da19Fb9dcdD7Fb8d0F59cDeE";
|
|
1311
|
+
readonly publicAllocator: "0x2d4cf00e18D48fD030d9b1E2FAAE6e0384C7610B";
|
|
1312
|
+
readonly metaMorphoFactory: "0xA148a8223B622A72dC36472DE1492aBb5c089BA7";
|
|
1313
|
+
readonly vaultV2Factory: "0x5DC11CF8BA4C39d1194F91218D35008d9F52A5d0";
|
|
1314
|
+
readonly morphoMarketV1AdapterFactory: "0x3267BbdC94274B4BE081c01ffc6123dA12E8c043";
|
|
1315
|
+
readonly morphoVaultV1AdapterFactory: "0x6FaF26DD640e22457cA4fd5DA702BA3E169eEd87";
|
|
1316
|
+
readonly registryList: "0x122Ea8ff8888C29F8736665d576e3fAEF15D27D5";
|
|
1317
|
+
readonly chainlinkOracleFactory: "0x3FFF726062B03BfD5BC485eeEEcc92CF1d8F0105";
|
|
1318
|
+
readonly preLiquidationFactory: "0x05a0Ff4E564ED1ba6B42247E19edFf83545C3C40";
|
|
1319
|
+
readonly wNative: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f";
|
|
1320
|
+
readonly usdc: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff";
|
|
1321
|
+
};
|
|
1270
1322
|
readonly 143: {
|
|
1271
1323
|
readonly morpho: "0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee";
|
|
1272
1324
|
readonly bundler3: {
|
|
@@ -1631,6 +1683,22 @@ export declare let deployments: {
|
|
|
1631
1683
|
readonly chainlinkOracleFactory: 7526768n;
|
|
1632
1684
|
readonly preLiquidationFactory: 7527649n;
|
|
1633
1685
|
};
|
|
1686
|
+
readonly 59144: {
|
|
1687
|
+
readonly morpho: 25072608n;
|
|
1688
|
+
readonly bundler3: {
|
|
1689
|
+
readonly bundler3: 25072853n;
|
|
1690
|
+
readonly generalAdapter1: 25072853n;
|
|
1691
|
+
};
|
|
1692
|
+
readonly adaptiveCurveIrm: 25072608n;
|
|
1693
|
+
readonly publicAllocator: 25072608n;
|
|
1694
|
+
readonly metaMorphoFactory: 25072665n;
|
|
1695
|
+
readonly vaultV2Factory: 25072951n;
|
|
1696
|
+
readonly morphoMarketV1AdapterFactory: 25072951n;
|
|
1697
|
+
readonly morphoVaultV1AdapterFactory: 25072951n;
|
|
1698
|
+
readonly registryList: 25073088n;
|
|
1699
|
+
readonly chainlinkOracleFactory: 25072665n;
|
|
1700
|
+
readonly preLiquidationFactory: 25072853n;
|
|
1701
|
+
};
|
|
1634
1702
|
readonly 143: {
|
|
1635
1703
|
readonly morpho: 31907457n;
|
|
1636
1704
|
readonly bundler3: {
|
package/lib/addresses.js
CHANGED
|
@@ -439,6 +439,24 @@ const _addressesRegistry = {
|
|
|
439
439
|
preLiquidationFactory: "0x534858821653467c2ae231dc027aa1F2c8D91802",
|
|
440
440
|
wNative: "0x1Cd0690fF9a693f5EF2dD976660a8dAFc81A109c",
|
|
441
441
|
},
|
|
442
|
+
[chain_js_1.ChainId.LineaMainnet]: {
|
|
443
|
+
morpho: "0x6B0D716aC0A45536172308e08fC2C40387262c9F",
|
|
444
|
+
bundler3: {
|
|
445
|
+
bundler3: "0x1Ee8Ec299E8014760D50A4E3CfC3b44Cc2242625",
|
|
446
|
+
generalAdapter1: "0x454dAb6ce9891245696b239b4845a1cDC268255d",
|
|
447
|
+
},
|
|
448
|
+
adaptiveCurveIrm: "0x85C2Ef4Bd69f42D7Da19Fb9dcdD7Fb8d0F59cDeE",
|
|
449
|
+
publicAllocator: "0x2d4cf00e18D48fD030d9b1E2FAAE6e0384C7610B",
|
|
450
|
+
metaMorphoFactory: "0xA148a8223B622A72dC36472DE1492aBb5c089BA7",
|
|
451
|
+
vaultV2Factory: "0x5DC11CF8BA4C39d1194F91218D35008d9F52A5d0",
|
|
452
|
+
morphoMarketV1AdapterFactory: "0x3267BbdC94274B4BE081c01ffc6123dA12E8c043",
|
|
453
|
+
morphoVaultV1AdapterFactory: "0x6FaF26DD640e22457cA4fd5DA702BA3E169eEd87",
|
|
454
|
+
registryList: "0x122Ea8ff8888C29F8736665d576e3fAEF15D27D5",
|
|
455
|
+
chainlinkOracleFactory: "0x3FFF726062B03BfD5BC485eeEEcc92CF1d8F0105",
|
|
456
|
+
preLiquidationFactory: "0x05a0Ff4E564ED1ba6B42247E19edFf83545C3C40",
|
|
457
|
+
wNative: "0xe5D7C2a44FfDDf6b295A15c148167daaAf5Cf34f",
|
|
458
|
+
usdc: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff",
|
|
459
|
+
},
|
|
442
460
|
[chain_js_1.ChainId.MonadMainnet]: {
|
|
443
461
|
morpho: "0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee",
|
|
444
462
|
bundler3: {
|
|
@@ -802,6 +820,22 @@ const _deployments = {
|
|
|
802
820
|
chainlinkOracleFactory: 7526768n,
|
|
803
821
|
preLiquidationFactory: 7527649n,
|
|
804
822
|
},
|
|
823
|
+
[chain_js_1.ChainId.LineaMainnet]: {
|
|
824
|
+
morpho: 25072608n,
|
|
825
|
+
bundler3: {
|
|
826
|
+
bundler3: 25072853n,
|
|
827
|
+
generalAdapter1: 25072853n,
|
|
828
|
+
},
|
|
829
|
+
adaptiveCurveIrm: 25072608n,
|
|
830
|
+
publicAllocator: 25072608n,
|
|
831
|
+
metaMorphoFactory: 25072665n,
|
|
832
|
+
vaultV2Factory: 25072951n,
|
|
833
|
+
morphoMarketV1AdapterFactory: 25072951n,
|
|
834
|
+
morphoVaultV1AdapterFactory: 25072951n,
|
|
835
|
+
registryList: 25073088n,
|
|
836
|
+
chainlinkOracleFactory: 25072665n,
|
|
837
|
+
preLiquidationFactory: 25072853n,
|
|
838
|
+
},
|
|
805
839
|
[chain_js_1.ChainId.MonadMainnet]: {
|
|
806
840
|
morpho: 31907457n,
|
|
807
841
|
bundler3: {
|
|
@@ -910,6 +944,9 @@ const _unwrappedTokensMapping = {
|
|
|
910
944
|
[chain_js_1.ChainId.ZeroGMainnet]: {
|
|
911
945
|
[_addressesRegistry[chain_js_1.ChainId.ZeroGMainnet].wNative]: exports.NATIVE_ADDRESS,
|
|
912
946
|
},
|
|
947
|
+
[chain_js_1.ChainId.LineaMainnet]: {
|
|
948
|
+
[_addressesRegistry[chain_js_1.ChainId.LineaMainnet].wNative]: exports.NATIVE_ADDRESS,
|
|
949
|
+
},
|
|
913
950
|
[chain_js_1.ChainId.MonadMainnet]: {
|
|
914
951
|
[_addressesRegistry[chain_js_1.ChainId.MonadMainnet].wNative]: exports.NATIVE_ADDRESS,
|
|
915
952
|
},
|
package/lib/chain.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare enum ChainId {
|
|
|
22
22
|
HyperliquidMainnet = 999,
|
|
23
23
|
SeiMainnet = 1329,
|
|
24
24
|
ZeroGMainnet = 16661,
|
|
25
|
+
LineaMainnet = 59144,
|
|
25
26
|
MonadMainnet = 143
|
|
26
27
|
}
|
|
27
28
|
export interface ChainMetadata {
|
|
@@ -294,6 +295,17 @@ export declare namespace ChainUtils {
|
|
|
294
295
|
explorerUrl: string;
|
|
295
296
|
identifier: string;
|
|
296
297
|
};
|
|
298
|
+
59144: {
|
|
299
|
+
name: string;
|
|
300
|
+
id: ChainId.LineaMainnet;
|
|
301
|
+
nativeCurrency: {
|
|
302
|
+
name: string;
|
|
303
|
+
symbol: string;
|
|
304
|
+
decimals: number;
|
|
305
|
+
};
|
|
306
|
+
explorerUrl: string;
|
|
307
|
+
identifier: string;
|
|
308
|
+
};
|
|
297
309
|
143: {
|
|
298
310
|
name: string;
|
|
299
311
|
id: ChainId.MonadMainnet;
|
package/lib/chain.js
CHANGED
|
@@ -26,6 +26,7 @@ var ChainId;
|
|
|
26
26
|
ChainId[ChainId["HyperliquidMainnet"] = 999] = "HyperliquidMainnet";
|
|
27
27
|
ChainId[ChainId["SeiMainnet"] = 1329] = "SeiMainnet";
|
|
28
28
|
ChainId[ChainId["ZeroGMainnet"] = 16661] = "ZeroGMainnet";
|
|
29
|
+
ChainId[ChainId["LineaMainnet"] = 59144] = "LineaMainnet";
|
|
29
30
|
ChainId[ChainId["MonadMainnet"] = 143] = "MonadMainnet";
|
|
30
31
|
})(ChainId || (exports.ChainId = ChainId = {}));
|
|
31
32
|
var ChainUtils;
|
|
@@ -204,6 +205,13 @@ var ChainUtils;
|
|
|
204
205
|
explorerUrl: "https://chainscan.0g.ai",
|
|
205
206
|
identifier: "0G",
|
|
206
207
|
},
|
|
208
|
+
[ChainId.LineaMainnet]: {
|
|
209
|
+
name: "Linea",
|
|
210
|
+
id: ChainId.LineaMainnet,
|
|
211
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
212
|
+
explorerUrl: "https://lineascan.build",
|
|
213
|
+
identifier: "linea",
|
|
214
|
+
},
|
|
207
215
|
[ChainId.MonadMainnet]: {
|
|
208
216
|
name: "Monad",
|
|
209
217
|
id: ChainId.MonadMainnet,
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
1
2
|
import type { Address, MarketId } from "./types.js";
|
|
3
|
+
export declare class InvalidMarketParamsError extends Error {
|
|
4
|
+
readonly data: Hex;
|
|
5
|
+
constructor(data: Hex);
|
|
6
|
+
}
|
|
2
7
|
export declare class UnknownDataError extends Error {
|
|
3
8
|
}
|
|
4
9
|
export declare class UnknownTokenError extends UnknownDataError {
|
|
@@ -25,6 +30,10 @@ export declare class UnsupportedPreLiquidationParamsError extends Error {
|
|
|
25
30
|
readonly lltv: bigint;
|
|
26
31
|
constructor(lltv: bigint);
|
|
27
32
|
}
|
|
33
|
+
export declare class UnsupportedVaultV2AdapterError extends Error {
|
|
34
|
+
readonly address: Address;
|
|
35
|
+
constructor(address: Address);
|
|
36
|
+
}
|
|
28
37
|
export declare namespace BlueErrors {
|
|
29
38
|
class AlreadySet extends Error {
|
|
30
39
|
readonly name: string;
|
|
@@ -65,6 +74,18 @@ export declare namespace BlueErrors {
|
|
|
65
74
|
constructor(deadline: bigint);
|
|
66
75
|
}
|
|
67
76
|
}
|
|
77
|
+
export declare namespace VaultV2Errors {
|
|
78
|
+
class InvalidInterestAccrual extends Error {
|
|
79
|
+
readonly vault: Address;
|
|
80
|
+
readonly timestamp: bigint;
|
|
81
|
+
readonly lastUpdate: bigint;
|
|
82
|
+
constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
|
|
83
|
+
}
|
|
84
|
+
class UnsupportedLiquidityAdapter extends Error {
|
|
85
|
+
readonly address: Address;
|
|
86
|
+
constructor(address: Address);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
68
89
|
export interface ErrorClass<E extends Error> {
|
|
69
90
|
new (...args: any[]): E;
|
|
70
91
|
}
|
package/lib/errors.js
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BlueErrors = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
|
|
3
|
+
exports.VaultV2Errors = exports.BlueErrors = exports.UnsupportedVaultV2AdapterError = exports.UnsupportedPreLiquidationParamsError = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketParamsError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = exports.InvalidMarketParamsError = void 0;
|
|
4
4
|
exports._try = _try;
|
|
5
5
|
const viem_1 = require("viem");
|
|
6
|
+
class InvalidMarketParamsError extends Error {
|
|
7
|
+
data;
|
|
8
|
+
constructor(data) {
|
|
9
|
+
super(`cannot decode valid MarketParams from "${data}"`);
|
|
10
|
+
this.data = data;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.InvalidMarketParamsError = InvalidMarketParamsError;
|
|
6
14
|
class UnknownDataError extends Error {
|
|
7
15
|
}
|
|
8
16
|
exports.UnknownDataError = UnknownDataError;
|
|
@@ -54,6 +62,14 @@ class UnsupportedPreLiquidationParamsError extends Error {
|
|
|
54
62
|
}
|
|
55
63
|
}
|
|
56
64
|
exports.UnsupportedPreLiquidationParamsError = UnsupportedPreLiquidationParamsError;
|
|
65
|
+
class UnsupportedVaultV2AdapterError extends Error {
|
|
66
|
+
address;
|
|
67
|
+
constructor(address) {
|
|
68
|
+
super(`vault v2 adapter "${address}" is not supported`);
|
|
69
|
+
this.address = address;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.UnsupportedVaultV2AdapterError = UnsupportedVaultV2AdapterError;
|
|
57
73
|
var BlueErrors;
|
|
58
74
|
(function (BlueErrors) {
|
|
59
75
|
class AlreadySet extends Error {
|
|
@@ -133,6 +149,29 @@ var BlueErrors;
|
|
|
133
149
|
}
|
|
134
150
|
BlueErrors.ExpiredSignature = ExpiredSignature;
|
|
135
151
|
})(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
|
|
152
|
+
var VaultV2Errors;
|
|
153
|
+
(function (VaultV2Errors) {
|
|
154
|
+
class InvalidInterestAccrual extends Error {
|
|
155
|
+
vault;
|
|
156
|
+
timestamp;
|
|
157
|
+
lastUpdate;
|
|
158
|
+
constructor(vault, timestamp, lastUpdate) {
|
|
159
|
+
super(`invalid interest accrual on vault ${vault}: accrual timestamp ${timestamp} can't be prior to last update ${lastUpdate}`);
|
|
160
|
+
this.vault = vault;
|
|
161
|
+
this.timestamp = timestamp;
|
|
162
|
+
this.lastUpdate = lastUpdate;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
166
|
+
class UnsupportedLiquidityAdapter extends Error {
|
|
167
|
+
address;
|
|
168
|
+
constructor(address) {
|
|
169
|
+
super(`unsupported liquidity adapter "${address}"`);
|
|
170
|
+
this.address = address;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
VaultV2Errors.UnsupportedLiquidityAdapter = UnsupportedLiquidityAdapter;
|
|
174
|
+
})(VaultV2Errors || (exports.VaultV2Errors = VaultV2Errors = {}));
|
|
136
175
|
function _try(accessor, ...errorClasses) {
|
|
137
176
|
const maybeCatchError = (error) => {
|
|
138
177
|
if (errorClasses.length === 0 ||
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./holding/index.js"), exports);
|
|
|
27
27
|
__exportStar(require("./position/index.js"), exports);
|
|
28
28
|
__exportStar(require("./vault/index.js"), exports);
|
|
29
29
|
__exportStar(require("./preLiquidation.js"), exports);
|
|
30
|
+
__exportStar(require("./utils.js"), exports);
|
package/lib/market/Market.d.ts
CHANGED
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
2
2
|
import type { BigIntish } from "../types.js";
|
|
3
|
+
import { type CapacityLimit } from "../utils.js";
|
|
3
4
|
import { type IMarketParams, MarketParams } from "./MarketParams.js";
|
|
4
|
-
export declare enum CapacityLimitReason {
|
|
5
|
-
liquidity = "Liquidity",
|
|
6
|
-
balance = "Balance",
|
|
7
|
-
position = "Position",
|
|
8
|
-
collateral = "Collateral",
|
|
9
|
-
cap = "Cap"
|
|
10
|
-
}
|
|
11
|
-
export interface CapacityLimit {
|
|
12
|
-
value: bigint;
|
|
13
|
-
limiter: CapacityLimitReason;
|
|
14
|
-
}
|
|
15
5
|
export interface MaxBorrowOptions {
|
|
16
6
|
maxLtv?: bigint;
|
|
17
7
|
}
|
package/lib/market/Market.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Market =
|
|
3
|
+
exports.Market = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
6
|
const index_js_1 = require("../math/index.js");
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
7
8
|
const MarketParams_js_1 = require("./MarketParams.js");
|
|
8
9
|
const MarketUtils_js_1 = require("./MarketUtils.js");
|
|
9
|
-
var CapacityLimitReason;
|
|
10
|
-
(function (CapacityLimitReason) {
|
|
11
|
-
CapacityLimitReason["liquidity"] = "Liquidity";
|
|
12
|
-
CapacityLimitReason["balance"] = "Balance";
|
|
13
|
-
CapacityLimitReason["position"] = "Position";
|
|
14
|
-
CapacityLimitReason["collateral"] = "Collateral";
|
|
15
|
-
CapacityLimitReason["cap"] = "Cap";
|
|
16
|
-
})(CapacityLimitReason || (exports.CapacityLimitReason = CapacityLimitReason = {}));
|
|
17
10
|
/**
|
|
18
11
|
* Represents a lending market on Morpho Blue.
|
|
19
12
|
*/
|
|
@@ -498,11 +491,11 @@ class Market {
|
|
|
498
491
|
if (maxBorrowableAssets > liquidity)
|
|
499
492
|
return {
|
|
500
493
|
value: liquidity,
|
|
501
|
-
limiter: CapacityLimitReason.liquidity,
|
|
494
|
+
limiter: utils_js_1.CapacityLimitReason.liquidity,
|
|
502
495
|
};
|
|
503
496
|
return {
|
|
504
497
|
value: maxBorrowableAssets,
|
|
505
|
-
limiter: CapacityLimitReason.collateral,
|
|
498
|
+
limiter: utils_js_1.CapacityLimitReason.collateral,
|
|
506
499
|
};
|
|
507
500
|
}
|
|
508
501
|
/**
|
|
@@ -515,11 +508,11 @@ class Market {
|
|
|
515
508
|
if (borrowAssets > loanTokenBalance)
|
|
516
509
|
return {
|
|
517
510
|
value: loanTokenBalance,
|
|
518
|
-
limiter: CapacityLimitReason.balance,
|
|
511
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
519
512
|
};
|
|
520
513
|
return {
|
|
521
514
|
value: borrowAssets,
|
|
522
|
-
limiter: CapacityLimitReason.position,
|
|
515
|
+
limiter: utils_js_1.CapacityLimitReason.position,
|
|
523
516
|
};
|
|
524
517
|
}
|
|
525
518
|
/**
|
|
@@ -533,11 +526,11 @@ class Market {
|
|
|
533
526
|
if (supplyAssets > liquidity)
|
|
534
527
|
return {
|
|
535
528
|
value: liquidity,
|
|
536
|
-
limiter: CapacityLimitReason.liquidity,
|
|
529
|
+
limiter: utils_js_1.CapacityLimitReason.liquidity,
|
|
537
530
|
};
|
|
538
531
|
return {
|
|
539
532
|
value: supplyAssets,
|
|
540
|
-
limiter: CapacityLimitReason.position,
|
|
533
|
+
limiter: utils_js_1.CapacityLimitReason.position,
|
|
541
534
|
};
|
|
542
535
|
}
|
|
543
536
|
/**
|
|
@@ -553,11 +546,11 @@ class Market {
|
|
|
553
546
|
if (position.collateral > withdrawableCollateral)
|
|
554
547
|
return {
|
|
555
548
|
value: withdrawableCollateral,
|
|
556
|
-
limiter: CapacityLimitReason.collateral,
|
|
549
|
+
limiter: utils_js_1.CapacityLimitReason.collateral,
|
|
557
550
|
};
|
|
558
551
|
return {
|
|
559
552
|
value: position.collateral,
|
|
560
|
-
limiter: CapacityLimitReason.position,
|
|
553
|
+
limiter: utils_js_1.CapacityLimitReason.position,
|
|
561
554
|
};
|
|
562
555
|
}
|
|
563
556
|
/**
|
|
@@ -571,14 +564,14 @@ class Market {
|
|
|
571
564
|
return {
|
|
572
565
|
supply: {
|
|
573
566
|
value: loanTokenBalance,
|
|
574
|
-
limiter: CapacityLimitReason.balance,
|
|
567
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
575
568
|
},
|
|
576
569
|
withdraw: this.getWithdrawCapacityLimit(position),
|
|
577
570
|
borrow: this.getBorrowCapacityLimit(position, options?.borrow),
|
|
578
571
|
repay: this.getRepayCapacityLimit(position.borrowShares, loanTokenBalance),
|
|
579
572
|
supplyCollateral: {
|
|
580
573
|
value: collateralTokenBalance,
|
|
581
|
-
limiter: CapacityLimitReason.balance,
|
|
574
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
582
575
|
},
|
|
583
576
|
withdrawCollateral: this.getWithdrawCollateralCapacityLimit(position, options?.withdrawCollateral),
|
|
584
577
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
2
|
+
import { type Hex } from "viem";
|
|
2
3
|
export interface IMarketParams {
|
|
3
4
|
loanToken: Address;
|
|
4
5
|
collateralToken: Address;
|
|
@@ -7,6 +8,25 @@ export interface IMarketParams {
|
|
|
7
8
|
lltv: BigIntish;
|
|
8
9
|
}
|
|
9
10
|
export type InputMarketParams = Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
|
|
11
|
+
export declare const marketParamsAbi: {
|
|
12
|
+
readonly type: "tuple";
|
|
13
|
+
readonly components: readonly [{
|
|
14
|
+
readonly type: "address";
|
|
15
|
+
readonly name: "loanToken";
|
|
16
|
+
}, {
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
readonly name: "collateralToken";
|
|
19
|
+
}, {
|
|
20
|
+
readonly type: "address";
|
|
21
|
+
readonly name: "oracle";
|
|
22
|
+
}, {
|
|
23
|
+
readonly type: "address";
|
|
24
|
+
readonly name: "irm";
|
|
25
|
+
}, {
|
|
26
|
+
readonly type: "uint256";
|
|
27
|
+
readonly name: "lltv";
|
|
28
|
+
}];
|
|
29
|
+
};
|
|
10
30
|
/**
|
|
11
31
|
* Represents a market's configuration (also called market params).
|
|
12
32
|
*/
|
|
@@ -21,6 +41,7 @@ export declare class MarketParams implements IMarketParams {
|
|
|
21
41
|
* Returns the canonical idle market configuration for the given loan token.
|
|
22
42
|
*/
|
|
23
43
|
static idle(token: Address): MarketParams;
|
|
44
|
+
static fromHex(data: Hex): MarketParams;
|
|
24
45
|
/**
|
|
25
46
|
* The market's collateral token address.
|
|
26
47
|
*/
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.MarketParams = void 0;
|
|
3
|
+
exports.MarketParams = exports.marketParamsAbi = void 0;
|
|
4
4
|
const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
5
5
|
const errors_js_1 = require("../errors.js");
|
|
6
|
+
const viem_1 = require("viem");
|
|
6
7
|
const MarketUtils_js_1 = require("./MarketUtils.js");
|
|
8
|
+
exports.marketParamsAbi = {
|
|
9
|
+
type: "tuple",
|
|
10
|
+
components: [
|
|
11
|
+
{ type: "address", name: "loanToken" },
|
|
12
|
+
{ type: "address", name: "collateralToken" },
|
|
13
|
+
{ type: "address", name: "oracle" },
|
|
14
|
+
{ type: "address", name: "irm" },
|
|
15
|
+
{ type: "uint256", name: "lltv" },
|
|
16
|
+
],
|
|
17
|
+
};
|
|
7
18
|
/**
|
|
8
19
|
* Represents a market's configuration (also called market params).
|
|
9
20
|
*/
|
|
@@ -31,6 +42,15 @@ class MarketParams {
|
|
|
31
42
|
lltv: 0n,
|
|
32
43
|
});
|
|
33
44
|
}
|
|
45
|
+
static fromHex(data) {
|
|
46
|
+
try {
|
|
47
|
+
const [marketParams] = (0, viem_1.decodeAbiParameters)([exports.marketParamsAbi], data);
|
|
48
|
+
return new MarketParams(marketParams);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
throw new errors_js_1.InvalidMarketParamsError(data);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
34
54
|
/**
|
|
35
55
|
* The market's collateral token address.
|
|
36
56
|
*/
|
|
@@ -109,7 +109,7 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
|
|
|
109
109
|
* Returns the maximum amount of loan assets that can be withdrawn given a certain supply position
|
|
110
110
|
* and a balance of loan assets, and the reason for the limit.
|
|
111
111
|
*/
|
|
112
|
-
get withdrawCapacityLimit(): import("../
|
|
112
|
+
get withdrawCapacityLimit(): import("../utils.js").CapacityLimit;
|
|
113
113
|
/**
|
|
114
114
|
* Returns a new position derived from this position, whose interest has been accrued up to the given timestamp.
|
|
115
115
|
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the market's `lastUpdate`.
|
|
@@ -137,9 +137,9 @@ export declare class AccrualPosition extends Position implements IAccrualPositio
|
|
|
137
137
|
assets: bigint;
|
|
138
138
|
shares: bigint;
|
|
139
139
|
};
|
|
140
|
-
getBorrowCapacityLimit(options?: MaxBorrowOptions): import("../
|
|
141
|
-
getWithdrawCollateralCapacityLimit(options?: MaxWithdrawCollateralOptions): import("../
|
|
142
|
-
getRepayCapacityLimit(loanTokenBalance: bigint): import("../
|
|
140
|
+
getBorrowCapacityLimit(options?: MaxBorrowOptions): import("../utils.js").CapacityLimit | undefined;
|
|
141
|
+
getWithdrawCollateralCapacityLimit(options?: MaxWithdrawCollateralOptions): import("../utils.js").CapacityLimit | undefined;
|
|
142
|
+
getRepayCapacityLimit(loanTokenBalance: bigint): import("../utils.js").CapacityLimit;
|
|
143
143
|
getMaxCapacities(loanTokenBalance: bigint, collateralTokenBalance: bigint, options?: {
|
|
144
144
|
borrow?: MaxBorrowOptions;
|
|
145
145
|
withdrawCollateral?: MaxWithdrawCollateralOptions;
|
package/lib/position/Position.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.AccrualPosition = exports.Position = void 0;
|
|
|
4
4
|
const errors_js_1 = require("../errors.js");
|
|
5
5
|
const index_js_1 = require("../market/index.js");
|
|
6
6
|
const MathLib_js_1 = require("../math/MathLib.js");
|
|
7
|
+
const utils_js_1 = require("../utils.js");
|
|
7
8
|
class Position {
|
|
8
9
|
/**
|
|
9
10
|
* The user holding this position.
|
|
@@ -225,14 +226,14 @@ class AccrualPosition extends Position {
|
|
|
225
226
|
return {
|
|
226
227
|
supply: {
|
|
227
228
|
value: loanTokenBalance,
|
|
228
|
-
limiter:
|
|
229
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
229
230
|
},
|
|
230
231
|
withdraw: this.withdrawCapacityLimit,
|
|
231
232
|
borrow: this.getBorrowCapacityLimit(options?.borrow),
|
|
232
233
|
repay: this.getRepayCapacityLimit(loanTokenBalance),
|
|
233
234
|
supplyCollateral: {
|
|
234
235
|
value: collateralTokenBalance,
|
|
235
|
-
limiter:
|
|
236
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
236
237
|
},
|
|
237
238
|
withdrawCollateral: this.getWithdrawCollateralCapacityLimit(options?.withdrawCollateral),
|
|
238
239
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RoundingDirection } from "../math/index.js";
|
|
2
|
-
import type { Address } from "../types.js";
|
|
2
|
+
import type { Address, BigIntish } from "../types.js";
|
|
3
3
|
import type { IVaultConfig } from "../vault/VaultConfig.js";
|
|
4
4
|
import { WrappedToken } from "./WrappedToken.js";
|
|
5
5
|
export interface IVaultToken {
|
|
@@ -18,6 +18,6 @@ export declare class VaultToken extends WrappedToken implements IVaultToken {
|
|
|
18
18
|
*/
|
|
19
19
|
totalAssets: bigint;
|
|
20
20
|
constructor(config: IVaultConfig, { totalAssets, totalSupply }: IVaultToken);
|
|
21
|
-
protected _wrap(amount:
|
|
22
|
-
protected _unwrap(amount:
|
|
21
|
+
protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
22
|
+
protected _unwrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
23
23
|
}
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum CapacityLimitReason {
|
|
2
|
+
liquidity = "Liquidity",
|
|
3
|
+
balance = "Balance",
|
|
4
|
+
position = "Position",
|
|
5
|
+
collateral = "Collateral",
|
|
6
|
+
cap = "Cap",
|
|
7
|
+
vaultV2_absoluteCap = "VaultV2_AbsoluteCap",
|
|
8
|
+
vaultV2_relativeCap = "VaultV2_RelativeCap"
|
|
9
|
+
}
|
|
10
|
+
export interface CapacityLimit {
|
|
11
|
+
value: bigint;
|
|
12
|
+
limiter: CapacityLimitReason;
|
|
13
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CapacityLimitReason = void 0;
|
|
4
|
+
var CapacityLimitReason;
|
|
5
|
+
(function (CapacityLimitReason) {
|
|
6
|
+
CapacityLimitReason["liquidity"] = "Liquidity";
|
|
7
|
+
CapacityLimitReason["balance"] = "Balance";
|
|
8
|
+
CapacityLimitReason["position"] = "Position";
|
|
9
|
+
CapacityLimitReason["collateral"] = "Collateral";
|
|
10
|
+
CapacityLimitReason["cap"] = "Cap";
|
|
11
|
+
CapacityLimitReason["vaultV2_absoluteCap"] = "VaultV2_AbsoluteCap";
|
|
12
|
+
CapacityLimitReason["vaultV2_relativeCap"] = "VaultV2_RelativeCap";
|
|
13
|
+
})(CapacityLimitReason || (exports.CapacityLimitReason = CapacityLimitReason = {}));
|
package/lib/vault/Vault.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { type CapacityLimit } from "../market/index.js";
|
|
2
1
|
import { type RoundingDirection } from "../math/index.js";
|
|
3
2
|
import { VaultToken } from "../token/index.js";
|
|
4
3
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
4
|
+
import { type CapacityLimit } from "../utils.js";
|
|
5
5
|
import type { IVaultConfig } from "./VaultConfig.js";
|
|
6
6
|
import { type IVaultMarketAllocation, VaultMarketAllocation } from "./VaultMarketAllocation.js";
|
|
7
7
|
export interface Pending<T> {
|
|
@@ -116,8 +116,8 @@ export declare class Vault extends VaultToken implements IVault {
|
|
|
116
116
|
* The amount of interest in assets accrued since the last interaction with the vault.
|
|
117
117
|
*/
|
|
118
118
|
get totalInterest(): bigint;
|
|
119
|
-
toAssets(shares:
|
|
120
|
-
toShares(assets:
|
|
119
|
+
toAssets(shares: BigIntish, rounding?: RoundingDirection): bigint;
|
|
120
|
+
toShares(assets: BigIntish, rounding?: RoundingDirection): bigint;
|
|
121
121
|
}
|
|
122
122
|
export interface CollateralAllocation {
|
|
123
123
|
address: Address;
|
|
@@ -184,11 +184,31 @@ export declare class AccrualVault extends Vault implements IAccrualVault {
|
|
|
184
184
|
*/
|
|
185
185
|
getNetApy(timestamp?: BigIntish): number;
|
|
186
186
|
getAllocationProportion(marketId: MarketId): bigint;
|
|
187
|
+
/**
|
|
188
|
+
* Returns the deposit capacity limit of a given amount of assets on the vault.
|
|
189
|
+
* @param assets The maximum amount of assets to deposit.
|
|
190
|
+
* @deprecated Use `maxDeposit` instead.
|
|
191
|
+
*/
|
|
187
192
|
getDepositCapacityLimit(assets: bigint): CapacityLimit;
|
|
193
|
+
/**
|
|
194
|
+
* Returns the withdraw capacity limit corresponding to a given amount of shares of the vault.
|
|
195
|
+
* @param shares The maximum amount of shares to redeem.
|
|
196
|
+
* @deprecated Use `maxWithdraw` instead.
|
|
197
|
+
*/
|
|
188
198
|
getWithdrawCapacityLimit(shares: bigint): CapacityLimit;
|
|
199
|
+
/**
|
|
200
|
+
* Returns the maximum amount of assets that can be deposited to the vault.
|
|
201
|
+
* @param assets The maximum amount of assets to deposit.
|
|
202
|
+
*/
|
|
203
|
+
maxDeposit(assets: BigIntish): CapacityLimit;
|
|
204
|
+
/**
|
|
205
|
+
* Returns the maximum amount of assets that can be withdrawn from the vault.
|
|
206
|
+
* @param shares The maximum amount of shares to redeem.
|
|
207
|
+
*/
|
|
208
|
+
maxWithdraw(shares: BigIntish): CapacityLimit;
|
|
189
209
|
/**
|
|
190
210
|
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
191
211
|
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to each of the vault's market's `lastUpdate`.
|
|
192
212
|
*/
|
|
193
|
-
accrueInterest(timestamp
|
|
213
|
+
accrueInterest(timestamp?: BigIntish): AccrualVault;
|
|
194
214
|
}
|
package/lib/vault/Vault.js
CHANGED
|
@@ -5,6 +5,7 @@ const morpho_ts_1 = require("@morpho-org/morpho-ts");
|
|
|
5
5
|
const index_js_1 = require("../market/index.js");
|
|
6
6
|
const index_js_2 = require("../math/index.js");
|
|
7
7
|
const index_js_3 = require("../token/index.js");
|
|
8
|
+
const utils_js_1 = require("../utils.js");
|
|
8
9
|
const VaultMarketAllocation_js_1 = require("./VaultMarketAllocation.js");
|
|
9
10
|
class Vault extends index_js_3.VaultToken {
|
|
10
11
|
/**
|
|
@@ -208,7 +209,28 @@ class AccrualVault extends Vault {
|
|
|
208
209
|
return 0n;
|
|
209
210
|
return index_js_2.MathLib.wDivDown(allocation.position.supplyAssets, this.totalAssets);
|
|
210
211
|
}
|
|
212
|
+
/**
|
|
213
|
+
* Returns the deposit capacity limit of a given amount of assets on the vault.
|
|
214
|
+
* @param assets The maximum amount of assets to deposit.
|
|
215
|
+
* @deprecated Use `maxDeposit` instead.
|
|
216
|
+
*/
|
|
211
217
|
getDepositCapacityLimit(assets) {
|
|
218
|
+
return this.maxDeposit(assets);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Returns the withdraw capacity limit corresponding to a given amount of shares of the vault.
|
|
222
|
+
* @param shares The maximum amount of shares to redeem.
|
|
223
|
+
* @deprecated Use `maxWithdraw` instead.
|
|
224
|
+
*/
|
|
225
|
+
getWithdrawCapacityLimit(shares) {
|
|
226
|
+
return this.maxWithdraw(shares);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Returns the maximum amount of assets that can be deposited to the vault.
|
|
230
|
+
* @param assets The maximum amount of assets to deposit.
|
|
231
|
+
*/
|
|
232
|
+
maxDeposit(assets) {
|
|
233
|
+
assets = BigInt(assets);
|
|
212
234
|
const suppliable = this.allocations
|
|
213
235
|
.values()
|
|
214
236
|
.reduce((total, { config: { cap }, position: { marketId, supplyAssets } }) => index_js_2.MathLib.min(total +
|
|
@@ -218,24 +240,28 @@ class AccrualVault extends Vault {
|
|
|
218
240
|
if (assets > suppliable)
|
|
219
241
|
return {
|
|
220
242
|
value: suppliable,
|
|
221
|
-
limiter:
|
|
243
|
+
limiter: utils_js_1.CapacityLimitReason.cap,
|
|
222
244
|
};
|
|
223
245
|
return {
|
|
224
246
|
value: assets,
|
|
225
|
-
limiter:
|
|
247
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
226
248
|
};
|
|
227
249
|
}
|
|
228
|
-
|
|
250
|
+
/**
|
|
251
|
+
* Returns the maximum amount of assets that can be withdrawn from the vault.
|
|
252
|
+
* @param shares The maximum amount of shares to redeem.
|
|
253
|
+
*/
|
|
254
|
+
maxWithdraw(shares) {
|
|
229
255
|
const assets = this.toAssets(shares);
|
|
230
256
|
const { liquidity } = this;
|
|
231
257
|
if (assets > liquidity)
|
|
232
258
|
return {
|
|
233
259
|
value: liquidity,
|
|
234
|
-
limiter:
|
|
260
|
+
limiter: utils_js_1.CapacityLimitReason.liquidity,
|
|
235
261
|
};
|
|
236
262
|
return {
|
|
237
263
|
value: assets,
|
|
238
|
-
limiter:
|
|
264
|
+
limiter: utils_js_1.CapacityLimitReason.balance,
|
|
239
265
|
};
|
|
240
266
|
}
|
|
241
267
|
/**
|
package/lib/vault/index.d.ts
CHANGED
package/lib/vault/index.js
CHANGED
|
@@ -21,3 +21,4 @@ __exportStar(require("./VaultMarketConfig.js"), exports);
|
|
|
21
21
|
__exportStar(require("./VaultMarketPublicAllocatorConfig.js"), exports);
|
|
22
22
|
__exportStar(require("./VaultUser.js"), exports);
|
|
23
23
|
__exportStar(require("./Vault.js"), exports);
|
|
24
|
+
__exportStar(require("./v2"), exports);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { type Address, type Hash, type Hex } from "viem";
|
|
2
|
+
import { type RoundingDirection } from "../../math";
|
|
3
|
+
import { type IToken, WrappedToken } from "../../token";
|
|
4
|
+
import type { BigIntish } from "../../types";
|
|
5
|
+
import { type CapacityLimit } from "../../utils";
|
|
6
|
+
import type { IAccrualVaultV2Adapter } from "./VaultV2Adapter";
|
|
7
|
+
export interface IVaultV2Allocation {
|
|
8
|
+
id: Hash;
|
|
9
|
+
absoluteCap: bigint;
|
|
10
|
+
relativeCap: bigint;
|
|
11
|
+
allocation: bigint;
|
|
12
|
+
}
|
|
13
|
+
export interface IVaultV2 extends IToken {
|
|
14
|
+
asset: Address;
|
|
15
|
+
/**
|
|
16
|
+
* The total assets, *including* virtually accrued interest.
|
|
17
|
+
*/
|
|
18
|
+
totalAssets: bigint;
|
|
19
|
+
/**
|
|
20
|
+
* The total assets, *excluding* virtually accrued interest.
|
|
21
|
+
*/
|
|
22
|
+
_totalAssets: bigint;
|
|
23
|
+
/**
|
|
24
|
+
* The total supply of shares.
|
|
25
|
+
*/
|
|
26
|
+
totalSupply: bigint;
|
|
27
|
+
virtualShares: bigint;
|
|
28
|
+
maxRate: bigint;
|
|
29
|
+
lastUpdate: bigint;
|
|
30
|
+
adapters: Address[];
|
|
31
|
+
liquidityAdapter: Address;
|
|
32
|
+
liquidityData: Hex;
|
|
33
|
+
liquidityAllocations: IVaultV2Allocation[] | undefined;
|
|
34
|
+
performanceFee: bigint;
|
|
35
|
+
managementFee: bigint;
|
|
36
|
+
performanceFeeRecipient: Address;
|
|
37
|
+
managementFeeRecipient: Address;
|
|
38
|
+
}
|
|
39
|
+
export declare class VaultV2 extends WrappedToken implements IVaultV2 {
|
|
40
|
+
readonly asset: Address;
|
|
41
|
+
totalAssets: bigint;
|
|
42
|
+
_totalAssets: bigint;
|
|
43
|
+
totalSupply: bigint;
|
|
44
|
+
virtualShares: bigint;
|
|
45
|
+
maxRate: bigint;
|
|
46
|
+
lastUpdate: bigint;
|
|
47
|
+
adapters: `0x${string}`[];
|
|
48
|
+
liquidityAdapter: `0x${string}`;
|
|
49
|
+
liquidityData: `0x${string}`;
|
|
50
|
+
liquidityAllocations: IVaultV2Allocation[] | undefined;
|
|
51
|
+
performanceFee: bigint;
|
|
52
|
+
managementFee: bigint;
|
|
53
|
+
performanceFeeRecipient: `0x${string}`;
|
|
54
|
+
managementFeeRecipient: `0x${string}`;
|
|
55
|
+
constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }: IVaultV2);
|
|
56
|
+
toAssets(shares: BigIntish): bigint;
|
|
57
|
+
toShares(assets: BigIntish): bigint;
|
|
58
|
+
protected _wrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
59
|
+
protected _unwrap(amount: BigIntish, rounding: RoundingDirection): bigint;
|
|
60
|
+
}
|
|
61
|
+
export interface IAccrualVaultV2 extends Omit<IVaultV2, "adapters"> {
|
|
62
|
+
}
|
|
63
|
+
export declare class AccrualVaultV2 extends VaultV2 implements IAccrualVaultV2 {
|
|
64
|
+
accrualLiquidityAdapter: IAccrualVaultV2Adapter | undefined;
|
|
65
|
+
accrualAdapters: IAccrualVaultV2Adapter[];
|
|
66
|
+
assetBalance: bigint;
|
|
67
|
+
constructor(vault: IAccrualVaultV2, accrualLiquidityAdapter: IAccrualVaultV2Adapter | undefined, accrualAdapters: IAccrualVaultV2Adapter[], assetBalance: bigint);
|
|
68
|
+
/**
|
|
69
|
+
* Returns the maximum amount of assets that can be deposited to the vault.
|
|
70
|
+
* @param assets The maximum amount of assets to deposit.
|
|
71
|
+
*/
|
|
72
|
+
maxDeposit(assets: BigIntish): CapacityLimit;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the maximum amount of assets that can be withdrawn from the vault.
|
|
75
|
+
* @param shares The maximum amount of shares to redeem.
|
|
76
|
+
*/
|
|
77
|
+
maxWithdraw(shares: BigIntish): CapacityLimit;
|
|
78
|
+
/**
|
|
79
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
80
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
|
|
81
|
+
*/
|
|
82
|
+
accrueInterest(timestamp: BigIntish): {
|
|
83
|
+
vault: AccrualVaultV2;
|
|
84
|
+
performanceFeeShares: bigint;
|
|
85
|
+
managementFeeShares: bigint;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVaultV2 = exports.VaultV2 = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const errors_1 = require("../../errors");
|
|
6
|
+
const math_1 = require("../../math");
|
|
7
|
+
const token_1 = require("../../token");
|
|
8
|
+
const utils_1 = require("../../utils");
|
|
9
|
+
class VaultV2 extends token_1.WrappedToken {
|
|
10
|
+
asset;
|
|
11
|
+
totalAssets;
|
|
12
|
+
_totalAssets;
|
|
13
|
+
totalSupply;
|
|
14
|
+
virtualShares;
|
|
15
|
+
maxRate;
|
|
16
|
+
lastUpdate;
|
|
17
|
+
adapters;
|
|
18
|
+
liquidityAdapter;
|
|
19
|
+
liquidityData;
|
|
20
|
+
liquidityAllocations;
|
|
21
|
+
performanceFee;
|
|
22
|
+
managementFee;
|
|
23
|
+
performanceFeeRecipient;
|
|
24
|
+
managementFeeRecipient;
|
|
25
|
+
constructor({ asset, totalAssets, _totalAssets, totalSupply, virtualShares, maxRate, lastUpdate, adapters, liquidityAdapter, liquidityData, liquidityAllocations, performanceFee, managementFee, performanceFeeRecipient, managementFeeRecipient, ...config }) {
|
|
26
|
+
super(config, asset);
|
|
27
|
+
this.asset = asset;
|
|
28
|
+
this.totalAssets = totalAssets;
|
|
29
|
+
this._totalAssets = _totalAssets;
|
|
30
|
+
this.totalSupply = totalSupply;
|
|
31
|
+
this.virtualShares = virtualShares;
|
|
32
|
+
this.maxRate = maxRate;
|
|
33
|
+
this.lastUpdate = lastUpdate;
|
|
34
|
+
this.adapters = adapters;
|
|
35
|
+
this.liquidityAdapter = liquidityAdapter;
|
|
36
|
+
this.liquidityData = liquidityData;
|
|
37
|
+
this.liquidityAllocations = liquidityAllocations;
|
|
38
|
+
this.performanceFee = performanceFee;
|
|
39
|
+
this.managementFee = managementFee;
|
|
40
|
+
this.performanceFeeRecipient = performanceFeeRecipient;
|
|
41
|
+
this.managementFeeRecipient = managementFeeRecipient;
|
|
42
|
+
}
|
|
43
|
+
toAssets(shares) {
|
|
44
|
+
return this._unwrap(shares, "Down");
|
|
45
|
+
}
|
|
46
|
+
toShares(assets) {
|
|
47
|
+
return this._wrap(assets, "Down");
|
|
48
|
+
}
|
|
49
|
+
_wrap(amount, rounding) {
|
|
50
|
+
return math_1.MathLib.mulDiv(amount, this.totalSupply + this.virtualShares, this.totalAssets + 1n, rounding);
|
|
51
|
+
}
|
|
52
|
+
_unwrap(amount, rounding) {
|
|
53
|
+
return math_1.MathLib.mulDiv(amount, this.totalAssets + 1n, this.totalSupply + this.virtualShares, rounding);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.VaultV2 = VaultV2;
|
|
57
|
+
class AccrualVaultV2 extends VaultV2 {
|
|
58
|
+
accrualLiquidityAdapter;
|
|
59
|
+
accrualAdapters;
|
|
60
|
+
assetBalance;
|
|
61
|
+
constructor(vault, accrualLiquidityAdapter, accrualAdapters, assetBalance) {
|
|
62
|
+
super({ ...vault, adapters: accrualAdapters.map((a) => a.address) });
|
|
63
|
+
this.accrualLiquidityAdapter = accrualLiquidityAdapter;
|
|
64
|
+
this.accrualAdapters = accrualAdapters;
|
|
65
|
+
this.assetBalance = assetBalance;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Returns the maximum amount of assets that can be deposited to the vault.
|
|
69
|
+
* @param assets The maximum amount of assets to deposit.
|
|
70
|
+
*/
|
|
71
|
+
maxDeposit(assets) {
|
|
72
|
+
if (this.liquidityAdapter === viem_1.zeroAddress)
|
|
73
|
+
return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
|
|
74
|
+
let liquidityAdapterLimit;
|
|
75
|
+
if (this.accrualLiquidityAdapter != null)
|
|
76
|
+
liquidityAdapterLimit = this.accrualLiquidityAdapter.maxDeposit(this.liquidityData, assets);
|
|
77
|
+
if (this.liquidityAllocations == null || liquidityAdapterLimit == null)
|
|
78
|
+
throw new errors_1.VaultV2Errors.UnsupportedLiquidityAdapter(this.liquidityAdapter);
|
|
79
|
+
// At this stage: `liquidityAdapterLimit.value <= assets`
|
|
80
|
+
for (const { absoluteCap, relativeCap, allocation } of this
|
|
81
|
+
.liquidityAllocations) {
|
|
82
|
+
// `absoluteCap` can be set lower than `allocation`.
|
|
83
|
+
const absoluteMaxDeposit = math_1.MathLib.zeroFloorSub(absoluteCap, allocation);
|
|
84
|
+
if (liquidityAdapterLimit.value > absoluteMaxDeposit)
|
|
85
|
+
return {
|
|
86
|
+
value: absoluteMaxDeposit,
|
|
87
|
+
limiter: utils_1.CapacityLimitReason.vaultV2_absoluteCap,
|
|
88
|
+
};
|
|
89
|
+
if (relativeCap !== math_1.MathLib.WAD) {
|
|
90
|
+
// `relativeCap` can be set lower than `allocation / totalAssets`.
|
|
91
|
+
const relativeMaxDeposit = math_1.MathLib.zeroFloorSub(math_1.MathLib.wMulDown(this.totalAssets, relativeCap), allocation);
|
|
92
|
+
if (liquidityAdapterLimit.value > relativeMaxDeposit)
|
|
93
|
+
return {
|
|
94
|
+
value: relativeMaxDeposit,
|
|
95
|
+
limiter: utils_1.CapacityLimitReason.vaultV2_relativeCap,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return liquidityAdapterLimit;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Returns the maximum amount of assets that can be withdrawn from the vault.
|
|
103
|
+
* @param shares The maximum amount of shares to redeem.
|
|
104
|
+
*/
|
|
105
|
+
maxWithdraw(shares) {
|
|
106
|
+
const assets = this.toAssets(shares);
|
|
107
|
+
if (this.liquidityAdapter === viem_1.zeroAddress)
|
|
108
|
+
return { value: BigInt(assets), limiter: utils_1.CapacityLimitReason.balance };
|
|
109
|
+
let liquidity = this.assetBalance;
|
|
110
|
+
if (this.accrualLiquidityAdapter != null)
|
|
111
|
+
liquidity += this.accrualLiquidityAdapter.maxWithdraw(this.liquidityData).value;
|
|
112
|
+
if (assets > liquidity)
|
|
113
|
+
return {
|
|
114
|
+
value: liquidity,
|
|
115
|
+
limiter: utils_1.CapacityLimitReason.liquidity,
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
value: assets,
|
|
119
|
+
limiter: utils_1.CapacityLimitReason.balance,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns a new vault derived from this vault, whose interest has been accrued up to the given timestamp.
|
|
124
|
+
* @param timestamp The timestamp at which to accrue interest. Must be greater than or equal to the vault's `lastUpdate`.
|
|
125
|
+
*/
|
|
126
|
+
accrueInterest(timestamp) {
|
|
127
|
+
const vault = new AccrualVaultV2(this, this.accrualLiquidityAdapter, this.accrualAdapters, this.assetBalance);
|
|
128
|
+
timestamp = BigInt(timestamp);
|
|
129
|
+
const elapsed = timestamp - this.lastUpdate;
|
|
130
|
+
if (elapsed < 0n)
|
|
131
|
+
throw new errors_1.VaultV2Errors.InvalidInterestAccrual(this.address, timestamp, this.lastUpdate);
|
|
132
|
+
// Corresponds to the `firstTotalAssets == 0` onchain check.
|
|
133
|
+
if (elapsed === 0n)
|
|
134
|
+
return { vault, performanceFeeShares: 0n, managementFeeShares: 0n };
|
|
135
|
+
const realAssets = vault.accrualAdapters.reduce((curr, adapter) => curr + adapter.realAssets(timestamp), vault.assetBalance);
|
|
136
|
+
const maxTotalAssets = vault._totalAssets +
|
|
137
|
+
math_1.MathLib.wMulDown(vault._totalAssets * elapsed, vault.maxRate);
|
|
138
|
+
const newTotalAssets = math_1.MathLib.min(realAssets, maxTotalAssets);
|
|
139
|
+
const interest = math_1.MathLib.zeroFloorSub(newTotalAssets, vault._totalAssets);
|
|
140
|
+
const performanceFeeAssets = interest > 0n && vault.performanceFee > 0n
|
|
141
|
+
? math_1.MathLib.wMulDown(interest, vault.performanceFee)
|
|
142
|
+
: 0n;
|
|
143
|
+
const managementFeeAssets = elapsed > 0n && vault.managementFee > 0n
|
|
144
|
+
? math_1.MathLib.wMulDown(newTotalAssets * elapsed, vault.managementFee)
|
|
145
|
+
: 0n;
|
|
146
|
+
const newTotalAssetsWithoutFees = newTotalAssets - performanceFeeAssets - managementFeeAssets;
|
|
147
|
+
const performanceFeeShares = math_1.MathLib.mulDivDown(performanceFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
148
|
+
const managementFeeShares = math_1.MathLib.mulDivDown(managementFeeAssets, vault.totalSupply + vault.virtualShares, newTotalAssetsWithoutFees + 1n);
|
|
149
|
+
vault.totalAssets = newTotalAssets;
|
|
150
|
+
vault._totalAssets = newTotalAssets;
|
|
151
|
+
if (performanceFeeShares)
|
|
152
|
+
vault.totalSupply += performanceFeeShares;
|
|
153
|
+
if (managementFeeShares)
|
|
154
|
+
vault.totalSupply += managementFeeShares;
|
|
155
|
+
vault.lastUpdate = BigInt(timestamp);
|
|
156
|
+
return { vault, performanceFeeShares, managementFeeShares };
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
exports.AccrualVaultV2 = AccrualVaultV2;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Address, Hash, Hex } from "viem";
|
|
2
|
+
import type { BigIntish } from "../../types";
|
|
3
|
+
import type { CapacityLimit } from "../../utils";
|
|
4
|
+
export interface IVaultV2Adapter {
|
|
5
|
+
address: Address;
|
|
6
|
+
parentVault: Address;
|
|
7
|
+
adapterId: Hash;
|
|
8
|
+
skimRecipient: Address;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class VaultV2Adapter implements IVaultV2Adapter {
|
|
11
|
+
readonly address: Address;
|
|
12
|
+
readonly parentVault: Address;
|
|
13
|
+
readonly adapterId: Hash;
|
|
14
|
+
skimRecipient: Address;
|
|
15
|
+
constructor({ address, parentVault, adapterId, skimRecipient, }: IVaultV2Adapter);
|
|
16
|
+
}
|
|
17
|
+
export interface IAccrualVaultV2Adapter extends IVaultV2Adapter {
|
|
18
|
+
realAssets(timestamp: BigIntish): bigint;
|
|
19
|
+
/**
|
|
20
|
+
* Returns the maximum amount of assets that can be deposited to this adapter.
|
|
21
|
+
* @param assets The maximum amount of assets to deposit.
|
|
22
|
+
*/
|
|
23
|
+
maxDeposit(data: Hex, assets: BigIntish): CapacityLimit;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the maximum amount of assets that can be withdrawn from this adapter.
|
|
26
|
+
* @param shares The maximum amount of shares to redeem.
|
|
27
|
+
*/
|
|
28
|
+
maxWithdraw(data: Hex): CapacityLimit;
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VaultV2Adapter = void 0;
|
|
4
|
+
class VaultV2Adapter {
|
|
5
|
+
address;
|
|
6
|
+
parentVault;
|
|
7
|
+
adapterId;
|
|
8
|
+
skimRecipient;
|
|
9
|
+
constructor({ address, parentVault, adapterId, skimRecipient, }) {
|
|
10
|
+
this.address = address;
|
|
11
|
+
this.parentVault = parentVault;
|
|
12
|
+
this.adapterId = adapterId;
|
|
13
|
+
this.skimRecipient = skimRecipient;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.VaultV2Adapter = VaultV2Adapter;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { type IMarketParams, MarketParams } from "../../market";
|
|
3
|
+
import type { AccrualPosition } from "../../position";
|
|
4
|
+
import type { BigIntish } from "../../types";
|
|
5
|
+
import { CapacityLimitReason } from "../../utils";
|
|
6
|
+
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
7
|
+
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
8
|
+
export interface IVaultV2MorphoMarketV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
|
|
9
|
+
marketParamsList: IMarketParams[];
|
|
10
|
+
}
|
|
11
|
+
export declare class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter implements IVaultV2MorphoMarketV1Adapter {
|
|
12
|
+
static adapterId(address: Address): `0x${string}`;
|
|
13
|
+
static collateralId(address: Address): `0x${string}`;
|
|
14
|
+
static marketParamsId(address: Address, params: MarketParams): `0x${string}`;
|
|
15
|
+
marketParamsList: MarketParams[];
|
|
16
|
+
constructor({ marketParamsList, ...vaultV2Adapter }: IVaultV2MorphoMarketV1Adapter);
|
|
17
|
+
ids(params: MarketParams): `0x${string}`[];
|
|
18
|
+
}
|
|
19
|
+
export interface IAccrualVaultV2MorphoMarketV1Adapter extends IVaultV2MorphoMarketV1Adapter {
|
|
20
|
+
}
|
|
21
|
+
export declare class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter implements IAccrualVaultV2MorphoMarketV1Adapter, IAccrualVaultV2Adapter {
|
|
22
|
+
positions: AccrualPosition[];
|
|
23
|
+
constructor(adapter: IAccrualVaultV2MorphoMarketV1Adapter, positions: AccrualPosition[]);
|
|
24
|
+
realAssets(timestamp?: BigIntish): bigint;
|
|
25
|
+
maxDeposit(_data: Hex, assets: BigIntish): {
|
|
26
|
+
value: bigint;
|
|
27
|
+
limiter: CapacityLimitReason;
|
|
28
|
+
};
|
|
29
|
+
maxWithdraw(data: Hex): import("../../utils").CapacityLimit;
|
|
30
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVaultV2MorphoMarketV1Adapter = exports.VaultV2MorphoMarketV1Adapter = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const market_1 = require("../../market");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const VaultV2Adapter_1 = require("./VaultV2Adapter");
|
|
8
|
+
class VaultV2MorphoMarketV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
9
|
+
static adapterId(address) {
|
|
10
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
11
|
+
}
|
|
12
|
+
static collateralId(address) {
|
|
13
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["collateralToken", address]));
|
|
14
|
+
}
|
|
15
|
+
static marketParamsId(address, params) {
|
|
16
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }, market_1.marketParamsAbi], ["this/marketParams", address, params]));
|
|
17
|
+
}
|
|
18
|
+
marketParamsList;
|
|
19
|
+
constructor({ marketParamsList, ...vaultV2Adapter }) {
|
|
20
|
+
super({
|
|
21
|
+
...vaultV2Adapter,
|
|
22
|
+
adapterId: VaultV2MorphoMarketV1Adapter.adapterId(vaultV2Adapter.address),
|
|
23
|
+
});
|
|
24
|
+
this.marketParamsList = marketParamsList.map((params) => new market_1.MarketParams(params));
|
|
25
|
+
}
|
|
26
|
+
ids(params) {
|
|
27
|
+
return [
|
|
28
|
+
this.adapterId,
|
|
29
|
+
VaultV2MorphoMarketV1Adapter.collateralId(params.collateralToken),
|
|
30
|
+
VaultV2MorphoMarketV1Adapter.marketParamsId(this.address, params),
|
|
31
|
+
];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.VaultV2MorphoMarketV1Adapter = VaultV2MorphoMarketV1Adapter;
|
|
35
|
+
class AccrualVaultV2MorphoMarketV1Adapter extends VaultV2MorphoMarketV1Adapter {
|
|
36
|
+
positions;
|
|
37
|
+
constructor(adapter, positions) {
|
|
38
|
+
super(adapter);
|
|
39
|
+
this.positions = positions;
|
|
40
|
+
}
|
|
41
|
+
realAssets(timestamp) {
|
|
42
|
+
return this.positions.reduce((total, position) => total + position.accrueInterest(timestamp).supplyAssets, 0n);
|
|
43
|
+
}
|
|
44
|
+
maxDeposit(_data, assets) {
|
|
45
|
+
return {
|
|
46
|
+
value: BigInt(assets),
|
|
47
|
+
limiter: utils_1.CapacityLimitReason.balance,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
maxWithdraw(data) {
|
|
51
|
+
const marketId = market_1.MarketParams.fromHex(data).id;
|
|
52
|
+
const position = this.positions.find((position) => position.marketId === marketId);
|
|
53
|
+
return (position?.market?.getWithdrawCapacityLimit(position) ?? {
|
|
54
|
+
value: 0n,
|
|
55
|
+
limiter: utils_1.CapacityLimitReason.position,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.AccrualVaultV2MorphoMarketV1Adapter = AccrualVaultV2MorphoMarketV1Adapter;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import { VaultV2Adapter } from "./VaultV2Adapter";
|
|
3
|
+
export interface IVaultV2MorphoVaultV1Adapter extends Omit<IVaultV2Adapter, "adapterId"> {
|
|
4
|
+
morphoVaultV1: Address;
|
|
5
|
+
}
|
|
6
|
+
import type { BigIntish } from "../../types";
|
|
7
|
+
import type { AccrualVault } from "../Vault";
|
|
8
|
+
import type { IAccrualVaultV2Adapter, IVaultV2Adapter } from "./VaultV2Adapter";
|
|
9
|
+
export declare class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter implements IVaultV2MorphoVaultV1Adapter {
|
|
10
|
+
static adapterId(address: Address): `0x${string}`;
|
|
11
|
+
readonly morphoVaultV1: Address;
|
|
12
|
+
constructor({ morphoVaultV1, ...vaultV2Adapter }: IVaultV2MorphoVaultV1Adapter);
|
|
13
|
+
ids(): `0x${string}`[];
|
|
14
|
+
}
|
|
15
|
+
export interface IAccrualVaultV2MorphoVaultV1Adapter extends IVaultV2MorphoVaultV1Adapter {
|
|
16
|
+
}
|
|
17
|
+
export declare class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter implements IAccrualVaultV2MorphoVaultV1Adapter, IAccrualVaultV2Adapter {
|
|
18
|
+
accrualVaultV1: AccrualVault;
|
|
19
|
+
shares: bigint;
|
|
20
|
+
constructor(adapter: IAccrualVaultV2MorphoVaultV1Adapter, accrualVaultV1: AccrualVault, shares: bigint);
|
|
21
|
+
realAssets(timestamp?: BigIntish): bigint;
|
|
22
|
+
maxDeposit(_data: Hex, assets: BigIntish): import("../..").CapacityLimit;
|
|
23
|
+
maxWithdraw(_data: Hex): import("../..").CapacityLimit;
|
|
24
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccrualVaultV2MorphoVaultV1Adapter = exports.VaultV2MorphoVaultV1Adapter = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const VaultV2Adapter_1 = require("./VaultV2Adapter");
|
|
6
|
+
class VaultV2MorphoVaultV1Adapter extends VaultV2Adapter_1.VaultV2Adapter {
|
|
7
|
+
static adapterId(address) {
|
|
8
|
+
return (0, viem_1.keccak256)((0, viem_1.encodeAbiParameters)([{ type: "string" }, { type: "address" }], ["this", address]));
|
|
9
|
+
}
|
|
10
|
+
morphoVaultV1;
|
|
11
|
+
constructor({ morphoVaultV1, ...vaultV2Adapter }) {
|
|
12
|
+
super({
|
|
13
|
+
...vaultV2Adapter,
|
|
14
|
+
adapterId: VaultV2MorphoVaultV1Adapter.adapterId(vaultV2Adapter.address),
|
|
15
|
+
});
|
|
16
|
+
this.morphoVaultV1 = morphoVaultV1;
|
|
17
|
+
}
|
|
18
|
+
ids() {
|
|
19
|
+
return [this.adapterId];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.VaultV2MorphoVaultV1Adapter = VaultV2MorphoVaultV1Adapter;
|
|
23
|
+
class AccrualVaultV2MorphoVaultV1Adapter extends VaultV2MorphoVaultV1Adapter {
|
|
24
|
+
accrualVaultV1;
|
|
25
|
+
shares;
|
|
26
|
+
constructor(adapter, accrualVaultV1, shares) {
|
|
27
|
+
super(adapter);
|
|
28
|
+
this.accrualVaultV1 = accrualVaultV1;
|
|
29
|
+
this.shares = shares;
|
|
30
|
+
}
|
|
31
|
+
realAssets(timestamp) {
|
|
32
|
+
return this.accrualVaultV1.accrueInterest(timestamp).toAssets(this.shares);
|
|
33
|
+
}
|
|
34
|
+
maxDeposit(_data, assets) {
|
|
35
|
+
return this.accrualVaultV1.maxDeposit(assets);
|
|
36
|
+
}
|
|
37
|
+
maxWithdraw(_data) {
|
|
38
|
+
return this.accrualVaultV1.maxWithdraw(this.shares);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.AccrualVaultV2MorphoVaultV1Adapter = AccrualVaultV2MorphoVaultV1Adapter;
|
|
@@ -0,0 +1,20 @@
|
|
|
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("./VaultV2.js"), exports);
|
|
18
|
+
__exportStar(require("./VaultV2Adapter.js"), exports);
|
|
19
|
+
__exportStar(require("./VaultV2MorphoMarketV1Adapter.js"), exports);
|
|
20
|
+
__exportStar(require("./VaultV2MorphoVaultV1Adapter.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": "5.
|
|
4
|
+
"version": "5.6.0",
|
|
5
5
|
"author": "Morpho Association <contact@morpho.org>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Rubilmax <rmilon@gmail.com>"
|
|
@@ -25,14 +25,14 @@
|
|
|
25
25
|
"lodash.mergewith": "^4.6.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@morpho-org/morpho-ts": "^2.4.
|
|
28
|
+
"@morpho-org/morpho-ts": "^2.4.5"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.7.2",
|
|
32
|
-
"viem": "^2.
|
|
32
|
+
"viem": "^2.33.3",
|
|
33
33
|
"vitest": "^3.0.5",
|
|
34
|
-
"@morpho-org/morpho-ts": "^2.4.
|
|
35
|
-
"@morpho-org/test": "^2.6.
|
|
34
|
+
"@morpho-org/morpho-ts": "^2.4.5",
|
|
35
|
+
"@morpho-org/test": "^2.6.1"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"prepublish": "$npm_execpath build",
|