@morpho-org/blue-sdk 6.0.1 → 6.2.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 (139) hide show
  1. package/lib/cjs/addresses.d.ts +225 -0
  2. package/lib/cjs/addresses.js +140 -0
  3. package/lib/cjs/chain.d.ts +108 -1
  4. package/lib/cjs/chain.js +94 -0
  5. package/lib/cjs/errors.d.ts +39 -0
  6. package/lib/cjs/errors.js +38 -1
  7. package/lib/cjs/holding/AssetBalances.d.ts +3 -0
  8. package/lib/cjs/holding/AssetBalances.js +1 -0
  9. package/lib/cjs/holding/Holding.d.ts +6 -0
  10. package/lib/cjs/holding/Holding.js +2 -0
  11. package/lib/cjs/market/Market.d.ts +4 -0
  12. package/lib/cjs/market/MarketParams.d.ts +3 -0
  13. package/lib/cjs/market/MarketParams.js +1 -0
  14. package/lib/cjs/market/MarketUtils.d.ts +397 -0
  15. package/lib/cjs/market/MarketUtils.js +397 -2
  16. package/lib/cjs/math/AdaptiveCurveIrmLib.d.ts +51 -1
  17. package/lib/cjs/math/AdaptiveCurveIrmLib.js +52 -2
  18. package/lib/cjs/math/MathLib.d.ts +152 -4
  19. package/lib/cjs/math/MathLib.js +151 -4
  20. package/lib/cjs/math/SharesMath.d.ts +34 -0
  21. package/lib/cjs/math/SharesMath.js +34 -0
  22. package/lib/cjs/position/Position.d.ts +4 -0
  23. package/lib/cjs/position/Position.js +2 -0
  24. package/lib/cjs/position/PreLiquidationPosition.d.ts +4 -0
  25. package/lib/cjs/position/PreLiquidationPosition.js +2 -0
  26. package/lib/cjs/preLiquidation.d.ts +16 -0
  27. package/lib/cjs/preLiquidation.js +16 -0
  28. package/lib/cjs/token/ConstantWrappedToken.d.ts +1 -0
  29. package/lib/cjs/token/ConstantWrappedToken.js +1 -0
  30. package/lib/cjs/token/Eip5267Domain.d.ts +4 -0
  31. package/lib/cjs/token/Eip5267Domain.js +2 -0
  32. package/lib/cjs/token/ExchangeRateWrappedToken.d.ts +1 -0
  33. package/lib/cjs/token/ExchangeRateWrappedToken.js +1 -0
  34. package/lib/cjs/token/Token.d.ts +2 -0
  35. package/lib/cjs/token/Token.js +1 -0
  36. package/lib/cjs/token/VaultToken.d.ts +2 -0
  37. package/lib/cjs/token/VaultToken.js +1 -0
  38. package/lib/cjs/token/WrappedToken.d.ts +1 -0
  39. package/lib/cjs/token/WrappedToken.js +1 -0
  40. package/lib/cjs/types.d.ts +17 -0
  41. package/lib/cjs/types.js +13 -0
  42. package/lib/cjs/user/User.d.ts +1 -0
  43. package/lib/cjs/user/User.js +1 -0
  44. package/lib/cjs/utils.d.ts +2 -0
  45. package/lib/cjs/utils.js +1 -0
  46. package/lib/cjs/vault/Vault.d.ts +9 -0
  47. package/lib/cjs/vault/Vault.js +14 -1
  48. package/lib/cjs/vault/VaultConfig.d.ts +2 -0
  49. package/lib/cjs/vault/VaultConfig.js +1 -0
  50. package/lib/cjs/vault/VaultMarketAllocation.d.ts +2 -0
  51. package/lib/cjs/vault/VaultMarketAllocation.js +1 -0
  52. package/lib/cjs/vault/VaultMarketConfig.d.ts +2 -0
  53. package/lib/cjs/vault/VaultMarketConfig.js +1 -0
  54. package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
  55. package/lib/cjs/vault/VaultMarketPublicAllocatorConfig.js +1 -0
  56. package/lib/cjs/vault/VaultUser.d.ts +2 -0
  57. package/lib/cjs/vault/VaultUser.js +1 -0
  58. package/lib/cjs/vault/VaultUtils.d.ts +49 -0
  59. package/lib/cjs/vault/VaultUtils.js +51 -2
  60. package/lib/cjs/vault/v2/VaultV2.d.ts +5 -0
  61. package/lib/cjs/vault/v2/VaultV2.js +2 -0
  62. package/lib/cjs/vault/v2/VaultV2Adapter.d.ts +3 -0
  63. package/lib/cjs/vault/v2/VaultV2Adapter.js +1 -0
  64. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
  65. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
  66. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  67. package/lib/cjs/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
  68. package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
  69. package/lib/cjs/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
  70. package/lib/esm/addresses.d.ts +225 -0
  71. package/lib/esm/addresses.js +140 -0
  72. package/lib/esm/chain.d.ts +108 -1
  73. package/lib/esm/chain.js +94 -0
  74. package/lib/esm/errors.d.ts +39 -0
  75. package/lib/esm/errors.js +36 -0
  76. package/lib/esm/holding/AssetBalances.d.ts +3 -0
  77. package/lib/esm/holding/AssetBalances.js +1 -0
  78. package/lib/esm/holding/Holding.d.ts +6 -0
  79. package/lib/esm/holding/Holding.js +2 -0
  80. package/lib/esm/market/Market.d.ts +4 -0
  81. package/lib/esm/market/MarketParams.d.ts +3 -0
  82. package/lib/esm/market/MarketParams.js +1 -0
  83. package/lib/esm/market/MarketUtils.d.ts +397 -0
  84. package/lib/esm/market/MarketUtils.js +397 -2
  85. package/lib/esm/math/AdaptiveCurveIrmLib.d.ts +51 -1
  86. package/lib/esm/math/AdaptiveCurveIrmLib.js +52 -2
  87. package/lib/esm/math/MathLib.d.ts +152 -4
  88. package/lib/esm/math/MathLib.js +151 -4
  89. package/lib/esm/math/SharesMath.d.ts +34 -0
  90. package/lib/esm/math/SharesMath.js +34 -0
  91. package/lib/esm/position/Position.d.ts +4 -0
  92. package/lib/esm/position/Position.js +2 -0
  93. package/lib/esm/position/PreLiquidationPosition.d.ts +4 -0
  94. package/lib/esm/position/PreLiquidationPosition.js +2 -0
  95. package/lib/esm/preLiquidation.d.ts +16 -0
  96. package/lib/esm/preLiquidation.js +16 -0
  97. package/lib/esm/token/ConstantWrappedToken.d.ts +1 -0
  98. package/lib/esm/token/ConstantWrappedToken.js +1 -0
  99. package/lib/esm/token/Eip5267Domain.d.ts +4 -0
  100. package/lib/esm/token/Eip5267Domain.js +2 -0
  101. package/lib/esm/token/ExchangeRateWrappedToken.d.ts +1 -0
  102. package/lib/esm/token/ExchangeRateWrappedToken.js +1 -0
  103. package/lib/esm/token/Token.d.ts +2 -0
  104. package/lib/esm/token/Token.js +1 -0
  105. package/lib/esm/token/VaultToken.d.ts +2 -0
  106. package/lib/esm/token/VaultToken.js +1 -0
  107. package/lib/esm/token/WrappedToken.d.ts +1 -0
  108. package/lib/esm/token/WrappedToken.js +1 -0
  109. package/lib/esm/types.d.ts +17 -0
  110. package/lib/esm/types.js +13 -0
  111. package/lib/esm/user/User.d.ts +1 -0
  112. package/lib/esm/user/User.js +1 -0
  113. package/lib/esm/utils.d.ts +2 -0
  114. package/lib/esm/utils.js +1 -0
  115. package/lib/esm/vault/Vault.d.ts +9 -0
  116. package/lib/esm/vault/Vault.js +14 -1
  117. package/lib/esm/vault/VaultConfig.d.ts +2 -0
  118. package/lib/esm/vault/VaultConfig.js +1 -0
  119. package/lib/esm/vault/VaultMarketAllocation.d.ts +2 -0
  120. package/lib/esm/vault/VaultMarketAllocation.js +1 -0
  121. package/lib/esm/vault/VaultMarketConfig.d.ts +2 -0
  122. package/lib/esm/vault/VaultMarketConfig.js +1 -0
  123. package/lib/esm/vault/VaultMarketPublicAllocatorConfig.d.ts +1 -0
  124. package/lib/esm/vault/VaultMarketPublicAllocatorConfig.js +1 -0
  125. package/lib/esm/vault/VaultUser.d.ts +2 -0
  126. package/lib/esm/vault/VaultUser.js +1 -0
  127. package/lib/esm/vault/VaultUtils.d.ts +49 -0
  128. package/lib/esm/vault/VaultUtils.js +51 -2
  129. package/lib/esm/vault/v2/VaultV2.d.ts +5 -0
  130. package/lib/esm/vault/v2/VaultV2.js +2 -0
  131. package/lib/esm/vault/v2/VaultV2Adapter.d.ts +3 -0
  132. package/lib/esm/vault/v2/VaultV2Adapter.js +1 -0
  133. package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.d.ts +4 -0
  134. package/lib/esm/vault/v2/VaultV2MorphoMarketV1Adapter.js +3 -1
  135. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.d.ts +4 -0
  136. package/lib/esm/vault/v2/VaultV2MorphoMarketV1AdapterV2.js +3 -1
  137. package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.d.ts +4 -0
  138. package/lib/esm/vault/v2/VaultV2MorphoVaultV1Adapter.js +2 -0
  139. package/package.json +4 -4
