@morpho-org/blue-sdk 1.0.6 → 1.2.1

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 (104) hide show
  1. package/README.md +2 -2
  2. package/lib/addresses.d.ts +34 -20
  3. package/lib/addresses.js +50 -13
  4. package/lib/chain.d.ts +30 -0
  5. package/lib/chain.js +288 -0
  6. package/lib/chain.test.js +22 -0
  7. package/lib/constants.d.ts +27 -6
  8. package/lib/constants.js +28 -8
  9. package/lib/errors.d.ts +18 -7
  10. package/lib/errors.js +38 -10
  11. package/lib/helpers/format/format.js +21 -60
  12. package/lib/helpers/index.d.ts +0 -2
  13. package/lib/helpers/index.js +0 -2
  14. package/lib/holding/Holding.d.ts +3 -4
  15. package/lib/holding/Holding.js +32 -4
  16. package/lib/index.d.ts +0 -8
  17. package/lib/index.js +1 -9
  18. package/lib/market/Market.d.ts +202 -54
  19. package/lib/market/Market.js +263 -62
  20. package/lib/market/MarketConfig.d.ts +17 -9
  21. package/lib/market/MarketConfig.js +39 -21
  22. package/lib/market/MarketUtils.d.ts +151 -102
  23. package/lib/market/MarketUtils.js +91 -39
  24. package/lib/market/MarketUtils.test.js +1 -2
  25. package/lib/maths/AdaptiveCurveIrmLib.d.ts +5 -4
  26. package/lib/maths/AdaptiveCurveIrmLib.js +10 -7
  27. package/lib/maths/MathLib.d.ts +35 -15
  28. package/lib/maths/MathLib.js +53 -33
  29. package/lib/maths/SharesMath.d.ts +3 -3
  30. package/lib/maths/SharesMath.js +2 -3
  31. package/lib/maths/index.d.ts +0 -1
  32. package/lib/maths/index.js +0 -1
  33. package/lib/position/Position.d.ts +5 -26
  34. package/lib/position/Position.js +28 -35
  35. package/lib/tests/mocks/markets.d.ts +1 -0
  36. package/lib/tests/mocks/markets.js +35 -29
  37. package/lib/token/Token.d.ts +4 -3
  38. package/lib/token/Token.js +28 -3
  39. package/lib/token/WrappedToken.js +12 -6
  40. package/lib/token/index.d.ts +1 -1
  41. package/lib/token/index.js +1 -1
  42. package/lib/types.d.ts +1 -0
  43. package/lib/types.js +3 -4
  44. package/lib/user/User.js +12 -0
  45. package/lib/vault/Vault.d.ts +12 -12
  46. package/lib/vault/Vault.js +102 -18
  47. package/lib/vault/VaultConfig.js +9 -3
  48. package/lib/vault/VaultMarketAllocation.d.ts +20 -0
  49. package/lib/vault/VaultMarketAllocation.js +30 -0
  50. package/lib/vault/VaultMarketConfig.d.ts +43 -0
  51. package/lib/vault/VaultMarketConfig.js +43 -0
  52. package/lib/vault/VaultMarketPublicAllocatorConfig.d.ts +29 -0
  53. package/lib/vault/VaultMarketPublicAllocatorConfig.js +28 -0
  54. package/lib/vault/VaultUtils.d.ts +8 -9
  55. package/lib/vault/VaultUtils.js +2 -3
  56. package/lib/vault/index.d.ts +3 -1
  57. package/lib/vault/index.js +3 -1
  58. package/package.json +6 -11
  59. package/lib/chain/chain.constants.d.ts +0 -3
  60. package/lib/chain/chain.constants.js +0 -232
  61. package/lib/chain/chain.test.js +0 -37
  62. package/lib/chain/chain.types.d.ts +0 -20
  63. package/lib/chain/chain.types.js +0 -30
  64. package/lib/chain/chain.utils.d.ts +0 -14
  65. package/lib/chain/chain.utils.js +0 -30
  66. package/lib/chain/index.d.ts +0 -2
  67. package/lib/chain/index.js +0 -18
  68. package/lib/ethers/ethers.test.d.ts +0 -1
  69. package/lib/ethers/ethers.test.js +0 -11
  70. package/lib/ethers/index.d.ts +0 -2
  71. package/lib/ethers/index.js +0 -18
  72. package/lib/ethers/safeGetAddress.d.ts +0 -1
  73. package/lib/ethers/safeGetAddress.js +0 -6
  74. package/lib/ethers/safeParseUnits.d.ts +0 -2
  75. package/lib/ethers/safeParseUnits.js +0 -25
  76. package/lib/evm.d.ts +0 -36
  77. package/lib/evm.js +0 -113
  78. package/lib/helpers/getChecksumedAddress.d.ts +0 -7
  79. package/lib/helpers/getChecksumedAddress.js +0 -17
  80. package/lib/helpers/isZeroAddressOrUnset.d.ts +0 -7
  81. package/lib/helpers/isZeroAddressOrUnset.js +0 -14
  82. package/lib/maths/MathUtils.d.ts +0 -15
  83. package/lib/maths/MathUtils.js +0 -33
  84. package/lib/notifications.d.ts +0 -98
  85. package/lib/notifications.js +0 -52
  86. package/lib/signatures/index.d.ts +0 -12
  87. package/lib/signatures/index.js +0 -39
  88. package/lib/signatures/manager.d.ts +0 -10
  89. package/lib/signatures/manager.js +0 -37
  90. package/lib/signatures/permit.d.ts +0 -21
  91. package/lib/signatures/permit.js +0 -101
  92. package/lib/signatures/permit2.d.ts +0 -20
  93. package/lib/signatures/permit2.js +0 -91
  94. package/lib/signatures/types.d.ts +0 -13
  95. package/lib/signatures/types.js +0 -2
  96. package/lib/signatures/utils.d.ts +0 -6
  97. package/lib/signatures/utils.js +0 -44
  98. package/lib/token/ERC20Metadata.d.ts +0 -249
  99. package/lib/token/ERC20Metadata.js +0 -81
  100. package/lib/token/TokenNamespace.d.ts +0 -18
  101. package/lib/token/TokenNamespace.js +0 -55
  102. package/lib/vault/VaultAllocation.d.ts +0 -38
  103. package/lib/vault/VaultAllocation.js +0 -18
  104. /package/lib/{chain/chain.test.d.ts → chain.test.d.ts} +0 -0
