@exodus/web3-ethereum 7.0.0 → 8.1.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.
@@ -1,3 +1,3 @@
1
1
  import type { CreateEvmDepsFactoryParams, EVMFactory } from '../types.js';
2
- declare const createEvmDepsFactory: ({ analytics, blockchainMetadata, simulateTransactionConfig, }: CreateEvmDepsFactoryParams) => EVMFactory;
2
+ declare const createEvmDepsFactory: ({ analytics, blockchainMetadata, }: CreateEvmDepsFactoryParams) => EVMFactory;
3
3
  export default createEvmDepsFactory;
@@ -1,8 +1,7 @@
1
1
  import { fetchGasLimit, getNonce as apiGetNonce, getServer, } from '@exodus/ethereum-api';
2
- import { createSimulationService } from '@exodus/web3-ethereum-utils';
3
2
  import BN from 'bn.js';
4
- const createEvmDepsFactory = ({ analytics, blockchainMetadata, simulateTransactionConfig = {}, }) => {
5
- return ({ assetName, origin, getAsset, getAddress: _getAddress, getPrivateKey: _getPrivateKey, getFeeData: getFeeConfig, getActiveWalletAccount, }) => {
3
+ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
4
+ return ({ assetName, origin, getAsset, getAddress: _getAddress, getPrivateKey: _getPrivateKey, getFeeData: getFeeConfig, getActiveWalletAccount, simulateTransactions, }) => {
6
5
  const asset = getAsset(assetName);
7
6
  const server = getServer(asset);
8
7
  const forwardRequest = async ({ method, params }) => {
@@ -78,8 +77,6 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, simulateTransacti
78
77
  });
79
78
  return true;
80
79
  };
81
- const getOrigin = () => origin;
82
- const simulationFunctions = createSimulationService(simulateTransactionConfig);
83
80
  return {
84
81
  chainId: 'undefined',
85
82
  forwardRequest,
@@ -90,8 +87,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, simulateTransacti
90
87
  getFeeData,
91
88
  getEstimatedGas,
92
89
  onEthWalletWatchAssetRequest: trackWalletWatchAssetUse,
93
- getOrigin,
94
- ...simulationFunctions,
90
+ simulateTransactions,
95
91
  };
96
92
  };
97
93
  };
@@ -1,5 +1,6 @@
1
1
  import { AssetNotSupportedError, InvalidInputError, UnauthorizedError, UserRejectedRequestError, } from '@exodus/web3-errors';
2
2
  import { getTransactionId, signMessage, signTransaction, signTypedData, } from '@exodus/web3-ethereum-utils';
3
+ import { connect } from '@exodus/web3-rpc-handlers';
3
4
  import { hexToBN } from '@exodus/web3-utils';
4
5
  import { SignTypedDataVersion } from '@metamask/eth-sig-util';
5
6
  import { parseAndValidateTypedData } from './parseAndValidateTypedData.js';
@@ -61,7 +62,7 @@ const isValidGasLimitValue = (value) => {
61
62
  return proposedGasLimit.lte(maximumBlockGasLimit);
62
63
  };
63
64
  export function exposeHandlers(rpc, deps) {
64
- const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getFeeData, getNonce, sendRawTransaction, simulateTransaction, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = () => true, getAsset, getOrigin, } = deps;
65
+ const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getFeeData, getNonce, sendRawTransaction, simulateTransactions, scanDomains, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = async () => true, getAsset, getOrigin, } = deps;
65
66
  const network = `evm:${chainId}`;