@@ -710,6 +710,50 @@ const _addressesRegistry = {
710
710
  preLiquidationFactory: "0xe8eCe452F04117e5Fe1Ea4403097215443225440",
711
711
  wNative: "0x19Aac5f612f524B754CA7e7c41cbFa2E981A4432",
712
712
  },
713
+ [ChainId.ArcMainnet]: {
714
+ morpho: "0x34CD04070dD72b14E241112F6d83812Df5Af7fCD",
715
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
716
+ bundler3: {
717
+ bundler3: "0x855dbe13C409Df75CAF6a985Cf6993a4D0319Feb",
718
+ generalAdapter1: "0x0AF5BE7BD7B615e94e1d9275414482D028952466",
719
+ },
720
+ adaptiveCurveIrm: "0xF02615d094Fc02fC031C35fe705e175aA4653f20",
721
+ vaultV2Factory: "0x3b0eefaBfa22ec7CF2c73877ac16e78D76749f12",
722
+ morphoMarketV1AdapterV2Factory: "0x6C2FF5114E45b50bc7195c2F1f87C98cbdad62Cc",
723
+ registryList: "0xdEBC92370Cd74d55DA144116138681dbbb528765",
724
+ chainlinkOracleFactory: "0xbFc8D6167a02889D5EB08a023d9aB712B44f7dE8",
725
+ preLiquidationFactory: "0x8edf6Ac769a7E7D81d571aC0FB8733aD724f6922",
726
+ },
727
+ [ChainId.MorphMainnet]: {
728
+ morpho: "0xAd10d07901Dc3195c3cb5e78E061F4EA8D9B4905",
729
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
730
+ bundler3: {
731
+ bundler3: "0xDB83A44Bf8f53966f7A4F7dCE7F8CdAaBCf83628",
732
+ generalAdapter1: "0xcaeec65c85Fe964c8Bd814cb8E4CaF8B06bde776",
733
+ },
734
+ adaptiveCurveIrm: "0xfB69467De332E03FF502B85bB2249d2f721F3319",
735
+ vaultV2Factory: "0x7D8BF8B276f967F7539c9e91E1a85a33fefE612B",
736
+ morphoMarketV1AdapterV2Factory: "0xa01D7c41cf419405d4DF2e5750d26438DCAC28a6",
737
+ registryList: "0x553c013d1978CF82EF6b316f5c247B73718ba481",
738
+ chainlinkOracleFactory: "0xE91032cE5B8D86bA4Be146c186984F49Af37fbf1",
739
+ preLiquidationFactory: "0x41581344ba49B07EFA758a0F2a199b90f05Cc866",
740
+ wNative: "0x5300000000000000000000000000000000000011",
741
+ },
742
+ [ChainId.MegaEthMainnet]: {
743
+ morpho: "0x18120312A7cf44DcfEc6dCe5632a431579ED9100",
744
+ permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3",
745
+ bundler3: {
746
+ bundler3: "0xf53D4c8f0f83F697CD6bB303567400cCf411aA63",
747
+ generalAdapter1: "0x74d3cbc721613C8461df92658d0a20dF275Ca31b",
748
+ },
749
+ adaptiveCurveIrm: "0x56875764185548B0ca72A1877b3aE15E44e8A323",
750
+ vaultV2Factory: "0xf133FA5A78C398B31Cc4a180E6Ae84111D6DCF5B",
751
+ morphoMarketV1AdapterV2Factory: "0x00a58b7a9B3E86CB21f5F11f29F4A12346457012",
752
+ registryList: "0x3aE18af9717C734820137726967bef4fBc5Ec95c",
753
+ chainlinkOracleFactory: "0x02522D475E7064E1d1E966e3197db050b19b2FC2",
754
+ preLiquidationFactory: "0xF6035B231028E61cd2283651f22ecA45f8e3ADc8",
755
+ wNative: "0x4200000000000000000000000000000000000006",
756
+ },
713
757
  };
