@exodus/web3-ethereum 5.1.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/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { EthereumProvider } from './provider/index.js';
2
- export { simulateTransaction } from './simulation/index.js';
3
2
  export { ExodusEthereumWallet } from './wallet-standard/index.js';
4
3
  export { registerRPCHandlers } from './rpc-handlers/index.js';
package/lib/index.js CHANGED
@@ -1,4 +1,3 @@
1
1
  export { EthereumProvider } from './provider/index.js';
2
- export { simulateTransaction } from './simulation/index.js';
3
2
  export { ExodusEthereumWallet } from './wallet-standard/index.js';
4
3
  export { registerRPCHandlers } from './rpc-handlers/index.js';
@@ -1,3 +1,3 @@
1
1
  import type { CreateEvmDepsFactoryParams, EVMFactory } from '../types.js';
2
- declare const createEvmDepsFactory: ({ analytics, blockchainMetadata, }: CreateEvmDepsFactoryParams) => EVMFactory;
2
+ declare const createEvmDepsFactory: ({ analytics, blockchainMetadata, simulateTransactionConfig, }: CreateEvmDepsFactoryParams) => EVMFactory;
3
3
  export default createEvmDepsFactory;
@@ -1,6 +1,7 @@
1
1
  import { fetchGasLimit, getNonce as apiGetNonce, getServer, } from '@exodus/ethereum-api';
2
+ import { createSimulateTransaction } from '@exodus/web3-ethereum-utils';
2
3
  import BN from 'bn.js';
3
- const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
4
+ const createEvmDepsFactory = ({ analytics, blockchainMetadata, simulateTransactionConfig = {}, }) => {
4
5
  return ({ assetName, origin, getAsset, getAddress: _getAddress, getPrivateKey: _getPrivateKey, getFeeData: getFeeConfig, getActiveWalletAccount, }) => {
5
6
  const asset = getAsset(assetName);
6
7
  const server = getServer(asset);
@@ -78,6 +79,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
78
79
  return true;
79
80
  };
80
81
  const getOrigin = () => origin;
82
+ const simulateTransaction = createSimulateTransaction(simulateTransactionConfig);
81
83
  return {
82
84
  chainId: 'undefined',
83
85
  forwardRequest,
@@ -89,6 +91,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
89
91
  getEstimatedGas,
90
92
  onEthWalletWatchAssetRequest: trackWalletWatchAssetUse,
91
93
  getOrigin,
94
+ simulateTransaction,
92
95
  };
93
96
  };
94
97
  };
@@ -1,9 +1,8 @@
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 { hexToBN } from '@exodus/web3-utils';
3
4
  import { SignTypedDataVersion } from '@metamask/eth-sig-util';
4
5
  import { parseAndValidateTypedData } from './parseAndValidateTypedData.js';
5
- import { simulateTransaction } from '../simulation/index.js';
6
- import { hexToBN } from '../simulation/utils.js';
7
6
  // See: https://eips.ethereum.org/EIPS/eip-2255.
8
7
  const ETH_ACCOUNTS_PERMISSION = 'eth_accounts';
