@exodus/web3-ethereum 3.2.1 → 4.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.
@@ -77,6 +77,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
77
77
  });
78
78
  return true;
79
79
  };
80
+ const getOrigin = () => origin;
80
81
  return {
81
82
  chainId: 'undefined',
82
83
  forwardRequest,
@@ -87,6 +88,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
87
88
  getFeeData,
88
89
  getEstimatedGas,
89
90
  onEthWalletWatchAssetRequest: trackWalletWatchAssetUse,
91
+ getOrigin,
90
92
  };
91
93
  };
92
94
  };
@@ -62,7 +62,7 @@ const isValidGasLimitValue = (value) => {
62
62
  return proposedGasLimit.lte(maximumBlockGasLimit);
63
63
  };
64
64
  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, } = 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;
66
66
  const network = `evm:${chainId}`;
67
67
  async function assertTrusted() {
68
68
  const trusted = await isTrusted();
@@ -123,7 +123,12 @@ export function exposeHandlers(rpc, deps) {
123
123
  const asset = await getAsset(network);
124
124
  const preparedTransaction = await prepareTransaction(transaction);
125
125
  validateTransaction(preparedTransaction);
126
- const simulatedChanges = await simulateTransaction(asset, preparedTransaction);
126
+ const origin = getOrigin();
127
+ const simulatedChanges = await simulateTransaction({
128
+ asset,
129
+ transaction: preparedTransaction,
130
+ origin,
131
+ });
127
132
  await approve(approveTransactions, network, simulatedChanges);
128
133
  const privateKey = await getPrivateKey();
129
134
  const signedTransaction = signTransaction({ ...preparedTransaction, chainId }, privateKey);
@@ -13,6 +13,7 @@ const validateEVMDeps = (evm) => {
13
13
  'getFeeData',
14
14
  'getNonce',
15
15
  'sendRawTransaction',
16
+ 'getOrigin',
16
17
  ];
17
18
  const optionalKeys = ['onEthWalletWatchAssetRequest'];
18
19
  validateDeps(evm, requiredKeys, optionalKeys);
@@ -1,10 +1,9 @@
1
- import type { EthBalanceChanges } from './types.js';
2
- import type { EthTransaction } from '@exodus/web3-ethereum-utils';
3
- import type { Asset, NumberUnit } from '@exodus/web3-types';
4
- export declare const simulateTransaction: (asset: Asset, transaction: EthTransaction) => Promise<{
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<{
5
4
  baseAssetName: string;
6
5
  advancedDetails: never[];
7
- balanceChanges: EthBalanceChanges;
6
+ balanceChanges: import("@exodus/web3-types").BalanceChanges;
8
7
  displayInfo: {
9
8
  title: string;
10
9
  };
@@ -1,35 +1,7 @@
1
- import { retrieveSideEffects } from '@exodus/ethereum-api';
1
+ import { createSimulateTransaction } from '@exodus/web3-ethereum-utils';
2
2
  import { SIMULATION_SUPPORTED_ASSET_NAMES } from './constant.js';
3
- import { formatAccounts, getEthereumDisplayInfo, hexToBN, isEthTransferTx, } from './utils.js';
4
- const computeBalanceChanges = async (asset, shouldSimulate, transaction) => {
5
- let balanceChanges = {
6
- willReceive: [],
7
- willSend: [],
8
- willApprove: [],
9
- };
10
- if (isEthTransferTx(transaction)) {
11
- const txValue = hexToBN(transaction.value).toString();
12
- balanceChanges.willSend.push({
13
- balance: asset.currency.baseUnit(txValue),
14
- });
15
- }
16
- else {
17
- try {
18
- const sideEffect = await retrieveSideEffects({
19
- asset,
20
- shouldSimulate,
21
- transaction,
22
- });
23
- if (sideEffect) {
24
- balanceChanges = formatAccounts(sideEffect);
25
- }
26
- }
27
- catch (error) {
28
- console.error('Ethereum transaction simulation failed.', error);
29
- }
30
- }
31
- return balanceChanges;
32
- };
3
+ import { getEthereumDisplayInfo, hexToBN } from './utils.js';
4
+ const simulateTransactionV2 = createSimulateTransaction();
33
5
  const getTxFeeDetails = (asset, transaction) => {
34
6
  const maxFeePerGasBn = transaction.maxFeePerGas
35
7
  ? hexToBN(transaction.maxFeePerGas)
@@ -45,10 +17,15 @@ const getTxFeeDetails = (asset, transaction) => {
45
17
  },
46
18
  };
47
19
  };
48
- export const simulateTransaction = async (asset, transaction) => {
20
+ export const simulateTransaction = async ({ asset, transaction, origin, }) => {
49
21
  const baseAssetName = asset.name;
50
22
  const shouldSimulate = SIMULATION_SUPPORTED_ASSET_NAMES.includes(baseAssetName);
51
- const balanceChanges = await computeBalanceChanges(asset, shouldSimulate, transaction);
23
+ const { balanceChanges } = await simulateTransactionV2({
24
+ transaction,
25
+ asset,
26
+ origin,
27
+ shouldCallPreviewApi: shouldSimulate,
28
+ });
52
29
  const { txFee, txFeeDetails } = getTxFeeDetails(asset, transaction);
53
30
  const displayInfo = getEthereumDisplayInfo(balanceChanges);
54
31
  return {
package/lib/types.d.ts CHANGED
@@ -37,6 +37,7 @@ export declare type EVMDeps = {
37
37
  sendRawTransaction: (rawTransaction: string) => Promise<EthTransactionHash>;
38
38
  getEstimatedGas: (transaction: EthTransaction) => Promise<string>;
39
39
  getFeeData: () => Promise<FeeData>;
40
+ getOrigin: () => string;
40
41
  getNonce: () => Promise<string>;
41
42
  forwardRequest: (args: EthRequestArguments) => Promise<unknown>;
42
43
  onEthWalletWatchAssetRequest?: (assetDetails: EthWalletWatchAsset) => Promise<boolean>;
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": "3.2.1",
4
+ "version": "4.0.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -34,10 +34,10 @@
34
34
  "@exodus/currency": "^2.1.2",
35
35
  "@exodus/ethereum-api": "^6.0.0",
36
36
  "@exodus/web3-constants": "^1.29.0",
37
- "@exodus/web3-ethereum-utils": "^1.20.0",
38
- "@exodus/web3-provider": "^2.27.0",
39
- "@exodus/web3-rpc-handlers": "^1.2.0",
40
- "@exodus/web3-utils": "^1.16.0",
37
+ "@exodus/web3-ethereum-utils": "^1.21.0",
38
+ "@exodus/web3-provider": "^2.28.0",
39
+ "@exodus/web3-rpc-handlers": "^1.3.0",
40
+ "@exodus/web3-utils": "^1.17.0",
41
41
  "bn.js": "^5.2.0",
42
42
  "eth-rpc-errors": "^4.0.3"
43
43
  },
@@ -45,12 +45,12 @@
45
45
  "@exodus/assets": "^8.0.72",
46
46
  "@exodus/json-rpc": "^1.11.0",
47
47
  "@exodus/schemasafe": "^1.0.0",
48
- "@exodus/web3-types": "^1.25.0",
48
+ "@exodus/web3-types": "^1.26.0",
49
49
  "@exodus/web3-validation": "^1.35.0",
50
50
  "@wallet-standard/base": "^1.0.1"
51
51
  },
52
52
  "peerDependencies": {
53
53
  "@exodus/assets": "^8.0.72"
54
54
  },
55
- "gitHead": "0a1ef133949a68de8df6ab3320d75319f10eadaa"
55
+ "gitHead": "e425fafca91cd79471b6fd4fbcd6b78a0a8d4a22"
56
56
  }