714
758
  const _deployments = {
715
759
  [ChainId.EthMainnet]: {
@@ -1306,7 +1350,65 @@ const _deployments = {
1306
1350
  preLiquidationFactory: 213462907n,
1307
1351
  wNative: 104802159n,
1308
1352
  },
1353
+ [ChainId.ArcMainnet]: {
1354
+ morpho: 1208685n,
1355
+ permit2: 0n,
1356
+ bundler3: {
1357
+ bundler3: 1208685n,
1358
+ generalAdapter1: 1208685n,
1359
+ },
1360
+ adaptiveCurveIrm: 1208685n,
1361
+ vaultV2Factory: 1208931n,
1362
+ morphoMarketV1AdapterV2Factory: 1208978n,
1363
+ registryList: 1208978n,
1364
+ chainlinkOracleFactory: 1208882n,
1365
+ preLiquidationFactory: 1208882n,
1366
+ },
1367
+ [ChainId.MorphMainnet]: {
1368
+ morpho: 23180020n,
1369
+ permit2: 5081244n,
1370
+ bundler3: {
1371
+ bundler3: 23180020n,
1372
+ generalAdapter1: 23180020n,
1373
+ },
1374
+ adaptiveCurveIrm: 23180020n,
1375
+ vaultV2Factory: 23180183n,
1376
+ morphoMarketV1AdapterV2Factory: 23180228n,
1377
+ registryList: 23180228n,
1378
+ chainlinkOracleFactory: 23180111n,
1379
+ preLiquidationFactory: 23180111n,
1380
+ wNative: 0n,
1381
+ },
1382
+ [ChainId.MegaEthMainnet]: {
1383
+ morpho: 16408957n,
1384
+ permit2: 0n,
1385
+ bundler3: {
1386
+ bundler3: 16408957n,
1387
+ generalAdapter1: 16408957n,
1388
+ },
1389
+ adaptiveCurveIrm: 16408957n,
1390
+ vaultV2Factory: 16409067n,
1391
+ morphoMarketV1AdapterV2Factory: 16409115n,
1392
+ registryList: 16409115n,
1393
+ chainlinkOracleFactory: 16409024n,
1394
+ preLiquidationFactory: 16409024n,
1395
+ wNative: 0n,
1396
+ },
1309
1397
  };
1398
+ /**
1399
+ * Returns the protocol address registry for a chain.
1400
+ *
1401
+ * @param chainId - The EIP-155 chain id.
1402
+ * @returns The configured protocol, adapter, factory, and token addresses for `chainId`.
1403
+ * @throws {UnsupportedChainIdError} when no address registry exists for `chainId`.
1404
+ * @example
1405
+ * ```ts
1406
+ * import { ChainId, getChainAddresses } from "@morpho-org/blue-sdk";
1407
+ *
1408
+ * const chainAddresses = getChainAddresses(ChainId.EthMainnet);
1409
+ * // chainAddresses satisfies ChainAddresses
1410
+ * ```
1411
+ */
1310
1412
  export const getChainAddresses = (chainId) => {
1311
1413
  const chainAddresses = addresses[chainId];
1312
1414
  if (chainAddresses == null)
@@ -1435,7 +1537,27 @@ const _unwrappedTokensMapping = {
1435
1537
  [ChainId.KaiaMainnet]: {
1436
1538
  [_addressesRegistry[ChainId.KaiaMainnet].wNative]: NATIVE_ADDRESS,
1437
1539
  },
1540
+ [ChainId.MorphMainnet]: {
1541
+ [_addressesRegistry[ChainId.MorphMainnet].wNative]: NATIVE_ADDRESS,
1542
+ },
1543
+ [ChainId.MegaEthMainnet]: {
1544
+ [_addressesRegistry[ChainId.MegaEthMainnet].wNative]: NATIVE_ADDRESS,
1545
+ },
1438
1546
  };
1547
+ /**
1548
+ * Returns the unwrapped token mapped to a wrapped token on a chain.
1549
+ *
1550
+ * @param wrappedToken - The wrapped token address to resolve.
1551
+ * @param chainId - The EIP-155 chain id.
1552
+ * @returns The unwrapped token address, or `undefined` when no mapping is registered.
1553
+ * @example
1554
+ * ```ts
1555
+ * import { ChainId, getUnwrappedToken, NATIVE_ADDRESS, addresses } from "@morpho-org/blue-sdk";
1556
+ *
1557
+ * const unwrapped = getUnwrappedToken(addresses[ChainId.EthMainnet].wNative!, ChainId.EthMainnet);
1558
+ * // unwrapped === NATIVE_ADDRESS
1559
+ * ```
1560
+ */
1439
1561
  export function getUnwrappedToken(wrappedToken, chainId) {
1440
1562
  return unwrappedTokensMapping[chainId]?.[wrappedToken];
1441
1563
  }
@@ -1471,6 +1593,19 @@ export const permissionedCoinbaseTokens = {
1471
1593
  _addressesRegistry[ChainId.BaseMainnet].verUsdc,
1472
1594
  ]),
1473
1595
  };
