@exodus/web3-ethereum-utils 1.25.0 → 2.0.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.
@@ -1,3 +1,3 @@
1
1
  import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from './types.js';
2
2
  import type { CreateSimulateTransactionParams } from '@exodus/web3-types';
3
- export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, }?: CreateSimulateTransactionParams) => ({ transaction, asset, shouldCallPreviewApi, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
3
+ export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, shouldSimulate, }: CreateSimulateTransactionParams) => ({ transaction, asset, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
@@ -9,7 +9,7 @@ const SIMULATION_HEADERS = {
9
9
  'X-Api-Version': '2023-06-05',
10
10
  };
11
11
  /* eslint-disable @typescript-eslint/no-unused-vars */
12
- export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS, } = {}) => async ({ transaction, asset, shouldCallPreviewApi = true, origin, }) => {
12
+ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS, shouldSimulate = true, }) => async ({ transaction, asset, origin, }) => {
13
13
  const simulationResult = createEmptySimulationResult({
14
14
  asset,
15
15
  });
@@ -20,7 +20,7 @@ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_D
20
20
  if (!transaction.to) {
21
21
  return simulationResult;
22
22
  }
23
- if (!shouldCallPreviewApi) {
23
+ if (!shouldSimulate) {
24
24
  tryEstimatingChangesLocally({ asset, simulationResult, transaction });
25
25
  return simulationResult;
26
26
  }
@@ -30,6 +30,7 @@ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_D
30
30
  origin,
31
31
  simulationResult,
32
32
  headers,
33
+ assetName: asset.name,
33
34
  });
34
35
  simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
35
36
  return simulationResult;
@@ -1,8 +1,16 @@
1
1
  import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from '../types.js';
2
2
  import type { CreateSimulateTransactionParams } from '@exodus/web3-types';
3
+ interface BlowfishEvmChain {
4
+ [key: string]: {
5
+ network: string;
6
+ chain: string;
7
+ };
8
+ }
9
+ export declare const BLOWFISH_EVM_CHAINS: BlowfishEvmChain;
3
10
  declare type SimulateTransactionParams = Required<Pick<CreateSimulateTransactionParams, 'apiEndpoint'>> & Required<Pick<EthSimulateTransactionParams, 'transaction' | 'origin'>> & {
4
11
  simulationResult: EthAggregatedTransactionSimulationResult;
5
12
  headers?: Record<string, string>;
13
+ assetName: string;
6
14
  };
7
- export declare const simulateTransaction: ({ transaction, apiEndpoint, origin, simulationResult, headers, }: SimulateTransactionParams) => Promise<void> | never;
15
+ export declare const simulateTransaction: ({ transaction, apiEndpoint, origin, simulationResult, headers, assetName, }: SimulateTransactionParams) => Promise<void> | never;
8
16
  export {};
@@ -3,6 +3,28 @@
3
3
  with the according balance changes.
4
4
  */
5
5
  import { createCurrency, makeSimulationAPICall } from '@exodus/web3-utils';
6
+ export const BLOWFISH_EVM_CHAINS = {
7
+ ethereum: {
8
+ network: 'ethereum',
9
+ chain: 'mainnet',
10
+ },
11
+ matic: {
12
+ network: 'polygon',
13
+ chain: 'mainnet',
14
+ },
15
+ bsc: {
16
+ network: 'bnb',
17
+ chain: 'mainnet',
18
+ },
19
+ ethereumarbone: {
20
+ network: 'arbitrum',
21
+ chain: 'one',
22
+ },
23
+ optimism: {
24
+ network: 'optimism',
25
+ chain: 'goerli',
26
+ },
27
+ };
6
28
  const convertTransactionToApiPayload = (transaction, origin) => ({
7
29
  txObjects: [
8
30
  {
@@ -86,12 +108,18 @@ const simulationResultHasAssets = (expectedStateChanges) => {
86
108
  }
87
109
  return true;
88
110
  };
89
- export const simulateTransaction = async ({ transaction, apiEndpoint, origin, simulationResult, headers, }) => {
111
+ export const simulateTransaction = async ({ transaction, apiEndpoint, origin, simulationResult, headers, assetName, }) => {
90
112
  const userAddress = transaction.from;
91
113
  const payload = convertTransactionToApiPayload(transaction, origin);
114
+ if (!Object.hasOwnProperty.call(BLOWFISH_EVM_CHAINS, assetName)) {
115
+ // ToDo: accept a logger dep and log the error
116
+ return;
117
+ }
118
+ const { network, chain } = BLOWFISH_EVM_CHAINS[assetName];
92
119
  const response = await makeSimulationAPICall({
93
120
  url: apiEndpoint,
94
- network: 'ethereum',
121
+ chain,
122
+ network,
95
123
  payload,
96
124
  headers,
97
125
  });
@@ -102,7 +130,7 @@ export const simulateTransaction = async ({ transaction, apiEndpoint, origin, si
102
130
  return;
103
131
  }
104
132
  const userExpectedChanges = Object.keys(expectedStateChanges).reduce((prev, address) => {
105
- if (userAddress !== address) {
133
+ if (userAddress.toLowerCase() !== address.toLowerCase()) {
106
134
  return prev;
107
135
  }
108
136
  const result = (Object.prototype.hasOwnProperty.call(expectedStateChanges, address) &&
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@exodus/web3-ethereum-utils",
3
3
  "description": "Web3 Ethereum utils.",
4
- "version": "1.25.0",
4
+ "version": "2.0.1",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -26,13 +26,13 @@
26
26
  "build": "yarn clean && tsc"
27
27
  },
28
28
  "devDependencies": {
29
- "@exodus/web3-types": "^1.28.0"
29
+ "@exodus/web3-types": "^1.29.0"
30
30
  },
31
31
  "dependencies": {
32
32
  "@exodus/ethereumjs-common": "^2.4.0-exodus.6",
33
33
  "@exodus/ethereumjs-tx": "^3.3.0-exodus.6",
34
- "@exodus/web3-utils": "^1.20.0",
34
+ "@exodus/web3-utils": "^1.21.0",
35
35
  "@metamask/eth-sig-util": "^4.0.1"
36
36
  },
37
- "gitHead": "6ecf2163a1426779896da6b283d4d7547068a84f"
37
+ "gitHead": "4a85fd2502fe494a739bbdbd6ebdaae1194d8286"
38
38
  }