@toruslabs/ethereum-controllers 4.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/ethereumControllers.cjs.js +6153 -0
- package/dist/ethereumControllers.cjs.js.map +1 -0
- package/dist/ethereumControllers.esm.js +5570 -0
- package/dist/ethereumControllers.esm.js.map +1 -0
- package/dist/ethereumControllers.umd.min.js +3 -0
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +38 -0
- package/dist/ethereumControllers.umd.min.js.map +1 -0
- package/dist/types/Account/AccountTrackerController.d.ts +35 -0
- package/dist/types/Block/PollingBlockTracker.d.ts +14 -0
- package/dist/types/Currency/CurrencyController.d.ts +30 -0
- package/dist/types/Gas/GasFeeController.d.ts +64 -0
- package/dist/types/Gas/IGasFeeController.d.ts +49 -0
- package/dist/types/Gas/gasUtil.d.ts +21 -0
- package/dist/types/Keyring/KeyringController.d.ts +20 -0
- package/dist/types/Message/AbstractMessageController.d.ts +36 -0
- package/dist/types/Message/DecryptMessageController.d.ts +20 -0
- package/dist/types/Message/EncryptionPublicKeyController.d.ts +20 -0
- package/dist/types/Message/MessageController.d.ts +20 -0
- package/dist/types/Message/PersonalMessageController.d.ts +20 -0
- package/dist/types/Message/TypedMessageController.d.ts +21 -0
- package/dist/types/Message/utils.d.ts +10 -0
- package/dist/types/Network/NetworkController.d.ts +40 -0
- package/dist/types/Network/createEthereumMiddleware.d.ts +66 -0
- package/dist/types/Network/createJsonRpcClient.d.ts +9 -0
- package/dist/types/Nfts/INftsController.d.ts +10 -0
- package/dist/types/Nfts/NftHandler.d.ts +35 -0
- package/dist/types/Nfts/NftsController.d.ts +40 -0
- package/dist/types/Preferences/PreferencesController.d.ts +53 -0
- package/dist/types/Tokens/ITokensController.d.ts +10 -0
- package/dist/types/Tokens/TokenHandler.d.ts +20 -0
- package/dist/types/Tokens/TokenRatesController.d.ts +42 -0
- package/dist/types/Tokens/TokensController.d.ts +42 -0
- package/dist/types/Transaction/NonceTracker.d.ts +37 -0
- package/dist/types/Transaction/PendingTransactionTracker.d.ts +32 -0
- package/dist/types/Transaction/TransactionController.d.ts +67 -0
- package/dist/types/Transaction/TransactionGasUtil.d.ts +21 -0
- package/dist/types/Transaction/TransactionStateHistoryHelper.d.ts +16 -0
- package/dist/types/Transaction/TransactionStateManager.d.ts +30 -0
- package/dist/types/Transaction/TransactionUtils.d.ts +70 -0
- package/dist/types/index.d.ts +43 -0
- package/dist/types/utils/abiDecoder.d.ts +17 -0
- package/dist/types/utils/abis.d.ts +84 -0
- package/dist/types/utils/constants.d.ts +81 -0
- package/dist/types/utils/contractAddresses.d.ts +1 -0
- package/dist/types/utils/conversionUtils.d.ts +42 -0
- package/dist/types/utils/helpers.d.ts +24 -0
- package/dist/types/utils/interfaces.d.ts +384 -0
- package/package.json +71 -0
- package/src/Account/AccountTrackerController.ts +157 -0
- package/src/Block/PollingBlockTracker.ts +89 -0
- package/src/Currency/CurrencyController.ts +117 -0
- package/src/Gas/GasFeeController.ts +254 -0
- package/src/Gas/IGasFeeController.ts +56 -0
- package/src/Gas/gasUtil.ts +163 -0
- package/src/Keyring/KeyringController.ts +118 -0
- package/src/Message/AbstractMessageController.ts +136 -0
- package/src/Message/DecryptMessageController.ts +81 -0
- package/src/Message/EncryptionPublicKeyController.ts +83 -0
- package/src/Message/MessageController.ts +74 -0
- package/src/Message/PersonalMessageController.ts +74 -0
- package/src/Message/TypedMessageController.ts +112 -0
- package/src/Message/utils.ts +107 -0
- package/src/Network/NetworkController.ts +184 -0
- package/src/Network/createEthereumMiddleware.ts +307 -0
- package/src/Network/createJsonRpcClient.ts +59 -0
- package/src/Nfts/INftsController.ts +13 -0
- package/src/Nfts/NftHandler.ts +191 -0
- package/src/Nfts/NftsController.ts +230 -0
- package/src/Preferences/PreferencesController.ts +409 -0
- package/src/Tokens/ITokensController.ts +13 -0
- package/src/Tokens/TokenHandler.ts +60 -0
- package/src/Tokens/TokenRatesController.ts +134 -0
- package/src/Tokens/TokensController.ts +278 -0
- package/src/Transaction/NonceTracker.ts +152 -0
- package/src/Transaction/PendingTransactionTracker.ts +235 -0
- package/src/Transaction/TransactionController.ts +558 -0
- package/src/Transaction/TransactionGasUtil.ts +74 -0
- package/src/Transaction/TransactionStateHistoryHelper.ts +41 -0
- package/src/Transaction/TransactionStateManager.ts +315 -0
- package/src/Transaction/TransactionUtils.ts +333 -0
- package/src/index.ts +45 -0
- package/src/utils/abiDecoder.ts +195 -0
- package/src/utils/abis.ts +677 -0
- package/src/utils/constants.ts +379 -0
- package/src/utils/contractAddresses.ts +21 -0
- package/src/utils/conversionUtils.ts +269 -0
- package/src/utils/helpers.ts +177 -0
- package/src/utils/interfaces.ts +454 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { addHexPrefix, isValidAddress, toChecksumAddress } from "@ethereumjs/util";
|
|
2
|
+
import {
|
|
3
|
+
ACTIVITY_ACTION_RECEIVE,
|
|
4
|
+
ACTIVITY_ACTION_SEND,
|
|
5
|
+
addressSlicer,
|
|
6
|
+
formatSmallNumbers,
|
|
7
|
+
significantDigits,
|
|
8
|
+
TransactionStatus,
|
|
9
|
+
} from "@toruslabs/base-controllers";
|
|
10
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
11
|
+
import BigNumber from "bignumber.js";
|
|
12
|
+
import log from "loglevel";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
CONTRACT_TYPE_ERC20,
|
|
16
|
+
CONTRACT_TYPE_ERC721,
|
|
17
|
+
CONTRACT_TYPE_ERC1155,
|
|
18
|
+
MAINNET_CHAIN_ID,
|
|
19
|
+
METHOD_TYPES,
|
|
20
|
+
SUPPORTED_NETWORKS,
|
|
21
|
+
TEST_CHAINS,
|
|
22
|
+
} from "./constants";
|
|
23
|
+
import { FormattedTransactionActivity, TransactionPayload, TransactionReceipt } from "./interfaces";
|
|
24
|
+
|
|
25
|
+
export function getEtherScanHashLink(txHash: string, chainId: string) {
|
|
26
|
+
if (!SUPPORTED_NETWORKS[chainId]) return "";
|
|
27
|
+
return `${SUPPORTED_NETWORKS[chainId].blockExplorerUrl}/tx/${txHash}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const formatPastTx = (x: TransactionPayload, lowerCaseSelectedAddress?: string): FormattedTransactionActivity => {
|
|
31
|
+
let totalAmountString = "";
|
|
32
|
+
if (x.type === CONTRACT_TYPE_ERC721 || x.type === CONTRACT_TYPE_ERC1155) totalAmountString = x.symbol;
|
|
33
|
+
else if (x.type === CONTRACT_TYPE_ERC20) totalAmountString = formatSmallNumbers(Number.parseFloat(x.total_amount), x.symbol, true);
|
|
34
|
+
else totalAmountString = formatSmallNumbers(Number.parseFloat(x.total_amount), x.type_name, true);
|
|
35
|
+
const currencyAmountString =
|
|
36
|
+
x.type === CONTRACT_TYPE_ERC721 || x.type === CONTRACT_TYPE_ERC1155
|
|
37
|
+
? ""
|
|
38
|
+
: formatSmallNumbers(Number.parseFloat(x.currency_amount), x.selected_currency, true);
|
|
39
|
+
const finalObject: FormattedTransactionActivity = {
|
|
40
|
+
id: x.created_at.toString(),
|
|
41
|
+
date: new Date(x.created_at).toString(),
|
|
42
|
+
from: x.from,
|
|
43
|
+
from_aa_address: x.from_aa_address,
|
|
44
|
+
slicedFrom: typeof x.from === "string" ? addressSlicer(x.from) : "",
|
|
45
|
+
to: x.to,
|
|
46
|
+
slicedTo: typeof x.to === "string" ? addressSlicer(x.to) : "",
|
|
47
|
+
action: lowerCaseSelectedAddress === x.to?.toLowerCase() || "" ? ACTIVITY_ACTION_RECEIVE : ACTIVITY_ACTION_SEND,
|
|
48
|
+
totalAmount: x.total_amount,
|
|
49
|
+
totalAmountString,
|
|
50
|
+
currencyAmount: x.currency_amount,
|
|
51
|
+
currencyAmountString,
|
|
52
|
+
amount: `${totalAmountString} / ${currencyAmountString}`,
|
|
53
|
+
status: x.status,
|
|
54
|
+
etherscanLink: getEtherScanHashLink(x.transaction_hash, x.network || MAINNET_CHAIN_ID),
|
|
55
|
+
networkType: x.network,
|
|
56
|
+
ethRate:
|
|
57
|
+
Number.parseFloat(x?.total_amount) && Number.parseFloat(x?.currency_amount)
|
|
58
|
+
? `1 ${x.symbol} = ${significantDigits(Number.parseFloat(x.currency_amount) / Number.parseFloat(x.total_amount))}`
|
|
59
|
+
: "",
|
|
60
|
+
currencyUsed: x.selected_currency,
|
|
61
|
+
type: x.type,
|
|
62
|
+
type_name: x.type_name,
|
|
63
|
+
type_image_link: x.type_image_link,
|
|
64
|
+
transaction_hash: x.transaction_hash,
|
|
65
|
+
transaction_category: x.transaction_category,
|
|
66
|
+
// TODO: // figure out how to handle these values.
|
|
67
|
+
// isEtherscan: x.isEtherscan,
|
|
68
|
+
// input: x.input || "",
|
|
69
|
+
// token_id: x.token_id || "",
|
|
70
|
+
contract_address: x.contract_address || "",
|
|
71
|
+
nonce: x.nonce || "",
|
|
72
|
+
is_cancel: !!x.is_cancel || false,
|
|
73
|
+
gas: x.gas || "",
|
|
74
|
+
gasPrice: x.gasPrice || "",
|
|
75
|
+
};
|
|
76
|
+
return finalObject;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
|
|
81
|
+
*/
|
|
82
|
+
export const getEthTxStatus = async (hash: string, provider: SafeEventEmitterProvider): Promise<TransactionStatus | undefined> => {
|
|
83
|
+
try {
|
|
84
|
+
const result = await provider.request<[string], TransactionReceipt>({ method: METHOD_TYPES.ETH_GET_TRANSACTION_RECEIPT, params: [hash] });
|
|
85
|
+
if (result === null) return TransactionStatus.submitted;
|
|
86
|
+
if (result && result.status === "0x1") return TransactionStatus.confirmed;
|
|
87
|
+
if (result && result.status === "0x0") return TransactionStatus.rejected;
|
|
88
|
+
return undefined;
|
|
89
|
+
} catch (err) {
|
|
90
|
+
log.warn("unable to fetch transaction status", err);
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export function formatDate(inputDate: string) {
|
|
96
|
+
const monthList = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
97
|
+
const date = new Date(inputDate);
|
|
98
|
+
const day = date.getDate();
|
|
99
|
+
const month = monthList[date.getMonth()];
|
|
100
|
+
const year = date.getFullYear();
|
|
101
|
+
return `${day} ${month} ${year}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function formatTime(time: number) {
|
|
105
|
+
return new Date(time).toTimeString().slice(0, 8);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const idleTimeTracker = ((activityThresholdTime: number): { checkIfIdle: () => boolean } => {
|
|
109
|
+
let isIdle = false;
|
|
110
|
+
let idleTimeout: number = null;
|
|
111
|
+
|
|
112
|
+
const resetTimer = () => {
|
|
113
|
+
if (idleTimeout) {
|
|
114
|
+
window.clearTimeout(idleTimeout);
|
|
115
|
+
}
|
|
116
|
+
isIdle = false;
|
|
117
|
+
idleTimeout = window.setTimeout(() => {
|
|
118
|
+
isIdle = true;
|
|
119
|
+
}, activityThresholdTime * 1000);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
window.addEventListener("load", resetTimer);
|
|
123
|
+
document.addEventListener("mousemove", resetTimer);
|
|
124
|
+
document.addEventListener("keydown", resetTimer);
|
|
125
|
+
|
|
126
|
+
function checkIfIdle() {
|
|
127
|
+
return isIdle;
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
checkIfIdle,
|
|
131
|
+
};
|
|
132
|
+
})(60 * 3);
|
|
133
|
+
|
|
134
|
+
export function isAddressByChainId(address: string, _chainId: string) {
|
|
135
|
+
// TOOD: add rsk network checks.
|
|
136
|
+
return isValidAddress(address);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export function toChecksumAddressByChainId(address: string, chainId: string) {
|
|
140
|
+
// TOOD: add rsk network checks.
|
|
141
|
+
if (!isAddressByChainId(address, chainId)) return address;
|
|
142
|
+
return toChecksumAddress(address);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const GAS_LIMITS = {
|
|
146
|
+
// maximum gasLimit of a simple send
|
|
147
|
+
SIMPLE: addHexPrefix((21_000).toString(16)),
|
|
148
|
+
// a base estimate for token transfers.
|
|
149
|
+
BASE_TOKEN_ESTIMATE: addHexPrefix((100_000).toString(16)),
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export function bnLessThan(a: string | number, b: string | number) {
|
|
153
|
+
if (a === null || a === undefined || b === null || b === undefined) {
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
return new BigNumber(a, 10).lt(b, 10);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export const getIpfsEndpoint = (path: string) => `https://infura-ipfs.io/${path}`;
|
|
160
|
+
|
|
161
|
+
export function sanitizeNftMetdataUrl(url: string): string {
|
|
162
|
+
let finalUri = url;
|
|
163
|
+
if (url?.startsWith("ipfs")) {
|
|
164
|
+
const ipfsPath = url.split("ipfs://")[1];
|
|
165
|
+
finalUri = getIpfsEndpoint(ipfsPath);
|
|
166
|
+
}
|
|
167
|
+
return finalUri;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function getChainType(chainId: string) {
|
|
171
|
+
if (chainId === MAINNET_CHAIN_ID) {
|
|
172
|
+
return "mainnet";
|
|
173
|
+
} else if ((TEST_CHAINS as string[]).includes(chainId)) {
|
|
174
|
+
return "testnet";
|
|
175
|
+
}
|
|
176
|
+
return "custom";
|
|
177
|
+
}
|
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { AccessList } from "@ethereumjs/common";
|
|
2
|
+
import { SignTypedDataVersion } from "@metamask/eth-sig-util";
|
|
3
|
+
import {
|
|
4
|
+
AddressPreferences,
|
|
5
|
+
BaseBlockTrackerState,
|
|
6
|
+
NetworkConfig,
|
|
7
|
+
NetworkState,
|
|
8
|
+
PaymentTransaction,
|
|
9
|
+
PopupWhitelabelData,
|
|
10
|
+
ProviderConfig,
|
|
11
|
+
TRANSACTION_TYPE,
|
|
12
|
+
TransactionMeta,
|
|
13
|
+
TransactionStatus,
|
|
14
|
+
User,
|
|
15
|
+
} from "@toruslabs/base-controllers";
|
|
16
|
+
import { Json } from "@toruslabs/openlogin-jrpc";
|
|
17
|
+
import { MutexInterface } from "async-mutex";
|
|
18
|
+
|
|
19
|
+
import { MessageStatus, METHOD_TYPES, TRANSACTION_ENVELOPE_TYPES } from "./constants";
|
|
20
|
+
|
|
21
|
+
export type CustomTokenInfo = {
|
|
22
|
+
tokenAddress: string;
|
|
23
|
+
name: string;
|
|
24
|
+
chainId: string;
|
|
25
|
+
erc20: boolean;
|
|
26
|
+
symbol: string;
|
|
27
|
+
decimals: string;
|
|
28
|
+
balance?: string;
|
|
29
|
+
customTokenId?: string;
|
|
30
|
+
isEtherScan?: boolean;
|
|
31
|
+
logo?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type CustomNftItemInfo = {
|
|
35
|
+
image: string;
|
|
36
|
+
name: string;
|
|
37
|
+
tokenBalance: string;
|
|
38
|
+
description: string;
|
|
39
|
+
tokenId: string;
|
|
40
|
+
video?: string;
|
|
41
|
+
decimals?: string;
|
|
42
|
+
customNftId?: string;
|
|
43
|
+
};
|
|
44
|
+
export type NftStandardType = "erc721" | "erc1155";
|
|
45
|
+
|
|
46
|
+
export type CustomNftInfo = {
|
|
47
|
+
contractAddress: string;
|
|
48
|
+
contractName: string;
|
|
49
|
+
contractSymbol: string;
|
|
50
|
+
contractImage?: string;
|
|
51
|
+
contractSupply?: string;
|
|
52
|
+
contractFallbackLogo?: string;
|
|
53
|
+
nftStandard: NftStandardType;
|
|
54
|
+
contractDescription?: string;
|
|
55
|
+
chainId: string;
|
|
56
|
+
assets: CustomNftItemInfo[];
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export interface EthereumBlock {
|
|
60
|
+
blockHash: string;
|
|
61
|
+
idempotencyKey: string;
|
|
62
|
+
timestamp: string;
|
|
63
|
+
baseFeePerGas: string;
|
|
64
|
+
gasLimit: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface UserRequestApprovalParams {
|
|
68
|
+
windowId?: string;
|
|
69
|
+
origin?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface BaseRequestParams {
|
|
73
|
+
/**
|
|
74
|
+
* Unique id for each request
|
|
75
|
+
*/
|
|
76
|
+
id: string;
|
|
77
|
+
/**
|
|
78
|
+
* Address to send this transaction from.
|
|
79
|
+
*/
|
|
80
|
+
from: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Domain requested from
|
|
84
|
+
*/
|
|
85
|
+
origin?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface MessageParams extends BaseRequestParams {
|
|
89
|
+
data: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export type MessageStatusType = (typeof MessageStatus)[keyof typeof MessageStatus];
|
|
93
|
+
|
|
94
|
+
export interface AbstractMessage {
|
|
95
|
+
id: string;
|
|
96
|
+
time: number;
|
|
97
|
+
status: MessageStatusType;
|
|
98
|
+
/**
|
|
99
|
+
* JRPC method for which sig request is made
|
|
100
|
+
*/
|
|
101
|
+
type: string;
|
|
102
|
+
rawSig?: string;
|
|
103
|
+
metadata?: Json;
|
|
104
|
+
error?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface Message extends AbstractMessage {
|
|
108
|
+
messageParams: MessageParams;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type SignTypedDataMessageV3V4 = {
|
|
112
|
+
types: Record<string, unknown>;
|
|
113
|
+
domain: Record<string, unknown>;
|
|
114
|
+
primaryType: string;
|
|
115
|
+
message: unknown;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
export interface TypedMessageParams extends BaseRequestParams {
|
|
119
|
+
data: Record<string, unknown>[] | string | SignTypedDataMessageV3V4;
|
|
120
|
+
version?: SignTypedDataVersion;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface TypedMessage extends AbstractMessage {
|
|
124
|
+
messageParams: TypedMessageParams;
|
|
125
|
+
}
|
|
126
|
+
export type TRANSACTION_ENVELOPE_TYPES_TYPE = (typeof TRANSACTION_ENVELOPE_TYPES)[keyof typeof TRANSACTION_ENVELOPE_TYPES];
|
|
127
|
+
|
|
128
|
+
export interface TransactionParams extends BaseRequestParams {
|
|
129
|
+
/**
|
|
130
|
+
* Network ID as per EIP-155.
|
|
131
|
+
*/
|
|
132
|
+
chainId?: string;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Data to pass with this transaction.
|
|
136
|
+
*/
|
|
137
|
+
data?: string;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Error message for gas estimation failure.
|
|
141
|
+
*/
|
|
142
|
+
estimateGasError?: string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Estimated base fee for this transaction.
|
|
146
|
+
*/
|
|
147
|
+
estimatedBaseFee?: string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Gas to send with this transaction.
|
|
151
|
+
*/
|
|
152
|
+
gas?: string;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Price of gas with this transaction.
|
|
156
|
+
*/
|
|
157
|
+
gasPrice?: string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gas used in the transaction.
|
|
161
|
+
*/
|
|
162
|
+
gasUsed?: string;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Maximum fee per gas for this transaction.
|
|
166
|
+
*/
|
|
167
|
+
maxFeePerGas?: string;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Maximum priority fee per gas for this transaction.
|
|
171
|
+
*/
|
|
172
|
+
maxPriorityFeePerGas?: string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Unique number to prevent replay attacks.
|
|
176
|
+
*/
|
|
177
|
+
nonce?: string;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Address to send this transaction to.
|
|
181
|
+
*/
|
|
182
|
+
to?: string;
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Value associated with this transaction.
|
|
186
|
+
*/
|
|
187
|
+
value?: string;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* EIP 2930
|
|
191
|
+
*/
|
|
192
|
+
accessList?: AccessList;
|
|
193
|
+
/**
|
|
194
|
+
* Custom Nonce passed by the user
|
|
195
|
+
*/
|
|
196
|
+
customNonceValue?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Transaction envelope type
|
|
199
|
+
*/
|
|
200
|
+
type?: TRANSACTION_ENVELOPE_TYPES_TYPE;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Max Gas to send with this transaction.
|
|
204
|
+
*/
|
|
205
|
+
gasLimit?: string;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export type Nonce = {
|
|
209
|
+
name: string;
|
|
210
|
+
nonce: number;
|
|
211
|
+
details: {
|
|
212
|
+
startPoint?: number;
|
|
213
|
+
highest?: number;
|
|
214
|
+
block?: EthereumBlock;
|
|
215
|
+
baseCount?: number;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
export type NonceDetails = {
|
|
220
|
+
params: {
|
|
221
|
+
highestLocallyConfirmed: number; // A hex string of the highest nonce on a confirmed transaction.
|
|
222
|
+
nextNetworkNonce: number; // The next nonce suggested by the eth_getTransactionCount method.
|
|
223
|
+
highestSuggested: number; // The maximum between the other two, the number returned.
|
|
224
|
+
};
|
|
225
|
+
local: Nonce;
|
|
226
|
+
network: Nonce;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Ref - https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactionreceipt
|
|
231
|
+
*/
|
|
232
|
+
export interface TransactionReceipt {
|
|
233
|
+
transactionHash: string;
|
|
234
|
+
transactionIndex: string;
|
|
235
|
+
blockNumber: string;
|
|
236
|
+
blockHash: string;
|
|
237
|
+
from: string;
|
|
238
|
+
to: string | null;
|
|
239
|
+
cumulativeGasUsed: string;
|
|
240
|
+
effectiveGasPrice: string;
|
|
241
|
+
gasUsed: string;
|
|
242
|
+
contractAddress: string | null;
|
|
243
|
+
logs: unknown[];
|
|
244
|
+
logsBloom: string;
|
|
245
|
+
type: TRANSACTION_ENVELOPE_TYPES_TYPE;
|
|
246
|
+
root?: string;
|
|
247
|
+
status?: "0x0" | "0x1";
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export type BlockTag = "earliest" | "finalized" | "safe" | "latest" | "pending";
|
|
251
|
+
export type BlockParams = string | BlockTag;
|
|
252
|
+
|
|
253
|
+
export interface TransactionRPCMeta {
|
|
254
|
+
v: string;
|
|
255
|
+
r: string;
|
|
256
|
+
s: string;
|
|
257
|
+
to: string | null;
|
|
258
|
+
gas: string;
|
|
259
|
+
from: string;
|
|
260
|
+
hash: string;
|
|
261
|
+
nonce: string;
|
|
262
|
+
input: string;
|
|
263
|
+
value: string;
|
|
264
|
+
accessList?: string[];
|
|
265
|
+
blockHash: string | null;
|
|
266
|
+
blockNumber: string | null;
|
|
267
|
+
transactionIndex: string | null;
|
|
268
|
+
maxFeePerGas?: string;
|
|
269
|
+
maxPriorityFeePerGas?: string;
|
|
270
|
+
gasPrice?: string;
|
|
271
|
+
type: TRANSACTION_ENVELOPE_TYPES_TYPE;
|
|
272
|
+
chainID?: string;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export type PollingBlockTrackerState = BaseBlockTrackerState<EthereumBlock>;
|
|
276
|
+
|
|
277
|
+
export interface EthereumProviderConfig extends ProviderConfig {
|
|
278
|
+
isErc20?: boolean;
|
|
279
|
+
tokenAddress?: string;
|
|
280
|
+
isTestNet?: boolean;
|
|
281
|
+
// infuraKey?: string;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface EthereumNetworkState extends NetworkState {
|
|
285
|
+
providerConfig: EthereumProviderConfig;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface EthereumNetworkConfig extends NetworkConfig {
|
|
289
|
+
providerConfig: EthereumProviderConfig;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export type CustomNetworkPayload = Partial<EthereumProviderConfig> & Pick<EthereumProviderConfig, "chainId" | "displayName" | "rpcTarget" | "ticker">;
|
|
293
|
+
|
|
294
|
+
export interface CustomNetworks {
|
|
295
|
+
id: number;
|
|
296
|
+
created_at: Date;
|
|
297
|
+
updated_at: Date;
|
|
298
|
+
network_name: string;
|
|
299
|
+
public_address: string;
|
|
300
|
+
chain_id: string;
|
|
301
|
+
type: string;
|
|
302
|
+
rpc_url: string;
|
|
303
|
+
deleted: boolean;
|
|
304
|
+
symbol?: string;
|
|
305
|
+
block_explorer_url?: string;
|
|
306
|
+
is_test_net?: boolean;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
export interface EthereumUser extends User {
|
|
310
|
+
customNetworks: CustomNetworks[];
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface ContractParams {
|
|
314
|
+
erc20?: boolean;
|
|
315
|
+
erc721?: boolean;
|
|
316
|
+
erc1155?: boolean;
|
|
317
|
+
isSpecial?: boolean;
|
|
318
|
+
symbol?: string;
|
|
319
|
+
logo?: string;
|
|
320
|
+
decimals?: number;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
export interface DappSuggestedGasFees {
|
|
324
|
+
gasPrice?: string;
|
|
325
|
+
maxPriorityFeePerGas?: string;
|
|
326
|
+
maxFeePerGas?: string;
|
|
327
|
+
gas?: string;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface EthereumTransactionMeta extends TransactionMeta<TransactionParams> {
|
|
331
|
+
r?: string;
|
|
332
|
+
s?: string;
|
|
333
|
+
v?: string;
|
|
334
|
+
type: string;
|
|
335
|
+
txReceipt?: TransactionReceipt;
|
|
336
|
+
history: Record<string, unknown>[];
|
|
337
|
+
accessList?: string[];
|
|
338
|
+
firstRetryBlockNumber?: string;
|
|
339
|
+
retryCount?: number;
|
|
340
|
+
simulationFails?: Record<string, unknown>;
|
|
341
|
+
loadingDefaults?: boolean;
|
|
342
|
+
transactionCategory?: TRANSACTION_TYPE;
|
|
343
|
+
nonceDetails?: NonceDetails;
|
|
344
|
+
methodParams?: unknown[];
|
|
345
|
+
dappSuggestedGasFees?: DappSuggestedGasFees;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// TODO:// mark fields which will be optional.
|
|
349
|
+
export interface TransactionPayload {
|
|
350
|
+
created_at: Date;
|
|
351
|
+
from: string;
|
|
352
|
+
to: string;
|
|
353
|
+
total_amount: string;
|
|
354
|
+
currency_amount: string;
|
|
355
|
+
selected_currency: string;
|
|
356
|
+
status?: TransactionStatus;
|
|
357
|
+
network: string;
|
|
358
|
+
transaction_hash: string;
|
|
359
|
+
transaction_category: string;
|
|
360
|
+
gas: string;
|
|
361
|
+
gasPrice: string;
|
|
362
|
+
nonce: string;
|
|
363
|
+
type: string;
|
|
364
|
+
type_name: string;
|
|
365
|
+
type_image_link: string;
|
|
366
|
+
symbol: string;
|
|
367
|
+
is_cancel: boolean;
|
|
368
|
+
contract_address?: string;
|
|
369
|
+
from_aa_address?: string;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface FetchedTransaction extends TransactionPayload {
|
|
373
|
+
id: string;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface FetchCommonTransaction extends PaymentTransaction {
|
|
377
|
+
etherscanLink?: string | null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface FormattedTransactionActivity {
|
|
381
|
+
id: string;
|
|
382
|
+
date: string;
|
|
383
|
+
from: string;
|
|
384
|
+
from_aa_address?: string;
|
|
385
|
+
slicedFrom: string;
|
|
386
|
+
to: string;
|
|
387
|
+
slicedTo: string;
|
|
388
|
+
action: string;
|
|
389
|
+
totalAmount: string;
|
|
390
|
+
totalAmountString: string;
|
|
391
|
+
currencyAmount: string;
|
|
392
|
+
currencyAmountString: string;
|
|
393
|
+
amount: string;
|
|
394
|
+
status: TransactionStatus;
|
|
395
|
+
etherscanLink: string;
|
|
396
|
+
ethRate: string;
|
|
397
|
+
currencyUsed: string;
|
|
398
|
+
networkType: string;
|
|
399
|
+
type: string;
|
|
400
|
+
type_name: string;
|
|
401
|
+
type_image_link: string;
|
|
402
|
+
transaction_hash: string;
|
|
403
|
+
isEtherscan?: boolean;
|
|
404
|
+
transaction_category: string;
|
|
405
|
+
input?: string;
|
|
406
|
+
contract_address?: string;
|
|
407
|
+
token_id?: string;
|
|
408
|
+
nonce: string;
|
|
409
|
+
is_cancel: boolean;
|
|
410
|
+
gas: string;
|
|
411
|
+
gasPrice: string;
|
|
412
|
+
hasCancel?: boolean;
|
|
413
|
+
cancelDateInitiated?: string;
|
|
414
|
+
cancelGas?: string;
|
|
415
|
+
cancelGasPrice?: string;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
export interface ExtendedAddressPreferences extends AddressPreferences {
|
|
419
|
+
fetchedPastTx?: FetchedTransaction[];
|
|
420
|
+
formattedPastTransactions?: FormattedTransactionActivity[];
|
|
421
|
+
paymentTx: FetchCommonTransaction[];
|
|
422
|
+
customNetworks: CustomNetworks[];
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export interface ProviderChangeChannelEventData {
|
|
426
|
+
newNetwork: EthereumProviderConfig;
|
|
427
|
+
whitelabelData: PopupWhitelabelData;
|
|
428
|
+
origin: string;
|
|
429
|
+
currentChainId: string;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
export interface NonceLockRes {
|
|
433
|
+
nextNonce: number;
|
|
434
|
+
nonceDetails: NonceDetails;
|
|
435
|
+
releaseLock: MutexInterface.Releaser;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export type METHOD_TYPES_TYPE = (typeof METHOD_TYPES)[keyof typeof METHOD_TYPES];
|
|
439
|
+
|
|
440
|
+
export interface EncryptionPublicKeyParams extends BaseRequestParams {
|
|
441
|
+
data: string;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
export interface EncryptionPublicKey extends AbstractMessage {
|
|
445
|
+
messageParams: EncryptionPublicKeyParams;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
export interface DecryptMessageParams extends BaseRequestParams {
|
|
449
|
+
data: string;
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export interface DecryptMessage extends AbstractMessage {
|
|
453
|
+
messageParams: DecryptMessageParams;
|
|
454
|
+
}
|