1596
+ /**
1597
+ * Returns the known Coinbase-attested wrapped tokens for a chain.
1598
+ *
1599
+ * @param chainId - The EIP-155 chain id.
1600
+ * @returns A set of permissioned wrapped token addresses, or an empty set when none are registered.
1601
+ * @example
1602
+ * ```ts
1603
+ * import { ChainId, getPermissionedCoinbaseTokens } from "@morpho-org/blue-sdk";
1604
+ *
1605
+ * const tokens = getPermissionedCoinbaseTokens(ChainId.BaseMainnet);
1606
+ * // tokens satisfies Set<Address>
1607
+ * ```
1608
+ */
1474
1609
  export const getPermissionedCoinbaseTokens = (chainId) => permissionedCoinbaseTokens[chainId] ?? new Set();
1475
1610
  entries(permissionedBackedTokens).forEach(([chainId, tokens]) => {
1476
1611
  tokens.forEach((token) => (erc20WrapperTokens[chainId] ??= new Set()).add(token));
@@ -1494,9 +1629,13 @@ export const convexWrapperTokens = {
1494
1629
  _addressesRegistry[ChainId.EthMainnet]["stkcvx2BTC-f-morpho"],
1495
1630
  ]),
1496
1631
  };
1632
+ /** Deep-frozen registry of known chain addresses, keyed by chain id. */
1497
1633
  export let addressesRegistry = deepFreeze(_addressesRegistry);
