@toruslabs/ethereum-controllers 9.2.0 → 9.4.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/Currency/CurrencyController.js +9 -4
- package/dist/lib.cjs/Eip5792/walletGetCapabilities.js +9 -0
- package/dist/lib.cjs/Eip5792/walletSendCalls.js +8 -2
- package/dist/lib.cjs/Network/createEthereumMiddleware.js +7 -3
- package/dist/lib.cjs/Preferences/PreferencesController.js +34 -400
- package/dist/lib.cjs/Tokens/TokenRatesController.js +16 -7
- package/dist/lib.cjs/Transaction/TransactionController.js +1 -1
- package/dist/lib.cjs/index.js +2 -2
- package/dist/lib.cjs/types/Currency/CurrencyController.d.ts +4 -2
- package/dist/lib.cjs/types/Eip5792/walletGetCapabilities.d.ts +2 -1
- package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +4 -2
- package/dist/lib.cjs/types/Network/interfaces.d.ts +5 -1
- package/dist/lib.cjs/types/Preferences/IPreferencesController.d.ts +0 -6
- package/dist/lib.cjs/types/Preferences/PreferencesController.d.ts +5 -29
- package/dist/lib.cjs/types/Tokens/TokenRatesController.d.ts +5 -3
- package/dist/lib.cjs/types/utils/constants.d.ts +5 -0
- package/dist/lib.cjs/types/utils/helpers.d.ts +0 -13
- package/dist/lib.cjs/types/utils/interfaces.d.ts +6 -68
- package/dist/lib.cjs/utils/constants.js +7 -0
- package/dist/lib.cjs/utils/helpers.js +0 -119
- package/dist/lib.esm/Currency/CurrencyController.js +10 -5
- package/dist/lib.esm/Eip5792/walletGetCapabilities.js +9 -0
- package/dist/lib.esm/Eip5792/walletSendCalls.js +9 -2
- package/dist/lib.esm/Network/createEthereumMiddleware.js +7 -3
- package/dist/lib.esm/Preferences/PreferencesController.js +37 -405
- package/dist/lib.esm/Tokens/TokenRatesController.js +17 -8
- package/dist/lib.esm/index.js +2 -2
- package/dist/lib.esm/utils/constants.js +6 -1
- package/dist/lib.esm/utils/helpers.js +3 -120
- package/dist/lib.esm/utils/interfaces.js +0 -2
- package/package.json +6 -6
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _objectSpread from '@babel/runtime/helpers/objectSpread2';
|
|
2
2
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
3
|
-
import { BaseController, PollingManager } from '@toruslabs/base-controllers';
|
|
4
|
-
import { get } from '@toruslabs/http-helpers';
|
|
3
|
+
import { BaseController, PollingManager, resolveAuthHttpClient } from '@toruslabs/base-controllers';
|
|
5
4
|
import log from 'loglevel';
|
|
6
5
|
import { COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES } from '../utils/constants.js';
|
|
7
6
|
|
|
@@ -16,13 +15,15 @@ class TokenRatesController extends BaseController {
|
|
|
16
15
|
idleTimeTracker,
|
|
17
16
|
onPreferencesStateChange,
|
|
18
17
|
onNetworkStateChange,
|
|
19
|
-
onTokensStateChange
|
|
18
|
+
onTokensStateChange,
|
|
19
|
+
getAuthHttpClient
|
|
20
20
|
}) {
|
|
21
21
|
super({
|
|
22
22
|
config,
|
|
23
23
|
state
|
|
24
24
|
});
|
|
25
25
|
_defineProperty(this, "pollingManager", void 0);
|
|
26
|
+
_defineProperty(this, "getAuthHttpClient", void 0);
|
|
26
27
|
this.defaultState = _objectSpread(_objectSpread({}, this.defaultState), {}, {
|
|
27
28
|
contractExchangeRates: {}
|
|
28
29
|
});
|
|
@@ -50,18 +51,19 @@ class TokenRatesController extends BaseController {
|
|
|
50
51
|
tokens
|
|
51
52
|
} = tokensState;
|
|
52
53
|
const currentUserTokens = tokens[this.config.selectedAddress];
|
|
53
|
-
if ((currentUserTokens === null || currentUserTokens === void 0 ? void 0 : currentUserTokens.length) > 0 && this.config.tokens !==
|
|
54
|
+
if ((currentUserTokens === null || currentUserTokens === void 0 ? void 0 : currentUserTokens.length) > 0 && this.config.tokens !== currentUserTokens) {
|
|
54
55
|
this.configure({
|
|
55
|
-
tokens:
|
|
56
|
+
tokens: currentUserTokens
|
|
56
57
|
});
|
|
57
58
|
this.updateExchangeRates();
|
|
58
59
|
}
|
|
59
60
|
});
|
|
61
|
+
this.getAuthHttpClient = getAuthHttpClient;
|
|
60
62
|
this.pollingManager = new PollingManager(idleTimeTracker, this.config.pollInterval);
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
64
|
-
* Creates a new poll, using setInterval, to periodically call
|
|
66
|
+
* Creates a new poll, using setInterval, to periodically call updateExchangeRates. The id of the interval is
|
|
65
67
|
* stored at the controller's conversionInterval property. If it is called and such an id already exists, the
|
|
66
68
|
* previous interval is clear and a new one is created.
|
|
67
69
|
*/
|
|
@@ -84,17 +86,24 @@ class TokenRatesController extends BaseController {
|
|
|
84
86
|
});
|
|
85
87
|
}
|
|
86
88
|
async fetchExchangeRates(nativeCurrency, chainCodes) {
|
|
89
|
+
const httpClient = resolveAuthHttpClient(this.getAuthHttpClient, this.name);
|
|
87
90
|
const contractAddresses = this.config.tokens.map(token => token.tokenAddress);
|
|
88
91
|
const isNativeCurrencySupported = COINGECKO_SUPPORTED_CURRENCIES.has(nativeCurrency.toLowerCase());
|
|
89
92
|
if (isNativeCurrencySupported) {
|
|
90
|
-
const response = await get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}
|
|
93
|
+
const response = await httpClient.get(`${this.config.currencyApi}/v2/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${nativeCurrency.toLowerCase()}`, {
|
|
94
|
+
authenticated: true
|
|
95
|
+
});
|
|
91
96
|
const newContractExchangeRates = {};
|
|
92
97
|
Object.keys(response).forEach(contractAddress => {
|
|
93
98
|
newContractExchangeRates[contractAddress] = response[contractAddress][nativeCurrency.toLowerCase()] || 0;
|
|
94
99
|
});
|
|
95
100
|
return newContractExchangeRates;
|
|
96
101
|
}
|
|
97
|
-
const [response, currencyResponse] = await Promise.all([get(`${this.config.currencyApi}/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}
|
|
102
|
+
const [response, currencyResponse] = await Promise.all([httpClient.get(`${this.config.currencyApi}/v2/currency/exchange-rates?platform=${chainCodes.platform}&contract_addresses=${contractAddresses.join(",")}&vs_currencies=${DEFAULT_CURRENCY}`, {
|
|
103
|
+
authenticated: true
|
|
104
|
+
}), httpClient.get(`${this.config.currencyApi}/v2/currency?fsym=${nativeCurrency.toUpperCase()}&tsyms=${DEFAULT_CURRENCY.toUpperCase()}`, {
|
|
105
|
+
authenticated: true
|
|
106
|
+
})]);
|
|
98
107
|
const newContractExchangeRates = {};
|
|
99
108
|
Object.keys(response).forEach(contractAddress => {
|
|
100
109
|
newContractExchangeRates[contractAddress] = response[contractAddress][DEFAULT_CURRENCY] * Number.parseFloat(currencyResponse[DEFAULT_CURRENCY]) || 0;
|
package/dist/lib.esm/index.js
CHANGED
|
@@ -25,11 +25,11 @@ export { generateHistoryEntry, replayHistory, snapshotFromTxMeta } from './Trans
|
|
|
25
25
|
export { TransactionStateManager } from './Transaction/TransactionStateManager.js';
|
|
26
26
|
export { createNestedTransactionMeta, determineTransactionType, ensureFieldIsString, ensureMutuallyExclusiveFieldsNotProvided, getFinalStates, isEIP1559Transaction, isEip7702SetCodeTx, isEip7702UpgradeWithDataToSelfTransaction, isLegacyTransaction, normalizeAndValidateTxParams, normalizeTxParameters, parseStandardTokenTransactionData, readAddressAsContract, transactionMatchesNetwork, validateFrom, validateRecipient, validateTxParameters } from './Transaction/TransactionUtils.js';
|
|
27
27
|
export { erc1155Abi, erc20Abi, erc721Abi, erc7821Abi, singleBalanceCheckerAbi } from './utils/abis.js';
|
|
28
|
-
export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID } from './utils/constants.js';
|
|
28
|
+
export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SMART_ACCOUNT_EIP_STANDARD, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID } from './utils/constants.js';
|
|
29
29
|
export { addCurrencies, conversionGTE, conversionGreaterThan, conversionLTE, conversionLessThan, conversionMax, conversionUtil, decGWEIToHexWEI, getBigNumber, hexWEIToDecGWEI, multiplyCurrencies, subtractCurrencies, toNegative } from './utils/conversionUtils.js';
|
|
30
30
|
export { EIP5792ErrorCode, EIP_5792_METHODS, Eip5792AtomicStatus, GetCallsStatusCode } from './utils/eip5792Types.js';
|
|
31
31
|
export { DUMMY_AUTHORIZATION_SIGNATURE, EIP_7702_METHODS, EIP_7702_PREFIX, EIP_7702_REVOKE_ADDRESS } from './utils/eip7702Types.js';
|
|
32
|
-
export { BNToHex, GAS_LIMITS,
|
|
32
|
+
export { BNToHex, GAS_LIMITS, bnLessThan, formatDate, formatTime, getChainType, getEthTxStatus, getEtherScanHashLink, getIpfsEndpoint, hexToBn, isAddressByChainId, sanitizeNftMetdataUrl, toChecksumAddressByChainId } from './utils/helpers.js';
|
|
33
33
|
export { TRANSACTION_CATEGORY_EIP7702 } from './utils/interfaces.js';
|
|
34
34
|
export { BiconomySmartAccount } from './AccountAbstraction/smartAccounts/BiconomySmartAccount.js';
|
|
35
35
|
export { CacheStrategy, blockTagParamIndex, cacheIdentifierForRequest, cacheTypeForMethod } from './Network/cacheIdentifier.js';
|
|
@@ -366,5 +366,10 @@ const SMART_ACCOUNT = {
|
|
|
366
366
|
NEXUS: "nexus",
|
|
367
367
|
METAMASK: "metamask"
|
|
368
368
|
};
|
|
369
|
+
const SMART_ACCOUNT_EIP_STANDARD = {
|
|
370
|
+
ERC_4337: "4337",
|
|
371
|
+
EIP_7702: "7702"
|
|
372
|
+
};
|
|
373
|
+
const EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES = [SMART_ACCOUNT.METAMASK];
|
|
369
374
|
|
|
370
|
-
export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
|
|
375
|
+
export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, BUNDLER_METHOD_TYPES, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC7821, CONTRACT_TYPE_ETH, EIP7702_SUPPORTED_SMART_ACCOUNT_TYPES, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, GAS_ESTIMATE_TYPES, LINEA_CHAIN_ID, LINEA_SEPOLIA_CHAIN_ID, LOCALHOST, MAINNET_CHAIN_ID, METHOD_TYPES, MM_NFT_API_SUPPORTED_CHAINS, MM_TOKEN_API_SUPPORTED_CHAINS, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, PAYMASTER_METHOD_TYPES, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, SEPOLIA_CHAIN_ID, SMART_ACCOUNT, SMART_ACCOUNT_EIP_STANDARD, SUPPORTED_NETWORKS, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, XDAI_CHAIN_ID };
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { TransactionStatus, formatSmallNumbers, significantDigits, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, addressSlicer } from '@toruslabs/base-controllers';
|
|
1
|
+
import { TransactionStatus } from '@toruslabs/base-controllers';
|
|
3
2
|
import { add0x, remove0x } from '@toruslabs/metadata-helpers';
|
|
4
3
|
import { BigNumber } from 'bignumber.js';
|
|
5
4
|
import log from 'loglevel';
|
|
6
5
|
import { toHex, isAddress, getAddress } from 'viem';
|
|
7
|
-
import {
|
|
8
|
-
import { SUPPORTED_NETWORKS, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC20, MAINNET_CHAIN_ID, TEST_CHAINS, METHOD_TYPES, CONTRACT_TYPE_ETH } from './constants.js';
|
|
6
|
+
import { MAINNET_CHAIN_ID, TEST_CHAINS, METHOD_TYPES, SUPPORTED_NETWORKS } from './constants.js';
|
|
9
7
|
|
|
10
8
|
function hexToBn(hex) {
|
|
11
9
|
return new BigNumber(remove0x(hex), 16);
|
|
@@ -17,51 +15,6 @@ function getEtherScanHashLink(txHash, chainId) {
|
|
|
17
15
|
if (!SUPPORTED_NETWORKS[chainId]) return "";
|
|
18
16
|
return `${SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
|
|
19
17
|
}
|
|
20
|
-
const formatPastTx = params => {
|
|
21
|
-
var _transaction$to;
|
|
22
|
-
const {
|
|
23
|
-
transaction,
|
|
24
|
-
lowerCaseSelectedAddress,
|
|
25
|
-
blockExplorerUrl
|
|
26
|
-
} = params;
|
|
27
|
-
let totalAmountString = "";
|
|
28
|
-
if (transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155) totalAmountString = transaction.symbol;else if (transaction.type === CONTRACT_TYPE_ERC20) totalAmountString = formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.symbol, true);else totalAmountString = formatSmallNumbers(Number.parseFloat(transaction.total_amount), transaction.type_name, true);
|
|
29
|
-
const currencyAmountString = transaction.type === CONTRACT_TYPE_ERC721 || transaction.type === CONTRACT_TYPE_ERC1155 || transaction.isEtherscan ? "" : formatSmallNumbers(Number.parseFloat(transaction.currency_amount), transaction.selected_currency, true);
|
|
30
|
-
const finalObject = {
|
|
31
|
-
id: transaction.created_at.toString(),
|
|
32
|
-
date: new Date(transaction.created_at).toString(),
|
|
33
|
-
from: transaction.from,
|
|
34
|
-
from_aa_address: transaction.from_aa_address,
|
|
35
|
-
slicedFrom: typeof transaction.from === "string" ? addressSlicer(transaction.from) : "",
|
|
36
|
-
to: transaction.to,
|
|
37
|
-
slicedTo: typeof transaction.to === "string" ? addressSlicer(transaction.to) : "",
|
|
38
|
-
action: lowerCaseSelectedAddress === ((_transaction$to = transaction.to) === null || _transaction$to === void 0 ? void 0 : _transaction$to.toLowerCase()) || "" ? ACTIVITY_ACTION_RECEIVE : ACTIVITY_ACTION_SEND,
|
|
39
|
-
totalAmount: transaction.total_amount,
|
|
40
|
-
totalAmountString,
|
|
41
|
-
currencyAmount: transaction.currency_amount,
|
|
42
|
-
currencyAmountString,
|
|
43
|
-
amount: `${totalAmountString} / ${currencyAmountString}`,
|
|
44
|
-
status: transaction.status,
|
|
45
|
-
etherscanLink: blockExplorerUrl ? `${blockExplorerUrl}/tx/${transaction.transaction_hash}` : "",
|
|
46
|
-
chainId: transaction.chain_id,
|
|
47
|
-
ethRate: Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.total_amount) && Number.parseFloat(transaction === null || transaction === void 0 ? void 0 : transaction.currency_amount) ? `1 ${transaction.symbol} = ${significantDigits(Number.parseFloat(transaction.currency_amount) / Number.parseFloat(transaction.total_amount))}` : "",
|
|
48
|
-
currencyUsed: transaction.selected_currency,
|
|
49
|
-
type: transaction.type,
|
|
50
|
-
type_name: transaction.type_name,
|
|
51
|
-
type_image_link: transaction.type_image_link,
|
|
52
|
-
transaction_hash: transaction.transaction_hash,
|
|
53
|
-
transaction_category: transaction.transaction_category,
|
|
54
|
-
isEtherscan: transaction.isEtherscan,
|
|
55
|
-
input: transaction.input || "",
|
|
56
|
-
token_id: transaction.token_id || "",
|
|
57
|
-
contract_address: transaction.contract_address || "",
|
|
58
|
-
nonce: transaction.nonce || "",
|
|
59
|
-
is_cancel: !!transaction.is_cancel || false,
|
|
60
|
-
gas: transaction.gas || "",
|
|
61
|
-
gasPrice: transaction.gasPrice || ""
|
|
62
|
-
};
|
|
63
|
-
return finalObject;
|
|
64
|
-
};
|
|
65
18
|
|
|
66
19
|
/**
|
|
67
20
|
* Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
|
|
@@ -130,75 +83,5 @@ function getChainType(chainId) {
|
|
|
130
83
|
}
|
|
131
84
|
return "custom";
|
|
132
85
|
}
|
|
133
|
-
const addEtherscanTransactions = async params => {
|
|
134
|
-
const {
|
|
135
|
-
txn,
|
|
136
|
-
lowerCaseSelectedAddress,
|
|
137
|
-
provider,
|
|
138
|
-
chainId,
|
|
139
|
-
blockExplorerUrl
|
|
140
|
-
} = params;
|
|
141
|
-
const transactionPromises = await Promise.all(txn.map(async tx => {
|
|
142
|
-
var _SUPPORTED_NETWORKS$c, _SUPPORTED_NETWORKS$c2;
|
|
143
|
-
const {
|
|
144
|
-
category,
|
|
145
|
-
type
|
|
146
|
-
} = await determineTransactionType(_objectSpread(_objectSpread({}, tx), {}, {
|
|
147
|
-
data: tx.input
|
|
148
|
-
}), provider);
|
|
149
|
-
tx.transaction_category = tx.transaction_category || category;
|
|
150
|
-
tx.type_image_link = ((_SUPPORTED_NETWORKS$c = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c === void 0 ? void 0 : _SUPPORTED_NETWORKS$c.logo) || "";
|
|
151
|
-
tx.type_name = (_SUPPORTED_NETWORKS$c2 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c2 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c2.ticker;
|
|
152
|
-
tx.type = type;
|
|
153
|
-
return tx;
|
|
154
|
-
}));
|
|
155
|
-
const finalTxs = transactionPromises.reduce((accumulator, x) => {
|
|
156
|
-
var _SUPPORTED_NETWORKS$c3, _SUPPORTED_NETWORKS$c4;
|
|
157
|
-
let totalAmountString = x.value ? new BigNumber(x.value).div(new BigNumber(10).pow(new BigNumber(x.tokenDecimal || 18))).toString() : "";
|
|
158
|
-
let type = CONTRACT_TYPE_ETH;
|
|
159
|
-
if (x.contractAddress !== "") {
|
|
160
|
-
if (x.tokenID) {
|
|
161
|
-
type = x.tokenValue ? CONTRACT_TYPE_ERC1155 : CONTRACT_TYPE_ERC721;
|
|
162
|
-
} else {
|
|
163
|
-
type = CONTRACT_TYPE_ERC20;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
if (type === CONTRACT_TYPE_ERC1155) {
|
|
167
|
-
totalAmountString = x.tokenValue;
|
|
168
|
-
}
|
|
169
|
-
const etherscanTransaction = {
|
|
170
|
-
type,
|
|
171
|
-
type_image_link: x.type_image_link || "n/a",
|
|
172
|
-
type_name: x.tokenName || ((_SUPPORTED_NETWORKS$c3 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c3 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c3.ticker) || "n/a",
|
|
173
|
-
symbol: x.tokenSymbol || ((_SUPPORTED_NETWORKS$c4 = SUPPORTED_NETWORKS[chainId]) === null || _SUPPORTED_NETWORKS$c4 === void 0 ? void 0 : _SUPPORTED_NETWORKS$c4.ticker),
|
|
174
|
-
token_id: x.tokenID || "",
|
|
175
|
-
total_amount: totalAmountString,
|
|
176
|
-
created_at: new Date(Number(x.timeStamp) * 1000),
|
|
177
|
-
from: x.from,
|
|
178
|
-
to: x.to,
|
|
179
|
-
transaction_hash: x.hash,
|
|
180
|
-
status: x.txreceipt_status && x.txreceipt_status === "0" ? TransactionStatus.failed : TransactionStatus.confirmed,
|
|
181
|
-
isEtherscan: true,
|
|
182
|
-
input: x.input,
|
|
183
|
-
contract_address: x.contractAddress,
|
|
184
|
-
transaction_category: x.transaction_category,
|
|
185
|
-
gas: `0x${new BigNumber(x.gasUsed || 0, 10).toString(16)}`,
|
|
186
|
-
gasPrice: `0x${new BigNumber(x.gasPrice || 0, 10).toString(16)}`,
|
|
187
|
-
chain_id: chainId,
|
|
188
|
-
currency_amount: "",
|
|
189
|
-
nonce: x.nonce,
|
|
190
|
-
from_aa_address: "",
|
|
191
|
-
is_cancel: false,
|
|
192
|
-
selected_currency: ""
|
|
193
|
-
};
|
|
194
|
-
accumulator.push(formatPastTx({
|
|
195
|
-
transaction: etherscanTransaction,
|
|
196
|
-
lowerCaseSelectedAddress,
|
|
197
|
-
blockExplorerUrl
|
|
198
|
-
}));
|
|
199
|
-
return accumulator;
|
|
200
|
-
}, []);
|
|
201
|
-
return finalTxs;
|
|
202
|
-
};
|
|
203
86
|
|
|
204
|
-
export { BNToHex, GAS_LIMITS,
|
|
87
|
+
export { BNToHex, GAS_LIMITS, bnLessThan, formatDate, formatTime, getChainType, getEthTxStatus, getEtherScanHashLink, getIpfsEndpoint, hexToBn, isAddressByChainId, sanitizeNftMetdataUrl, toChecksumAddressByChainId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@toruslabs/ethereum-controllers",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.4.0",
|
|
4
4
|
"homepage": "https://github.com/torusresearch/controllers#readme",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -21,10 +21,10 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@metamask/smart-accounts-kit": "~0.4.0-beta.1",
|
|
24
|
-
"@toruslabs/base-controllers": "^9.
|
|
24
|
+
"@toruslabs/base-controllers": "^9.4.0",
|
|
25
25
|
"@toruslabs/http-helpers": "^9.0.0",
|
|
26
26
|
"@toruslabs/metadata-helpers": "^8.2.0",
|
|
27
|
-
"@web3auth/auth": "^11.
|
|
27
|
+
"@web3auth/auth": "^11.4.0",
|
|
28
28
|
"async-mutex": "^0.5.0",
|
|
29
29
|
"bignumber.js": "^9.3.1",
|
|
30
30
|
"deepmerge": "^4.3.1",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"jsonschema": "^1.5.0",
|
|
35
35
|
"loglevel": "^1.9.2",
|
|
36
36
|
"permissionless": "^0.3.4",
|
|
37
|
-
"uuid": "^
|
|
37
|
+
"uuid": "^13.0.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@babel/runtime": "7.x",
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
"publishConfig": {
|
|
65
65
|
"access": "public"
|
|
66
66
|
},
|
|
67
|
-
"gitHead": "
|
|
67
|
+
"gitHead": "b84f5368b4ba5c51f6ab94c4f2b951a2b53c808c",
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@types/uuid": "^
|
|
69
|
+
"@types/uuid": "^11.0.0",
|
|
70
70
|
"typechain": "^8.3.2"
|
|
71
71
|
}
|
|
72
72
|
}
|