@exodus/web3-ethereum 9.0.0 → 9.2.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,7 +1,7 @@
|
|
|
1
1
|
import { fetchGasLimit, getNonce as apiGetNonce, getServer, } from '@exodus/ethereum-api';
|
|
2
2
|
import BN from 'bn.js';
|
|
3
3
|
const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
4
|
-
return ({ assetName, origin, getAsset, getAddress: _getAddress, getPrivateKey: _getPrivateKey, getFeeData: getFeeConfig, getActiveWalletAccount, simulateEthereumTransactions, }) => {
|
|
4
|
+
return ({ assetName, origin, getAsset, getAddress: _getAddress, getPrivateKey: _getPrivateKey, getFeeData: getFeeConfig, getCustomFeeRate, getActiveWalletAccount, simulateEthereumTransactions, }) => {
|
|
5
5
|
const asset = getAsset(assetName);
|
|
6
6
|
const server = getServer(asset);
|
|
7
7
|
const forwardRequest = async ({ method, params }) => {
|
|
@@ -53,6 +53,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
53
53
|
const { eip1559Enabled, tipGasPrice, gasPrice: _gasPrice, } = await getFeeConfig({
|
|
54
54
|
assetName,
|
|
55
55
|
});
|
|
56
|
+
// gasPrice is actually maxFeePerGas if eip1559 is true
|
|
56
57
|
const gasPrice = `0x${_gasPrice.toBaseNumber().toString(16)}`;
|
|
57
58
|
const feeData = {
|
|
58
59
|
gasPrice,
|
|
@@ -65,6 +66,35 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
65
66
|
}
|
|
66
67
|
return feeData;
|
|
67
68
|
};
|
|
69
|
+
const getCustomFeeData = async () => {
|
|
70
|
+
const _maxFeePerGas = await getCustomFeeRate?.();
|
|
71
|
+
if (!_maxFeePerGas) {
|
|
72
|
+
// The user did not select a custom fee rate or
|
|
73
|
+
// we didn't supply the function, eitherway nothing should happen.
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const { eip1559Enabled, baseFeePerGas } = await getFeeConfig({
|
|
77
|
+
assetName,
|
|
78
|
+
});
|
|
79
|
+
const maxFeePerGas = `0x${_maxFeePerGas.toBaseNumber().toString(16)}`;
|
|
80
|
+
const feeData = {
|
|
81
|
+
// If no eip1559 support, so set it to the max
|
|
82
|
+
// Otherwise ignored
|
|
83
|
+
gasPrice: maxFeePerGas,
|
|
84
|
+
};
|
|
85
|
+
if (eip1559Enabled) {
|
|
86
|
+
feeData.maxFeePerGas = maxFeePerGas;
|
|
87
|
+
// If our custom fee rate is higher than the base fee rate
|
|
88
|
+
// then compute the priority / tip fee.
|
|
89
|
+
if (baseFeePerGas && _maxFeePerGas.gt(baseFeePerGas)) {
|
|
90
|
+
const maxPriorityFeePerGas = _maxFeePerGas.sub(baseFeePerGas);
|
|
91
|
+
feeData.maxPriorityFeePerGas = `0x${maxPriorityFeePerGas
|
|
92
|
+
.toBaseNumber()
|
|
93
|
+
.toString(16)}`;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return feeData;
|
|
97
|
+
};
|
|
68
98
|
const trackWalletWatchAssetUse = async (assetDetails) => {
|
|
69
99
|
// TODO: do we still need this? If yes, this ...assetDetails expansion is no bueno
|
|
70
100
|
// why is this not always returning true in browser?
|
|
@@ -86,6 +116,7 @@ const createEvmDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
86
116
|
getNonce,
|
|
87
117
|
getFeeData,
|
|
88
118
|
getEstimatedGas,
|
|
119
|
+
getCustomFeeData,
|
|
89
120
|
onEthWalletWatchAssetRequest: trackWalletWatchAssetUse,
|
|
90
121
|
simulateEthereumTransactions,
|
|
91
122
|
};
|
|
@@ -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, simulateEthereumTransactions, scanDomains, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = async () => true, getAsset, getOrigin, } = deps;
|
|
65
|
+
const { chainId, isTrusted, isAutoApproved, ensureTrusted, approveConnection, approveMessage, approveTransactions, forwardRequest, getAddress, getPrivateKey, getEstimatedGas, getCustomFeeData, getFeeData, getNonce, sendRawTransaction, simulateEthereumTransactions, scanDomains, onTransactionsSigned = () => { }, onEthWalletWatchAssetRequest = () => { }, isUnlocked = () => true, ensureUnlocked = async () => true, getAsset, getOrigin, } = deps;
|
|
66
66
|
const network = `evm:${chainId}`;
|
|
67
67
|
async function assertTrusted() {
|
|
68
68
|
const trusted = await isTrusted();
|
|
@@ -72,18 +72,19 @@ export function exposeHandlers(rpc, deps) {
|
|
|
72
72
|
}
|
|
73
73
|
async function prepareTransaction(transaction) {
|
|
74
74
|
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = await getFeeData();
|
|
75
|
+
const eip1559Enabled = maxFeePerGas !== undefined && maxPriorityFeePerGas !== undefined;
|
|
75
76
|
const preparedTransaction = { ...transaction };
|
|
76
77
|
preparedTransaction.nonce = await getNonce();
|
|
77
78
|
if (!transaction.value) {
|
|
78
79
|
preparedTransaction.value = '0x0';
|
|
79
80
|
}
|
|
80
|
-
if (!transaction.gasPrice) {
|
|
81
|
+
if (!transaction.gasPrice && !eip1559Enabled) {
|
|
81
82
|
preparedTransaction.gasPrice = gasPrice;
|
|
82
83
|
}
|
|
83
|
-
if (!transaction.maxFeePerGas &&
|
|
84
|
+
if (!transaction.maxFeePerGas && eip1559Enabled) {
|
|
84
85
|
preparedTransaction.maxFeePerGas = maxFeePerGas;
|
|
85
86
|
}
|
|
86
|
-
if (!transaction.maxPriorityFeePerGas &&
|
|
87
|
+
if (!transaction.maxPriorityFeePerGas && eip1559Enabled) {
|
|
87
88
|
preparedTransaction.maxPriorityFeePerGas = maxPriorityFeePerGas;
|
|
88
89
|
}
|
|
89
90
|
if (!transaction.data) {
|
|
@@ -95,6 +96,16 @@ export function exposeHandlers(rpc, deps) {
|
|
|
95
96
|
}
|
|
96
97
|
return preparedTransaction;
|
|
97
98
|
}
|
|
99
|
+
async function applyCustomFeeRate(transaction) {
|
|
100
|
+
const feeData = await getCustomFeeData();
|
|
101
|
+
if (feeData) {
|
|
102
|
+
const { gasPrice, maxFeePerGas, maxPriorityFeePerGas } = feeData;
|
|
103
|
+
return { ...transaction, gasPrice, maxFeePerGas, maxPriorityFeePerGas };
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
return transaction;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
98
109
|
function validateTransaction(transaction) {
|
|
99
110
|
const gasKeys = [
|
|
100
111
|
'gas',
|
|
@@ -130,9 +141,10 @@ export function exposeHandlers(rpc, deps) {
|
|
|
130
141
|
origin,
|
|
131
142
|
});
|
|
132
143
|
await approve(approveTransactions, network, simulatedChanges);
|
|
144
|
+
const modifiedTransaction = await applyCustomFeeRate(preparedTransaction);
|
|
133
145
|
const privateKey = await getPrivateKey();
|
|
134
|
-
const signedTransaction = signTransaction({ ...
|
|
135
|
-
const isEIP1559Enabled = !!
|
|
146
|
+
const signedTransaction = signTransaction({ ...modifiedTransaction, chainId }, privateKey);
|
|
147
|
+
const isEIP1559Enabled = !!modifiedTransaction.maxFeePerGas;
|
|
136
148
|
const transactionId = getTransactionId(signedTransaction, isEIP1559Enabled);
|
|
137
149
|
onTransactionsSigned(network, [transactionId]);
|
|
138
150
|
return `0x${signedTransaction.toString('hex')}`;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import type { EthAggregatedTransactionSimulationResult, EthSimulateTransactionParams, EthTransaction, EthTransactionHash, EthWalletWatchAsset } from '@exodus/web3-ethereum-utils';
|
|
3
3
|
import type { CommonDeps } from '@exodus/web3-rpc-handlers';
|
|
4
|
-
import type { Asset, IAnalyticsModule, IBlockchainMetadataModule, EthereumFeeData, GetFeeDataParams, CreateSimulationServiceParams } from '@exodus/web3-types';
|
|
4
|
+
import type { Asset, IAnalyticsModule, IBlockchainMetadataModule, EthereumFeeData, GetFeeDataParams, CreateSimulationServiceParams, NumberUnit } from '@exodus/web3-types';
|
|
5
5
|
/**
|
|
6
6
|
* EVM-compatible chains.
|
|
7
7
|
*/
|
|
@@ -27,6 +27,7 @@ export interface CreateEvmDepsParams {
|
|
|
27
27
|
getActiveWalletAccount: () => Promise<string>;
|
|
28
28
|
getAsset: (assetName: string) => Asset;
|
|
29
29
|
getFeeData: ({ assetName }: GetFeeDataParams) => Promise<EthereumFeeData>;
|
|
30
|
+
getCustomFeeRate?: () => Promise<NumberUnit>;
|
|
30
31
|
getPrivateKey: (assetName: string) => Promise<{
|
|
31
32
|
privateKey: Buffer;
|
|
32
33
|
}>;
|
|
@@ -41,6 +42,7 @@ export declare type EVMDeps = {
|
|
|
41
42
|
simulateEthereumTransactions: SimulateTransactionsFn;
|
|
42
43
|
getEstimatedGas: (transaction: EthTransaction) => Promise<string>;
|
|
43
44
|
getFeeData: () => Promise<FeeData>;
|
|
45
|
+
getCustomFeeData: () => Promise<FeeData | undefined>;
|
|
44
46
|
getNonce: () => Promise<string>;
|
|
45
47
|
forwardRequest: (args: EthRequestArguments) => Promise<unknown>;
|
|
46
48
|
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": "9.
|
|
4
|
+
"version": "9.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"@exodus/currency": "^2.1.2",
|
|
34
34
|
"@exodus/ethereum-api": "^6.0.0",
|
|
35
35
|
"@exodus/web3-constants": "^1.29.0",
|
|
36
|
-
"@exodus/web3-ethereum-utils": "^3.
|
|
37
|
-
"@exodus/web3-provider": "^2.
|
|
38
|
-
"@exodus/web3-rpc-handlers": "^2.
|
|
39
|
-
"@exodus/web3-utils": "^1.
|
|
36
|
+
"@exodus/web3-ethereum-utils": "^3.7.0",
|
|
37
|
+
"@exodus/web3-provider": "^2.38.0",
|
|
38
|
+
"@exodus/web3-rpc-handlers": "^2.5.0",
|
|
39
|
+
"@exodus/web3-utils": "^1.28.0",
|
|
40
40
|
"bn.js": "^5.2.0",
|
|
41
41
|
"eth-rpc-errors": "^4.0.3"
|
|
42
42
|
},
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"@exodus/assets": "^8.0.72",
|
|
45
45
|
"@exodus/json-rpc": "^1.11.0",
|
|
46
46
|
"@exodus/schemasafe": "^1.0.0",
|
|
47
|
-
"@exodus/web3-types": "^1.
|
|
47
|
+
"@exodus/web3-types": "^1.36.0",
|
|
48
48
|
"@exodus/web3-validation": "^1.37.0",
|
|
49
49
|
"@wallet-standard/base": "^1.0.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@exodus/assets": "^8.0.72"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "ad7cf0bf015329652410c87a33327515fed9fe42"
|
|
55
55
|
}
|