@exodus/web3-ethereum-utils 3.0.0 → 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/createSimulateTransactions.js +33 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/simulation/{simulateTransaction.d.ts → simulateTransactions.d.ts} +2 -2
- package/lib/simulation/{simulateTransaction.js → simulateTransactions.js} +11 -13
- package/lib/types.d.ts +2 -6
- package/package.json +4 -4
- package/lib/createSimulateTransaction.d.ts +0 -2
- package/lib/createSimulateTransaction.js +0 -40
|
@@ -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>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createEmptySimulationResult } from '@exodus/web3-utils';
|
|
2
|
+
import { estimateFee } from './simulation/estimateFee.js';
|
|
3
|
+
import { simulateTransactions } from './simulation/simulateTransactions.js';
|
|
4
|
+
import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
|
|
5
|
+
import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
|
|
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];
|
|
9
|
+
const simulationResult = createEmptySimulationResult({
|
|
10
|
+
asset,
|
|
11
|
+
});
|
|
12
|
+
simulationResult.balanceChanges.willPayFee.push({
|
|
13
|
+
balance: estimateFee({ asset, transaction }),
|
|
14
|
+
feeDetails: getTxFeeDetails(transaction),
|
|
15
|
+
});
|
|
16
|
+
if (!transaction.to) {
|
|
17
|
+
return simulationResult;
|
|
18
|
+
}
|
|
19
|
+
if (!shouldSimulate) {
|
|
20
|
+
tryEstimatingChangesLocally({ asset, simulationResult, transaction });
|
|
21
|
+
return simulationResult;
|
|
22
|
+
}
|
|
23
|
+
await simulateTransactions({
|
|
24
|
+
transactions,
|
|
25
|
+
apiEndpoint,
|
|
26
|
+
origin,
|
|
27
|
+
simulationResult,
|
|
28
|
+
headers,
|
|
29
|
+
assetName: asset.name,
|
|
30
|
+
});
|
|
31
|
+
simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
|
|
32
|
+
return simulationResult;
|
|
33
|
+
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -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<CreateSimulationServiceParams, 'apiEndpoint'>> & Required<Pick<EthSimulateTransactionParams, '
|
|
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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AggregatedTransactionSimulationResult,
|
|
1
|
+
import type { AggregatedTransactionSimulationResult, BN, SimulateTransactionParams } from '@exodus/web3-types';
|
|
2
2
|
export interface EthTransactionParams {
|
|
3
3
|
chainId: string;
|
|
4
4
|
from: string;
|
|
@@ -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;
|
|
@@ -47,7 +47,3 @@ export interface EthFeeDetails {
|
|
|
47
47
|
gasPrice: BN;
|
|
48
48
|
}
|
|
49
49
|
export declare type EthAggregatedTransactionSimulationResult = AggregatedTransactionSimulationResult<EthFeeDetails>;
|
|
50
|
-
export declare type CreateEthSimulationServiceFn = (simulationServiceParams: CreateSimulationServiceParams) => {
|
|
51
|
-
simulateTransaction: (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|
|
52
|
-
scanDomains: ScanDomainsFn;
|
|
53
|
-
};
|
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": "3.
|
|
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,40 +0,0 @@
|
|
|
1
|
-
import { createEmptySimulationResult, createScanDomains, } from '@exodus/web3-utils';
|
|
2
|
-
import { estimateFee } from './simulation/estimateFee.js';
|
|
3
|
-
import { simulateTransaction } from './simulation/simulateTransaction.js';
|
|
4
|
-
import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
|
|
5
|
-
import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
|
|
6
|
-
const SIMULATION_API_DEFAULT = 'https://simulation.a.exodus.io/simulate';
|
|
7
|
-
const SERVICE_PROVIDER_DEFAULT = 'blowfish';
|
|
8
|
-
const SIMULATION_HEADERS_DEFAULT = {
|
|
9
|
-
'X-Api-Version': '2023-06-05',
|
|
10
|
-
};
|
|
11
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
|
-
export const createSimulationService = ({ apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS_DEFAULT, serviceProvider = SERVICE_PROVIDER_DEFAULT, shouldSimulate = true, }) => ({
|
|
13
|
-
simulateTransaction: async ({ transaction, asset, origin, }) => {
|
|
14
|
-
const simulationResult = createEmptySimulationResult({
|
|
15
|
-
asset,
|
|
16
|
-
});
|
|
17
|
-
simulationResult.balanceChanges.willPayFee.push({
|
|
18
|
-
balance: estimateFee({ asset, transaction }),
|
|
19
|
-
feeDetails: getTxFeeDetails(transaction),
|
|
20
|
-
});
|
|
21
|
-
if (!transaction.to) {
|
|
22
|
-
return simulationResult;
|
|
23
|
-
}
|
|
24
|
-
if (!shouldSimulate) {
|
|
25
|
-
tryEstimatingChangesLocally({ asset, simulationResult, transaction });
|
|
26
|
-
return simulationResult;
|
|
27
|
-
}
|
|
28
|
-
await simulateTransaction({
|
|
29
|
-
transaction,
|
|
30
|
-
apiEndpoint,
|
|
31
|
-
origin,
|
|
32
|
-
simulationResult,
|
|
33
|
-
headers,
|
|
34
|
-
assetName: asset.name,
|
|
35
|
-
});
|
|
36
|
-
simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
|
|
37
|
-
return simulationResult;
|
|
38
|
-
},
|
|
39
|
-
scanDomains: createScanDomains({ url: apiEndpoint, headers }),
|
|
40
|
-
});
|