@exodus/web3-ethereum-utils 1.24.0 → 1.25.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/createSimulateTransaction.d.ts +3 -3
- package/lib/createSimulateTransaction.js +6 -1
- package/lib/simulation/simulateTransaction.d.ts +3 -3
- package/lib/simulation/tryEstimatingChangesLocally.d.ts +3 -3
- package/lib/transactions.d.ts +10 -0
- package/lib/transactions.js +21 -0
- package/lib/types.d.ts +8 -5
- package/package.json +4 -4
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { EthSimulateTransactionParams } from './types.js';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, }?: CreateSimulateTransactionParams) => ({ transaction, asset, shouldCallPreviewApi, origin, }: EthSimulateTransactionParams) => Promise<
|
|
1
|
+
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from './types.js';
|
|
2
|
+
import type { CreateSimulateTransactionParams } from '@exodus/web3-types';
|
|
3
|
+
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, }?: CreateSimulateTransactionParams) => ({ transaction, asset, shouldCallPreviewApi, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|
|
@@ -2,6 +2,7 @@ import { createEmptySimulationResult } from '@exodus/web3-utils';
|
|
|
2
2
|
import { estimateFee } from './simulation/estimateFee.js';
|
|
3
3
|
import { simulateTransaction } from './simulation/simulateTransaction.js';
|
|
4
4
|
import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
|
|
5
|
+
import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
|
|
5
6
|
const SIMULATION_API_DEFAULT = 'https://simulation.a.exodus.io/simulate';
|
|
6
7
|
const SERVICE_PROVIDER_DEFAULT = 'blowfish';
|
|
7
8
|
const SIMULATION_HEADERS = {
|
|
@@ -9,9 +10,12 @@ const SIMULATION_HEADERS = {
|
|
|
9
10
|
};
|
|
10
11
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
11
12
|
export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS, } = {}) => async ({ transaction, asset, shouldCallPreviewApi = true, origin, }) => {
|
|
12
|
-
const simulationResult = createEmptySimulationResult({
|
|
13
|
+
const simulationResult = createEmptySimulationResult({
|
|
14
|
+
asset,
|
|
15
|
+
});
|
|
13
16
|
simulationResult.balanceChanges.willPayFee.push({
|
|
14
17
|
balance: estimateFee({ asset, transaction }),
|
|
18
|
+
feeDetails: getTxFeeDetails(transaction),
|
|
15
19
|
});
|
|
16
20
|
if (!transaction.to) {
|
|
17
21
|
return simulationResult;
|
|
@@ -27,5 +31,6 @@ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_D
|
|
|
27
31
|
simulationResult,
|
|
28
32
|
headers,
|
|
29
33
|
});
|
|
34
|
+
simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
|
|
30
35
|
return simulationResult;
|
|
31
36
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { EthSimulateTransactionParams } from '../types.js';
|
|
2
|
-
import type {
|
|
1
|
+
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from '../types.js';
|
|
2
|
+
import type { CreateSimulateTransactionParams } from '@exodus/web3-types';
|
|
3
3
|
declare type SimulateTransactionParams = Required<Pick<CreateSimulateTransactionParams, 'apiEndpoint'>> & Required<Pick<EthSimulateTransactionParams, 'transaction' | 'origin'>> & {
|
|
4
|
-
simulationResult:
|
|
4
|
+
simulationResult: EthAggregatedTransactionSimulationResult;
|
|
5
5
|
headers?: Record<string, string>;
|
|
6
6
|
};
|
|
7
7
|
export declare const simulateTransaction: ({ transaction, apiEndpoint, origin, simulationResult, headers, }: SimulateTransactionParams) => Promise<void> | never;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { EthTransaction } from '../types.js';
|
|
2
|
-
import type {
|
|
1
|
+
import type { EthAggregatedTransactionSimulationResult, EthTransaction } from '../types.js';
|
|
2
|
+
import type { Asset } from '@exodus/web3-types';
|
|
3
3
|
export declare const tryEstimatingChangesLocally: ({ asset, simulationResult, transaction, }: {
|
|
4
4
|
asset: Asset;
|
|
5
|
-
simulationResult:
|
|
5
|
+
simulationResult: EthAggregatedTransactionSimulationResult;
|
|
6
6
|
transaction: EthTransaction;
|
|
7
7
|
}) => void;
|
package/lib/transactions.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { EthTransaction } from './types.js';
|
|
3
|
+
import type { ApprovalBalanceChange } from '@exodus/web3-types';
|
|
2
4
|
export declare function getTransactionId(serializedTransaction: Buffer, isEIP1559Transaction?: boolean): string;
|
|
5
|
+
export declare function getDisplayDetails(willApprove: ApprovalBalanceChange[]): {
|
|
6
|
+
title: string;
|
|
7
|
+
};
|
|
8
|
+
export declare const getTxFeeDetails: (transaction: EthTransaction) => {
|
|
9
|
+
gasLimit: import("bn.js");
|
|
10
|
+
maxFeePerGas: import("bn.js");
|
|
11
|
+
gasPrice: import("bn.js");
|
|
12
|
+
};
|
package/lib/transactions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FeeMarketEIP1559Transaction, Transaction as LegacyTransaction, } from '@exodus/ethereumjs-tx';
|
|
2
|
+
import { hexToBN } from '@exodus/web3-utils';
|
|
2
3
|
export function getTransactionId(serializedTransaction, isEIP1559Transaction = false) {
|
|
3
4
|
const Transaction = isEIP1559Transaction
|
|
4
5
|
? FeeMarketEIP1559Transaction
|
|
@@ -6,3 +7,23 @@ export function getTransactionId(serializedTransaction, isEIP1559Transaction = f
|
|
|
6
7
|
const transaction = Transaction.fromSerializedTx(serializedTransaction);
|
|
7
8
|
return `0x${transaction.hash().toString('hex')}`;
|
|
8
9
|
}
|
|
10
|
+
export function getDisplayDetails(willApprove) {
|
|
11
|
+
let title = 'Approve Transaction?';
|
|
12
|
+
const isApproveTransaction = willApprove.length;
|
|
13
|
+
if (isApproveTransaction) {
|
|
14
|
+
const tokenName = willApprove[0].unitName;
|
|
15
|
+
// Don't change the title if 'tokenName' is undefined
|
|
16
|
+
title = tokenName ? `Approve ${tokenName} Transactions?` : title;
|
|
17
|
+
}
|
|
18
|
+
return { title };
|
|
19
|
+
}
|
|
20
|
+
export const getTxFeeDetails = (transaction) => {
|
|
21
|
+
const maxFeePerGas = hexToBN(transaction.maxFeePerGas);
|
|
22
|
+
const gasPrice = hexToBN(transaction.gasPrice);
|
|
23
|
+
const gasLimit = hexToBN(transaction.gas);
|
|
24
|
+
return {
|
|
25
|
+
gasLimit,
|
|
26
|
+
maxFeePerGas,
|
|
27
|
+
gasPrice,
|
|
28
|
+
};
|
|
29
|
+
};
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type { SimulateTransactionParams } from '@exodus/web3-types';
|
|
2
|
-
export interface EthChainParam {
|
|
3
|
-
chainId: string;
|
|
4
|
-
}
|
|
1
|
+
import type { AggregatedTransactionSimulationResult, BN, SimulateTransactionParams } from '@exodus/web3-types';
|
|
5
2
|
export interface EthTransactionParams {
|
|
6
3
|
chainId: string;
|
|
7
4
|
from: string;
|
|
@@ -24,7 +21,7 @@ export interface EthTransaction {
|
|
|
24
21
|
data: string;
|
|
25
22
|
nonce: string;
|
|
26
23
|
maxPriorityFeePerGas?: string;
|
|
27
|
-
maxFeePerGas
|
|
24
|
+
maxFeePerGas: string;
|
|
28
25
|
}
|
|
29
26
|
export declare type EthTransactionHash = string;
|
|
30
27
|
export declare type EthParentCapability = 'eth_accounts';
|
|
@@ -44,3 +41,9 @@ export interface EthWalletWatchAsset {
|
|
|
44
41
|
export interface EthSimulateTransactionParams extends SimulateTransactionParams {
|
|
45
42
|
transaction: EthTransaction;
|
|
46
43
|
}
|
|
44
|
+
export interface EthFeeDetails {
|
|
45
|
+
gasLimit: BN;
|
|
46
|
+
maxFeePerGas: BN;
|
|
47
|
+
gasPrice: BN;
|
|
48
|
+
}
|
|
49
|
+
export declare type EthAggregatedTransactionSimulationResult = AggregatedTransactionSimulationResult<EthFeeDetails>;
|
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.
|
|
4
|
+
"version": "1.25.0",
|
|
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.
|
|
29
|
+
"@exodus/web3-types": "^1.28.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.
|
|
34
|
+
"@exodus/web3-utils": "^1.20.0",
|
|
35
35
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "6ecf2163a1426779896da6b283d4d7547068a84f"
|
|
38
38
|
}
|