@morpho-org/blue-sdk 1.0.0-integ-650.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.
Files changed (86) hide show
  1. package/README.md +106 -0
  2. package/lib/addresses.d.ts +113 -0
  3. package/lib/addresses.js +162 -0
  4. package/lib/chain.d.ts +29 -0
  5. package/lib/chain.js +289 -0
  6. package/lib/chain.test.d.ts +1 -0
  7. package/lib/chain.test.js +21 -0
  8. package/lib/constants.d.ts +29 -0
  9. package/lib/constants.js +33 -0
  10. package/lib/errors.d.ts +58 -0
  11. package/lib/errors.js +119 -0
  12. package/lib/helpers/format/format.d.ts +122 -0
  13. package/lib/helpers/format/format.js +286 -0
  14. package/lib/helpers/format/format.test.d.ts +1 -0
  15. package/lib/helpers/format/format.test.js +255 -0
  16. package/lib/helpers/format/index.d.ts +1 -0
  17. package/lib/helpers/format/index.js +17 -0
  18. package/lib/helpers/index.d.ts +2 -0
  19. package/lib/helpers/index.js +18 -0
  20. package/lib/helpers/locale.d.ts +46 -0
  21. package/lib/helpers/locale.js +96 -0
  22. package/lib/holding/AssetBalances.d.ts +48 -0
  23. package/lib/holding/AssetBalances.js +42 -0
  24. package/lib/holding/Holding.d.ts +59 -0
  25. package/lib/holding/Holding.js +59 -0
  26. package/lib/holding/index.d.ts +2 -0
  27. package/lib/holding/index.js +18 -0
  28. package/lib/index.d.ts +25 -0
  29. package/lib/index.js +54 -0
  30. package/lib/market/Market.d.ts +329 -0
  31. package/lib/market/Market.js +460 -0
  32. package/lib/market/MarketConfig.d.ts +52 -0
  33. package/lib/market/MarketConfig.js +76 -0
  34. package/lib/market/MarketUtils.d.ts +232 -0
  35. package/lib/market/MarketUtils.js +263 -0
  36. package/lib/market/MarketUtils.test.d.ts +1 -0
  37. package/lib/market/MarketUtils.test.js +38 -0
  38. package/lib/market/index.d.ts +3 -0
  39. package/lib/market/index.js +19 -0
  40. package/lib/maths/AdaptiveCurveIrmLib.d.ts +39 -0
  41. package/lib/maths/AdaptiveCurveIrmLib.js +134 -0
  42. package/lib/maths/MathLib.d.ts +114 -0
  43. package/lib/maths/MathLib.js +175 -0
  44. package/lib/maths/SharesMath.d.ts +12 -0
  45. package/lib/maths/SharesMath.js +21 -0
  46. package/lib/maths/index.d.ts +3 -0
  47. package/lib/maths/index.js +19 -0
  48. package/lib/position/Position.d.ts +126 -0
  49. package/lib/position/Position.js +203 -0
  50. package/lib/position/index.d.ts +1 -0
  51. package/lib/position/index.js +17 -0
  52. package/lib/tests/mocks/markets.d.ts +19 -0
  53. package/lib/tests/mocks/markets.js +121 -0
  54. package/lib/token/ConstantWrappedToken.d.ts +18 -0
  55. package/lib/token/ConstantWrappedToken.js +36 -0
  56. package/lib/token/ExchangeRateWrappedToken.d.ts +11 -0
  57. package/lib/token/ExchangeRateWrappedToken.js +21 -0
  58. package/lib/token/Token.d.ts +46 -0
  59. package/lib/token/Token.js +64 -0
  60. package/lib/token/VaultToken.d.ts +14 -0
  61. package/lib/token/VaultToken.js +23 -0
  62. package/lib/token/WrappedToken.d.ts +17 -0
  63. package/lib/token/WrappedToken.js +33 -0
  64. package/lib/token/index.d.ts +5 -0
  65. package/lib/token/index.js +21 -0
  66. package/lib/types.d.ts +30 -0
  67. package/lib/types.js +22 -0
  68. package/lib/user/User.d.ts +20 -0
  69. package/lib/user/User.js +23 -0
  70. package/lib/user/index.d.ts +1 -0
  71. package/lib/user/index.js +17 -0
  72. package/lib/vault/Vault.d.ts +166 -0
  73. package/lib/vault/Vault.js +234 -0
  74. package/lib/vault/VaultConfig.d.ts +22 -0
  75. package/lib/vault/VaultConfig.js +32 -0
  76. package/lib/vault/VaultMarketAllocation.d.ts +20 -0
  77. package/lib/vault/VaultMarketAllocation.js +30 -0
  78. package/lib/vault/VaultMarketConfig.d.ts +43 -0
  79. package/lib/vault/VaultMarketConfig.js +43 -0
  80. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
  81. package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
  82. package/lib/vault/VaultUtils.d.ts +18 -0
  83. package/lib/vault/VaultUtils.js +20 -0
  84. package/lib/vault/index.d.ts +6 -0
  85. package/lib/vault/index.js +22 -0
  86. package/package.json +53 -0
