@exodus/web3-ethereum-utils 1.20.0 → 1.21.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 +1 -1
- package/lib/createSimulateTransaction.js +13 -3
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/simulation/simulateTransaction.d.ts +3 -2
- package/lib/simulation/simulateTransaction.js +12 -7
- package/lib/types.d.ts +0 -1
- package/package.json +4 -4
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { EthSimulateTransactionParams } from './types.js';
|
|
2
2
|
import type { AggregatedTransactionSimulationResult, CreateSimulateTransactionParams } from '@exodus/web3-types';
|
|
3
|
-
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, }
|
|
3
|
+
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, }?: CreateSimulateTransactionParams) => ({ transaction, asset, shouldCallPreviewApi, origin, }: EthSimulateTransactionParams) => Promise<AggregatedTransactionSimulationResult>;
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { createEmptySimulationResult } from '@exodus/web3-utils';
|
|
2
2
|
import { estimateFee } from './simulation/estimateFee.js';
|
|
3
|
+
import { simulateTransaction } from './simulation/simulateTransaction.js';
|
|
3
4
|
import { tryEstimatingChangesLocally } from './simulation/tryEstimatingChangesLocally.js';
|
|
4
5
|
const SIMULATION_API_DEFAULT = 'https://simulation.a.exodus.io/simulate';
|
|
5
6
|
const SERVICE_PROVIDER_DEFAULT = 'blowfish';
|
|
7
|
+
const SIMULATION_HEADERS = {
|
|
8
|
+
'X-Api-Version': '2023-06-05',
|
|
9
|
+
};
|
|
6
10
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
-
export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, }) => async ({ transaction, asset, shouldCallPreviewApi = true, }) => {
|
|
11
|
+
export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_DEFAULT, apiEndpoint = SIMULATION_API_DEFAULT, headers = SIMULATION_HEADERS, } = {}) => async ({ transaction, asset, shouldCallPreviewApi = true, origin, }) => {
|
|
8
12
|
const simulationResult = createEmptySimulationResult({ asset });
|
|
9
13
|
simulationResult.balanceChanges.willPayFee.push({
|
|
10
14
|
balance: estimateFee({ asset, transaction }),
|
|
@@ -16,6 +20,12 @@ export const createSimulateTransaction = ({ serviceProvider = SERVICE_PROVIDER_D
|
|
|
16
20
|
tryEstimatingChangesLocally({ asset, simulationResult, transaction });
|
|
17
21
|
return simulationResult;
|
|
18
22
|
}
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
await simulateTransaction({
|
|
24
|
+
transaction,
|
|
25
|
+
apiEndpoint,
|
|
26
|
+
origin,
|
|
27
|
+
simulationResult,
|
|
28
|
+
headers,
|
|
29
|
+
});
|
|
30
|
+
return simulationResult;
|
|
21
31
|
};
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { EthSimulateTransactionParams } from '../types.js';
|
|
2
2
|
import type { AggregatedTransactionSimulationResult, CreateSimulateTransactionParams } from '@exodus/web3-types';
|
|
3
|
-
declare type SimulateTransactionParams = Required<CreateSimulateTransactionParams
|
|
3
|
+
declare type SimulateTransactionParams = Required<Pick<CreateSimulateTransactionParams, 'apiEndpoint'>> & Required<Pick<EthSimulateTransactionParams, 'transaction' | 'origin'>> & {
|
|
4
4
|
simulationResult: AggregatedTransactionSimulationResult;
|
|
5
|
+
headers?: Record<string, string>;
|
|
5
6
|
};
|
|
6
|
-
export declare const simulateTransaction: ({ transaction, apiEndpoint, origin, simulationResult, }: SimulateTransactionParams) => Promise<void> | never;
|
|
7
|
+
export declare const simulateTransaction: ({ transaction, apiEndpoint, origin, simulationResult, headers, }: SimulateTransactionParams) => Promise<void> | never;
|
|
7
8
|
export {};
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { createCurrency, makeSimulationAPICall } from '@exodus/web3-utils';
|
|
6
6
|
const convertTransactionToApiPayload = (transaction, origin) => ({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
txObjects: [
|
|
8
|
+
{
|
|
9
|
+
from: transaction.from,
|
|
10
|
+
to: transaction.to,
|
|
11
|
+
data: transaction.data,
|
|
12
|
+
value: transaction.value,
|
|
13
|
+
},
|
|
14
|
+
],
|
|
13
15
|
metadata: {
|
|
14
16
|
origin,
|
|
15
17
|
},
|
|
@@ -66,6 +68,8 @@ const handleExpectedBalanceChange = (expectedBalanceChange, simulationResult) =>
|
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
70
|
if (balance.isNegative) {
|
|
71
|
+
// Convert to non-negative value.
|
|
72
|
+
balanceChange.balance = balanceChange.balance.negate();
|
|
69
73
|
willReceive.push(balanceChange);
|
|
70
74
|
}
|
|
71
75
|
else {
|
|
@@ -82,13 +86,14 @@ const simulationResultHasAssets = (expectedStateChanges) => {
|
|
|
82
86
|
}
|
|
83
87
|
return true;
|
|
84
88
|
};
|
|
85
|
-
export const simulateTransaction = async ({ transaction, apiEndpoint, origin, simulationResult, }) => {
|
|
89
|
+
export const simulateTransaction = async ({ transaction, apiEndpoint, origin, simulationResult, headers, }) => {
|
|
86
90
|
const userAddress = transaction.from;
|
|
87
91
|
const payload = convertTransactionToApiPayload(transaction, origin);
|
|
88
92
|
const response = await makeSimulationAPICall({
|
|
89
93
|
url: apiEndpoint,
|
|
90
94
|
network: 'ethereum',
|
|
91
95
|
payload,
|
|
96
|
+
headers,
|
|
92
97
|
});
|
|
93
98
|
const { expectedStateChanges = {}, error } = response.simulationResults.aggregated;
|
|
94
99
|
if (error) {
|
package/lib/types.d.ts
CHANGED
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.21.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.26.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.17.0",
|
|
35
35
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "e425fafca91cd79471b6fd4fbcd6b78a0a8d4a22"
|
|
38
38
|
}
|