@tetherto/wdk-wallet-evm 1.0.0-beta.2
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/.editorconfig +11 -0
- package/LICENSE +176 -0
- package/README.md +420 -0
- package/bare.js +20 -0
- package/hardhat.config.cjs +16 -0
- package/index.js +31 -0
- package/package.json +67 -0
- package/src/memory-safe/hd-node-wallet.js +196 -0
- package/src/memory-safe/signing-key.js +77 -0
- package/src/wallet-account-evm.js +200 -0
- package/src/wallet-account-read-only-evm.js +191 -0
- package/src/wallet-manager-evm.js +127 -0
- package/types/index.d.ts +11 -0
- package/types/src/wallet-account-evm.d.ts +91 -0
- package/types/src/wallet-account-read-only-evm.d.ts +112 -0
- package/types/src/wallet-manager-evm.d.ts +68 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
import { WalletAccountReadOnly } from '@tetherto/wdk-wallet'
|
|
18
|
+
|
|
19
|
+
import { BrowserProvider, Contract, JsonRpcProvider } from 'ethers'
|
|
20
|
+
|
|
21
|
+
/** @typedef {import('ethers').Provider} Provider */
|
|
22
|
+
/** @typedef {import('ethers').Eip1193Provider} Eip1193Provider */
|
|
23
|
+
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
24
|
+
|
|
25
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
26
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransferOptions} TransferOptions */
|
|
27
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} EvmTransaction
|
|
31
|
+
* @property {string} to - The transaction's recipient.
|
|
32
|
+
* @property {number | bigint} value - The amount of ethers to send to the recipient (in weis).
|
|
33
|
+
* @property {string} [data] - The transaction's data in hex format.
|
|
34
|
+
* @property {number | bigint} [gasLimit] - The maximum amount of gas this transaction is permitted to use.
|
|
35
|
+
* @property {number | bigint} [gasPrice] - The price (in wei) per unit of gas this transaction will pay.
|
|
36
|
+
* @property {number | bigint} [maxFeePerGas] - The maximum price (in wei) per unit of gas this transaction will pay for the combined [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee and this transaction's priority fee.
|
|
37
|
+
* @property {number | bigint} [maxPriorityFeePerGas] - The price (in wei) per unit of gas this transaction will allow in addition to the [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee to bribe miners into giving this transaction priority. This is included in the maxFeePerGas, so this will not affect the total maximum cost set with maxFeePerGas.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {Object} EvmWalletConfig
|
|
42
|
+
* @property {string | Eip1193Provider} [provider] - The url of the rpc provider, or an instance of a class that implements eip-1193.
|
|
43
|
+
* @property {number | bigint} [transferMaxFee] - The maximum fee amount for transfer operations.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
47
|
+
/**
|
|
48
|
+
* Creates a new evm read-only wallet account.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} address - The account's address.
|
|
51
|
+
* @param {Omit<EvmWalletConfig, 'transferMaxFee'>} [config] - The configuration object.
|
|
52
|
+
*/
|
|
53
|
+
constructor (address, config = { }) {
|
|
54
|
+
super(address)
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The read-only wallet account configuration.
|
|
58
|
+
*
|
|
59
|
+
* @protected
|
|
60
|
+
* @type {Omit<EvmWalletConfig, 'transferMaxFee'>}
|
|
61
|
+
*/
|
|
62
|
+
this._config = config
|
|
63
|
+
|
|
64
|
+
const { provider } = config
|
|
65
|
+
|
|
66
|
+
if (provider) {
|
|
67
|
+
/**
|
|
68
|
+
* An ethers provider to interact with a node of the blockchain.
|
|
69
|
+
*
|
|
70
|
+
* @protected
|
|
71
|
+
* @type {Provider | undefined}
|
|
72
|
+
*/
|
|
73
|
+
this._provider = typeof provider === 'string'
|
|
74
|
+
? new JsonRpcProvider(provider)
|
|
75
|
+
: new BrowserProvider(provider)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns the account's eth balance.
|
|
81
|
+
*
|
|
82
|
+
* @returns {Promise<bigint>} The eth balance (in weis).
|
|
83
|
+
*/
|
|
84
|
+
async getBalance () {
|
|
85
|
+
if (!this._provider) {
|
|
86
|
+
throw new Error('The wallet must be connected to a provider to retrieve balances.')
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const address = await this.getAddress()
|
|
90
|
+
|
|
91
|
+
const balance = await this._provider.getBalance(address)
|
|
92
|
+
|
|
93
|
+
return balance
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Returns the account balance for a specific token.
|
|
98
|
+
*
|
|
99
|
+
* @param {string} tokenAddress - The smart contract address of the token.
|
|
100
|
+
* @returns {Promise<bigint>} The token balance (in base unit).
|
|
101
|
+
*/
|
|
102
|
+
async getTokenBalance (tokenAddress) {
|
|
103
|
+
if (!this._provider) {
|
|
104
|
+
throw new Error('The wallet must be connected to a provider to retrieve token balances.')
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const address = await this.getAddress()
|
|
108
|
+
|
|
109
|
+
const abi = ['function balanceOf(address owner) view returns (uint256)']
|
|
110
|
+
const contract = new Contract(tokenAddress, abi, this._provider)
|
|
111
|
+
const balance = await contract.balanceOf(address)
|
|
112
|
+
|
|
113
|
+
return balance
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Quotes the costs of a send transaction operation.
|
|
118
|
+
*
|
|
119
|
+
* @param {EvmTransaction} tx - The transaction.
|
|
120
|
+
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
121
|
+
*/
|
|
122
|
+
async quoteSendTransaction (tx) {
|
|
123
|
+
if (!this._provider) {
|
|
124
|
+
throw new Error('The wallet must be connected to a provider to quote send transaction operations.')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const gas = await this._provider.estimateGas({
|
|
128
|
+
from: await this.getAddress(),
|
|
129
|
+
...tx
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
const { maxFeePerGas } = await this._provider.getFeeData()
|
|
133
|
+
|
|
134
|
+
return { fee: gas * maxFeePerGas }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Quotes the costs of a transfer operation.
|
|
139
|
+
*
|
|
140
|
+
* @param {TransferOptions} options - The transfer's options.
|
|
141
|
+
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
142
|
+
*/
|
|
143
|
+
async quoteTransfer (options) {
|
|
144
|
+
if (!this._provider) {
|
|
145
|
+
throw new Error('The wallet must be connected to a provider to quote transfer operations.')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const tx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
|
|
149
|
+
|
|
150
|
+
const result = await this.quoteSendTransaction(tx)
|
|
151
|
+
|
|
152
|
+
return result
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Returns a transaction's receipt.
|
|
157
|
+
*
|
|
158
|
+
* @param {string} hash - The transaction's hash.
|
|
159
|
+
* @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
|
|
160
|
+
*/
|
|
161
|
+
async getTransactionReceipt (hash) {
|
|
162
|
+
if (!this._provider) {
|
|
163
|
+
throw new Error('The wallet must be connected to a provider to fetch transaction receipts.')
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return await this._provider.getTransactionReceipt(hash)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Returns an evm transaction to execute the given token transfer.
|
|
171
|
+
*
|
|
172
|
+
* @protected
|
|
173
|
+
* @param {TransferOptions} options - The transfer's options.
|
|
174
|
+
* @returns {Promise<EvmTransaction>} The evm transaction.
|
|
175
|
+
*/
|
|
176
|
+
static async _getTransferTransaction (options) {
|
|
177
|
+
const { token, recipient, amount } = options
|
|
178
|
+
|
|
179
|
+
const abi = ['function transfer(address to, uint256 amount) returns (bool)']
|
|
180
|
+
|
|
181
|
+
const contract = new Contract(token, abi)
|
|
182
|
+
|
|
183
|
+
const tx = {
|
|
184
|
+
to: token,
|
|
185
|
+
value: 0,
|
|
186
|
+
data: contract.interface.encodeFunctionData('transfer', [recipient, amount])
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return tx
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
'use strict'
|
|
16
|
+
|
|
17
|
+
import WalletManager from '@tetherto/wdk-wallet'
|
|
18
|
+
|
|
19
|
+
import { BrowserProvider, JsonRpcProvider } from 'ethers'
|
|
20
|
+
|
|
21
|
+
import WalletAccountEvm from './wallet-account-evm.js'
|
|
22
|
+
|
|
23
|
+
/** @typedef {import('ethers').Provider} Provider */
|
|
24
|
+
|
|
25
|
+
/** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
|
|
26
|
+
|
|
27
|
+
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
28
|
+
|
|
29
|
+
export default class WalletManagerEvm extends WalletManager {
|
|
30
|
+
/**
|
|
31
|
+
* Multiplier for normal fee rate calculations (in %).
|
|
32
|
+
*
|
|
33
|
+
* @protected
|
|
34
|
+
* @type {bigint}
|
|
35
|
+
*/
|
|
36
|
+
static _FEE_RATE_NORMAL_MULTIPLIER = 110n
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Multiplier for fast fee rate calculations (in %).
|
|
40
|
+
*
|
|
41
|
+
* @protected
|
|
42
|
+
* @type {bigint}
|
|
43
|
+
*/
|
|
44
|
+
static _FEE_RATE_FAST_MULTIPLIER = 200n
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Creates a new wallet manager for evm blockchains.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
|
|
50
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
51
|
+
*/
|
|
52
|
+
constructor (seed, config = {}) {
|
|
53
|
+
super(seed, config)
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The evm wallet configuration.
|
|
57
|
+
*
|
|
58
|
+
* @protected
|
|
59
|
+
* @type {EvmWalletConfig}
|
|
60
|
+
*/
|
|
61
|
+
this._config = config
|
|
62
|
+
|
|
63
|
+
const { provider } = config
|
|
64
|
+
|
|
65
|
+
if (provider) {
|
|
66
|
+
/**
|
|
67
|
+
* An ethers provider to interact with a node of the blockchain.
|
|
68
|
+
*
|
|
69
|
+
* @protected
|
|
70
|
+
* @type {Provider | undefined}
|
|
71
|
+
*/
|
|
72
|
+
this._provider = typeof provider === 'string'
|
|
73
|
+
? new JsonRpcProvider(provider)
|
|
74
|
+
: new BrowserProvider(provider)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
83
|
+
* const account = await wallet.getAccount(1);
|
|
84
|
+
* @param {number} [index] - The index of the account to get (default: 0).
|
|
85
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
86
|
+
*/
|
|
87
|
+
async getAccount (index = 0) {
|
|
88
|
+
return await this.getAccountByPath(`0'/0/${index}`)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns the wallet account at a specific BIP-44 derivation path.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
96
|
+
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
97
|
+
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
98
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
99
|
+
*/
|
|
100
|
+
async getAccountByPath (path) {
|
|
101
|
+
if (!this._accounts[path]) {
|
|
102
|
+
const account = new WalletAccountEvm(this.seed, path, this._config)
|
|
103
|
+
|
|
104
|
+
this._accounts[path] = account
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return this._accounts[path]
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the current fee rates.
|
|
112
|
+
*
|
|
113
|
+
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
114
|
+
*/
|
|
115
|
+
async getFeeRates () {
|
|
116
|
+
if (!this._provider) {
|
|
117
|
+
throw new Error('The wallet must be connected to a provider to get fee rates.')
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const { maxFeePerGas } = await this._provider.getFeeData()
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
normal: maxFeePerGas * WalletManagerEvm._FEE_RATE_NORMAL_MULTIPLIER / 100n,
|
|
124
|
+
fast: maxFeePerGas * WalletManagerEvm._FEE_RATE_FAST_MULTIPLIER / 100n
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default } from "./src/wallet-manager-evm.js";
|
|
2
|
+
export { default as WalletAccountReadOnlyEvm } from "./src/wallet-account-read-only-evm.js";
|
|
3
|
+
export { default as WalletAccountEvm } from "./src/wallet-account-evm.js";
|
|
4
|
+
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
5
|
+
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
6
|
+
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
7
|
+
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
8
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
9
|
+
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
10
|
+
export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
|
|
11
|
+
export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/** @implements {IWalletAccount} */
|
|
2
|
+
export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implements IWalletAccount {
|
|
3
|
+
/**
|
|
4
|
+
* Creates a new evm wallet account.
|
|
5
|
+
*
|
|
6
|
+
* @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
|
|
7
|
+
* @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
|
|
8
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
9
|
+
*/
|
|
10
|
+
constructor(seed: string | Uint8Array, path: string, config?: EvmWalletConfig);
|
|
11
|
+
/**
|
|
12
|
+
* The wallet account configuration.
|
|
13
|
+
*
|
|
14
|
+
* @protected
|
|
15
|
+
* @type {EvmWalletConfig}
|
|
16
|
+
*/
|
|
17
|
+
protected _config: EvmWalletConfig;
|
|
18
|
+
/**
|
|
19
|
+
* The account.
|
|
20
|
+
*
|
|
21
|
+
* @protected
|
|
22
|
+
* @type {HDNodeWallet}
|
|
23
|
+
*/
|
|
24
|
+
protected _account: HDNodeWallet;
|
|
25
|
+
/**
|
|
26
|
+
* The derivation path's index of this account.
|
|
27
|
+
*
|
|
28
|
+
* @type {number}
|
|
29
|
+
*/
|
|
30
|
+
get index(): number;
|
|
31
|
+
/**
|
|
32
|
+
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
33
|
+
*
|
|
34
|
+
* @type {string}
|
|
35
|
+
*/
|
|
36
|
+
get path(): string;
|
|
37
|
+
/**
|
|
38
|
+
* The account's key pair.
|
|
39
|
+
*
|
|
40
|
+
* @type {KeyPair}
|
|
41
|
+
*/
|
|
42
|
+
get keyPair(): KeyPair;
|
|
43
|
+
/**
|
|
44
|
+
* Signs a message.
|
|
45
|
+
*
|
|
46
|
+
* @param {string} message - The message to sign.
|
|
47
|
+
* @returns {Promise<string>} The message's signature.
|
|
48
|
+
*/
|
|
49
|
+
sign(message: string): Promise<string>;
|
|
50
|
+
/**
|
|
51
|
+
* Verifies a message's signature.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} message - The original message.
|
|
54
|
+
* @param {string} signature - The signature to verify.
|
|
55
|
+
* @returns {Promise<boolean>} True if the signature is valid.
|
|
56
|
+
*/
|
|
57
|
+
verify(message: string, signature: string): Promise<boolean>;
|
|
58
|
+
/**
|
|
59
|
+
* Sends a transaction.
|
|
60
|
+
*
|
|
61
|
+
* @param {EvmTransaction} tx - The transaction.
|
|
62
|
+
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
63
|
+
*/
|
|
64
|
+
sendTransaction(tx: EvmTransaction): Promise<TransactionResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Transfers a token to another address.
|
|
67
|
+
*
|
|
68
|
+
* @param {TransferOptions} options - The transfer's options.
|
|
69
|
+
* @returns {Promise<TransferResult>} The transfer's result.
|
|
70
|
+
*/
|
|
71
|
+
transfer(options: TransferOptions): Promise<TransferResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Returns a read-only copy of the account.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<WalletAccountReadOnlyEvm>} The read-only account.
|
|
76
|
+
*/
|
|
77
|
+
toReadOnlyAccount(): Promise<WalletAccountReadOnlyEvm>;
|
|
78
|
+
/**
|
|
79
|
+
* Disposes the wallet account, erasing the private key from the memory.
|
|
80
|
+
*/
|
|
81
|
+
dispose(): void;
|
|
82
|
+
}
|
|
83
|
+
export type HDNodeWallet = import("ethers").HDNodeWallet;
|
|
84
|
+
export type IWalletAccount = import("@tetherto/wdk-wallet").IWalletAccount;
|
|
85
|
+
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
86
|
+
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
87
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
88
|
+
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
89
|
+
export type EvmTransaction = import("./wallet-account-read-only-evm.js").EvmTransaction;
|
|
90
|
+
export type EvmWalletConfig = import("./wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
91
|
+
import WalletAccountReadOnlyEvm from './wallet-account-read-only-evm.js';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
2
|
+
/**
|
|
3
|
+
* Returns an evm transaction to execute the given token transfer.
|
|
4
|
+
*
|
|
5
|
+
* @protected
|
|
6
|
+
* @param {TransferOptions} options - The transfer's options.
|
|
7
|
+
* @returns {Promise<EvmTransaction>} The evm transaction.
|
|
8
|
+
*/
|
|
9
|
+
protected static _getTransferTransaction(options: TransferOptions): Promise<EvmTransaction>;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new evm read-only wallet account.
|
|
12
|
+
*
|
|
13
|
+
* @param {string} address - The account's address.
|
|
14
|
+
* @param {Omit<EvmWalletConfig, 'transferMaxFee'>} [config] - The configuration object.
|
|
15
|
+
*/
|
|
16
|
+
constructor(address: string, config?: Omit<EvmWalletConfig, "transferMaxFee">);
|
|
17
|
+
/**
|
|
18
|
+
* The read-only wallet account configuration.
|
|
19
|
+
*
|
|
20
|
+
* @protected
|
|
21
|
+
* @type {Omit<EvmWalletConfig, 'transferMaxFee'>}
|
|
22
|
+
*/
|
|
23
|
+
protected _config: Omit<EvmWalletConfig, "transferMaxFee">;
|
|
24
|
+
/**
|
|
25
|
+
* An ethers provider to interact with a node of the blockchain.
|
|
26
|
+
*
|
|
27
|
+
* @protected
|
|
28
|
+
* @type {Provider | undefined}
|
|
29
|
+
*/
|
|
30
|
+
protected _provider: Provider | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Returns the account's eth balance.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<bigint>} The eth balance (in weis).
|
|
35
|
+
*/
|
|
36
|
+
getBalance(): Promise<bigint>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the account balance for a specific token.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} tokenAddress - The smart contract address of the token.
|
|
41
|
+
* @returns {Promise<bigint>} The token balance (in base unit).
|
|
42
|
+
*/
|
|
43
|
+
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
44
|
+
/**
|
|
45
|
+
* Quotes the costs of a send transaction operation.
|
|
46
|
+
*
|
|
47
|
+
* @param {EvmTransaction} tx - The transaction.
|
|
48
|
+
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
49
|
+
*/
|
|
50
|
+
quoteSendTransaction(tx: EvmTransaction): Promise<Omit<TransactionResult, "hash">>;
|
|
51
|
+
/**
|
|
52
|
+
* Quotes the costs of a transfer operation.
|
|
53
|
+
*
|
|
54
|
+
* @param {TransferOptions} options - The transfer's options.
|
|
55
|
+
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
56
|
+
*/
|
|
57
|
+
quoteTransfer(options: TransferOptions): Promise<Omit<TransferResult, "hash">>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns a transaction's receipt.
|
|
60
|
+
*
|
|
61
|
+
* @param {string} hash - The transaction's hash.
|
|
62
|
+
* @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
|
|
63
|
+
*/
|
|
64
|
+
getTransactionReceipt(hash: string): Promise<EvmTransactionReceipt | null>;
|
|
65
|
+
}
|
|
66
|
+
export type Provider = import("ethers").Provider;
|
|
67
|
+
export type Eip1193Provider = import("ethers").Eip1193Provider;
|
|
68
|
+
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
69
|
+
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
70
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
71
|
+
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
72
|
+
export type EvmTransaction = {
|
|
73
|
+
/**
|
|
74
|
+
* - The transaction's recipient.
|
|
75
|
+
*/
|
|
76
|
+
to: string;
|
|
77
|
+
/**
|
|
78
|
+
* - The amount of ethers to send to the recipient (in weis).
|
|
79
|
+
*/
|
|
80
|
+
value: number | bigint;
|
|
81
|
+
/**
|
|
82
|
+
* - The transaction's data in hex format.
|
|
83
|
+
*/
|
|
84
|
+
data?: string;
|
|
85
|
+
/**
|
|
86
|
+
* - The maximum amount of gas this transaction is permitted to use.
|
|
87
|
+
*/
|
|
88
|
+
gasLimit?: number | bigint;
|
|
89
|
+
/**
|
|
90
|
+
* - The price (in wei) per unit of gas this transaction will pay.
|
|
91
|
+
*/
|
|
92
|
+
gasPrice?: number | bigint;
|
|
93
|
+
/**
|
|
94
|
+
* - The maximum price (in wei) per unit of gas this transaction will pay for the combined [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee and this transaction's priority fee.
|
|
95
|
+
*/
|
|
96
|
+
maxFeePerGas?: number | bigint;
|
|
97
|
+
/**
|
|
98
|
+
* - The price (in wei) per unit of gas this transaction will allow in addition to the [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee to bribe miners into giving this transaction priority. This is included in the maxFeePerGas, so this will not affect the total maximum cost set with maxFeePerGas.
|
|
99
|
+
*/
|
|
100
|
+
maxPriorityFeePerGas?: number | bigint;
|
|
101
|
+
};
|
|
102
|
+
export type EvmWalletConfig = {
|
|
103
|
+
/**
|
|
104
|
+
* - The url of the rpc provider, or an instance of a class that implements eip-1193.
|
|
105
|
+
*/
|
|
106
|
+
provider?: string | Eip1193Provider;
|
|
107
|
+
/**
|
|
108
|
+
* - The maximum fee amount for transfer operations.
|
|
109
|
+
*/
|
|
110
|
+
transferMaxFee?: number | bigint;
|
|
111
|
+
};
|
|
112
|
+
import { WalletAccountReadOnly } from '@tetherto/wdk-wallet';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export default class WalletManagerEvm extends WalletManager {
|
|
2
|
+
/**
|
|
3
|
+
* Multiplier for normal fee rate calculations (in %).
|
|
4
|
+
*
|
|
5
|
+
* @protected
|
|
6
|
+
* @type {bigint}
|
|
7
|
+
*/
|
|
8
|
+
protected static _FEE_RATE_NORMAL_MULTIPLIER: bigint;
|
|
9
|
+
/**
|
|
10
|
+
* Multiplier for fast fee rate calculations (in %).
|
|
11
|
+
*
|
|
12
|
+
* @protected
|
|
13
|
+
* @type {bigint}
|
|
14
|
+
*/
|
|
15
|
+
protected static _FEE_RATE_FAST_MULTIPLIER: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a new wallet manager for evm blockchains.
|
|
18
|
+
*
|
|
19
|
+
* @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
|
|
20
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
21
|
+
*/
|
|
22
|
+
constructor(seed: string | Uint8Array, config?: EvmWalletConfig);
|
|
23
|
+
/**
|
|
24
|
+
* The evm wallet configuration.
|
|
25
|
+
*
|
|
26
|
+
* @protected
|
|
27
|
+
* @type {EvmWalletConfig}
|
|
28
|
+
*/
|
|
29
|
+
protected _config: EvmWalletConfig;
|
|
30
|
+
/**
|
|
31
|
+
* An ethers provider to interact with a node of the blockchain.
|
|
32
|
+
*
|
|
33
|
+
* @protected
|
|
34
|
+
* @type {Provider | undefined}
|
|
35
|
+
*/
|
|
36
|
+
protected _provider: Provider | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
42
|
+
* const account = await wallet.getAccount(1);
|
|
43
|
+
* @param {number} [index] - The index of the account to get (default: 0).
|
|
44
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
45
|
+
*/
|
|
46
|
+
getAccount(index?: number): Promise<WalletAccountEvm>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the wallet account at a specific BIP-44 derivation path.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
52
|
+
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
53
|
+
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
54
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
55
|
+
*/
|
|
56
|
+
getAccountByPath(path: string): Promise<WalletAccountEvm>;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the current fee rates.
|
|
59
|
+
*
|
|
60
|
+
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
61
|
+
*/
|
|
62
|
+
getFeeRates(): Promise<FeeRates>;
|
|
63
|
+
}
|
|
64
|
+
export type Provider = import("ethers").Provider;
|
|
65
|
+
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
66
|
+
export type EvmWalletConfig = import("./wallet-account-evm.js").EvmWalletConfig;
|
|
67
|
+
import WalletManager from '@tetherto/wdk-wallet';
|
|
68
|
+
import WalletAccountEvm from './wallet-account-evm.js';
|