@tetherto/wdk-wallet-evm 1.0.0-beta.16 → 1.0.0-beta.18
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/index.js +6 -0
- package/package.json +3 -3
- package/src/signers/private-key-signer-evm.js +3 -3
- package/src/signers/seed-signer-evm.js +9 -10
- package/src/utils/tx-populator-evm.js +7 -4
- package/src/wallet-account-evm.js +29 -15
- package/src/wallet-account-read-only-evm.js +140 -10
- package/src/wallet-manager-evm.js +11 -9
- package/types/index.d.ts +6 -0
- package/types/src/signers/private-key-signer-evm.d.ts +1 -1
- package/types/src/signers/seed-signer-evm.d.ts +4 -4
- package/types/src/utils/tx-populator-evm.d.ts +1 -0
- package/types/src/wallet-account-evm.d.ts +10 -4
- package/types/src/wallet-account-read-only-evm.d.ts +66 -0
- package/types/src/wallet-manager-evm.d.ts +9 -5
package/index.js
CHANGED
|
@@ -19,17 +19,23 @@
|
|
|
19
19
|
/** @typedef {import('ethers').Authorization} Authorization */
|
|
20
20
|
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
21
21
|
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
22
|
+
/** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
|
|
22
23
|
|
|
23
24
|
/** @typedef {import('@tetherto/wdk-wallet').FeeRates} FeeRates */
|
|
24
25
|
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
25
26
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
26
27
|
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
28
|
+
/** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
|
|
29
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
|
|
30
|
+
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
|
|
31
|
+
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
|
|
27
32
|
|
|
28
33
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
29
34
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').DelegationInfo} DelegationInfo */
|
|
30
35
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransaction} EvmTransaction */
|
|
31
36
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransferOptions} EvmTransferOptions */
|
|
32
37
|
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
38
|
+
/** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransactionDetails} EvmTransactionDetails */
|
|
33
39
|
|
|
34
40
|
/** @typedef {import('./src/wallet-account-evm.js').ApproveOptions} ApproveOptions */
|
|
35
41
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet-evm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
4
4
|
"description": "A simple package to manage BIP-32 wallets for evm blockchains.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wdk",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@noble/hashes": "1.8.0",
|
|
33
33
|
"@noble/secp256k1": "2.2.3",
|
|
34
|
-
"@tetherto/wdk-wallet": "1.0.0-beta.13",
|
|
35
34
|
"@tetherto/wdk-failover-provider": "1.0.0-beta.2",
|
|
35
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.17",
|
|
36
36
|
"bare-node-runtime": "^1.5.0",
|
|
37
37
|
"bip39": "3.1.0",
|
|
38
38
|
"ethers": "6.17.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"concurrently": "9.2.0",
|
|
43
43
|
"cross-env": "7.0.3",
|
|
44
|
-
"hardhat": "3.
|
|
44
|
+
"hardhat": "3.12.0",
|
|
45
45
|
"jest": "29.7.0",
|
|
46
46
|
"standard": "17.1.2",
|
|
47
47
|
"typescript": "5.8.3",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
import { BaseWallet } from 'ethers'
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { InvalidSignerError } from '@tetherto/wdk-wallet'
|
|
19
19
|
|
|
20
20
|
import MemorySafeSigningKey from '../memory-safe/signing-key.js'
|
|
21
21
|
import { ISignerEvm } from './seed-signer-evm.js'
|
|
@@ -97,10 +97,10 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
|
|
|
97
97
|
/**
|
|
98
98
|
* PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
|
|
99
99
|
* @returns {Promise<never>}
|
|
100
|
-
* @throws {
|
|
100
|
+
* @throws {InvalidSignerError} Always — private-key signers do not support derivation.
|
|
101
101
|
*/
|
|
102
102
|
async derive () {
|
|
103
|
-
throw new
|
|
103
|
+
throw new InvalidSignerError('PrivateKeySignerEvm does not support derivation.')
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
/** @returns {Promise<string>} */
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
import * as bip39 from 'bip39'
|
|
17
17
|
|
|
18
18
|
import MemorySafeHDNodeWallet from '../memory-safe/hd-node-wallet.js'
|
|
19
|
-
import { ISigner, NotImplementedError } from '@tetherto/wdk-wallet'
|
|
19
|
+
import { ISigner, InvalidSignerError, NotImplementedError, ValueError } from '@tetherto/wdk-wallet'
|
|
20
20
|
|
|
21
21
|
const BIP_44_ETH_DERIVATION_PATH_PREFIX = "m/44'/60'"
|
|
22
22
|
|
|
@@ -25,7 +25,6 @@ const DEFAULT_ACCOUNT_PATH = "0'/0/0"
|
|
|
25
25
|
|
|
26
26
|
/** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
27
27
|
/** @typedef {import('@tetherto/wdk-wallet').ISigner} ISigner */
|
|
28
|
-
/** @typedef {import('@tetherto/wdk-wallet').SignerError} SignerError */
|
|
29
28
|
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
30
29
|
/** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
|
|
31
30
|
/** @typedef {import('ethers').Authorization} Authorization */
|
|
@@ -93,7 +92,7 @@ export class ISignerEvm extends ISigner {
|
|
|
93
92
|
*
|
|
94
93
|
* @param {string} relPath - The relative BIP-44 path segment.
|
|
95
94
|
* @returns {Promise<ISignerEvm>} The derived child signer.
|
|
96
|
-
* @throws {
|
|
95
|
+
* @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
|
|
97
96
|
*/
|
|
98
97
|
async derive (relPath) {
|
|
99
98
|
throw new NotImplementedError('derive(relPath)')
|
|
@@ -163,24 +162,24 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
163
162
|
*
|
|
164
163
|
* @param {string|Uint8Array|null} seed - BIP-39 mnemonic or seed bytes. Omit when providing `opts.root`.
|
|
165
164
|
* @param {SeedSignerEvmOpts} [opts] - Construction options for root reuse, direct child derivation or path definition (default is index 0).
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
* @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
|
|
166
|
+
* @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
|
|
168
167
|
*/
|
|
169
168
|
constructor (seed, opts = {}) {
|
|
170
169
|
super()
|
|
171
170
|
|
|
172
171
|
// If a root is provided, do not expect a seed
|
|
173
172
|
if (opts.root && seed) {
|
|
174
|
-
throw new
|
|
173
|
+
throw new ValueError('Provide either a seed or a root, not both.')
|
|
175
174
|
}
|
|
176
175
|
|
|
177
176
|
if (!opts.root && !seed) {
|
|
178
|
-
throw new
|
|
177
|
+
throw new ValueError('Seed or root is required.')
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
if (typeof seed === 'string') {
|
|
182
181
|
if (!bip39.validateMnemonic(seed)) {
|
|
183
|
-
throw new
|
|
182
|
+
throw new ValueError('The seed phrase is invalid.')
|
|
184
183
|
}
|
|
185
184
|
seed = bip39.mnemonicToSeedSync(seed)
|
|
186
185
|
}
|
|
@@ -251,11 +250,11 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
251
250
|
* Derive a child signer using the provided relative path (e.g. "0'/0/0").
|
|
252
251
|
* @param {string} relPath
|
|
253
252
|
* @returns {Promise<SeedSignerEvm>}
|
|
254
|
-
* @throws {
|
|
253
|
+
* @throws {InvalidSignerError} If called on a derived child signer, which does not retain the root.
|
|
255
254
|
*/
|
|
256
255
|
async derive (relPath) {
|
|
257
256
|
if (!this._root) {
|
|
258
|
-
throw new
|
|
257
|
+
throw new InvalidSignerError('Cannot derive: this signer has no root (it is a derived child or has been disposed).')
|
|
259
258
|
}
|
|
260
259
|
return new SeedSignerEvm(null, { root: this._root, path: relPath, isChild: true })
|
|
261
260
|
}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
+
import { ValueError } from '@tetherto/wdk-wallet'
|
|
17
|
+
|
|
16
18
|
import { Signature, toQuantity } from 'ethers'
|
|
17
19
|
|
|
18
20
|
/** @typedef {import('ethers').Provider} Provider */
|
|
@@ -51,6 +53,7 @@ import { Signature, toQuantity } from 'ethers'
|
|
|
51
53
|
* @param {string} from - The sender address.
|
|
52
54
|
* @param {UnsignedEvmTransaction} tx - The partial transaction to populate.
|
|
53
55
|
* @returns {Promise<UnsignedEvmTransaction>} The fully populated unsigned transaction.
|
|
56
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
54
57
|
*/
|
|
55
58
|
export async function populateTransactionEvm (provider, from, tx) {
|
|
56
59
|
const net = await provider.getNetwork()
|
|
@@ -65,13 +68,13 @@ export async function populateTransactionEvm (provider, from, tx) {
|
|
|
65
68
|
const explicitType = (tx.type != null) ? Number(tx.type) : null
|
|
66
69
|
|
|
67
70
|
if ((explicitType === 2 || (explicitType == null && has1559)) && hasLegacy) {
|
|
68
|
-
throw new
|
|
71
|
+
throw new ValueError('eip-1559 transaction does not support gasPrice')
|
|
69
72
|
}
|
|
70
73
|
if ((explicitType === 0 || explicitType === 1) && has1559) {
|
|
71
|
-
throw new
|
|
74
|
+
throw new ValueError('pre-eip-1559 transaction does not support maxFeePerGas/maxPriorityFeePerGas')
|
|
72
75
|
}
|
|
73
76
|
if ((explicitType === 3 || hasBlobs) && hasLegacy) {
|
|
74
|
-
throw new
|
|
77
|
+
throw new ValueError('blob transaction does not support gasPrice')
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
const feeData = await provider.getFeeData()
|
|
@@ -132,7 +135,7 @@ export async function populateTransactionEvm (provider, from, tx) {
|
|
|
132
135
|
populated.type = 3
|
|
133
136
|
populated.maxFeePerGas = tx.maxFeePerGas ?? feeData.maxFeePerGas
|
|
134
137
|
populated.maxPriorityFeePerGas = tx.maxPriorityFeePerGas ?? feeData.maxPriorityFeePerGas
|
|
135
|
-
if (tx.maxFeePerBlobGas == null) throw new
|
|
138
|
+
if (tx.maxFeePerBlobGas == null) throw new ValueError('maxFeePerBlobGas is required for type 3 transactions')
|
|
136
139
|
populated.maxFeePerBlobGas = tx.maxFeePerBlobGas
|
|
137
140
|
if (tx.blobs != null) populated.blobs = tx.blobs
|
|
138
141
|
if (tx.blobVersionedHashes != null) populated.blobVersionedHashes = tx.blobVersionedHashes
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
+
import { MaximumFeeExceededError, ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
|
|
18
|
+
|
|
17
19
|
import { Contract, Transaction, ZeroAddress } from 'ethers'
|
|
18
20
|
|
|
19
21
|
import WalletAccountReadOnlyEvm from './wallet-account-read-only-evm.js'
|
|
@@ -172,14 +174,14 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
172
174
|
*
|
|
173
175
|
* @param {EvmTransaction} tx - The transaction to sign.
|
|
174
176
|
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
175
|
-
* @throws {
|
|
177
|
+
* @throws {MaximumFeeExceededError} If a provider is set, and the transaction's cost surpasses the transaction max. fee option.
|
|
176
178
|
*/
|
|
177
179
|
async signTransaction (tx) {
|
|
178
180
|
if (this._provider && this._config.transactionMaxFee !== undefined) {
|
|
179
181
|
const { fee } = await this.quoteSendTransaction(tx)
|
|
180
182
|
|
|
181
183
|
if (fee > this._config.transactionMaxFee) {
|
|
182
|
-
throw new
|
|
184
|
+
throw new MaximumFeeExceededError('Exceeded maximum fee cost for transaction operation.')
|
|
183
185
|
}
|
|
184
186
|
}
|
|
185
187
|
return await this._signer.signTransaction({
|
|
@@ -191,18 +193,26 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
191
193
|
/**
|
|
192
194
|
* Sends a transaction.
|
|
193
195
|
*
|
|
194
|
-
* @param {EvmTransaction | string} tx - The transaction.
|
|
196
|
+
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
195
197
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
196
|
-
* @throws {
|
|
198
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
199
|
+
* @throws {MaximumFeeExceededError} If the transaction's cost exceeds the maximum transaction fee option.
|
|
200
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
197
201
|
*/
|
|
198
202
|
async sendTransaction (tx) {
|
|
199
203
|
if (!this._provider) {
|
|
200
|
-
throw new
|
|
204
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to send transactions.')
|
|
201
205
|
}
|
|
202
206
|
const { fee } = await this.quoteSendTransaction(tx)
|
|
203
207
|
if (this._config.transactionMaxFee !== undefined && fee > this._config.transactionMaxFee) {
|
|
204
|
-
throw new
|
|
208
|
+
throw new MaximumFeeExceededError('Exceeded maximum fee cost for transaction operation.')
|
|
205
209
|
}
|
|
210
|
+
|
|
211
|
+
if (typeof tx === 'string') {
|
|
212
|
+
const hash = await this._provider.send('eth_sendRawTransaction', [tx])
|
|
213
|
+
return { hash, fee }
|
|
214
|
+
}
|
|
215
|
+
|
|
206
216
|
// Build, sign and broadcast raw transaction using the signer
|
|
207
217
|
const from = await this.getAddress()
|
|
208
218
|
const unsignedTx = await populateTransactionEvm(this._provider, from, tx)
|
|
@@ -214,13 +224,14 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
214
224
|
/**
|
|
215
225
|
* Quotes the costs of a send transaction operation.
|
|
216
226
|
*
|
|
217
|
-
* @param {EvmTransaction | string} tx - The transaction.
|
|
227
|
+
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
218
228
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
229
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
219
230
|
*/
|
|
220
231
|
async quoteSendTransaction (tx) {
|
|
221
232
|
if (typeof tx === 'string') {
|
|
222
233
|
if (!this._provider) {
|
|
223
|
-
throw new
|
|
234
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to quote send transaction operations.')
|
|
224
235
|
}
|
|
225
236
|
|
|
226
237
|
const { from, to, value, data, gasLimit, gasPrice, maxFeePerGas, maxPriorityFeePerGas, type, nonce, chainId, authorizationList } = Transaction.from(tx)
|
|
@@ -246,11 +257,12 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
246
257
|
*
|
|
247
258
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
248
259
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
249
|
-
* @throws {
|
|
260
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
261
|
+
* @throws {MaximumFeeExceededError} If the transfer's cost exceeds the maximum transfer fee option.
|
|
250
262
|
*/
|
|
251
263
|
async transfer (options) {
|
|
252
264
|
if (!this._provider) {
|
|
253
|
-
throw new
|
|
265
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to transfer tokens.')
|
|
254
266
|
}
|
|
255
267
|
|
|
256
268
|
const tx = await WalletAccountEvm._getTransferTransaction(options)
|
|
@@ -258,7 +270,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
258
270
|
const { fee } = await this.quoteSendTransaction(tx)
|
|
259
271
|
|
|
260
272
|
if (this._config.transferMaxFee !== undefined && fee > this._config.transferMaxFee) {
|
|
261
|
-
throw new
|
|
273
|
+
throw new MaximumFeeExceededError('Exceeded maximum fee cost for transfer operation.')
|
|
262
274
|
}
|
|
263
275
|
|
|
264
276
|
const { hash } = await this.sendTransaction(tx)
|
|
@@ -271,11 +283,12 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
271
283
|
*
|
|
272
284
|
* @param {ApproveOptions} options The approve options.
|
|
273
285
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
274
|
-
* @throws {
|
|
286
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
287
|
+
* @throws {ValueError} If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
275
288
|
*/
|
|
276
289
|
async approve (options) {
|
|
277
290
|
if (!this._provider) {
|
|
278
|
-
throw new
|
|
291
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to approve funds.')
|
|
279
292
|
}
|
|
280
293
|
|
|
281
294
|
const { token, spender, amount } = options
|
|
@@ -284,7 +297,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
284
297
|
if (chainId === 1n && token.toLowerCase() === USDT_MAINNET_ADDRESS.toLowerCase()) {
|
|
285
298
|
const currentAllowance = await this.getAllowance(token, spender)
|
|
286
299
|
if (currentAllowance > 0n && BigInt(amount) > 0n) {
|
|
287
|
-
throw new
|
|
300
|
+
throw new ValueError(
|
|
288
301
|
'USDT requires the current allowance to be reset to 0 before setting a new non-zero value. Please send an "approve" transaction with an amount of 0 first.'
|
|
289
302
|
)
|
|
290
303
|
}
|
|
@@ -345,10 +358,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
345
358
|
*
|
|
346
359
|
* @param {string} delegateAddress - The address of the contract to delegate to.
|
|
347
360
|
* @returns {Promise<TransactionResult>} The transaction result.
|
|
361
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
348
362
|
*/
|
|
349
363
|
async delegate (delegateAddress) {
|
|
350
364
|
if (!this._provider) {
|
|
351
|
-
throw new
|
|
365
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to delegate.')
|
|
352
366
|
}
|
|
353
367
|
|
|
354
368
|
const address = await this.getAddress()
|
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
-
import { WalletAccountReadOnly } from '@tetherto/wdk-wallet'
|
|
17
|
+
import { WalletAccountReadOnly, NoSuchElementError, ProviderRequiredError, ValueError } from '@tetherto/wdk-wallet'
|
|
18
18
|
|
|
19
|
-
import { BrowserProvider, Contract, Interface, JsonRpcProvider, Network, Signature, toQuantity, verifyMessage, verifyTypedData } from 'ethers'
|
|
19
|
+
import { BrowserProvider, Contract, Interface, isError, isHexString, JsonRpcProvider, Network, Signature, toQuantity, verifyMessage, verifyTypedData } from 'ethers'
|
|
20
20
|
|
|
21
21
|
import { multicall } from './multicall.js'
|
|
22
22
|
|
|
@@ -28,9 +28,20 @@ import FailoverProvider from '@tetherto/wdk-failover-provider'
|
|
|
28
28
|
/** @typedef {import('ethers').TypedDataField} TypedDataField */
|
|
29
29
|
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
30
30
|
/** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
|
|
31
|
+
/** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
|
|
31
32
|
|
|
32
33
|
/** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
|
|
33
34
|
/** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
|
|
35
|
+
/** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
|
|
36
|
+
/** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The EVM-specific fields added to a normalized transaction receipt.
|
|
40
|
+
*
|
|
41
|
+
* @typedef {Object} EvmTransactionDetails
|
|
42
|
+
* @property {number} confirmations - The number of confirmations (0 while pending or dropped).
|
|
43
|
+
* @property {EvmTransactionReceipt | null} receipt - The native ethers receipt, or null while the transaction is pending or dropped.
|
|
44
|
+
*/
|
|
34
45
|
|
|
35
46
|
/**
|
|
36
47
|
* @typedef {Object} TypedData
|
|
@@ -145,10 +156,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
145
156
|
* Returns the account's eth balance.
|
|
146
157
|
*
|
|
147
158
|
* @returns {Promise<bigint>} The eth balance (in weis).
|
|
159
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
148
160
|
*/
|
|
149
161
|
async getBalance () {
|
|
150
162
|
if (!this._provider) {
|
|
151
|
-
throw new
|
|
163
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to retrieve balances.')
|
|
152
164
|
}
|
|
153
165
|
|
|
154
166
|
const address = await this.getAddress()
|
|
@@ -163,10 +175,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
163
175
|
*
|
|
164
176
|
* @param {string} tokenAddress - The smart contract address of the token.
|
|
165
177
|
* @returns {Promise<bigint>} The token balance (in base unit).
|
|
178
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
166
179
|
*/
|
|
167
180
|
async getTokenBalance (tokenAddress) {
|
|
168
181
|
if (!this._provider) {
|
|
169
|
-
throw new
|
|
182
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to retrieve token balances.')
|
|
170
183
|
}
|
|
171
184
|
|
|
172
185
|
const address = await this.getAddress()
|
|
@@ -183,10 +196,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
183
196
|
*
|
|
184
197
|
* @param {string[]} tokenAddresses - The smart contract addresses of the tokens.
|
|
185
198
|
* @returns {Promise<Record<string, bigint>>} A mapping of token addresses to their balances (in base units).
|
|
199
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
186
200
|
*/
|
|
187
201
|
async getTokenBalances (tokenAddresses) {
|
|
188
202
|
if (!this._provider) {
|
|
189
|
-
throw new
|
|
203
|
+
throw new ProviderRequiredError(
|
|
190
204
|
'The wallet must be connected to a provider to retrieve token balances.'
|
|
191
205
|
)
|
|
192
206
|
}
|
|
@@ -220,10 +234,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
220
234
|
*
|
|
221
235
|
* @param {EvmTransaction} tx - The transaction.
|
|
222
236
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
237
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
223
238
|
*/
|
|
224
239
|
async quoteSendTransaction (tx) {
|
|
225
240
|
if (!this._provider) {
|
|
226
|
-
throw new
|
|
241
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to quote send transaction operations.')
|
|
227
242
|
}
|
|
228
243
|
|
|
229
244
|
const from = await this.getAddress()
|
|
@@ -244,10 +259,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
244
259
|
*
|
|
245
260
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
246
261
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
262
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
247
263
|
*/
|
|
248
264
|
async quoteTransfer (options) {
|
|
249
265
|
if (!this._provider) {
|
|
250
|
-
throw new
|
|
266
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to quote transfer operations.')
|
|
251
267
|
}
|
|
252
268
|
|
|
253
269
|
const tx = await WalletAccountReadOnlyEvm._getTransferTransaction(options)
|
|
@@ -260,26 +276,139 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
260
276
|
/**
|
|
261
277
|
* Returns a transaction's receipt.
|
|
262
278
|
*
|
|
279
|
+
* @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt remains available on its `receipt` property.
|
|
263
280
|
* @param {string} hash - The transaction's hash.
|
|
264
281
|
* @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
|
|
282
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
265
283
|
*/
|
|
266
284
|
async getTransactionReceipt (hash) {
|
|
267
285
|
if (!this._provider) {
|
|
268
|
-
throw new
|
|
286
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to fetch transaction receipts.')
|
|
269
287
|
}
|
|
270
288
|
|
|
271
289
|
return await this._provider.getTransactionReceipt(hash)
|
|
272
290
|
}
|
|
273
291
|
|
|
292
|
+
/**
|
|
293
|
+
* Returns a normalized, finality-based receipt for a transaction.
|
|
294
|
+
*
|
|
295
|
+
* @param {string} hash - The transaction's hash.
|
|
296
|
+
* @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The normalized receipt.
|
|
297
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
298
|
+
* @throws {ValueError} If the hash is not a valid transaction hash.
|
|
299
|
+
* @throws {NoSuchElementError} If no transaction has been found for the given hash.
|
|
300
|
+
*/
|
|
301
|
+
async getTransaction (hash) {
|
|
302
|
+
if (!this._provider) {
|
|
303
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to fetch transactions.')
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!isHexString(hash, 32)) {
|
|
307
|
+
throw new ValueError(`Invalid transaction hash: '${hash}'.`)
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
const [transaction, receipt] = await Promise.all([
|
|
311
|
+
this._provider.getTransaction(hash),
|
|
312
|
+
this._provider.getTransactionReceipt(hash)
|
|
313
|
+
])
|
|
314
|
+
|
|
315
|
+
if (!transaction && !receipt) {
|
|
316
|
+
throw new NoSuchElementError(`No transaction found for '${hash}'.`)
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
if (!receipt) {
|
|
320
|
+
const dropped = transaction
|
|
321
|
+
? await this._isReplaced(transaction)
|
|
322
|
+
: false
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
hash,
|
|
326
|
+
finality: dropped ? 'dropped' : 'pending',
|
|
327
|
+
confirmations: 0,
|
|
328
|
+
receipt: null
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const confirmations = await receipt.confirmations()
|
|
333
|
+
const finalized = await this._isFinalized(receipt.blockNumber)
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
hash,
|
|
337
|
+
finality: finalized ? 'final' : 'confirmed',
|
|
338
|
+
success: receipt.status === 1,
|
|
339
|
+
block: receipt.blockNumber,
|
|
340
|
+
fee: receipt.fee,
|
|
341
|
+
confirmations,
|
|
342
|
+
receipt
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
|
|
348
|
+
*
|
|
349
|
+
* @param {string} hash - The transaction's hash.
|
|
350
|
+
* @param {WaitForTransactionOptions} [options] - The wait options.
|
|
351
|
+
* @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
|
|
352
|
+
* @throws {TimeoutError} If the target is not reached before the timeout.
|
|
353
|
+
*/
|
|
354
|
+
async waitForTransaction (hash, options = {}) {
|
|
355
|
+
return await super.waitForTransaction(hash, options)
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Returns whether a block is at or below the chain's `finalized` block. Chains that don't support the tag are treated as not finalized.
|
|
360
|
+
*
|
|
361
|
+
* @protected
|
|
362
|
+
* @param {number} blockNumber - The block number to check.
|
|
363
|
+
* @returns {Promise<boolean>} True if the block is finalized.
|
|
364
|
+
*/
|
|
365
|
+
async _isFinalized (blockNumber) {
|
|
366
|
+
try {
|
|
367
|
+
const finalizedBlock = await this._provider.getBlock('finalized')
|
|
368
|
+
return !!finalizedBlock && blockNumber <= finalizedBlock.number
|
|
369
|
+
} catch (error) {
|
|
370
|
+
// Treat an unsupported 'finalized' block tag as not-finalized; let real failures propagate.
|
|
371
|
+
const rpcCode = error?.info?.error?.code
|
|
372
|
+
|
|
373
|
+
if (isError(error, 'UNSUPPORTED_OPERATION') || rpcCode === -32601 || rpcCode === -32602) {
|
|
374
|
+
return false
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
throw error
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Returns whether an unmined transaction has been replaced, i.e. its sender's mined nonce has already advanced past the transaction's nonce.
|
|
383
|
+
*
|
|
384
|
+
* @protected
|
|
385
|
+
* @param {EvmTransactionResponse} transaction - The unmined transaction.
|
|
386
|
+
* @returns {Promise<boolean>} True if the transaction's nonce slot is already taken.
|
|
387
|
+
*/
|
|
388
|
+
async _isReplaced (transaction) {
|
|
389
|
+
const accountNonce = await this._provider.getTransactionCount(transaction.from, 'latest')
|
|
390
|
+
return accountNonce > transaction.nonce
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Overrides the base default to allow for slower EVM inclusion and confirmation.
|
|
395
|
+
*
|
|
396
|
+
* @type {number}
|
|
397
|
+
*/
|
|
398
|
+
get defaultWaitTimeout () {
|
|
399
|
+
return 120000
|
|
400
|
+
}
|
|
401
|
+
|
|
274
402
|
/**
|
|
275
403
|
* Returns the current allowance for the given token and spender.
|
|
276
404
|
* @param {string} token The token's address.
|
|
277
405
|
* @param {string} spender The spender's address.
|
|
278
406
|
* @returns {Promise<bigint>} The allowance.
|
|
407
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
279
408
|
*/
|
|
280
409
|
async getAllowance (token, spender) {
|
|
281
410
|
if (!this._provider) {
|
|
282
|
-
throw new
|
|
411
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to retrieve allowances.')
|
|
283
412
|
}
|
|
284
413
|
|
|
285
414
|
const address = await this.getAddress()
|
|
@@ -322,10 +451,11 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
322
451
|
* Checks if this account has an active ERC-7702 delegation.
|
|
323
452
|
*
|
|
324
453
|
* @returns {Promise<DelegationInfo>} The delegation info.
|
|
454
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
325
455
|
*/
|
|
326
456
|
async getDelegation () {
|
|
327
457
|
if (!this._provider) {
|
|
328
|
-
throw new
|
|
458
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to check delegation.')
|
|
329
459
|
}
|
|
330
460
|
|
|
331
461
|
const address = await this.getAddress()
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
-
import WalletManager from '@tetherto/wdk-wallet'
|
|
17
|
+
import WalletManager, { InvalidSignerError, ProviderRequiredError } from '@tetherto/wdk-wallet'
|
|
18
18
|
|
|
19
19
|
import { BrowserProvider, JsonRpcProvider } from 'ethers'
|
|
20
20
|
|
|
@@ -28,7 +28,7 @@ import SeedSignerEvm from './signers/seed-signer-evm.js'
|
|
|
28
28
|
|
|
29
29
|
/** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
|
|
30
30
|
/** @typedef {import("@tetherto/wdk-wallet").ISigner} ISigner */
|
|
31
|
-
/** @typedef {import("@tetherto/wdk-wallet").
|
|
31
|
+
/** @typedef {import("@tetherto/wdk-wallet").NoSuchElementError} NoSuchElementError */
|
|
32
32
|
|
|
33
33
|
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
34
34
|
|
|
@@ -59,6 +59,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
59
59
|
*
|
|
60
60
|
* @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 seed phrase, seed bytes, or a root signer. Root signers must be derivable — non-derivable signers (e.g. private-key signers) can only be registered by name via {@link addSigner}.
|
|
61
61
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
62
|
+
* @throws {InvalidSignerError} If the default signer doesn't support account derivation.
|
|
62
63
|
*/
|
|
63
64
|
constructor (seedOrSigner, config = {}) {
|
|
64
65
|
let signer = seedOrSigner
|
|
@@ -66,7 +67,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
66
67
|
signer = new SeedSignerEvm(seedOrSigner)
|
|
67
68
|
}
|
|
68
69
|
if (!signer.isDerivable) {
|
|
69
|
-
throw new
|
|
70
|
+
throw new InvalidSignerError('The default signer must be derivable. Non-derivable signers (e.g. private-key signers) can only be registered by name via addSigner.')
|
|
70
71
|
}
|
|
71
72
|
super(signer, config)
|
|
72
73
|
|
|
@@ -117,8 +118,8 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
117
118
|
* @param {Object} [options] - Account options.
|
|
118
119
|
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
119
120
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
120
|
-
* @throws {
|
|
121
|
-
* @throws {
|
|
121
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
122
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
122
123
|
*/
|
|
123
124
|
|
|
124
125
|
/**
|
|
@@ -129,7 +130,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
129
130
|
* @overload
|
|
130
131
|
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
131
132
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
132
|
-
* @throws {
|
|
133
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
133
134
|
*/
|
|
134
135
|
|
|
135
136
|
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
@@ -158,8 +159,8 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
158
159
|
* @param {Object} [options] - Account options.
|
|
159
160
|
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
160
161
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
161
|
-
* @throws {
|
|
162
|
-
* @throws {
|
|
162
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
163
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
163
164
|
*/
|
|
164
165
|
async getAccountByPath (path, options = {}) {
|
|
165
166
|
const { signerName } = options
|
|
@@ -178,10 +179,11 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
178
179
|
* Returns the current fee rates.
|
|
179
180
|
*
|
|
180
181
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
182
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
181
183
|
*/
|
|
182
184
|
async getFeeRates () {
|
|
183
185
|
if (!this._provider) {
|
|
184
|
-
throw new
|
|
186
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to get fee rates.')
|
|
185
187
|
}
|
|
186
188
|
|
|
187
189
|
const data = await this._provider.getFeeData()
|
package/types/index.d.ts
CHANGED
|
@@ -7,14 +7,20 @@ export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
|
7
7
|
export type Authorization = import("ethers").Authorization;
|
|
8
8
|
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
9
9
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
10
|
+
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
10
11
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
11
12
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
12
13
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
13
14
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
15
|
+
export type Finality = import("@tetherto/wdk-wallet").Finality;
|
|
16
|
+
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
17
|
+
export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
|
|
18
|
+
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
14
19
|
export type TypedData = import("./src/wallet-account-read-only-evm.js").TypedData;
|
|
15
20
|
export type DelegationInfo = import("./src/wallet-account-read-only-evm.js").DelegationInfo;
|
|
16
21
|
export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
|
|
17
22
|
export type EvmTransferOptions = import("./src/wallet-account-read-only-evm.js").EvmTransferOptions;
|
|
18
23
|
export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
24
|
+
export type EvmTransactionDetails = import("./src/wallet-account-read-only-evm.js").EvmTransactionDetails;
|
|
19
25
|
export type ApproveOptions = import("./src/wallet-account-evm.js").ApproveOptions;
|
|
20
26
|
export type UnsignedEvmTransaction = import("./src/utils/tx-populator-evm.js").UnsignedEvmTransaction;
|
|
@@ -39,7 +39,7 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
|
|
|
39
39
|
/**
|
|
40
40
|
* PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
|
|
41
41
|
* @returns {Promise<never>}
|
|
42
|
-
* @throws {
|
|
42
|
+
* @throws {InvalidSignerError} Always — private-key signers do not support derivation.
|
|
43
43
|
*/
|
|
44
44
|
derive(): Promise<never>;
|
|
45
45
|
/** @returns {Promise<string>} */
|
|
@@ -79,7 +79,7 @@ export class ISignerEvm extends ISigner {
|
|
|
79
79
|
*
|
|
80
80
|
* @param {string} relPath - The relative BIP-44 path segment.
|
|
81
81
|
* @returns {Promise<ISignerEvm>} The derived child signer.
|
|
82
|
-
* @throws {
|
|
82
|
+
* @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
|
|
83
83
|
*/
|
|
84
84
|
derive(relPath: string): Promise<ISignerEvm>;
|
|
85
85
|
/**
|
|
@@ -128,8 +128,8 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
128
128
|
*
|
|
129
129
|
* @param {string|Uint8Array|null} seed - BIP-39 mnemonic or seed bytes. Omit when providing `opts.root`.
|
|
130
130
|
* @param {SeedSignerEvmOpts} [opts] - Construction options for root reuse, direct child derivation or path definition (default is index 0).
|
|
131
|
-
* @throws {
|
|
132
|
-
* @throws {
|
|
131
|
+
* @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
|
|
132
|
+
* @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
|
|
133
133
|
*/
|
|
134
134
|
constructor(seed: string | Uint8Array | null, opts?: SeedSignerEvmOpts);
|
|
135
135
|
/** @private */
|
|
@@ -149,7 +149,7 @@ export default class SeedSignerEvm extends ISignerEvm {
|
|
|
149
149
|
* Derive a child signer using the provided relative path (e.g. "0'/0/0").
|
|
150
150
|
* @param {string} relPath
|
|
151
151
|
* @returns {Promise<SeedSignerEvm>}
|
|
152
|
-
* @throws {
|
|
152
|
+
* @throws {InvalidSignerError} If called on a derived child signer, which does not retain the root.
|
|
153
153
|
*/
|
|
154
154
|
derive(relPath: string): Promise<SeedSignerEvm>;
|
|
155
155
|
/**
|
|
@@ -80,5 +80,6 @@ export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
|
80
80
|
* @param {string} from - The sender address.
|
|
81
81
|
* @param {UnsignedEvmTransaction} tx - The partial transaction to populate.
|
|
82
82
|
* @returns {Promise<UnsignedEvmTransaction>} The fully populated unsigned transaction.
|
|
83
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
83
84
|
*/
|
|
84
85
|
export function populateTransactionEvm(provider: Provider, from: string, tx: UnsignedEvmTransaction): Promise<UnsignedEvmTransaction>;
|
|
@@ -83,7 +83,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
83
83
|
*
|
|
84
84
|
* @param {EvmTransaction} tx - The transaction to sign.
|
|
85
85
|
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
86
|
-
* @throws {
|
|
86
|
+
* @throws {MaximumFeeExceededError} If a provider is set, and the transaction's cost surpasses the transaction max. fee option.
|
|
87
87
|
*/
|
|
88
88
|
signTransaction(tx: EvmTransaction): Promise<string>;
|
|
89
89
|
/**
|
|
@@ -91,7 +91,9 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
91
91
|
*
|
|
92
92
|
* @param {EvmTransaction | string} tx - The transaction.
|
|
93
93
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
94
|
-
* @throws {
|
|
94
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
95
|
+
* @throws {MaximumFeeExceededError} If the transaction's cost exceeds the maximum transaction fee option.
|
|
96
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
95
97
|
*/
|
|
96
98
|
sendTransaction(tx: EvmTransaction | string): Promise<TransactionResult>;
|
|
97
99
|
/**
|
|
@@ -99,6 +101,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
99
101
|
*
|
|
100
102
|
* @param {EvmTransaction | string} tx - The transaction.
|
|
101
103
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
104
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
102
105
|
*/
|
|
103
106
|
quoteSendTransaction(tx: EvmTransaction | string): Promise<Omit<TransactionResult, "hash">>;
|
|
104
107
|
/**
|
|
@@ -106,7 +109,8 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
106
109
|
*
|
|
107
110
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
108
111
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
109
|
-
* @throws {
|
|
112
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
113
|
+
* @throws {MaximumFeeExceededError} If the transfer's cost exceeds the maximum transfer fee option.
|
|
110
114
|
*/
|
|
111
115
|
transfer(options: EvmTransferOptions): Promise<TransferResult>;
|
|
112
116
|
/**
|
|
@@ -114,7 +118,8 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
114
118
|
*
|
|
115
119
|
* @param {ApproveOptions} options The approve options.
|
|
116
120
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
117
|
-
* @throws {
|
|
121
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
122
|
+
* @throws {ValueError} If trying to approve usdts on ethereum with allowance not equal to zero (due to the usdt allowance reset requirement).
|
|
118
123
|
*/
|
|
119
124
|
approve(options: ApproveOptions): Promise<TransactionResult>;
|
|
120
125
|
/**
|
|
@@ -139,6 +144,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
139
144
|
*
|
|
140
145
|
* @param {string} delegateAddress - The address of the contract to delegate to.
|
|
141
146
|
* @returns {Promise<TransactionResult>} The transaction result.
|
|
147
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
142
148
|
*/
|
|
143
149
|
delegate(delegateAddress: string): Promise<TransactionResult>;
|
|
144
150
|
/**
|
|
@@ -38,6 +38,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
38
38
|
* Returns the account's eth balance.
|
|
39
39
|
*
|
|
40
40
|
* @returns {Promise<bigint>} The eth balance (in weis).
|
|
41
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
41
42
|
*/
|
|
42
43
|
getBalance(): Promise<bigint>;
|
|
43
44
|
/**
|
|
@@ -45,6 +46,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
45
46
|
*
|
|
46
47
|
* @param {string} tokenAddress - The smart contract address of the token.
|
|
47
48
|
* @returns {Promise<bigint>} The token balance (in base unit).
|
|
49
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
48
50
|
*/
|
|
49
51
|
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
50
52
|
/**
|
|
@@ -52,6 +54,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
52
54
|
*
|
|
53
55
|
* @param {string[]} tokenAddresses - The smart contract addresses of the tokens.
|
|
54
56
|
* @returns {Promise<Record<string, bigint>>} A mapping of token addresses to their balances (in base units).
|
|
57
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
55
58
|
*/
|
|
56
59
|
getTokenBalances(tokenAddresses: string[]): Promise<Record<string, bigint>>;
|
|
57
60
|
/**
|
|
@@ -59,6 +62,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
59
62
|
*
|
|
60
63
|
* @param {EvmTransaction} tx - The transaction.
|
|
61
64
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
65
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
62
66
|
*/
|
|
63
67
|
quoteSendTransaction(tx: EvmTransaction): Promise<Omit<TransactionResult, "hash">>;
|
|
64
68
|
/**
|
|
@@ -66,20 +70,65 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
66
70
|
*
|
|
67
71
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
68
72
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
73
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
69
74
|
*/
|
|
70
75
|
quoteTransfer(options: EvmTransferOptions): Promise<Omit<TransferResult, "hash">>;
|
|
71
76
|
/**
|
|
72
77
|
* Returns a transaction's receipt.
|
|
73
78
|
*
|
|
79
|
+
* @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt remains available on its `receipt` property.
|
|
74
80
|
* @param {string} hash - The transaction's hash.
|
|
75
81
|
* @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
|
|
82
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
76
83
|
*/
|
|
77
84
|
getTransactionReceipt(hash: string): Promise<EvmTransactionReceipt | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns a normalized, finality-based receipt for a transaction.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} hash - The transaction's hash.
|
|
89
|
+
* @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The normalized receipt.
|
|
90
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
91
|
+
* @throws {ValueError} If the hash is not a valid transaction hash.
|
|
92
|
+
* @throws {NoSuchElementError} If no transaction has been found for the given hash.
|
|
93
|
+
*/
|
|
94
|
+
getTransaction(hash: string): Promise<TransactionReceipt & EvmTransactionDetails>;
|
|
95
|
+
/**
|
|
96
|
+
* Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
|
|
97
|
+
*
|
|
98
|
+
* @param {string} hash - The transaction's hash.
|
|
99
|
+
* @param {WaitForTransactionOptions} [options] - The wait options.
|
|
100
|
+
* @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
|
|
101
|
+
* @throws {TimeoutError} If the target is not reached before the timeout.
|
|
102
|
+
*/
|
|
103
|
+
waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt & EvmTransactionDetails>;
|
|
104
|
+
/**
|
|
105
|
+
* Returns whether a block is at or below the chain's `finalized` block. Chains that don't support the tag are treated as not finalized.
|
|
106
|
+
*
|
|
107
|
+
* @protected
|
|
108
|
+
* @param {number} blockNumber - The block number to check.
|
|
109
|
+
* @returns {Promise<boolean>} True if the block is finalized.
|
|
110
|
+
*/
|
|
111
|
+
protected _isFinalized(blockNumber: number): Promise<boolean>;
|
|
112
|
+
/**
|
|
113
|
+
* Returns whether an unmined transaction has been replaced, i.e. its sender's mined nonce has already advanced past the transaction's nonce.
|
|
114
|
+
*
|
|
115
|
+
* @protected
|
|
116
|
+
* @param {EvmTransactionResponse} transaction - The unmined transaction.
|
|
117
|
+
* @returns {Promise<boolean>} True if the transaction's nonce slot is already taken.
|
|
118
|
+
*/
|
|
119
|
+
protected _isReplaced(transaction: EvmTransactionResponse): Promise<boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* Overrides the base default to allow for slower EVM inclusion and confirmation.
|
|
122
|
+
*
|
|
123
|
+
* @type {number}
|
|
124
|
+
*/
|
|
125
|
+
get defaultWaitTimeout(): number;
|
|
78
126
|
/**
|
|
79
127
|
* Returns the current allowance for the given token and spender.
|
|
80
128
|
* @param {string} token The token's address.
|
|
81
129
|
* @param {string} spender The spender's address.
|
|
82
130
|
* @returns {Promise<bigint>} The allowance.
|
|
131
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
83
132
|
*/
|
|
84
133
|
getAllowance(token: string, spender: string): Promise<bigint>;
|
|
85
134
|
/**
|
|
@@ -102,6 +151,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
102
151
|
* Checks if this account has an active ERC-7702 delegation.
|
|
103
152
|
*
|
|
104
153
|
* @returns {Promise<DelegationInfo>} The delegation info.
|
|
154
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
105
155
|
*/
|
|
106
156
|
getDelegation(): Promise<DelegationInfo>;
|
|
107
157
|
/** @private */
|
|
@@ -113,8 +163,24 @@ export type TypedDataDomain = import("ethers").TypedDataDomain;
|
|
|
113
163
|
export type TypedDataField = import("ethers").TypedDataField;
|
|
114
164
|
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
115
165
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
166
|
+
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
116
167
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
117
168
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
169
|
+
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
170
|
+
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
171
|
+
/**
|
|
172
|
+
* The EVM-specific fields added to a normalized transaction receipt.
|
|
173
|
+
*/
|
|
174
|
+
export type EvmTransactionDetails = {
|
|
175
|
+
/**
|
|
176
|
+
* - The number of confirmations (0 while pending or dropped).
|
|
177
|
+
*/
|
|
178
|
+
confirmations: number;
|
|
179
|
+
/**
|
|
180
|
+
* - The native ethers receipt, or null while the transaction is pending or dropped.
|
|
181
|
+
*/
|
|
182
|
+
receipt: EvmTransactionReceipt | null;
|
|
183
|
+
};
|
|
118
184
|
export type TypedData = {
|
|
119
185
|
/**
|
|
120
186
|
* - The domain separator.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/** @typedef {import('ethers').Provider} Provider */
|
|
2
2
|
/** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
|
|
3
3
|
/** @typedef {import("@tetherto/wdk-wallet").ISigner} ISigner */
|
|
4
|
+
/** @typedef {import("@tetherto/wdk-wallet").NoSuchElementError} NoSuchElementError */
|
|
4
5
|
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
5
6
|
export default class WalletManagerEvm extends WalletManager {
|
|
6
7
|
/**
|
|
@@ -27,6 +28,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
27
28
|
*
|
|
28
29
|
* @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 seed phrase, seed bytes, or a root signer. Root signers must be derivable — non-derivable signers (e.g. private-key signers) can only be registered by name via {@link addSigner}.
|
|
29
30
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
31
|
+
* @throws {InvalidSignerError} If the default signer doesn't support account derivation.
|
|
30
32
|
*/
|
|
31
33
|
constructor(seedOrSigner: string | Uint8Array | ISigner, config?: EvmWalletConfig);
|
|
32
34
|
/**
|
|
@@ -43,8 +45,8 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
43
45
|
* @param {Object} [options] - Account options.
|
|
44
46
|
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
45
47
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
46
|
-
* @throws {
|
|
47
|
-
* @throws {
|
|
48
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
49
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
48
50
|
*/
|
|
49
51
|
getAccount(index?: number, options?: {
|
|
50
52
|
signerName?: string;
|
|
@@ -56,7 +58,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
56
58
|
*
|
|
57
59
|
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
58
60
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
59
|
-
* @throws {
|
|
61
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
60
62
|
*/
|
|
61
63
|
getAccount(signerName: string): Promise<WalletAccountEvm>;
|
|
62
64
|
/**
|
|
@@ -66,8 +68,8 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
66
68
|
* @param {Object} [options] - Account options.
|
|
67
69
|
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
68
70
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
69
|
-
* @throws {
|
|
70
|
-
* @throws {
|
|
71
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
72
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
71
73
|
*/
|
|
72
74
|
getAccountByPath(path: string, options?: {
|
|
73
75
|
signerName?: string;
|
|
@@ -76,6 +78,7 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
76
78
|
* Returns the current fee rates.
|
|
77
79
|
*
|
|
78
80
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
81
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
79
82
|
*/
|
|
80
83
|
getFeeRates(): Promise<FeeRates>;
|
|
81
84
|
}
|
|
@@ -83,6 +86,7 @@ export type ISignerEvm = import("./signers/seed-signer-evm.js").ISignerEvm;
|
|
|
83
86
|
export type Provider = import("ethers").Provider;
|
|
84
87
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
85
88
|
export type ISigner = import("@tetherto/wdk-wallet").ISigner;
|
|
89
|
+
export type NoSuchElementError = import("@tetherto/wdk-wallet").NoSuchElementError;
|
|
86
90
|
export type EvmWalletConfig = import("./wallet-account-evm.js").EvmWalletConfig;
|
|
87
91
|
import WalletManager from '@tetherto/wdk-wallet';
|
|
88
92
|
import WalletAccountEvm from './wallet-account-evm.js';
|