@exodus/web3-ethereum-utils 2.0.2 → 3.0.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.
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare const createSimulateTransaction: ({ serviceProvider, apiEndpoint, headers, shouldSimulate, }: CreateSimulateTransactionParams) => ({ transaction, asset, origin, }: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|
|
1
|
+
import type { CreateEthSimulationServiceFn } from './types.js';
|
|
2
|
+
export declare const createSimulationService: CreateEthSimulationServiceFn;
|
|
@@ -1,37 +1,40 @@
|
|
|
1
|
-
import { createEmptySimulationResult } from '@exodus/web3-utils';
|
|
1
|
+
import { createEmptySimulationResult, createScanDomains, } 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
5
|
import { getDisplayDetails, getTxFeeDetails } from './transactions.js';
|
|
6
6
|
const SIMULATION_API_DEFAULT = 'https://simulation.a.exodus.io/simulate';
|
|
7
7
|
const SERVICE_PROVIDER_DEFAULT = 'blowfish';
|
|
8
|
-
const
|
|
8
|
+
const SIMULATION_HEADERS_DEFAULT = {
|
|
9
9
|
'X-Api-Version': '2023-06-05',
|
|
10
10
|
};
|
|
11
11
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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);
|
|
21
37
|
return simulationResult;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return simulationResult;
|
|
26
|
-
}
|
|
27
|
-
await simulateTransaction({
|
|
28
|
-
transaction,
|
|
29
|
-
apiEndpoint,
|
|
30
|
-
origin,
|
|
31
|
-
simulationResult,
|
|
32
|
-
headers,
|
|
33
|
-
assetName: asset.name,
|
|
34
|
-
});
|
|
35
|
-
simulationResult.displayDetails = getDisplayDetails(simulationResult.balanceChanges.willApprove);
|
|
36
|
-
return simulationResult;
|
|
37
|
-
};
|
|
38
|
+
},
|
|
39
|
+
scanDomains: createScanDomains({ url: apiEndpoint, headers }),
|
|
40
|
+
});
|
|
@@ -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,7 +7,7 @@ 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, 'transaction' | 'origin'>> & {
|
|
11
11
|
simulationResult: EthAggregatedTransactionSimulationResult;
|
|
12
12
|
headers?: Record<string, string>;
|
|
13
13
|
assetName: string;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AggregatedTransactionSimulationResult, BN, SimulateTransactionParams } from '@exodus/web3-types';
|
|
1
|
+
import type { AggregatedTransactionSimulationResult, CreateSimulationServiceParams, BN, ScanDomainsFn, SimulateTransactionParams } from '@exodus/web3-types';
|
|
2
2
|
export interface EthTransactionParams {
|
|
3
3
|
chainId: string;
|
|
4
4
|
from: string;
|
|
@@ -47,3 +47,7 @@ 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": "
|
|
4
|
+
"version": "3.0.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.30.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.22.0",
|
|
35
35
|
"@metamask/eth-sig-util": "^4.0.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "5130517c87424b7118b272f053d10fb42750fa3f"
|
|
38
38
|
}
|