66
67
  async function assertTrusted() {
67
68
  const trusted = await isTrusted();
@@ -123,9 +124,9 @@ export function exposeHandlers(rpc, deps) {
123
124
  const preparedTransaction = await prepareTransaction(transaction);
124
125
  validateTransaction(preparedTransaction);
125
126
  const origin = getOrigin();
126
- const simulatedChanges = await simulateTransaction({
127
+ const simulatedChanges = await simulateTransactions({
127
128
  asset,
128
- transaction: preparedTransaction,
129
+ transactions: [preparedTransaction],
129
130
  origin,
130
131
  });
131
132
  await approve(approveTransactions, network, simulatedChanges);
@@ -211,18 +212,14 @@ export function exposeHandlers(rpc, deps) {
211
212
  // See: https://docs.metamask.io/guide/rpc-api.html#restricted-methods.
212
213
  throw new InvalidInputError();
213
214
  }
214
- const unlocked = await ensureUnlocked();
215
- if (!unlocked) {
216
- throw new UserRejectedRequestError();
217
- }
218
- const trusted = await isTrusted();
219
- if (!trusted) {
220
- const approved = await approveConnection(network);
221
- if (!approved) {
222
- throw new UserRejectedRequestError();
223
- }
224
- await ensureTrusted(network);
225
- }
215
+ await connect({
216
+ approveConnection,
217
+ ensureTrusted,
218
+ isTrusted,
219
+ ensureUnlocked,
220
+ getOrigin,
221
+ scanDomains,
222
+ }, network);
226
223
  return [{ parentCapability: ETH_ACCOUNTS_PERMISSION }];
227
224
  });
228
225
  exposeEvmFunction('wallet_watchAsset', async (assetDetails) => {
@@ -13,9 +13,7 @@ const validateEVMDeps = (evm) => {
13
13
  'getFeeData',
14
14
  'getNonce',
15
15
  'sendRawTransaction',
16
- 'simulateTransaction',
17
- 'scanDomains',
18
- 'getOrigin',
16
+ 'simulateTransactions',
19
17
  ];
20
18
  const optionalKeys = ['onEthWalletWatchAssetRequest'];
21
19
  validateDeps(evm, requiredKeys, optionalKeys);
package/lib/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
2
  import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams, EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
3
3
  import type { CommonDeps } from '@exodus/web3-rpc-handlers';
4
- import type { Asset, IAnalyticsModule, IBlockchainMetadataModule, EthereumFeeData, GetFeeDataParams, CreateSimulationServiceParams, ScanDomainsFn } from '@exodus/web3-types';
4
+ import type { Asset, IAnalyticsModule, IBlockchainMetadataModule, EthereumFeeData, GetFeeDataParams, CreateSimulationServiceParams } from '@exodus/web3-types';
5
5
  /**
6
6
  * EVM-compatible chains.
7
7
  */
@@ -19,6 +19,7 @@ export interface CreateEvmDepsFactoryParams {
19
19
  blockchainMetadata: IBlockchainMetadataModule;
20
20
  simulateTransactionConfig?: CreateSimulationServiceParams;
21
21
  }
22
+ declare type SimulateTransactionsFn = (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
22
23
  export interface CreateEvmDepsParams {
23
24
  assetName: string;
24
25
  origin: string;
@@ -29,6 +30,7 @@ export interface CreateEvmDepsParams {
29
30
  getPrivateKey: (assetName: string) => Promise<{
30
31
  privateKey: Buffer;
31
32
  }>;
33
+ simulateTransactions: SimulateTransactionsFn;
32
34
  }
33
35
  export declare type EVMFactory = (params: CreateEvmDepsParams) => EVMDeps;
34
36
  export declare type EVMDeps = {
@@ -36,11 +38,9 @@ export declare type EVMDeps = {
36
38
  getAddress: () => Promise<string>;
37
39
  getPrivateKey: () => Promise<Buffer>;
38
40
  sendRawTransaction: (rawTransaction: string) => Promise<EthTransactionHash>;
39
- simulateTransaction: (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
40
- scanDomains: ScanDomainsFn;
41
+ simulateTransactions: SimulateTransactionsFn;
41
42
  getEstimatedGas: (transaction: EthTransaction) => Promise<string>;
42
43
  getFeeData: () => Promise<FeeData>;
43
- getOrigin: () => string;
44
44
  getNonce: () => Promise<string>;
45
45
  forwardRequest: (args: EthRequestArguments) => Promise<unknown>;
46
46
  onEthWalletWatchAssetRequest?: (assetDetails: EthWalletWatchAsset) => Promise<boolean>;
@@ -48,3 +48,4 @@ export declare type EVMDeps = {
48
48
  export declare type Dependencies = {
49
49
  evms: EVMDeps[];
50
50
  } & CommonDeps;
51
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum",
3
3
  "description": "Apps connectivity library for EVM-compatible chains.",
4
- "version": "7.0.0",
4
+ "version": "8.1.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -33,10 +33,10 @@
33
33
  "@exodus/currency": "^2.1.2",
34
34
  "@exodus/ethereum-api": "^6.0.0",
35
35
  "@exodus/web3-constants": "^1.29.0",
36
- "@exodus/web3-ethereum-utils": "^3.0.0",
37
- "@exodus/web3-provider": "^2.32.0",
38
- "@exodus/web3-rpc-handlers": "^1.7.0",
39
- "@exodus/web3-utils": "^1.22.0",
36
+ "@exodus/web3-ethereum-utils": "^3.2.0",
37
+ "@exodus/web3-provider": "^2.34.0",
38
+ "@exodus/web3-rpc-handlers": "^2.1.0",
39
+ "@exodus/web3-utils": "^1.24.0",
40
40
  "bn.js": "^5.2.0",
41
41
  "eth-rpc-errors": "^4.0.3"
42
42
  },
@@ -44,12 +44,12 @@
44
44
  "@exodus/assets": "^8.0.72",
45
45
  "@exodus/json-rpc": "^1.11.0",
46
46
  "@exodus/schemasafe": "^1.0.0",
47
- "@exodus/web3-types": "^1.30.0",
47
+ "@exodus/web3-types": "^1.32.0",
48
48
  "@exodus/web3-validation": "^1.36.0",
49
49
  "@wallet-standard/base": "^1.0.1"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@exodus/assets": "^8.0.72"
53
53
  },
54
- "gitHead": "5130517c87424b7118b272f053d10fb42750fa3f"
54
+ "gitHead": "bcd3faa51e2a31d8324d8b107a6bb1327a77fd1d"
55
55
  }