@exodus/web3-ethereum-utils 4.2.1 → 4.3.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.
@@ -2,7 +2,7 @@ import { createEmptySimulationResult } from '@exodus/web3-utils';
2
2
  import { estimateFee } from './simulation/estimateFee.js';
3
3
  import { simulateTransactions } from './simulation/simulateTransactions.js';
4
4
  import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
5
- import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
5
+ import { decodeRecipientAddresses, getDisplayDetails, getTxFeeDetails } from './transactions.js';
6
6
  export const createSimulateTransactions = ({ apiEndpoint, headers }) => async ({ transactions, asset, origin, overrideApiEndpoint, }) => {
7
7
  // Ethereum transactions from web3 providers are always one item in an array.
8
8
  const transaction = transactions[0];
@@ -16,6 +16,7 @@ export const createSimulateTransactions = ({ apiEndpoint, headers }) => async ({
16
16
  if (!transaction.to) {
17
17
  return simulationResult;
18
18
  }
19
+ simulationResult.recipientAddresses = transactions.map((tx) => decodeRecipientAddresses(tx));
19
20
  const simulationTransactionInternalResult = await simulateTransactions({
20
21
  asset,
21
22
  transactions,
@@ -8,14 +8,14 @@
8
8
  */
9
9
  import { createCurrency, hexToBN } from '@exodus/web3-utils';
10
10
  import { getCreateCurrencyParams } from './common.js';
11
+ import { isSimpleTransfer } from '../transactions.js';
11
12
  export class NotSimpleTransferError extends Error {
12
13
  constructor(msg) {
13
14
  super(msg);
14
15
  }
15
16
  }
16
17
  export const estimateSimpleTransfer = ({ asset, transaction, }) => {
17
- // Transaction shouldn't provide any parameters to a smart contract.
18
- if (!['0x', null, undefined].includes(transaction.data)) {
18
+ if (!isSimpleTransfer(transaction)) {
19
19
  throw new NotSimpleTransferError('The transaction input should be empty ("0x").');
20
20
  }
21
21
  const txValue = hexToBN(transaction.value || '0x0').toString();
@@ -11,6 +11,8 @@ const convertTransactionToApiPayload = (transactions, origin) => ({
11
11
  to: transaction.to,
12
12
  data: transaction.data,
13
13
  value: transaction.value,
14
+ gas: transaction.gas,
15
+ gas_price: transaction.gasPrice,
14
16
  })),
15
17
  metadata: {
16
18
  origin,
@@ -6,8 +6,10 @@ export declare function getTransactionId(serializedTransaction: Buffer, isEIP155
6
6
  export declare function getDisplayDetails(willApprove: ApprovalBalanceChange[]): {
7
7
  title: string;
8
8
  };
9
+ export declare const isSimpleTransfer: (transaction: EthTransaction) => boolean;
9
10
  export declare const getTxFeeDetails: (transaction: EthTransaction) => {
10
11
  gasLimit: string;
11
12
  maxFeePerGas: string | undefined;
12
13
  gasPrice: string;
13
14
  };
15
+ export declare function decodeRecipientAddresses(transaction: EthTransaction): string[];
@@ -1,4 +1,5 @@
1
1
  import { FeeMarketEIP1559Transaction, Transaction as LegacyTransaction, } from '@exodus/ethereumjs/tx';
2
+ import SolidityContract from '@exodus/solidity-contract';
2
3
  export function getTransactionId(serializedTransaction, isEIP1559Transaction = false) {
3
4
  const Transaction = isEIP1559Transaction
4
5
  ? FeeMarketEIP1559Transaction
@@ -16,6 +17,10 @@ export function getDisplayDetails(willApprove) {
16
17
  }
17
18
  return { title };
18
19
  }
20
+ export const isSimpleTransfer = (transaction) => {
21
+ // Transaction shouldn't provide any parameters to a smart contract.
22
+ return ['0x', null, undefined].includes(transaction.data);
23
+ };
19
24
  export const getTxFeeDetails = (transaction) => {
20
25
  const maxFeePerGas = transaction.maxFeePerGas;
21
26
  const gasPrice = transaction.gasPrice;
@@ -26,3 +31,22 @@ export const getTxFeeDetails = (transaction) => {
26
31
  gasPrice,
27
32
  };
28
33
  };
34
+ export function decodeRecipientAddresses(transaction) {
35
+ try {
36
+ if (!transaction.to) {
37
+ return [];
38
+ }
39
+ if (isSimpleTransfer(transaction)) {
40
+ return [transaction.to];
41
+ }
42
+ const token = SolidityContract.erc20(transaction.to);
43
+ const { method, values } = token.decodeInput(transaction.data);
44
+ if (method === 'transfer') {
45
+ return [values[0]];
46
+ }
47
+ return [];
48
+ }
49
+ catch {
50
+ return [];
51
+ }
52
+ }
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": "4.2.1",
4
+ "version": "4.3.1",
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
7
  "module": "lib/index.js",
@@ -34,11 +34,12 @@
34
34
  "test": "run -T exodus-test --jest --esbuild"
35
35
  },
36
36
  "devDependencies": {
37
- "@exodus/web3-types": "1.53.2"
37
+ "@exodus/web3-types": "1.57.1"
38
38
  },
39
39
  "dependencies": {
40
40
  "@exodus/basic-utils": "^3.0.1",
41
41
  "@exodus/ethereumjs": "^1.0.0",
42
+ "@exodus/solidity-contract": "^1.2.1",
42
43
  "@exodus/web3-utils": "^1.50.1",
43
44
  "@metamask/eth-sig-util": "^4.0.1",
44
45
  "minimalistic-assert": "^1.0.1"
@@ -48,5 +49,5 @@
48
49
  "url": "https://github.com/ExodusMovement/assets/issues?q=is%3Aissue+is%3Aopen+label%3Aweb3-ethereum-utils"
49
50
  },
50
51
  "homepage": "https://github.com/ExodusMovement/assets/tree/master/web3/web3-ethereum-utils",
51
- "gitHead": "ca80bc54107fb73e965defe4948136e7130a8f02"
52
+ "gitHead": "e4c5768bef1ad9231580331f700f4d9fc25ecd92"
52
53
  }