1634
+ /** Address registry keyed by numeric chain id. */
1498
1635
  export let addresses = addressesRegistry;
1636
+ /** Deep-frozen registry of deployment blocks, keyed by chain id. */
1499
1637
  export let deployments = deepFreeze(_deployments);
1638
+ /** Deep-frozen registry of wrapped token to unwrapped token mappings. */
1500
1639
  export let unwrappedTokensMapping = deepFreeze(_unwrappedTokensMapping);
1501
1640
  /**
1502
1641
  * Registers custom addresses and unwrapped token mappings to extend
@@ -1513,6 +1652,7 @@ export let unwrappedTokensMapping = deepFreeze(_unwrappedTokensMapping);
1513
1652
  * Must provide all required deployments if chain is unknown.
1514
1653
  *
1515
1654
  * @throws {Error} If attempting to override an existing address.
1655
+ * @returns Nothing.
1516
1656
  *
1517
1657
  * @example
1518
1658
  * ```ts
@@ -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,12 @@ 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,
43
+ MorphMainnet = 2818,
44
+ MegaEthMainnet = 4326
41
45
  }
46
+ /** Explorer, native currency, and identifier metadata for a supported chain. */
42
47
  export interface ChainMetadata {
43
48
  readonly name: string;
44
49
  readonly id: ChainId;
@@ -52,12 +57,81 @@ export interface ChainMetadata {
52
57
  /** Whether eth_getBalance returns a reliable value. Defaults to true. */
53
58
  readonly hasReliableNativeBalance?: boolean;
54
59
  }
60
+ /** Chain metadata helpers and registries. */
55
61
  export declare namespace ChainUtils {
62
+ /**
63
+ * Returns whether native token balances are reliable on a chain.
64
+ *
65
+ * @param chainId - The EIP-155 chain id to inspect.
66
+ * @returns `false` only for chains whose metadata marks native balances as unreliable.
67
+ * @example
68
+ * ```ts
69
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
70
+ *
71
+ * const reliable = ChainUtils.hasReliableNativeBalance(ChainId.EthMainnet);
72
+ * // reliable === true
73
+ * ```
74
+ */
56
75
  const hasReliableNativeBalance: (chainId: number) => boolean;
76
+ /**
77
+ * Converts a supported chain id to its hexadecimal JSON-RPC form.
78
+ *
79
+ * @param chainId - The supported chain id.
80
+ * @returns The chain id as a `0x`-prefixed hexadecimal string.
81
+ * @example
82
+ * ```ts
83
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
84
+ *
85
+ * const hexChainId = ChainUtils.toHexChainId(ChainId.EthMainnet);
86
+ * // hexChainId === "0x1"
87
+ * ```
88
+ */
57
89
  const toHexChainId: (chainId: ChainId) => string;
90
+ /**
91
+ * Returns the block explorer base URL for a supported chain.
92
+ *
93
+ * @param chainId - The supported chain id.
94
+ * @returns The chain's configured block explorer base URL.
95
+ * @example
96
+ * ```ts
97
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
98
+ *
99
+ * const explorerUrl = ChainUtils.getExplorerUrl(ChainId.EthMainnet);
100
+ * // explorerUrl === "https://etherscan.io"
101
+ * ```
102
+ */
58
103
  const getExplorerUrl: (chainId: ChainId) => string;
104
+ /**
105
+ * Returns a block explorer address URL for a supported chain.
106
+ *
107
+ * @param chainId - The supported chain id.
108
+ * @param address - The address to link to.
109
+ * @returns The block explorer URL for `address`.
110
+ * @example
111
+ * ```ts
112
+ * import { ChainId, ChainUtils, NATIVE_ADDRESS } from "@morpho-org/blue-sdk";
113
+ *
114
+ * const url = ChainUtils.getExplorerAddressUrl(ChainId.EthMainnet, NATIVE_ADDRESS);
115
+ * // url satisfies string
116
+ * ```
117
+ */
59
118
  const getExplorerAddressUrl: (chainId: ChainId, address: string) => string;
119
+ /**
120
+ * Returns a block explorer transaction URL for a supported chain.
121
+ *
122
+ * @param chainId - The supported chain id.
123
+ * @param tx - The transaction hash to link to.
124
+ * @returns The block explorer URL for `tx`.
125
+ * @example
126
+ * ```ts
127
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
128
+ *
129
+ * const url = ChainUtils.getExplorerTransactionUrl(ChainId.EthMainnet, "0xabc");
130
+ * // url satisfies string
131
+ * ```
132
+ */
60
133
  const getExplorerTransactionUrl: (chainId: ChainId, tx: string) => string;
134
+ /** Metadata for each supported chain, keyed by `ChainId`. */
61
135
  const CHAIN_METADATA: {
62
136
  1: {
63
137
  name: string;
@@ -489,5 +563,38 @@ export declare namespace ChainUtils {
489
563
  explorerUrl: string;
490
564
  identifier: string;
491
565
  };
566
+ 5042: {
567
+ name: string;
568
+ id: ChainId.ArcMainnet;
569
+ nativeCurrency: {
570
+ name: string;
571
+ symbol: string;
572
+ decimals: number;
573
+ };
574
+ explorerUrl: string;
575
+ identifier: string;
576
+ };
577
+ 2818: {
578
+ name: string;
579
+ id: ChainId.MorphMainnet;
580
+ nativeCurrency: {
581
+ name: string;
582
+ symbol: string;
583
+ decimals: number;
584
+ };
585
+ explorerUrl: string;
586
+ identifier: string;
587
+ };
588
+ 4326: {
589
+ name: string;
590
+ id: ChainId.MegaEthMainnet;
591
+ nativeCurrency: {
592
+ name: string;
593
+ symbol: string;
594
+ decimals: number;
595
+ };
596
+ explorerUrl: string;
597
+ identifier: string;
598
+ };
492
599
  };
493
600
  }
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,97 @@ 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";
44
+ ChainId[ChainId["MorphMainnet"] = 2818] = "MorphMainnet";
45
+ ChainId[ChainId["MegaEthMainnet"] = 4326] = "MegaEthMainnet";
42
46
  })(ChainId || (ChainId = {}));
