@toruslabs/ethereum-controllers 5.11.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ethereumControllers.cjs.js +80 -431
- package/dist/ethereumControllers.esm.js +30 -349
- package/dist/ethereumControllers.umd.min.js +1 -1
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +7 -2
- package/dist/lib.cjs/Account/AccountTrackerController.js +160 -0
- package/dist/lib.cjs/Block/PollingBlockTracker.js +85 -0
- package/dist/lib.cjs/Currency/CurrencyController.js +111 -0
- package/dist/lib.cjs/Gas/GasFeeController.js +214 -0
- package/dist/lib.cjs/Gas/gasUtil.js +148 -0
- package/dist/lib.cjs/Keyring/KeyringController.js +93 -0
- package/dist/lib.cjs/Message/AbstractMessageController.js +107 -0
- package/dist/lib.cjs/Message/AddChainController.js +78 -0
- package/dist/lib.cjs/Message/MessageController.js +77 -0
- package/dist/lib.cjs/Message/PersonalMessageController.js +77 -0
- package/dist/lib.cjs/Message/SwitchChainController.js +78 -0
- package/dist/lib.cjs/Message/TypedMessageController.js +81 -0
- package/dist/lib.cjs/Message/utils.js +112 -0
- package/dist/lib.cjs/Network/NetworkController.js +201 -0
- package/dist/lib.cjs/Network/cacheIdentifier.js +112 -0
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +302 -0
- package/dist/lib.cjs/Network/createJsonRpcClient.js +64 -0
- package/dist/lib.cjs/Nfts/NftHandler.js +180 -0
- package/dist/lib.cjs/Nfts/NftsController.js +213 -0
- package/dist/lib.cjs/Preferences/PreferencesController.js +476 -0
- package/dist/lib.cjs/Tokens/TokenHandler.js +51 -0
- package/dist/lib.cjs/Tokens/TokenRatesController.js +112 -0
- package/dist/lib.cjs/Tokens/TokensController.js +259 -0
- package/dist/lib.cjs/Transaction/NonceTracker.js +150 -0
- package/dist/lib.cjs/Transaction/PendingTransactionTracker.js +222 -0
- package/dist/lib.cjs/Transaction/TransactionController.js +515 -0
- package/dist/lib.cjs/Transaction/TransactionGasUtil.js +81 -0
- package/dist/lib.cjs/Transaction/TransactionStateHistoryHelper.js +42 -0
- package/dist/lib.cjs/Transaction/TransactionStateManager.js +296 -0
- package/dist/lib.cjs/Transaction/TransactionUtils.js +341 -0
- package/dist/lib.cjs/index.js +171 -0
- package/dist/lib.cjs/utils/abis.js +510 -0
- package/dist/lib.cjs/utils/constants.js +362 -0
- package/dist/lib.cjs/utils/contractAddresses.js +16 -0
- package/dist/lib.cjs/utils/conversionUtils.js +232 -0
- package/dist/lib.cjs/utils/helpers.js +244 -0
- package/dist/lib.cjs/utils/lodashUtils.js +25 -0
- package/dist/lib.esm/Account/AccountTrackerController.js +158 -0
- package/dist/lib.esm/Block/PollingBlockTracker.js +83 -0
- package/dist/lib.esm/Currency/CurrencyController.js +109 -0
- package/dist/lib.esm/Gas/GasFeeController.js +212 -0
- package/dist/lib.esm/Gas/gasUtil.js +141 -0
- package/dist/lib.esm/Keyring/KeyringController.js +91 -0
- package/dist/lib.esm/Message/AbstractMessageController.js +105 -0
- package/dist/lib.esm/Message/AddChainController.js +76 -0
- package/dist/lib.esm/Message/MessageController.js +75 -0
- package/dist/lib.esm/Message/PersonalMessageController.js +75 -0
- package/dist/lib.esm/Message/SwitchChainController.js +76 -0
- package/dist/lib.esm/Message/TypedMessageController.js +79 -0
- package/dist/lib.esm/Message/utils.js +105 -0
- package/dist/lib.esm/Network/NetworkController.js +199 -0
- package/dist/lib.esm/Network/cacheIdentifier.js +107 -0
- package/dist/lib.esm/Network/createEthereumMiddleware.js +289 -0
- package/dist/lib.esm/Network/createJsonRpcClient.js +60 -0
- package/dist/lib.esm/Nfts/NftHandler.js +178 -0
- package/dist/lib.esm/Nfts/NftsController.js +211 -0
- package/dist/lib.esm/Preferences/PreferencesController.js +474 -0
- package/dist/lib.esm/Tokens/TokenHandler.js +49 -0
- package/dist/lib.esm/Tokens/TokenRatesController.js +109 -0
- package/dist/lib.esm/Tokens/TokensController.js +257 -0
- package/dist/lib.esm/Transaction/NonceTracker.js +148 -0
- package/dist/lib.esm/Transaction/PendingTransactionTracker.js +220 -0
- package/dist/lib.esm/Transaction/TransactionController.js +513 -0
- package/dist/lib.esm/Transaction/TransactionGasUtil.js +79 -0
- package/dist/lib.esm/Transaction/TransactionStateHistoryHelper.js +38 -0
- package/dist/lib.esm/Transaction/TransactionStateManager.js +294 -0
- package/dist/lib.esm/Transaction/TransactionUtils.js +326 -0
- package/dist/lib.esm/index.js +33 -0
- package/dist/lib.esm/utils/abis.js +505 -0
- package/dist/lib.esm/utils/constants.js +323 -0
- package/dist/lib.esm/utils/contractAddresses.js +14 -0
- package/dist/lib.esm/utils/conversionUtils.js +218 -0
- package/dist/lib.esm/utils/helpers.js +227 -0
- package/dist/lib.esm/utils/lodashUtils.js +21 -0
- package/dist/types/Account/AccountTrackerController.d.ts +5 -5
- package/dist/types/Block/PollingBlockTracker.d.ts +1 -2
- package/dist/types/Currency/CurrencyController.d.ts +1 -1
- package/dist/types/Gas/GasFeeController.d.ts +3 -3
- package/dist/types/Gas/gasUtil.d.ts +1 -1
- package/dist/types/Keyring/KeyringController.d.ts +3 -5
- package/dist/types/Message/AbstractMessageController.d.ts +5 -6
- package/dist/types/Message/AddChainController.d.ts +4 -4
- package/dist/types/Message/MessageController.d.ts +4 -4
- package/dist/types/Message/PersonalMessageController.d.ts +4 -4
- package/dist/types/Message/SwitchChainController.d.ts +4 -4
- package/dist/types/Message/TypedMessageController.d.ts +6 -7
- package/dist/types/Message/utils.d.ts +2 -7
- package/dist/types/Network/NetworkController.d.ts +4 -4
- package/dist/types/Network/cacheIdentifier.d.ts +1 -1
- package/dist/types/Network/createEthereumMiddleware.d.ts +2 -18
- package/dist/types/Network/createJsonRpcClient.d.ts +2 -2
- package/dist/types/Nfts/NftsController.d.ts +2 -2
- package/dist/types/Preferences/PreferencesController.d.ts +4 -4
- package/dist/types/Tokens/TokensController.d.ts +3 -3
- package/dist/types/Transaction/NonceTracker.d.ts +5 -5
- package/dist/types/Transaction/PendingTransactionTracker.d.ts +5 -5
- package/dist/types/Transaction/TransactionController.d.ts +12 -12
- package/dist/types/Transaction/TransactionGasUtil.d.ts +4 -4
- package/dist/types/Transaction/TransactionStateManager.d.ts +3 -3
- package/dist/types/Transaction/TransactionUtils.d.ts +1 -1
- package/dist/types/index.d.ts +12 -14
- package/dist/types/utils/constants.d.ts +1 -5
- package/dist/types/utils/helpers.d.ts +4 -4
- package/dist/types/utils/interfaces.d.ts +43 -23
- package/package.json +7 -7
- package/dist/types/Message/DecryptMessageController.d.ts +0 -20
- package/dist/types/Message/EncryptionPublicKeyController.d.ts +0 -20
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { CHAIN_NAMESPACES } from '@toruslabs/base-controllers';
|
|
2
|
+
|
|
3
|
+
const LOCALHOST = "localhost";
|
|
4
|
+
const CONTRACT_TYPE_ETH = "eth";
|
|
5
|
+
const CONTRACT_TYPE_ERC20 = "erc20";
|
|
6
|
+
const CONTRACT_TYPE_ERC721 = "erc721";
|
|
7
|
+
const CONTRACT_TYPE_ERC1155 = "erc1155";
|
|
8
|
+
const ERC1155_INTERFACE_ID = "0xd9b67a26";
|
|
9
|
+
const ERC721_INTERFACE_ID = "0x80ac58cd";
|
|
10
|
+
const ERC721_METADATA_INTERFACE_ID = "0x5b5e139f";
|
|
11
|
+
const ERC721_ENUMERABLE_INTERFACE_ID = "0x780e9d63";
|
|
12
|
+
const MAINNET_CHAIN_ID = "0x1";
|
|
13
|
+
const POLYGON_CHAIN_ID = "0x89";
|
|
14
|
+
const BSC_MAINNET_CHAIN_ID = "0x38";
|
|
15
|
+
const AVALANCHE_MAINNET_CHAIN_ID = "0xa86a";
|
|
16
|
+
const XDAI_CHAIN_ID = "0x64";
|
|
17
|
+
const ARBITRUM_MAINNET_CHAIN_ID = "0xa4b1";
|
|
18
|
+
const OPTIMISM_MAINNET_CHAIN_ID = "0xa";
|
|
19
|
+
const CELO_MAINNET_CHAIN_ID = "0xa4ec";
|
|
20
|
+
const BASE_CHAIN_ID = "0x2105";
|
|
21
|
+
const SEPOLIA_CHAIN_ID = "0xaa36a7";
|
|
22
|
+
const POLYGON_AMOY_CHAIN_ID = "0x13882";
|
|
23
|
+
const BSC_TESTNET_CHAIN_ID = "0x61";
|
|
24
|
+
const AVALANCHE_TESTNET_CHAIN_ID = "0xa869";
|
|
25
|
+
const ARBITRUM_TESTNET_CHAIN_ID = "0x66eee";
|
|
26
|
+
const OPTIMISM_TESTNET_CHAIN_ID = "0xaa37dc";
|
|
27
|
+
const BASE_TESTNET_CHAIN_ID = "0x14a34";
|
|
28
|
+
const INFURA_KEY = process.env.VITE_APP_INFURA_PROJECT_KEY;
|
|
29
|
+
const SUPPORTED_NETWORKS = {
|
|
30
|
+
[MAINNET_CHAIN_ID]: {
|
|
31
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
32
|
+
decimals: 18,
|
|
33
|
+
blockExplorerUrl: "https://etherscan.io",
|
|
34
|
+
chainId: MAINNET_CHAIN_ID,
|
|
35
|
+
displayName: "Ethereum",
|
|
36
|
+
logo: "eth.svg",
|
|
37
|
+
rpcTarget: `https://mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
38
|
+
ticker: "ETH",
|
|
39
|
+
tickerName: "Ethereum"
|
|
40
|
+
},
|
|
41
|
+
[POLYGON_CHAIN_ID]: {
|
|
42
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
43
|
+
decimals: 18,
|
|
44
|
+
blockExplorerUrl: "https://polygonscan.com",
|
|
45
|
+
chainId: POLYGON_CHAIN_ID,
|
|
46
|
+
displayName: "Polygon",
|
|
47
|
+
logo: "polygon.svg",
|
|
48
|
+
rpcTarget: `https://polygon-mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
49
|
+
ticker: "MATIC",
|
|
50
|
+
tickerName: "Matic Network Token"
|
|
51
|
+
},
|
|
52
|
+
[BSC_MAINNET_CHAIN_ID]: {
|
|
53
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
54
|
+
decimals: 18,
|
|
55
|
+
blockExplorerUrl: "https://bscscan.com",
|
|
56
|
+
chainId: BSC_MAINNET_CHAIN_ID,
|
|
57
|
+
displayName: "Binance Smart Chain (BSC)",
|
|
58
|
+
logo: "bnb_logo.svg",
|
|
59
|
+
rpcTarget: `https://bsc-dataseed.binance.org`,
|
|
60
|
+
ticker: "BNB",
|
|
61
|
+
tickerName: "Binance Coin"
|
|
62
|
+
},
|
|
63
|
+
[AVALANCHE_MAINNET_CHAIN_ID]: {
|
|
64
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
65
|
+
decimals: 18,
|
|
66
|
+
blockExplorerUrl: "https://snowtrace.io",
|
|
67
|
+
chainId: AVALANCHE_MAINNET_CHAIN_ID,
|
|
68
|
+
displayName: "Avalanche",
|
|
69
|
+
logo: "avax.svg",
|
|
70
|
+
rpcTarget: `https://api.avax.network/ext/bc/C/rpc`,
|
|
71
|
+
ticker: "AVAX",
|
|
72
|
+
tickerName: "Avalanche"
|
|
73
|
+
},
|
|
74
|
+
[OPTIMISM_MAINNET_CHAIN_ID]: {
|
|
75
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
76
|
+
decimals: 18,
|
|
77
|
+
blockExplorerUrl: "https://optimistic.etherscan.io",
|
|
78
|
+
chainId: OPTIMISM_MAINNET_CHAIN_ID,
|
|
79
|
+
displayName: "Optimism",
|
|
80
|
+
logo: "optimism.svg",
|
|
81
|
+
rpcTarget: `https://optimism-mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
82
|
+
ticker: "ETH",
|
|
83
|
+
tickerName: "Ethereum"
|
|
84
|
+
},
|
|
85
|
+
[CELO_MAINNET_CHAIN_ID]: {
|
|
86
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
87
|
+
decimals: 18,
|
|
88
|
+
blockExplorerUrl: "https://explorer.celo.org",
|
|
89
|
+
chainId: CELO_MAINNET_CHAIN_ID,
|
|
90
|
+
displayName: "Celo Mainnet",
|
|
91
|
+
logo: "celo.svg",
|
|
92
|
+
rpcTarget: `https://celo-mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
93
|
+
ticker: "CELO",
|
|
94
|
+
tickerName: "Celo"
|
|
95
|
+
},
|
|
96
|
+
[ARBITRUM_MAINNET_CHAIN_ID]: {
|
|
97
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
98
|
+
decimals: 18,
|
|
99
|
+
blockExplorerUrl: "https://arbiscan.io",
|
|
100
|
+
chainId: ARBITRUM_MAINNET_CHAIN_ID,
|
|
101
|
+
displayName: "Arbitrum One",
|
|
102
|
+
logo: "arbitrum.svg",
|
|
103
|
+
rpcTarget: `https://arbitrum-mainnet.infura.io/v3/${INFURA_KEY}`,
|
|
104
|
+
ticker: "ETH",
|
|
105
|
+
tickerName: "Ethereum"
|
|
106
|
+
},
|
|
107
|
+
[XDAI_CHAIN_ID]: {
|
|
108
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
109
|
+
decimals: 18,
|
|
110
|
+
blockExplorerUrl: "https://gnosis.blockscout.com",
|
|
111
|
+
chainId: XDAI_CHAIN_ID,
|
|
112
|
+
displayName: "xDai",
|
|
113
|
+
logo: "xDai.svg",
|
|
114
|
+
rpcTarget: `https://rpc.gnosischain.com`,
|
|
115
|
+
ticker: "DAI",
|
|
116
|
+
tickerName: "xDai Token"
|
|
117
|
+
},
|
|
118
|
+
[BASE_CHAIN_ID]: {
|
|
119
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
120
|
+
decimals: 18,
|
|
121
|
+
blockExplorerUrl: "https://basescan.org",
|
|
122
|
+
chainId: BASE_CHAIN_ID,
|
|
123
|
+
displayName: "Base",
|
|
124
|
+
logo: "base.svg",
|
|
125
|
+
rpcTarget: `https://mainnet.base.org`,
|
|
126
|
+
ticker: "ETH",
|
|
127
|
+
tickerName: "Ethereum"
|
|
128
|
+
},
|
|
129
|
+
[SEPOLIA_CHAIN_ID]: {
|
|
130
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
131
|
+
decimals: 18,
|
|
132
|
+
blockExplorerUrl: "https://sepolia.etherscan.io",
|
|
133
|
+
chainId: SEPOLIA_CHAIN_ID,
|
|
134
|
+
displayName: "Sepolia Test Network",
|
|
135
|
+
logo: "eth.svg",
|
|
136
|
+
rpcTarget: `https://sepolia.infura.io/v3/${INFURA_KEY}`,
|
|
137
|
+
ticker: "ETH",
|
|
138
|
+
tickerName: "Ethereum",
|
|
139
|
+
isTestnet: true
|
|
140
|
+
},
|
|
141
|
+
[POLYGON_AMOY_CHAIN_ID]: {
|
|
142
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
143
|
+
decimals: 18,
|
|
144
|
+
blockExplorerUrl: "https://amoy.polygonscan.com",
|
|
145
|
+
chainId: POLYGON_AMOY_CHAIN_ID,
|
|
146
|
+
displayName: "Polygon Amoy",
|
|
147
|
+
logo: "polygon.svg",
|
|
148
|
+
rpcTarget: `https://polygon-amoy.infura.io/v3/${INFURA_KEY}`,
|
|
149
|
+
ticker: "MATIC",
|
|
150
|
+
tickerName: "Matic Network Token",
|
|
151
|
+
isTestnet: true
|
|
152
|
+
},
|
|
153
|
+
[BSC_TESTNET_CHAIN_ID]: {
|
|
154
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
155
|
+
decimals: 18,
|
|
156
|
+
blockExplorerUrl: "https://testnet.bscscan.com",
|
|
157
|
+
chainId: BSC_TESTNET_CHAIN_ID,
|
|
158
|
+
displayName: "Binance Smart Chain Testnet",
|
|
159
|
+
logo: "bnb_logo.svg",
|
|
160
|
+
rpcTarget: `https://data-seed-prebsc-1-s1.binance.org:8545`,
|
|
161
|
+
ticker: "BNB",
|
|
162
|
+
tickerName: "Binance Coin",
|
|
163
|
+
isTestnet: true
|
|
164
|
+
},
|
|
165
|
+
[AVALANCHE_TESTNET_CHAIN_ID]: {
|
|
166
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
167
|
+
decimals: 18,
|
|
168
|
+
blockExplorerUrl: "https://testnet.snowtrace.io",
|
|
169
|
+
chainId: AVALANCHE_TESTNET_CHAIN_ID,
|
|
170
|
+
displayName: "Avalanche Testnet C-Chain",
|
|
171
|
+
logo: "avax.svg",
|
|
172
|
+
rpcTarget: `https://api.avax-test.network/ext/bc/C/rpc`,
|
|
173
|
+
ticker: "AVAX",
|
|
174
|
+
tickerName: "Avalanche",
|
|
175
|
+
isTestnet: true
|
|
176
|
+
},
|
|
177
|
+
[ARBITRUM_TESTNET_CHAIN_ID]: {
|
|
178
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
179
|
+
decimals: 18,
|
|
180
|
+
blockExplorerUrl: "https://sepolia.arbiscan.io",
|
|
181
|
+
chainId: ARBITRUM_TESTNET_CHAIN_ID,
|
|
182
|
+
displayName: "Arbitrum Sepolia",
|
|
183
|
+
logo: "arbitrum.svg",
|
|
184
|
+
rpcTarget: `https://arbitrum-sepolia.infura.io/v3/${INFURA_KEY}`,
|
|
185
|
+
ticker: "ETH",
|
|
186
|
+
tickerName: "Ethereum",
|
|
187
|
+
isTestnet: true
|
|
188
|
+
},
|
|
189
|
+
[OPTIMISM_TESTNET_CHAIN_ID]: {
|
|
190
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
191
|
+
decimals: 18,
|
|
192
|
+
blockExplorerUrl: "https://sepolia-optimistic.etherscan.io",
|
|
193
|
+
chainId: OPTIMISM_TESTNET_CHAIN_ID,
|
|
194
|
+
displayName: "Optimism Sepolia",
|
|
195
|
+
logo: "optimism.svg",
|
|
196
|
+
rpcTarget: `https://optimism-sepolia.infura.io/v3/${INFURA_KEY}`,
|
|
197
|
+
ticker: "ETH",
|
|
198
|
+
tickerName: "Ethereum",
|
|
199
|
+
isTestnet: true
|
|
200
|
+
},
|
|
201
|
+
[BASE_TESTNET_CHAIN_ID]: {
|
|
202
|
+
chainNamespace: CHAIN_NAMESPACES.EIP155,
|
|
203
|
+
decimals: 18,
|
|
204
|
+
blockExplorerUrl: "https://sepolia.basescan.org",
|
|
205
|
+
chainId: BASE_TESTNET_CHAIN_ID,
|
|
206
|
+
displayName: "Base Sepolia",
|
|
207
|
+
logo: "base.svg",
|
|
208
|
+
rpcTarget: `https://sepolia.base.org`,
|
|
209
|
+
ticker: "ETH",
|
|
210
|
+
tickerName: "Ethereum",
|
|
211
|
+
isTestnet: true
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
const METHOD_TYPES = {
|
|
215
|
+
GET_ACCOUNTS: "eth_accounts",
|
|
216
|
+
ETH_TRANSACTION: "eth_sendTransaction",
|
|
217
|
+
ETH_REQUEST_ACCOUNTS: "eth_requestAccounts",
|
|
218
|
+
ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction",
|
|
219
|
+
ETH_SIGN: "eth_sign",
|
|
220
|
+
ETH_SIGN_TYPED_DATA_V4: "eth_signTypedData_v4",
|
|
221
|
+
PERSONAL_SIGN: "personal_sign",
|
|
222
|
+
ETH_GET_TRANSACTION_COUNT: "eth_getTransactionCount",
|
|
223
|
+
ETH_GET_TRANSACTION_BY_HASH: "eth_getTransactionByHash",
|
|
224
|
+
ETH_GET_TRANSACTION_RECEIPT: "eth_getTransactionReceipt",
|
|
225
|
+
WATCH_ASSET: "wallet_watchAsset",
|
|
226
|
+
ETH_GET_BLOCK_BY_HASH: "eth_getBlockByHash",
|
|
227
|
+
ETH_GET_CODE: "eth_getCode",
|
|
228
|
+
ETH_GET_GAS_PRICE: "eth_gasPrice",
|
|
229
|
+
SWITCH_CHAIN: "wallet_switchEthereumChain",
|
|
230
|
+
ADD_CHAIN: "wallet_addEthereumChain"
|
|
231
|
+
};
|
|
232
|
+
const TRANSACTION_ENVELOPE_TYPES = {
|
|
233
|
+
LEGACY: "0x0",
|
|
234
|
+
ACCESS_LIST: "0x1",
|
|
235
|
+
FEE_MARKET: "0x2"
|
|
236
|
+
};
|
|
237
|
+
const GAS_ESTIMATE_TYPES = {
|
|
238
|
+
// Fee Market describes the way gas is set after the london hardfork, and was
|
|
239
|
+
// defined by EIP-1559.
|
|
240
|
+
FEE_MARKET: "fee-market",
|
|
241
|
+
// Legacy describes gasPrice estimates from before london hardfork, when the
|
|
242
|
+
// user is connected to mainnet and are presented with fast/average/slow
|
|
243
|
+
// estimate levels to choose from.
|
|
244
|
+
LEGACY: "legacy",
|
|
245
|
+
// EthGasPrice describes a gasPrice estimate received from eth_gasPrice. Post
|
|
246
|
+
// london this value should only be used for legacy type transactions when on
|
|
247
|
+
// networks that support EIP-1559. This type of estimate is the most accurate
|
|
248
|
+
// to display on custom networks that don't support EIP-1559.
|
|
249
|
+
ETH_GASPRICE: "eth_gasPrice",
|
|
250
|
+
// NoEstimate describes the state of the controller before receiving its first
|
|
251
|
+
// estimate.
|
|
252
|
+
NONE: "none"
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// https://help.optimism.io/hc/en-us/articles/4411895794715-Transaction-fees
|
|
256
|
+
const CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP = {
|
|
257
|
+
[OPTIMISM_MAINNET_CHAIN_ID]: 1,
|
|
258
|
+
[OPTIMISM_TESTNET_CHAIN_ID]: 1
|
|
259
|
+
};
|
|
260
|
+
const OLD_ERC721_LIST = {
|
|
261
|
+
"0x06012c8cf97bead5deae237070f9587f8e7a266d": {
|
|
262
|
+
name: "Cryptokitties",
|
|
263
|
+
logo: "dapp-cryptokitty.svg",
|
|
264
|
+
erc20: true,
|
|
265
|
+
symbol: "CK",
|
|
266
|
+
decimals: 0
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
const TEST_CHAINS = [SEPOLIA_CHAIN_ID];
|
|
270
|
+
const ETHERSCAN_SUPPORTED_CHAINS = [MAINNET_CHAIN_ID, SEPOLIA_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, POLYGON_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, CELO_MAINNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID];
|
|
271
|
+
const SIMPLEHASH_SUPPORTED_CHAINS = [MAINNET_CHAIN_ID, POLYGON_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, CELO_MAINNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, SEPOLIA_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID];
|
|
272
|
+
const COINGECKO_SUPPORTED_CURRENCIES = new Set(["btc", "eth", "ltc", "bch", "bnb", "eos", "xrp", "xlm", "link", "dot", "yfi", "usd", "aed", "ars", "aud", "bdt", "bhd", "bmd", "brl", "cad", "chf", "clp", "cny", "czk", "dkk", "eur", "gbp", "hkd", "huf", "idr", "ils", "inr", "jpy", "krw", "kwd", "lkr", "mmk", "mxn", "myr", "ngn", "nok", "nzd", "php", "pkr", "pln", "rub", "sar", "sek", "sgd", "thb", "try", "twd", "uah", "vef", "vnd", "zar", "xdr", "xag", "xau", "bits", "sats"]);
|
|
273
|
+
const COINGECKO_PLATFORMS_CHAIN_CODE_MAP = {
|
|
274
|
+
[POLYGON_CHAIN_ID]: {
|
|
275
|
+
platform: "polygon-pos",
|
|
276
|
+
currency: "matic"
|
|
277
|
+
},
|
|
278
|
+
[BSC_MAINNET_CHAIN_ID]: {
|
|
279
|
+
platform: "binance-smart-chain",
|
|
280
|
+
currency: "bnb"
|
|
281
|
+
},
|
|
282
|
+
[MAINNET_CHAIN_ID]: {
|
|
283
|
+
platform: "ethereum",
|
|
284
|
+
currency: "eth"
|
|
285
|
+
},
|
|
286
|
+
[ARBITRUM_MAINNET_CHAIN_ID]: {
|
|
287
|
+
platform: "arbitrum-one",
|
|
288
|
+
currency: "eth"
|
|
289
|
+
},
|
|
290
|
+
[OPTIMISM_MAINNET_CHAIN_ID]: {
|
|
291
|
+
platform: "optimistic-ethereum",
|
|
292
|
+
currency: "eth"
|
|
293
|
+
},
|
|
294
|
+
[CELO_MAINNET_CHAIN_ID]: {
|
|
295
|
+
platform: "celo",
|
|
296
|
+
currency: "celo"
|
|
297
|
+
},
|
|
298
|
+
[XDAI_CHAIN_ID]: {
|
|
299
|
+
platform: "xdai",
|
|
300
|
+
currency: "xDAI"
|
|
301
|
+
},
|
|
302
|
+
[AVALANCHE_MAINNET_CHAIN_ID]: {
|
|
303
|
+
platform: "avalanche",
|
|
304
|
+
currency: "avax"
|
|
305
|
+
},
|
|
306
|
+
[BASE_CHAIN_ID]: {
|
|
307
|
+
platform: "base",
|
|
308
|
+
currency: "eth"
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
const MessageStatus = {
|
|
312
|
+
UNAPPROVED: "unapproved",
|
|
313
|
+
SIGNED: "signed",
|
|
314
|
+
PENDING: "pending",
|
|
315
|
+
APPROVED: "approved",
|
|
316
|
+
REJECTED: "rejected",
|
|
317
|
+
FAILED: "failed"
|
|
318
|
+
};
|
|
319
|
+
const MESSAGE_EVENTS = {
|
|
320
|
+
UNAPPROVED_MESSAGE: "unapprovedMessage"
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ETHERSCAN_SUPPORTED_CHAINS, GAS_ESTIMATE_TYPES, LOCALHOST, MAINNET_CHAIN_ID, MESSAGE_EVENTS, METHOD_TYPES, MessageStatus, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SIMPLEHASH_SUPPORTED_CHAINS, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MAINNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, OPTIMISM_MAINNET_CHAIN_ID, POLYGON_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, ARBITRUM_MAINNET_CHAIN_ID } from './constants.js';
|
|
2
|
+
|
|
3
|
+
const SINGLE_CALL_BALANCES_ADDRESSES = {
|
|
4
|
+
[MAINNET_CHAIN_ID]: "0xb1f8e55c7f64d203c1400b9d8555d050f94adf39",
|
|
5
|
+
// [SEPOLIA_CHAIN_ID]: SINGLE_CALL_BALANCES_ADDRESS_SEPOLIA,
|
|
6
|
+
// [FANTOM_CHAIN_ID]: "0x07f697424ABe762bB808c109860c04eA488ff92B",
|
|
7
|
+
[BSC_MAINNET_CHAIN_ID]: "0x2352c63A83f9Fd126af8676146721Fa00924d7e4",
|
|
8
|
+
[OPTIMISM_MAINNET_CHAIN_ID]: "0xB1c568e9C3E6bdaf755A60c7418C269eb11524FC",
|
|
9
|
+
[POLYGON_CHAIN_ID]: "0x2352c63A83f9Fd126af8676146721Fa00924d7e4",
|
|
10
|
+
[AVALANCHE_MAINNET_CHAIN_ID]: "0xD023D153a0DFa485130ECFdE2FAA7e612EF94818",
|
|
11
|
+
[ARBITRUM_MAINNET_CHAIN_ID]: "0x151E24A486D7258dd7C33Fb67E4bB01919B7B32c"
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export { SINGLE_CALL_BALANCES_ADDRESSES };
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
|
|
2
|
+
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
3
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
|
+
import { stripHexPrefix } from '@ethereumjs/util';
|
|
5
|
+
import BigNumber from 'bignumber.js';
|
|
6
|
+
import BN from 'bn.js';
|
|
7
|
+
|
|
8
|
+
const _excluded = ["aBase", "bBase"],
|
|
9
|
+
_excluded2 = ["aBase", "bBase"],
|
|
10
|
+
_excluded3 = ["multiplicandBase", "multiplierBase"];
|
|
11
|
+
|
|
12
|
+
// Big Number Constants
|
|
13
|
+
const BIG_NUMBER_WEI_MULTIPLIER = new BigNumber("1000000000000000000");
|
|
14
|
+
const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber("1000000000");
|
|
15
|
+
const BIG_NUMBER_ETH_MULTIPLIER = new BigNumber("1");
|
|
16
|
+
// Setter Maps
|
|
17
|
+
const toBigNumber = {
|
|
18
|
+
hex: n => new BigNumber(stripHexPrefix(n), 16),
|
|
19
|
+
dec: n => new BigNumber(String(n), 10),
|
|
20
|
+
BN: n => new BigNumber(n.toString(16), 16)
|
|
21
|
+
};
|
|
22
|
+
const toNormalizedDenomination = {
|
|
23
|
+
WEI: bigNumber => bigNumber.div(BIG_NUMBER_WEI_MULTIPLIER),
|
|
24
|
+
GWEI: bigNumber => bigNumber.div(BIG_NUMBER_GWEI_MULTIPLIER),
|
|
25
|
+
ETH: bigNumber => bigNumber.div(BIG_NUMBER_ETH_MULTIPLIER)
|
|
26
|
+
};
|
|
27
|
+
const toSpecifiedDenomination = {
|
|
28
|
+
WEI: bigNumber => bigNumber.times(BIG_NUMBER_WEI_MULTIPLIER).dp(0, BigNumber.ROUND_HALF_UP),
|
|
29
|
+
GWEI: bigNumber => bigNumber.times(BIG_NUMBER_GWEI_MULTIPLIER).dp(9, BigNumber.ROUND_HALF_UP),
|
|
30
|
+
ETH: bigNumber => bigNumber.times(BIG_NUMBER_ETH_MULTIPLIER).dp(9, BigNumber.ROUND_HALF_UP)
|
|
31
|
+
};
|
|
32
|
+
const baseChange = {
|
|
33
|
+
hex: n => n.toString(16),
|
|
34
|
+
dec: n => new BigNumber(n).toString(10),
|
|
35
|
+
BN: n => new BN(n.toString(16))
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// Utility function for checking base types
|
|
39
|
+
const isValidBase = base => Number.isInteger(base) && base > 1;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Utility method to convert a value between denominations, formats and currencies.
|
|
43
|
+
*/
|
|
44
|
+
const converter = ({
|
|
45
|
+
value,
|
|
46
|
+
fromNumericBase,
|
|
47
|
+
fromDenomination,
|
|
48
|
+
fromCurrency,
|
|
49
|
+
toNumericBase,
|
|
50
|
+
toDenomination,
|
|
51
|
+
toCurrency,
|
|
52
|
+
numberOfDecimals,
|
|
53
|
+
conversionRate,
|
|
54
|
+
invertConversionRate,
|
|
55
|
+
roundDown
|
|
56
|
+
}) => {
|
|
57
|
+
let convertedValue = fromNumericBase ? toBigNumber[fromNumericBase](value) : value;
|
|
58
|
+
if (fromDenomination) {
|
|
59
|
+
convertedValue = toNormalizedDenomination[fromDenomination](convertedValue);
|
|
60
|
+
}
|
|
61
|
+
if (fromCurrency !== toCurrency) {
|
|
62
|
+
if (conversionRate === null || conversionRate === undefined) {
|
|
63
|
+
throw new Error(`Converting from ${fromCurrency} to ${toCurrency} requires a conversionRate, but one was not provided`);
|
|
64
|
+
}
|
|
65
|
+
let rate = toBigNumber.dec(conversionRate);
|
|
66
|
+
if (invertConversionRate) {
|
|
67
|
+
rate = new BigNumber(1).div(conversionRate);
|
|
68
|
+
}
|
|
69
|
+
convertedValue = convertedValue.times(rate);
|
|
70
|
+
}
|
|
71
|
+
if (toDenomination) {
|
|
72
|
+
convertedValue = toSpecifiedDenomination[toDenomination](convertedValue);
|
|
73
|
+
}
|
|
74
|
+
if (numberOfDecimals) {
|
|
75
|
+
convertedValue = convertedValue.dp(numberOfDecimals, BigNumber.ROUND_HALF_DOWN);
|
|
76
|
+
}
|
|
77
|
+
if (roundDown) {
|
|
78
|
+
convertedValue = convertedValue.dp(roundDown, BigNumber.ROUND_DOWN);
|
|
79
|
+
}
|
|
80
|
+
if (toNumericBase) {
|
|
81
|
+
convertedValue = baseChange[toNumericBase](convertedValue);
|
|
82
|
+
}
|
|
83
|
+
return convertedValue;
|
|
84
|
+
};
|
|
85
|
+
const conversionUtil = (value, {
|
|
86
|
+
fromCurrency = null,
|
|
87
|
+
toCurrency = fromCurrency,
|
|
88
|
+
fromNumericBase,
|
|
89
|
+
toNumericBase,
|
|
90
|
+
fromDenomination,
|
|
91
|
+
toDenomination,
|
|
92
|
+
numberOfDecimals,
|
|
93
|
+
conversionRate,
|
|
94
|
+
invertConversionRate
|
|
95
|
+
}) => {
|
|
96
|
+
if (fromCurrency !== toCurrency && !conversionRate) {
|
|
97
|
+
return 0;
|
|
98
|
+
}
|
|
99
|
+
return converter({
|
|
100
|
+
fromCurrency,
|
|
101
|
+
toCurrency,
|
|
102
|
+
fromNumericBase,
|
|
103
|
+
toNumericBase,
|
|
104
|
+
fromDenomination,
|
|
105
|
+
toDenomination,
|
|
106
|
+
numberOfDecimals,
|
|
107
|
+
conversionRate,
|
|
108
|
+
invertConversionRate,
|
|
109
|
+
value
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
const getBigNumber = (value, base) => {
|
|
113
|
+
if (!isValidBase(base)) {
|
|
114
|
+
throw new Error("Must specificy valid base");
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// We don't include 'number' here, because BigNumber will throw if passed
|
|
118
|
+
// a number primitive it considers unsafe.
|
|
119
|
+
if (typeof value === "string" || value instanceof BigNumber) {
|
|
120
|
+
return new BigNumber(value, base);
|
|
121
|
+
}
|
|
122
|
+
return new BigNumber(String(value), base);
|
|
123
|
+
};
|
|
124
|
+
const addCurrencies = (a, b, options = {}) => {
|
|
125
|
+
const {
|
|
126
|
+
aBase,
|
|
127
|
+
bBase
|
|
128
|
+
} = options,
|
|
129
|
+
conversionOptions = _objectWithoutProperties(options, _excluded);
|
|
130
|
+
if (!isValidBase(aBase) || !isValidBase(bBase)) {
|
|
131
|
+
throw new Error("Must specify valid aBase and bBase");
|
|
132
|
+
}
|
|
133
|
+
const value = getBigNumber(a, aBase).plus(getBigNumber(b, bBase));
|
|
134
|
+
return converter(_objectSpread({
|
|
135
|
+
value
|
|
136
|
+
}, conversionOptions));
|
|
137
|
+
};
|
|
138
|
+
const subtractCurrencies = (a, b, options = {}) => {
|
|
139
|
+
const {
|
|
140
|
+
aBase,
|
|
141
|
+
bBase
|
|
142
|
+
} = options,
|
|
143
|
+
conversionOptions = _objectWithoutProperties(options, _excluded2);
|
|
144
|
+
if (!isValidBase(aBase) || !isValidBase(bBase)) {
|
|
145
|
+
throw new Error("Must specify valid aBase and bBase");
|
|
146
|
+
}
|
|
147
|
+
const value = getBigNumber(a, aBase).minus(getBigNumber(b, bBase));
|
|
148
|
+
return converter(_objectSpread({
|
|
149
|
+
value
|
|
150
|
+
}, conversionOptions));
|
|
151
|
+
};
|
|
152
|
+
const multiplyCurrencies = (a, b, options = {}) => {
|
|
153
|
+
const {
|
|
154
|
+
multiplicandBase,
|
|
155
|
+
multiplierBase
|
|
156
|
+
} = options,
|
|
157
|
+
conversionOptions = _objectWithoutProperties(options, _excluded3);
|
|
158
|
+
if (!isValidBase(multiplicandBase) || !isValidBase(multiplierBase)) {
|
|
159
|
+
throw new Error("Must specify valid multiplicandBase and multiplierBase");
|
|
160
|
+
}
|
|
161
|
+
const value = getBigNumber(a, multiplicandBase).times(getBigNumber(b, multiplierBase));
|
|
162
|
+
return converter(_objectSpread({
|
|
163
|
+
value
|
|
164
|
+
}, conversionOptions));
|
|
165
|
+
};
|
|
166
|
+
const conversionGreaterThan = (_ref, _ref2) => {
|
|
167
|
+
let secondProps = Object.assign({}, (_objectDestructuringEmpty(_ref2), _ref2));
|
|
168
|
+
let firstProps = Object.assign({}, (_objectDestructuringEmpty(_ref), _ref));
|
|
169
|
+
const firstValue = converter(_objectSpread({}, firstProps));
|
|
170
|
+
const secondValue = converter(_objectSpread({}, secondProps));
|
|
171
|
+
return firstValue.gt(secondValue);
|
|
172
|
+
};
|
|
173
|
+
const conversionLessThan = (_ref3, _ref4) => {
|
|
174
|
+
let secondProps = Object.assign({}, (_objectDestructuringEmpty(_ref4), _ref4));
|
|
175
|
+
let firstProps = Object.assign({}, (_objectDestructuringEmpty(_ref3), _ref3));
|
|
176
|
+
const firstValue = converter(_objectSpread({}, firstProps));
|
|
177
|
+
const secondValue = converter(_objectSpread({}, secondProps));
|
|
178
|
+
return firstValue.lt(secondValue);
|
|
179
|
+
};
|
|
180
|
+
const conversionMax = (_ref5, _ref6) => {
|
|
181
|
+
let secondProps = Object.assign({}, (_objectDestructuringEmpty(_ref6), _ref6));
|
|
182
|
+
let firstProps = Object.assign({}, (_objectDestructuringEmpty(_ref5), _ref5));
|
|
183
|
+
const firstIsGreater = conversionGreaterThan(_objectSpread({}, firstProps), _objectSpread({}, secondProps));
|
|
184
|
+
return firstIsGreater ? firstProps.value : secondProps.value;
|
|
185
|
+
};
|
|
186
|
+
const conversionGTE = (_ref7, _ref8) => {
|
|
187
|
+
let secondProps = Object.assign({}, (_objectDestructuringEmpty(_ref8), _ref8));
|
|
188
|
+
let firstProps = Object.assign({}, (_objectDestructuringEmpty(_ref7), _ref7));
|
|
189
|
+
const firstValue = converter(_objectSpread({}, firstProps));
|
|
190
|
+
const secondValue = converter(_objectSpread({}, secondProps));
|
|
191
|
+
return firstValue.isGreaterThanOrEqualTo(secondValue);
|
|
192
|
+
};
|
|
193
|
+
const conversionLTE = (_ref9, _ref10) => {
|
|
194
|
+
let secondProps = Object.assign({}, (_objectDestructuringEmpty(_ref10), _ref10));
|
|
195
|
+
let firstProps = Object.assign({}, (_objectDestructuringEmpty(_ref9), _ref9));
|
|
196
|
+
const firstValue = converter(_objectSpread({}, firstProps));
|
|
197
|
+
const secondValue = converter(_objectSpread({}, secondProps));
|
|
198
|
+
return firstValue.isLessThanOrEqualTo(secondValue);
|
|
199
|
+
};
|
|
200
|
+
const toNegative = (n, options = {}) => multiplyCurrencies(n, -1, options);
|
|
201
|
+
const decGWEIToHexWEI = decGWEI => {
|
|
202
|
+
return conversionUtil(decGWEI, {
|
|
203
|
+
fromNumericBase: "dec",
|
|
204
|
+
toNumericBase: "hex",
|
|
205
|
+
fromDenomination: "GWEI",
|
|
206
|
+
toDenomination: "WEI"
|
|
207
|
+
});
|
|
208
|
+
};
|
|
209
|
+
const hexWEIToDecGWEI = decGWEI => {
|
|
210
|
+
return conversionUtil(decGWEI, {
|
|
211
|
+
fromNumericBase: "hex",
|
|
212
|
+
toNumericBase: "dec",
|
|
213
|
+
fromDenomination: "WEI",
|
|
214
|
+
toDenomination: "GWEI"
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
export { addCurrencies, conversionGTE, conversionGreaterThan, conversionLTE, conversionLessThan, conversionMax, conversionUtil, decGWEIToHexWEI, getBigNumber, hexWEIToDecGWEI, multiplyCurrencies, subtractCurrencies, toNegative };
|