@exodus/web3-ethereum 3.2.0 → 4.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.
- package/lib/provider/provider.js +1 -1
- package/lib/rpc-handlers/createEvmDeps.js +2 -0
- package/lib/rpc-handlers/exposeHandlers.js +7 -2
- package/lib/rpc-handlers/index.js +1 -0
- package/lib/simulation/simulation.d.ts +4 -5
- package/lib/simulation/simulation.js +10 -33
- package/lib/types.d.ts +1 -0
- package/package.json +7 -7
package/lib/provider/provider.js
CHANGED
|
@@ -69,9 +69,9 @@ export class EthereumProvider extends BaseProvider {
|
|
|
69
69
|
this.#handleConnect(chainId);
|
|
70
70
|
this.#handleChainChanged(chainId.toLowerCase());
|
|
71
71
|
const accounts = await this.#getAccounts();
|
|
72
|
-
this.#handleAccountsChanged(accounts);
|
|
73
72
|
this.#initialized = true;
|
|
74
73
|
this.#initializePromise = null;
|
|
74
|
+
this.#handleAccountsChanged(accounts);
|
|
75
75
|
};
|
|
76
76
|
#awaitInitialized = async () => {
|
|
77
77
|
if (this.#initializePromise) {
|
|
@@ -77,6 +77,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
77
77
|
});
|
|
78
78
|
return true;
|
|
79
79
|
};
|
|
80
|
+
const getOrigin = () => origin;
|
|
80
81
|
return {
|
|
81
82
|
chainId: 'undefined',
|
|
82
83
|
forwardRequest,
|
|
@@ -87,6 +88,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
87
88
|
getFeeData,
|
|
88
89
|
getEstimatedGas,
|
|
89
90
|
onEthWalletWatchAssetRequest: trackWalletWatchAssetUse,
|
|
91
|
+
getOrigin,
|
|
90
92
|
};
|
|
91
93
|
};
|
|
92
94
|
};
|
|
@@ -62,7 +62,7 @@ const isValidGasLimitValue = (value) => {
|
|
|
62
62
|
return proposedGasLimit.lte(maximumBlockGasLimit);
|
|
63
63
|
};
|
|
64
64
|
export function exposeHandlers(rpc, deps) {
|
|
65
|
-
const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getFeeData, getNonce, sendRawTransaction, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = () => true, getAsset, } = deps;
|
|
65
|
+
const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getFeeData, getNonce, sendRawTransaction, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = () => true, getAsset, getOrigin, } = deps;
|
|
66
66
|
const network = `evm:${chainId}`;
|
|
67
67
|
async function assertTrusted() {
|
|
68
68
|
const trusted = await isTrusted();
|
|
@@ -123,7 +123,12 @@ export function exposeHandlers(rpc, deps) {
|
|
|
123
123
|
const asset = await getAsset(network);
|
|
124
124
|
const preparedTransaction = await prepareTransaction(transaction);
|
|
125
125
|
validateTransaction(preparedTransaction);
|
|
126
|
-
const
|
|
126
|
+
const origin = getOrigin();
|
|
127
|
+
const simulatedChanges = await simulateTransaction({
|
|
128
|
+
asset,
|
|
129
|
+
transaction: preparedTransaction,
|
|
130
|
+
origin,
|
|
131
|
+
});
|
|
127
132
|
await approve(approveTransactions, network, simulatedChanges);
|
|
128
133
|
const privateKey = await getPrivateKey();
|
|
129
134
|
const signedTransaction = signTransaction({ ...preparedTransaction, chainId }, privateKey);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
export declare const simulateTransaction: (asset: Asset, transaction: EthTransaction) => Promise<{
|
|
1
|
+
import type { EthSimulateTransactionParams } from '@exodus/web3-ethereum-utils';
|
|
2
|
+
import type { NumberUnit } from '@exodus/web3-types';
|
|
3
|
+
export declare const simulateTransaction: ({ asset, transaction, origin, }: EthSimulateTransactionParams) => Promise<{
|
|
5
4
|
baseAssetName: string;
|
|
6
5
|
advancedDetails: never[];
|
|
7
|
-
balanceChanges:
|
|
6
|
+
balanceChanges: import("@exodus/web3-types").BalanceChanges;
|
|
8
7
|
displayInfo: {
|
|
9
8
|
title: string;
|
|
10
9
|
};
|
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createSimulateTransaction } from '@exodus/web3-ethereum-utils';
|
|
2
2
|
import { SIMULATION_SUPPORTED_ASSET_NAMES } from './constant.js';
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
let balanceChanges = {
|
|
6
|
-
willReceive: [],
|
|
7
|
-
willSend: [],
|
|
8
|
-
willApprove: [],
|
|
9
|
-
};
|
|
10
|
-
if (isEthTransferTx(transaction)) {
|
|
11
|
-
const txValue = hexToBN(transaction.value).toString();
|
|
12
|
-
balanceChanges.willSend.push({
|
|
13
|
-
balance: asset.currency.baseUnit(txValue),
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
try {
|
|
18
|
-
const sideEffect = await retrieveSideEffects({
|
|
19
|
-
asset,
|
|
20
|
-
shouldSimulate,
|
|
21
|
-
transaction,
|
|
22
|
-
});
|
|
23
|
-
if (sideEffect) {
|
|
24
|
-
balanceChanges = formatAccounts(sideEffect);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
console.error('Ethereum transaction simulation failed.', error);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return balanceChanges;
|
|
32
|
-
};
|
|
3
|
+
import { getEthereumDisplayInfo, hexToBN } from './utils.js';
|
|
4
|
+
const simulateTransactionV2 = createSimulateTransaction();
|
|
33
5
|
const getTxFeeDetails = (asset, transaction) => {
|
|
34
6
|
const maxFeePerGasBn = transaction.maxFeePerGas
|
|
35
7
|
? hexToBN(transaction.maxFeePerGas)
|
|
@@ -45,10 +17,15 @@ const getTxFeeDetails = (asset, transaction) => {
|
|
|
45
17
|
},
|
|
46
18
|
};
|
|
47
19
|
};
|
|
48
|
-
export const simulateTransaction = async (asset, transaction) => {
|
|
20
|
+
export const simulateTransaction = async ({ asset, transaction, origin, }) => {
|
|
49
21
|
const baseAssetName = asset.name;
|
|
50
22
|
const shouldSimulate = SIMULATION_SUPPORTED_ASSET_NAMES.includes(baseAssetName);
|
|
51
|
-
const balanceChanges = await
|
|
23
|
+
const { balanceChanges } = await simulateTransactionV2({
|
|
24
|
+
transaction,
|
|
25
|
+
asset,
|
|
26
|
+
origin,
|
|
27
|
+
shouldCallPreviewApi: shouldSimulate,
|
|
28
|
+
});
|
|
52
29
|
const { txFee, txFeeDetails } = getTxFeeDetails(asset, transaction);
|
|
53
30
|
const displayInfo = getEthereumDisplayInfo(balanceChanges);
|
|
54
31
|
return {
|
package/lib/types.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare type EVMDeps = {
|
|
|
37
37
|
sendRawTransaction: (rawTransaction: string) => Promise<EthTransactionHash>;
|
|
38
38
|
getEstimatedGas: (transaction: EthTransaction) => Promise<string>;
|
|
39
39
|
getFeeData: () => Promise<FeeData>;
|
|
40
|
+
getOrigin: () => string;
|
|
40
41
|
getNonce: () => Promise<string>;
|
|
41
42
|
forwardRequest: (args: EthRequestArguments) => Promise<unknown>;
|
|
42
43
|
onEthWalletWatchAssetRequest?: (assetDetails: EthWalletWatchAsset) => Promise<boolean>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/web3-ethereum",
|
|
3
3
|
"description": "Apps connectivity library for EVM-compatible chains.",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"@exodus/currency": "^2.1.2",
|
|
35
35
|
"@exodus/ethereum-api": "^6.0.0",
|
|
36
36
|
"@exodus/web3-constants": "^1.29.0",
|
|
37
|
-
"@exodus/web3-ethereum-utils": "^1.
|
|
38
|
-
"@exodus/web3-provider": "^2.
|
|
39
|
-
"@exodus/web3-rpc-handlers": "^1.
|
|
40
|
-
"@exodus/web3-utils": "^1.
|
|
37
|
+
"@exodus/web3-ethereum-utils": "^1.21.0",
|
|
38
|
+
"@exodus/web3-provider": "^2.28.0",
|
|
39
|
+
"@exodus/web3-rpc-handlers": "^1.3.0",
|
|
40
|
+
"@exodus/web3-utils": "^1.17.0",
|
|
41
41
|
"bn.js": "^5.2.0",
|
|
42
42
|
"eth-rpc-errors": "^4.0.3"
|
|
43
43
|
},
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"@exodus/assets": "^8.0.72",
|
|
46
46
|
"@exodus/json-rpc": "^1.11.0",
|
|
47
47
|
"@exodus/schemasafe": "^1.0.0",
|
|
48
|
-
"@exodus/web3-types": "^1.
|
|
48
|
+
"@exodus/web3-types": "^1.26.0",
|
|
49
49
|
"@exodus/web3-validation": "^1.35.0",
|
|
50
50
|
"@wallet-standard/base": "^1.0.1"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@exodus/assets": "^8.0.72"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "e425fafca91cd79471b6fd4fbcd6b78a0a8d4a22"
|
|
56
56
|
}
|