package/README.md CHANGED
@@ -42,7 +42,7 @@ Leverage the [`Market`](./src/market/Market.ts) class to fetch and query useful
42
42
  import { Market } from "@morpho-org/blue-sdk";
43
43
  import { Time } from "@morpho-org/morpho-ts";
44
44
 
45
- const market = Market.fetchFromId(
45
+ const market = Market.fetch(
46
46
  "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
47
47
  provider // Ethers provider.
48
48
  );
@@ -70,7 +70,7 @@ Leverage the [`Position`](./src/position/Position.ts) class to fetch and query u
70
70
  import { Position } from "@morpho-org/blue-sdk";
71
71
  import { Time } from "@morpho-org/morpho-ts";
72
72
 
73
- const position = AccrualPosition.fetchFromId(
73
+ const position = AccrualPosition.fetch(
74
74
  "0x7f65e7326F22963e2039734dDfF61958D5d284Ca",
75
75
  "0xb323495f7e4148be5643a4ea4a8221eef163e4bccfdedc2a6f4696baacbc86cc",
76
76
  provider // Ethers provider.
@@ -29,6 +29,7 @@ export declare const addresses: {
29
29
  readonly aaveV3OptimizerBundler: "0x16F38d2E764E7BeBF625a8E995b34968226D2F9c";
30
30
  readonly aaveV2Bundler: "0xb3dCc75DB379925edFd3007511A8CE0cB4aa8e76";
31
31
  readonly aaveV3Bundler: "0x98ccB155E86bb478d514a827d16f58c6912f9BDC";
32
+ readonly compoundV3Bundler: "0x3a0e2E9FB9c95fBc843daF166276C90B6C479558";
32
33
  readonly morphoToken: "0x9994E35Db50125E0DF82e4c2dde62496CE330999";
33
34
  readonly rEth: "0xae78736Cd615f374D3085123A210448E74Fc6393";
34
35
  readonly sDai: "0x83F20F44975D03b1b09e64809B757c47f942BEeA";
@@ -57,6 +58,7 @@ export declare const addresses: {
57
58
  readonly marketRewardsProgramRegistry: "0x5148bF15bb722E1854F66430Bc9FeD0E9FDaCE7D";
58
59
  readonly timeBoundedUrd: "0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb";
59
60
  readonly rsEth: "0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7";
61
+ readonly uni: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984";
60
62
  readonly "stkcvxcrvUSDTWBTCWETH-morpho": "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278";
61
63
  readonly crvUSDTWBTCWETH: "0xf5f5B97624542D72A9E06f04804Bf81baA15e2B4";
62
64
  readonly "stkcvxcrvUSDCWBTCWETH-morpho": "0x0ea1a65A2c255f24Ee8D81eA6AaC54Decd9d269e";
@@ -75,8 +77,12 @@ export declare const addresses: {
75
77
  readonly wNative: "0x4200000000000000000000000000000000000006";
76
78
  readonly adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687";
77
79
  readonly publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467";
80
+ readonly aaveV3Bundler: "0xcAe2929baBc60Be34818EaA5F40bF69265677108";
78
81
  readonly usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
79
82
  readonly cbEth: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22";
83
+ readonly verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b";
84
+ readonly ezEth: "0x2416092f143378750bb29b79eD961ab195CcEea5";
85
+ readonly testUsdc: "0xBC77067f829979812d795d516E523C4033b66409";
80
86
  };
81
87
  };
82
88
  interface ChainAddresses {
@@ -107,6 +113,7 @@ interface ChainAddresses {
107
113
  pyUsd?: Address;
108
114
  sUSDe?: Address;
109
115
  USDe?: Address;
116
+ uni?: Address;
110
117
  marketRewardsProgramRegistry?: Address;
111
118
  timeBoundedUrd?: Address;
112
119
  rsEth?: Address;
@@ -116,6 +123,7 @@ interface ChainAddresses {
116
123
  aaveV3OptimizerBundler?: Address;
117
124
  aaveV2Bundler?: Address;
118
125
  aaveV3Bundler?: Address;
126
+ compoundV3Bundler?: Address;
119
127
  "stkcvxcrvUSDTWBTCWETH-morpho"?: Address;
120
128
  crvUSDTWBTCWETH?: Address;
121
129
  "stkcvxcrvUSDCWBTCWETH-morpho"?: Address;
@@ -128,29 +136,35 @@ interface ChainAddresses {
128
136
  crvUSDETHCRV?: Address;
129
137
  }
130
138
  export type AddressLabel = keyof (typeof addresses)[ChainId];
131
- declare const _default: {
132
- 1: ChainAddresses;
133
- 5: ChainAddresses;
134
- 8453: ChainAddresses;
135
- };
139
+ declare const _default: { [n in ChainId]: ChainAddresses; };
136
140
  export default _default;
137
141
  export declare const getChainAddresses: (chainId: number) => ChainAddresses;
138
- export declare const unwrappedTokensMapping: {
139
- [n in ChainId]: {
140
- [wrapped: string]: string;
141
- };
142
- };
142
+ /**
143
+ * Assumptions:
144
+ * - unwrapped token has same number of decimals than wrapped tokens.
145
+ */
146
+ export declare const unwrappedTokensMapping: Record<ChainId, Record<Address, Address>>;
143
147
  export declare function getUnwrappedToken(wrappedToken: Address, chainId: ChainId): string | undefined;
144
- export declare const erc20WrapperTokens: {
145
- [id in ChainId]: Set<Address>;
146
- };
147
- export declare const wrappedBackedTokens: {
148
- [id in ChainId]: Set<Address>;
149
- };
150
- export declare const getWrappedBackedTokens: (chainId: number) => Set<string>;
148
+ /**
149
+ * The registry of all known ERC20Wrapper tokens.
150
+ */
151
+ export declare const erc20WrapperTokens: Record<ChainId, Set<Address>>;
152
+ /**
153
+ * The registry of all known PermissionedERC20Wrapper with a `hasPermission` getter.
154
+ * All permissioned wrapper tokens are considered ERC20Wrapper and automatically added to the erc20WrapperTokens registry.
155
+ */
156
+ export declare const permissionedWrapperTokens: Record<ChainId, Set<Address>>;
157
+ /**
158
+ * The registry of all known permissioned wrapped Backed tokens.
159
+ * All permissioned Backed tokens are considered ERC20Wrapper and automatically added to the erc20WrapperTokens registry.
160
+ */
161
+ export declare const permissionedBackedTokens: Record<ChainId, Set<Address>>;
162
+ /**
163
+ * The registry of all known permissioned wrapped tokens that require a Coinbase attestation.
164
+ * All permissioned Coinbase tokens are considered PermissionedERC20Wrapper and automatically added to the permissionedWrapperTokens registry.
165
+ */
166
+ export declare const permissionedCoinbaseTokens: Record<ChainId, Set<Address>>;
151
167
  /** /!\ These tokens can not be listed in `erc20WrapperTokens` because the following specs are different:
152
168
  * - calling `depositFor` supplies on blue instead of minting wrapped token to the user
153
169
  */
154
- export declare const convexWrapperTokens: {
155
- [id in ChainId]: Set<Address>;
156
- };
170
+ export declare const convexWrapperTokens: Record<ChainId, Set<Address>>;
package/lib/addresses.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convexWrapperTokens = exports.getWrappedBackedTokens = exports.wrappedBackedTokens = exports.erc20WrapperTokens = exports.getUnwrappedToken = exports.unwrappedTokensMapping = exports.getChainAddresses = exports.addresses = exports.NATIVE_ADDRESS = void 0;
3
+ exports.convexWrapperTokens = exports.permissionedCoinbaseTokens = exports.permissionedBackedTokens = exports.permissionedWrapperTokens = exports.erc20WrapperTokens = exports.unwrappedTokensMapping = exports.getChainAddresses = exports.addresses = exports.NATIVE_ADDRESS = void 0;
4
+ exports.getUnwrappedToken = getUnwrappedToken;
5
+ const morpho_ts_1 = require("@morpho-org/morpho-ts");
4
6
  const chain_1 = require("./chain");
5
7
  const errors_1 = require("./errors");
6
8
  /** Address used to replicate an erc20-behaviour for native token.
@@ -32,6 +34,7 @@ exports.addresses = {
32
34
  aaveV3OptimizerBundler: "0x16F38d2E764E7BeBF625a8E995b34968226D2F9c",
33
35
  aaveV2Bundler: "0xb3dCc75DB379925edFd3007511A8CE0cB4aa8e76",
34
36
  aaveV3Bundler: "0x98ccB155E86bb478d514a827d16f58c6912f9BDC",
37
+ compoundV3Bundler: "0x3a0e2E9FB9c95fBc843daF166276C90B6C479558",
35
38
  morphoToken: "0x9994E35Db50125E0DF82e4c2dde62496CE330999",
36
39
  rEth: "0xae78736Cd615f374D3085123A210448E74Fc6393",
37
40
  sDai: "0x83F20F44975D03b1b09e64809B757c47f942BEeA",
@@ -64,6 +67,7 @@ exports.addresses = {
64
67
  marketRewardsProgramRegistry: "0x5148bF15bb722E1854F66430Bc9FeD0E9FDaCE7D",
65
68
  timeBoundedUrd: "0x330eefa8a787552DC5cAd3C3cA644844B1E61Ddb",
66
69
  rsEth: "0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7",
70
+ uni: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
67
71
  /* Curve tokens */
68
72
  "stkcvxcrvUSDTWBTCWETH-morpho": "0xb0Ce26C88e4e7DCa51968b6047f44646f5064278",
69
73
  crvUSDTWBTCWETH: "0xf5f5B97624542D72A9E06f04804Bf81baA15e2B4",
@@ -83,9 +87,13 @@ exports.addresses = {
83
87
  wNative: "0x4200000000000000000000000000000000000006",
84
88
  adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687",
85
89
  publicAllocator: "0xA090dD1a701408Df1d4d0B85b716c87565f90467",
90
+ aaveV3Bundler: "0xcAe2929baBc60Be34818EaA5F40bF69265677108",
86
91
  /* Tokens */
87
92
  usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
88
93
  cbEth: "0x2Ae3F1Ec7F1F5012CFEab0185bfc7aa3cf0DEc22",
94
+ verUsdc: "0x59aaF835D34b1E3dF2170e4872B785f11E2a964b",
95
+ ezEth: "0x2416092f143378750bb29b79eD961ab195CcEea5",
96
+ testUsdc: "0xBC77067f829979812d795d516E523C4033b66409",
89
97
  },
90
98
  };
91
99
  exports.default = exports.addresses;
@@ -96,6 +104,10 @@ const getChainAddresses = (chainId) => {
96
104
  return chainAddresses;
97
105
  };
98
106
  exports.getChainAddresses = getChainAddresses;
107
+ /**
108
+ * Assumptions:
109
+ * - unwrapped token has same number of decimals than wrapped tokens.
110
+ */
99
111
  exports.unwrappedTokensMapping = {
100
112
  [chain_1.ChainId.EthGoerliTestnet]: {
101
113
  [exports.addresses[chain_1.ChainId.EthGoerliTestnet].wNative]: exports.NATIVE_ADDRESS,
@@ -115,21 +127,35 @@ exports.unwrappedTokensMapping = {
115
127
  },
116
128
  [chain_1.ChainId.BaseMainnet]: {
117
129
  [exports.addresses[chain_1.ChainId.BaseMainnet].wNative]: exports.NATIVE_ADDRESS,
130
+ [exports.addresses[chain_1.ChainId.BaseMainnet].verUsdc]: exports.addresses[chain_1.ChainId.BaseMainnet].usdc,
131
+ [exports.addresses[chain_1.ChainId.BaseMainnet].testUsdc]: exports.addresses[chain_1.ChainId.BaseMainnet].usdc,
118
132
  },
119
133
  };
120
134
  function getUnwrappedToken(wrappedToken, chainId) {
121
135
  return exports.unwrappedTokensMapping[chainId][wrappedToken];
122
136
  }
123
- exports.getUnwrappedToken = getUnwrappedToken;
137
+ /**
138
+ * The registry of all known ERC20Wrapper tokens.
139
+ */
124
140
  exports.erc20WrapperTokens = {
125
- [chain_1.ChainId.EthMainnet]: new Set([
126
- exports.addresses[chain_1.ChainId.EthMainnet].wbIB01,
127
- exports.addresses[chain_1.ChainId.EthMainnet].wbC3M,
128
- ]),
141
+ [chain_1.ChainId.EthMainnet]: new Set(),
129
142
  [chain_1.ChainId.EthGoerliTestnet]: new Set(),
130
143
  [chain_1.ChainId.BaseMainnet]: new Set(),
131
144
  };
132
- exports.wrappedBackedTokens = {
145
+ /**
146
+ * The registry of all known PermissionedERC20Wrapper with a `hasPermission` getter.
147
+ * All permissioned wrapper tokens are considered ERC20Wrapper and automatically added to the erc20WrapperTokens registry.
148
+ */
149
+ exports.permissionedWrapperTokens = {
150
+ [chain_1.ChainId.EthMainnet]: new Set(),
151
+ [chain_1.ChainId.EthGoerliTestnet]: new Set(),
152
+ [chain_1.ChainId.BaseMainnet]: new Set([exports.addresses[chain_1.ChainId.BaseMainnet].testUsdc]),
153
+ };
154
+ /**
155
+ * The registry of all known permissioned wrapped Backed tokens.
156
+ * All permissioned Backed tokens are considered ERC20Wrapper and automatically added to the erc20WrapperTokens registry.
157
+ */
158
+ exports.permissionedBackedTokens = {
133
159
  [chain_1.ChainId.EthMainnet]: new Set([
134
160
  exports.addresses[chain_1.ChainId.EthMainnet].wbIB01,
135
161
  exports.addresses[chain_1.ChainId.EthMainnet].wbC3M,
@@ -137,13 +163,24 @@ exports.wrappedBackedTokens = {
137
163
  [chain_1.ChainId.EthGoerliTestnet]: new Set(),
138
164
  [chain_1.ChainId.BaseMainnet]: new Set(),
139
165
  };
140
- const getWrappedBackedTokens = (chainId) => {
141
- const tokens = exports.wrappedBackedTokens[chainId];
142
- if (!tokens)
143
- throw new errors_1.UnsupportedChainIdError(chainId);
144
- return tokens;
166
+ /**
167
+ * The registry of all known permissioned wrapped tokens that require a Coinbase attestation.
168
+ * All permissioned Coinbase tokens are considered PermissionedERC20Wrapper and automatically added to the permissionedWrapperTokens registry.
169
+ */
170
+ exports.permissionedCoinbaseTokens = {
171
+ [chain_1.ChainId.EthMainnet]: new Set(),
172
+ [chain_1.ChainId.EthGoerliTestnet]: new Set(),
173
+ [chain_1.ChainId.BaseMainnet]: new Set([exports.addresses[chain_1.ChainId.BaseMainnet].verUsdc]),
145
174
  };
146
- exports.getWrappedBackedTokens = getWrappedBackedTokens;
175
+ (0, morpho_ts_1.entries)(exports.permissionedBackedTokens).forEach(([chainId, tokens]) => {
176
+ tokens.forEach((token) => exports.erc20WrapperTokens[chainId].add(token));
177
+ });
178
+ (0, morpho_ts_1.entries)(exports.permissionedCoinbaseTokens).forEach(([chainId, tokens]) => {
179
+ tokens.forEach((token) => exports.permissionedWrapperTokens[chainId].add(token));
180
+ });
181
+ (0, morpho_ts_1.entries)(exports.permissionedWrapperTokens).forEach(([chainId, tokens]) => {
182
+ tokens.forEach((token) => exports.erc20WrapperTokens[chainId].add(token));
183
+ });
147
184
  /** /!\ These tokens can not be listed in `erc20WrapperTokens` because the following specs are different:
148
185
  * - calling `depositFor` supplies on blue instead of minting wrapped token to the user
149
186
  */
package/lib/chain.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ export declare enum ChainId {
2
+ EthMainnet = 1,
3
+ EthGoerliTestnet = 5,
4
+ BaseMainnet = 8453
5
+ }
6
+ export interface ChainMetadata {
7
+ readonly name: string;
8
+ readonly id: ChainId;
9
+ readonly defaultRpcUrl: string;
10
+ readonly explorerUrl: string;
11
+ readonly nativeCurrency: {
12
+ readonly name: string;
13
+ readonly symbol: string;
14
+ readonly decimals: number;
15
+ };
16
+ readonly isTestnet: boolean;
17
+ readonly shortName: string;
18
+ readonly identifier: string;
19
+ readonly logoSrc: string;
20
+ }
21
+ export declare namespace ChainUtils {
22
+ const toHexChainId: (chainId: ChainId) => string;
23
+ const getExplorerUrl: (chainId: ChainId) => string;
24
+ const getExplorerAddressUrl: (chainId: ChainId, address: string) => string;
25
+ const getExplorerTransactionUrl: (chainId: ChainId, tx: string) => string;
26
+ function isSupported(chainId: number): chainId is ChainId;
27
+ function parseSupportedChainId(candidate: any): ChainId;
28
+ const BLUE_AVAILABLE_CHAINS: [ChainId, ...ChainId[]];
29
+ const CHAIN_METADATA: Record<ChainId, ChainMetadata>;
30
+ }
package/lib/chain.js ADDED
@@ -0,0 +1,288 @@
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["EthGoerliTestnet"] = 5] = "EthGoerliTestnet";
9
+ ChainId[ChainId["BaseMainnet"] = 8453] = "BaseMainnet";
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.EthGoerliTestnet]: {
74
+ name: "Ethereum Goerli Testnet",
75
+ id: ChainId.EthGoerliTestnet,
76
+ nativeCurrency: { name: "Goerli Ether", symbol: "ETH", decimals: 18 },
77
+ defaultRpcUrl: "https://goerli.infura.io/V3/84842078b09946638c03157f83405213",
78
+ explorerUrl: "https://goerli.etherscan.io",
79
+ isTestnet: true,
80
+ shortName: "Goerli",
81
+ logoSrc: "https://cdn.morpho.org/assets/chains/eth.svg",
82
+ identifier: "goerli",
83
+ },
84
+ [ChainId.BaseMainnet]: {
85
+ name: "Base",
86
+ id: ChainId.BaseMainnet,
87
+ nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
88
+ defaultRpcUrl: "https://rpc.baseprotocol.org",
89
+ explorerUrl: "https://basescan.org",
90
+ isTestnet: false,
91
+ shortName: "Base",
92
+ logoSrc: "https://cdn.morpho.org/assets/chains/base.png",
93
+ identifier: "base",
94
+ },
95
+ // [ChainId.PolygonMainnet]: {
96
+ // name: "Polygon Mainnet",
97
+ // id: ChainId.PolygonMainnet,
98
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
99
+ // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
100
+ // explorerUrl: "https://polygonscan.com",
101
+ // isTestnet: false,
102
+ // shortName: "Polygon",
103
+ // },
104
+ // [ChainId.MumbaiTestnet]: {
105
+ // name: "Mumbai Testnet",
106
+ // id: ChainId.MumbaiTestnet,
107
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
108
+ // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
109
+ // explorerUrl: "https://mumbai.polygonscan.com",
110
+ // isTestnet: true,
111
+ // shortName: "Mumbai",
112
+ // },
113
+ /* see https://chainid.network/chains.json */
114
+ // [ChainId.PolygonMainnet]: {
115
+ // name: "Polygon Mainnet",
116
+ // id: ChainId.PolygonMainnet,
117
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
118
+ // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
119
+ // explorerUrl: "https://polygonscan.com",
120
+ // isTestnet: false,
121
+ // shortName: "Polygon",
122
+ // },
123
+ // [ChainId.MumbaiTestnet]: {
124
+ // name: "Mumbai Testnet",
125
+ // id: ChainId.MumbaiTestnet,
126
+ // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
127
+ // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
128
+ // explorerUrl: "https://mumbai.polygonscan.com",
129
+ // isTestnet: true,
130
+ // shortName: "Mumbai",
131
+ // },
132
+ // [ChainId.OptimismMainnet]: {
133
+ // name: "Optimism Mainnet",
134
+ // id: ChainId.OptimismMainnet,
135
+ // baseCurrency: "ETH",
136
+ // defaultRpcUrl: "https://mainnet.optimism.io",
137
+ // explorerUrl: "https://optimistic.etherscan.io",
138
+ // isTestnet: false,
139
+ // },
140
+ // [ChainId.BscMainnet]: {
141
+ // name: "Binance Smart Chain Mainnet",
142
+ // id: ChainId.BscMainnet,
143
+ // baseCurrency: "BNB",
144
+ // defaultRpcUrl: "https://bsc-dataseed.binance.org",
145
+ // explorerUrl: "https://bscscan.com",
146
+ // isTestnet: false,
147
+ // },
148
+ // [ChainId.ArbitrumMainnet]: {
149
+ // name: "Arbitrum Mainnet",
150
+ // id: ChainId.ArbitrumMainnet,
151
+ // baseCurrency: "ETH",
152
+ // defaultRpcUrl: "https://arb1.arbitrum.io/rpc",
153
+ // explorerUrl: "https://arbiscan.io",
154
+ // isTestnet: false,
155
+ // },
156
+ // [ChainId.ArbitrumTestnet]: {
157
+ // name: "Arbitrum Testnet",
158
+ // id: ChainId.ArbitrumTestnet,
159
+ // baseCurrency: "ETH",
160
+ // defaultRpcUrl: "https://rinkeby.arbitrum.io/rpc",
161
+ // explorerUrl: "https://rinkeby-explorer.arbitrum.io",
162
+ // isTestnet: true,
163
+ // },
164
+ // [ChainId.GnosisChain]: {
165
+ // name: "Gnosis Chain",
166
+ // id: ChainId.GnosisChain,
167
+ // baseCurrency: "XDAI",
168
+ // defaultRpcUrl: "https://rpc.xdaichain.com",
169
+ // explorerUrl: "https://gnosis.blockscout.com",
170
+ // isTestnet: false,
171
+ // },
172
+ // [ChainId.FantomMainnet]: {
173
+ // name: "Fantom Mainnet",
174
+ // id: ChainId.FantomMainnet,
175
+ // baseCurrency: "FTM",
176
+ // defaultRpcUrl: "https://rpcapi.fantom.network",
177
+ // explorerUrl: "https://ftmscan.com",
178
+ // isTestnet: false,
179
+ // },
180
+ // [ChainId.FantomTestnet]: {
181
+ // name: "Fantom Testnet",
182
+ // id: ChainId.FantomTestnet,
183
+ // baseCurrency: "FTM",
184
+ // defaultRpcUrl: "https://rpc.testnet.fantom.network",
185
+ // explorerUrl: "https://explorer.testnet.fantom.network",
186
+ // isTestnet: true,
187
+ // },
188
+ // [ChainId.HarmonyMainnet]: {
189
+ // name: "Harmony Mainnet",
190
+ // id: ChainId.HarmonyMainnet,
191
+ // baseCurrency: "ONE",
192
+ // defaultRpcUrl: "https://api.harmony.one",
193
+ // explorerUrl: "https://explorer.harmony.one",
194
+ // isTestnet: false,
195
+ // },
196
+ // [ChainId.HarmonyTestnet]: {
197
+ // name: "Harmony Testnet",
198
+ // id: ChainId.HarmonyTestnet,
199
+ // baseCurrency: "ONE",
200
+ // defaultRpcUrl: "https://api.s0.b.hmny.io",
201
+ // explorerUrl: "https://explorer.testnet.harmony.one",
202
+ // isTestnet: true,
203
+ // },
204
+ // [ChainId.BscTestnet]: {
205
+ // name: "Binance Smart Chain Testnet",
206
+ // id: ChainId.BscTestnet,
207
+ // baseCurrency: "BNB",
208
+ // defaultRpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545",
209
+ // explorerUrl: "https://testnet.bscscan.com",
210
+ // isTestnet: true,
211
+ // },
212
+ // [ChainId.OptimismTestnet]: {
213
+ // name: "Optimism Testnet",
214
+ // id: ChainId.OptimismTestnet,
215
+ // baseCurrency: "ETH",
216
+ // defaultRpcUrl: "https://kovan.optimism.io",
217
+ // explorerUrl: "https://kovan-optimistic.etherscan.io",
218
+ // isTestnet: true,
219
+ // },
220
+ // [ChainId.EthRopstenTestnet]: {
221
+ // name: "Ethereum Ropsten Testnet",
222
+ // id: ChainId.EthRopstenTestnet,
223
+ // baseCurrency: "ETH",
224
+ // defaultRpcUrl:
225
+ // "https://ropsten.infura.io/V4/84842078b09946638c03157f83405213",
226
+ // explorerUrl: "https://ropsten.etherscan.io",
227
+ // isTestnet: true,
228
+ // },
229
+ // [ChainId.EthRinkebyTestnet]: {
230
+ // name: "Ethereum Rinkeby Testnet",
231
+ // id: ChainId.EthRinkebyTestnet,
232
+ // baseCurrency: "ETH",
233
+ // defaultRpcUrl:
234
+ // "https://rinkeby.infura.io/V4/84842078b09946638c03157f83405213",
235
+ // explorerUrl: "https://rinkeby.etherscan.io",
236
+ // isTestnet: true,
237
+ // },
238
+ // [ChainId.EthKovanTestnet]: {
239
+ // name: "Ethereum Kovan Testnet",
240
+ // id: ChainId.EthKovanTestnet,
241
+ // baseCurrency: "ETH",
242
+ // defaultRpcUrl:
243
+ // "https://kovan.infura.io/V4/84842078b09946638c03157f83405213",
244
+ // explorerUrl: "https://kovan.etherscan.io",
245
+ // isTestnet: true,
246
+ // },
247
+ // [ChainId.BaseGoerliTestnet]: {
248
+ // name: "Base Goerli Testnet",
249
+ // id: ChainId.BaseGoerliTestnet,
250
+ // baseCurrency: "ETH",
251
+ // defaultRpcUrl: "https://rpc-goerli.baseprotocol.org",
252
+ // explorerUrl: "https://goerli.basescan.org",
253
+ // isTestnet: true,
254
+ // },
255
+ // [ChainId.GnosisChainTestnet]: {
256
+ // name: "Gnosis Chain Testnet",
257
+ // id: ChainId.GnosisChainTestnet,
258
+ // baseCurrency: "XDAI",
259
+ // defaultRpcUrl: "https://rpc.chiado.gnosis.gateway.fm",
260
+ // explorerUrl: "https://gnosis-chiado.blockscout.com/",
261
+ // isTestnet: true,
262
+ // },
263
+ // [ChainId.AvalancheMainnet]: {
264
+ // name: "Avalanche Mainnet",
265
+ // id: ChainId.AvalancheMainnet,
266
+ // baseCurrency: "AVAX",
267
+ // defaultRpcUrl: "https://api.avax.network/ext/bc/C/rpc",
268
+ // explorerUrl: "https://cchain.explorer.avax.network",
269
+ // isTestnet: false,
270
+ // },
271
+ // [ChainId.AvalancheFujiTestnet]: {
272
+ // name: "Avalanche Fuji Testnet",
273
+ // id: ChainId.AvalancheFujiTestnet,
274
+ // baseCurrency: "AVAX",
275
+ // defaultRpcUrl: "https://api.avax-test.network/ext/bc/C/rpc",
276
+ // explorerUrl: "https://cchain.explorer.avax-test.network",
277
+ // isTestnet: true,
278
+ // },
279
+ // [ChainId.MoonbaseAlphaTestnet]: {
280
+ // name: "Moonbase Alpha Testnet",
281
+ // id: ChainId.MoonbaseAlphaTestnet,
282
+ // baseCurrency: "DEV",
283
+ // defaultRpcUrl: "https://rpc.testnet.moonbeam.network",
284
+ // explorerUrl: "https://moonbase-blockscout.testnet.moonbeam.network",
285
+ // isTestnet: true,
286
+ // },
287
+ };
288
+ })(ChainUtils || (exports.ChainUtils = ChainUtils = {}));
@@ -0,0 +1,22 @@
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.EthGoerliTestnet)).toEqual("0x5");
20
+ expect(chain_1.ChainUtils.toHexChainId(chain_1.ChainId.BaseMainnet)).toEqual("0x2105");
21
+ });
22
+ });
@@ -1,8 +1,29 @@
1
- export declare const LIQUIDATION_CURSOR: bigint;
2
- export declare const MAX_LIQUIDATION_INCENTIVE_FACTOR: bigint;
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;
3
9
  export declare const ORACLE_PRICE_OFFSET = 36;
4
- export declare const ORACLE_PRICE_SCALE: bigint;
5
- export declare const MAX_FEE: bigint;
6
- export declare const DEFAULT_SLIPPAGE_TOLERANCE: bigint;
7
- export declare const DEFAULT_TARGET_UTILIZATION: bigint;
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
+ */
8
29
  export declare const SECONDS_PER_YEAR: bigint;
package/lib/constants.js CHANGED
@@ -1,13 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SECONDS_PER_YEAR = exports.DEFAULT_TARGET_UTILIZATION = exports.DEFAULT_SLIPPAGE_TOLERANCE = exports.MAX_FEE = exports.ORACLE_PRICE_SCALE = exports.ORACLE_PRICE_OFFSET = exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = exports.LIQUIDATION_CURSOR = void 0;
4
- const ethers_1 = require("ethers");
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;
5
4
  const morpho_ts_1 = require("@morpho-org/morpho-ts");
6
- exports.LIQUIDATION_CURSOR = (0, ethers_1.parseEther)("0.3");
7
- exports.MAX_LIQUIDATION_INCENTIVE_FACTOR = (0, ethers_1.parseEther)("1.15");
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;
8
13
  exports.ORACLE_PRICE_OFFSET = 36;
9
- exports.ORACLE_PRICE_SCALE = (0, ethers_1.parseUnits)("1", exports.ORACLE_PRICE_OFFSET);
10
- exports.MAX_FEE = (0, ethers_1.parseEther)("0.25"); // 25%
11
- exports.DEFAULT_SLIPPAGE_TOLERANCE = (0, ethers_1.parseEther)("0.0003"); // 0.03%
12
- exports.DEFAULT_TARGET_UTILIZATION = (0, ethers_1.parseEther)("0.92"); // 92%
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
+ */
13
33
  exports.SECONDS_PER_YEAR = morpho_ts_1.Time.s.from.y(1n);