@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
@@ -1,17 +1,16 @@
1
- import { BigNumberish } from "ethers";
2
1
  import { RoundingDirection } from "../maths";
3
2
  export declare namespace VaultUtils {
4
3
  const VIRTUAL_ASSETS = 1n;
5
- function toAssets(shares: BigNumberish, { totalAssets, totalSupply, }: {
6
- totalAssets: BigNumberish;
7
- totalSupply: BigNumberish;
4
+ function toAssets(shares: bigint, { totalAssets, totalSupply, }: {
5
+ totalAssets: bigint;
6
+ totalSupply: bigint;
8
7
  }, { decimalsOffset }: {
9
- decimalsOffset: BigNumberish;
8
+ decimalsOffset: bigint;
10
9
  }, rounding?: RoundingDirection): bigint;
11
- function toShares(assets: BigNumberish, { totalAssets, totalSupply, }: {
12
- totalAssets: BigNumberish;
13
- totalSupply: BigNumberish;
10
+ function toShares(assets: bigint, { totalAssets, totalSupply, }: {
11
+ totalAssets: bigint;
12
+ totalSupply: bigint;
14
13
  }, { decimalsOffset }: {
15
- decimalsOffset: BigNumberish;
14
+ decimalsOffset: bigint;
16
15
  }, rounding?: RoundingDirection): bigint;
17
16
  }
@@ -1,17 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultUtils = void 0;
4
- const ethers_1 = require("ethers");
5
4
  const maths_1 = require("../maths");
6
5
  var VaultUtils;
7
6
  (function (VaultUtils) {
8
7
  VaultUtils.VIRTUAL_ASSETS = 1n;
9
8
  function toAssets(shares, { totalAssets, totalSupply, }, { decimalsOffset }, rounding = "Down") {
10
- return maths_1.MathLib.mulDiv(shares, (0, ethers_1.toBigInt)(totalAssets) + VaultUtils.VIRTUAL_ASSETS, (0, ethers_1.toBigInt)(totalSupply) + 10n ** (0, ethers_1.toBigInt)(decimalsOffset), rounding);
9
+ return maths_1.MathLib.mulDiv(shares, totalAssets + VaultUtils.VIRTUAL_ASSETS, totalSupply + 10n ** decimalsOffset, rounding);
11
10
  }
12
11
  VaultUtils.toAssets = toAssets;
13
12
  function toShares(assets, { totalAssets, totalSupply, }, { decimalsOffset }, rounding = "Up") {
14
- return maths_1.MathLib.mulDiv(assets, (0, ethers_1.toBigInt)(totalSupply) + 10n ** (0, ethers_1.toBigInt)(decimalsOffset), (0, ethers_1.toBigInt)(totalAssets) + VaultUtils.VIRTUAL_ASSETS, rounding);
13
+ return maths_1.MathLib.mulDiv(assets, totalSupply + 10n ** decimalsOffset, totalAssets + VaultUtils.VIRTUAL_ASSETS, rounding);
15
14
  }
16
15
  VaultUtils.toShares = toShares;
17
16
  })(VaultUtils || (exports.VaultUtils = VaultUtils = {}));
@@ -1,4 +1,6 @@
1
1
  export * from "./VaultUtils";
2
2
  export * from "./VaultConfig";
3
- export * from "./VaultAllocation";
3
+ export * from "./VaultMarketAllocation";
4
+ export * from "./VaultMarketConfig";
5
+ export * from "./VaultMarketPublicAllocatorConfig";
4
6
  export * from "./Vault";
@@ -16,5 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./VaultUtils"), exports);
18
18
  __exportStar(require("./VaultConfig"), exports);
19
- __exportStar(require("./VaultAllocation"), exports);
19
+ __exportStar(require("./VaultMarketAllocation"), exports);
20
+ __exportStar(require("./VaultMarketConfig"), exports);
21
+ __exportStar(require("./VaultMarketPublicAllocatorConfig"), exports);
20
22
  __exportStar(require("./Vault"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morpho-org/blue-sdk",
3
- "version": "1.0.6",
3
+ "version": "1.2.1",
4
4
  "author": "Morpho Association <contact@morpho.org>",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -10,19 +10,14 @@
10
10
  "scripts": {
11
11
  "prepublish": "yarn build",
12
12
  "build": "tsc --build tsconfig.build.json",
13
- "build:blue-sdk": "yarn build",
14
- "test": "jest",
15
- "test:blue-sdk": "yarn test"
13
+ "test": "jest"
16
14
  },
17
15
  "dependencies": {
18
- "@morpho-org/morpho-ts": "1.0.4",
19
- "ethers": "^6.12.1",
20
- "ethers-multicall-provider": "^6.3.0",
21
- "ethers-types": "^3.15.1",
22
- "rxjs": "^7.8.1"
16
+ "@morpho-org/morpho-ts": "1.0.5",
17
+ "keccak256": "^1.0.6"
23
18
  },
24
19
  "devDependencies": {
25
- "@morpho-org/morpho-test": "1.0.4",
20
+ "@morpho-org/morpho-test": "1.0.5",
26
21
  "@types/jest": "^29.5.12",
27
22
  "jest": "^29.6.2",
28
23
  "ts-jest": "^29.1.1",
@@ -50,5 +45,5 @@
50
45
  ],
51
46
  "preset": "ts-jest"
52
47
  },
53
- "gitHead": "bbda7acf4856a4096456091ef5862d0df7e06f22"
48
+ "gitHead": "cc64e88993808eb357c59e27501e4d05bd868e5b"
54
49
  }
@@ -1,3 +0,0 @@
1
- import { ChainMetadata, ChainId } from "./chain.types";
2
- export declare const BLUE_AVAILABLE_CHAINS: ChainId[];
3
- export declare const CHAIN_METADATA: Record<ChainId, ChainMetadata>;
@@ -1,232 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CHAIN_METADATA = exports.BLUE_AVAILABLE_CHAINS = void 0;
4
- const chain_types_1 = require("./chain.types");
5
- exports.BLUE_AVAILABLE_CHAINS = [chain_types_1.ChainId.EthMainnet, chain_types_1.ChainId.BaseMainnet];
6
- exports.CHAIN_METADATA = {
7
- [chain_types_1.ChainId.EthMainnet]: {
8
- name: "Ethereum",
9
- id: chain_types_1.ChainId.EthMainnet,
10
- nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
11
- defaultRpcUrl: "https://mainnet.infura.io/V3/84842078b09946638c03157f83405213",
12
- explorerUrl: "https://etherscan.io",
13
- isTestnet: false,
14
- shortName: "ETH",
15
- logoSrc: "https://cdn.morpho.org/assets/chains/eth.svg",
16
- identifier: "mainnet",
17
- },
18
- [chain_types_1.ChainId.EthGoerliTestnet]: {
19
- name: "Ethereum Goerli Testnet",
20
- id: chain_types_1.ChainId.EthGoerliTestnet,
21
- nativeCurrency: { name: "Goerli Ether", symbol: "ETH", decimals: 18 },
22
- defaultRpcUrl: "https://goerli.infura.io/V3/84842078b09946638c03157f83405213",
23
- explorerUrl: "https://goerli.etherscan.io",
24
- isTestnet: true,
25
- shortName: "Goerli",
26
- logoSrc: "https://cdn.morpho.org/assets/chains/eth.svg",
27
- identifier: "goerli",
28
- },
29
- [chain_types_1.ChainId.BaseMainnet]: {
30
- name: "Base",
31
- id: chain_types_1.ChainId.BaseMainnet,
32
- nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
33
- defaultRpcUrl: "https://rpc.baseprotocol.org",
34
- explorerUrl: "https://basescan.org",
35
- isTestnet: false,
36
- shortName: "Base",
37
- logoSrc: "https://cdn.morpho.org/assets/chains/base.png",
38
- identifier: "base",
39
- },
40
- // [ChainId.PolygonMainnet]: {
41
- // name: "Polygon Mainnet",
42
- // id: ChainId.PolygonMainnet,
43
- // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
44
- // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
45
- // explorerUrl: "https://polygonscan.com",
46
- // isTestnet: false,
47
- // shortName: "Polygon",
48
- // },
49
- // [ChainId.MumbaiTestnet]: {
50
- // name: "Mumbai Testnet",
51
- // id: ChainId.MumbaiTestnet,
52
- // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
53
- // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
54
- // explorerUrl: "https://mumbai.polygonscan.com",
55
- // isTestnet: true,
56
- // shortName: "Mumbai",
57
- // },
58
- /* see https://chainid.network/chains.json */
59
- // [ChainId.PolygonMainnet]: {
60
- // name: "Polygon Mainnet",
61
- // id: ChainId.PolygonMainnet,
62
- // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
63
- // defaultRpcUrl: "https://rpc-mainnet.maticvigil.com",
64
- // explorerUrl: "https://polygonscan.com",
65
- // isTestnet: false,
66
- // shortName: "Polygon",
67
- // },
68
- // [ChainId.MumbaiTestnet]: {
69
- // name: "Mumbai Testnet",
70
- // id: ChainId.MumbaiTestnet,
71
- // nativeCurrency: { name: "MATIC", symbol: "MATIC", decimals: 18n },
72
- // defaultRpcUrl: "https://rpc-mumbai.maticvigil.com",
73
- // explorerUrl: "https://mumbai.polygonscan.com",
74
- // isTestnet: true,
75
- // shortName: "Mumbai",
76
- // },
77
- // [ChainId.OptimismMainnet]: {
78
- // name: "Optimism Mainnet",
79
- // id: ChainId.OptimismMainnet,
80
- // baseCurrency: "ETH",
81
- // defaultRpcUrl: "https://mainnet.optimism.io",
82
- // explorerUrl: "https://optimistic.etherscan.io",
83
- // isTestnet: false,
84
- // },
85
- // [ChainId.BscMainnet]: {
86
- // name: "Binance Smart Chain Mainnet",
87
- // id: ChainId.BscMainnet,
88
- // baseCurrency: "BNB",
89
- // defaultRpcUrl: "https://bsc-dataseed.binance.org",
90
- // explorerUrl: "https://bscscan.com",
91
- // isTestnet: false,
92
- // },
93
- // [ChainId.ArbitrumMainnet]: {
94
- // name: "Arbitrum Mainnet",
95
- // id: ChainId.ArbitrumMainnet,
96
- // baseCurrency: "ETH",
97
- // defaultRpcUrl: "https://arb1.arbitrum.io/rpc",
98
- // explorerUrl: "https://arbiscan.io",
99
- // isTestnet: false,
100
- // },
101
- // [ChainId.ArbitrumTestnet]: {
102
- // name: "Arbitrum Testnet",
103
- // id: ChainId.ArbitrumTestnet,
104
- // baseCurrency: "ETH",
105
- // defaultRpcUrl: "https://rinkeby.arbitrum.io/rpc",
106
- // explorerUrl: "https://rinkeby-explorer.arbitrum.io",
107
- // isTestnet: true,
108
- // },
109
- // [ChainId.GnosisChain]: {
110
- // name: "Gnosis Chain",
111
- // id: ChainId.GnosisChain,
112
- // baseCurrency: "XDAI",
113
- // defaultRpcUrl: "https://rpc.xdaichain.com",
114
- // explorerUrl: "https://gnosis.blockscout.com",
115
- // isTestnet: false,
116
- // },
117
- // [ChainId.FantomMainnet]: {
118
- // name: "Fantom Mainnet",
119
- // id: ChainId.FantomMainnet,
120
- // baseCurrency: "FTM",
121
- // defaultRpcUrl: "https://rpcapi.fantom.network",
122
- // explorerUrl: "https://ftmscan.com",
123
- // isTestnet: false,
124
- // },
125
- // [ChainId.FantomTestnet]: {
126
- // name: "Fantom Testnet",
127
- // id: ChainId.FantomTestnet,
128
- // baseCurrency: "FTM",
129
- // defaultRpcUrl: "https://rpc.testnet.fantom.network",
130
- // explorerUrl: "https://explorer.testnet.fantom.network",
131
- // isTestnet: true,
132
- // },
133
- // [ChainId.HarmonyMainnet]: {
134
- // name: "Harmony Mainnet",
135
- // id: ChainId.HarmonyMainnet,
136
- // baseCurrency: "ONE",
137
- // defaultRpcUrl: "https://api.harmony.one",
138
- // explorerUrl: "https://explorer.harmony.one",
139
- // isTestnet: false,
140
- // },
141
- // [ChainId.HarmonyTestnet]: {
142
- // name: "Harmony Testnet",
143
- // id: ChainId.HarmonyTestnet,
144
- // baseCurrency: "ONE",
145
- // defaultRpcUrl: "https://api.s0.b.hmny.io",
146
- // explorerUrl: "https://explorer.testnet.harmony.one",
147
- // isTestnet: true,
148
- // },
149
- // [ChainId.BscTestnet]: {
150
- // name: "Binance Smart Chain Testnet",
151
- // id: ChainId.BscTestnet,
152
- // baseCurrency: "BNB",
153
- // defaultRpcUrl: "https://data-seed-prebsc-1-s1.binance.org:8545",
154
- // explorerUrl: "https://testnet.bscscan.com",
155
- // isTestnet: true,
156
- // },
157
- // [ChainId.OptimismTestnet]: {
158
- // name: "Optimism Testnet",
159
- // id: ChainId.OptimismTestnet,
160
- // baseCurrency: "ETH",
161
- // defaultRpcUrl: "https://kovan.optimism.io",
162
- // explorerUrl: "https://kovan-optimistic.etherscan.io",
163
- // isTestnet: true,
164
- // },
165
- // [ChainId.EthRopstenTestnet]: {
166
- // name: "Ethereum Ropsten Testnet",
167
- // id: ChainId.EthRopstenTestnet,
168
- // baseCurrency: "ETH",
169
- // defaultRpcUrl:
170
- // "https://ropsten.infura.io/V4/84842078b09946638c03157f83405213",
171
- // explorerUrl: "https://ropsten.etherscan.io",
172
- // isTestnet: true,
173
- // },
174
- // [ChainId.EthRinkebyTestnet]: {
175
- // name: "Ethereum Rinkeby Testnet",
176
- // id: ChainId.EthRinkebyTestnet,
177
- // baseCurrency: "ETH",
178
- // defaultRpcUrl:
179
- // "https://rinkeby.infura.io/V4/84842078b09946638c03157f83405213",
180
- // explorerUrl: "https://rinkeby.etherscan.io",
181
- // isTestnet: true,
182
- // },
183
- // [ChainId.EthKovanTestnet]: {
184
- // name: "Ethereum Kovan Testnet",
185
- // id: ChainId.EthKovanTestnet,
186
- // baseCurrency: "ETH",
187
- // defaultRpcUrl:
188
- // "https://kovan.infura.io/V4/84842078b09946638c03157f83405213",
189
- // explorerUrl: "https://kovan.etherscan.io",
190
- // isTestnet: true,
191
- // },
192
- // [ChainId.BaseGoerliTestnet]: {
193
- // name: "Base Goerli Testnet",
194
- // id: ChainId.BaseGoerliTestnet,
195
- // baseCurrency: "ETH",
196
- // defaultRpcUrl: "https://rpc-goerli.baseprotocol.org",
197
- // explorerUrl: "https://goerli.basescan.org",
198
- // isTestnet: true,
199
- // },
200
- // [ChainId.GnosisChainTestnet]: {
201
- // name: "Gnosis Chain Testnet",
202
- // id: ChainId.GnosisChainTestnet,
203
- // baseCurrency: "XDAI",
204
- // defaultRpcUrl: "https://rpc.chiado.gnosis.gateway.fm",
205
- // explorerUrl: "https://gnosis-chiado.blockscout.com/",
206
- // isTestnet: true,
207
- // },
208
- // [ChainId.AvalancheMainnet]: {
209
- // name: "Avalanche Mainnet",
210
- // id: ChainId.AvalancheMainnet,
211
- // baseCurrency: "AVAX",
212
- // defaultRpcUrl: "https://api.avax.network/ext/bc/C/rpc",
213
- // explorerUrl: "https://cchain.explorer.avax.network",
214
- // isTestnet: false,
215
- // },
216
- // [ChainId.AvalancheFujiTestnet]: {
217
- // name: "Avalanche Fuji Testnet",
218
- // id: ChainId.AvalancheFujiTestnet,
219
- // baseCurrency: "AVAX",
220
- // defaultRpcUrl: "https://api.avax-test.network/ext/bc/C/rpc",
221
- // explorerUrl: "https://cchain.explorer.avax-test.network",
222
- // isTestnet: true,
223
- // },
224
- // [ChainId.MoonbaseAlphaTestnet]: {
225
- // name: "Moonbase Alpha Testnet",
226
- // id: ChainId.MoonbaseAlphaTestnet,
227
- // baseCurrency: "DEV",
228
- // defaultRpcUrl: "https://rpc.testnet.moonbeam.network",
229
- // explorerUrl: "https://moonbase-blockscout.testnet.moonbeam.network",
230
- // isTestnet: true,
231
- // },
232
- };
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
4
- const chain_types_1 = require("./chain.types");
5
- const chain_utils_1 = require("./chain.utils");
6
- describe("Network", () => {
7
- it("Should have all data for all networks", () => {
8
- const chainIdLength = chain_utils_1.ChainUtils.getAllChainIds().length;
9
- const chainMetadataLength = (0, morpho_ts_1.keys)(chain_utils_1.ChainUtils.chainMetadata).length;
10
- expect(chainIdLength).toEqual(chainMetadataLength);
11
- });
12
- it("Should have consistent chainIds", () => {
13
- (0, morpho_ts_1.entries)(chain_utils_1.ChainUtils.chainMetadata).forEach(([chainId, { id }]) => {
14
- expect(+chainId).toEqual(id);
15
- });
16
- });
17
- it("Should have Testnet in the name for testnet chains", () => {
18
- Object.values(chain_utils_1.ChainUtils.chainMetadata)
19
- .filter(({ isTestnet }) => isTestnet)
20
- .forEach(({ name }) => {
21
- expect(name).toMatch(/Testnet/);
22
- });
23
- });
24
- it("Should convert correctly a chainId to hexChainId", () => {
25
- expect(chain_utils_1.ChainUtils.toHexChainId(chain_utils_1.ChainUtils.ChainId.EthGoerliTestnet)).toEqual("0x5");
26
- expect(chain_utils_1.ChainUtils.toHexChainId(chain_utils_1.ChainUtils.ChainId.BaseMainnet)).toEqual("0x2105");
27
- });
28
- it("Should return all testnets", () => {
29
- expect(chain_utils_1.ChainUtils.getTestnets()).toEqual((0, morpho_ts_1.values)(chain_utils_1.ChainUtils.chainMetadata)
30
- .filter(({ isTestnet }) => isTestnet)
31
- .map(({ id }) => id));
32
- });
33
- it("Should return all networks", () => {
34
- expect(chain_utils_1.ChainUtils.getAllChainIds()).toEqual((0, morpho_ts_1.values)(chain_utils_1.ChainUtils.chainMetadata).map(({ id }) => id));
35
- expect(chain_utils_1.ChainUtils.getAllChainLabels().map((label) => chain_types_1.ChainId[label])).toEqual(chain_utils_1.ChainUtils.getAllChainIds());
36
- });
37
- });
@@ -1,20 +0,0 @@
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
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChainId = void 0;
4
- var ChainId;
5
- (function (ChainId) {
6
- ChainId[ChainId["EthMainnet"] = 1] = "EthMainnet";
7
- ChainId[ChainId["EthGoerliTestnet"] = 5] = "EthGoerliTestnet";
8
- ChainId[ChainId["BaseMainnet"] = 8453] = "BaseMainnet";
9
- // PolygonMainnet = 137,
10
- // MumbaiTestnet = 80001,
11
- // OptimismMainnet = 10,
12
- // BscMainnet = 56,
13
- // ArbitrumMainnet = 42161,
14
- // ArbitrumTestnet = 421611,
15
- // GnosisChain = 100,
16
- // FantomMainnet = 250,
17
- // FantomTestnet = 4002,
18
- // HarmonyMainnet = 128,
19
- // HarmonyTestnet = 1666600000,
20
- // BscTestnet = 97,
21
- // OptimismTestnet = 69,
22
- // EthRopstenTestnet = 3,
23
- // EthRinkebyTestnet = 4,
24
- // EthKovanTestnet = 42,
25
- // GnosisChainTestnet = 10200,
26
- // AvalancheMainnet = 43114,
27
- // AvalancheFujiTestnet = 43113,
28
- // MoonbaseAlphaTestnet = 1287,
29
- // BaseGoerliTestnet = 84531,
30
- })(ChainId || (exports.ChainId = ChainId = {}));
@@ -1,14 +0,0 @@
1
- import { ChainId as _ChainId, ChainMetadata as _ChainMetadata } from "./chain.types";
2
- export declare namespace ChainUtils {
3
- const blueAvailableChains: ChainId[];
4
- const chainMetadata: Record<ChainId, _ChainMetadata>;
5
- interface ChainMetadata extends _ChainMetadata {
6
- }
7
- export import ChainId = _ChainId;
8
- const toHexChainId: (chainId: ChainId) => string;
9
- const getAllChainIds: () => ChainId[];
10
- const getAllChainLabels: () => ("EthMainnet" | "EthGoerliTestnet" | "BaseMainnet")[];
11
- const getTestnets: () => ChainId[];
12
- function isSupported(chainId: number): chainId is ChainId;
13
- function parseSupportedChainId(candidate: any): ChainId;
14
- }
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChainUtils = void 0;
4
- const morpho_ts_1 = require("@morpho-org/morpho-ts");
5
- const errors_1 = require("../errors");
6
- const chain_constants_1 = require("./chain.constants");
7
- const chain_types_1 = require("./chain.types");
8
- var ChainUtils;
9
- (function (ChainUtils) {
10
- ChainUtils.blueAvailableChains = chain_constants_1.BLUE_AVAILABLE_CHAINS;
11
- ChainUtils.chainMetadata = chain_constants_1.CHAIN_METADATA;
12
- ChainUtils.ChainId = chain_types_1.ChainId;
13
- ChainUtils.toHexChainId = (chainId) => {
14
- return `0x${chainId.toString(16)}`;
15
- };
16
- ChainUtils.getAllChainIds = () => (0, morpho_ts_1.values)(ChainUtils.ChainId).filter((value) => typeof value === "number");
17
- ChainUtils.getAllChainLabels = () => Object.values(ChainUtils.ChainId).filter((value) => typeof value === "string");
18
- ChainUtils.getTestnets = () => ChainUtils.getAllChainIds().filter((chainId) => chain_constants_1.CHAIN_METADATA[chainId].isTestnet);
19
- function isSupported(chainId) {
20
- return ChainUtils.blueAvailableChains.includes(chainId);
21
- }
22
- ChainUtils.isSupported = isSupported;
23
- function parseSupportedChainId(candidate) {
24
- const chainId = parseInt(candidate);
25
- if (!isSupported(chainId))
26
- throw new errors_1.UnsupportedChainIdError(candidate);
27
- return chainId;
28
- }
29
- ChainUtils.parseSupportedChainId = parseSupportedChainId;
30
- })(ChainUtils || (exports.ChainUtils = ChainUtils = {}));
@@ -1,2 +0,0 @@
1
- export * from "./chain.utils";
2
- export * from "./chain.types";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./chain.utils"), exports);
18
- __exportStar(require("./chain.types"), exports);
@@ -1 +0,0 @@
1
- export {};
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const safeParseUnits_1 = require("./safeParseUnits");
4
- describe("safeParseNumber", () => {
5
- it("should parse excessively small number", () => {
6
- expect((0, safeParseUnits_1.safeParseNumber)(0.000000000000000000000000000000042, 18)).toEqual(0n);
7
- });
8
- it("should parse excessively large number", () => {
9
- expect((0, safeParseUnits_1.safeParseNumber)(4200000000000000000000000000000000000, 18).toString()).toEqual(4200000000000000000000000000000000000000000000000000000n.toString());
10
- });
11
- });
@@ -1,2 +0,0 @@
1
- export * from "./safeGetAddress";
2
- export * from "./safeParseUnits";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./safeGetAddress"), exports);
18
- __exportStar(require("./safeParseUnits"), exports);
@@ -1 +0,0 @@
1
- export declare const safeGetAddress: (address: string) => string;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeGetAddress = void 0;
4
- const ethers_1 = require("ethers");
5
- const safeGetAddress = (address) => (0, ethers_1.getAddress)(address.toLowerCase());
6
- exports.safeGetAddress = safeGetAddress;
@@ -1,2 +0,0 @@
1
- export declare const safeParseUnits: (strValue: string, decimals?: number) => bigint;
2
- export declare function safeParseNumber(value: number, decimals?: number): bigint;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.safeParseNumber = exports.safeParseUnits = void 0;
4
- const ethers_1 = require("ethers");
5
- const safeParseUnits = (strValue, decimals = 18) => {
6
- if (!/[-+]?[0-9]*\.?[0-9]+/.test(strValue))
7
- throw new Error("invalid number: " + strValue);
8
- let [whole, dec = ""] = strValue.split(".");
9
- dec = dec.slice(0, decimals);
10
- return (0, ethers_1.parseUnits)([whole || "0", dec].filter((v) => v.length > 0).join("."), decimals);
11
- };
12
- exports.safeParseUnits = safeParseUnits;
13
- // Alternative to Number.toFixed that doesn't use scientific notation for excessively small or large numbers
14
- function toFixed(x, decimals) {
15
- return new Intl.NumberFormat("en-US", {
16
- style: "decimal",
17
- useGrouping: false,
18
- maximumFractionDigits: decimals,
19
- minimumFractionDigits: decimals,
20
- }).format(x);
21
- }
22
- function safeParseNumber(value, decimals = 18) {
23
- return (0, exports.safeParseUnits)(toFixed(value, decimals), decimals);
24
- }
25
- exports.safeParseNumber = safeParseNumber;
package/lib/evm.d.ts DELETED
@@ -1,36 +0,0 @@
1
- import { TransactionRequest, Signer } from "ethers";
2
- import { ChainId } from "./chain";
3
- import { NotificationProducer, NotificationTopic } from "./notifications";
4
- import { SignatureMessage } from "./signatures/types";
5
- export interface NotificationOptions<Topic extends NotificationTopic> {
6
- producer: NotificationProducer<Topic>;
7
- id: string;
8
- args: Record<PropertyKey, any>;
9
- }
10
- /**
11
- * Sends a transaction via the provided signer, optionnally waiting for the corresponding transaction receipt.
12
- * @param signer The signer to send the tx with.
13
- * @param tx The transaction request.
14
- * @param wait Whether to wait for the transaction receipt. Defaults to true.
15
- * @param notificationOptions The optional notification options. Warning: if `wait` is set to true, the provided topic will never complete.
16
- */
17
- export declare const sendTransactionWithProducer: (signer: Signer, req: TransactionRequest, defaultGasLimit?: bigint, confirms?: number, notificationOptions?: NotificationOptions<NotificationTopic.tx>) => Promise<void>;
18
- /**
19
- * Sends a transaction via the provided signer, optionnally waiting for the corresponding transaction receipt.
20
- * @param signer The signer to send the tx with.
21
- * @param tx The transaction request.
22
- * @param wait Whether to wait for the transaction receipt. Defaults to true.
23
- * @param topic The type of notifications to emit.
24
- * @param args The optional notification arguments.
25
- * @return The notification consumer which receives the transaction notifications.
26
- */
27
- export declare const sendTransaction: (signer: Signer, tx: TransactionRequest, defaultGasLimit?: bigint, confirms?: number, args?: Record<PropertyKey, any>) => import("./notifications").NotificationConsumer<NotificationTopic.tx>;
28
- export declare const signMessageWithProducer: (signer: Signer, message: SignatureMessage, notificationOptions?: NotificationOptions<NotificationTopic.signature>) => Promise<void>;
29
- /**
30
- * Sends a signature request to the provided signer.
31
- * @param signer The signer to send the approval with.
32
- * @param args The approval parameters.
33
- * @param encodeMessage The approval encoder to pass the approval parameters to get the approval transactions.
34
- * @return The notification consumer which receives the transaction notifications.
35
- */
36
- export declare const signMessage: <T extends object>(signer: Signer, args: T, encodeMessage: (args: T, chainId: ChainId) => SignatureMessage, chainId: ChainId) => import("./notifications").NotificationConsumer<NotificationTopic.signature>;