package/lib/chain.js ADDED
@@ -0,0 +1,289 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ChainUtils = exports.ChainId = void 0;
4
+ const errors_1 = require("./errors");
5
+ var ChainId;
6
+ (function (ChainId) {
7
+ ChainId[ChainId["EthMainnet"] = 1] = "EthMainnet";
8
+ ChainId[ChainId["BaseMainnet"] = 8453] = "BaseMainnet";
9
+ // EthGoerliTestnet = 5,
10
+ // PolygonMainnet = 137,
11
+ // MumbaiTestnet = 80001,
12
+ // OptimismMainnet = 10,
13
+ // BscMainnet = 56,
14
+ // ArbitrumMainnet = 42161,
15
+ // ArbitrumTestnet = 421611,
16
+ // GnosisChain = 100,
17
+ // FantomMainnet = 250,
18
+ // FantomTestnet = 4002,
19
+ // HarmonyMainnet = 128,
20
+ // HarmonyTestnet = 1666600000,
21
+ // BscTestnet = 97,
22
+ // OptimismTestnet = 69,
23
+ // EthRopstenTestnet = 3,
24
+ // EthRinkebyTestnet = 4,
25
+ // EthKovanTestnet = 42,
26
+ // GnosisChainTestnet = 10200,
27
+ // AvalancheMainnet = 43114,
28
+ // AvalancheFujiTestnet = 43113,
29
+ // MoonbaseAlphaTestnet = 1287,
30
+ // BaseGoerliTestnet = 84531,
31
+ })(ChainId || (exports.ChainId = ChainId = {}));
32
+ var ChainUtils;
33
+ (function (ChainUtils) {
34
+ ChainUtils.toHexChainId = (chainId) => {
35
+ return `0x${chainId.toString(16)}`;
36
+ };
37
+ ChainUtils.getExplorerUrl = (chainId) => {
38
+ return ChainUtils.CHAIN_METADATA[chainId].explorerUrl;
39
+ };
40
+ ChainUtils.getExplorerAddressUrl = (chainId, address) => {
41
+ return `${ChainUtils.getExplorerUrl(chainId)}/address/${address}`;
42
+ };
43
+ ChainUtils.getExplorerTransactionUrl = (chainId, tx) => {
44
+ return `${ChainUtils.getExplorerUrl(chainId)}/tx/${tx}`;
45
+ };
46
+ function isSupported(chainId) {
47
+ return ChainUtils.BLUE_AVAILABLE_CHAINS.includes(chainId);
48
+ }
49
+ ChainUtils.isSupported = isSupported;
50
+ function parseSupportedChainId(candidate) {
51
+ const chainId = parseInt(candidate);
52
+ if (!isSupported(chainId))
53
+ throw new errors_1.UnsupportedChainIdError(candidate);
54
+ return chainId;
55
+ }
56
+ ChainUtils.parseSupportedChainId = parseSupportedChainId;
57
+ ChainUtils.BLUE_AVAILABLE_CHAINS = [
58
+ ChainId.EthMainnet,
59
+ ChainId.BaseMainnet,
60
+ ];
61
+ ChainUtils.CHAIN_METADATA = {
62
+ [ChainId.EthMainnet]: {
63
+ name: "Ethereum",
64
+ id: ChainId.EthMainnet,
65
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
66
+ defaultRpcUrl: "https://mainnet.infura.io/V3/84842078b09946638c03157f83405213",
67
+ explorerUrl: "https://etherscan.io",
68
+ isTestnet: false,
69
+ shortName: "ETH",
70
+ logoSrc: "https://cdn.morpho.org/assets/chains/eth.svg",
71
+ identifier: "mainnet",
72
+ },
73
+ [ChainId.BaseMainnet]: {
74
+ name: "Base",
75
+ id: ChainId.BaseMainnet,
76
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
77
+ defaultRpcUrl: "https://rpc.baseprotocol.org",
78
+ explorerUrl: "https://basescan.org",
79
+ isTestnet: false,
80
+ shortName: "Base",
81
+ logoSrc: "https://cdn.morpho.org/assets/chains/base.png",
82
+ identifier: "base",
83
+ },
84
+ // [ChainId.EthGoerliTestnet]: {
85
+ // name: "Ethereum Goerli Testnet",
86
+ // id: ChainId.EthGoerliTestnet,
87
+ // nativeCurrency: { name: "Goerli Ether", symbol: "ETH", decimals: 18 },
88
+ // defaultRpcUrl:
89
+ // "https://goerli.infura.io/V3/84842078b09946638c03157f83405213",
90
+ // explorerUrl: "https://goerli.etherscan.io",
91
+ // isTestnet: true,
92
+ // shortName: "Goerli",
93
+ // logoSrc: "https://cdn.morpho.org/assets/chains/eth.svg",
94
+ // identifier: "goerli",
95
+ // },
96
+ // [ChainId.PolygonMainnet]: {
97
+ // name: "Polygon Mainnet",
98
+ // id: ChainId.PolygonMainnet,
99
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
100
+ // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
101
+ // explorerUrl: "https://polygonscan.com",
102
+ // isTestnet: false,
103
+ // shortName: "Polygon",
104
+ // },
105
+ // [ChainId.MumbaiTestnet]: {
106
+ // name: "Mumbai Testnet",
107
+ // id: ChainId.MumbaiTestnet,
108
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
109
+ // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
110
+ // explorerUrl: "https://mumbai.polygonscan.com",
111
+ // isTestnet: true,
112
+ // shortName: "Mumbai",
113
+ // },
114
+ /* see https://chainid.network/chains.json */
115
+ // [ChainId.PolygonMainnet]: {
116
+ // name: "Polygon Mainnet",
117
+ // id: ChainId.PolygonMainnet,
118
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
119
+ // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
120
+ // explorerUrl: "https://polygonscan.com",
121
+ // isTestnet: false,
122
+ // shortName: "Polygon",
123
+ // },
124
+ // [ChainId.MumbaiTestnet]: {
125
+ // name: "Mumbai Testnet",
126
+ // id: ChainId.MumbaiTestnet,
127
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
128
+ // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
129
+ // explorerUrl: "https://mumbai.polygonscan.com",
130
+ // isTestnet: true,
131
+ // shortName: "Mumbai",
132
+ // },
133
+ // [ChainId.OptimismMainnet]: {
134
+ // name: "Optimism Mainnet",
135
+ // id: ChainId.OptimismMainnet,
136
+ // baseCurrency: "ETH",
137
+ // defaultRpcUrl: "https://mainnet.optimism.io",
138
+ // explorerUrl: "https://optimistic.etherscan.io",
139
+ // isTestnet: false,
140
+ // },
141
+ // [ChainId.BscMainnet]: {
142
+ // name: "Binance Smart Chain Mainnet",
143
+ // id: ChainId.BscMainnet,
144
+ // baseCurrency: "BNB",
145
+ // defaultRpcUrl: "https://bsc-dataseed.binance.org",
146
+ // explorerUrl: "https://bscscan.com",
147
+ // isTestnet: false,
148
+ // },
149
+ // [ChainId.ArbitrumMainnet]: {
150
+ // name: "Arbitrum Mainnet",
151
+ // id: ChainId.ArbitrumMainnet,
152
+ // baseCurrency: "ETH",
153
+ // defaultRpcUrl: "https://arb1.arbitrum.io/rpc",
154
+ // explorerUrl: "https://arbiscan.io",
155
+ // isTestnet: false,
156
+ // },
157
+ // [ChainId.ArbitrumTestnet]: {
158
+ // name: "Arbitrum Testnet",
159
+ // id: ChainId.ArbitrumTestnet,
160
+ // baseCurrency: "ETH",
161
+ // defaultRpcUrl: "https://rinkeby.arbitrum.io/rpc",
162
+ // explorerUrl: "https://rinkeby-explorer.arbitrum.io",
163
+ // isTestnet: true,
164
+ // },
165
+ // [ChainId.GnosisChain]: {
166
+ // name: "Gnosis Chain",
167
+ // id: ChainId.GnosisChain,
168
+ // baseCurrency: "XDAI",
169
+ // defaultRpcUrl: "https://rpc.xdaichain.com",
170
+ // explorerUrl: "https://gnosis.blockscout.com",
171
+ // isTestnet: false,
172
+ // },
173
+ // [ChainId.FantomMainnet]: {
174
+ // name: "Fantom Mainnet",
175
+ // id: ChainId.FantomMainnet,
176
+ // baseCurrency: "FTM",
177
+ // defaultRpcUrl: "https://rpcapi.fantom.network",
178
+ // explorerUrl: "https://ftmscan.com",
179
+ // isTestnet: false,
180
+ // },
181
+ // [ChainId.FantomTestnet]: {
182
+ // name: "Fantom Testnet",
183
+ // id: ChainId.FantomTestnet,
184
+ // baseCurrency: "FTM",
185
+ // defaultRpcUrl: "https://rpc.testnet.fantom.network",
186
+ // explorerUrl: "https://explorer.testnet.fantom.network",
187
+ // isTestnet: true,
188
+ // },
189
+ // [ChainId.HarmonyMainnet]: {
190
+ // name: "Harmony Mainnet",
191
+ // id: ChainId.HarmonyMainnet,
192
+ // baseCurrency: "ONE",
193
+ // defaultRpcUrl: "https://api.harmony.one",
194
+ // explorerUrl: "https://explorer.harmony.one",
195
+ // isTestnet: false,
196
+ // },
197
+ // [ChainId.HarmonyTestnet]: {
198
+ // name: "Harmony Testnet",
199
+ // id: ChainId.HarmonyTestnet,
200
+ // baseCurrency: "ONE",
201
+ // defaultRpcUrl: "https://api.s0.b.hmny.io",
202
+ // explorerUrl: "https://explorer.testnet.harmony.one",
203
+ // isTestnet: true,
204
+ // },
205
+ // [ChainId.BscTestnet]: {
206
+ // name: "Binance Smart Chain Testnet",
207
+ // id: ChainId.BscTestnet,
208
+ // baseCurrency: "BNB",
209
+ // defaultRpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545",
210
+ // explorerUrl: "https://testnet.bscscan.com",
211
+ // isTestnet: true,
212
+ // },
213
+ // [ChainId.OptimismTestnet]: {
214
+ // name: "Optimism Testnet",
215
+ // id: ChainId.OptimismTestnet,
216
+ // baseCurrency: "ETH",
217
+ // defaultRpcUrl: "https://kovan.optimism.io",
218
+ // explorerUrl: "https://kovan-optimistic.etherscan.io",
219
+ // isTestnet: true,
220
+ // },
221
+ // [ChainId.EthRopstenTestnet]: {
222
+ // name: "Ethereum Ropsten Testnet",
223
+ // id: ChainId.EthRopstenTestnet,
224
+ // baseCurrency: "ETH",
225
+ // defaultRpcUrl:
226
+ // "https://ropsten.infura.io/V4/84842078b09946638c03157f83405213",
227
+ // explorerUrl: "https://ropsten.etherscan.io",
228
+ // isTestnet: true,
229
+ // },
230
+ // [ChainId.EthRinkebyTestnet]: {
231
+ // name: "Ethereum Rinkeby Testnet",
232
+ // id: ChainId.EthRinkebyTestnet,
233
+ // baseCurrency: "ETH",
234
+ // defaultRpcUrl:
235
+ // "https://rinkeby.infura.io/V4/84842078b09946638c03157f83405213",
236
+ // explorerUrl: "https://rinkeby.etherscan.io",
237
+ // isTestnet: true,
238
+ // },
239
+ // [ChainId.EthKovanTestnet]: {
240
+ // name: "Ethereum Kovan Testnet",
241
+ // id: ChainId.EthKovanTestnet,
242
+ // baseCurrency: "ETH",
243
+ // defaultRpcUrl:
244
+ // "https://kovan.infura.io/V4/84842078b09946638c03157f83405213",
245
+ // explorerUrl: "https://kovan.etherscan.io",
246
+ // isTestnet: true,
247
+ // },
248
+ // [ChainId.BaseGoerliTestnet]: {
249
+ // name: "Base Goerli Testnet",
250
+ // id: ChainId.BaseGoerliTestnet,
251
+ // baseCurrency: "ETH",
252
+ // defaultRpcUrl: "https://rpc-goerli.baseprotocol.org",
253
+ // explorerUrl: "https://goerli.basescan.org",
254
+ // isTestnet: true,
255
+ // },
256
+ // [ChainId.GnosisChainTestnet]: {
257
+ // name: "Gnosis Chain Testnet",
258
+ // id: ChainId.GnosisChainTestnet,
259
+ // baseCurrency: "XDAI",
260
+ // defaultRpcUrl: "https://rpc.chiado.gnosis.gateway.fm",
261
+ // explorerUrl: "https://gnosis-chiado.blockscout.com/",
262
+ // isTestnet: true,
263
+ // },
264
+ // [ChainId.AvalancheMainnet]: {
265
+ // name: "Avalanche Mainnet",
266
+ // id: ChainId.AvalancheMainnet,
267
+ // baseCurrency: "AVAX",
268
+ // defaultRpcUrl: "https://api.avax.network/ext/bc/C/rpc",
269
+ // explorerUrl: "https://cchain.explorer.avax.network",
270
+ // isTestnet: false,
271
+ // },
272
+ // [ChainId.AvalancheFujiTestnet]: {
273
+ // name: "Avalanche Fuji Testnet",
274
+ // id: ChainId.AvalancheFujiTestnet,
275
+ // baseCurrency: "AVAX",
276
+ // defaultRpcUrl: "https://api.avax-test.network/ext/bc/C/rpc",
277
+ // explorerUrl: "https://cchain.explorer.avax-test.network",
278
+ // isTestnet: true,
279
+ // },
280
+ // [ChainId.MoonbaseAlphaTestnet]: {
281
+ // name: "Moonbase Alpha Testnet",
282
+ // id: ChainId.MoonbaseAlphaTestnet,
283
+ // baseCurrency: "DEV",
284
+ // defaultRpcUrl: "https://rpc.testnet.moonbeam.network",
285
+ // explorerUrl: "https://moonbase-blockscout.testnet.moonbeam.network",
286
+ // isTestnet: true,
287
+ // },
288
+ };
289
+ })(ChainUtils || (exports.ChainUtils = ChainUtils = {}));
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
4
+ const chain_1 = require("./chain");
5
+ describe("Network", () => {
6
+ it("Should have consistent chainIds", () => {
7
+ (0, morpho_ts_1.entries)(chain_1.ChainUtils.CHAIN_METADATA).forEach(([chainId, { id }]) => {
8
+ expect(+chainId).toEqual(id);
9
+ });
10
+ });
11
+ it("Should have Testnet in the name for testnet chains", () => {
12
+ Object.values(chain_1.ChainUtils.CHAIN_METADATA)
13
+ .filter(({ isTestnet }) => isTestnet)
14
+ .forEach(({ name }) => {
15
+ expect(name).toMatch(/Testnet/);
16
+ });
17
+ });
18
+ it("Should convert correctly a chainId to hexChainId", () => {
19
+ expect(chain_1.ChainUtils.toHexChainId(chain_1.ChainId.BaseMainnet)).toEqual("0x2105");
20
+ });
21
+ });
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The liquidation cursor used to calculate the liquidation incentive. Hardcoded to 30%.
3
+ */
4
+ export declare const LIQUIDATION_CURSOR = 300000000000000000n;
5
+ /**
6
+ * The maximum liquidation incentive factor. Hardcoded to 115%.
7
+ */
8
+ export declare const MAX_LIQUIDATION_INCENTIVE_FACTOR = 1150000000000000000n;
9
+ export declare const ORACLE_PRICE_OFFSET = 36;
10
+ /**
11
+ * The scale of the oracle price. Hardcoded to 1e36.
12
+ */
13
+ export declare const ORACLE_PRICE_SCALE = 1000000000000000000000000000000000000n;
14
+ /**
15
+ * The default slippage tolerance used in the SDK. Hardcoded to 0.03%.
16
+ */
17
+ export declare const DEFAULT_SLIPPAGE_TOLERANCE = 300000000000000n;
18
+ /**
19
+ * The default withdrawal target utilization used by the shared liquidity algorithm. Hardcoded to 92%.
20
+ */
21
+ export declare const DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 920000000000000000n;
22
+ /**
23
+ * The default supply target utilization used by the shared liquidity algorithm. Hardcoded to 90.5%.
24
+ */
25
+ export declare const DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
26
+ /**
27
+ * The number of seconds in a year.
28
+ */
29
+ export declare const SECONDS_PER_YEAR: bigint;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SECONDS_PER_YEAR = exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = exports.DEFAULT_SLIPPAGE_TOLERANCE = exports.ORACLE_PRICE_SCALE = exports.ORACLE_PRICE_OFFSET = exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.LIQUIDATION_CURSOR = void 0;
4
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
+ /**
6
+ * The liquidation cursor used to calculate the liquidation incentive. Hardcoded to 30%.
7
+ */
8
+ exports.LIQUIDATION_CURSOR = 300000000000000000n;
9
+ /**
10
+ * The maximum liquidation incentive factor. Hardcoded to 115%.
11
+ */
12
+ exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = 1150000000000000000n;
13
+ exports.ORACLE_PRICE_OFFSET = 36;
14
+ /**
15
+ * The scale of the oracle price. Hardcoded to 1e36.
16
+ */
17
+ exports.ORACLE_PRICE_SCALE = 1000000000000000000000000000000000000n;
18
+ /**
19
+ * The default slippage tolerance used in the SDK. Hardcoded to 0.03%.
20
+ */
21
+ exports.DEFAULT_SLIPPAGE_TOLERANCE = 300000000000000n;
22
+ /**
23
+ * The default withdrawal target utilization used by the shared liquidity algorithm. Hardcoded to 92%.
24
+ */
25
+ exports.DEFAULT_WITHDRAWAL_TARGET_UTILIZATION = 920000000000000000n;
26
+ /**
27
+ * The default supply target utilization used by the shared liquidity algorithm. Hardcoded to 90.5%.
28
+ */
29
+ exports.DEFAULT_SUPPLY_TARGET_UTILIZATION = 905000000000000000n;
30
+ /**
31
+ * The number of seconds in a year.
32
+ */
33
+ exports.SECONDS_PER_YEAR = morpho_ts_1.Time.s.from.y(1n);
@@ -0,0 +1,58 @@
1
+ import { Address, MarketId } from "./types";
2
+ export declare class UnknownDataError extends Error {
3
+ }
4
+ export declare class UnknownTokenError extends UnknownDataError {
5
+ readonly address: Address;
6
+ constructor(address: Address);
7
+ }
8
+ export declare class UnknownTokenPriceError extends UnknownDataError {
9
+ readonly address: Address;
10
+ constructor(address: Address);
11
+ }
12
+ export declare class UnknownMarketConfigError extends UnknownDataError {
13
+ readonly marketId: MarketId;
14
+ constructor(marketId: MarketId);
15
+ }
16
+ export declare class UnknownVaultConfigError extends UnknownDataError {
17
+ readonly vault: Address;
18
+ constructor(vault: Address);
19
+ }
20
+ export declare class UnsupportedChainIdError extends Error {
21
+ readonly chainId: number;
22
+ constructor(chainId: number);
23
+ }
24
+ export declare namespace BlueErrors {
25
+ class InvalidInterestAccrual extends Error {
26
+ readonly marketId: MarketId;
27
+ readonly timestamp: bigint;
28
+ readonly lastUpdate: bigint;
29
+ constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
30
+ }
31
+ class InconsistentInput extends Error {
32
+ constructor();
33
+ }
34
+ class InsufficientLiquidity extends Error {
35
+ readonly marketId: MarketId;
36
+ constructor(marketId: MarketId);
37
+ }
38
+ class InsufficientPosition extends Error {
39
+ readonly user: Address;
40
+ readonly marketId: MarketId;
41
+ constructor(user: Address, marketId: MarketId);
42
+ }
43
+ class InsufficientCollateral extends Error {
44
+ readonly user: Address;
45
+ readonly marketId: MarketId;
46
+ constructor(user: Address, marketId: MarketId);
47
+ }
48
+ }
49
+ export declare class InvalidSignatureError extends Error {
50
+ readonly hash: string;
51
+ readonly signer: Address;
52
+ readonly recovered: Address;
53
+ constructor(hash: string, signer: Address, recovered: Address);
54
+ }
55
+ export interface ErrorClass<E extends Error> {
56
+ new (...args: any[]): E;
57
+ }
58
+ export declare function _try<T, E extends Error>(accessor: () => T, ...errorClasses: ErrorClass<E>[]): T | undefined;
package/lib/errors.js ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidSignatureError = exports.BlueErrors = exports.UnsupportedChainIdError = exports.UnknownVaultConfigError = exports.UnknownMarketConfigError = exports.UnknownTokenPriceError = exports.UnknownTokenError = exports.UnknownDataError = void 0;
4
+ exports._try = _try;
5
+ class UnknownDataError extends Error {
6
+ }
7
+ exports.UnknownDataError = UnknownDataError;
8
+ class UnknownTokenError extends UnknownDataError {
9
+ address;
10
+ constructor(address) {
11
+ super(`unknown token ${address}`);
12
+ this.address = address;
13
+ }
14
+ }
15
+ exports.UnknownTokenError = UnknownTokenError;
16
+ class UnknownTokenPriceError extends UnknownDataError {
17
+ address;
18
+ constructor(address) {
19
+ super(`unknown price of token ${address}`);
20
+ this.address = address;
21
+ }
22
+ }
23
+ exports.UnknownTokenPriceError = UnknownTokenPriceError;
24
+ class UnknownMarketConfigError extends UnknownDataError {
25
+ marketId;
26
+ constructor(marketId) {
27
+ super(`unknown config for market ${marketId}`);
28
+ this.marketId = marketId;
29
+ }
30
+ }
31
+ exports.UnknownMarketConfigError = UnknownMarketConfigError;
32
+ class UnknownVaultConfigError extends UnknownDataError {
33
+ vault;
34
+ constructor(vault) {
35
+ super(`unknown config for vault ${vault}`);
36
+ this.vault = vault;
37
+ }
38
+ }
39
+ exports.UnknownVaultConfigError = UnknownVaultConfigError;
40
+ class UnsupportedChainIdError extends Error {
41
+ chainId;
42
+ constructor(chainId) {
43
+ super(`unsupported chain ${chainId}`);
44
+ this.chainId = chainId;
45
+ }
46
+ }
47
+ exports.UnsupportedChainIdError = UnsupportedChainIdError;
48
+ var BlueErrors;
49
+ (function (BlueErrors) {
50
+ class InvalidInterestAccrual extends Error {
51
+ marketId;
52
+ timestamp;
53
+ lastUpdate;
54
+ constructor(marketId, timestamp, lastUpdate) {
55
+ super(`invalid interest accrual on market ${marketId}: accrual timestamp ${timestamp} can't be prior to last update ${lastUpdate}`);
56
+ this.marketId = marketId;
57
+ this.timestamp = timestamp;
58
+ this.lastUpdate = lastUpdate;
59
+ }
60
+ }
61
+ BlueErrors.InvalidInterestAccrual = InvalidInterestAccrual;
62
+ class InconsistentInput extends Error {
63
+ constructor() {
64
+ super(`inconsistent input: assets & shares cannot both be zero`);
65
+ }
66
+ }
67
+ BlueErrors.InconsistentInput = InconsistentInput;
68
+ class InsufficientLiquidity extends Error {
69
+ marketId;
70
+ constructor(marketId) {
71
+ super(`insufficient liquidity on market ${marketId}`);
72
+ this.marketId = marketId;
73
+ }
74
+ }
75
+ BlueErrors.InsufficientLiquidity = InsufficientLiquidity;
76
+ class InsufficientPosition extends Error {
77
+ user;
78
+ marketId;
79
+ constructor(user, marketId) {
80
+ super(`insufficient position for user ${user} on market ${marketId}`);
81
+ this.user = user;
82
+ this.marketId = marketId;
83
+ }
84
+ }
85
+ BlueErrors.InsufficientPosition = InsufficientPosition;
86
+ class InsufficientCollateral extends Error {
87
+ user;
88
+ marketId;
89
+ constructor(user, marketId) {
90
+ super(`insufficient collateral for user ${user} on market ${marketId}`);
91
+ this.user = user;
92
+ this.marketId = marketId;
93
+ }
94
+ }
95
+ BlueErrors.InsufficientCollateral = InsufficientCollateral;
96
+ })(BlueErrors || (exports.BlueErrors = BlueErrors = {}));
97
+ class InvalidSignatureError extends Error {
98
+ hash;
99
+ signer;
100
+ recovered;
101
+ constructor(hash, signer, recovered) {
102
+ super(`invalid signature for hash ${hash}: expected ${signer}, recovered ${recovered}`);
103
+ this.hash = hash;
104
+ this.signer = signer;
105
+ this.recovered = recovered;
106
+ }
107
+ }
108
+ exports.InvalidSignatureError = InvalidSignatureError;
109
+ function _try(accessor, ...errorClasses) {
110
+ try {
111
+ return accessor();
112
+ }
113
+ catch (error) {
114
+ if (errorClasses.length === 0 ||
115
+ errorClasses.some((errorClass) => error instanceof errorClass))
116
+ return;
117
+ throw error;
118
+ }
119
+ }
@@ -0,0 +1,122 @@
1
+ declare enum Format {
2
+ number = "number",
3
+ commas = "commas",
4
+ short = "short",
5
+ hex = "hex",
6
+ percent = "percent"
7
+ }
8
+ interface BaseFormatOptions {
9
+ format: Format;
10
+ digits?: number;
11
+ removeTrailingZero?: boolean;
12
+ min?: number;
13
+ max?: number;
14
+ sign?: boolean;
15
+ unit?: string;
16
+ readable?: boolean;
17
+ locale?: string;
18
+ }
19
+ interface FormatShortOptions extends BaseFormatOptions {
20
+ format: Format.short;
21
+ smallValuesWithCommas?: boolean;
22
+ }
23
+ interface FormatHexOptions {
24
+ format: Format.hex;
25
+ }
26
+ interface FormatCommasOptions extends BaseFormatOptions {
27
+ format: Format.commas;
28
+ }
29
+ interface FormatNumberOptions extends BaseFormatOptions {
30
+ format: Format.number;
31
+ }
32
+ interface FormatPercentOptions extends BaseFormatOptions {
33
+ format: Format.percent;
34
+ }
35
+ type FormatOptions = FormatHexOptions | FormatShortOptions | FormatNumberOptions | FormatCommasOptions | FormatPercentOptions;
36
+ declare global {
37
+ interface String {
38
+ insert(index: number, substr: string, fillWith?: string): string;
39
+ }
40
+ }
41
+ /**
42
+ * @deprecated Import from `@morpho-org/morpho-ts`
43
+ */
44
+ export declare abstract class BaseFormatter {
45
+ protected abstract _options: FormatOptions;
46
+ constructor();
47
+ of(value: bigint, decimals: number): string;
48
+ of(value: number): string;
49
+ }
50
+ /**
51
+ * @deprecated Import from `@morpho-org/morpho-ts`
52
+ */
53
+ export declare class HexFormatter extends BaseFormatter {
54
+ protected _options: {
55
+ format: Format;
56
+ };
57
+ }
58
+ /**
59
+ * @deprecated Import from `@morpho-org/morpho-ts`
60
+ */
61
+ export declare abstract class CommonFormatter extends BaseFormatter {
62
+ protected abstract _options: BaseFormatOptions;
63
+ digits(_d: number): this;
64
+ removeTrailingZero(): this;
65
+ readable(): this;
66
+ min(_m: number): this;
67
+ max(_m: number): this;
68
+ sign(): this;
69
+ unit(_u: string): this;
70
+ locale(_l: string): this;
71
+ }
72
+ /**
73
+ * @deprecated Import from `@morpho-org/morpho-ts`
74
+ */
75
+ export declare class NumberFormatter extends CommonFormatter {
76
+ protected _options: FormatNumberOptions;
77
+ }
78
+ /**
79
+ * @deprecated Import from `@morpho-org/morpho-ts`
80
+ */
81
+ export declare class CommasFormatter extends CommonFormatter {
82
+ protected _options: FormatCommasOptions;
83
+ }
84
+ /**
85
+ * @deprecated Import from `@morpho-org/morpho-ts`
86
+ */
87
+ export declare class ShortFormatter extends CommonFormatter {
88
+ protected _options: FormatShortOptions;
89
+ smallValuesWithCommas(): this;
90
+ }
91
+ /**
92
+ * @deprecated Import from `@morpho-org/morpho-ts`
93
+ */
94
+ export declare class PercentFormatter extends CommonFormatter {
95
+ protected _options: FormatPercentOptions;
96
+ }
97
+ /**
98
+ * @deprecated Import from `@morpho-org/morpho-ts`
99
+ */
100
+ export declare const format: {
101
+ /**
102
+ * Return the value as an integer in hex format
103
+ */
104
+ readonly hex: HexFormatter;
105
+ /**
106
+ * Return the value as a stringified number (12345.6789)
107
+ */
108
+ readonly number: NumberFormatter;
109
+ /**
110
+ * Return the value as a commas-separated stringified number (12,345.6789)
111
+ */
112
+ readonly commas: CommasFormatter;
113
+ /**
114
+ * Return the value as a shorted stringified number (12.3456789k)
115
+ */
116
+ readonly short: ShortFormatter;
117
+ /**
118
+ * Return the value as a percent based stringified number (10.00 instead of 0.1)
119
+ */
120
+ readonly percent: PercentFormatter;
121
+ };
122
+ export {};