47
+ /** Chain metadata helpers and registries. */
43
48
  export var ChainUtils;
44
49
  (function (ChainUtils) {
50
+ /**
51
+ * Returns whether native token balances are reliable on a chain.
52
+ *
53
+ * @param chainId - The EIP-155 chain id to inspect.
54
+ * @returns `false` only for chains whose metadata marks native balances as unreliable.
55
+ * @example
56
+ * ```ts
57
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
58
+ *
59
+ * const reliable = ChainUtils.hasReliableNativeBalance(ChainId.EthMainnet);
60
+ * // reliable === true
61
+ * ```
62
+ */
45
63
  ChainUtils.hasReliableNativeBalance = (chainId) => {
46
64
  return (ChainUtils.CHAIN_METADATA[chainId]
47
65
  ?.hasReliableNativeBalance ?? true);
48
66
  };
67
+ /**
68
+ * Converts a supported chain id to its hexadecimal JSON-RPC form.
69
+ *
70
+ * @param chainId - The supported chain id.
71
+ * @returns The chain id as a `0x`-prefixed hexadecimal string.
72
+ * @example
73
+ * ```ts
74
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
75
+ *
76
+ * const hexChainId = ChainUtils.toHexChainId(ChainId.EthMainnet);
77
+ * // hexChainId === "0x1"
78
+ * ```
79
+ */
49
80
  ChainUtils.toHexChainId = (chainId) => {
50
81
  return `0x${chainId.toString(16)}`;
51
82
  };
83
+ /**
84
+ * Returns the block explorer base URL for a supported chain.
85
+ *
86
+ * @param chainId - The supported chain id.
87
+ * @returns The chain's configured block explorer base URL.
88
+ * @example
89
+ * ```ts
90
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
91
+ *
92
+ * const explorerUrl = ChainUtils.getExplorerUrl(ChainId.EthMainnet);
93
+ * // explorerUrl === "https://etherscan.io"
94
+ * ```
95
+ */
52
96
  ChainUtils.getExplorerUrl = (chainId) => {
53
97
  return ChainUtils.CHAIN_METADATA[chainId].explorerUrl;
54
98
  };
99
+ /**
100
+ * Returns a block explorer address URL for a supported chain.
101
+ *
102
+ * @param chainId - The supported chain id.
103
+ * @param address - The address to link to.
104
+ * @returns The block explorer URL for `address`.
105
+ * @example
106
+ * ```ts
107
+ * import { ChainId, ChainUtils, NATIVE_ADDRESS } from "@morpho-org/blue-sdk";
108
+ *
109
+ * const url = ChainUtils.getExplorerAddressUrl(ChainId.EthMainnet, NATIVE_ADDRESS);
110
+ * // url satisfies string
111
+ * ```
112
+ */
55
113
  ChainUtils.getExplorerAddressUrl = (chainId, address) => {
56
114
  return `${ChainUtils.getExplorerUrl(chainId)}/address/${address}`;
57
115
  };
116
+ /**
117
+ * Returns a block explorer transaction URL for a supported chain.
118
+ *
119
+ * @param chainId - The supported chain id.
120
+ * @param tx - The transaction hash to link to.
121
+ * @returns The block explorer URL for `tx`.
122
+ * @example
123
+ * ```ts
124
+ * import { ChainId, ChainUtils } from "@morpho-org/blue-sdk";
125
+ *
126
+ * const url = ChainUtils.getExplorerTransactionUrl(ChainId.EthMainnet, "0xabc");
127
+ * // url satisfies string
128
+ * ```
129
+ */
58
130
  ChainUtils.getExplorerTransactionUrl = (chainId, tx) => {
59
131
  return `${ChainUtils.getExplorerUrl(chainId)}/tx/${tx}`;
60
132
  };
133
+ /** Metadata for each supported chain, keyed by `ChainId`. */
61
134
  ChainUtils.CHAIN_METADATA = {
62
135
  [ChainId.EthMainnet]: {
63
136
  name: "Ethereum",
@@ -333,5 +406,26 @@ export var ChainUtils;
333
406
  explorerUrl: "https://kaiascan.io",
334
407
  identifier: "kaia",
335
408
  },
409
+ [ChainId.ArcMainnet]: {
410
+ name: "Arc",
411
+ id: ChainId.ArcMainnet,
412
+ nativeCurrency: { name: "USDC", symbol: "USDC", decimals: 18 },
413
+ explorerUrl: "http://explorer.arc.io/",
414
+ identifier: "arc",
415
+ },
416
+ [ChainId.MorphMainnet]: {
417
+ name: "Morph",
418
+ id: ChainId.MorphMainnet,
419
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
420
+ explorerUrl: "https://explorer.morphl2.io",
421
+ identifier: "morph",
422
+ },
423
+ [ChainId.MegaEthMainnet]: {
424
+ name: "MegaETH",
425
+ id: ChainId.MegaEthMainnet,
426
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
427
+ explorerUrl: "https://mega.etherscan.io",
428
+ identifier: "megaeth",
429
+ },
336
430
  };
337
431
  })(ChainUtils || (ChainUtils = {}));
