@exodus/web3-ethereum-utils 3.37.1 → 3.38.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.js +13 -4
- package/lib/simulation/simulateTransactions.d.ts +2 -1
- package/lib/simulation/simulateTransactions.js +4 -1
- package/lib/simulation/tryEstimatingChangesLocally.d.ts +1 -1
- package/lib/simulation/tryEstimatingChangesLocally.js +3 -0
- package/package.json +2 -2
|
@@ -24,10 +24,19 @@ export const createSimulateTransactions = ({ apiEndpoint, headers }) => async ({
|
|
|
24
24
|
simulationResult,
|
|
25
25
|
headers,
|
|
26
26
|
});
|
|
27
|
-
if (simulationTransactionInternalResult.kind === 'error'
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
if (simulationTransactionInternalResult.kind === 'error') {
|
|
28
|
+
const simulatedLocally = tryEstimatingChangesLocally({
|
|
29
|
+
asset,
|
|
30
|
+
simulationResult,
|
|
31
|
+
transaction,
|
|
32
|
+
});
|
|
33
|
+
if (!simulatedLocally) {
|
|
34
|
+
simulationResult.warnings.push({
|
|
35
|
+
kind: 'INTERNAL_ERROR',
|
|
36
|
+
severity: 'HIGH',
|
|
37
|
+
message: 'Balance changes cannot be estimated.',
|
|
38
|
+
});
|
|
39
|
+
}
|
|
31
40
|
return simulationResult;
|
|
32
41
|
}
|
|
33
42
|
simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
|
|
@@ -5,7 +5,8 @@ declare type SimulateTransactionParams = Required<Pick<CreateSimulateTransaction
|
|
|
5
5
|
headers?: Record<string, string>;
|
|
6
6
|
};
|
|
7
7
|
export declare const enum SimulationErrorMessages {
|
|
8
|
-
'SimulationNotSupported' = 0
|
|
8
|
+
'SimulationNotSupported' = 0,
|
|
9
|
+
'APICallFailed' = 1
|
|
9
10
|
}
|
|
10
11
|
export declare const simulateTransactions: ({ transactions, apiEndpoint, origin, simulationResult, headers, asset, }: SimulateTransactionParams) => SimulateTransactionsInternalResult<undefined, SimulationErrorMessages>;
|
|
11
12
|
export {};
|
|
@@ -145,7 +145,10 @@ export const simulateTransactions = async ({ transactions, apiEndpoint, origin,
|
|
|
145
145
|
headers,
|
|
146
146
|
});
|
|
147
147
|
if (!response) {
|
|
148
|
-
return
|
|
148
|
+
return {
|
|
149
|
+
kind: 'error',
|
|
150
|
+
error: 1 /* SimulationErrorMessages.APICallFailed */,
|
|
151
|
+
};
|
|
149
152
|
}
|
|
150
153
|
simulationResult.metadata.simulatedLocally = false;
|
|
151
154
|
const { expectedStateChanges = {}, error } = response.simulationResults.aggregated;
|
|
@@ -3,6 +3,7 @@ import { getCreateCurrencyParams } from './common.js';
|
|
|
3
3
|
import { estimateSimpleTransfer, NotSimpleTransferError, } from './estimateSimpleTransfer.js';
|
|
4
4
|
/*
|
|
5
5
|
Mutates the provided 'simulationResult' adding a 'willSend' entry if the transaction is a simple transfer.
|
|
6
|
+
The function also returns a boolean indicating whether the local simulation was possible (e.g., if any balance changes were made).
|
|
6
7
|
*/
|
|
7
8
|
export const tryEstimatingChangesLocally = ({ asset, simulationResult, transaction, }) => {
|
|
8
9
|
try {
|
|
@@ -13,11 +14,13 @@ export const tryEstimatingChangesLocally = ({ asset, simulationResult, transacti
|
|
|
13
14
|
simulationResult.balanceChanges.willSend.push({
|
|
14
15
|
balance: actualTransferValue,
|
|
15
16
|
});
|
|
17
|
+
return true;
|
|
16
18
|
}
|
|
17
19
|
catch (err) {
|
|
18
20
|
const expectedError = err instanceof NotSimpleTransferError;
|
|
19
21
|
if (!expectedError) {
|
|
20
22
|
// ToDo: accept a logger dep and log an error here
|
|
21
23
|
}
|
|
24
|
+
return false;
|
|
22
25
|
}
|
|
23
26
|
};
|
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.38.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"@exodus/web3-utils": "^1.48.2",
|
|
37
37
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "212dd8249e074525316708335355fda305aa691f"
|
|
40
40
|
}
|