9
8
  const PROXIED_METHODS = [
@@ -62,7 +61,7 @@ const isValidGasLimitValue = (value) => {
62
61
  return proposedGasLimit.lte(maximumBlockGasLimit);
63
62
  };
64
63
  export function exposeHandlers(rpc, deps) {
65
- const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getFeeData, getNonce, sendRawTransaction, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = () => true, getAsset, getOrigin, } = 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;
66
65
  const network = `evm:${chainId}`;
67
66
  async function assertTrusted() {
68
67
  const trusted = await isTrusted();
@@ -13,6 +13,7 @@ const validateEVMDeps = (evm) => {
13
13
  'getFeeData',
14
14
  'getNonce',
15
15
  'sendRawTransaction',
16
+ 'simulateTransaction',
16
17
  'getOrigin',
17
18
  ];
18
19
  const optionalKeys = ['onEthWalletWatchAssetRequest'];
package/lib/types.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- import type { EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
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 } from '@exodus/web3-types';
4
+ import type { Asset, IAnalyticsModule, IBlockchainMetadataModule, EthereumFeeData, GetFeeDataParams, CreateSimulateTransactionParams } from '@exodus/web3-types';
5
5
  /**
6
6
  * EVM-compatible chains.
7
7
  */
@@ -17,6 +17,7 @@ export interface FeeData {
17
17
  export interface CreateEvmDepsFactoryParams {
18
18
  analytics: IAnalyticsModule;
19
19
  blockchainMetadata: IBlockchainMetadataModule;
20
+ simulateTransactionConfig?: CreateSimulateTransactionParams;
20
21
  }
21
22
  export interface CreateEvmDepsParams {
22
23
  assetName: string;
@@ -35,6 +36,7 @@ export declare type EVMDeps = {
35
36
  getAddress: () => Promise<string>;
36
37
  getPrivateKey: () => Promise<Buffer>;
37
38
  sendRawTransaction: (rawTransaction: string) => Promise<EthTransactionHash>;
39
+ simulateTransaction: (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
38
40
  getEstimatedGas: (transaction: EthTransaction) => Promise<string>;
39
41
  getFeeData: () => Promise<FeeData>;
40
42
  getOrigin: () => string;
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": "5.1.0",
4
+ "version": "6.0.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -11,7 +11,6 @@
11
11
  "./package.json": "./package.json",
12
12
  "./provider": "./lib/provider/index.js",
13
13
  "./rpc": "./lib/rpc-handlers/index.js",
14
- "./simulation": "./lib/simulation/index.js",
15
14
  "./wallet-standard": "./lib/wallet-standard/index.js"
16
15
  },
17
16
  "react-native": "./lib/index.js",
@@ -34,10 +33,10 @@
34
33
  "@exodus/currency": "^2.1.2",
35
34
  "@exodus/ethereum-api": "^6.0.0",
36
35
  "@exodus/web3-constants": "^1.29.0",
37
- "@exodus/web3-ethereum-utils": "^1.23.0",
38
- "@exodus/web3-provider": "^2.29.0",
39
- "@exodus/web3-rpc-handlers": "^1.4.0",
40
- "@exodus/web3-utils": "^1.18.0",
36
+ "@exodus/web3-ethereum-utils": "^1.25.0",
37
+ "@exodus/web3-provider": "^2.30.0",
38
+ "@exodus/web3-rpc-handlers": "^1.5.0",
39
+ "@exodus/web3-utils": "^1.20.0",
41
40
  "bn.js": "^5.2.0",
42
41
  "eth-rpc-errors": "^4.0.3"
43
42
  },
@@ -45,12 +44,12 @@
45
44
  "@exodus/assets": "^8.0.72",
46
45
  "@exodus/json-rpc": "^1.11.0",
47
46
  "@exodus/schemasafe": "^1.0.0",
48
- "@exodus/web3-types": "^1.27.0",
47
+ "@exodus/web3-types": "^1.28.0",
49
48
  "@exodus/web3-validation": "^1.35.0",
50
49
  "@wallet-standard/base": "^1.0.1"
51
50
  },
52
51
  "peerDependencies": {
53
52
  "@exodus/assets": "^8.0.72"
54
53
  },
55
- "gitHead": "94b6a34b8a0f7826a4d4652dc1c7ff2b3ea6c017"
54
+ "gitHead": "6ecf2163a1426779896da6b283d4d7547068a84f"
56
55
  }
@@ -1 +0,0 @@
1
- export declare const SIMULATION_SUPPORTED_ASSET_NAMES: string[];
@@ -1 +0,0 @@
1
- export const SIMULATION_SUPPORTED_ASSET_NAMES = ['ethereum']; // just ethereum for now
@@ -1 +0,0 @@
1
- export { simulateTransaction } from './simulation.js';
@@ -1 +0,0 @@
1
- export { simulateTransaction } from './simulation.js';
@@ -1,16 +0,0 @@
1
- import type { EthSimulateTransactionParams } from '@exodus/web3-ethereum-utils';
2
- import type { NumberUnit } from '@exodus/web3-types';
3
- export declare const simulateTransaction: ({ asset, transaction, origin, }: EthSimulateTransactionParams) => Promise<{
4
- baseAssetName: string;
5
- advancedDetails: never[];
6
- balanceChanges: import("@exodus/web3-types").BalanceChanges;
7
- displayInfo: {
8
- title: string;
9
- };
10
- txFee: NumberUnit;
11
- txFeeDetails: {
12
- gasLimit: number;
13
- maxFeePerGas: number | undefined;
14
- gasPrice: number;
15
- };
16
- }>;
@@ -1,39 +0,0 @@
1
- import { createSimulateTransaction } from '@exodus/web3-ethereum-utils';
2
- import { SIMULATION_SUPPORTED_ASSET_NAMES } from './constant.js';
3
- import { getEthereumDisplayInfo, hexToBN } from './utils.js';
4
- const simulateTransactionV2 = createSimulateTransaction();
5
- const getTxFeeDetails = (asset, transaction) => {
6
- const maxFeePerGasBn = transaction.maxFeePerGas
7
- ? hexToBN(transaction.maxFeePerGas)
8
- : undefined;
9
- const gasPriceBn = hexToBN(transaction.gasPrice);
10
- const gasBn = hexToBN(transaction.gas);
11
- return {
12
- txFee: asset.currency.baseUnit(gasBn.mul(maxFeePerGasBn || gasPriceBn).toString()),
13
- txFeeDetails: {
14
- gasLimit: gasBn.toNumber(),
15
- maxFeePerGas: maxFeePerGasBn?.toNumber(),
16
- gasPrice: gasPriceBn.toNumber(),
17
- },
18
- };
19
- };
20
- export const simulateTransaction = async ({ asset, transaction, origin, }) => {
21
- const baseAssetName = asset.name;
22
- const shouldSimulate = SIMULATION_SUPPORTED_ASSET_NAMES.includes(baseAssetName);
23
- const { balanceChanges } = await simulateTransactionV2({
24
- transaction,
25
- asset,
26
- origin,
27
- shouldCallPreviewApi: shouldSimulate,
28
- });
29
- const { txFee, txFeeDetails } = getTxFeeDetails(asset, transaction);
30
- const displayInfo = getEthereumDisplayInfo(balanceChanges);
31
- return {
32
- baseAssetName,
33
- advancedDetails: [],
34
- balanceChanges,
35
- displayInfo,
36
- txFee,
37
- txFeeDetails,
38
- };
39
- };
@@ -1,22 +0,0 @@
1
- export interface CurrencyParams {
2
- amount: string;
3
- symbol: string;
4
- denominator: number;
5
- }
6
- export interface EthBalanceChanges {
7
- willReceive: Array<EthBalanceChange>;
8
- willSend: Array<EthBalanceChange>;
9
- willApprove: Array<EthBalanceChange>;
10
- }
11
- export interface EthBalanceChange {
12
- unitName?: string;
13
- balance: EthNumberUnit;
14
- }
15
- export interface EthNumberUnit {
16
- unitName: string;
17
- }
18
- export interface EthAccount {
19
- balance: number;
20
- symbol: string;
21
- decimal: number;
22
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- import BN from 'bn.js';
2
- import type { EthBalanceChange, EthBalanceChanges } from './types.js';
3
- import type { EthTransaction } from '@exodus/web3-ethereum-utils';
4
- export declare const hexToBN: (hexValue?: string) => BN;
5
- export declare const isEthTransferTx: (transaction: EthTransaction) => boolean;
6
- export declare function getEthereumDisplayInfo(balanceChanges: EthBalanceChanges): {
7
- title: string;
8
- };
9
- export declare const formatAccounts: ({ willSend, willReceive, willApprove, }: {
10
- willSend?: never[] | undefined;
11
- willReceive?: never[] | undefined;
12
- willApprove?: never[] | undefined;
13
- }) => {
14
- willSend: EthBalanceChange[];
15
- willReceive: EthBalanceChange[];
16
- willApprove: never[];
17
- };
@@ -1,34 +0,0 @@
1
- import { createCurrency } from '@exodus/web3-utils';
2
- import BN from 'bn.js';
3
- export const hexToBN = (hexValue) => new BN((hexValue || '').slice(2), 'hex');
4
- export const isEthTransferTx = (transaction) => {
5
- return (['0x', null, undefined].includes(transaction.data) &&
6
- [undefined, '0x5208'].includes(transaction.gas));
7
- };
8
- export function getEthereumDisplayInfo(balanceChanges) {
9
- let title = 'Approve Transaction?';
10
- const isApproveTransaction = balanceChanges.willApprove.length;
11
- if (isApproveTransaction) {
12
- const tokenName = balanceChanges.willApprove[0].unitName;
13
- // Don't change the title if 'tokenName' is undefined
14
- title = tokenName ? `Approve ${tokenName} Transactions?` : title;
15
- }
16
- return { title };
17
- }
18
- const convertToNumberUnit = (account) => ({
19
- ...account,
20
- balance: createCurrency({
21
- amount: new BN(account.balance).abs().toString(),
22
- symbol: account.symbol,
23
- denominator: account.decimal,
24
- }),
25
- });
26
- export const formatAccounts = ({ willSend = [], willReceive = [], willApprove = [], }) => {
27
- const newWillSend = willSend.map(convertToNumberUnit);
28
- const newWillReceive = willReceive.map(convertToNumberUnit);
29
- return {
30
- willSend: newWillSend,
31
- willReceive: newWillReceive,
32
- willApprove,
33
- };
34
- };