@@ -1,101 +1,140 @@
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 vault withdraw queue references a market without an allocation. */
32
+ export declare class UnknownMarketAllocationError extends UnknownDataError {
33
+ readonly marketId: MarketId;
34
+ constructor(marketId: MarketId);
35
+ }
36
+ /** Error thrown when a chain id has no configured SDK registry entry. */
25
37
  export declare class UnsupportedChainIdError extends Error {
26
38
  readonly chainId: number;
27
39
  constructor(chainId: number);
28
40
  }
41
+ /** Error thrown when no default pre-liquidation params exist for an LLTV. */
29
42
  export declare class UnsupportedPreLiquidationParamsError extends Error {
30
43
  readonly lltv: bigint;
31
44
  constructor(lltv: bigint);
32
45
  }
46
+ /** Error thrown when a Vault V2 adapter address is not supported by the SDK. */
33
47
  export declare class UnsupportedVaultV2AdapterError extends Error {
34
48
  readonly address: Address;
35
49
  constructor(address: Address);
36
50
  }
51
+ /** Morpho Blue protocol simulation errors. */
37
52
  export declare namespace BlueErrors {
53
+ /** Error thrown when a value that must be set once is already set. */
38
54
  class AlreadySet extends Error {
39
55
  readonly name: string;
40
56
  readonly value: string;
41
57
  constructor(name: string, value: string);
42
58
  }
59
+ /** Error thrown when market interest accrual is requested before `lastUpdate`. */
43
60
  class InvalidInterestAccrual extends Error {
44
61
  readonly marketId: MarketId;
45
62
  readonly timestamp: bigint;
46
63
  readonly lastUpdate: bigint;
47
64
  constructor(marketId: MarketId, timestamp: bigint, lastUpdate: bigint);
48
65
  }
66
+ /** Error thrown when asset and share inputs describe inconsistent values. */
49
67
  class InconsistentInput extends Error {
50
68
  readonly assets: bigint;
51
69
  readonly shares: bigint;
52
70
  constructor(assets: bigint, shares: bigint);
53
71
  }
72
+ /** Error thrown when a market has insufficient liquidity for an operation. */
54
73
  class InsufficientLiquidity extends Error {
55
74
  readonly marketId: MarketId;
56
75
  constructor(marketId: MarketId);
57
76
  }
77
+ /** Error thrown when a market oracle price is unavailable. */
58
78
  class UnknownOraclePrice extends Error {
59
79
  readonly marketId: MarketId;
60
80
  constructor(marketId: MarketId);
61
81
  }
82
+ /** Error thrown when a user position is too small for an operation. */
62
83
  class InsufficientPosition extends Error {
63
84
  readonly user: Address;
64
85
  readonly marketId: MarketId;
65
86
  constructor(user: Address, marketId: MarketId);
66
87
  }
88
+ /** Error thrown when a user position lacks required collateral. */
67
89
  class InsufficientCollateral extends Error {
68
90
  readonly user: Address;
69
91
  readonly marketId: MarketId;
70
92
  constructor(user: Address, marketId: MarketId);
71
93
  }
94
+ /** Error thrown when a signature deadline has expired. */
72
95
  class ExpiredSignature extends Error {
73
96
  readonly deadline: bigint;
74
97
  constructor(deadline: bigint);
75
98
  }
76
99
  }
