@toruslabs/ethereum-controllers 8.17.1 → 9.1.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/dist/lib.cjs/Account/AccountTrackerController.js +15 -7
- package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +22 -26
- package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.cjs/Eip5792/walletSendCalls.js +6 -7
- package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.cjs/Gas/GasFeeController.js +2 -2
- package/dist/lib.cjs/Keyring/KeyringController.js +68 -41
- package/dist/lib.cjs/Message/utils.js +14 -16
- package/dist/lib.cjs/Network/NetworkController.js +7 -9
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +373 -285
- package/dist/lib.cjs/Network/createJsonRpcClient.js +21 -21
- package/dist/lib.cjs/Nfts/NftHandler.js +54 -12
- package/dist/lib.cjs/Nfts/NftsController.js +1 -4
- package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
- package/dist/lib.cjs/Tokens/TokenHandler.js +39 -7
- package/dist/lib.cjs/Tokens/TokensController.js +15 -7
- package/dist/lib.cjs/Transaction/TransactionController.js +17 -20
- package/dist/lib.cjs/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.cjs/Transaction/TransactionUtils.js +44 -39
- package/dist/lib.cjs/index.js +9 -0
- package/dist/lib.cjs/types/Account/AccountTrackerController.d.ts +1 -1
- package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +4 -6
- package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +1 -1
- package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +1 -1
- package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +4 -4
- package/dist/lib.cjs/types/Network/NetworkController.d.ts +1 -1
- package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +28 -90
- package/dist/lib.cjs/types/Network/createJsonRpcClient.d.ts +4 -4
- package/dist/lib.cjs/types/Network/index.d.ts +5 -0
- package/dist/lib.cjs/types/Network/interfaces.d.ts +58 -0
- package/dist/lib.cjs/types/Nfts/NftHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Nfts/NftsController.d.ts +0 -1
- package/dist/lib.cjs/types/Tokens/TokenHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Tokens/TokensController.d.ts +1 -1
- package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +11 -3
- package/dist/lib.cjs/types/index.d.ts +1 -3
- package/dist/lib.cjs/types/utils/abis.d.ts +544 -99
- package/dist/lib.cjs/types/utils/eip5792Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/eip7702Types.d.ts +1 -1
- package/dist/lib.cjs/types/utils/interfaces.d.ts +207 -4
- package/dist/lib.cjs/types/utils/transaction.d.ts +1 -1
- package/dist/lib.cjs/types/utils/viem.d.ts +8 -0
- package/dist/lib.cjs/utils/abis.js +12 -0
- package/dist/lib.cjs/utils/conversionUtils.js +3 -4
- package/dist/lib.cjs/utils/helpers.js +8 -7
- package/dist/lib.cjs/utils/transaction.js +7 -11
- package/dist/lib.cjs/utils/viem.js +214 -0
- package/dist/lib.esm/Account/AccountTrackerController.js +15 -7
- package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +24 -28
- package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.esm/Eip5792/walletSendCalls.js +6 -7
- package/dist/lib.esm/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.esm/Gas/GasFeeController.js +2 -2
- package/dist/lib.esm/Keyring/KeyringController.js +68 -42
- package/dist/lib.esm/Message/utils.js +14 -16
- package/dist/lib.esm/Network/NetworkController.js +8 -10
- package/dist/lib.esm/Network/createEthereumMiddleware.js +387 -290
- package/dist/lib.esm/Network/createJsonRpcClient.js +22 -22
- package/dist/lib.esm/Nfts/NftHandler.js +54 -12
- package/dist/lib.esm/Nfts/NftsController.js +1 -4
- package/dist/lib.esm/Preferences/PreferencesController.js +2 -2
- package/dist/lib.esm/Tokens/TokenHandler.js +39 -7
- package/dist/lib.esm/Tokens/TokensController.js +15 -7
- package/dist/lib.esm/Transaction/TransactionController.js +18 -21
- package/dist/lib.esm/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.esm/Transaction/TransactionUtils.js +44 -40
- package/dist/lib.esm/index.js +4 -3
- package/dist/lib.esm/utils/abis.js +12 -0
- package/dist/lib.esm/utils/conversionUtils.js +3 -4
- package/dist/lib.esm/utils/helpers.js +8 -7
- package/dist/lib.esm/utils/interfaces.js +64 -0
- package/dist/lib.esm/utils/transaction.js +7 -11
- package/dist/lib.esm/utils/viem.js +214 -0
- package/package.json +14 -19
- package/dist/ethereumControllers.umd.min.js +0 -2
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -50
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import { createFetchMiddleware, createInflightCacheMiddleware } from '@toruslabs/base-controllers';
|
|
3
|
-
import {
|
|
3
|
+
import { providerFromMiddlewareV2, JRPCEngineV2 } from '@web3auth/auth';
|
|
4
4
|
import { PollingBlockTracker } from '../Block/PollingBlockTracker.js';
|
|
5
5
|
import { transactionDecoder } from '../utils/transaction.js';
|
|
6
6
|
import { cacheIdentifierForRequest } from './cacheIdentifier.js';
|
|
7
7
|
|
|
8
8
|
function createChainIdMiddleware(chainId) {
|
|
9
|
-
return (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return async ({
|
|
10
|
+
request,
|
|
11
|
+
next
|
|
12
|
+
}) => {
|
|
13
|
+
if (request.method === "eth_chainId") {
|
|
14
|
+
return chainId;
|
|
13
15
|
}
|
|
14
|
-
if (
|
|
16
|
+
if (request.method === "net_version") {
|
|
15
17
|
// convert to decimal
|
|
16
|
-
|
|
17
|
-
return end();
|
|
18
|
+
return Number.parseInt(chainId, 16).toString(10);
|
|
18
19
|
}
|
|
19
20
|
return next();
|
|
20
21
|
};
|
|
21
22
|
}
|
|
22
23
|
function createProviderConfigMiddleware(providerConfig) {
|
|
23
|
-
return (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
return async ({
|
|
25
|
+
request,
|
|
26
|
+
next
|
|
27
|
+
}) => {
|
|
28
|
+
if (request.method === "eth_provider_config") {
|
|
29
|
+
return providerConfig;
|
|
27
30
|
}
|
|
28
31
|
return next();
|
|
29
32
|
};
|
|
@@ -39,7 +42,7 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
|
|
|
39
42
|
analytics,
|
|
40
43
|
transactionDecoder
|
|
41
44
|
});
|
|
42
|
-
const blockProvider =
|
|
45
|
+
const blockProvider = providerFromMiddlewareV2(fetchMiddleware);
|
|
43
46
|
const blockTracker = new PollingBlockTracker({
|
|
44
47
|
config: _objectSpread(_objectSpread({}, networkConfig), {}, {
|
|
45
48
|
provider: blockProvider
|
|
@@ -47,15 +50,12 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
|
|
|
47
50
|
state: {},
|
|
48
51
|
idleTimeTracker
|
|
49
52
|
});
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}),
|
|
57
|
-
// createBlockTrackerInspectorMiddleware({ blockTracker }),
|
|
58
|
-
fetchMiddleware]);
|
|
53
|
+
const jrpcEngineV2 = JRPCEngineV2.create({
|
|
54
|
+
middleware: [createChainIdMiddleware(chainId), createProviderConfigMiddleware(providerConfig), createInflightCacheMiddleware({
|
|
55
|
+
cacheIdentifierForRequest
|
|
56
|
+
}), fetchMiddleware]
|
|
57
|
+
});
|
|
58
|
+
const networkMiddleware = jrpcEngineV2.asMiddleware();
|
|
59
59
|
return {
|
|
60
60
|
networkMiddleware,
|
|
61
61
|
blockTracker
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { get } from '@toruslabs/http-helpers';
|
|
4
|
-
import { Contract } from 'ethers';
|
|
5
4
|
import log from 'loglevel';
|
|
5
|
+
import { createPublicClient, custom } from 'viem';
|
|
6
6
|
import { erc721Abi, erc1155Abi } from '../utils/abis.js';
|
|
7
7
|
import { CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC1155, OLD_ERC721_LIST, ERC721_INTERFACE_ID, ERC1155_INTERFACE_ID } from '../utils/constants.js';
|
|
8
8
|
import { sanitizeNftMetdataUrl } from '../utils/helpers.js';
|
|
@@ -31,6 +31,7 @@ class NftHandler {
|
|
|
31
31
|
_defineProperty(this, "chainId", void 0);
|
|
32
32
|
_defineProperty(this, "provider", void 0);
|
|
33
33
|
_defineProperty(this, "isSpecial", void 0);
|
|
34
|
+
_defineProperty(this, "publicClient", void 0);
|
|
34
35
|
this.chainId = chainId;
|
|
35
36
|
this.contractAddress = contractAddress;
|
|
36
37
|
this.contractImage = contractImage;
|
|
@@ -38,6 +39,9 @@ class NftHandler {
|
|
|
38
39
|
this.contractSymbol = contractSymbol;
|
|
39
40
|
this.nftStandard = nftStandard;
|
|
40
41
|
this.provider = provider;
|
|
42
|
+
this.publicClient = createPublicClient({
|
|
43
|
+
transport: custom(this.provider)
|
|
44
|
+
});
|
|
41
45
|
this.contractDescription = contractDescription;
|
|
42
46
|
this.contractFallbackLogo = contractFallbackLogo;
|
|
43
47
|
this.contractSupply = contractSupply;
|
|
@@ -101,8 +105,17 @@ class NftHandler {
|
|
|
101
105
|
}
|
|
102
106
|
if (!this.contractName || !this.contractSymbol || !this.contractDescription) {
|
|
103
107
|
const abi = this.nftStandard === CONTRACT_TYPE_ERC721 ? erc721Abi : erc1155Abi;
|
|
104
|
-
const
|
|
105
|
-
|
|
108
|
+
const [name, symbol] = await Promise.all([this.publicClient.readContract({
|
|
109
|
+
address: this.contractAddress,
|
|
110
|
+
abi,
|
|
111
|
+
functionName: "name",
|
|
112
|
+
authorizationList: undefined
|
|
113
|
+
}), this.publicClient.readContract({
|
|
114
|
+
address: this.contractAddress,
|
|
115
|
+
abi,
|
|
116
|
+
functionName: "symbol",
|
|
117
|
+
authorizationList: undefined
|
|
118
|
+
})]);
|
|
106
119
|
returnNft.contractName = name;
|
|
107
120
|
returnNft.contractSymbol = symbol;
|
|
108
121
|
if (!this.contractName) this.contractName = name;
|
|
@@ -115,14 +128,25 @@ class NftHandler {
|
|
|
115
128
|
standard
|
|
116
129
|
} = await this.checkNftStandard();
|
|
117
130
|
const abi = standard === CONTRACT_TYPE_ERC721 ? erc721Abi : erc1155Abi;
|
|
118
|
-
const contract = new Contract(this.contractAddress, abi, this.provider);
|
|
119
131
|
if (standard === CONTRACT_TYPE_ERC1155) {
|
|
120
|
-
const balance = await
|
|
121
|
-
|
|
132
|
+
const balance = await this.publicClient.readContract({
|
|
133
|
+
address: this.contractAddress,
|
|
134
|
+
abi,
|
|
135
|
+
functionName: "balanceOf",
|
|
136
|
+
args: [userAddress, BigInt(tokenId)],
|
|
137
|
+
authorizationList: undefined
|
|
138
|
+
});
|
|
139
|
+
return String(balance);
|
|
122
140
|
}
|
|
123
141
|
let owner = "";
|
|
124
142
|
try {
|
|
125
|
-
owner = await
|
|
143
|
+
owner = await this.publicClient.readContract({
|
|
144
|
+
address: this.contractAddress,
|
|
145
|
+
abi,
|
|
146
|
+
functionName: "ownerOf",
|
|
147
|
+
args: [BigInt(tokenId)],
|
|
148
|
+
authorizationList: undefined
|
|
149
|
+
});
|
|
126
150
|
} catch {
|
|
127
151
|
throw new Error("Token id doesn't exists");
|
|
128
152
|
}
|
|
@@ -164,14 +188,32 @@ class NftHandler {
|
|
|
164
188
|
}
|
|
165
189
|
async contractSupportsInterface(standard, interfaceId) {
|
|
166
190
|
const abi = standard === CONTRACT_TYPE_ERC721 ? erc721Abi : erc1155Abi;
|
|
167
|
-
|
|
168
|
-
|
|
191
|
+
return await this.publicClient.readContract({
|
|
192
|
+
address: this.contractAddress,
|
|
193
|
+
abi,
|
|
194
|
+
functionName: "supportsInterface",
|
|
195
|
+
args: [interfaceId],
|
|
196
|
+
authorizationList: undefined
|
|
197
|
+
});
|
|
169
198
|
}
|
|
170
199
|
async getCollectibleTokenURI(tokenId, standard = CONTRACT_TYPE_ERC721) {
|
|
171
|
-
const method = standard === CONTRACT_TYPE_ERC721 ? "tokenURI" : "uri";
|
|
172
200
|
const abi = standard === CONTRACT_TYPE_ERC721 ? erc721Abi : erc1155Abi;
|
|
173
|
-
|
|
174
|
-
|
|
201
|
+
if (standard === CONTRACT_TYPE_ERC721) {
|
|
202
|
+
return await this.publicClient.readContract({
|
|
203
|
+
address: this.contractAddress,
|
|
204
|
+
abi,
|
|
205
|
+
functionName: "tokenURI",
|
|
206
|
+
args: [BigInt(tokenId)],
|
|
207
|
+
authorizationList: undefined
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return await this.publicClient.readContract({
|
|
211
|
+
address: this.contractAddress,
|
|
212
|
+
abi,
|
|
213
|
+
functionName: "uri",
|
|
214
|
+
args: [BigInt(tokenId)],
|
|
215
|
+
authorizationList: undefined
|
|
216
|
+
});
|
|
175
217
|
}
|
|
176
218
|
}
|
|
177
219
|
|
|
@@ -2,7 +2,6 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { BaseController, PollingManager } from '@toruslabs/base-controllers';
|
|
4
4
|
import deepmerge from 'deepmerge';
|
|
5
|
-
import { BrowserProvider } from 'ethers';
|
|
6
5
|
import log from 'loglevel';
|
|
7
6
|
import { MM_NFT_API_SUPPORTED_CHAINS } from '../utils/constants.js';
|
|
8
7
|
import { NftHandler } from './NftHandler.js';
|
|
@@ -25,12 +24,10 @@ class NftsController extends BaseController {
|
|
|
25
24
|
});
|
|
26
25
|
_defineProperty(this, "name", "NftsController");
|
|
27
26
|
_defineProperty(this, "provider", void 0);
|
|
28
|
-
_defineProperty(this, "ethersProvider", void 0);
|
|
29
27
|
_defineProperty(this, "getCustomNfts", void 0);
|
|
30
28
|
_defineProperty(this, "getSimpleHashNfts", void 0);
|
|
31
29
|
_defineProperty(this, "pollingManager", void 0);
|
|
32
30
|
this.provider = provider;
|
|
33
|
-
this.ethersProvider = new BrowserProvider(this.provider, "any");
|
|
34
31
|
this.getCustomNfts = getCustomNfts;
|
|
35
32
|
this.getSimpleHashNfts = getSimpleHashNfts;
|
|
36
33
|
this.defaultConfig = {
|
|
@@ -174,7 +171,7 @@ class NftsController extends BaseController {
|
|
|
174
171
|
const promiseSettledResult = await Promise.allSettled(currentNetworkNfts.map(async x => {
|
|
175
172
|
try {
|
|
176
173
|
const tokenInstance = new NftHandler(_objectSpread(_objectSpread({}, x), {}, {
|
|
177
|
-
provider: this.
|
|
174
|
+
provider: this.provider
|
|
178
175
|
}));
|
|
179
176
|
const contractData = await tokenInstance.getContractMetadata();
|
|
180
177
|
const assetData = await Promise.allSettled(x.assets.map(y => tokenInstance.getNftMetadata(userAddress, y)));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { stripHexPrefix } from '@ethereumjs/util';
|
|
3
2
|
import { BasePreferencesController, CHAIN_NAMESPACES, isUnauthorizedError, TransactionStatus } from '@toruslabs/base-controllers';
|
|
3
|
+
import { remove0x } from '@toruslabs/metadata-helpers';
|
|
4
4
|
import { Mutex } from 'async-mutex';
|
|
5
5
|
import log from 'loglevel';
|
|
6
6
|
import { MM_TOKEN_API_SUPPORTED_CHAINS, SUPPORTED_NETWORKS } from '../utils/constants.js';
|
|
@@ -302,7 +302,7 @@ class PreferencesController extends BasePreferencesController {
|
|
|
302
302
|
}
|
|
303
303
|
isChainIdSupported(address, chainId) {
|
|
304
304
|
const approveChainOptions = this.getChainOptions(address);
|
|
305
|
-
const providerConfig = approveChainOptions.find(x =>
|
|
305
|
+
const providerConfig = approveChainOptions.find(x => remove0x(x.chainId) === chainId);
|
|
306
306
|
return !!providerConfig;
|
|
307
307
|
}
|
|
308
308
|
async addChain(network) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
2
|
-
import { Contract } from 'ethers';
|
|
3
2
|
import log from 'loglevel';
|
|
3
|
+
import { createPublicClient, custom } from 'viem';
|
|
4
4
|
import { erc20Abi } from '../utils/abis.js';
|
|
5
5
|
|
|
6
6
|
class TokenHandler {
|
|
@@ -15,20 +15,38 @@ class TokenHandler {
|
|
|
15
15
|
_defineProperty(this, "symbol", void 0);
|
|
16
16
|
_defineProperty(this, "decimals", void 0);
|
|
17
17
|
_defineProperty(this, "name", void 0);
|
|
18
|
-
_defineProperty(this, "
|
|
18
|
+
_defineProperty(this, "provider", void 0);
|
|
19
|
+
_defineProperty(this, "publicClient", void 0);
|
|
19
20
|
this.address = address;
|
|
20
|
-
this.
|
|
21
|
+
this.provider = provider;
|
|
22
|
+
this.publicClient = createPublicClient({
|
|
23
|
+
transport: custom(this.provider)
|
|
24
|
+
});
|
|
21
25
|
this.symbol = symbol;
|
|
22
26
|
this.decimals = decimals;
|
|
23
27
|
this.name = name;
|
|
24
28
|
}
|
|
25
29
|
async getSymbol() {
|
|
26
|
-
if (!this.symbol || this.symbol === "ERC20")
|
|
30
|
+
if (!this.symbol || this.symbol === "ERC20") {
|
|
31
|
+
this.symbol = await this.publicClient.readContract({
|
|
32
|
+
address: this.address,
|
|
33
|
+
abi: erc20Abi,
|
|
34
|
+
functionName: "symbol",
|
|
35
|
+
authorizationList: undefined
|
|
36
|
+
});
|
|
37
|
+
}
|
|
27
38
|
return this.symbol;
|
|
28
39
|
}
|
|
29
40
|
async getDecimals() {
|
|
30
41
|
try {
|
|
31
|
-
if (!this.decimals)
|
|
42
|
+
if (!this.decimals) {
|
|
43
|
+
this.decimals = Number(await this.publicClient.readContract({
|
|
44
|
+
address: this.address,
|
|
45
|
+
abi: erc20Abi,
|
|
46
|
+
functionName: "decimals",
|
|
47
|
+
authorizationList: undefined
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
32
50
|
return this.decimals;
|
|
33
51
|
} catch (error) {
|
|
34
52
|
log.warn(`Could not get decimals for token ${this.address}`, error);
|
|
@@ -36,12 +54,26 @@ class TokenHandler {
|
|
|
36
54
|
}
|
|
37
55
|
}
|
|
38
56
|
async getName() {
|
|
39
|
-
if (!this.name)
|
|
57
|
+
if (!this.name) {
|
|
58
|
+
const name = await this.publicClient.readContract({
|
|
59
|
+
address: this.address,
|
|
60
|
+
abi: erc20Abi,
|
|
61
|
+
functionName: "name",
|
|
62
|
+
authorizationList: undefined
|
|
63
|
+
});
|
|
64
|
+
this.name = name;
|
|
65
|
+
}
|
|
40
66
|
return this.name;
|
|
41
67
|
}
|
|
42
68
|
async getUserBalance(userAddress) {
|
|
43
69
|
if (!this.decimals) await this.getDecimals();
|
|
44
|
-
const balance = await this.
|
|
70
|
+
const balance = await this.publicClient.readContract({
|
|
71
|
+
address: this.address,
|
|
72
|
+
abi: erc20Abi,
|
|
73
|
+
functionName: "balanceOf",
|
|
74
|
+
args: [userAddress],
|
|
75
|
+
authorizationList: undefined
|
|
76
|
+
});
|
|
45
77
|
return balance.toString(16);
|
|
46
78
|
}
|
|
47
79
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
3
|
import { BaseController, PollingManager } from '@toruslabs/base-controllers';
|
|
4
|
-
import { BrowserProvider, Contract, toQuantity } from 'ethers';
|
|
5
4
|
import log from 'loglevel';
|
|
5
|
+
import { createPublicClient, custom, toHex } from 'viem';
|
|
6
6
|
import { singleBalanceCheckerAbi } from '../utils/abis.js';
|
|
7
7
|
import { MM_TOKEN_API_SUPPORTED_CHAINS } from '../utils/constants.js';
|
|
8
8
|
import { SINGLE_CALL_BALANCES_ADDRESSES } from '../utils/contractAddresses.js';
|
|
@@ -27,13 +27,15 @@ class TokensController extends BaseController {
|
|
|
27
27
|
});
|
|
28
28
|
_defineProperty(this, "name", "TokensController");
|
|
29
29
|
_defineProperty(this, "provider", void 0);
|
|
30
|
-
_defineProperty(this, "
|
|
30
|
+
_defineProperty(this, "publicClient", void 0);
|
|
31
31
|
_defineProperty(this, "pollingManager", void 0);
|
|
32
32
|
_defineProperty(this, "getProviderConfig", void 0);
|
|
33
33
|
_defineProperty(this, "getCustomTokens", void 0);
|
|
34
34
|
_defineProperty(this, "getEtherScanTokens", void 0);
|
|
35
35
|
this.provider = provider;
|
|
36
|
-
this.
|
|
36
|
+
this.publicClient = createPublicClient({
|
|
37
|
+
transport: custom(this.provider)
|
|
38
|
+
});
|
|
37
39
|
this.getCustomTokens = getCustomTokens;
|
|
38
40
|
this.getEtherScanTokens = getEtherScanTokens;
|
|
39
41
|
this.getProviderConfig = getProviderConfig;
|
|
@@ -167,10 +169,16 @@ class TokensController extends BaseController {
|
|
|
167
169
|
const remainingTokensAddresses = remainingTokens.map(x => x.tokenAddress);
|
|
168
170
|
const currentSingleCallAddress = SINGLE_CALL_BALANCES_ADDRESSES[currentChainId];
|
|
169
171
|
if (currentSingleCallAddress) {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
+
const result = await this.publicClient.readContract({
|
|
173
|
+
address: currentSingleCallAddress,
|
|
174
|
+
abi: singleBalanceCheckerAbi,
|
|
175
|
+
functionName: "balances",
|
|
176
|
+
args: [[userAddress], remainingTokensAddresses],
|
|
177
|
+
authorizationList: undefined
|
|
178
|
+
});
|
|
172
179
|
remainingTokensAddresses.forEach((_, index) => {
|
|
173
|
-
|
|
180
|
+
var _result$index;
|
|
181
|
+
const balance = toHex((_result$index = result[index]) !== null && _result$index !== void 0 ? _result$index : 0n);
|
|
174
182
|
if (balance && balance !== "0x0") {
|
|
175
183
|
nonZeroTokens.push(_objectSpread(_objectSpread({}, remainingTokens[index]), {}, {
|
|
176
184
|
balance,
|
|
@@ -208,7 +216,7 @@ class TokensController extends BaseController {
|
|
|
208
216
|
decimals: Number.parseInt(x.decimals),
|
|
209
217
|
name: x.name,
|
|
210
218
|
symbol: x.symbol,
|
|
211
|
-
provider: this.
|
|
219
|
+
provider: this.provider
|
|
212
220
|
});
|
|
213
221
|
const balance = await tokenInstance.getUserBalance(this.userSelectedAddress);
|
|
214
222
|
return {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { addHexPrefix, stripHexPrefix } from '@ethereumjs/util';
|
|
4
3
|
import { TRANSACTION_TYPES, TX_EVENTS, TransactionStatus } from '@toruslabs/base-controllers';
|
|
4
|
+
import { add0x, remove0x } from '@toruslabs/metadata-helpers';
|
|
5
5
|
import { rpcErrors, providerErrors } from '@web3auth/auth';
|
|
6
6
|
import { BigNumber } from 'bignumber.js';
|
|
7
|
-
import { Signature, Transaction, keccak256 } from 'ethers';
|
|
8
7
|
import log from 'loglevel';
|
|
9
|
-
import { toHex } from 'viem';
|
|
8
|
+
import { toHex, keccak256 } from 'viem';
|
|
10
9
|
import { generateEIP7702BatchTransaction } from '../Eip7702/eip7702Utils.js';
|
|
11
10
|
import { METHOD_TYPES, TRANSACTION_ENVELOPE_TYPES, CONTRACT_TYPE_ERC7821, GAS_ESTIMATE_TYPES, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP } from '../utils/constants.js';
|
|
12
11
|
import { decGWEIToHexWEI } from '../utils/conversionUtils.js';
|
|
@@ -129,7 +128,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
129
128
|
}
|
|
130
129
|
txParams.authorizationList = [{
|
|
131
130
|
address: delegationAddress,
|
|
132
|
-
chainId:
|
|
131
|
+
chainId: add0x(chainId)
|
|
133
132
|
}];
|
|
134
133
|
txParams.type = TRANSACTION_ENVELOPE_TYPES.SET_CODE;
|
|
135
134
|
}
|
|
@@ -180,7 +179,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
180
179
|
// higher gas settings and therefor the nonce should not be recalculated
|
|
181
180
|
const nonce = nonceLock.nextNonce;
|
|
182
181
|
const customOrNonce = customNonceValueNumber === 0 ? customNonceValue : customNonceValue || nonce;
|
|
183
|
-
txMeta.transaction.nonce =
|
|
182
|
+
txMeta.transaction.nonce = add0x(customOrNonce.toString(16));
|
|
184
183
|
// add nonce debugging information to txMeta
|
|
185
184
|
txMeta.nonceDetails = nonceLock.nonceDetails;
|
|
186
185
|
this.updateTransactionInState(txMeta, "transactions#approveTransaction");
|
|
@@ -244,20 +243,19 @@ class TransactionController extends TransactionStateManager {
|
|
|
244
243
|
address: signedAuthorization.address,
|
|
245
244
|
chainId: BigInt(signedAuthorization.chainId),
|
|
246
245
|
nonce: BigInt(signedAuthorization.nonce),
|
|
247
|
-
signature:
|
|
246
|
+
signature: {
|
|
248
247
|
r: signedAuthorization.r,
|
|
249
248
|
s: signedAuthorization.s,
|
|
250
249
|
yParity: parseInt(signedAuthorization.yParity, 16)
|
|
251
|
-
}
|
|
250
|
+
}
|
|
252
251
|
});
|
|
253
252
|
}
|
|
254
253
|
txMeta.transaction.authorizationList = signedAuthorizations;
|
|
255
254
|
}
|
|
256
|
-
const
|
|
257
|
-
const signedEthTx = await this.signEthTx(tx, fromAddress);
|
|
255
|
+
const signedEthTx = await this.signEthTx(txParams, fromAddress);
|
|
258
256
|
txMeta.r = signedEthTx.signature.r;
|
|
259
257
|
txMeta.s = signedEthTx.signature.s;
|
|
260
|
-
txMeta.v =
|
|
258
|
+
txMeta.v = signedEthTx.signature.v != null ? toHex(signedEthTx.signature.v) : undefined;
|
|
261
259
|
const rawTx = signedEthTx.serialized;
|
|
262
260
|
txMeta.rawTransaction = rawTx;
|
|
263
261
|
this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values and rawTx");
|
|
@@ -275,8 +273,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
275
273
|
});
|
|
276
274
|
} catch (error) {
|
|
277
275
|
if (error.message.toLowerCase().includes("known transaction")) {
|
|
278
|
-
txHash = keccak256(
|
|
279
|
-
txHash = addHexPrefix(txHash);
|
|
276
|
+
txHash = keccak256(add0x(rawTx));
|
|
280
277
|
} else {
|
|
281
278
|
throw error;
|
|
282
279
|
}
|
|
@@ -354,7 +351,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
354
351
|
// If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas
|
|
355
352
|
// then we set maxFeePerGas to the suggested gasPrice.
|
|
356
353
|
|
|
357
|
-
txMeta.transaction.maxPriorityFeePerGas = bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ?
|
|
354
|
+
txMeta.transaction.maxPriorityFeePerGas = bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? remove0x(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? remove0x(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
|
|
358
355
|
} else {
|
|
359
356
|
if (defaultMaxFeePerGas && !txMeta.transaction.maxFeePerGas) {
|
|
360
357
|
// If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
|
|
@@ -430,8 +427,8 @@ class TransactionController extends TransactionStateManager {
|
|
|
430
427
|
if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
|
|
431
428
|
return {
|
|
432
429
|
// send to controller in hex wei
|
|
433
|
-
maxFeePerGas:
|
|
434
|
-
maxPriorityFeePerGas:
|
|
430
|
+
maxFeePerGas: add0x(decGWEIToHexWEI(new BigNumber(suggestedMaxFeePerGas)).toString(16)),
|
|
431
|
+
maxPriorityFeePerGas: add0x(decGWEIToHexWEI(new BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
|
|
435
432
|
};
|
|
436
433
|
}
|
|
437
434
|
} else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
|
|
@@ -441,7 +438,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
441
438
|
// The LEGACY type includes low, medium and high estimates of
|
|
442
439
|
// gas price values.
|
|
443
440
|
return {
|
|
444
|
-
gasPrice:
|
|
441
|
+
gasPrice: add0x(decGWEIToHexWEI(new BigNumber(medium)).toString(16))
|
|
445
442
|
};
|
|
446
443
|
} else if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
|
|
447
444
|
const {
|
|
@@ -450,7 +447,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
450
447
|
// The ETH_GASPRICE type just includes a single gas price property,
|
|
451
448
|
// which we can assume was retrieved from eth_gasPrice
|
|
452
449
|
return {
|
|
453
|
-
gasPrice:
|
|
450
|
+
gasPrice: add0x(decGWEIToHexWEI(new BigNumber(gasPrice)).toString(16))
|
|
454
451
|
};
|
|
455
452
|
}
|
|
456
453
|
} catch (error) {
|
|
@@ -460,7 +457,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
460
457
|
method: METHOD_TYPES.ETH_GET_GAS_PRICE
|
|
461
458
|
});
|
|
462
459
|
return {
|
|
463
|
-
gasPrice: gasPrice &&
|
|
460
|
+
gasPrice: gasPrice && add0x(gasPrice)
|
|
464
461
|
};
|
|
465
462
|
}
|
|
466
463
|
async getDefaultGasLimit(txMeta) {
|
|
@@ -496,9 +493,9 @@ class TransactionController extends TransactionStateManager {
|
|
|
496
493
|
const baseMultiplier = 1.5;
|
|
497
494
|
const perCallBuffer = 0.1;
|
|
498
495
|
const eip7702UpgradeWithDataToSelfGasBufferMultiplier = baseMultiplier + perCallBuffer * batchCallsCount;
|
|
499
|
-
gasLimit = this.txGasUtil.addGasBuffer(
|
|
496
|
+
gasLimit = this.txGasUtil.addGasBuffer(add0x(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
|
|
500
497
|
} else {
|
|
501
|
-
gasLimit = this.txGasUtil.addGasBuffer(
|
|
498
|
+
gasLimit = this.txGasUtil.addGasBuffer(add0x(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
|
|
502
499
|
}
|
|
503
500
|
return {
|
|
504
501
|
gasLimit,
|
|
@@ -523,7 +520,7 @@ class TransactionController extends TransactionStateManager {
|
|
|
523
520
|
txMeta.methodParams = methodParams;
|
|
524
521
|
txMeta.isUserOperation = req.isUserOperation;
|
|
525
522
|
txMeta.isSignOnly = req.isSignOnly;
|
|
526
|
-
txMeta.transaction.value = txMeta.transaction.value ?
|
|
523
|
+
txMeta.transaction.value = txMeta.transaction.value ? add0x(txMeta.transaction.value) : "0x0";
|
|
527
524
|
txMeta.batchId = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.batchId;
|
|
528
525
|
txMeta.nestedTransactions = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.nestedTransactions;
|
|
529
526
|
this.emit(`${txMeta.id}:unapproved`, txMeta);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { stripHexPrefix, addHexPrefix } from '@ethereumjs/util';
|
|
4
3
|
import { cloneDeep } from '@toruslabs/base-controllers';
|
|
5
|
-
import {
|
|
4
|
+
import { hexToBigInt, add0x, bigIntToHexPrefixedString } from '@toruslabs/metadata-helpers';
|
|
6
5
|
import log from 'loglevel';
|
|
7
6
|
import { DUMMY_AUTHORIZATION_SIGNATURE } from '../utils/eip7702Types.js';
|
|
8
7
|
import { isEip7702SetCodeTx } from './TransactionUtils.js';
|
|
@@ -17,9 +16,9 @@ class TransactionGasUtil {
|
|
|
17
16
|
async analyzeGasUsage(txMeta) {
|
|
18
17
|
const block = await this.blockTracker.getLatestBlock();
|
|
19
18
|
// fallback to block gasLimit
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
let estimatedGasHex =
|
|
19
|
+
const blockGasLimit = hexToBigInt(block.gasLimit);
|
|
20
|
+
const saferGasLimit = blockGasLimit * 19n / 20n;
|
|
21
|
+
let estimatedGasHex = add0x(saferGasLimit.toString(16));
|
|
23
22
|
let simulationFails;
|
|
24
23
|
try {
|
|
25
24
|
estimatedGasHex = await this.estimateTxGas(txMeta);
|
|
@@ -45,17 +44,17 @@ class TransactionGasUtil {
|
|
|
45
44
|
Adds a gas buffer with out exceeding the block gas limit
|
|
46
45
|
*/
|
|
47
46
|
addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
|
|
48
|
-
const
|
|
49
|
-
const
|
|
50
|
-
const
|
|
51
|
-
const
|
|
47
|
+
const initialGasLimit = hexToBigInt(initialGasLimitHex);
|
|
48
|
+
const blockGasLimit = hexToBigInt(blockGasLimitHex);
|
|
49
|
+
const upperGasLimit = blockGasLimit * 9n / 10n;
|
|
50
|
+
const bufferedGasLimit = initialGasLimit * BigInt(Math.round(multiplier * 10)) / 10n;
|
|
52
51
|
|
|
53
52
|
// if initialGasLimit is above blockGasLimit, dont modify it
|
|
54
|
-
if (
|
|
53
|
+
if (initialGasLimit > upperGasLimit) return bigIntToHexPrefixedString(initialGasLimit);
|
|
55
54
|
// if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
|
|
56
|
-
if (
|
|
55
|
+
if (bufferedGasLimit < upperGasLimit) return bigIntToHexPrefixedString(bufferedGasLimit);
|
|
57
56
|
// otherwise use blockGasLimit
|
|
58
|
-
return
|
|
57
|
+
return bigIntToHexPrefixedString(upperGasLimit);
|
|
59
58
|
}
|
|
60
59
|
|
|
61
60
|
/**
|