@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,53 @@
|
|
|
1
|
+
import { BasePreferencesController, CustomNft, CustomToken, IPreferencesController, PreferencesConfig, PreferencesState, UserInfo } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
5
|
+
import NetworkController from "../Network/NetworkController";
|
|
6
|
+
import type { CustomNetworkPayload, CustomNftInfo, CustomTokenInfo, ExtendedAddressPreferences, TransactionPayload } from "../utils/interfaces";
|
|
7
|
+
interface IPreferencesControllerOptions {
|
|
8
|
+
config?: Partial<PreferencesConfig> & Pick<PreferencesConfig, "api" | "commonApiHost" | "signInPrefix">;
|
|
9
|
+
state?: Partial<PreferencesState<ExtendedAddressPreferences>>;
|
|
10
|
+
provider: SafeEventEmitterProvider;
|
|
11
|
+
blockTracker?: PollingBlockTracker;
|
|
12
|
+
signAuthMessage?: KeyringController["signAuthMessage"];
|
|
13
|
+
getProviderConfig?: NetworkController["getProviderConfig"];
|
|
14
|
+
}
|
|
15
|
+
export default class PreferencesController extends BasePreferencesController<ExtendedAddressPreferences, PreferencesConfig, PreferencesState<ExtendedAddressPreferences>> implements IPreferencesController<ExtendedAddressPreferences, PreferencesConfig, PreferencesState<ExtendedAddressPreferences>> {
|
|
16
|
+
private _handle?;
|
|
17
|
+
private _mutex;
|
|
18
|
+
private getProviderConfig;
|
|
19
|
+
private provider;
|
|
20
|
+
private blockTracker;
|
|
21
|
+
constructor({ config, state, provider, blockTracker, signAuthMessage, getProviderConfig }: IPreferencesControllerOptions);
|
|
22
|
+
poll(interval?: number): Promise<void>;
|
|
23
|
+
initPreferences(params: {
|
|
24
|
+
address: string;
|
|
25
|
+
jwtToken?: string;
|
|
26
|
+
calledFromEmbed?: boolean;
|
|
27
|
+
userInfo?: UserInfo;
|
|
28
|
+
rehydrate?: boolean;
|
|
29
|
+
locale?: string;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
getSelectedAddress(): string;
|
|
32
|
+
sync(address: string): Promise<boolean>;
|
|
33
|
+
patchNewTx(tx: TransactionPayload, address: string): Promise<void>;
|
|
34
|
+
recalculatePastTx(address?: string): void;
|
|
35
|
+
refetchEtherscanTx(address?: string): Promise<void>;
|
|
36
|
+
getEtherScanTokens(address: string, chainId: string): Promise<CustomTokenInfo[]>;
|
|
37
|
+
getSimpleHashNfts(address: string, chainId: string): Promise<CustomNftInfo[]>;
|
|
38
|
+
getCustomTokens(address?: string): CustomToken[];
|
|
39
|
+
getCustomNfts(address?: string): CustomNft[];
|
|
40
|
+
addCustomNetwork({ type, network }: {
|
|
41
|
+
type: string;
|
|
42
|
+
network: CustomNetworkPayload;
|
|
43
|
+
}): Promise<number>;
|
|
44
|
+
deleteCustomNetwork(id: number): Promise<boolean>;
|
|
45
|
+
editCustomNetwork({ network, id }: {
|
|
46
|
+
network: CustomNetworkPayload;
|
|
47
|
+
id: number | null;
|
|
48
|
+
}): Promise<boolean>;
|
|
49
|
+
private calculatePaymentTx;
|
|
50
|
+
private calculatePastTx;
|
|
51
|
+
private cancelTxCalculate;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseConfig, BaseState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { CustomTokenInfo } from "../utils/interfaces";
|
|
3
|
+
export interface TokensControllerConfig extends BaseConfig {
|
|
4
|
+
interval?: number;
|
|
5
|
+
selectedAddress: string;
|
|
6
|
+
chainId: string;
|
|
7
|
+
}
|
|
8
|
+
export interface TokensControllerState extends BaseState {
|
|
9
|
+
tokens: Record<string, CustomTokenInfo[]>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { BrowserProvider, Contract } from "ethers";
|
|
2
|
+
export interface ITokenOptions {
|
|
3
|
+
address: string;
|
|
4
|
+
symbol: string;
|
|
5
|
+
decimals: number;
|
|
6
|
+
name: string;
|
|
7
|
+
provider: BrowserProvider;
|
|
8
|
+
}
|
|
9
|
+
export declare class TokenHandler {
|
|
10
|
+
address: string;
|
|
11
|
+
symbol: string;
|
|
12
|
+
decimals: number;
|
|
13
|
+
name: string;
|
|
14
|
+
contract: Contract;
|
|
15
|
+
constructor({ address, symbol, decimals, name, provider }: ITokenOptions);
|
|
16
|
+
getSymbol(): Promise<string>;
|
|
17
|
+
getDecimals(): Promise<number>;
|
|
18
|
+
getName(): Promise<string>;
|
|
19
|
+
getUserBalance(userAddress: string): Promise<string>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseConfig, BaseController, BaseState, PreferencesState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { CustomTokenInfo, EthereumNetworkState, ExtendedAddressPreferences } from "../utils/interfaces";
|
|
3
|
+
import { TokensControllerState } from "./ITokensController";
|
|
4
|
+
export interface CoinGeckoResponse {
|
|
5
|
+
[address: string]: {
|
|
6
|
+
[currency: string]: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
type ContractExchangeRates = Record<string, number | undefined>;
|
|
10
|
+
export declare const DEFAULT_CURRENCY = "eth";
|
|
11
|
+
export interface ITokenRatesControllerState extends BaseState {
|
|
12
|
+
contractExchangeRates: ContractExchangeRates;
|
|
13
|
+
}
|
|
14
|
+
export interface ITokenRatesControllerConfig extends BaseConfig {
|
|
15
|
+
pollInterval: number;
|
|
16
|
+
api: string;
|
|
17
|
+
currencyApi: string;
|
|
18
|
+
chainId: string;
|
|
19
|
+
selectedAddress: string;
|
|
20
|
+
nativeCurrency: string;
|
|
21
|
+
tokens: CustomTokenInfo[];
|
|
22
|
+
}
|
|
23
|
+
export interface TokenRatesControllerOptions {
|
|
24
|
+
config: Partial<ITokenRatesControllerConfig>;
|
|
25
|
+
state: Partial<ITokenRatesControllerState>;
|
|
26
|
+
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
27
|
+
onTokensStateChange: (listener: (tokensState: TokensControllerState) => void) => void;
|
|
28
|
+
onNetworkStateChange: (listener: (networkState: EthereumNetworkState) => void) => void;
|
|
29
|
+
}
|
|
30
|
+
export declare class TokenRatesController extends BaseController<ITokenRatesControllerConfig, ITokenRatesControllerState> {
|
|
31
|
+
private conversionInterval;
|
|
32
|
+
constructor({ config, state, onPreferencesStateChange, onNetworkStateChange, onTokensStateChange }: TokenRatesControllerOptions);
|
|
33
|
+
/**
|
|
34
|
+
* Creates a new poll, using setInterval, to periodically call updateConversionRate. The id of the interval is
|
|
35
|
+
* stored at the controller's conversionInterval property. If it is called and such an id already exists, the
|
|
36
|
+
* previous interval is clear and a new one is created.
|
|
37
|
+
*/
|
|
38
|
+
scheduleConversionInterval(): void;
|
|
39
|
+
updateExchangeRates(): Promise<void>;
|
|
40
|
+
private fetchExchangeRates;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { BaseController, PreferencesState } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import NetworkController from "../Network/NetworkController";
|
|
4
|
+
import PreferencesController from "../Preferences/PreferencesController";
|
|
5
|
+
import { CustomTokenInfo, EthereumNetworkState, ExtendedAddressPreferences } from "../utils/interfaces";
|
|
6
|
+
import { TokensControllerConfig, TokensControllerState } from "./ITokensController";
|
|
7
|
+
export interface ITokensControllerOptions {
|
|
8
|
+
config?: Partial<TokensControllerConfig>;
|
|
9
|
+
state?: Partial<TokensControllerState>;
|
|
10
|
+
provider: SafeEventEmitterProvider;
|
|
11
|
+
getNetworkIdentifier: NetworkController["getNetworkIdentifier"];
|
|
12
|
+
getCustomTokens?: PreferencesController["getCustomTokens"];
|
|
13
|
+
getEtherScanTokens: PreferencesController["getEtherScanTokens"];
|
|
14
|
+
getProviderConfig: NetworkController["getProviderConfig"];
|
|
15
|
+
onPreferencesStateChange: (listener: (preferencesState: PreferencesState<ExtendedAddressPreferences>) => void) => void;
|
|
16
|
+
onNetworkStateChange: (listener: (networkState: EthereumNetworkState) => void) => void;
|
|
17
|
+
}
|
|
18
|
+
export declare class TokensController extends BaseController<TokensControllerConfig, TokensControllerState> {
|
|
19
|
+
name: string;
|
|
20
|
+
private provider;
|
|
21
|
+
private ethersProvider;
|
|
22
|
+
private _timer;
|
|
23
|
+
private getNetworkIdentifier;
|
|
24
|
+
private getProviderConfig;
|
|
25
|
+
private getCustomTokens;
|
|
26
|
+
private getEtherScanTokens;
|
|
27
|
+
constructor({ config, state, provider, getNetworkIdentifier, getCustomTokens, getEtherScanTokens, getProviderConfig, onPreferencesStateChange, onNetworkStateChange, }: ITokensControllerOptions);
|
|
28
|
+
get userSelectedAddress(): string;
|
|
29
|
+
get userTokens(): CustomTokenInfo[];
|
|
30
|
+
get interval(): number;
|
|
31
|
+
set interval(interval: number);
|
|
32
|
+
startTokenDetection(selectedAddress: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* Restart token detection polling period and call detectNewTokens
|
|
35
|
+
* in case of address change or user session initialization.
|
|
36
|
+
*
|
|
37
|
+
*/
|
|
38
|
+
restartTokenDetection(): void;
|
|
39
|
+
detectNewTokens(): void;
|
|
40
|
+
refreshTokenBalances(): Promise<void>;
|
|
41
|
+
getTokenBalancesUsingHandler(customTokens: CustomTokenInfo[]): Promise<void>;
|
|
42
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
2
|
+
import { MutexInterface } from "async-mutex";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
import { NonceLockRes } from "../utils/interfaces";
|
|
5
|
+
import TransactionStateManager from "./TransactionStateManager";
|
|
6
|
+
interface INonceTrackerOptions {
|
|
7
|
+
provider: SafeEventEmitterProvider;
|
|
8
|
+
blockTracker: PollingBlockTracker;
|
|
9
|
+
getPendingTransactions: TransactionStateManager["getPendingTransactions"];
|
|
10
|
+
getConfirmedTransactions: TransactionStateManager["getConfirmedTransactions"];
|
|
11
|
+
}
|
|
12
|
+
declare class NonceTracker {
|
|
13
|
+
private provider;
|
|
14
|
+
private blockTracker;
|
|
15
|
+
private getPendingTransactions;
|
|
16
|
+
private getConfirmedTransactions;
|
|
17
|
+
private lockMap;
|
|
18
|
+
constructor({ provider, blockTracker, getPendingTransactions, getConfirmedTransactions }: INonceTrackerOptions);
|
|
19
|
+
getGlobalLock(): Promise<{
|
|
20
|
+
releaseLock: MutexInterface.Releaser;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
this will return an object with the `nextNonce`
|
|
24
|
+
`nonceDetails`, and the releaseLock.
|
|
25
|
+
Note: releaseLock must be called after adding a signed tx
|
|
26
|
+
to pending transactions (or discarding).
|
|
27
|
+
*/
|
|
28
|
+
getNonceLock(address: string): Promise<NonceLockRes>;
|
|
29
|
+
private _globalMutexFree;
|
|
30
|
+
private _takeMutex;
|
|
31
|
+
private _lookupMutex;
|
|
32
|
+
private _getNetworkNextNonce;
|
|
33
|
+
private _getHighestLocallyConfirmed;
|
|
34
|
+
private _getHighestNonce;
|
|
35
|
+
private _getHighestContinuousFrom;
|
|
36
|
+
}
|
|
37
|
+
export default NonceTracker;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ITransactionController } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitter, SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import { EthereumBlock, EthereumTransactionMeta } from "../utils/interfaces";
|
|
4
|
+
import NonceTracker from "./NonceTracker";
|
|
5
|
+
import TransactionStateManager from "./TransactionStateManager";
|
|
6
|
+
export default class PendingTransactionTracker extends SafeEventEmitter {
|
|
7
|
+
DROPPED_BUFFER_COUNT: number;
|
|
8
|
+
private nonceTracker;
|
|
9
|
+
private provider;
|
|
10
|
+
private approveTransaction;
|
|
11
|
+
private droppedBlocksBufferByHash;
|
|
12
|
+
private getConfirmedTransactions;
|
|
13
|
+
private getPendingTransactions;
|
|
14
|
+
private publishTransaction;
|
|
15
|
+
constructor({ provider, nonceTracker, approveTransaction, publishTransaction, getPendingTransactions, getConfirmedTransactions, }: {
|
|
16
|
+
provider: SafeEventEmitterProvider;
|
|
17
|
+
nonceTracker: NonceTracker;
|
|
18
|
+
approveTransaction: ITransactionController<EthereumTransactionMeta>["approveTransaction"];
|
|
19
|
+
publishTransaction: (rawTx: string) => Promise<string>;
|
|
20
|
+
getPendingTransactions: TransactionStateManager["getPendingTransactions"];
|
|
21
|
+
getConfirmedTransactions: TransactionStateManager["getConfirmedTransactions"];
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
checks the network for signed txs and releases the nonce global lock if it is
|
|
25
|
+
*/
|
|
26
|
+
updatePendingTxs(): Promise<void>;
|
|
27
|
+
resubmitPendingTxs(block: EthereumBlock): Promise<void>;
|
|
28
|
+
_resubmitTx(txMeta: EthereumTransactionMeta, latestBlockNumber?: string): Promise<string | void>;
|
|
29
|
+
_checkPendingTx(foundTx: EthereumTransactionMeta): Promise<void>;
|
|
30
|
+
_checkIfTxWasDropped(txMeta: EthereumTransactionMeta): Promise<boolean>;
|
|
31
|
+
_checkIfNonceIsTaken(txMeta: EthereumTransactionMeta): boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ITransactionController, TransactionConfig, TransactionState, TX_CONFIRMED_EVENT_TYPE } from "@toruslabs/base-controllers";
|
|
2
|
+
import { JRPCRequest, SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
4
|
+
import GasFeeController from "../Gas/GasFeeController";
|
|
5
|
+
import KeyringController from "../Keyring/KeyringController";
|
|
6
|
+
import NetworkController from "../Network/NetworkController";
|
|
7
|
+
import PreferencesController from "../Preferences/PreferencesController";
|
|
8
|
+
import { EthereumTransactionMeta, TransactionParams, UserRequestApprovalParams } from "../utils/interfaces";
|
|
9
|
+
import NonceTracker from "./NonceTracker";
|
|
10
|
+
import PendingTransactionTracker from "./PendingTransactionTracker";
|
|
11
|
+
import TransactionGasUtil from "./TransactionGasUtil";
|
|
12
|
+
import TransactionStateManager from "./TransactionStateManager";
|
|
13
|
+
export default class TransactionController extends TransactionStateManager implements ITransactionController<TransactionParams> {
|
|
14
|
+
getSelectedAddress: PreferencesController["getSelectedAddress"];
|
|
15
|
+
getEIP1559GasFeeEstimates: GasFeeController["fetchGasFeeEstimates"];
|
|
16
|
+
nonceTracker: NonceTracker;
|
|
17
|
+
pendingTxTracker: PendingTransactionTracker;
|
|
18
|
+
txGasUtil: TransactionGasUtil;
|
|
19
|
+
private _getCurrentNetworkEIP1559Compatibility;
|
|
20
|
+
private _getCurrentAccountEIP1559Compatibility;
|
|
21
|
+
private getProviderConfig;
|
|
22
|
+
private signEthTx;
|
|
23
|
+
private provider;
|
|
24
|
+
private blockTracker;
|
|
25
|
+
private inProcessOfSigning;
|
|
26
|
+
constructor({ config, state, provider, blockTracker, signEthTx, getCurrentChainId, getCurrentNetworkEIP1559Compatibility, getProviderConfig, getCurrentAccountEIP1559Compatibility, getSelectedAddress, getEIP1559GasFeeEstimates, }: {
|
|
27
|
+
config?: Partial<TransactionConfig>;
|
|
28
|
+
state?: Partial<TransactionState<TransactionParams, EthereumTransactionMeta>>;
|
|
29
|
+
provider: SafeEventEmitterProvider;
|
|
30
|
+
blockTracker: PollingBlockTracker;
|
|
31
|
+
signEthTx: KeyringController["signTransaction"];
|
|
32
|
+
getCurrentChainId: NetworkController["getNetworkIdentifier"];
|
|
33
|
+
getProviderConfig: NetworkController["getProviderConfig"];
|
|
34
|
+
getCurrentNetworkEIP1559Compatibility: NetworkController["getEIP1559Compatibility"];
|
|
35
|
+
getCurrentAccountEIP1559Compatibility: (address?: string) => Promise<boolean>;
|
|
36
|
+
getSelectedAddress: PreferencesController["getSelectedAddress"];
|
|
37
|
+
getEIP1559GasFeeEstimates: GasFeeController["fetchGasFeeEstimates"];
|
|
38
|
+
});
|
|
39
|
+
addTransactionUnapproved(txMeta: EthereumTransactionMeta): void;
|
|
40
|
+
addNewUnapprovedTransaction(txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams & {
|
|
41
|
+
origin: string;
|
|
42
|
+
}): Promise<string>;
|
|
43
|
+
processApproval(txMeta: EthereumTransactionMeta): Promise<string>;
|
|
44
|
+
approveTransaction(transactionID: string): Promise<void>;
|
|
45
|
+
signTransaction(txId: string): Promise<string>;
|
|
46
|
+
publishTransaction(txId: string, rawTx: string): Promise<void>;
|
|
47
|
+
confirmTransaction(params: TX_CONFIRMED_EVENT_TYPE): Promise<void>;
|
|
48
|
+
cancelTransaction?(transactionID: string): Promise<void>;
|
|
49
|
+
getEIP1559Compatibility(fromAddress?: string): Promise<boolean>;
|
|
50
|
+
addTransactionGasDefaults(txMeta: EthereumTransactionMeta): Promise<EthereumTransactionMeta>;
|
|
51
|
+
addTxGasDefaults(txMeta: EthereumTransactionMeta): Promise<EthereumTransactionMeta>;
|
|
52
|
+
setTxHash(txId: string, txHash: string): void;
|
|
53
|
+
getUnapprovedTxCount: () => number;
|
|
54
|
+
getPendingTxCount: (account?: string) => number;
|
|
55
|
+
getDefaultGasFees(txMeta: EthereumTransactionMeta, eip1559Compatibility: boolean): Promise<{
|
|
56
|
+
maxFeePerGas?: string;
|
|
57
|
+
maxPriorityFeePerGas?: string;
|
|
58
|
+
gasPrice?: string;
|
|
59
|
+
}>;
|
|
60
|
+
private getDefaultGasLimit;
|
|
61
|
+
private createTransaction;
|
|
62
|
+
private _setupListeners;
|
|
63
|
+
private setupBlockTrackerListener;
|
|
64
|
+
private onLatestBlock;
|
|
65
|
+
private getCommonConfiguration;
|
|
66
|
+
private markNonceDuplicatesDropped;
|
|
67
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
2
|
+
import PollingBlockTracker from "../Block/PollingBlockTracker";
|
|
3
|
+
import { EthereumTransactionMeta } from "../utils/interfaces";
|
|
4
|
+
export default class TransactionGasUtil {
|
|
5
|
+
provider: SafeEventEmitterProvider;
|
|
6
|
+
blockTracker: PollingBlockTracker;
|
|
7
|
+
constructor(provider: SafeEventEmitterProvider, blockTracker: PollingBlockTracker);
|
|
8
|
+
analyzeGasUsage(txMeta: EthereumTransactionMeta): Promise<{
|
|
9
|
+
blockGasLimit: string;
|
|
10
|
+
estimatedGasHex: string;
|
|
11
|
+
simulationFails: Record<string, unknown>;
|
|
12
|
+
}>;
|
|
13
|
+
/**
|
|
14
|
+
Adds a gas buffer with out exceeding the block gas limit
|
|
15
|
+
*/
|
|
16
|
+
addGasBuffer(initialGasLimitHex: string, blockGasLimitHex: string, multiplier?: number): string;
|
|
17
|
+
/**
|
|
18
|
+
Estimates the tx's gas usage
|
|
19
|
+
*/
|
|
20
|
+
private estimateTxGas;
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { EthereumTransactionMeta } from "../utils/interfaces";
|
|
2
|
+
/**
|
|
3
|
+
Generates an array of history objects sense the previous state.
|
|
4
|
+
The object has the keys
|
|
5
|
+
op (the operation performed),
|
|
6
|
+
path (the key and if a nested object then each key will be seperated with a `/`)
|
|
7
|
+
value
|
|
8
|
+
with the first entry having the note and a timestamp when the change took place
|
|
9
|
+
*/
|
|
10
|
+
declare function generateHistoryEntry(previousState: Record<string, unknown>, newState: Record<string, unknown>, note?: string): Record<string, unknown>[];
|
|
11
|
+
/**
|
|
12
|
+
Recovers previous txMeta state obj
|
|
13
|
+
*/
|
|
14
|
+
declare function replayHistory(_shortHistory: Record<string, unknown>[]): Record<string, unknown>;
|
|
15
|
+
declare function snapshotFromTxMeta(txMeta: EthereumTransactionMeta): EthereumTransactionMeta;
|
|
16
|
+
export { generateHistoryEntry, replayHistory, snapshotFromTxMeta };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseTransactionStateManager, ITransactionStateManager, TransactionConfig, TransactionState, TransactionStatus } from "@toruslabs/base-controllers";
|
|
2
|
+
import NetworkController from "../Network/NetworkController";
|
|
3
|
+
import { EthereumTransactionMeta, TransactionParams } from "../utils/interfaces";
|
|
4
|
+
export default class TransactionStateManager extends BaseTransactionStateManager<TransactionParams, EthereumTransactionMeta> implements ITransactionStateManager<TransactionParams> {
|
|
5
|
+
constructor({ config, state, getCurrentChainId, }: {
|
|
6
|
+
config?: Partial<TransactionConfig>;
|
|
7
|
+
state?: Partial<TransactionState<TransactionParams, EthereumTransactionMeta>>;
|
|
8
|
+
getCurrentChainId: NetworkController["getNetworkIdentifier"];
|
|
9
|
+
});
|
|
10
|
+
generateTxMeta(opts?: Partial<EthereumTransactionMeta>): EthereumTransactionMeta;
|
|
11
|
+
addTransactionToState(txMeta: EthereumTransactionMeta): EthereumTransactionMeta;
|
|
12
|
+
/**
|
|
13
|
+
Removes transaction from the given address for the current network
|
|
14
|
+
from the txList
|
|
15
|
+
*/
|
|
16
|
+
wipeTransactions(address: string): void;
|
|
17
|
+
getTransactions({ searchCriteria, initialList, filterToCurrentNetwork, limit, }?: {
|
|
18
|
+
searchCriteria?: Record<string, (val: unknown) => boolean> | Record<string, unknown>;
|
|
19
|
+
initialList?: EthereumTransactionMeta[];
|
|
20
|
+
filterToCurrentNetwork?: boolean;
|
|
21
|
+
limit?: number;
|
|
22
|
+
}): EthereumTransactionMeta[];
|
|
23
|
+
getApprovedTransactions(address?: string): EthereumTransactionMeta[];
|
|
24
|
+
getSubmittedTransactions(address?: string): EthereumTransactionMeta[];
|
|
25
|
+
getPendingTransactions(address?: string): EthereumTransactionMeta[];
|
|
26
|
+
getConfirmedTransactions(address?: string): EthereumTransactionMeta[];
|
|
27
|
+
getUnapprovedTxList(): Record<string, EthereumTransactionMeta>;
|
|
28
|
+
updateTransactionInState(txMeta: EthereumTransactionMeta, note?: string): void;
|
|
29
|
+
protected _setTransactionStatus(txId: string, status: TransactionStatus, isFinalStep?: boolean): void;
|
|
30
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { TransactionStatus } from "@toruslabs/base-controllers";
|
|
2
|
+
import { SafeEventEmitterProvider } from "@toruslabs/openlogin-jrpc";
|
|
3
|
+
import { EthereumTransactionMeta, TransactionParams } from "../utils/interfaces";
|
|
4
|
+
type NormalizableTransactionParams = keyof Omit<TransactionParams, "accessList">;
|
|
5
|
+
/**
|
|
6
|
+
* normalizes txParams
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeTxParameters(txParameters: TransactionParams, lowerCase?: boolean): TransactionParams;
|
|
9
|
+
export declare function transactionMatchesNetwork(transaction: EthereumTransactionMeta, chainId: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Determines if the maxFeePerGas and maxPriorityFeePerGas fields are supplied
|
|
12
|
+
* and valid inputs. This will return false for non hex string inputs.
|
|
13
|
+
* the transaction to check
|
|
14
|
+
* @returns true if transaction uses valid EIP1559 fields
|
|
15
|
+
*/
|
|
16
|
+
export declare function isEIP1559Transaction(transaction: Partial<EthereumTransactionMeta>): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
|
|
19
|
+
* supplied and that the gasPrice field is valid if it is provided. This will
|
|
20
|
+
* return false if gasPrice is a non hex string.
|
|
21
|
+
* transaction -
|
|
22
|
+
* the transaction to check
|
|
23
|
+
* @returns true if transaction uses valid Legacy fields OR lacks
|
|
24
|
+
* EIP1559 fields
|
|
25
|
+
*/
|
|
26
|
+
export declare function isLegacyTransaction(transaction: EthereumTransactionMeta): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Given two fields, ensure that the second field is not included in txParams,
|
|
29
|
+
* and if it is throw an invalidParams error.
|
|
30
|
+
*/
|
|
31
|
+
export declare function ensureMutuallyExclusiveFieldsNotProvided(txParams: TransactionParams, fieldBeingValidated: NormalizableTransactionParams, mutuallyExclusiveField: NormalizableTransactionParams): void;
|
|
32
|
+
/**
|
|
33
|
+
* Ensures that the provided value for field is a string, throws an
|
|
34
|
+
* invalidParams error if field is not a string.
|
|
35
|
+
*/
|
|
36
|
+
export declare function ensureFieldIsString(txParams: TransactionParams, field: NormalizableTransactionParams): void;
|
|
37
|
+
/**
|
|
38
|
+
* validates the from field in txParams
|
|
39
|
+
*/
|
|
40
|
+
export declare function validateFrom(txParams: TransactionParams): void;
|
|
41
|
+
/**
|
|
42
|
+
* validates the to field in txParams
|
|
43
|
+
*/
|
|
44
|
+
export declare function validateRecipient(txParameters: TransactionParams): TransactionParams;
|
|
45
|
+
/**
|
|
46
|
+
* Validates the given tx parameters
|
|
47
|
+
* @throws if the tx params contains invalid fields
|
|
48
|
+
*/
|
|
49
|
+
export declare function validateTxParameters(txParams: TransactionParams, eip1559Compatibility?: boolean): void;
|
|
50
|
+
export declare function normalizeAndValidateTxParams(txParams: TransactionParams, lowerCase?: boolean): TransactionParams;
|
|
51
|
+
/**
|
|
52
|
+
* @returns an array of states that can be considered final
|
|
53
|
+
*/
|
|
54
|
+
export declare function getFinalStates(): TransactionStatus[];
|
|
55
|
+
export declare function parseStandardTokenTransactionData(data: string): {
|
|
56
|
+
name: string;
|
|
57
|
+
methodParams: any[];
|
|
58
|
+
type: string;
|
|
59
|
+
};
|
|
60
|
+
export declare const readAddressAsContract: (provider: SafeEventEmitterProvider, address: string) => Promise<{
|
|
61
|
+
contractCode: string;
|
|
62
|
+
isContractAddress: boolean;
|
|
63
|
+
}>;
|
|
64
|
+
export declare function determineTransactionType(txParams: TransactionParams, provider: SafeEventEmitterProvider): Promise<{
|
|
65
|
+
type: string;
|
|
66
|
+
category: string;
|
|
67
|
+
methodParams: any[];
|
|
68
|
+
getCodeResponse: string;
|
|
69
|
+
}>;
|
|
70
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export { default as AccountTrackerController } from "./Account/AccountTrackerController";
|
|
2
|
+
export { default as PollingBlockTracker } from "./Block/PollingBlockTracker";
|
|
3
|
+
export { default as CurrencyController } from "./Currency/CurrencyController";
|
|
4
|
+
export { default as GasFeeController } from "./Gas/GasFeeController";
|
|
5
|
+
export * from "./Gas/IGasFeeController";
|
|
6
|
+
export { default as KeyringController } from "./Keyring/KeyringController";
|
|
7
|
+
export * from "./Message/AbstractMessageController";
|
|
8
|
+
export * from "./Message/DecryptMessageController";
|
|
9
|
+
export * from "./Message/EncryptionPublicKeyController";
|
|
10
|
+
export * from "./Message/MessageController";
|
|
11
|
+
export * from "./Message/PersonalMessageController";
|
|
12
|
+
export * from "./Message/TypedMessageController";
|
|
13
|
+
export * from "./Message/utils";
|
|
14
|
+
export * from "./Network/createEthereumMiddleware";
|
|
15
|
+
export * from "./Network/createJsonRpcClient";
|
|
16
|
+
export { default as NetworkController } from "./Network/NetworkController";
|
|
17
|
+
export * from "./Nfts/INftsController";
|
|
18
|
+
export * from "./Nfts/NftHandler";
|
|
19
|
+
export * from "./Nfts/NftsController";
|
|
20
|
+
export { default as PreferencesController } from "./Preferences/PreferencesController";
|
|
21
|
+
export * from "./Tokens/ITokensController";
|
|
22
|
+
export * from "./Tokens/TokenHandler";
|
|
23
|
+
export * from "./Tokens/TokenRatesController";
|
|
24
|
+
export * from "./Tokens/TokensController";
|
|
25
|
+
export { default as NonceTracker } from "./Transaction/NonceTracker";
|
|
26
|
+
export { default as PendingTransactionTracker } from "./Transaction/PendingTransactionTracker";
|
|
27
|
+
export { default as TransactionController } from "./Transaction/TransactionController";
|
|
28
|
+
export { default as TransactionGasUtil } from "./Transaction/TransactionGasUtil";
|
|
29
|
+
export * from "./Transaction/TransactionStateHistoryHelper";
|
|
30
|
+
export { default as TransactionStateManager } from "./Transaction/TransactionStateManager";
|
|
31
|
+
export * from "./Transaction/TransactionUtils";
|
|
32
|
+
export * from "./utils/constants";
|
|
33
|
+
export * from "./utils/helpers";
|
|
34
|
+
export * from "./utils/interfaces";
|
|
35
|
+
/**
|
|
36
|
+
* Pending controllers
|
|
37
|
+
* - Transaction Controllers
|
|
38
|
+
// * - AA Controller
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Backend apis
|
|
42
|
+
* - Preferences Controller
|
|
43
|
+
*/
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare class AbiDecoder {
|
|
2
|
+
state: {
|
|
3
|
+
savedABIs: any[];
|
|
4
|
+
methodIDs: Record<string, any>;
|
|
5
|
+
};
|
|
6
|
+
constructor(abi: any);
|
|
7
|
+
getABIs(): any[];
|
|
8
|
+
addABI(abiArray: any): void;
|
|
9
|
+
removeABI(abiArray: any): void;
|
|
10
|
+
getMethodIDs(): Record<string, any>;
|
|
11
|
+
decodeMethod(data: any): {
|
|
12
|
+
name: any;
|
|
13
|
+
params: any[];
|
|
14
|
+
};
|
|
15
|
+
decodeLogs(logs: any): any;
|
|
16
|
+
}
|
|
17
|
+
export default AbiDecoder;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export declare const ecr20Abi: ({
|
|
2
|
+
constant: boolean;
|
|
3
|
+
inputs: {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
}[];
|
|
7
|
+
name: string;
|
|
8
|
+
outputs: {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}[];
|
|
12
|
+
payable: boolean;
|
|
13
|
+
type: string;
|
|
14
|
+
} | {
|
|
15
|
+
inputs: {
|
|
16
|
+
name: string;
|
|
17
|
+
type: string;
|
|
18
|
+
}[];
|
|
19
|
+
type: string;
|
|
20
|
+
constant?: undefined;
|
|
21
|
+
name?: undefined;
|
|
22
|
+
outputs?: undefined;
|
|
23
|
+
payable?: undefined;
|
|
24
|
+
} | {
|
|
25
|
+
payable: boolean;
|
|
26
|
+
type: string;
|
|
27
|
+
constant?: undefined;
|
|
28
|
+
inputs?: undefined;
|
|
29
|
+
name?: undefined;
|
|
30
|
+
outputs?: undefined;
|
|
31
|
+
})[];
|
|
32
|
+
export declare const erc721Abi: {
|
|
33
|
+
constant: boolean;
|
|
34
|
+
inputs: {
|
|
35
|
+
name: string;
|
|
36
|
+
type: string;
|
|
37
|
+
}[];
|
|
38
|
+
name: string;
|
|
39
|
+
outputs: {
|
|
40
|
+
name: string;
|
|
41
|
+
type: string;
|
|
42
|
+
}[];
|
|
43
|
+
payable: boolean;
|
|
44
|
+
stateMutability: string;
|
|
45
|
+
type: string;
|
|
46
|
+
}[];
|
|
47
|
+
export declare const erc1155Abi: {
|
|
48
|
+
inputs: {
|
|
49
|
+
internalType: string;
|
|
50
|
+
name: string;
|
|
51
|
+
type: string;
|
|
52
|
+
}[];
|
|
53
|
+
name: string;
|
|
54
|
+
outputs: {
|
|
55
|
+
internalType: string;
|
|
56
|
+
name: string;
|
|
57
|
+
type: string;
|
|
58
|
+
}[];
|
|
59
|
+
stateMutability: string;
|
|
60
|
+
type: string;
|
|
61
|
+
}[];
|
|
62
|
+
export declare const singleBalanceCheckerAbi: ({
|
|
63
|
+
payable: boolean;
|
|
64
|
+
stateMutability: string;
|
|
65
|
+
type: string;
|
|
66
|
+
constant?: undefined;
|
|
67
|
+
inputs?: undefined;
|
|
68
|
+
name?: undefined;
|
|
69
|
+
outputs?: undefined;
|
|
70
|
+
} | {
|
|
71
|
+
constant: boolean;
|
|
72
|
+
inputs: {
|
|
73
|
+
name: string;
|
|
74
|
+
type: string;
|
|
75
|
+
}[];
|
|
76
|
+
name: string;
|
|
77
|
+
outputs: {
|
|
78
|
+
name: string;
|
|
79
|
+
type: string;
|
|
80
|
+
}[];
|
|
81
|
+
payable: boolean;
|
|
82
|
+
stateMutability: string;
|
|
83
|
+
type: string;
|
|
84
|
+
})[];
|