@morpho-org/blue-sdk 6.0.1 → 6.1.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/cjs/addresses.d.ts +105 -0
- package/lib/cjs/addresses.js +74 -0
- package/lib/cjs/chain.d.ts +84 -1
- package/lib/cjs/chain.js +78 -0
- package/lib/cjs/errors.d.ts +34 -0
- package/lib/cjs/errors.js +28 -0
- package/lib/cjs/holding/AssetBalances.d.ts +3 -0
- package/lib/cjs/holding/AssetBalances.js +1 -0
- package/lib/cjs/holding/Holding.d.ts +6 -0
- package/lib/cjs/holding/Holding.js +2 -0
- package/lib/cjs/market/Market.d.ts +4 -0
- package/lib/cjs/market/MarketParams.d.ts +3 -0
- package/lib/cjs/market/MarketParams.js +1 -0
- package/lib/cjs/market/MarketUtils.d.ts +397 -0
- package/lib/cjs/market/MarketUtils.js +397 -2
- package/lib/cjs/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/cjs/math/AdaptiveCurveIrmLib.js +51 -1
- package/lib/cjs/math/MathLib.d.ts +152 -4
- package/lib/cjs/math/MathLib.js +151 -4
- package/lib/cjs/math/SharesMath.d.ts +34 -0
- package/lib/cjs/math/SharesMath.js +34 -0
- package/lib/cjs/position/Position.d.ts +4 -0
- package/lib/cjs/position/Position.js +2 -0
- package/lib/cjs/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/cjs/position/PreLiquidationPosition.js +2 -0
- package/lib/cjs/preLiquidation.d.ts +16 -0
- package/lib/cjs/preLiquidation.js +16 -0
- package/lib/cjs/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ConstantWrappedToken.js +1 -0
- package/lib/cjs/token/Eip5267Domain.d.ts +4 -0
- package/lib/cjs/token/Eip5267Domain.js +2 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/cjs/token/Token.d.ts +2 -0
- package/lib/cjs/token/Token.js +1 -0
- package/lib/cjs/token/VaultToken.d.ts +2 -0
- package/lib/cjs/token/VaultToken.js +1 -0
- package/lib/cjs/token/WrappedToken.d.ts +1 -0
- package/lib/cjs/token/WrappedToken.js +1 -0
- package/lib/cjs/types.d.ts +17 -0
- package/lib/cjs/types.js +13 -0
- package/lib/cjs/user/User.d.ts +1 -0
- package/lib/cjs/user/User.js +1 -0
- package/lib/cjs/utils.d.ts +2 -0
- package/lib/cjs/utils.js +1 -0
- package/lib/cjs/vault/Vault.d.ts +7 -0
- package/lib/cjs/vault/Vault.js +2 -0
- package/lib/cjs/vault/VaultConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketAllocation.js +1 -0
- package/lib/cjs/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/cjs/vault/VaultMarketConfig.js +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/cjs/vault/VaultUser.d.ts +2 -0
- package/lib/cjs/vault/VaultUser.js +1 -0
- package/lib/cjs/vault/VaultUtils.d.ts +49 -0
- package/lib/cjs/vault/VaultUtils.js +49 -0
- package/lib/cjs/vault/v2/VaultV2.d.ts +5 -0
- package/lib/cjs/vault/v2/VaultV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/cjs/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/lib/esm/addresses.d.ts +105 -0
- package/lib/esm/addresses.js +74 -0
- package/lib/esm/chain.d.ts +84 -1
- package/lib/esm/chain.js +78 -0
- package/lib/esm/errors.d.ts +34 -0
- package/lib/esm/errors.js +28 -0
- package/lib/esm/holding/AssetBalances.d.ts +3 -0
- package/lib/esm/holding/AssetBalances.js +1 -0
- package/lib/esm/holding/Holding.d.ts +6 -0
- package/lib/esm/holding/Holding.js +2 -0
- package/lib/esm/market/Market.d.ts +4 -0
- package/lib/esm/market/MarketParams.d.ts +3 -0
- package/lib/esm/market/MarketParams.js +1 -0
- package/lib/esm/market/MarketUtils.d.ts +397 -0
- package/lib/esm/market/MarketUtils.js +397 -2
- package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +51 -1
- package/lib/esm/math/AdaptiveCurveIrmLib.js +51 -1
- package/lib/esm/math/MathLib.d.ts +152 -4
- package/lib/esm/math/MathLib.js +151 -4
- package/lib/esm/math/SharesMath.d.ts +34 -0
- package/lib/esm/math/SharesMath.js +34 -0
- package/lib/esm/position/Position.d.ts +4 -0
- package/lib/esm/position/Position.js +2 -0
- package/lib/esm/position/PreLiquidationPosition.d.ts +4 -0
- package/lib/esm/position/PreLiquidationPosition.js +2 -0
- package/lib/esm/preLiquidation.d.ts +16 -0
- package/lib/esm/preLiquidation.js +16 -0
- package/lib/esm/token/ConstantWrappedToken.d.ts +1 -0
- package/lib/esm/token/ConstantWrappedToken.js +1 -0
- package/lib/esm/token/Eip5267Domain.d.ts +4 -0
- package/lib/esm/token/Eip5267Domain.js +2 -0
- package/lib/esm/token/ExchangeRateWrappedToken.d.ts +1 -0
- package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
- package/lib/esm/token/Token.d.ts +2 -0
- package/lib/esm/token/Token.js +1 -0
- package/lib/esm/token/VaultToken.d.ts +2 -0
- package/lib/esm/token/VaultToken.js +1 -0
- package/lib/esm/token/WrappedToken.d.ts +1 -0
- package/lib/esm/token/WrappedToken.js +1 -0
- package/lib/esm/types.d.ts +17 -0
- package/lib/esm/types.js +13 -0
- package/lib/esm/user/User.d.ts +1 -0
- package/lib/esm/user/User.js +1 -0
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +1 -0
- package/lib/esm/vault/Vault.d.ts +7 -0
- package/lib/esm/vault/Vault.js +2 -0
- package/lib/esm/vault/VaultConfig.d.ts +2 -0
- package/lib/esm/vault/VaultConfig.js +1 -0
- package/lib/esm/vault/VaultMarketAllocation.d.ts +2 -0
- package/lib/esm/vault/VaultMarketAllocation.js +1 -0
- package/lib/esm/vault/VaultMarketConfig.d.ts +2 -0
- package/lib/esm/vault/VaultMarketConfig.js +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
- package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +1 -0
- package/lib/esm/vault/VaultUser.d.ts +2 -0
- package/lib/esm/vault/VaultUser.js +1 -0
- package/lib/esm/vault/VaultUtils.d.ts +49 -0
- package/lib/esm/vault/VaultUtils.js +49 -0
- package/lib/esm/vault/v2/VaultV2.d.ts +5 -0
- package/lib/esm/vault/v2/VaultV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2Adapter.d.ts +3 -0
- package/lib/esm/vault/v2/VaultV2Adapter.js +1 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +2 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +2 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
- package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
- package/package.json +2 -2
package/lib/esm/chain.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Supported EIP-155 chain ids with Morpho Blue deployments or registry metadata. */
|
|
1
2
|
export declare enum ChainId {
|
|
2
3
|
EthMainnet = 1,
|
|
3
4
|
BaseMainnet = 8453,
|
|
@@ -37,8 +38,10 @@ export declare enum ChainId {
|
|
|
37
38
|
GensynMainnet = 685689,
|
|
38
39
|
FlareMainnet = 14,
|
|
39
40
|
XdcMainnet = 50,
|
|
40
|
-
KaiaMainnet = 8217
|
|
41
|
+
KaiaMainnet = 8217,
|
|
42
|
+
ArcMainnet = 5042
|
|
41
43
|
}
|
|
44
|
+
/** Explorer, native currency, and identifier metadata for a supported chain. */
|
|
42
45
|
export interface ChainMetadata {
|
|
43
46
|
readonly name: string;
|
|
44
47
|
readonly id: ChainId;
|
|
@@ -52,12 +55,81 @@ export interface ChainMetadata {
|
|
|
52
55
|
/** Whether eth_getBalance returns a reliable value. Defaults to true. */
|
|
53
56
|
readonly hasReliableNativeBalance?: boolean;
|
|
54
57
|
}
|
|
58
|
+
/** Chain metadata helpers and registries. */
|
|
55
59
|
export declare namespace ChainUtils {
|
|
60
|
+
/**
|
|
61
|
+
* Returns whether native token balances are reliable on a chain.
|
|
62
|
+
*
|
|
63
|
+
* @param chainId - The EIP-155 chain id to inspect.
|
|
64
|
+
* @returns `false` only for chains whose metadata marks native balances as unreliable.
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
68
|
+
*
|
|
69
|
+
* const reliable = ChainUtils.hasReliableNativeBalance(ChainId.EthMainnet);
|
|
70
|
+
* // reliable === true
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
56
73
|
const hasReliableNativeBalance: (chainId: number) => boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Converts a supported chain id to its hexadecimal JSON-RPC form.
|
|
76
|
+
*
|
|
77
|
+
* @param chainId - The supported chain id.
|
|
78
|
+
* @returns The chain id as a `0x`-prefixed hexadecimal string.
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
82
|
+
*
|
|
83
|
+
* const hexChainId = ChainUtils.toHexChainId(ChainId.EthMainnet);
|
|
84
|
+
* // hexChainId === "0x1"
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
57
87
|
const toHexChainId: (chainId: ChainId) => string;
|
|
88
|
+
/**
|
|
89
|
+
* Returns the block explorer base URL for a supported chain.
|
|
90
|
+
*
|
|
91
|
+
* @param chainId - The supported chain id.
|
|
92
|
+
* @returns The chain's configured block explorer base URL.
|
|
93
|
+
* @example
|
|
94
|
+
* ```ts
|
|
95
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
96
|
+
*
|
|
97
|
+
* const explorerUrl = ChainUtils.getExplorerUrl(ChainId.EthMainnet);
|
|
98
|
+
* // explorerUrl === "https://etherscan.io"
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
58
101
|
const getExplorerUrl: (chainId: ChainId) => string;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a block explorer address URL for a supported chain.
|
|
104
|
+
*
|
|
105
|
+
* @param chainId - The supported chain id.
|
|
106
|
+
* @param address - The address to link to.
|
|
107
|
+
* @returns The block explorer URL for `address`.
|
|
108
|
+
* @example
|
|
109
|
+
* ```ts
|
|
110
|
+
* import { ChainId, ChainUtils, NATIVE_ADDRESS } from "@morpho-org/blue-sdk";
|
|
111
|
+
*
|
|
112
|
+
* const url = ChainUtils.getExplorerAddressUrl(ChainId.EthMainnet, NATIVE_ADDRESS);
|
|
113
|
+
* // url satisfies string
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
59
116
|
const getExplorerAddressUrl: (chainId: ChainId, address: string) => string;
|
|
117
|
+
/**
|
|
118
|
+
* Returns a block explorer transaction URL for a supported chain.
|
|
119
|
+
*
|
|
120
|
+
* @param chainId - The supported chain id.
|
|
121
|
+
* @param tx - The transaction hash to link to.
|
|
122
|
+
* @returns The block explorer URL for `tx`.
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
126
|
+
*
|
|
127
|
+
* const url = ChainUtils.getExplorerTransactionUrl(ChainId.EthMainnet, "0xabc");
|
|
128
|
+
* // url satisfies string
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
60
131
|
const getExplorerTransactionUrl: (chainId: ChainId, tx: string) => string;
|
|
132
|
+
/** Metadata for each supported chain, keyed by `ChainId`. */
|
|
61
133
|
const CHAIN_METADATA: {
|
|
62
134
|
1: {
|
|
63
135
|
name: string;
|
|
@@ -489,5 +561,16 @@ export declare namespace ChainUtils {
|
|
|
489
561
|
explorerUrl: string;
|
|
490
562
|
identifier: string;
|
|
491
563
|
};
|
|
564
|
+
5042: {
|
|
565
|
+
name: string;
|
|
566
|
+
id: ChainId.ArcMainnet;
|
|
567
|
+
nativeCurrency: {
|
|
568
|
+
name: string;
|
|
569
|
+
symbol: string;
|
|
570
|
+
decimals: number;
|
|
571
|
+
};
|
|
572
|
+
explorerUrl: string;
|
|
573
|
+
identifier: string;
|
|
574
|
+
};
|
|
492
575
|
};
|
|
493
576
|
}
|
package/lib/esm/chain.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Supported EIP-155 chain ids with Morpho Blue deployments or registry metadata. */
|
|
1
2
|
export var ChainId;
|
|
2
3
|
(function (ChainId) {
|
|
3
4
|
ChainId[ChainId["EthMainnet"] = 1] = "EthMainnet";
|
|
@@ -39,25 +40,95 @@ export var ChainId;
|
|
|
39
40
|
ChainId[ChainId["FlareMainnet"] = 14] = "FlareMainnet";
|
|
40
41
|
ChainId[ChainId["XdcMainnet"] = 50] = "XdcMainnet";
|
|
41
42
|
ChainId[ChainId["KaiaMainnet"] = 8217] = "KaiaMainnet";
|
|
43
|
+
ChainId[ChainId["ArcMainnet"] = 5042] = "ArcMainnet";
|
|
42
44
|
})(ChainId || (ChainId = {}));
|
|
45
|
+
/** Chain metadata helpers and registries. */
|
|
43
46
|
export var ChainUtils;
|
|
44
47
|
(function (ChainUtils) {
|
|
48
|
+
/**
|
|
49
|
+
* Returns whether native token balances are reliable on a chain.
|
|
50
|
+
*
|
|
51
|
+
* @param chainId - The EIP-155 chain id to inspect.
|
|
52
|
+
* @returns `false` only for chains whose metadata marks native balances as unreliable.
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
56
|
+
*
|
|
57
|
+
* const reliable = ChainUtils.hasReliableNativeBalance(ChainId.EthMainnet);
|
|
58
|
+
* // reliable === true
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
45
61
|
ChainUtils.hasReliableNativeBalance = (chainId) => {
|
|
46
62
|
return (ChainUtils.CHAIN_METADATA[chainId]
|
|
47
63
|
?.hasReliableNativeBalance ?? true);
|
|
48
64
|
};
|
|
65
|
+
/**
|
|
66
|
+
* Converts a supported chain id to its hexadecimal JSON-RPC form.
|
|
67
|
+
*
|
|
68
|
+
* @param chainId - The supported chain id.
|
|
69
|
+
* @returns The chain id as a `0x`-prefixed hexadecimal string.
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
73
|
+
*
|
|
74
|
+
* const hexChainId = ChainUtils.toHexChainId(ChainId.EthMainnet);
|
|
75
|
+
* // hexChainId === "0x1"
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
49
78
|
ChainUtils.toHexChainId = (chainId) => {
|
|
50
79
|
return `0x${chainId.toString(16)}`;
|
|
51
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Returns the block explorer base URL for a supported chain.
|
|
83
|
+
*
|
|
84
|
+
* @param chainId - The supported chain id.
|
|
85
|
+
* @returns The chain's configured block explorer base URL.
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
89
|
+
*
|
|
90
|
+
* const explorerUrl = ChainUtils.getExplorerUrl(ChainId.EthMainnet);
|
|
91
|
+
* // explorerUrl === "https://etherscan.io"
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
52
94
|
ChainUtils.getExplorerUrl = (chainId) => {
|
|
53
95
|
return ChainUtils.CHAIN_METADATA[chainId].explorerUrl;
|
|
54
96
|
};
|
|
97
|
+
/**
|
|
98
|
+
* Returns a block explorer address URL for a supported chain.
|
|
99
|
+
*
|
|
100
|
+
* @param chainId - The supported chain id.
|
|
101
|
+
* @param address - The address to link to.
|
|
102
|
+
* @returns The block explorer URL for `address`.
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { ChainId, ChainUtils, NATIVE_ADDRESS } from "@morpho-org/blue-sdk";
|
|
106
|
+
*
|
|
107
|
+
* const url = ChainUtils.getExplorerAddressUrl(ChainId.EthMainnet, NATIVE_ADDRESS);
|
|
108
|
+
* // url satisfies string
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
55
111
|
ChainUtils.getExplorerAddressUrl = (chainId, address) => {
|
|
56
112
|
return `${ChainUtils.getExplorerUrl(chainId)}/address/${address}`;
|
|
57
113
|
};
|
|
114
|
+
/**
|
|
115
|
+
* Returns a block explorer transaction URL for a supported chain.
|
|
116
|
+
*
|
|
117
|
+
* @param chainId - The supported chain id.
|
|
118
|
+
* @param tx - The transaction hash to link to.
|
|
119
|
+
* @returns The block explorer URL for `tx`.
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
|
|
123
|
+
*
|
|
124
|
+
* const url = ChainUtils.getExplorerTransactionUrl(ChainId.EthMainnet, "0xabc");
|
|
125
|
+
* // url satisfies string
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
58
128
|
ChainUtils.getExplorerTransactionUrl = (chainId, tx) => {
|
|
59
129
|
return `${ChainUtils.getExplorerUrl(chainId)}/tx/${tx}`;
|
|
60
130
|
};
|
|
131
|
+
/** Metadata for each supported chain, keyed by `ChainId`. */
|
|
61
132
|
ChainUtils.CHAIN_METADATA = {
|
|
62
133
|
[ChainId.EthMainnet]: {
|
|
63
134
|
name: "Ethereum",
|
|
@@ -333,5 +404,12 @@ export var ChainUtils;
|
|
|
333
404
|
explorerUrl: "https://kaiascan.io",
|
|
334
405
|
identifier: "kaia",
|
|
335
406
|
},
|
|
407
|
+
[ChainId.ArcMainnet]: {
|
|
408
|
+
name: "Arc",
|
|
409
|
+
id: ChainId.ArcMainnet,
|
|
410
|
+
nativeCurrency: { name: "USDC", symbol: "USDC", decimals: 18 },
|
|
411
|
+
explorerUrl: "http://explorer.arc.io/",
|
|
412
|
+
identifier: "arc",
|
|
413
|
+
},
|
|
336
414
|
};
|
|
337
415
|
})(ChainUtils || (ChainUtils = {}));
|
package/lib/esm/errors.d.ts
CHANGED
|
@@ -1,101 +1,135 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
2
|
import type { Address, MarketId } from "./types.js";
|
|
3
|
+
/** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
|
|
3
4
|
export declare class InvalidMarketParamsError extends Error {
|
|
4
5
|
readonly data: Hex;
|
|
5
6
|
constructor(data: Hex);
|
|
6
7
|
}
|
|
8
|
+
/** Base error for optional data lookups that were not available. */
|
|
7
9
|
export declare class UnknownDataError extends Error {
|
|
8
10
|
}
|
|
11
|
+
/** Error thrown when token metadata is unavailable for an address. */
|
|
9
12
|
export declare class UnknownTokenError extends UnknownDataError {
|
|
10
13
|
readonly address: Address;
|
|
11
14
|
constructor(address: Address);
|
|
12
15
|
}
|
|
16
|
+
/** Error thrown when a token price is unavailable for an address. */
|
|
13
17
|
export declare class UnknownTokenPriceError extends UnknownDataError {
|
|
14
18
|
readonly address: Address;
|
|
15
19
|
constructor(address: Address);
|
|
16
20
|
}
|
|
21
|
+
/** Error thrown when market params are unavailable for a market id. */
|
|
17
22
|
export declare class UnknownMarketParamsError extends UnknownDataError {
|
|
18
23
|
readonly marketId: MarketId;
|
|
19
24
|
constructor(marketId: MarketId);
|
|
20
25
|
}
|
|
26
|
+
/** Error thrown when vault config is unavailable for a vault address. */
|
|
21
27
|
export declare class UnknownVaultConfigError extends UnknownDataError {
|
|
22
28
|
readonly vault: Address;
|
|
23
29
|
constructor(vault: Address);
|
|
24
30
|
}
|
|
31
|
+
/** Error thrown when a chain id has no configured SDK registry entry. */
|
|
25
32
|
export declare class UnsupportedChainIdError extends Error {
|
|
26
33
|
readonly chainId: number;
|
|
27
34
|
constructor(chainId: number);
|
|
28
35
|
}
|
|
36
|
+
/** Error thrown when no default pre-liquidation params exist for an LLTV. */
|
|
29
37
|
export declare class UnsupportedPreLiquidationParamsError extends Error {
|
|
30
38
|
readonly lltv: bigint;
|
|
31
39
|
constructor(lltv: bigint);
|
|
32
40
|
}
|
|
41
|
+
/** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
|
|
33
42
|
export declare class UnsupportedVaultV2AdapterError extends Error {
|
|
34
43
|
readonly address: Address;
|
|
35
44
|
constructor(address: Address);
|
|
36
45
|
}
|
|
46
|
+
/** Morpho Blue protocol simulation errors. */
|
|
37
47
|
export declare namespace BlueErrors {
|
|
48
|
+
/** Error thrown when a value that must be set once is already set. */
|
|
38
49
|
class AlreadySet extends Error {
|
|
39
50
|
readonly name: string;
|
|
40
51
|
readonly value: string;
|
|
41
52
|
constructor(name: string, value: string);
|
|
42
53
|
}
|
|
54
|
+
/** Error thrown when market interest accrual is requested before `lastUpdate`. */
|
|
43
55
|
class InvalidInterestAccrual extends Error {
|
|
44
56
|
readonly marketId: MarketId;
|
|
45
57
|
readonly timestamp: bigint;
|
|
46
58
|
readonly lastUpdate: bigint;
|
|
47
59
|
constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
|
|
48
60
|
}
|
|
61
|
+
/** Error thrown when asset and share inputs describe inconsistent values. */
|
|
49
62
|
class InconsistentInput extends Error {
|
|
50
63
|
readonly assets: bigint;
|
|
51
64
|
readonly shares: bigint;
|
|
52
65
|
constructor(assets: bigint, shares: bigint);
|
|
53
66
|
}
|
|
67
|
+
/** Error thrown when a market has insufficient liquidity for an operation. */
|
|
54
68
|
class InsufficientLiquidity extends Error {
|
|
55
69
|
readonly marketId: MarketId;
|
|
56
70
|
constructor(marketId: MarketId);
|
|
57
71
|
}
|
|
72
|
+
/** Error thrown when a market oracle price is unavailable. */
|
|
58
73
|
class UnknownOraclePrice extends Error {
|
|
59
74
|
readonly marketId: MarketId;
|
|
60
75
|
constructor(marketId: MarketId);
|
|
61
76
|
}
|
|
77
|
+
/** Error thrown when a user position is too small for an operation. */
|
|
62
78
|
class InsufficientPosition extends Error {
|
|
63
79
|
readonly user: Address;
|
|
64
80
|
readonly marketId: MarketId;
|
|
65
81
|
constructor(user: Address, marketId: MarketId);
|
|
66
82
|
}
|
|
83
|
+
/** Error thrown when a user position lacks required collateral. */
|
|
67
84
|
class InsufficientCollateral extends Error {
|
|
68
85
|
readonly user: Address;
|
|
69
86
|
readonly marketId: MarketId;
|
|
70
87
|
constructor(user: Address, marketId: MarketId);
|
|
71
88
|
}
|
|
89
|
+
/** Error thrown when a signature deadline has expired. */
|
|
72
90
|
class ExpiredSignature extends Error {
|
|
73
91
|
readonly deadline: bigint;
|
|
74
92
|
constructor(deadline: bigint);
|
|
75
93
|
}
|
|
76
94
|
}
|
|
95
|
+
/** Morpho Vault V2 simulation errors. */
|
|
77
96
|
export declare namespace VaultV2Errors {
|
|
97
|
+
/** Error thrown when vault interest accrual is requested before `lastUpdate`. */
|
|
78
98
|
class InvalidInterestAccrual extends Error {
|
|
79
99
|
readonly vault: Address;
|
|
80
100
|
readonly timestamp: bigint;
|
|
81
101
|
readonly lastUpdate: bigint;
|
|
82
102
|
constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
|
|
83
103
|
}
|
|
104
|
+
/** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
|
|
84
105
|
class UnsupportedLiquidityAdapter extends Error {
|
|
85
106
|
readonly address: Address;
|
|
86
107
|
constructor(address: Address);
|
|
87
108
|
}
|
|
88
109
|
}
|
|
110
|
+
/** Error thrown when a factory address is unavailable. */
|
|
89
111
|
export declare class UnknownFactory extends Error {
|
|
90
112
|
constructor();
|
|
91
113
|
}
|
|
114
|
+
/** Error thrown when an address is not deployed by the expected factory. */
|
|
92
115
|
export declare class UnknownOfFactory extends Error {
|
|
93
116
|
readonly factory: Address;
|
|
94
117
|
readonly address: Address;
|
|
95
118
|
constructor(factory: Address, address: Address);
|
|
96
119
|
}
|
|
120
|
+
/** Constructor type for errors accepted by `_try`. */
|
|
97
121
|
export interface ErrorClass<E extends Error = Error> {
|
|
98
122
|
new (...args: any[]): E;
|
|
99
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Runs an async accessor and returns `undefined` for expected lookup errors.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
100
129
|
export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => Promise<T>, ...errorClasses: ErrorClasses): Promise<T | undefined>;
|
|
130
|
+
/**
|
|
131
|
+
* Runs a sync accessor and returns `undefined` for expected lookup errors.
|
|
132
|
+
*
|
|
133
|
+
* @internal
|
|
134
|
+
*/
|
|
101
135
|
export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => T, ...errorClasses: ErrorClasses): T | undefined;
|
package/lib/esm/errors.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { formatUnits } from "viem";
|
|
2
|
+
/** Error thrown when bytes cannot be decoded into valid Morpho Blue market params. */
|
|
2
3
|
export class InvalidMarketParamsError extends Error {
|
|
3
4
|
data;
|
|
4
5
|
constructor(data) {
|
|
@@ -6,8 +7,10 @@ export class InvalidMarketParamsError extends Error {
|
|
|
6
7
|
this.data = data;
|
|
7
8
|
}
|
|
8
9
|
}
|
|
10
|
+
/** Base error for optional data lookups that were not available. */
|
|
9
11
|
export class UnknownDataError extends Error {
|
|
10
12
|
}
|
|
13
|
+
/** Error thrown when token metadata is unavailable for an address. */
|
|
11
14
|
export class UnknownTokenError extends UnknownDataError {
|
|
12
15
|
address;
|
|
13
16
|
constructor(address) {
|
|
@@ -15,6 +18,7 @@ export class UnknownTokenError extends UnknownDataError {
|
|
|
15
18
|
this.address = address;
|
|
16
19
|
}
|
|
17
20
|
}
|
|
21
|
+
/** Error thrown when a token price is unavailable for an address. */
|
|
18
22
|
export class UnknownTokenPriceError extends UnknownDataError {
|
|
19
23
|
address;
|
|
20
24
|
constructor(address) {
|
|
@@ -22,6 +26,7 @@ export class UnknownTokenPriceError extends UnknownDataError {
|
|
|
22
26
|
this.address = address;
|
|
23
27
|
}
|
|
24
28
|
}
|
|
29
|
+
/** Error thrown when market params are unavailable for a market id. */
|
|
25
30
|
export class UnknownMarketParamsError extends UnknownDataError {
|
|
26
31
|
marketId;
|
|
27
32
|
constructor(marketId) {
|
|
@@ -29,6 +34,7 @@ export class UnknownMarketParamsError extends UnknownDataError {
|
|
|
29
34
|
this.marketId = marketId;
|
|
30
35
|
}
|
|
31
36
|
}
|
|
37
|
+
/** Error thrown when vault config is unavailable for a vault address. */
|
|
32
38
|
export class UnknownVaultConfigError extends UnknownDataError {
|
|
33
39
|
vault;
|
|
34
40
|
constructor(vault) {
|
|
@@ -36,6 +42,7 @@ export class UnknownVaultConfigError extends UnknownDataError {
|
|
|
36
42
|
this.vault = vault;
|
|
37
43
|
}
|
|
38
44
|
}
|
|
45
|
+
/** Error thrown when a chain id has no configured SDK registry entry. */
|
|
39
46
|
export class UnsupportedChainIdError extends Error {
|
|
40
47
|
chainId;
|
|
41
48
|
constructor(chainId) {
|
|
@@ -43,6 +50,7 @@ export class UnsupportedChainIdError extends Error {
|
|
|
43
50
|
this.chainId = chainId;
|
|
44
51
|
}
|
|
45
52
|
}
|
|
53
|
+
/** Error thrown when no default pre-liquidation params exist for an LLTV. */
|
|
46
54
|
export class UnsupportedPreLiquidationParamsError extends Error {
|
|
47
55
|
lltv;
|
|
48
56
|
constructor(lltv) {
|
|
@@ -50,6 +58,7 @@ export class UnsupportedPreLiquidationParamsError extends Error {
|
|
|
50
58
|
this.lltv = lltv;
|
|
51
59
|
}
|
|
52
60
|
}
|
|
61
|
+
/** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
|
|
53
62
|
export class UnsupportedVaultV2AdapterError extends Error {
|
|
54
63
|
address;
|
|
55
64
|
constructor(address) {
|
|
@@ -57,8 +66,10 @@ export class UnsupportedVaultV2AdapterError extends Error {
|
|
|
57
66
|
this.address = address;
|
|
58
67
|
}
|
|
59
68
|
}
|
|
69
|
+
/** Morpho Blue protocol simulation errors. */
|
|
60
70
|
export var BlueErrors;
|
|
61
71
|
(function (BlueErrors) {
|
|
72
|
+
/** Error thrown when a value that must be set once is already set. */
|
|
62
73
|
class AlreadySet extends Error {
|
|
63
74
|
name;
|
|
64
75
|
value;
|
|
@@ -69,6 +80,7 @@ export var BlueErrors;
|
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
BlueErrors.AlreadySet = AlreadySet;
|
|
83
|
+
/** Error thrown when market interest accrual is requested before `lastUpdate`. */
|
|
72
84
|
class InvalidInterestAccrual extends Error {
|
|
73
85
|
marketId;
|
|
74
86
|
timestamp;
|
|
@@ -82,6 +94,7 @@ export var BlueErrors;
|
|
|
82
94
|
}
|
|
83
95
|
}
|
|
84
96
|
BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
97
|
+
/** Error thrown when asset and share inputs describe inconsistent values. */
|
|
85
98
|
class InconsistentInput extends Error {
|
|
86
99
|
assets;
|
|
87
100
|
shares;
|
|
@@ -92,6 +105,7 @@ export var BlueErrors;
|
|
|
92
105
|
}
|
|
93
106
|
}
|
|
94
107
|
BlueErrors.InconsistentInput = InconsistentInput;
|
|
108
|
+
/** Error thrown when a market has insufficient liquidity for an operation. */
|
|
95
109
|
class InsufficientLiquidity extends Error {
|
|
96
110
|
marketId;
|
|
97
111
|
constructor(marketId) {
|
|
@@ -100,6 +114,7 @@ export var BlueErrors;
|
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
116
|
BlueErrors.InsufficientLiquidity = InsufficientLiquidity;
|
|
117
|
+
/** Error thrown when a market oracle price is unavailable. */
|
|
103
118
|
class UnknownOraclePrice extends Error {
|
|
104
119
|
marketId;
|
|
105
120
|
constructor(marketId) {
|
|
@@ -108,6 +123,7 @@ export var BlueErrors;
|
|
|
108
123
|
}
|
|
109
124
|
}
|
|
110
125
|
BlueErrors.UnknownOraclePrice = UnknownOraclePrice;
|
|
126
|
+
/** Error thrown when a user position is too small for an operation. */
|
|
111
127
|
class InsufficientPosition extends Error {
|
|
112
128
|
user;
|
|
113
129
|
marketId;
|
|
@@ -118,6 +134,7 @@ export var BlueErrors;
|
|
|
118
134
|
}
|
|
119
135
|
}
|
|
120
136
|
BlueErrors.InsufficientPosition = InsufficientPosition;
|
|
137
|
+
/** Error thrown when a user position lacks required collateral. */
|
|
121
138
|
class InsufficientCollateral extends Error {
|
|
122
139
|
user;
|
|
123
140
|
marketId;
|
|
@@ -128,6 +145,7 @@ export var BlueErrors;
|
|
|
128
145
|
}
|
|
129
146
|
}
|
|
130
147
|
BlueErrors.InsufficientCollateral = InsufficientCollateral;
|
|
148
|
+
/** Error thrown when a signature deadline has expired. */
|
|
131
149
|
class ExpiredSignature extends Error {
|
|
132
150
|
deadline;
|
|
133
151
|
constructor(deadline) {
|
|
@@ -137,8 +155,10 @@ export var BlueErrors;
|
|
|
137
155
|
}
|
|
138
156
|
BlueErrors.ExpiredSignature = ExpiredSignature;
|
|
139
157
|
})(BlueErrors || (BlueErrors = {}));
|
|
158
|
+
/** Morpho Vault V2 simulation errors. */
|
|
140
159
|
export var VaultV2Errors;
|
|
141
160
|
(function (VaultV2Errors) {
|
|
161
|
+
/** Error thrown when vault interest accrual is requested before `lastUpdate`. */
|
|
142
162
|
class InvalidInterestAccrual extends Error {
|
|
143
163
|
vault;
|
|
144
164
|
timestamp;
|
|
@@ -152,6 +172,7 @@ export var VaultV2Errors;
|
|
|
152
172
|
}
|
|
153
173
|
}
|
|
154
174
|
VaultV2Errors.InvalidInterestAccrual = InvalidInterestAccrual;
|
|
175
|
+
/** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
|
|
155
176
|
class UnsupportedLiquidityAdapter extends Error {
|
|
156
177
|
address;
|
|
157
178
|
constructor(address) {
|
|
@@ -161,11 +182,13 @@ export var VaultV2Errors;
|
|
|
161
182
|
}
|
|
162
183
|
VaultV2Errors.UnsupportedLiquidityAdapter = UnsupportedLiquidityAdapter;
|
|
163
184
|
})(VaultV2Errors || (VaultV2Errors = {}));
|
|
185
|
+
/** Error thrown when a factory address is unavailable. */
|
|
164
186
|
export class UnknownFactory extends Error {
|
|
165
187
|
constructor() {
|
|
166
188
|
super(`unknown factory`);
|
|
167
189
|
}
|
|
168
190
|
}
|
|
191
|
+
/** Error thrown when an address is not deployed by the expected factory. */
|
|
169
192
|
export class UnknownOfFactory extends Error {
|
|
170
193
|
factory;
|
|
171
194
|
address;
|
|
@@ -175,6 +198,11 @@ export class UnknownOfFactory extends Error {
|
|
|
175
198
|
this.address = address;
|
|
176
199
|
}
|
|
177
200
|
}
|
|
201
|
+
/**
|
|
202
|
+
* Runs an accessor and returns `undefined` for expected lookup errors.
|
|
203
|
+
*
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
178
206
|
export function _try(accessor, ...errorClasses) {
|
|
179
207
|
const maybeCatchError = (error) => {
|
|
180
208
|
if (errorClasses.length === 0 ||
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Token } from "../token/Token.js";
|
|
2
|
+
/** Balance conversion category for a requested token and related peripheral tokens. */
|
|
2
3
|
export type PeripheralBalanceType = "base" | "wrapped" | "staked-wrapped" | "vault" | "wrapped-vault" | "unwrapped-staked-wrapped";
|
|
3
4
|
/**
|
|
4
5
|
* Represents the balance of a requested token and the balance quoted in the corresponding source token:
|
|
@@ -27,8 +28,10 @@ export interface PeripheralBalance {
|
|
|
27
28
|
*/
|
|
28
29
|
dstAmount: bigint;
|
|
29
30
|
}
|
|
31
|
+
/** Constructor input for `AssetBalances`. */
|
|
30
32
|
export interface IAssetBalances extends Omit<PeripheralBalance, "type"> {
|
|
31
33
|
}
|
|
34
|
+
/** Aggregates balances across a requested token and related peripheral tokens. */
|
|
32
35
|
export declare class AssetBalances {
|
|
33
36
|
/**
|
|
34
37
|
* The total balance of all types of related tokens.
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
import type { Address, BigIntish } from "../types.js";
|
|
2
|
+
/** Address registry labels that may receive ERC-20 allowances from a user. */
|
|
2
3
|
export declare const ERC20_ALLOWANCE_RECIPIENTS: readonly ["morpho", "permit2", "bundler3.generalAdapter1"];
|
|
4
|
+
/** Address registry label that may receive an ERC-20 allowance from a user. */
|
|
3
5
|
export type Erc20AllowanceRecipient = (typeof ERC20_ALLOWANCE_RECIPIENTS)[number];
|
|
6
|
+
/** Normalized Permit2 allowance values. */
|
|
4
7
|
export interface Permit2Allowance {
|
|
5
8
|
amount: bigint;
|
|
6
9
|
expiration: bigint;
|
|
7
10
|
nonce: bigint;
|
|
8
11
|
}
|
|
12
|
+
/** Input shape for Permit2 allowance values before bigint normalization. */
|
|
9
13
|
export interface IPermit2Allowance {
|
|
10
14
|
amount: BigIntish;
|
|
11
15
|
expiration: BigIntish;
|
|
12
16
|
nonce: BigIntish;
|
|
13
17
|
}
|
|
18
|
+
/** Input shape for a user's token holding and allowance state. */
|
|
14
19
|
export interface IHolding {
|
|
15
20
|
user: Address;
|
|
16
21
|
token: Address;
|
|
@@ -22,6 +27,7 @@ export interface IHolding {
|
|
|
22
27
|
canTransfer?: boolean;
|
|
23
28
|
balance: bigint;
|
|
24
29
|
}
|
|
30
|
+
/** Represents a user's balance and allowance state for one token. */
|
|
25
31
|
export declare class Holding implements IHolding {
|
|
26
32
|
/**
|
|
27
33
|
* The user of this holding.
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { entries, fromEntries } from "@morpho-org/morpho-ts";
|
|
2
|
+
/** Address registry labels that may receive ERC-20 allowances from a user. */
|
|
2
3
|
export const ERC20_ALLOWANCE_RECIPIENTS = [
|
|
3
4
|
"morpho",
|
|
4
5
|
"permit2",
|
|
5
6
|
"bundler3.generalAdapter1",
|
|
6
7
|
];
|
|
8
|
+
/** Represents a user's balance and allowance state for one token. */
|
|
7
9
|
export class Holding {
|
|
8
10
|
/**
|
|
9
11
|
* The user of this holding.
|
|
@@ -2,12 +2,15 @@ import { type RoundingDirection } from "../math/index.js";
|
|
|
2
2
|
import type { BigIntish } from "../types.js";
|
|
3
3
|
import { type CapacityLimit } from "../utils.js";
|
|
4
4
|
import { type IMarketParams, MarketParams } from "./MarketParams.js";
|
|
5
|
+
/** Options for max borrow capacity calculations. */
|
|
5
6
|
export interface MaxBorrowOptions {
|
|
6
7
|
maxLtv?: bigint;
|
|
7
8
|
}
|
|
9
|
+
/** Options for max withdraw collateral capacity calculations. */
|
|
8
10
|
export interface MaxWithdrawCollateralOptions {
|
|
9
11
|
maxLtv?: bigint;
|
|
10
12
|
}
|
|
13
|
+
/** Capacity limits for each market operation available to a position. */
|
|
11
14
|
export interface MaxPositionCapacities {
|
|
12
15
|
supply: CapacityLimit;
|
|
13
16
|
withdraw: CapacityLimit;
|
|
@@ -16,6 +19,7 @@ export interface MaxPositionCapacities {
|
|
|
16
19
|
supplyCollateral: CapacityLimit;
|
|
17
20
|
withdrawCollateral: CapacityLimit | undefined;
|
|
18
21
|
}
|
|
22
|
+
/** Plain input shape for a Morpho Blue market. */
|
|
19
23
|
export interface IMarket {
|
|
20
24
|
params: IMarketParams;
|
|
21
25
|
totalSupplyAssets: bigint;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Hex } from "viem";
|
|
2
2
|
import type { Address, BigIntish, MarketId } from "../types.js";
|
|
3
|
+
/** Plain input shape for Morpho Blue market params. */
|
|
3
4
|
export interface IMarketParams {
|
|
4
5
|
loanToken: Address;
|
|
5
6
|
collateralToken: Address;
|
|
@@ -7,7 +8,9 @@ export interface IMarketParams {
|
|
|
7
8
|
irm: Address;
|
|
8
9
|
lltv: BigIntish;
|
|
9
10
|
}
|
|
11
|
+
/** Minimal market params shape accepted by SDK constructors and helpers. */
|
|
10
12
|
export type InputMarketParams = Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
|
|
13
|
+
/** ABI tuple definition for Morpho Blue market params. */
|
|
11
14
|
export declare const marketParamsAbi: {
|
|
12
15
|
readonly type: "tuple";
|
|
13
16
|
readonly components: readonly [{
|
|
@@ -2,6 +2,7 @@ import { ZERO_ADDRESS } from "@morpho-org/morpho-ts";
|
|
|
2
2
|
import { decodeAbiParameters } from "viem";
|
|
3
3
|
import { InvalidMarketParamsError, UnknownMarketParamsError, } from "../errors.js";
|
|
4
4
|
import { MarketUtils } from "./MarketUtils.js";
|
|
5
|
+
/** ABI tuple definition for Morpho Blue market params. */
|
|
5
6
|
export const marketParamsAbi = {
|
|
6
7
|
type: "tuple",
|
|
7
8
|
components: [
|