@exodus/web3-ethereum-utils 2.0.2 → 3.1.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/createSimulateTransactions.d.ts +3 -0
- package/lib/{createSimulateTransaction.js → createSimulateTransactions.js} +6 -10
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/simulation/{simulateTransaction.d.ts → simulateTransactions.d.ts} +3 -3
- package/lib/simulation/{simulateTransaction.js → simulateTransactions.js} +11 -13
- package/lib/types.d.ts +1 -1
- package/package.json +4 -4
- package/lib/createSimulateTransaction.d.ts +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from './types.js';
|
|
2
|
+
import type { CreateSimulationServiceParams } from '@exodus/web3-types';
|
|
3
|
+
export declare const createSimulateTransactions: ({ apiEndpoint, headers, shouldSimulate, }: Required<CreateSimulationServiceParams>) => ({ transactions, asset, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { createEmptySimulationResult } from '@exodus/web3-utils';
|
|
2
2
|
import { estimateFee } from './simulation/estimateFee.js';
|
|
3
|
-
import {
|
|
3
|
+
import { simulateTransactions } from './simulation/simulateTransactions.js';
|
|
4
4
|
import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
|
|
5
5
|
import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
'X-Api-Version': '2023-06-05',
|
|
10
|
-
};
|
|
11
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
|
-
export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS, shouldSimulate = true, }) => async ({ transaction, asset, origin, }) => {
|
|
6
|
+
export const createSimulateTransactions = ({ apiEndpoint, headers, shouldSimulate, }) => async ({ transactions, asset, origin, }) => {
|
|
7
|
+
// Ethereum transactions from web3 providers are always one item in an array.
|
|
8
|
+
const transaction = transactions[0];
|
|
13
9
|
const simulationResult = createEmptySimulationResult({
|
|
14
10
|
asset,
|
|
15
11
|
});
|
|
@@ -24,8 +20,8 @@ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_D
|
|
|
24
20
|
tryEstimatingChangesLocally({ asset, simulationResult, transaction });
|
|
25
21
|
return simulationResult;
|
|
26
22
|
}
|
|
27
|
-
await
|
|
28
|
-
|
|
23
|
+
await simulateTransactions({
|
|
24
|
+
transactions,
|
|
29
25
|
apiEndpoint,
|
|
30
26
|
origin,
|
|
31
27
|
simulationResult,
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from '../types.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CreateSimulationServiceParams } from '@exodus/web3-types';
|
|
3
3
|
interface BlowfishEvmChain {
|
|
4
4
|
[key: string]: {
|
|
5
5
|
network: string;
|
|
@@ -7,10 +7,10 @@ interface BlowfishEvmChain {
|
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
9
|
export declare const BLOWFISH_EVM_CHAINS: BlowfishEvmChain;
|
|
10
|
-
declare type SimulateTransactionParams = Required<Pick<
|
|
10
|
+
declare type SimulateTransactionParams = Required<Pick<CreateSimulationServiceParams, 'apiEndpoint'>> & Required<Pick<EthSimulateTransactionParams, 'transactions' | 'origin'>> & {
|
|
11
11
|
simulationResult: EthAggregatedTransactionSimulationResult;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
assetName: string;
|
|
14
14
|
};
|
|
15
|
-
export declare const
|
|
15
|
+
export declare const simulateTransactions: ({ transactions, apiEndpoint, origin, simulationResult, headers, assetName, }: SimulateTransactionParams) => Promise<void> | never;
|
|
16
16
|
export {};
|
|
@@ -25,19 +25,17 @@ export const BLOWFISH_EVM_CHAINS = {
|
|
|
25
25
|
chain: 'goerli',
|
|
26
26
|
},
|
|
27
27
|
};
|
|
28
|
-
const convertTransactionToApiPayload = (
|
|
29
|
-
txObjects:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
},
|
|
36
|
-
],
|
|
28
|
+
const convertTransactionToApiPayload = (transactions, origin) => ({
|
|
29
|
+
txObjects: transactions.map((transaction) => ({
|
|
30
|
+
from: transaction.from,
|
|
31
|
+
to: transaction.to,
|
|
32
|
+
data: transaction.data,
|
|
33
|
+
value: transaction.value,
|
|
34
|
+
})),
|
|
37
35
|
metadata: {
|
|
38
36
|
origin,
|
|
39
37
|
},
|
|
40
|
-
userAccount:
|
|
38
|
+
userAccount: transactions[0].from,
|
|
41
39
|
});
|
|
42
40
|
const createBalanceAmount = (amount, { decimals, symbol }) => {
|
|
43
41
|
const beforeAmount = createCurrency({
|
|
@@ -108,9 +106,9 @@ const simulationResultHasAssets = (expectedStateChanges) => {
|
|
|
108
106
|
}
|
|
109
107
|
return true;
|
|
110
108
|
};
|
|
111
|
-
export const
|
|
112
|
-
const userAddress =
|
|
113
|
-
const payload = convertTransactionToApiPayload(
|
|
109
|
+
export const simulateTransactions = async ({ transactions, apiEndpoint, origin, simulationResult, headers, assetName, }) => {
|
|
110
|
+
const userAddress = transactions[0].from;
|
|
111
|
+
const payload = convertTransactionToApiPayload(transactions, origin);
|
|
114
112
|
if (!Object.hasOwnProperty.call(BLOWFISH_EVM_CHAINS, assetName)) {
|
|
115
113
|
// ToDo: accept a logger dep and log the error
|
|
116
114
|
return;
|
package/lib/types.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export interface EthWalletWatchAsset {
|
|
|
39
39
|
options: EthWalletWatchAssetOptions;
|
|
40
40
|
}
|
|
41
41
|
export interface EthSimulateTransactionParams extends SimulateTransactionParams {
|
|
42
|
-
|
|
42
|
+
transactions: EthTransaction[];
|
|
43
43
|
}
|
|
44
44
|
export interface EthFeeDetails {
|
|
45
45
|
gasLimit: BN;
|
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
|
+
"version": "3.1.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.31.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.23.0",
|
|
35
35
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "809f56d8040d221eb52373bc9ce3c797c1bbb7a5"
|
|
38
38
|
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams } from './types.js';
|
|
2
|
-
import type { CreateSimulateTransactionParams } from '@exodus/web3-types';
|
|
3
|
-
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, shouldSimulate, }: CreateSimulateTransactionParams) => ({ transaction, asset, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|