100
+ /** Morpho Vault V2 simulation errors. */
77
101
  export declare namespace VaultV2Errors {
102
+ /** Error thrown when vault interest accrual is requested before `lastUpdate`. */
78
103
  class InvalidInterestAccrual extends Error {
79
104
  readonly vault: Address;
80
105
  readonly timestamp: bigint;
81
106
  readonly lastUpdate: bigint;
82
107
  constructor(vault: Address, timestamp: bigint, lastUpdate: bigint);
83
108
  }
109
+ /** Error thrown when a Vault V2 liquidity adapter is not supported by the SDK. */
84
110
  class UnsupportedLiquidityAdapter extends Error {
85
111
  readonly address: Address;
86
112
  constructor(address: Address);
87
113
  }
88
114
  }
115
+ /** Error thrown when a factory address is unavailable. */
89
116
  export declare class UnknownFactory extends Error {
90
117
  constructor();
91
118
  }
119
+ /** Error thrown when an address is not deployed by the expected factory. */
92
120
  export declare class UnknownOfFactory extends Error {
93
121
  readonly factory: Address;
94
122
  readonly address: Address;
95
123
  constructor(factory: Address, address: Address);
96
124
  }
125
+ /** Constructor type for errors accepted by `_try`. */
97
126
  export interface ErrorClass<E extends Error = Error> {
98
127
  new (...args: any[]): E;
99
128
  }
129
+ /**
130
+ * Runs an async accessor and returns `undefined` for expected lookup errors.
131
+ *
132
+ * @internal
133
+ */
100
134
  export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => Promise<T>, ...errorClasses: ErrorClasses): Promise<T | undefined>;
135
+ /**
136
+ * Runs a sync accessor and returns `undefined` for expected lookup errors.
137
+ *
138
+ * @internal
139
+ */
101
140
  export declare function _try<T, ErrorClasses extends readonly ErrorClass[] = []>(accessor: () => T, ...errorClasses: ErrorClasses): T | undefined;